data = $data; parent::__construct(); } /** * 初始化卡片内容 */ protected function init() { parent::init(); $this->title('各专业录取统计'); if (!empty($this->data['speciality_id'])) { $specialityInfo = Speciality::query()->where('id', $this->data['speciality_id'])->first(['speciality_name', 'secondary_college_id']); $name = ""; if ($specialityInfo) { $name .= $specialityInfo['speciality_name']; $collegeName = SecondaryCollege::query()->where('id', $specialityInfo['secondary_college_id'])->value('name'); if ($collegeName) { $name .= "({$collegeName})"; } } } else { $name = "当前专业:无"; } $this->subTitle($name); // 新生数据 $studentsIds = AdmissionNewStudents::query()->where(["is_new_student" => "1"])->pluck('idCard')->toArray(); $all = UsersMember::query() ->where(['enroll_status' => '1']) ->whereIn("idcard", $studentsIds) ->where('speciality_id', $this->data['speciality_id']) ->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; $this->chartLabels(['总人数', '男生', '女生']); $this->withContent($total, $man, $girl); } /** * 设置图表数据. * * @param array $data * * @return $this */ public function withChart(array $data) { return $this->chart([ 'series' => $data, ]); } /** * @param int $percent * * @return $this */ public function up($percent) { return $this->footer( " {$percent}人 为当前年份已导入新生人数" ); } /** * 卡片内容. * * @param int $finished * @param int $pending * @param int $rejected * * @return $this */ public function withContent($finished, $pending, $rejected) { return $this->content( <<