From d8d790f96e628caf4b789e68861ae6e0ba038213 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Mon, 24 Mar 2025 13:57:06 +0800 Subject: [PATCH 01/14] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E5=9B=9E=E6=94=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/CustomerController.php | 83 +++++++++++++++++---------- 1 file changed, 54 insertions(+), 29 deletions(-) diff --git a/app/controller/CustomerController.php b/app/controller/CustomerController.php index 2ce3c6c..500ce30 100644 --- a/app/controller/CustomerController.php +++ b/app/controller/CustomerController.php @@ -68,9 +68,9 @@ class CustomerController $page = $request->input('page', 1); $perPage = $request->input('per_page', 10); - $follow = $request->input('follow',''); //跟进状态 - $keyword = $request->input('keyword',''); //follow_last - $follow_last = $request->input('follow_last',''); //最后跟进:1:当天跟进客户,2:近三天跟进客户,3:近七天跟进客户 + $follow = $request->input('follow', ''); //跟进状态 + $keyword = $request->input('keyword', ''); //follow_last + $follow_last = $request->input('follow_last', ''); //最后跟进:1:当天跟进客户,2:近三天跟进客户,3:近七天跟进客户 $where = []; @@ -78,30 +78,29 @@ class CustomerController if (Util::isEmpty($userId)) { return Util::fail(['user_id' => $userId], trans('user_none')); } - $where[] =['user_id',$userId] ; + $where[] = ['user_id', $userId]; //验证权限 // if ($request->user['role'] != 1) { // $where[] =['user_id',$userId] ; // } $grade = []; if (!Util::isEmpty($follow) && $follow == 0) { - $where[] = ['grade','<=', 2]; + $where[] = ['grade', '<=', 2]; } elseif (!Util::isEmpty($follow) && $follow == 1) { - $grade = [3, 4]; + $grade = [3, 4]; } elseif (!Util::isEmpty($follow) && $follow == 2) { - $where[] = ['grade','=', 5]; + $where[] = ['grade', '=', 5]; } if (!Util::isEmpty($follow_last) && $follow_last == 0) { - $where[] = ['follow_last','>', strtotime('-1 day')]; - }elseif (!Util::isEmpty($follow_last) && $follow_last == 1) { - $where[] = ['follow_last','>', strtotime('-3 day')]; - }elseif (!Util::isEmpty($follow_last) && $follow_last == 2) { - $where[] = ['follow_last','>', strtotime('-7 day')]; + $where[] = ['follow_last', '>', strtotime('-1 day')]; + } elseif (!Util::isEmpty($follow_last) && $follow_last == 1) { + $where[] = ['follow_last', '>', strtotime('-3 day')]; + } elseif (!Util::isEmpty($follow_last) && $follow_last == 2) { + $where[] = ['follow_last', '>', strtotime('-7 day')]; } - // 执行分页查询 $query = Customer::where($where) ->orderBy('id', 'desc'); @@ -116,7 +115,12 @@ class CustomerController $query->whereIn('grade', $grade); } -// return Util::success($query->toSql().serialize($where),$follow); + + $recycle = Util::getParam('recycle', ''); + if ($recycle == 'recycle') { + $query->onlyTrashed(); + } + $data = $query->paginate($perPage, ['*'], 'page', $page); foreach ($data->items() as &$value) { @@ -126,6 +130,27 @@ class CustomerController return Util::page($data); } + + /** + * 客户恢复 + * @param Request $request + * @return \support\Response + */ + public function restore(Request $request) + { + $id = Util::getParam('id', ''); + if (Util::isEmpty($id)) { + return Util::fail([], trans('id_empty')); + } + $where = ['id' => $id]; + $res = Customer::where($where)->restore(); + if($res){ + return Util::success($res, trans('success')); + }else{ + return Util::fail([], trans('fail')); + } + } + /** * 客户详情 * @param Request $request @@ -176,7 +201,7 @@ class CustomerController $email = Util::getParam($request, 'email'); $phone = Util::getParam($request, 'phone'); if (Util::isEmpty($contacts) && Util::isEmpty($email) && Util::isEmpty($phone)) { - return Util::fail([], trans('contacts_not_null')); + return Util::fail([], trans('contacts_not_null')); } $data = [ @@ -259,7 +284,7 @@ class CustomerController ]; $res = Customer::where('id', $id) - ->update($data); + ->update($data); if ($res) { return Util::success($res, trans('save_success')); @@ -298,19 +323,19 @@ class CustomerController } $userId = $request->user['id']; $created_at = $request->user['created_at']; - $day = ceil((time()-$created_at+1)/60/60/24); + $day = ceil((time() - $created_at + 1) / 60 / 60 / 24); $where[] = ['user_id', '=', $userId]; - $start = strtotime($created.'-01'); + $start = strtotime($created . '-01'); $year = date('Y', $start); - $month = date('n',$start); //获取月份 - $end = mktime(00, 00, 00, $month+1, 1, $year); + $month = date('n', $start); //获取月份 + $end = mktime(00, 00, 00, $month + 1, 1, $year); $where[] = ['created_at', '>=', $start]; $where[] = ['created_at', '<', $end]; $customer = Customer::where($where)->count(); //初步接触 $whereGrade = $where; - $whereGrade[] = ['grade','<=', 2]; + $whereGrade[] = ['grade', '<=', 2]; $customerInit = Customer::where($whereGrade)->count(); //跟进中 @@ -318,7 +343,7 @@ class CustomerController //已成交 $whereGrade = $where; - $whereGrade[] = ['grade','=', 5]; + $whereGrade[] = ['grade', '=', 5]; $customerDeal = Customer::where($whereGrade)->count(); //拜访数 @@ -332,13 +357,13 @@ class CustomerController $follow = Follow::where($whereVisit)->distinct('customer_id')->count(); $res = [ - 'customer'=>$customer, //客户数 - 'visit'=>$visit, //拜访 - 'follow'=>$follow, //跟进 - 'day'=>$day, //注册天数 - 'customer_init'=>$customerInit, //初步接触 - 'customero_fllow'=>$customeroFllow, //跟进中 - 'customer_deal'=>$customerDeal, //已成交 + 'customer' => $customer, //客户数 + 'visit' => $visit, //拜访 + 'follow' => $follow, //跟进 + 'day' => $day, //注册天数 + 'customer_init' => $customerInit, //初步接触 + 'customero_fllow' => $customeroFllow, //跟进中 + 'customer_deal' => $customerDeal, //已成交 ]; if ($res) { return Util::success($res, trans('success')); From d14945e54649b06ed3034c4cae5054933339eca0 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Mon, 24 Mar 2025 14:48:29 +0800 Subject: [PATCH 02/14] 1 --- app/controller/CustomerController.php | 73 +++++++++++++++++---------- 1 file changed, 45 insertions(+), 28 deletions(-) diff --git a/app/controller/CustomerController.php b/app/controller/CustomerController.php index 2ce3c6c..674752e 100644 --- a/app/controller/CustomerController.php +++ b/app/controller/CustomerController.php @@ -58,6 +58,24 @@ class CustomerController } + /** + * 待跟进客户列表 + * @param Request $request + * @return \support\Response + */ + public function waitFollow(Request $request) + { + $userId = $request->user['id']; + $where = [ + ['user_id', '=', $userId], +// ['follow_next', '<=', time() + 3600 * 24], + ['follow_next', '>', time()], + ['warn', '<', 1] + ]; + $customer = Customer::where($where)->orderBy('follow_next')->get(); + return Util::success($customer,trans('success')); + } + /** * 客户列表 * @param Request $request @@ -68,9 +86,9 @@ class CustomerController $page = $request->input('page', 1); $perPage = $request->input('per_page', 10); - $follow = $request->input('follow',''); //跟进状态 - $keyword = $request->input('keyword',''); //follow_last - $follow_last = $request->input('follow_last',''); //最后跟进:1:当天跟进客户,2:近三天跟进客户,3:近七天跟进客户 + $follow = $request->input('follow', ''); //跟进状态 + $keyword = $request->input('keyword', ''); //follow_last + $follow_last = $request->input('follow_last', ''); //最后跟进:1:当天跟进客户,2:近三天跟进客户,3:近七天跟进客户 $where = []; @@ -78,30 +96,29 @@ class CustomerController if (Util::isEmpty($userId)) { return Util::fail(['user_id' => $userId], trans('user_none')); } - $where[] =['user_id',$userId] ; + $where[] = ['user_id', $userId]; //验证权限 // if ($request->user['role'] != 1) { // $where[] =['user_id',$userId] ; // } $grade = []; if (!Util::isEmpty($follow) && $follow == 0) { - $where[] = ['grade','<=', 2]; + $where[] = ['grade', '<=', 2]; } elseif (!Util::isEmpty($follow) && $follow == 1) { - $grade = [3, 4]; + $grade = [3, 4]; } elseif (!Util::isEmpty($follow) && $follow == 2) { - $where[] = ['grade','=', 5]; + $where[] = ['grade', '=', 5]; } if (!Util::isEmpty($follow_last) && $follow_last == 0) { - $where[] = ['follow_last','>', strtotime('-1 day')]; - }elseif (!Util::isEmpty($follow_last) && $follow_last == 1) { - $where[] = ['follow_last','>', strtotime('-3 day')]; - }elseif (!Util::isEmpty($follow_last) && $follow_last == 2) { - $where[] = ['follow_last','>', strtotime('-7 day')]; + $where[] = ['follow_last', '>', strtotime('-1 day')]; + } elseif (!Util::isEmpty($follow_last) && $follow_last == 1) { + $where[] = ['follow_last', '>', strtotime('-3 day')]; + } elseif (!Util::isEmpty($follow_last) && $follow_last == 2) { + $where[] = ['follow_last', '>', strtotime('-7 day')]; } - // 执行分页查询 $query = Customer::where($where) ->orderBy('id', 'desc'); @@ -176,7 +193,7 @@ class CustomerController $email = Util::getParam($request, 'email'); $phone = Util::getParam($request, 'phone'); if (Util::isEmpty($contacts) && Util::isEmpty($email) && Util::isEmpty($phone)) { - return Util::fail([], trans('contacts_not_null')); + return Util::fail([], trans('contacts_not_null')); } $data = [ @@ -259,7 +276,7 @@ class CustomerController ]; $res = Customer::where('id', $id) - ->update($data); + ->update($data); if ($res) { return Util::success($res, trans('save_success')); @@ -298,19 +315,19 @@ class CustomerController } $userId = $request->user['id']; $created_at = $request->user['created_at']; - $day = ceil((time()-$created_at+1)/60/60/24); + $day = ceil((time() - $created_at + 1) / 60 / 60 / 24); $where[] = ['user_id', '=', $userId]; - $start = strtotime($created.'-01'); + $start = strtotime($created . '-01'); $year = date('Y', $start); - $month = date('n',$start); //获取月份 - $end = mktime(00, 00, 00, $month+1, 1, $year); + $month = date('n', $start); //获取月份 + $end = mktime(00, 00, 00, $month + 1, 1, $year); $where[] = ['created_at', '>=', $start]; $where[] = ['created_at', '<', $end]; $customer = Customer::where($where)->count(); //初步接触 $whereGrade = $where; - $whereGrade[] = ['grade','<=', 2]; + $whereGrade[] = ['grade', '<=', 2]; $customerInit = Customer::where($whereGrade)->count(); //跟进中 @@ -318,7 +335,7 @@ class CustomerController //已成交 $whereGrade = $where; - $whereGrade[] = ['grade','=', 5]; + $whereGrade[] = ['grade', '=', 5]; $customerDeal = Customer::where($whereGrade)->count(); //拜访数 @@ -332,13 +349,13 @@ class CustomerController $follow = Follow::where($whereVisit)->distinct('customer_id')->count(); $res = [ - 'customer'=>$customer, //客户数 - 'visit'=>$visit, //拜访 - 'follow'=>$follow, //跟进 - 'day'=>$day, //注册天数 - 'customer_init'=>$customerInit, //初步接触 - 'customero_fllow'=>$customeroFllow, //跟进中 - 'customer_deal'=>$customerDeal, //已成交 + 'customer' => $customer, //客户数 + 'visit' => $visit, //拜访 + 'follow' => $follow, //跟进 + 'day' => $day, //注册天数 + 'customer_init' => $customerInit, //初步接触 + 'customero_fllow' => $customeroFllow, //跟进中 + 'customer_deal' => $customerDeal, //已成交 ]; if ($res) { return Util::success($res, trans('success')); From fc1825a1c79228c55b201ebf236bd445e477d990 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Tue, 25 Mar 2025 09:10:31 +0800 Subject: [PATCH 03/14] =?UTF-8?q?=E7=99=BB=E5=BD=95=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/middleware/AuthMiddleware.php | 11 +++++++++-- resource/translations/en/messages.php | 1 + resource/translations/zh_CN/messages.php | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/middleware/AuthMiddleware.php b/app/middleware/AuthMiddleware.php index 8c96a0d..8306cc3 100644 --- a/app/middleware/AuthMiddleware.php +++ b/app/middleware/AuthMiddleware.php @@ -54,11 +54,15 @@ class AuthMiddleware implements MiddlewareInterface // 从 Header 获取 Token $token = $request->header('Authorization'); + $language = Util::getParam($request, 'language'); + $language = $language=='zh_CN'?:'en'; //需要登录并且未提供token if ($isLogin && (!$token || !str_starts_with($token, 'Bearer '))) { - return Util::fail('','请先登录',401); + locale($language); + return Util::fail('',trans('user_login'),401); // throw new BusinessException('未提供 Token'.$isLogin, 401); }elseif(!$isLogin){ + locale($language); return $handler($request); } @@ -68,8 +72,11 @@ class AuthMiddleware implements MiddlewareInterface // 验证 Token 并获取用户ID $decoded = JwtUtil::verifyToken($token); - $userId = $decoded->sub; + if (!isset($decoded->sub)) { + return Util::fail('', trans('user_login'),401); + } + $userId = $decoded->sub; $user = User::select(['id','name','sex','role','avatar','email','password','language','created_at']) ->find($userId); if(!$user){ diff --git a/resource/translations/en/messages.php b/resource/translations/en/messages.php index dffe5e5..b88fa5f 100644 --- a/resource/translations/en/messages.php +++ b/resource/translations/en/messages.php @@ -6,6 +6,7 @@ return [ 'login_success' => ' login success', 'password_error' => ' password error', 'user_none' => ' user none', + 'user_login' => ' Please log in first', 'not_null' => ' not null', 'code_error' => ' code error', 'format_error' => ' format error', diff --git a/resource/translations/zh_CN/messages.php b/resource/translations/zh_CN/messages.php index 09ede6c..285ec25 100644 --- a/resource/translations/zh_CN/messages.php +++ b/resource/translations/zh_CN/messages.php @@ -6,6 +6,7 @@ return [ 'login_success' => ' 登录成功', 'password_error' => ' 密码错误', 'user_none' => ' 用户不存在', + 'user_login' => ' 请先登录', 'not_null' => ' 不能为空', 'code_error' => ' 验证码错误', 'format_error' => ' 格式错误', From cef8472965fb1bbf71236725def4f9ea18a767cc Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Tue, 25 Mar 2025 10:26:17 +0800 Subject: [PATCH 04/14] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E5=9B=9E=E6=94=B6?= =?UTF-8?q?=E7=AB=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/CustomerController.php | 28 +++++++++++++++++++----- resource/translations/en/messages.php | 1 + resource/translations/zh_CN/messages.php | 1 + 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/controller/CustomerController.php b/app/controller/CustomerController.php index 500ce30..a03d57b 100644 --- a/app/controller/CustomerController.php +++ b/app/controller/CustomerController.php @@ -116,7 +116,7 @@ class CustomerController } - $recycle = Util::getParam('recycle', ''); + $recycle = Util::getParam($request,'recycle', ''); if ($recycle == 'recycle') { $query->onlyTrashed(); } @@ -138,11 +138,15 @@ class CustomerController */ public function restore(Request $request) { - $id = Util::getParam('id', ''); + $id = Util::getParam($request,'id', ''); if (Util::isEmpty($id)) { return Util::fail([], trans('id_empty')); } - $where = ['id' => $id]; + $userId = $request->user['id']; + $where = [ + 'id' => $id, + 'user_id' => $userId, + ]; $res = Customer::where($where)->restore(); if($res){ return Util::success($res, trans('success')); @@ -301,8 +305,22 @@ class CustomerController public function delete(Request $request) { $id = Util::getParam($request, 'id'); - $customer = Customer::where('id', $id)->first(); - $res = $customer->delete(); + $force = Util::getParam($request, 'force',''); + + $userId = $request->user['id']; + $where = [ + 'id' => $id, + 'user_id' => $userId, + ]; + $customer = Customer::where($where)->withTrashed()->first(); + if(empty($customer)){ + return Util::fail('', trans('fail')); + } + if($force == 'force'){ + $res = $customer->forceDelete(); + }else{ + $res = $customer->delete(); + } if ($res) { return Util::success($res, trans('success')); } else { diff --git a/resource/translations/en/messages.php b/resource/translations/en/messages.php index dffe5e5..9dff699 100644 --- a/resource/translations/en/messages.php +++ b/resource/translations/en/messages.php @@ -26,4 +26,5 @@ return [ 'email_consistent' => ' Inconsistent email addresses', 'sign_not_null' => ' No affiliated company has been set', 'password_short' => ' Password cannot be less than 6 characters', + 'id_empty' => ' ID cannot be empty', ]; \ No newline at end of file diff --git a/resource/translations/zh_CN/messages.php b/resource/translations/zh_CN/messages.php index 09ede6c..75cb7cd 100644 --- a/resource/translations/zh_CN/messages.php +++ b/resource/translations/zh_CN/messages.php @@ -26,4 +26,5 @@ return [ 'email_consistent' => ' 邮箱不一致', 'sign_not_null' => ' 未设置所属公司', 'password_short' => ' 密码不能少于6位', + 'id_empty' => ' id不能为空', ]; \ No newline at end of file From 68eb23e3163f368db38f09ba18656612d1ba0d8c Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Tue, 25 Mar 2025 13:42:24 +0800 Subject: [PATCH 05/14] =?UTF-8?q?=E5=BE=85=E8=B7=9F=E8=BF=9B=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/CustomerController.php | 11 ++++++++--- app/controller/FollowController.php | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/controller/CustomerController.php b/app/controller/CustomerController.php index 674752e..bab9349 100644 --- a/app/controller/CustomerController.php +++ b/app/controller/CustomerController.php @@ -68,11 +68,16 @@ class CustomerController $userId = $request->user['id']; $where = [ ['user_id', '=', $userId], + ['follow_next', '<>', 0], // ['follow_next', '<=', time() + 3600 * 24], - ['follow_next', '>', time()], - ['warn', '<', 1] +// ['follow_next', '>', time()], +// ['warn', '<', 1] ]; - $customer = Customer::where($where)->orderBy('follow_next')->get(); + $customer = Customer::where($where)->whereNotNull('follow_next')->orderBy('follow_next')->get(); + + foreach ($customer as &$item) { + $item['follow_remaining'] = $item->follow_next-time(); + } return Util::success($customer,trans('success')); } diff --git a/app/controller/FollowController.php b/app/controller/FollowController.php index c4bd59a..c92e599 100644 --- a/app/controller/FollowController.php +++ b/app/controller/FollowController.php @@ -146,6 +146,8 @@ class FollowController $customer = Customer::find($customer_id); $customer->follow_last = strtotime($res->created_at); + $customer->follow_next = null; + $customer->warn = 0; $customer->save(); if ($res) { From d5c9d1a7a5b64b0f46e00f98727c88c45f652015 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Tue, 25 Mar 2025 13:45:35 +0800 Subject: [PATCH 06/14] =?UTF-8?q?=E9=80=9A=E7=9F=A5=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/CustomerController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controller/CustomerController.php b/app/controller/CustomerController.php index bab9349..dbb1f31 100644 --- a/app/controller/CustomerController.php +++ b/app/controller/CustomerController.php @@ -278,6 +278,7 @@ class CustomerController $data = [ 'follow_next' => Util::getParam($request, 'follow_next', 0), 'follow_remark' => Util::getParam($request, 'follow_remark', 0), + 'warn' => 0, ]; $res = Customer::where('id', $id) From 23ffdab0f640612f4198e3986ea829a930b105d7 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Tue, 25 Mar 2025 14:25:16 +0800 Subject: [PATCH 07/14] =?UTF-8?q?=E4=B8=8B=E6=AC=A1=E8=B7=9F=E8=BF=9B?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/CustomerController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controller/CustomerController.php b/app/controller/CustomerController.php index dbb1f31..b1c9e14 100644 --- a/app/controller/CustomerController.php +++ b/app/controller/CustomerController.php @@ -77,6 +77,7 @@ class CustomerController foreach ($customer as &$item) { $item['follow_remaining'] = $item->follow_next-time(); + $item['follow_next'] = date('Y-m-d H:i:s',$item->follow_next); } return Util::success($customer,trans('success')); } From 8cbf82fb2d95fa89ece30f81bb2fe5858cf1c86b Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Wed, 26 Mar 2025 09:50:10 +0800 Subject: [PATCH 08/14] =?UTF-8?q?=E7=AD=9B=E9=80=89=E8=B7=9F=E8=BF=9B?= =?UTF-8?q?=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/CustomerController.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/app/controller/CustomerController.php b/app/controller/CustomerController.php index b1c9e14..b19d9cb 100644 --- a/app/controller/CustomerController.php +++ b/app/controller/CustomerController.php @@ -66,20 +66,31 @@ class CustomerController public function waitFollow(Request $request) { $userId = $request->user['id']; + $filter = Util::getParam($request, 'filter'); + $page = $request->input('page', 1); + $perPage = $request->input('per_page', 10); $where = [ ['user_id', '=', $userId], ['follow_next', '<>', 0], -// ['follow_next', '<=', time() + 3600 * 24], -// ['follow_next', '>', time()], -// ['warn', '<', 1] ]; - $customer = Customer::where($where)->whereNotNull('follow_next')->orderBy('follow_next')->get(); + + if($filter == 0){ + $where[] = ['follow_next', '<=', time() + 3600 * 24]; + }elseif($filter == 1){ + $where[] = ['follow_next', '<=', time() + 3600 * 24*3]; + }elseif($filter == 2){ + $where[] = ['follow_next', '<=', time() + 3600 * 24*7]; + } + $customer = Customer::where($where) + ->whereNotNull('follow_next') + ->orderBy('follow_next') + ->paginate($perPage, ['*'], 'page', $page); foreach ($customer as &$item) { $item['follow_remaining'] = $item->follow_next-time(); $item['follow_next'] = date('Y-m-d H:i:s',$item->follow_next); } - return Util::success($customer,trans('success')); + return Util::page($customer); } /** From d511b2fdb51342cb92bdc9936d6f371153551ef6 Mon Sep 17 00:00:00 2001 From: ylyg5690 Date: Wed, 26 Mar 2025 09:56:52 +0800 Subject: [PATCH 09/14] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=A4=B4=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/UserController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controller/UserController.php b/app/controller/UserController.php index e225579..a1fb4ff 100644 --- a/app/controller/UserController.php +++ b/app/controller/UserController.php @@ -154,7 +154,7 @@ class UserController 'role' => 1, 'password' => $hashedPassword, 'status' => 0, - 'avatar' => 'lingke_crm/lingke.png' + 'avatar' => 'lingke_crm/logo.png' ]; From 90ec9a7ad84a04525286ac851811acdcb93cc869 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Wed, 26 Mar 2025 14:07:29 +0800 Subject: [PATCH 10/14] =?UTF-8?q?=E5=9B=BE=E7=89=87=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/UploadController.php | 2 +- config/process.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controller/UploadController.php b/app/controller/UploadController.php index f13ec13..b080a21 100644 --- a/app/controller/UploadController.php +++ b/app/controller/UploadController.php @@ -115,7 +115,7 @@ class UploadController } $result = Storage::adapter('oss') - ->path('vehicle_album/'.date('Ymd')) + ->path('lingke_crm/'.date('Ymd')) ->size(1024*1024*5) ->extYes(['image/jpeg','image/png']) ->extNo(['image/gif']) diff --git a/config/process.php b/config/process.php index fb2d3f1..d093e40 100644 --- a/config/process.php +++ b/config/process.php @@ -22,7 +22,7 @@ return [ 'webman' => [ 'handler' => Http::class, 'listen' => getenv('WEBMAN_LISTEN'), - 'count' => cpu_count() * 1, + 'count' => 8, 'user' => '', 'group' => '', 'reusePort' => false, From 6e79dd47c45be922190745c864d460434b483e19 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Wed, 26 Mar 2025 17:13:11 +0800 Subject: [PATCH 11/14] =?UTF-8?q?=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/TagGroupController.php | 33 +++++++++++++++++ app/model/Tag.php | 51 +++++++++++++++++++++++++++ app/model/TagGroup.php | 50 ++++++++++++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 app/controller/TagGroupController.php create mode 100644 app/model/Tag.php create mode 100644 app/model/TagGroup.php diff --git a/app/controller/TagGroupController.php b/app/controller/TagGroupController.php new file mode 100644 index 0000000..04a7d9d --- /dev/null +++ b/app/controller/TagGroupController.php @@ -0,0 +1,33 @@ +get(); + $languageArr = config('translation.fallback_locale'); + $language = $request->user['language']; + foreach ($list as &$item) { + $item['names'] = unserialize($item['names']); + if(in_array($language, $languageArr)){ + $item['name'] = $item['names'][$language]; + } + foreach ($item['tags'] as &$tag) { + $tag['names'] = unserialize($tag['names']); + if(in_array($language, $languageArr)){ + $item['name'] = $item['names'][$language]; + } + } + } + + return Util::success($list); + } +} \ No newline at end of file diff --git a/app/model/Tag.php b/app/model/Tag.php new file mode 100644 index 0000000..2c4c541 --- /dev/null +++ b/app/model/Tag.php @@ -0,0 +1,51 @@ +belongsTo(TagGroup::class, 'group_id', 'id'); + } + +} \ No newline at end of file diff --git a/app/model/TagGroup.php b/app/model/TagGroup.php new file mode 100644 index 0000000..fbba597 --- /dev/null +++ b/app/model/TagGroup.php @@ -0,0 +1,50 @@ +hasMany(Tag::class, 'group_id', 'id'); + } +} \ No newline at end of file From aff152e40d04637faacfafd988a6b23720b43cbf Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Thu, 27 Mar 2025 11:13:46 +0800 Subject: [PATCH 12/14] =?UTF-8?q?=E6=A0=87=E7=AD=BE=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/CustomerController.php | 6 ++-- app/controller/TagGroupController.php | 36 ++++++++++++++++++++++-- app/model/Customer.php | 9 ++++++ app/model/CustomerTag.php | 36 ++++++++++++++++++++++++ app/model/Tag.php | 4 +++ resource/translations/en/messages.php | 2 ++ resource/translations/zh_CN/messages.php | 2 ++ 7 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 app/model/CustomerTag.php diff --git a/app/controller/CustomerController.php b/app/controller/CustomerController.php index b032c9b..f7da53f 100644 --- a/app/controller/CustomerController.php +++ b/app/controller/CustomerController.php @@ -144,8 +144,8 @@ class CustomerController } - // 执行分页查询 - $query = Customer::where($where) + // 执行分页查询 //关联标签tags //关联标签及分组tags.group + $query = Customer::with('tags')->where($where) ->orderBy('id', 'desc'); if (!Util::isEmpty($keyword)) { $query->where(function ($query) use ($keyword) { @@ -210,7 +210,7 @@ class CustomerController return Util::fail([], 'id' . trans('not_null')); } - $res = Customer::select('id', 'user_id', 'grade', 'channel_id', 'car_type_id', 'country_id', 'magnitude', 'email', 'phone', 'WhatsApp', 'contacts', 'describe', 'address', 'lat', 'lng', 'follow_next', 'follow_remark', 'sex') + $res = Customer::with('tags')->select('id', 'user_id', 'grade', 'channel_id', 'car_type_id', 'country_id', 'magnitude', 'email', 'phone', 'WhatsApp', 'contacts', 'describe', 'address', 'lat', 'lng', 'follow_next', 'follow_remark', 'sex') ->where('id', $id) ->first(); if ($res) { diff --git a/app/controller/TagGroupController.php b/app/controller/TagGroupController.php index 04a7d9d..7edb77a 100644 --- a/app/controller/TagGroupController.php +++ b/app/controller/TagGroupController.php @@ -2,6 +2,7 @@ namespace app\controller; +use app\model\CustomerTag; use app\model\TagGroup; use app\util\Util; use support\Request; @@ -17,12 +18,12 @@ class TagGroupController $language = $request->user['language']; foreach ($list as &$item) { $item['names'] = unserialize($item['names']); - if(in_array($language, $languageArr)){ + if (in_array($language, $languageArr)) { $item['name'] = $item['names'][$language]; } foreach ($item['tags'] as &$tag) { $tag['names'] = unserialize($tag['names']); - if(in_array($language, $languageArr)){ + if (in_array($language, $languageArr)) { $item['name'] = $item['names'][$language]; } } @@ -30,4 +31,35 @@ class TagGroupController return Util::success($list); } + + + /** + * 更新客户标签关系 + * @param Request $request + * @return \support\Response + */ + public function updatePivot(Request $request) + { + $customerId = Util::getParam($request, 'customer_id'); + $groupId = Util::getParam($request, 'group_id'); + $tagId = Util::getParam($request, 'tag_id'); + if (Util::isEmpty($customerId)) { + return Util::fail([], trans('customer_id') . trans('not_null')); + } + if (Util::isEmpty($groupId)) { + return Util::fail([], trans('tag_group_id') . trans('not_null')); + } + + if(empty($tagId)){ + $res = CustomerTag::where(['customer_id' => $customerId, 'group_id' => $groupId])->delete(); + }else{ + $res = CustomerTag::updateOrCreate(['customer_id' => $customerId, 'group_id' => $groupId], ['tag_id' => $tagId]); + } + + if($res){ + return Util::success($res, trans('success')); + }else{ + return Util::fail($res, trans('fail')); + } + } } \ No newline at end of file diff --git a/app/model/Customer.php b/app/model/Customer.php index a166ee8..09a9f0e 100644 --- a/app/model/Customer.php +++ b/app/model/Customer.php @@ -96,4 +96,13 @@ class Customer extends Model return $customer; } + + /** + * 客户的标签 + */ + public function tags() + { + return $this->belongsToMany(Tag::class, 'customer_tag', 'customer_id', 'tag_id') + ->withTimestamps(); // 如果需要记录关联时间 + } } \ No newline at end of file diff --git a/app/model/CustomerTag.php b/app/model/CustomerTag.php new file mode 100644 index 0000000..f3f96a3 --- /dev/null +++ b/app/model/CustomerTag.php @@ -0,0 +1,36 @@ +belongsTo(TagGroup::class, 'group_id', 'id'); } + public function customers() + { + return $this->belongsToMany(Customer::class, 'customer_tag', 'tag_id', 'customer_id'); + } } \ No newline at end of file diff --git a/resource/translations/en/messages.php b/resource/translations/en/messages.php index 9a7b4f9..2a20ae4 100644 --- a/resource/translations/en/messages.php +++ b/resource/translations/en/messages.php @@ -28,4 +28,6 @@ return [ 'sign_not_null' => ' No affiliated company has been set', 'password_short' => ' Password cannot be less than 6 characters', 'id_empty' => ' ID cannot be empty', + 'customer_id' => ' customer ID', + 'tag_group_id' => ' tag group ID', ]; \ No newline at end of file diff --git a/resource/translations/zh_CN/messages.php b/resource/translations/zh_CN/messages.php index 5647b34..1a6428c 100644 --- a/resource/translations/zh_CN/messages.php +++ b/resource/translations/zh_CN/messages.php @@ -28,4 +28,6 @@ return [ 'sign_not_null' => ' 未设置所属公司', 'password_short' => ' 密码不能少于6位', 'id_empty' => ' id不能为空', + 'customer_id' => ' 客户ID', + 'tag_group_id' => ' 标签组ID', ]; \ No newline at end of file From 16a7ea29762c71aa1e04bd497d297ade0a915539 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Thu, 27 Mar 2025 13:34:10 +0800 Subject: [PATCH 13/14] =?UTF-8?q?=E8=AF=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/CustomerController.php | 4 ++-- app/model/Customer.php | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/controller/CustomerController.php b/app/controller/CustomerController.php index f7da53f..da39f6e 100644 --- a/app/controller/CustomerController.php +++ b/app/controller/CustomerController.php @@ -145,7 +145,7 @@ class CustomerController // 执行分页查询 //关联标签tags //关联标签及分组tags.group - $query = Customer::with('tags')->where($where) + $query = Customer::where($where) ->orderBy('id', 'desc'); if (!Util::isEmpty($keyword)) { $query->where(function ($query) use ($keyword) { @@ -219,7 +219,7 @@ class CustomerController return Util::fail([], '记录不存在'); } - $res = Customer::getCustomer($res); + $res = Customer::getCustomer($res,$request); return Util::success($res); } diff --git a/app/model/Customer.php b/app/model/Customer.php index 09a9f0e..54cf548 100644 --- a/app/model/Customer.php +++ b/app/model/Customer.php @@ -59,7 +59,7 @@ class Customer extends Model return $date->format(Carbon::parse($date)->toDateTimeString()); } - public static function getCustomer($customer) + public static function getCustomer($customer,$request = null) { $customer['grade_txt'] = Constants::GRADE[$customer['grade']]; $customer['magnitude_txt'] = Constants::MAGNITUDE[$customer['magnitude']]; @@ -94,6 +94,14 @@ class Customer extends Model $customer['channel_name'] = empty($customer['channel_id'])?'':Channel::where(['id'=>$customer['channel_id']])->value('name'); // $customer['last_follow'] = $last_follow; + if (!empty($request)) { + $language = $request->user['language'] ?: 'en'; + foreach ($customer['tags'] as &$tag) { + $tag['names'] = unserialize($tag['names']); + $tag['name'] = $tag['names'][$language]; + } + } + return $customer; } From 80a7541d0c88764be81a70646c6de6416a06fa24 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Thu, 27 Mar 2025 14:05:14 +0800 Subject: [PATCH 14/14] =?UTF-8?q?=E6=A0=87=E7=AD=BE=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/CustomerController.php | 4 ++-- app/model/Customer.php | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/controller/CustomerController.php b/app/controller/CustomerController.php index da39f6e..179aa41 100644 --- a/app/controller/CustomerController.php +++ b/app/controller/CustomerController.php @@ -167,7 +167,7 @@ class CustomerController $data = $query->paginate($perPage, ['*'], 'page', $page); foreach ($data->items() as &$value) { - $value = Customer::getCustomer($value); + $value = Customer::getCustomer($value, $request); } return Util::page($data); @@ -219,7 +219,7 @@ class CustomerController return Util::fail([], '记录不存在'); } - $res = Customer::getCustomer($res,$request); + $res = Customer::getCustomer($res, $request, true); return Util::success($res); } diff --git a/app/model/Customer.php b/app/model/Customer.php index 54cf548..86adea5 100644 --- a/app/model/Customer.php +++ b/app/model/Customer.php @@ -59,11 +59,18 @@ class Customer extends Model return $date->format(Carbon::parse($date)->toDateTimeString()); } - public static function getCustomer($customer,$request = null) + /** + * @param $customer + * @param $request + * @param $tag 是否返回客户标签 + * @return mixed + */ + public static function getCustomer($customer, $request, $tag = false) { $customer['grade_txt'] = Constants::GRADE[$customer['grade']]; $customer['magnitude_txt'] = Constants::MAGNITUDE[$customer['magnitude']]; $customer['sex_txt'] = Constants::SEX[$customer['sex']]; + $language = $request->user['language'] ?: 'en'; if ($customer['grade']<=2) { $customer['follow'] = 0; @@ -94,8 +101,7 @@ class Customer extends Model $customer['channel_name'] = empty($customer['channel_id'])?'':Channel::where(['id'=>$customer['channel_id']])->value('name'); // $customer['last_follow'] = $last_follow; - if (!empty($request)) { - $language = $request->user['language'] ?: 'en'; + if ($tag) { foreach ($customer['tags'] as &$tag) { $tag['names'] = unserialize($tag['names']); $tag['name'] = $tag['names'][$language];