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.

179 lines
7.1 KiB

3 years ago
<?php
namespace App\Http\Controllers\Admin;
use App\Models\Visit;
3 years ago
use App\Models\VisitTime;
3 years ago
use Illuminate\Support\Facades\Validator;
use App\Helpers\ResponseCode;
3 years ago
use Rap2hpoutre\FastExcel\FastExcel;
3 years ago
/**
* 配置
*/
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"),
3 years ago
* @OA\Parameter(name="is_export", in="query", @OA\Schema(type="string"), required=false, description="是否导出0否1是默认0"),
3 years ago
* @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,
3 years ago
'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}%")->where('audit_status', 5)->count(),
3 years ago
];
}
3 years ago
if (isset($all['is_export']) && !empty($all['is_export'])) {
return (new FastExcel($list))->download('月度统计' . date('YmdHis') . '.csv', function ($info) {
return [
'月份' => $info['month'],
'预约人数' => $info['plan_total'],
'入场人数' => $info['enter_total'],
'取消人数' => $info['cancel_total'],
'核销比' => $info['enter_total'] / $info['plan_total'] * 100
];
});
} else {
return $this->success($list);
}
3 years ago
}
/**
* @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"),
3 years ago
* @OA\Parameter(name="is_export", in="query", @OA\Schema(type="string"), required=false, description="是否导出0否1是默认0"),
3 years ago
* @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())]);
}
3 years ago
$timeList = VisitTime::orderBy('start_time', 'asc')->get();
3 years ago
$list = [];
3 years ago
foreach ($timeList as $item) {
3 years ago
$list[] = [
3 years ago
'time' => $item->start_time . '-' . $item->end_time,
'plan_total' => Visit::where('date', $all['date'])->where('visit_time_id', $item->id)->count(),
'enter_total' => Visit::where('date', $all['date'])->where('visit_time_id', $item->id)->whereNotNull('accept_admin_sign')->count(),
'cancel_total' => Visit::where('date', $all['date'])->where('visit_time_id', $item->id)->where('audit_status', 5)->count(),
3 years ago
];
}
3 years ago
if (isset($all['is_export']) && !empty($all['is_export'])) {
return (new FastExcel($list))->download('车辆统计' . date('YmdHis') . '.csv', function ($info) {
return [
'时间段' => $info['time'],
'预约人数' => $info['plan_total'],
'入场人数' => $info['enter_total'],
'取消人数' => $info['cancel_total'],
'核销比' => $info['enter_total'] / $info['plan_total'] * 100
];
});
} else {
return $this->success($list);
}
3 years ago
}
/**
* @OA\Get(
* path="/api/admin/chart/car",
* tags={"图表"},
* summary="车辆统计",
* description="",
* @OA\Parameter(name="year", in="query", @OA\Schema(type="string"), required=true, description="年份例如2022"),
3 years ago
* @OA\Parameter(name="is_export", in="query", @OA\Schema(type="string"), required=false, description="是否导出0否1是默认0"),
3 years ago
* @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,
3 years ago
'plan_total' => Visit::where('type', 3)->where('date', 'like', "%{$month}%")->count(),
'enter_total' => Visit::where('type', 3)->where('date', 'like', "%{$month}%")->whereNotNull('accept_admin_sign')->count(),
'cancel_total' => Visit::where('type', 3)->where('date', 'like', "%{$month}%")->where('audit_status', 5)->count(),
3 years ago
];
}
3 years ago
if (isset($all['is_export']) && !empty($all['is_export'])) {
return (new FastExcel($list))->download('车辆统计' . date('YmdHis') . '.csv', function ($info) {
return [
'月份' => $info['month'],
'预约车辆数' => $info['plan_total'],
'入场车辆数' => $info['enter_total'],
'取消车辆数' => $info['cancel_total'],
'核销比' => $info['enter_total'] / $info['plan_total'] * 100
];
});
} else {
return $this->success($list);
}
3 years ago
}
}