input('option'); $table1 = UsersMember::query()->getModel()->getTable(); $table2 = UserFollowRecord::query()->getModel()->getTable(); $data = [[ 'name' => '总人数', 'data' => [], 'tooltip' => [ [ "name" => "男生", "data" => [], "color" => '#ff6b6b' ], [ "name" => "女生", "data" => [], "color" => "#a21919" ] ] ]]; $collegeAll = SecondaryCollege::query()->where(["status" => SecondaryCollege::STATUS_YES])->get(["name", "id"])->toArray(); $categories = array_column($collegeAll, 'name'); // 新生数据 $studentsIds = AdmissionNewStudents::query()->where(["is_new_student" => "1"])->pluck('idCard')->toArray(); foreach ($collegeAll as $key=>$value){ $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("aa.enroll_status", 1) ->where(function ($query) use ($value) { $specialityIds = Speciality::query()->where("secondary_college_id", $value['id'])->pluck('id')->toArray(); $query->whereIn('speciality_id', $specialityIds); }) ->where(function ($query) use ($option) { if (empty($option)) { $query->whereNull("bb.id"); } else { $query->where(["bb.follow_id" => $option]); } }) ->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; $data[0]['data'][] = $total; $data[0]['tooltip'][0]['data'][] = $man; $data[0]['tooltip'][1]['data'][] = $girl; } $this->withData($data); $this->option("labels", $categories); $tooltipCustomFunction = <<{ newStr += `
\${item.name}: \${item.data[dataPointIndex]}
` }) return `
\${w.config.labels[dataPointIndex]}
\${w.config.series[0].name}: \${w.config.series[0].data[dataPointIndex]}
\${newStr}
`; } JS; $this->option('tooltip.custom', JavaScript::make($tooltipCustomFunction)); } /** * 这里返回需要异步传递到 handler 方法的参数 * * @return array */ public function parameters(): array { return [ 'id' => $this->id, 'username' => $this->username, ]; } /** * 这里覆写父类的方法,不再查询数据 */ protected function buildData() { } }