allData = $data; parent::__construct(); } /** * 初始化卡片内容 */ protected function init() { parent::init(); $this->title($this->allData['title']); // 新生数据 $studentsIds = AdmissionNewStudents::query()->where(["is_new_student" => "1"])->pluck('idCard')->toArray(); $all = UsersMember::query() ->where(['enroll_status' => '1']) ->whereIn("idcard", $studentsIds) ->when($this->allData['collagesId'],function ($query) { $specialityIds = Speciality::query()->where("secondary_college_id", $this->allData['collagesId'])->pluck('id')->toArray(); $query->whereIn('speciality_id', $specialityIds); }) ->select('sex', DB::raw('count(*) as total')) ->groupBy('sex') ->pluck('total', 'sex') ->toArray(); // 总人数 $total = array_sum($all); // 男生 $man = $all[1] ?? 0; // 女生 $girl = $all[2] ?? 0; $manPercent = $total != 0 ? number_format(($man / $total) * 100) : 0; $girlPercent = $total != 0 ? number_format(($girl / $total) * 100) : 0; // 卡片内容 $this->withContent($total, $man, $girl)->height('220px'); $this->chartLabels(['男生', '女生']); // 图表数据 $this->withChart([$manPercent, $girlPercent]); // 总数 $this->chartTotal('全部', $total); } /** * 设置图表数据. * @param array $data * @return $this */ public function withChart(array $data): AllColleges { return $this->chart([ 'series' => $data, ]); } /** * 卡片内容. * @param int $finished * @param int $pending * @param int $rejected * @return $this */ public function withContent(int $finished, int $pending, int $rejected): AllColleges { return $this->content( <<
全部
{$finished}
男生
{$pending}
女生
{$rejected}
HTML ); } }