From c40d0bcec34cfa37afbb5546b141ef882e7a3998 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Wed, 13 Aug 2025 10:36:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=AE=A2=E6=88=B7=E4=B8=BA?= =?UTF-8?q?=E6=94=BE=E5=85=A5=E5=85=AC=E6=B5=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/crm/controller/CustomerController.php | 77 +++++++---------------- config/route.php | 1 - 2 files changed, 24 insertions(+), 54 deletions(-) diff --git a/app/crm/controller/CustomerController.php b/app/crm/controller/CustomerController.php index 48744e4..b00af0d 100644 --- a/app/crm/controller/CustomerController.php +++ b/app/crm/controller/CustomerController.php @@ -394,13 +394,31 @@ class CustomerController extends BaseController if(empty($customer)){ return $this->error( trans('fail')); } - if($force == 'force'){ - //强制删除 - $res = $customer->forceDelete(); - }else{ - //软删除 - $res = $customer->delete(); + try { + Db::beginTransaction(); + if ($force == 'force') { + //强制删除 + $res = $customer->forceDelete(); + } else { + $customer->user_id = 0; + $customer->save(); + + //记录客户关系变化 + $his = CustomerHis::create([ + 'customer_id' => $id, + 'user_his' => $userId, + 'user_id' => 0, + ]); + + //软删除 + $res = $customer->delete(); + } + Db::commit(); + } catch (\Throwable $e) { + Db::rollback(); + return $this->error($e->getMessage()); } + if ($res) { return $this->success($res, trans('success')); } else { @@ -527,53 +545,6 @@ class CustomerController extends BaseController } } - /** - * 客户转移至公海 - * @param Request $request - * @return \support\Response - */ - public function putSeas(Request $request) - { - $customerId = Util::getParam($request, 'customer_id'); - $userId = $request->user->uid; - if (Util::isEmpty($customerId)) { - return $this->error(trans('customer_id').trans('not_null')); - } - - try { - Db::beginTransaction(); - $customer= Customer::withTrashed()->where('user_id',$userId)->find($customerId); - - if(empty($customer)){ - return $this->error( 'customer_id错误'); - } - $data = [ - 'user_id' => 0, - ]; - - $res = $customer->update($data); - - //记录客户关系变化 - $his = CustomerHis::create([ - 'customer_id' => $customerId, - 'user_his' => $userId, - 'user_id' => 0, - ]); - Db::commit(); - } catch (\Throwable $e) { - Db::rollback(); - return $this->error($e->getMessage()); - } - - if ($res) { - return $this->success($res, trans('success')); - } else { - return $this->error(trans('fail')); - } - } - - - /** * 批量转让 * @param Request $request diff --git a/config/route.php b/config/route.php index e86a342..c4d9161 100644 --- a/config/route.php +++ b/config/route.php @@ -175,7 +175,6 @@ Route::group('/crm', function () { Route::any('/customer/getCountry', [app\crm\controller\CustomerController::class, 'getCountry']); Route::any('/customer/followNext', [app\crm\controller\CustomerController::class, 'followNext']); Route::any('/customer/report', [app\crm\controller\CustomerController::class, 'report']); - Route::any('/customer/seas', [app\crm\controller\CustomerController::class, 'putSeas']); Route::any('/tagGroup/list', [app\crm\controller\TagGroupController::class, 'list']); Route::any('/tagGroup/updatePivot', [app\crm\controller\TagGroupController::class, 'updatePivot']);