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 1/2] =?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 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 2/2] =?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