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']);