From 44688b3db75889761b6f9c1e66e27f59c5cfe3ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=90=8C?= <494089941@qq.com> Date: Sun, 5 Mar 2023 22:41:44 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=86=E5=8F=96=E5=85=AC=E6=B5=B7=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E5=AE=A1=E6=89=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/model/Message.php | 18 ++- application/crm/controller/CustomerPool.php | 128 +++++++++++++++++++- application/crm/model/CustomerCheck.php | 2 +- config/route_crm.php | 2 + 4 files changed, 140 insertions(+), 10 deletions(-) diff --git a/application/admin/model/Message.php b/application/admin/model/Message.php index 17a7af5..9edea23 100644 --- a/application/admin/model/Message.php +++ b/application/admin/model/Message.php @@ -269,7 +269,15 @@ class Message extends Common /** * 客户待审批 */ - const CUSTOMER_TO_DO = 57; + const CUSTOMER_CHECK_TO_DO = 57; + /** + * 客户待审批 + */ + const CUSTOMER_CHECK_REJECT = 58; + /** + * 客户待审批 + */ + const CUSTOMER_CHECK_PASS = 59; /** * 消息类型 @@ -428,7 +436,9 @@ class Message extends Common self::BUSINESS_PASS, self::CUSTOMER_PASS, self::CONTRACT_END, - self::CUSTOMER_TO_DO, + self::CUSTOMER_CHECK_TO_DO, + self::CUSTOMER_CHECK_REJECT, + self::CUSTOMER_CHECK_PASS, ], 'jxc' => [ self::PURCHASE_TO_DO, @@ -566,7 +576,9 @@ class Message extends Common case self::TEAM_CONTRACT: return ContractModel::where(['contract_id' => $data['action_id']])->value('name') ?: ''; // 客户 - case self::CUSTOMER_TO_DO: + case self::CUSTOMER_CHECK_TO_DO: + case self::CUSTOMER_CHECK_PASS: + case self::CUSTOMER_CHECK_REJECT: return CustomerCheck::where(['customer_check_id' => $data['action_id']])->value('name') ?: ''; // 回款 diff --git a/application/crm/controller/CustomerPool.php b/application/crm/controller/CustomerPool.php index bfd75e5..8ee24a8 100644 --- a/application/crm/controller/CustomerPool.php +++ b/application/crm/controller/CustomerPool.php @@ -9,6 +9,8 @@ namespace app\crm\controller; use app\admin\controller\ApiCommon; +use app\admin\model\Message; +use app\admin\model\User; use app\crm\logic\CustomerPoolLogic; use think\Hook; use think\Request; @@ -408,15 +410,129 @@ class CustomerPool extends ApiCommon */ public function checkCustomerReveive() { - if (empty($this->param['customer_id'])) return resultArray(['error' => '请选择要领取的公海客户!']); - $param = $this->param; - $param['user_id'] = $this->userInfo['id']; + $userInfo = $this->userInfo; + $user_id = $userInfo['id']; + $customerCheckModel = model('CustomerCheck'); + $examineStepModel = new \app\admin\model\ExamineStep(); + $examineRecordModel = new \app\admin\model\ExamineRecord(); + $examineFlowModel = new \app\admin\model\ExamineFlow(); + $customerModel = model('Customer'); - $result = (new CustomerPoolLogic())->customerReceiveExamine($param); + $customerCheckData = []; + $customerCheckData['update_time'] = time(); + $customerCheckData['check_status'] = 1; //0待审核,1审核通中,2审核通过,3审核未通过 + //权限判断 + if (!$examineStepModel->checkExamine($user_id, 'crm_contract', $param['id'])) { + return resultArray(['error' => $examineStepModel->getError()]); + } + //审批主体详情 + $dataInfo = db('crm_customer_check')->where('customer_id', 'in', $param['customer_id'])->find(); + $flowInfo = $examineFlowModel->getDataById($dataInfo['flow_id']); + $is_end = 0; // 1审批结束 - if (!empty($result)) return resultArray(['error' => $result]); + $status = $param['status'] ? 1 : 0; //1通过,0驳回 + $checkData = []; + $checkData['check_user_id'] = $user_id; + $checkData['types'] = 'crm_customer_check'; + $checkData['types_id'] = $param['id']; + $checkData['check_time'] = time(); + $checkData['content'] = $param['content']; + $checkData['flow_id'] = $dataInfo['flow_id']; + $checkData['order_id'] = $dataInfo['order_id'] ? : 1; + $checkData['status'] = $status; - return resultArray(['data' => '领取成功!']); + if ($status == 1) { + if ($flowInfo['config'] == 1) { + //固定流程 + //获取下一审批信息 + $nextStepData = $examineStepModel->nextStepUser($dataInfo['owner_user_id'], $dataInfo['flow_id'], 'crm_customer_check', $param['id'], $dataInfo['order_id'], $user_id); + $next_user_ids = $nextStepData['next_user_ids'] ? : []; + $customerCheckData['order_id'] = $nextStepData['order_id'] ? : ''; + if (!$next_user_ids) { + $is_end = 1; + //审批结束 + $checkData['check_status'] = !empty($status) ? 2 : 3; + $customerCheckData['check_user_id'] = ''; + } else { + //修改主体相关审批信息 + $customerCheckData['check_user_id'] = arrayToString($next_user_ids); + } + } else { + //自选流程 + $is_end = $param['is_end'] ? 1 : ''; + $check_user_id = $param['check_user_id'] ? : ''; + if ($is_end !== 1 && empty($check_user_id)) { + return resultArray(['error' => '请选择下一审批人']); + } + $customerCheckData['check_user_id'] = arrayToString($param['check_user_id']); + } + if ($is_end == 1) { + $checkData['check_status'] = !empty($status) ? 2 : 3; + $customerCheckData['check_user_id'] = ''; + $customerCheckData['check_status'] = 2; + } + } else { + //审批驳回 + $is_end = 1; + $customerCheckData['check_status'] = 3; + //将审批记录至为无效 + // $examineRecordModel->setEnd(['types' => 'crm_contract','types_id' => $param['id']]); + } + //已审批人ID + $customerCheckData['flow_user_id'] = stringToArray($dataInfo['flow_user_id']) ? arrayToString(array_merge(stringToArray($dataInfo['flow_user_id']),[$user_id])) : arrayToString([$user_id]); + $resCustomerCheck = db('crm_customer_check')->where(['customer_check_id' => $param['id']])->update($customerCheckData); + if ($resCustomerCheck) { + //审批记录 + $resRecord = $examineRecordModel->createData($checkData); + //审核通过,修改相关信息 + if ($is_end == 1 && !empty($status)) { + // 审批通过消息告知负责人 + (new Message())->send( + Message::CONTRACT_PASS, + [ + 'title' => $dataInfo['name'], + 'action_id' => $param['id'] + ], + $dataInfo['owner_user_id'] + ); + + $customerData = []; + $customerData['user_id']=$dataInfo['user_id']; + $customerData['customer_id']=$dataInfo['customer_id']; + + $result = (new CustomerPoolLogic())->receiveCustomers($customerData); + + if (!empty($result)) return resultArray(['error' => $result]); + + return resultArray(['data' => '领取成功!']); + } else { + if ($status) { + //发送站内信 + // 通过未完成,发送消息给 + (new Message())->send( + Message::CUSTOMER_CHECK_TO_DO, + [ + 'from_user' => User::where(['id' => $dataInfo['owner_user_id']])->value('realname'), + 'title' => $dataInfo['name'], + 'action_id' => $param['id'] + ], + stringToArray($customerCheckData['check_user_id']) + ); + } else { + (new Message())->send( + Message::CONTRACT_REJECT, + [ + 'title' => $dataInfo['name'], + 'action_id' => $param['id'] + ], + $dataInfo['owner_user_id'] + ); + } + } + return resultArray(['data' => '审批成功']); + } else { + return resultArray(['error' => '审批失败,请重试!']); + } } } diff --git a/application/crm/model/CustomerCheck.php b/application/crm/model/CustomerCheck.php index 7f2a98a..03f99af 100644 --- a/application/crm/model/CustomerCheck.php +++ b/application/crm/model/CustomerCheck.php @@ -315,7 +315,7 @@ class CustomerCheck extends Common $send_user_id = stringToArray($param['check_user_id']); if ($send_user_id && empty($param['check_status'])) { (new Message())->send( - Message::CUSTOMER_TO_DO, + Message::CUSTOMER_CHECK_TO_DO, [ 'title' => $param['name'], 'action_id' => $v['customer_check_id'] diff --git a/config/route_crm.php b/config/route_crm.php index 84ba21f..3816afc 100644 --- a/config/route_crm.php +++ b/config/route_crm.php @@ -71,6 +71,8 @@ return [ 'crm/customerPool/authority' => ['crm/customerPool/authority', ['method' => 'POST']], // 【客户】领取公海客户 'crm/customerPool/receive' => ['crm/customerPool/receive', ['method' => 'POST']], + // 【客户】领取公海客户审批 + 'crm/customerPool/checkCustomerReveive' => ['crm/customerPool/checkCustomerReveive', ['method' => 'POST']], // 【客户】分配公海客户 'crm/customerPool/distribute' => ['crm/customerPool/distribute', ['method' => 'POST']], // 【客户】删除公海客户