diff --git a/app/controller/CustomerController.php b/app/controller/CustomerController.php index 3881e59..b032c9b 100644 --- a/app/controller/CustomerController.php +++ b/app/controller/CustomerController.php @@ -158,7 +158,12 @@ class CustomerController $query->whereIn('grade', $grade); } -// return Util::success($query->toSql().serialize($where),$follow); + + $recycle = Util::getParam($request,'recycle', ''); + if ($recycle == 'recycle') { + $query->onlyTrashed(); + } + $data = $query->paginate($perPage, ['*'], 'page', $page); foreach ($data->items() as &$value) { @@ -168,6 +173,31 @@ class CustomerController return Util::page($data); } + + /** + * 客户恢复 + * @param Request $request + * @return \support\Response + */ + public function restore(Request $request) + { + $id = Util::getParam($request,'id', ''); + if (Util::isEmpty($id)) { + return Util::fail([], trans('id_empty')); + } + $userId = $request->user['id']; + $where = [ + 'id' => $id, + 'user_id' => $userId, + ]; + $res = Customer::where($where)->restore(); + if($res){ + return Util::success($res, trans('success')); + }else{ + return Util::fail([], trans('fail')); + } + } + /** * 客户详情 * @param Request $request @@ -319,8 +349,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