海工商新版后台
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.
 
 

185 lines
7.0 KiB

<?php
namespace App\Admin\Metrics\Chart;
use App\Models\AdmissionNewStudents;
use App\Models\CompletedOfflineStep;
use App\Models\Config;
use App\Models\OfflineStep;
use App\Models\Order;
use App\Models\PaymentList;
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 FullPaymentRateColumnCharts extends Chart
{
//各二级学院缴费率
public function __construct($containerSelector = null, $options = [])
{
parent::__construct($containerSelector, $options);
$this->setUpOptions();
}
//初始化方法,主要是调用$this->options()方法,执行整个option的初始化操作。
protected function setUpOptions()
{
$this->options([
"chart"=>[
"height"=>350, //高度
"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)){
foreach($list as $key => $item){
//取出该学院下的专业
$speciality = Speciality::query()->where([
"status" => Speciality::STATUS_YES,
"secondary_college_id" => $item["id"],
])->get()->toArray();
//专业ID
$specialityIds = array_column($speciality, "id");
//二级学院已录入的学生
$importStudents = AdmissionNewStudents::query()->where([
"annual_session" => $config->data,
"status" => AdmissionNewStudents::STATUS_YES,
"is_new_student" => AdmissionNewStudents::IS_NEW_STUDENT_YES,
])->whereIn("speciality_id", $specialityIds)->get("idCard")->toArray();
if(!empty($importStudents)){
$idcardList = array_column($importStudents, "idCard");
//根据身份证集取出已注册的用户
$userList = UsersMember::query()->whereIn("idcard", $idcardList)->where("status", UsersMember::STATUS_YES)->get("unique_number")->toArray();
if(!empty($userList)){
$userList = array_column($userList, "unique_number");
//已缴费人数
$payNum = Order::query()->whereIn("unique_number", $userList)->where([
"status" => Order::STATUS_PAID,
"annual_session" => $config->data,
])->select("unique_number")->groupBy('unique_number')->get()->toArray();
if(!empty($payNum)){
$completedOfflineStep = count($payNum);
}
//全额缴费人数
$paymentList = PaymentList::query()->where("annual_session", $config->data)
->whereIn("unique_number", $userList)
->select('unique_number', DB::raw('SUM(amount) as total_amount'))
->groupBy('unique_number')
->havingRaw('total_amount = ?', [0])
->get()->toArray();
$studentsNum = count($paymentList);
//报到率
if($studentsNum == 0 || $completedOfflineStep == 0){
$registering = 0;
}else{
$registering = round((($studentsNum / $completedOfflineStep ) * 100), 2) ;
}
$list[$key]["registering"] = $registering;
$list[$key]["studentsNum"] = $studentsNum; //全额缴费人数
$list[$key]["completedOfflineStep"] = $completedOfflineStep; //已缴费人数
}
}
}
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" => 100]); //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));
}
}