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