6 changed files with 523 additions and 108 deletions
@ -0,0 +1,143 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace App\Admin\Metrics\Examples\Follow; |
||||||
|
|
||||||
|
use App\Models\AdmissionNewStudents; |
||||||
|
use App\Models\CompletedOfflineStep; |
||||||
|
use App\Models\Config; |
||||||
|
use App\Models\OfflineStep; |
||||||
|
use App\Models\SecondaryCollege; |
||||||
|
use App\Models\Speciality; |
||||||
|
use App\Models\UsersMember; |
||||||
|
use Dcat\Admin\Support\JavaScript; |
||||||
|
use Dcat\Admin\Widgets\ApexCharts\Chart; |
||||||
|
use Illuminate\Support\Facades\DB; |
||||||
|
|
||||||
|
class AllCollegesCharts extends Chart |
||||||
|
{ |
||||||
|
//各二级学院女生报道率 |
||||||
|
public function __construct($containerSelector = null, $options = []) |
||||||
|
{ |
||||||
|
parent::__construct($containerSelector, $options); |
||||||
|
|
||||||
|
$this->setUpOptions(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
//初始化方法,主要是调用$this->options()方法,执行整个option的初始化操作。 |
||||||
|
protected function setUpOptions() |
||||||
|
{ |
||||||
|
$this->options([ |
||||||
|
"chart"=>[ |
||||||
|
"height"=>300, //高度 |
||||||
|
"type"=>"bar", //chart 类型 |
||||||
|
], |
||||||
|
]); |
||||||
|
|
||||||
|
$data = [[ |
||||||
|
"name" => "总人数", |
||||||
|
"data" => [], |
||||||
|
"tooltip" => [ |
||||||
|
[ |
||||||
|
"name" => "男生", |
||||||
|
"data" => [], |
||||||
|
"color" => '#ff6b6b' |
||||||
|
], |
||||||
|
[ |
||||||
|
"name" => "女生", |
||||||
|
"data" => [], |
||||||
|
"color"=>"#a21919" |
||||||
|
] |
||||||
|
], |
||||||
|
]]; |
||||||
|
$label = []; |
||||||
|
|
||||||
|
// 执行你的数据查询逻辑 |
||||||
|
//取出当前年份 |
||||||
|
$config = Config::query()->where([ |
||||||
|
"unique_identification" => "annual_session" |
||||||
|
])->first(); |
||||||
|
|
||||||
|
//二级学院 |
||||||
|
$list = SecondaryCollege::query()->where([ |
||||||
|
"status" => SecondaryCollege::STATUS_YES |
||||||
|
])->get(["id", "name"])->toArray(); |
||||||
|
|
||||||
|
//不为空时 |
||||||
|
if(!empty($list)){ |
||||||
|
// 新生数据 |
||||||
|
$studentsIds = AdmissionNewStudents::query()->where(["is_new_student" => "1"])->pluck('idCard')->toArray(); |
||||||
|
|
||||||
|
foreach($list as $key => $item){ |
||||||
|
$all = UsersMember::query() |
||||||
|
->whereIn("idcard", $studentsIds) |
||||||
|
->where("enroll_status", 1) |
||||||
|
->where(function ($query)use($item) { |
||||||
|
$specialityIds = Speciality::query()->where("secondary_college_id", $item['id'])->pluck('id')->toArray(); |
||||||
|
$query->whereIn('speciality_id', $specialityIds); |
||||||
|
}) |
||||||
|
->select('sex', DB::raw('count(*) as total')) |
||||||
|
->groupBy('sex') |
||||||
|
->pluck('total', 'sex') |
||||||
|
->toArray(); |
||||||
|
|
||||||
|
$list[$key]["registering"] = array_sum($all); |
||||||
|
$list[$key]["studentsNum"] = $all[1] ?? 0; |
||||||
|
$list[$key]["completedOfflineStep"] = $all[2] ?? 0; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
foreach($list as $item){ |
||||||
|
array_push($label, $item["name"]); |
||||||
|
if(!empty($item["registering"])){ |
||||||
|
array_push($data[0]["data"], $item["registering"]); |
||||||
|
array_push($data[0]['tooltip'][0]['data'], $item["studentsNum"]); |
||||||
|
array_push($data[0]['tooltip'][1]['data'], $item["completedOfflineStep"]); |
||||||
|
}else{ |
||||||
|
array_push($data[0]["data"], 0); |
||||||
|
array_push($data[0]['tooltip'][0]['data'], 0); |
||||||
|
array_push($data[0]['tooltip'][1]['data'], 0); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
$this->option("series",$data); |
||||||
|
$this->option("labels",$label); |
||||||
|
$this->option("yaxis",["max" => 2000]); //Y轴最大值 |
||||||
|
|
||||||
|
$tooltipCustomFunction = <<<JS |
||||||
|
function({ series, seriesIndex, dataPointIndex, w }) { |
||||||
|
|
||||||
|
let newStr = ""; |
||||||
|
w.config.series[0].tooltip.forEach(item=>{ |
||||||
|
newStr += `<div style="display: flex;padding: 0 10px;align-items: center;margin-top: 8px;"> |
||||||
|
<div style="width:12px;height:12px;border-radius:50%;background-color: \${item.color};margin-right: 10px;"> |
||||||
|
|
||||||
|
</div> |
||||||
|
<div style="font-size: 12px;"> |
||||||
|
\${item.name}: \${item.data[dataPointIndex]} |
||||||
|
</div> |
||||||
|
</div>` |
||||||
|
}) |
||||||
|
|
||||||
|
return ` |
||||||
|
<div style=' border: 1px solid #e3e3e3; background: rgba(255, 255, 255, 0.96); border-radius: 5px; box-shadow: 2px 2px 6px -4px #999; font-size: 14px;'> |
||||||
|
<div style='padding:6px;background: #ECEFF1;border-bottom: 1px solid #ddd;font-size:12px;'>\${w.config.labels[dataPointIndex]}</div> |
||||||
|
<div style="display: flex;padding: 0 10px;align-items: center; margin-top: 8px;"> |
||||||
|
<div style="width:12px;height:12px;border-radius:50%;background-color: rgb(0, 143, 251);margin-right: 10px;"> |
||||||
|
|
||||||
|
</div> |
||||||
|
<div style="font-size: 12px;"> |
||||||
|
\${w.config.series[0].name}: \${w.config.series[0].data[dataPointIndex]} |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
\${newStr} |
||||||
|
</div> |
||||||
|
`; |
||||||
|
} |
||||||
|
JS; |
||||||
|
|
||||||
|
$this->option('tooltip.custom', JavaScript::make($tooltipCustomFunction)); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,149 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace App\Admin\Metrics\Examples\Follow; |
||||||
|
|
||||||
|
use App\Models\AdmissionNewStudents; |
||||||
|
use App\Models\Config; |
||||||
|
use App\Models\SecondaryCollege; |
||||||
|
use App\Models\Speciality; |
||||||
|
use App\Models\UserFollowStatus; |
||||||
|
use App\Models\UsersMember; |
||||||
|
use Dcat\Admin\Support\JavaScript; |
||||||
|
use Dcat\Admin\Widgets\ApexCharts\Chart; |
||||||
|
use Illuminate\Support\Facades\DB; |
||||||
|
|
||||||
|
class AllCollegesFollowCharts extends Chart |
||||||
|
{ |
||||||
|
//各二级学院女生报道率 |
||||||
|
public function __construct($containerSelector = null, $options = []) |
||||||
|
{ |
||||||
|
parent::__construct($containerSelector, $options); |
||||||
|
|
||||||
|
$this->setUpOptions(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
//初始化方法,主要是调用$this->options()方法,执行整个option的初始化操作。 |
||||||
|
protected function setUpOptions() |
||||||
|
{ |
||||||
|
$this->options([ |
||||||
|
"chart"=>[ |
||||||
|
"height"=>300, //高度 |
||||||
|
"type"=>"bar", //chart 类型 |
||||||
|
], |
||||||
|
]); |
||||||
|
|
||||||
|
$followStatus = UserFollowStatus::query() |
||||||
|
->addSelect(DB::raw('\'虚拟字段\' as data')) |
||||||
|
->addSelect(DB::raw('\'颜色\' as color')) |
||||||
|
->select(['id', 'name']) |
||||||
|
->get() |
||||||
|
->toArray(); |
||||||
|
|
||||||
|
$data = [[ |
||||||
|
"name" => "总人数", |
||||||
|
"data" => [], |
||||||
|
"tooltip" => [ |
||||||
|
[ |
||||||
|
"name" => "男生", |
||||||
|
"data" => [], |
||||||
|
"color" => '' |
||||||
|
], |
||||||
|
[ |
||||||
|
"name" => "女生", |
||||||
|
"data" => [], |
||||||
|
"color"=>"" |
||||||
|
] |
||||||
|
], |
||||||
|
]]; |
||||||
|
$label = []; |
||||||
|
|
||||||
|
// 执行你的数据查询逻辑 |
||||||
|
//取出当前年份 |
||||||
|
$config = Config::query()->where([ |
||||||
|
"unique_identification" => "annual_session" |
||||||
|
])->first(); |
||||||
|
|
||||||
|
//二级学院 |
||||||
|
$list = SecondaryCollege::query()->where([ |
||||||
|
"status" => SecondaryCollege::STATUS_YES |
||||||
|
])->get(["id", "name"])->toArray(); |
||||||
|
|
||||||
|
//不为空时 |
||||||
|
if(!empty($list)){ |
||||||
|
// 新生数据 |
||||||
|
$studentsIds = AdmissionNewStudents::query()->where(["is_new_student" => "1"])->pluck('idCard')->toArray(); |
||||||
|
|
||||||
|
foreach($list as $key => $item){ |
||||||
|
$all = UsersMember::query() |
||||||
|
->whereIn("idcard", $studentsIds) |
||||||
|
->where("enroll_status", 1) |
||||||
|
->where(function ($query)use($item) { |
||||||
|
$specialityIds = Speciality::query()->where("secondary_college_id", $item['id'])->pluck('id')->toArray(); |
||||||
|
$query->whereIn('speciality_id', $specialityIds); |
||||||
|
}) |
||||||
|
->select('sex', DB::raw('count(*) as total')) |
||||||
|
->groupBy('sex') |
||||||
|
->pluck('total', 'sex') |
||||||
|
->toArray(); |
||||||
|
|
||||||
|
$list[$key]["registering"] = array_sum($all); |
||||||
|
$list[$key]["studentsNum"] = $all[1] ?? 0; |
||||||
|
$list[$key]["completedOfflineStep"] = $all[2] ?? 0; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
foreach($list as $item){ |
||||||
|
array_push($label, $item["name"]); |
||||||
|
if(!empty($item["registering"])){ |
||||||
|
array_push($data[0]["data"], $item["registering"]); |
||||||
|
array_push($data[0]['tooltip'][0]['data'], $item["studentsNum"]); |
||||||
|
array_push($data[0]['tooltip'][1]['data'], $item["completedOfflineStep"]); |
||||||
|
}else{ |
||||||
|
array_push($data[0]["data"], 0); |
||||||
|
array_push($data[0]['tooltip'][0]['data'], 0); |
||||||
|
array_push($data[0]['tooltip'][1]['data'], 0); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
$this->option("series",$data); |
||||||
|
$this->option("labels",$label); |
||||||
|
$this->option("yaxis",["max" => 2000]); //Y轴最大值 |
||||||
|
|
||||||
|
$tooltipCustomFunction = <<<JS |
||||||
|
function({ series, seriesIndex, dataPointIndex, w }) { |
||||||
|
|
||||||
|
let newStr = ""; |
||||||
|
w.config.series[0].tooltip.forEach(item=>{ |
||||||
|
newStr += `<div style="display: flex;padding: 0 10px;align-items: center;margin-top: 8px;"> |
||||||
|
<div style="width:12px;height:12px;border-radius:50%;background-color: \${item.color};margin-right: 10px;"> |
||||||
|
|
||||||
|
</div> |
||||||
|
<div style="font-size: 12px;"> |
||||||
|
\${item.name}: \${item.data[dataPointIndex]} |
||||||
|
</div> |
||||||
|
</div>` |
||||||
|
}) |
||||||
|
|
||||||
|
return ` |
||||||
|
<div style=' border: 1px solid #e3e3e3; background: rgba(255, 255, 255, 0.96); border-radius: 5px; box-shadow: 2px 2px 6px -4px #999; font-size: 14px;'> |
||||||
|
<div style='padding:6px;background: #ECEFF1;border-bottom: 1px solid #ddd;font-size:12px;'>\${w.config.labels[dataPointIndex]}</div> |
||||||
|
<div style="display: flex;padding: 0 10px;align-items: center; margin-top: 8px;"> |
||||||
|
<div style="width:12px;height:12px;border-radius:50%;background-color: rgb(0, 143, 251);margin-right: 10px;"> |
||||||
|
|
||||||
|
</div> |
||||||
|
<div style="font-size: 12px;"> |
||||||
|
\${w.config.series[0].name}: \${w.config.series[0].data[dataPointIndex]} |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
\${newStr} |
||||||
|
</div> |
||||||
|
`; |
||||||
|
} |
||||||
|
JS; |
||||||
|
|
||||||
|
$this->option('tooltip.custom', JavaScript::make($tooltipCustomFunction)); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,123 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace App\Admin\Repositories; |
||||||
|
|
||||||
|
use App\Models\AdminFollowShow; |
||||||
|
use App\Models\AdmissionNewStudents; |
||||||
|
use App\Models\SecondaryCollege; |
||||||
|
use App\Models\Speciality; |
||||||
|
use App\Models\Speciality as Model; |
||||||
|
use App\Models\UserFollowRecord; |
||||||
|
use App\Models\UserFollowStatus; |
||||||
|
use App\Models\UsersMember; |
||||||
|
use Dcat\Admin\Admin; |
||||||
|
use Dcat\Admin\Grid; |
||||||
|
use Dcat\Admin\Repositories\EloquentRepository; |
||||||
|
use Illuminate\Support\Facades\DB; |
||||||
|
|
||||||
|
class UserFollowOverview extends EloquentRepository |
||||||
|
{ |
||||||
|
/** |
||||||
|
* Model. |
||||||
|
* @var string |
||||||
|
*/ |
||||||
|
protected $eloquentClass = Model::class; |
||||||
|
|
||||||
|
|
||||||
|
public function get(Grid\Model $model) |
||||||
|
{ |
||||||
|
$secondary_college_id = $model->filter()->input('secondary_college_id'); |
||||||
|
$speciality_id = $model->filter()->input('speciality_id'); |
||||||
|
|
||||||
|
// 获取每页显示行数 |
||||||
|
$perPage = $model->getPerPage(); |
||||||
|
$table1 = UsersMember::query()->getModel()->getTable(); |
||||||
|
$table2 = UserFollowRecord::query()->getModel()->getTable(); |
||||||
|
$showInfo = AdminFollowShow::query()->where(['user_id' => Admin::user()['id']])->first(); |
||||||
|
|
||||||
|
// 新生数据 |
||||||
|
$studentsIds = AdmissionNewStudents::query()->where(["is_new_student" => "1"])->pluck('idCard')->toArray(); |
||||||
|
// 回访状态 |
||||||
|
$followStatus = UserFollowStatus::query()->get()->toArray(); |
||||||
|
$collegesName = SecondaryCollege::query()->pluck('name', 'id')->toArray(); |
||||||
|
$all = Model::query() |
||||||
|
->where(function ($query) use ($showInfo) { |
||||||
|
if ($showInfo) { |
||||||
|
if ($showInfo['type'] == '1') { |
||||||
|
$query->whereIn('secondary_college_id', $showInfo['secondary_college_id'] ?? []); |
||||||
|
} else { |
||||||
|
$query->whereIn('id', $showInfo['speciality_id'] ?? []); |
||||||
|
} |
||||||
|
} else { |
||||||
|
$query->where('id', 0); |
||||||
|
} |
||||||
|
}) |
||||||
|
->when($secondary_college_id, function ($query) use ($secondary_college_id) { |
||||||
|
$query->where('secondary_college_id', $secondary_college_id); |
||||||
|
}) |
||||||
|
->when($speciality_id, function ($query) use ($speciality_id) { |
||||||
|
$query->where('id', $speciality_id); |
||||||
|
}) |
||||||
|
->orderByDesc('id') |
||||||
|
->paginate($perPage) |
||||||
|
->toArray(); |
||||||
|
|
||||||
|
|
||||||
|
foreach ($all['data'] as $key => $value) { |
||||||
|
$all['data'][$key]["secondary_college_id"] = $collegesName[$value['secondary_college_id']] ?? null; |
||||||
|
|
||||||
|
// 各专业录取人数 |
||||||
|
$enroll_all = UsersMember::query() |
||||||
|
->where(['enroll_status' => '1']) |
||||||
|
->whereIn("idcard", $studentsIds) |
||||||
|
->where('speciality_id', $value['id']) |
||||||
|
->select('sex', DB::raw('count(*) as total')) |
||||||
|
->groupBy('sex') |
||||||
|
->pluck('total', 'sex') |
||||||
|
->toArray(); |
||||||
|
$all['data'][$key]["enroll_number"] = array_sum($enroll_all); |
||||||
|
$all['data'][$key]["enroll_man_student"] = $enroll_all[1] ?? 0; |
||||||
|
$all['data'][$key]["enroll_girl_student"] = $enroll_all[2] ?? 0; |
||||||
|
|
||||||
|
$all['data'][$key]["out_number"] = array_sum($enroll_all); |
||||||
|
$all['data'][$key]["out_man_student"] = $enroll_all[1] ?? 0; |
||||||
|
$all['data'][$key]["out_girl_student"] = $enroll_all[2] ?? 0; |
||||||
|
|
||||||
|
$total = DB::table("{$table2} as aa") |
||||||
|
->leftJoin("{$table1} as bb", function ($join) { |
||||||
|
$join->on("aa.unique_number", "=", "bb.unique_number"); |
||||||
|
}) |
||||||
|
->where(['aa.is_abandon' => '1', 'bb.speciality_id' => $value['id']]) |
||||||
|
->whereIn('bb.idcard', $studentsIds) |
||||||
|
->select('aa.follow_id', 'bb.sex', DB::raw('COUNT(*) as total')) |
||||||
|
->groupBy('aa.follow_id', 'bb.sex') |
||||||
|
->groupBy("bb.sex") |
||||||
|
->get() |
||||||
|
->toArray(); |
||||||
|
$totalData = []; |
||||||
|
foreach ($total as $key2 => $value2) { |
||||||
|
$totalData["{$value2->follow_id}{$value2->sex}"] = $value2->total; |
||||||
|
} |
||||||
|
|
||||||
|
foreach ($followStatus as $key3 => $value3) { |
||||||
|
$followId = $value3['id']; |
||||||
|
$man = 1; |
||||||
|
$girl = 2; |
||||||
|
|
||||||
|
$all['data'][$key]["total_number{$followId}"] = ($totalData["{$followId}{$man}"] ?? 0) + ($totalData["{$followId}{$girl}"] ?? 0); |
||||||
|
$all['data'][$key]["man_student{$followId}"] = $totalData["{$followId}{$man}"] ?? 0; |
||||||
|
$all['data'][$key]["girl_student{$followId}"] = $totalData["{$followId}{$girl}"] ?? 0; |
||||||
|
|
||||||
|
$all['data'][$key]["out_number"] -= $all['data'][$key]["total_number{$followId}"]; |
||||||
|
$all['data'][$key]["out_man_student"] -= $all['data'][$key]["man_student{$followId}"]; |
||||||
|
$all['data'][$key]["out_girl_student"] -= $all['data'][$key]["girl_student{$followId}"]; |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return $model->makePaginator( |
||||||
|
$all['total'] ?? 0, // 传入总记录数 |
||||||
|
$all['data'] ?? [] // 传入数据二维数组 |
||||||
|
); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue