diff --git a/app/Http/Controllers/Admin/ChartController.php b/app/Http/Controllers/Admin/ChartController.php new file mode 100644 index 0000000..410f0bc --- /dev/null +++ b/app/Http/Controllers/Admin/ChartController.php @@ -0,0 +1,148 @@ +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); + } + +} diff --git a/app/Models/Visit.php b/app/Models/Visit.php index c981478..885ce79 100644 --- a/app/Models/Visit.php +++ b/app/Models/Visit.php @@ -31,7 +31,7 @@ class Visit extends SoftDeletesModel public function getAuditStatusTextAttribute() { $array = ['-1' => '待学习', '0' => '待审核', '1' => '通过', '2' => '驳回', '3' => '已进厂', '4' => '已离厂']; - return $array[$this->type] ?? ''; + return $array[$this->audit_status] ?? ''; } public function visitTime() diff --git a/routes/api.php b/routes/api.php index 38a038e..ca61677 100644 --- a/routes/api.php +++ b/routes/api.php @@ -26,6 +26,12 @@ Route::get("admin/gate/use-code", [\App\Http\Controllers\Admin\GateController::c // 后台 Route::group(["namespace" => "Admin", "prefix" => "admin", "middleware" => "sanctum.jwt:admin,rbac"], function () { + // 统计 + Route::get("chart/month", [\App\Http\Controllers\Admin\ChartController::class, "month"]); + Route::get("chart/time", [\App\Http\Controllers\Admin\ChartController::class, "time"]); + Route::get("chart/car", [\App\Http\Controllers\Admin\ChartController::class, "car"]); + + // 配置管理 Route::get("config/index", [\App\Http\Controllers\Admin\ConfigController::class, "index"]); Route::get("config/show", [\App\Http\Controllers\Admin\ConfigController::class, "show"]);