diff --git a/app/Http/Controllers/Admin/ChartController.php b/app/Http/Controllers/Admin/ChartController.php index 65d9a82..a4951a5 100644 --- a/app/Http/Controllers/Admin/ChartController.php +++ b/app/Http/Controllers/Admin/ChartController.php @@ -51,14 +51,22 @@ class ChartController extends CommonController $list = [ 'common_visit' => [ + // 总人数 'total' => $buildQuery(1)->count(), + // 总入场人数 'enter_visit' => $buildQuery(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(), // 离厂统计 'leave_total' => $buildQuery(1)->where('audit_status', Visit::AUDIT_STATUS_LEFT)->count(), + // 总随访人数 + 'follow_total' => $buildQuery(1)->get()->sum('follw_people_total'), + // 今日总人数 + 'today_total' => $buildQuery(1)->where('date', date('Y-m-d'))->count(), + // 今日入场人数 + 'today_enter_visit' => $buildQuery(1)->where('date', date('Y-m-d'))->whereNotNull('accept_admin_sign')->count(), // 今日离厂 - 'today_leave_total' => Visit::where('type', 1)->where('date', date('Y-m-d'))->where('audit_status', Visit::AUDIT_STATUS_LEFT)->count(), + 'today_leave_total' => $buildQuery(1)->where('date', date('Y-m-d'))->where('audit_status', Visit::AUDIT_STATUS_LEFT)->count(), + // 今日随访人数 + 'today_follow_total' => $buildQuery(1)->where('date', date('Y-m-d'))->get()->sum('follw_people_total'), ], 'work_visit' => [ 'total' => $buildQuery(2)->count(), @@ -69,6 +77,10 @@ class ChartController extends CommonController 'leave_total' => $buildQuery(2)->where('audit_status', Visit::AUDIT_STATUS_LEFT)->count(), // 今日离厂 'today_leave_total' => Visit::where('type', 2)->where('date', date('Y-m-d'))->where('audit_status', Visit::AUDIT_STATUS_LEFT)->count(), + // 总随访人数 + 'follow_total' => $buildQuery(2)->get()->sum('follw_people_total'), + // 今日随访人数 + 'today_follow_total' => $buildQuery(2)->where('date', date('Y-m-d'))->get()->sum('follw_people_total'), ], 'car_visit' => [ 'total' => $buildQuery(3)->count(), @@ -79,6 +91,10 @@ class ChartController extends CommonController 'leave_total' => $buildQuery(3)->where('audit_status', Visit::AUDIT_STATUS_LEFT)->count(), // 今日离厂 'today_leave_total' => Visit::where('type', 3)->where('date', date('Y-m-d'))->where('audit_status', Visit::AUDIT_STATUS_LEFT)->count(), + // 总随访人数 + 'follow_total' => $buildQuery(3)->get()->sum('follw_people_total'), + // 今日随访人数 + 'today_follow_total' => $buildQuery(3)->where('date', date('Y-m-d'))->get()->sum('follw_people_total'), ], ]; diff --git a/app/Models/Visit.php b/app/Models/Visit.php index 48c2be2..ba3505a 100644 --- a/app/Models/Visit.php +++ b/app/Models/Visit.php @@ -32,7 +32,7 @@ class Visit extends SoftDeletesModel protected $guarded = ['id']; - protected $appends = ['type_text', 'audit_status_text', 'file_detail', 'vehicle_images_detail']; + protected $appends = ['type_text', 'audit_status_text', 'file_detail', 'vehicle_images_detail', 'follw_people_total']; protected $casts = [ 'follw_people' => 'json', @@ -51,6 +51,14 @@ class Visit extends SoftDeletesModel return Upload::whereIn('id', $this->file)->get(); } + /** + * 获取随访人数 + */ + public function getFollwPeopleTotalAttribute() + { + return $this->follw_people ? count($this->follw_people) : 0; + } + public function getVehicleImagesDetailAttribute() { if (empty($this->vehicle_images)) {