data = $data; parent::__construct(); } /** * 初始化卡片内容 */ protected function init() { parent::init(); $this->title('各院最新回访结果'); if (empty($this->data['follow_id'])) { $this->subTitle('当前回访状态:未联系'); } else { $this->subTitle('当前回访状态:' . UserFollowStatus::query()->where(['id' => $this->data['follow_id']])->value('name')); } $this->chartLabels(['女生', '男生']); $table1 = UsersMember::query()->getModel()->getTable(); $table2 = UserFollowRecord::query()->getModel()->getTable(); // 新生数据 $studentsIds = AdmissionNewStudents::query()->where(["is_new_student" => "1"])->pluck('idCard')->toArray(); $all = DB::table("{$table1} as aa") ->leftJoin("{$table2} as bb", function ($join) { $join->on("aa.unique_number", "=", "bb.unique_number")->where(["bb.is_abandon" => "1"]); }) ->whereIn("aa.idcard", $studentsIds) ->where(function ($query) { if (is_array($this->data['secondary_college_id'])) { $ids = $this->data['secondary_college_id']; } else { $ids = explode(',', $this->data['secondary_college_id']); } $specialityIds = Speciality::query()->whereIn("secondary_college_id", array_filter($ids))->pluck('id')->toArray(); $query->whereIn('speciality_id', $specialityIds); }) ->where(function ($query) { if (empty($this->data['follow_id'])) { $query->whereNull("bb.id"); } else { $query->where(["bb.follow_id" => $this->data['follow_id']]); } }) ->select('aa.sex', DB::raw('count(*) as total')) ->groupBy('aa.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) { $this->chartColors(['#586cb1', '#dda451', '#ea5455']); return $this->chart([ 'series' => $data, ]); } /** * 卡片内容. * @param int $finished * @param int $pending * @param int $rejected * @return $this */ public function withContent($finished, $pending, $rejected) { return $this->content( <<