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.
137 lines
4.0 KiB
137 lines
4.0 KiB
<?php |
|
|
|
namespace App\Admin\Metrics\Examples; |
|
|
|
use App\Admin\Traits\DatepickerTrait; |
|
use App\Models\Config; |
|
use App\Models\SelectedDormitory; |
|
use Dcat\Admin\Widgets\Metrics\Line; |
|
use Illuminate\Http\Request; |
|
|
|
class SelectedDormitoryNewTotal extends Line |
|
{ |
|
use DatepickerTrait; |
|
|
|
/** |
|
* 初始化卡片内容 |
|
* |
|
* @return void |
|
*/ |
|
protected function init() |
|
{ |
|
parent::init(); |
|
|
|
$this->title('该时间内分配(当前年份)'); |
|
|
|
#日期选择开始 |
|
$id = $this->id(); |
|
$this->datepicker($id) |
|
->click("#{$id} .datepicker .btn-primary") |
|
->addVariables([ |
|
'datepicker' => [ |
|
'start' => date('Y-m-d', strtotime('-7 days')), |
|
'end' => date('Y-m-d', time()), |
|
] |
|
]); |
|
#日期选择结束 |
|
} |
|
|
|
/** |
|
* 处理请求 |
|
* |
|
* @param Request $request |
|
* |
|
* @return mixed|void |
|
*/ |
|
public function handle(Request $request) |
|
{ |
|
$start = $request->get('started'); |
|
$end = $request->get('ended'); |
|
|
|
//取出当前年份 |
|
$config = Config::query()->where([ |
|
"unique_identification" => "annual_session" |
|
])->first(); |
|
|
|
if(empty($start) && empty($end)){ |
|
$start = date("Y-m-d 00:00:00", strtotime('-7 days')); |
|
$end = date("Y-m-d 23:59:59", time()); |
|
//取出今日分配数 |
|
$todayNum = SelectedDormitory::query()->where([ |
|
"annual_session" => $config->data, |
|
"status" => SelectedDormitory::STATUS_YES |
|
])->whereBetween("create_time", [strtotime($start), strtotime($end)])->count(); |
|
$this->withContent($todayNum.'人'); |
|
|
|
$chart = []; |
|
$dayCount = getDateRange($start, $end); |
|
foreach($dayCount as $item){ |
|
$thisDayCount = SelectedDormitory::query()->where([ |
|
"annual_session" => $config->data, |
|
"status" => SelectedDormitory::STATUS_YES |
|
])->whereBetween("create_time", [strtotime($item." 00:00:00"), strtotime($item." 23:59:59")])->count(); |
|
$chart[] = $thisDayCount; |
|
} |
|
$this->withChart($chart); |
|
|
|
}else{ |
|
//指定时间段内注册量 |
|
$start = $start." 00:00:00"; |
|
$end = $end." 23:59:59"; |
|
$num = SelectedDormitory::query()->where([ |
|
"annual_session" => $config->data, |
|
"status" => SelectedDormitory::STATUS_YES |
|
])->whereBetween("create_time", [strtotime($start), strtotime($end)])->count(); |
|
$this->withContent($num."人"); |
|
|
|
$chart = []; |
|
$dayCount = getDateRange($start, $end); |
|
foreach($dayCount as $item){ |
|
$thisDayCount = SelectedDormitory::query()->where([ |
|
"annual_session" => $config->data, |
|
"status" => SelectedDormitory::STATUS_YES |
|
])->whereBetween("create_time", [strtotime($item." 00:00:00"), strtotime($item." 23:59:59")])->count(); |
|
$chart[] = $thisDayCount; |
|
} |
|
$this->withChart($chart); |
|
} |
|
} |
|
|
|
/** |
|
* 设置图表数据. |
|
* |
|
* @param array $data |
|
* |
|
* @return $this |
|
*/ |
|
public function withChart(array $data) |
|
{ |
|
return $this->chart([ |
|
'series' => [ |
|
[ |
|
'name' => $this->title, |
|
'data' => $data, |
|
], |
|
], |
|
]); |
|
} |
|
|
|
/** |
|
* 设置卡片内容. |
|
* |
|
* @param string $content |
|
* |
|
* @return $this |
|
*/ |
|
public function withContent($content) |
|
{ |
|
return $this->content( |
|
<<<HTML |
|
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px"> |
|
<h2 class="ml-1 font-lg-1">{$content}</h2> |
|
<span class="mb-0 mr-1 text-80">{$this->title}</span> |
|
</div> |
|
HTML |
|
); |
|
} |
|
}
|
|
|