[ 'total' => Visit::where('type', 1)->count(), 'enter_visit' => Visit::where('type', 1)->whereNotNull('accept_admin_sign')->count(), 'today_total' => Visit::where('type', 1)->where('date', date('Y-m-d'))->count(), 'today_enter_visit' => Visit::where('type', 1)->where('date', date('Y-m-d'))->whereNotNull('accept_admin_sign')->count(), ], 'work_visit' => [ 'total' => Visit::where('type', 2)->count(), 'enter_visit' => Visit::where('type', 2)->whereNotNull('accept_admin_sign')->count(), 'today_total' => Visit::where('type', 2)->where('date', date('Y-m-d'))->count(), 'today_enter_visit' => Visit::where('type', 2)->where('date', date('Y-m-d'))->whereNotNull('accept_admin_sign')->count(), ], 'car_visit' => [ 'total' => Visit::where('type', 3)->count(), 'enter_visit' => Visit::where('type', 3)->whereNotNull('accept_admin_sign')->count(), 'today_total' => Visit::where('type', 3)->where('date', date('Y-m-d'))->count(), 'today_enter_visit' => Visit::where('type', 3)->where('date', date('Y-m-d'))->whereNotNull('accept_admin_sign')->count(), ], ]; $startDate = date('Y-m-d', strtotime('-30 day', time())); $dateList = getDateFromRange($startDate, date('Y-m-d')); $all_date_list = []; foreach ($dateList as &$item) { $allDateList[] = [ 'date' => $item, 'common_visit' => Visit::where('type', 1)->where('date', $item)->count(), 'work_visit' => Visit::where('type', 2)->where('date', $item)->count(), 'car_visit' => Visit::where('type', 3)->where('date', $item)->count(), ]; } return $this->success(compact('list', 'all_date_list')); } /** * @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="is_export", in="query", @OA\Schema(type="string"), required=false, description="是否导出0否1是,默认0"), * @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}%")->where('audit_status', 5)->count(), ]; } 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); } } /** * @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="is_export", in="query", @OA\Schema(type="string"), required=false, description="是否导出0否1是,默认0"), * @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())]); } $timeList = VisitTime::orderBy('start_time', 'asc')->get(); $list = []; foreach ($timeList as $item) { $list[] = [ '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(), ]; } 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); } } /** * @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="is_export", in="query", @OA\Schema(type="string"), required=false, description="是否导出0否1是,默认0"), * @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('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(), ]; } 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); } } }