From 474b375d69cf3e149b531718ecc2c6ddaaffad62 Mon Sep 17 00:00:00 2001 From: liyinglin Date: Thu, 23 Mar 2023 14:54:01 +0800 Subject: [PATCH] 1 --- .../Controllers/Admin/ChartController.php | 37 +++++++------------ app/Models/Visit.php | 2 +- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/app/Http/Controllers/Admin/ChartController.php b/app/Http/Controllers/Admin/ChartController.php index 410f0bc..c9635a4 100644 --- a/app/Http/Controllers/Admin/ChartController.php +++ b/app/Http/Controllers/Admin/ChartController.php @@ -2,9 +2,8 @@ namespace App\Http\Controllers\Admin; -use App\Models\Config; use App\Models\Visit; -use Illuminate\Support\Facades\DB; +use App\Models\VisitTime; use Illuminate\Support\Facades\Validator; use App\Helpers\ResponseCode; @@ -47,14 +46,11 @@ class ChartController extends CommonController $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(), - + '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(), ]; - } - return $this->success($list); } @@ -85,20 +81,16 @@ class ChartController extends CommonController 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']; + $timeList = VisitTime::orderBy('start_time','asc')->get(); $list = []; - foreach ($monthList as $item) { - $month = $all['year'] . '-' . $item; + foreach ($timeList as $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(), - + '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(), ]; - } - return $this->success($list); } @@ -134,14 +126,11 @@ class ChartController extends CommonController $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(), - + '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(), ]; - } - return $this->success($list); } diff --git a/app/Models/Visit.php b/app/Models/Visit.php index 885ce79..2ccb755 100644 --- a/app/Models/Visit.php +++ b/app/Models/Visit.php @@ -30,7 +30,7 @@ class Visit extends SoftDeletesModel public function getAuditStatusTextAttribute() { - $array = ['-1' => '待学习', '0' => '待审核', '1' => '通过', '2' => '驳回', '3' => '已进厂', '4' => '已离厂']; + $array = ['-1' => '待学习', '0' => '待审核', '1' => '通过', '2' => '驳回', '3' => '已进厂', '4' => '已离厂','5'=>'已取消']; return $array[$this->audit_status] ?? ''; }