From 9ee628e798a401b35e5b916e2942f313886c163f Mon Sep 17 00:00:00 2001 From: chuan <2154243450@qq.com> Date: Thu, 3 Jul 2025 22:37:06 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=9D=E5=8A=A1=E9=98=9F=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/User.php | 17 +++++ app/admin/route/app.php | 2 + app/admin/service/UserService.php | 110 +++++++++++++++++++++++++++--- 3 files changed, 119 insertions(+), 10 deletions(-) diff --git a/app/admin/controller/User.php b/app/admin/controller/User.php index 565af5c5..9c303a12 100644 --- a/app/admin/controller/User.php +++ b/app/admin/controller/User.php @@ -192,6 +192,7 @@ class User extends AdminBaseController return json($result); } + // 创建一条话务请i去 public function addBusiness() { $service = new UserService(); @@ -199,6 +200,14 @@ class User extends AdminBaseController return json([$result]); } + // 回复一条话务请求 + public function replyBusiness() + { + $service = new UserService(); + $result = $service->replyBusiness($this->request->param(), $this->getAdminId()); + return json([$result]); + } + // 获取话务队列 public function getBusinessList() { @@ -206,4 +215,12 @@ class User extends AdminBaseController $result = $service->getBusinessList($this->request->param(), $this->getAdminId()); return json($result); } + + // 获取所有用户的话务队列 + public function getAllBusinessList() + { + $service = new UserService(); + $result = $service->getAllBusinessList($this->request->param(), $this->getAdminId()); + return json($result); + } } diff --git a/app/admin/route/app.php b/app/admin/route/app.php index 8c678441..a1eb3384 100644 --- a/app/admin/route/app.php +++ b/app/admin/route/app.php @@ -236,7 +236,9 @@ Route::group('/', function () { // 话务队列 Route::post('user/add_business', 'User/addBusiness'); // 创建一条话务 + Route::post('user/reply_business', 'User/replyBusiness'); // 回复一条话务 Route::post('user/get_business_list', 'User/getBusinessList'); // 获取话务队列 + Route::post('user/get_all_business_list', 'User/getAllBusinessList'); // 获取话务队列 //送股 Route::post('/user/give_stock', 'setting.GiveStock/add')->middleware('admin_log'); diff --git a/app/admin/service/UserService.php b/app/admin/service/UserService.php index b01a3acc..8bcf2a2b 100644 --- a/app/admin/service/UserService.php +++ b/app/admin/service/UserService.php @@ -378,6 +378,14 @@ class UserService extends AdminBaseService $isVip = true; $vipExpire = $vipInfo[$item['user_id']]['expire']; } + // 话务数据 + $business = BusinessLogModel::where(['uid'=>$item['user_id']])->order('id', 'desc')->find(); + if (!empty($business)) { + $business = $business->toArray(); + } else { + $business = []; + } + $rows[] = [ 'id' => $item['user_id'], @@ -409,6 +417,7 @@ class UserService extends AdminBaseService 'third_stage_state' => $userStageStateList[$item['user_id']]['third_stage_state'] ?? 0, 'is_vip' => $isVip, // 是否vip 'vip_expire' => $vipExpire, // vip到期时间 + 'business' => $business, // 话务数据 //余额 'digital' => $userDigitalList[$item['user_id']]['usable_num'] ?? '0', @@ -1573,13 +1582,14 @@ class UserService extends AdminBaseService public function addBusiness($param, $adminId) { try { - if (empty($param['from_content'])) { + if (empty($param['user_id']) || empty($param['from_content'])) { return $this->toData('400', '参错错误'); } $result = BusinessLogModel::create([ - 'from_uid' => $adminId, - 'reply_uid' => 0, + 'uid' => $param['user_id'], // 操作的客户uid + 'from_uid' => $adminId, // 发起业务请求的客服 + 'reply_uid' => 0, // 待回复处理的话务员 'from_content' => $param['from_content'], 'is_reply' => 0 ]); @@ -1590,7 +1600,32 @@ class UserService extends AdminBaseService } } - // 获取话务队列 + // 回复话务 + public function replyBusiness($param, $adminId) + { + try { + if (empty($param['business_id']) || empty($param['reply_content'])) { + return $this->toData('400', '参错错误'); + } + $info = BusinessLogModel::where(['id'=>$param['business_id']])->find(); + if (empty($info)) { + return $this->toData('500', '数据不存在'); + } + if (!empty($info->reply_content)) { + return $this->toData('500', '该条数据已经完成回复处理'); + } + $info->reply_content = $param['reply_content']; + $info->reply_uid = $adminId; + $info->is_reply = 1; + $info->reply_time = date("Y-m-d H:i:s"); + $result = $info->save(); + return $this->toData('0', 'Successful', [$result]); + } catch (\Exception $e) { + return $this->toData('500', '系统异常 请稍后重试', [$e->getMessage(), $e->getTrace()]); + } + } + + // 获取话务队列 - 针对某个用户 public function getBusinessList($param, $adminId) { try { @@ -1600,19 +1635,24 @@ class UserService extends AdminBaseService if (empty($param['limit']) || !is_numeric($param['limit'])) { return $this->toData('400', '参错错误'); } - $where = ['is_reply'=>0]; // 只返回未回复的 - if (!empty($param['reply_uid'])) { - $where['reply_uid'] = $param['reply_uid']; + if (empty($param['user_id'])) { + return $this->toData('400', '缺少uid'); + } + // 获取用户信息 + $userInfo = UserModel::where(['user_id'=>$param['user_id']])->find(); + if (empty($userInfo)) { + return $this->toData('500', '用户信息错误'); } - if (isset($param['is_reply'])) { - $where['is_reply'] = $param['is_reply']; + $where = ['uid'=>$param['user_id']]; + if (!empty($param['is_reply']) && $param['is_reply'] < 2) { + $where['is_reply'] = $param['is_reply']; // 根据回复状态过滤:0-未回复的; 1-已经回复的; 2-全部 } - $list = BusinessLogModel::where($where)->order('id', 'desc')->paginate([ 'list_rows' => $param['limit'], 'page' => $param['page'], ]); return $this->toData('0', 'Successful', [ + 'user_info' => $userInfo->toArray(), 'list' => $list->items(), 'page' => $list->currentPage(), 'total' => $list->total(), @@ -1623,6 +1663,56 @@ class UserService extends AdminBaseService } } + // 获取所有用户的话务队列 + public function getAllBusinessList($param, $adminId) + { + try { + if (empty($param['page']) || !is_numeric($param['page'])) { + return $this->toData('400', '参错错误'); + } + if (empty($param['limit']) || !is_numeric($param['limit'])) { + return $this->toData('400', '参错错误'); + } + // 获取用户信息 + $userInfo = UserModel::where(['user_id'=>$param['user_id']])->find(); + if (empty($userInfo)) { + return $this->toData('500', '用户信息错误'); + } + $where = ['uid'=>$param['user_id']]; + if (!empty($param['is_reply']) && $param['is_reply'] < 2) { + $where['is_reply'] = $param['is_reply']; // 根据回复状态过滤:0-未回复的; 1-已经回复的; 2-全部 + } + $list = BusinessLogModel::where($where)->order('id', 'desc')->paginate([ + 'list_rows' => $param['limit'], + 'page' => $param['page'], + ]); + + if (!empty($list->items())) { + $data = []; + foreach ($list->items() as $v) { + $tmp = $v; + $userInfo = UserModel::where(['user_id'=>$param['user_id']])->find(); + if (!empty($userInfo)) { + $tmp['user_info'] = $userInfo->toArray(); + } else{ + $tmp['user_info'] = []; + } + $data[] = $tmp; + } + } + + return $this->toData('0', 'Successful', [ + 'user_inf' => $userInfo->toArray(), + 'list' => $data, + 'page' => $list->currentPage(), + 'total' => $list->total(), + 'last_page' => $list->lastPage(), + ]); + } catch (\Exception $e) { + return $this->toData('500', '系统异常 请稍后重试', [$e->getMessage(), $e->getTrace()]); + } + } + }