diff --git a/app/common/controller/PresetController.php b/app/common/controller/PresetController.php index a4b2a81..27f0c7a 100644 --- a/app/common/controller/PresetController.php +++ b/app/common/controller/PresetController.php @@ -6,6 +6,7 @@ use support\Request; use app\common\service\CorpService; use app\common\service\CorpFeishuAppService; use app\common\service\SystemsService; +use app\common\service\UserService; class PresetController extends BaseController { @@ -48,4 +49,15 @@ class PresetController extends BaseController return $this->error($e->getMessage()); } } + + + public function users() + { + try { + $result = (new UserService())->getList(); + return $this->success($result, '获取用户列表'); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } } \ No newline at end of file diff --git a/app/common/logic/UserLogic.php b/app/common/logic/UserLogic.php index 4b58247..9f5ae44 100644 --- a/app/common/logic/UserLogic.php +++ b/app/common/logic/UserLogic.php @@ -53,4 +53,19 @@ class UserLogic return $res; } + /** + * 获取用户列表 + */ + public function getList() + { + $list = User::where('status', 1)->orderBy('id', 'desc')->get(); + $arr = []; + foreach ($list->toArray() as $item) { + $arr[] = [ + 'name' => $item['name'], + 'id' => $item['id'], + ]; + } + return $arr; + } } \ No newline at end of file diff --git a/app/common/service/UserService.php b/app/common/service/UserService.php index 85684d3..25de588 100644 --- a/app/common/service/UserService.php +++ b/app/common/service/UserService.php @@ -5,6 +5,7 @@ namespace app\common\service; use app\common\logic\UserLogic; use app\common\model\Corp; use app\common\model\User; +use app\common\utils\CrudUtil; use app\crm\model\Country; use support\exception\BusinessException; @@ -99,4 +100,12 @@ class UserService $user = $this->logic->savePassword($uid,$data); return $user; } + + /** + * 获取用户列表 + */ + public function getList() + { + return $this->logic->getList(); + } } \ No newline at end of file diff --git a/app/common/traits/crud/CrudLogicTrait.php b/app/common/traits/crud/CrudLogicTrait.php index e648f2f..9e629f9 100644 --- a/app/common/traits/crud/CrudLogicTrait.php +++ b/app/common/traits/crud/CrudLogicTrait.php @@ -69,4 +69,12 @@ trait CrudLogicTrait { return CrudUtil::executeComplex($this->modelClass, $callback); } + + /** + * 根据主键查询 + */ + public function findByPk(int $id, array $with = []) + { + return CrudUtil::findByPk($this->modelClass, $id, $with); + } } diff --git a/app/common/traits/crud/CrudServiceTrait.php b/app/common/traits/crud/CrudServiceTrait.php index bf17abc..5ad6dbc 100644 --- a/app/common/traits/crud/CrudServiceTrait.php +++ b/app/common/traits/crud/CrudServiceTrait.php @@ -117,7 +117,7 @@ trait CrudServiceTrait $config['where']['id'] = $p['id']; break; case 'destroy': - // $config['where']['id'] = $p['id']; + $config['where']['id'] = $p['id']; break; } diff --git a/app/common/validate/InquiryLogValidate.php b/app/common/validate/InquiryLogValidate.php index 58058cb..aac6495 100644 --- a/app/common/validate/InquiryLogValidate.php +++ b/app/common/validate/InquiryLogValidate.php @@ -69,9 +69,14 @@ class InquiryLogValidate extends Validate 'store' => [ 'enter_user_id', 'quality', 'channel', 'email', 'tel', 'whatsapp', 'country', 'contacts', 'content' ], - 'update' => [ 'quality', 'channel', 'email', 'tel', 'whatsapp', 'country', 'contacts', 'content' + ], + 'release' => [ + 'status', 'r_time' + ], + 'allocation' => [ + 'status', 't_time' ] ]; diff --git a/app/inquiry/controller/InquiryLogController.php b/app/inquiry/controller/InquiryLogController.php index 8fbd985..8bc6761 100644 --- a/app/inquiry/controller/InquiryLogController.php +++ b/app/inquiry/controller/InquiryLogController.php @@ -4,6 +4,7 @@ namespace app\inquiry\controller; use app\common\controller\BaseController; use app\common\traits\crud\CrudControllerTrait; use app\inquiry\service\InquiryLogService; +use support\Request; class InquiryLogController extends BaseController { @@ -24,6 +25,11 @@ class InquiryLogController extends BaseController */ protected function indexFormat($data) { + $data['countdown'] = time()-1; + if (isset($data['r_time'])) { + $countdown = 60 * 60; + $data['countdown'] = (time() - $data['r_time']) < $countdown ? $data['r_time'] + (60*60) : time()-1; + } if (isset($data['created_at'])) $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); if (isset($data['updated_at'])) @@ -32,538 +38,41 @@ class InquiryLogController extends BaseController $data['r_time'] = $data['r_time'] > 0 ? date('Y-m-d H:i:s', $data['r_time']) : 0; if (isset($data['t_time'])) $data['t_time'] = $data['t_time'] > 0 ? date('Y-m-d H:i:s', $data['t_time']) : 0; + return $data; } - - // 列表 - public function list(Request $request) - { - if ($request->method() == 'POST') { - $data = $request->all(); - $limit = isset($data['limit']) && $data['limit'] ? $data['limit'] : 10; - - // 状态 - $roleId = $request->user->role_id; - $where = []; - if (in_array($roleId, [RoleRulesModel::ALL_ROLE_ID, RoleRulesModel::KEFU_ROLE_ID])) { - if (isset($data["status"]) && $data["status"] != "") { - $where[] = [ - "status", "=", $data["status"] - ]; - } else { - $where[] = [ - "status", ">", -1 - ]; - } - } else { - $where[] = [ - "status", "=", 1 - ]; - } - - // 检索渠道 - if (isset($data["channel"]) && $data["channel"]) { - $where[] = [ - "log_type", "=", $data["channel"] - ]; - } - - // 检索国家 - if (isset($data["country"]) && $data["country"]) { - $where[] = [ - "log_country", "=", $data["country"] - ]; - } - - // 检索时间 - if (isset($data["ld_time"]) && $data["ld_time"]) { - $times = explode(' - ', $data["ld_time"]); - $specificDayStart = trim($times[0]); - $specificDayEnd = trim($times[1]); - $where[] = [ - "c_time", ">", strtotime($specificDayStart) - ]; - $where[] = [ - "c_time", "<=", strtotime($specificDayEnd) - ]; - } - - // 检查渠道(不取缓存中的值) - // $channel = $request->user->channel; - $uinfos = UsersModel::where('id', $request->user->uid)->first(); - $channel = $uinfos->channel; - if ($channel) { - $channel = explode(",", $channel); - $InquiryLogModelModel = InquiryLogModel::where($where)->whereIn("log_type", $channel); - } else { - $InquiryLogModelModel = InquiryLogModel::where($where); - } - - // 关键字 - if (isset($data["kwd"]) && $data["kwd"] != "") { - $InquiryLogModelModel->whereRaw("concat(`log_contact_type`,`log_contact_tel`,`log_contact_whatsapp`,`log_contacts`,`order_no`) like '%".$data['kwd']."%'"); - } - - $list = $InquiryLogModelModel - ->with([ - "eUserInfo"=>function($query) { - $query->where("id", ">", 0); - }, "rUserInfo"=>function($query) { - $query->where("id", ">", 0); - }, "countryInfo" - ]) - ->orderBy("id", "desc") - ->paginate($limit); - - $configsModel = new ConfigsModel(); - $logLevel = $configsModel->getConfig("log_level"); - $countdown = (int)($configsModel->getConfig("score_countdown")) * 60; - $inquiryChannelList = ChannelModel::all(['id', 'name']); - $inquiryChannel = []; - foreach ($inquiryChannelList as $key => $val) { - $inquiryChannel[$val->id] = $val->name; - } - - $arr = []; - foreach ($list->items() as $key => $val) { - $expiry_time = $val->r_time + $countdown; - $is_expiry = 0; - $expiry_ts = 0; - if ($expiry_time <= time()) { - $is_expiry = 1; - } else { - $diff = $expiry_time - (int)time(); - $expiry_ts = $diff * 1000; - } - $rUinfo = ""; - if ($val->rUserInfo) { - $rUinfo = $val->rUserInfo->name; - } - $eUinfo = ""; - if ($val->eUserInfo) { - $eUinfo = $val->eUserInfo->name; - } - - /** - * 显示联系方式条件: - * 1.已跟单并且当前用户是接单人 - * 2.主权限 - * 3.当前用户是录单人 - */ - if ( - ($val->status == 2 && $request->user->uid == $val->recipient) || - ($roleId == RoleRulesModel::ALL_ROLE_ID) || - ($request->user->uid == $val->enter_user_id) - ) { - $log_contact_type = $val->log_contact_type == "" ? " 无 " : $val->log_contact_type; - $log_contact_tel = $val->log_contact_tel == "" ? " 无 " : $val->log_contact_tel; - $log_contact_whatsapp = $val->log_contact_whatsapp == "" ? " 无 " : $val->log_contact_whatsapp; - } else { - $log_contact_type = "******"; - $log_contact_tel = "******"; - $log_contact_whatsapp = "******"; - } - $arr[] = [ - "id" => $val->id, - "order_no" => $val->order_no, - "enter_user_id" => $val->enter_user_id, - "recipient" => $val->recipient, - "log_quality" => $val->log_quality, - "log_quality_desc" => $logLevel[$val->log_quality], - "log_quality_color" => InquiryLogModel::LEVEL_BUTTON_COLOR[$val->log_quality], - "log_type" => $val->log_type, - "log_type_desc" => $inquiryChannel[$val->log_type], - "log_contact_type" => $log_contact_type, - "log_contact_tel" => $log_contact_tel, - "log_contact_whatsapp" => $log_contact_whatsapp, - "log_country" => $val->countryInfo->cn_addr."(".$val->countryInfo->two_letter.")", - "log_country_steering" => $val->countryInfo->steering, - "log_contacts" => $val->log_contacts, - "log_content" => $val->log_content, - "e_time" => $val->status==1?date("Y-m-d H:i:s", $expiry_time):"", - "status" => $val->status, - "status_color" => InquiryLogModel::STATUS_BUTTON_COLOR[$val->status], - "status_desc" => InquiryLogModel::STATUS[$val->status], - "is_expiry" => $is_expiry, - "expiry_ts" => $expiry_ts, - "rUinfo" => $rUinfo, - "eUinfo" => $eUinfo, - "r_time" => $val->r_time?date("Y-m-d H:i:s", $val->r_time):"", - "n_time" => date("Y-m-d H:i:s", time()), - "c_time" => date("Y-m-d H:i:s", strtotime($val->c_time)), - "u_time" => date("Y-m-d H:i:s", strtotime($val->u_time)) - ]; - } - $data = [ - 'lastPage' => $list->lastPage(), - 'currentPage' => $list->currentPage(), - 'hasMorePages' => $list->hasMorePages(), - 'list' => $arr, - 'counts' => $list->total() - ]; - return $this->successResponse($data); - } - return view('inquiry-log/list'); - } - - // 添加 - public function add(Request $request) - { - if ($request->method() == "POST") { - $enterUserId = $request->user->uid; - $data = $request->all(); - - if ($data["log_contact_type"]) { - $check1 = InquiryLogModel::where("log_contact_type", trim($data["log_contact_type"]))->first(); - if ($check1 != NULL) { - return $this->errorResponse('邮箱-联系方式已存在'); - } - } - - if ($data["log_contact_tel"]) { - $check2 = InquiryLogModel::where("log_contact_tel", trim($data["log_contact_tel"]))->first(); - if ($check2 != NULL) { - return $this->errorResponse('电话-联系方式已存在'); - } - } - - if ($data["log_contact_whatsapp"]) { - $check3 = InquiryLogModel::where("log_contact_whatsapp", trim($data["log_contact_whatsapp"]))->first(); - if ($check3 != NULL) { - return $this->errorResponse('whatsapp-联系方式已存在'); - } - } - - if (!$data["log_contact_type"] && !$data["log_contact_tel"] && !$data["log_contact_whatsapp"]) { - $check4 = InquiryLogModel::where("log_contacts", trim($data["log_contacts"]))->where("log_country", $data["country"])->first(); - if ($check4 != NULL) { - return $this->errorResponse('联系人已存在'); - } - } - - $model = new InquiryLogModel(); - $model->order_no = orderNum(); - $model->enter_user_id = $enterUserId; - $model->recipient = 0; - $model->log_type = $data["log_type"]; - $model->log_contact_type = trim($data["log_contact_type"]); - $model->log_contact_tel = trim($data["log_contact_tel"]); - $model->log_contact_whatsapp = trim($data["log_contact_whatsapp"]); - $model->log_country = $data["country"]; - $model->log_contacts = $data["log_contacts"]; - $model->log_content = $data["log_content"]; - $model->log_quality = $data["log_quality"]; - $model->status = 0; - if ($model->save()) { - return $this->successResponse([], '添加成功'); - } else { - return $this->errorResponse('添加失败,请重试'); - } - } - return view('inquiry-log/add'); - } - - // 编辑 - public function edit(Request $request) - { - if ($request->method() == "POST") { - $data = $request->all(); - $model = new InquiryLogModel(); - $info = $model->where("id", $data["id"])->first(); - - if ($data["log_contact_type"]) { - $check1 = InquiryLogModel::where("log_contact_type", trim($data["log_contact_type"]))->first(); - if ($check1 != NULL && $check1->id != $data["id"]) { - return $this->errorResponse('邮箱-联系方式已存在'); - } - } - - if ($data["log_contact_tel"]) { - $check2 = InquiryLogModel::where("log_contact_tel", trim($data["log_contact_tel"]))->first(); - if ($check2 != NULL && $check2->id != $data["id"]) { - return $this->errorResponse('电话-联系方式已存在'); - } - } - - if ($data["log_contact_whatsapp"]) { - $check3 = InquiryLogModel::where("log_contact_whatsapp", trim($data["log_contact_whatsapp"]))->first(); - if ($check3 != NULL && $check3->id != $data["id"]) { - return $this->errorResponse('whatsapp-联系方式已存在'); - } - } - - if (!$data["log_contact_type"] && !$data["log_contact_tel"] && !$data["log_contact_whatsapp"]) { - $check4 = InquiryLogModel::where("log_contacts", trim($data["log_contacts"]))->where("log_country", $data["country"])->first(); - if ($check4 != NULL && $check4->id != $data["id"]) { - return $this->errorResponse('联系人已存在'); - } - } - - $info->log_type = $data["log_type"]; - $info->log_contact_type = $data["log_contact_type"]; - $info->log_contact_tel = $data["log_contact_tel"]; - $info->log_contact_whatsapp = $data["log_contact_whatsapp"]; - $info->log_country = $data["country"]; - $info->log_contacts = $data["log_contacts"]; - $info->log_content = $data["log_content"]; - $info->log_quality = $data["log_quality"]; - if (!$info->save()) { - return $this->errorResponse('操作失败,请重试'); - } - return $this->successResponse([], '操作成功'); - } - return view('inquiry-log/edit'); - } - - // 删除 - public function del(Request $request) - { - if ($request->method() == "POST") { - $id = $request->post("id"); - $rst = InquiryLogModel::where("id", $id)->first(); - if (!$rst) { - return $this->errorResponse('询单未找到'); - } - if ($rst->enter_user_id != $request->user->uid) { - return $this->errorResponse('只能删除自己录入的询单'); - } - $res = InquiryLogModel::where("id", $id)->where("enter_user_id", $request->user->uid)->delete(); - if (!$res) { - return $this->errorResponse('操作失败,请重试'); - } - fileLog('ID:'.$request->user->uid.' - 删除:询单ID:'.$id); - return $this->successResponse([], '操作成功'); - } - return $this->errorResponse('请求方式错误'); - } - - // 单条信息 - public function info(Request $request) - { - if ($request->method() == "POST") { - $id = $request->all("id"); - $info = InquiryLogModel::where("id", $id)->first()->toArray(); - $list = CountryModel::all(["cn_addr", "two_letter", "id"]); - $arr = []; - foreach ($list as $vo) { - $arr[] = [ - "value" => $vo->id, - "name" => $vo->cn_addr."(".$vo->two_letter.")" - ]; - } - $info["guojia"] = $arr; - $info["guojia_id"] = [$info["log_country"]]; - - $configsModel = new ConfigsModel(); - // $data = $configsModel->getConfig("inquiry_channel"); - $inquiryChannelList = ChannelModel::all(['id', 'name']); - $data = []; - foreach ($inquiryChannelList as $key => $val) { - $data[$val->id] = $val->name; - } - - $arr = []; - foreach ($data as $ky => $vo) { - $arr[] = [ - "id" => $ky, - "name" => $vo - ]; - } - $info["qudao"] = $arr; - - $data1 = $configsModel->getConfig("log_level"); - $arr1 = []; - foreach ($data1 as $ky => $vo) { - $arr1[] = [ - "id" => $ky, - "name" => $vo - ]; - } - $info["dengji"] = $arr1; - if (!$info) { - return $this->errorResponse('查询失败,请重试'); - } - $info["log_content"] = strTh($info["log_content"]); - return $this->successResponse($info, 'success'); - } - return $this->errorResponse('请求方式错误'); - } - - // 立即发布 + /** + * 发布 + * + * @param Request $request + * @return mixed + */ public function release(Request $request) { try { - if ($request->method() == "POST") { - $id = $request->post("id"); - if (!in_array($request->user->role_id, [RoleRulesModel::ALL_ROLE_ID, RoleRulesModel::KEFU_ROLE_ID])) { - return $this->errorResponse('无操作权限'); - } - $info = InquiryLogModel::where("id", $id)->first(); - if (!$info) { - return $this->errorResponse('询单信息未找到'); - } - if ($info->status != 0) { - return $this->errorResponse('状态异常,无法发布'); - } - $info->r_time = time(); - $info->status = 1; - if (!$info->save()) { - return $this->errorResponse('发布失败,请重试'); - } - - // 发送飞书群消息通知 - $data = ["order_id"=>$id]; - RedisQueueRedis::send("release", $data); - // 发送飞书群消息通知 - - return $this->successResponse([], '发布成功'); - } - return $this->errorResponse('电话-请求方式错误'); - } catch (\Throwable $th) { - fileLog($th->getFile()."|".$th->getLine()."|".$th->getMessage()); - return $this->errorResponse($th->getMessage()); + $data = $this->validate($this->service->getValidator(), $request->post(), 'release'); + $res = $this->service->serviceRelease($request, $data); + return $this->success([], '发布成功'); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); } } - // 立即跟单 - public function track(Request $request) - { - // Db::beginTransaction(); - try { - if ($request->method() == "POST") { - $id = $request->post("id"); - $uid = $request->user->uid; - if (!in_array($request->user->role_id, [RoleRulesModel::ALL_ROLE_ID, RoleRulesModel::YEWU_ROLE_ID])) { - // Db::rollBack(); - return $this->errorResponse('无操作权限'); - } - $info = InquiryLogModel::where("id", $id)->first(); - if (!$info) { - return $this->errorResponse('询单信息未找到'); - } - if ($info->status != 1) { - // Db::rollBack(); - return $this->errorResponse('状态异常,无法跟单'); - } - // 更新询单 - $info->recipient = $uid; - $info->t_time = time(); - $info->status = 2; - // 记录跟单 - $model = new UserOrderModel(); - $model->uid = $request->user->uid; - $model->log_id = $id; - $model->score = (new InquiryLogModel())->score($info->log_quality, $info->r_time); - if (!$info->save() || !$model->save()) { - // Db::rollBack(); - return $this->errorResponse('操作失败,请重试'); - } - // Db::commit(); - - // // 发送飞书群消息通知 - $data1 = ["order_id"=>$id]; - RedisQueueRedis::send("track", $data1); - // // 发送飞书群消息通知 - - // // 同步询单到crm - $data2 = ["order_id"=>$id]; - RedisQueueRedis::send("inquiry-sync", $data2); - // // 同步询单到crm - - return $this->successResponse([], '跟单操作成功'); - } else { - // Db::rollBack(); - return $this->errorResponse('请求方式错误'); - } - } catch (\Throwable $th) { - // Db::rollBack(); - fileLog($th->getFile()."|".$th->getLine()."|".$th->getMessage()); - return $this->errorResponse($th->getMessage()); - } - } - - // 详情 - public function detail(Request $request) - { - if ($request->method() == "POST") { - $id = $request->all("id"); - $res = InquiryLogModel::where("id", $id)->first()->toArray(); - return $this->successResponse(["detail"=>$res["log_content"]], '操作成功'); - - } - return view('inquiry-log/detail'); - } - - // 客服分单给业务 + /** + * 分配 + * + * @param Request $request + * @return mixed + */ public function allocation(Request $request) { - // Db::beginTransaction(); try { - if ($request->method() == "POST") { - $data = $request->all(); - - $userInfo = UsersModel::where("id", $data["gd_user"])->first(); - if (!$userInfo) { - // Db::rollBack(); - return $this->errorResponse('用户未找到'); - } - - $model = new InquiryLogModel(); - $info = $model->where("id", $data["id"])->first(); - if (!$info) { - // Db::rollBack(); - return $this->errorResponse('询单未找到'); - } - - $uomodel = new UserOrderModel(); - $uoInfo = $uomodel->where("log_id", $data["id"])->first(); - if (!$uoInfo) { - // 记录跟单 - $HsUserOrderModel = new UserOrderModel(); - $HsUserOrderModel->uid = $data["gd_user"]; - $HsUserOrderModel->log_id = $data["id"]; - $HsUserOrderModel->score = (new InquiryLogModel())->score($info->log_quality, $info->r_time); - if (!$HsUserOrderModel->save()) { - // Db::rollBack(); - return $this->errorResponse('记录跟单操作失败,请重试'); - } - } else { - $uoInfo->uid = $data["gd_user"]; - if (!$uoInfo->save()) { - // Db::rollBack(); - return $this->errorResponse('操作失败,请重试'); - } - } - - if ($info->status != 2) { - $info->t_time = time(); - $info->status = 2; - } - $info->recipient = $data["gd_user"]; - if (!$info->save()) { - // Db::rollBack(); - return $this->errorResponse('操作失败,请重试'); - } - // Db::commit(); - - // 发送飞书群消息通知 - $data1 = ["order_id"=>$data["id"]]; - RedisQueueRedis::send("allocation", $data1); - // 发送飞书群消息通知 - - // // 同步询单到crm - $data2 = ["order_id"=>$data["id"]]; - RedisQueueRedis::send("inquiry-sync", $data2); - // // 同步询单到crm - - return $this->successResponse([], '操作成功'); - } - return view('inquiry-log/allocation'); - } catch (\Throwable $th) { - // Db::rollBack(); - fileLog($th->getFile()."|".$th->getLine()."|".$th->getMessage()); - return $this->errorResponse($th->getMessage()); + $data = $this->validate($this->service->getValidator(), $request->post(), 'allocation'); + $res = $this->service->serviceAllocation($request, $data); + return $this->success([], '分配成功'); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); } } diff --git a/app/inquiry/service/InquiryLogService.php b/app/inquiry/service/InquiryLogService.php index 754280d..05b371d 100644 --- a/app/inquiry/service/InquiryLogService.php +++ b/app/inquiry/service/InquiryLogService.php @@ -5,6 +5,7 @@ namespace app\inquiry\service; use app\common\validate\InquiryLogValidate; use app\common\traits\crud\CrudServiceTrait; use app\common\model\InquiryLog; +use support\exception\BusinessException; use support\Request; class InquiryLogService @@ -30,7 +31,31 @@ class InquiryLogService return new $this->validator; } + /** + * 发布 + */ + public function serviceRelease(Request $request, array $data = []) + { + $data = $this->preProcess('Release', $data, $request); + $config = $this->buildQueryConfig($request, 'release'); + $updated = $this->logicUpdateBy($config, $data); + return $this->postProcess('Release', $updated); + } + /** + * 分配 + */ + public function serviceAllocation(Request $request, array $data = []) + { + $data = $this->preProcess('Allocation', $data, $request); + $config = $this->buildQueryConfig($request, 'allocation'); + $updated = $this->logicUpdateBy($config, $data); + return $this->postProcess('Allocation', $updated); + } + + /** + * 构建查询条件 + */ protected function buildQueryConfig(Request $request, string $scene = 'index'): array { $p = $request->all(); @@ -39,19 +64,18 @@ class InquiryLogService $config['model'] = $this->modelClass; switch ($scene) { case 'index': - // 排序 + // ====== ====== 排序 ====== ====== $config['order']['id'] = 'desc'; + // ====== ====== 筛选 ====== ====== // 渠道 if (isset($p['channel']) && $p['channel']) { $config['where']['channel'] = $p['channel']; } - // 国家 if (isset($p['country']) && $p['country']) { $config['where']['country'] = $p['country']; } - // 时间 if (isset($p['time']) && $p['time']) { $time = explode(' - ', $p['time']); @@ -59,12 +83,10 @@ class InquiryLogService 'between', [strtotime($time[0]), strtotime($time[1])] ]; } - // 状态 if (isset($p['status']) && $p['status']) { $config['where']['status'] = $p['status']; } - // 关键字 if (isset($p['keyword']) && $p['keyword']) { $k = '%' . $p['keyword'] . '%'; @@ -73,28 +95,29 @@ class InquiryLogService } } - // 关联 + // ====== ====== 关联 ====== ====== $config['with']['country'][] = 'cn_addr'; + $config['with']['country'][] = 'steering'; $config['with']['enter'][] = 'name'; $config['with']['recipient'][] = 'name'; $config['with']['channel'][] = 'name'; break; case 'show': - $config['where']['id'] = $p['id']; - break; - case 'store': - break; case 'update': - $config['where']['id'] = $p['id']; - break; case 'destroy': + case 'release': + case 'allocation': $config['where']['id'] = $p['id']; + case 'store': break; } return $config; } + /** + * 添加前置处理 + */ public function beforeServiceStore($data, Request $request) { $data['order_no'] = orderNum(); @@ -106,10 +129,37 @@ class InquiryLogService return $data; } - // public function afterServiceList($data) - // { - // var_dump($data); + /** + * 发布前置处理 + */ + public function beforeServiceRelease($data, Request $request) + { + $info = $this->findByPk($request->post('id')); + if (!$info) { + throw new BusinessException('数据不存在'); + } + if ($info->status != 0) { + throw new BusinessException('询单已发布'); + } + $data['r_time'] = time(); + $data['status'] = 1; + return $data; + } - // return $data; - // } + /** + * 分配前置处理 + */ + public function beforeServiceAllocation($data, Request $request) + { + $info = $this->findByPk($request->post('id')); + if (!$info) { + throw new BusinessException('数据不存在'); + } + if ($info->status == 2) { + throw new BusinessException('询单已被分配'); + } + $data['t_time'] = time(); + $data['status'] = 2; + return $data; + } } \ No newline at end of file diff --git a/config/route.php b/config/route.php index 6238ffd..ddd93d8 100644 --- a/config/route.php +++ b/config/route.php @@ -81,6 +81,8 @@ Route::group('/admin', function () { Route::any('/store', [app\inquiry\controller\InquiryLogController::class, 'store']); Route::any('/update', [app\inquiry\controller\InquiryLogController::class, 'update']); Route::any('/destroy', [app\inquiry\controller\InquiryLogController::class, 'destroy']); + Route::any('/release', [app\inquiry\controller\InquiryLogController::class, 'release']); + Route::any('/allocation', [app\inquiry\controller\InquiryLogController::class, 'allocation']); }); });