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.

149 lines
4.9 KiB

3 years ago
<?php
namespace App\Http\Controllers\Admin;
use App\Models\Config;
use App\Models\Visit;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
use App\Helpers\ResponseCode;
/**
* 配置
*/
class ChartController extends CommonController
{
/**
* @OA\Get(
* path="/api/admin/chart/month",
* tags={"图表"},
* summary="月度统计",
* description="",
* @OA\Parameter(name="year", in="query", @OA\Schema(type="string"), required=true, description="年份例如2022"),
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Response(
* response="200",
* description="暂无"
* )
* )
*/
public function month()
{
$all = \request()->all();
$messages = [
'year.required' => '年份必填',
];
$validator = Validator::make($all, [
'year' => 'required'
], $messages);
if ($validator->fails()) {
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
}
$monthList = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
$list = [];
foreach ($monthList as $item) {
$month = $all['year'] . '-' . $item;
$list[] = [
'month' => $month,
'plan_total'=>Visit::where('date','like',"%{$month}%")->count(),
'enter_total'=>Visit::where('date','like',"%{$month}%")->whereNotNull('accept_admin_sign')->count(),
'cancel_total'=>Visit::where('date','like',"%{$month}%")->whereNotNull('accept_admin_sign')->count(),
];
}
return $this->success($list);
}
/**
* @OA\Get(
* path="/api/admin/chart/time",
* tags={"图表"},
* summary="时段统计",
* description="",
* @OA\Parameter(name="date", in="query", @OA\Schema(type="string"), required=true, description="日期例如2022=01=01"),
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Response(
* response="200",
* description="暂无"
* )
* )
*/
public function time()
{
$all = \request()->all();
$messages = [
'date.required' => '时段必填',
];
$validator = Validator::make($all, [
'date' => 'required'
], $messages);
if ($validator->fails()) {
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
}
$monthList = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
$list = [];
foreach ($monthList as $item) {
$month = $all['year'] . '-' . $item;
$list[] = [
'month' => $month,
'plan_total'=>Visit::where('date','like',"%{$month}%")->count(),
'enter_total'=>Visit::where('date','like',"%{$month}%")->whereNotNull('accept_admin_sign')->count(),
'cancel_total'=>Visit::where('date','like',"%{$month}%")->whereNotNull('accept_admin_sign')->count(),
];
}
return $this->success($list);
}
/**
* @OA\Get(
* path="/api/admin/chart/car",
* tags={"图表"},
* summary="车辆统计",
* description="",
* @OA\Parameter(name="year", in="query", @OA\Schema(type="string"), required=true, description="年份例如2022"),
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Response(
* response="200",
* description="暂无"
* )
* )
*/
public function car()
{
$all = \request()->all();
$messages = [
'year.required' => '年份必填',
];
$validator = Validator::make($all, [
'year' => 'required'
], $messages);
if ($validator->fails()) {
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
}
$monthList = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
$list = [];
foreach ($monthList as $item) {
$month = $all['year'] . '-' . $item;
$list[] = [
'month' => $month,
'plan_total'=>Visit::where('date','like',"%{$month}%")->count(),
'enter_total'=>Visit::where('date','like',"%{$month}%")->whereNotNull('accept_admin_sign')->count(),
'cancel_total'=>Visit::where('date','like',"%{$month}%")->whereNotNull('accept_admin_sign')->count(),
];
}
return $this->success($list);
}
}