海工商新版后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

131 lines
4.0 KiB

<?php
namespace App\Admin\Metrics\Examples\Follow;
use App\Models\AdmissionNewStudents;
use App\Models\Speciality;
use App\Models\UserFollowRecord;
use App\Models\UserFollowStatus;
use App\Models\UsersMember;
use Dcat\Admin\Widgets\Metrics\Round;
use Illuminate\Support\Facades\DB;
class AllNewFollowSpeciality extends Round
{
// 保存自定义参数
protected $data = [];
// 构造方法参数必须设置默认值
public function __construct(array $data = [])
{
$this->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(['bb.follow_id' => $this->data['follow_id']])
->where(['aa.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->withChart([$man, $girl]);
// 总数
$this->chartTotal('总人数', $total);
// 卡片内容
$this->withContent($total, $man, $girl);
}
/**
* 设置图表数据.
* @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(
<<<HTML
<div class="col-12 d-flex flex-column flex-wrap text-center" style="max-width: 220px">
<div class="chart-info d-flex justify-content-between mb-1 mt-2" >
<div class="series-info d-flex align-items-center">
<i class="fa fa-circle-o text-bold-700 text-primary"></i>
<span class="text-bold-600 ml-50">总人数</span>
</div>
<div class="product-result">
<span>{$finished}</span>
</div>
</div>
<div class="chart-info d-flex justify-content-between mb-1">
<div class="series-info d-flex align-items-center">
<i class="fa fa-circle-o text-bold-700 text-warning"></i>
<span class="text-bold-600 ml-50">男生</span>
</div>
<div class="product-result">
<span>{$pending}</span>
</div>
</div>
<div class="chart-info d-flex justify-content-between mb-1">
<div class="series-info d-flex align-items-center">
<i class="fa fa-circle-o text-bold-700 text-danger"></i>
<span class="text-bold-600 ml-50">女生</span>
</div>
<div class="product-result">
<span>{$rejected}</span>
</div>
</div>
</div>
HTML
);
}
}