diff --git a/application/admin/model/Message.php b/application/admin/model/Message.php index 9edea23..2719292 100644 --- a/application/admin/model/Message.php +++ b/application/admin/model/Message.php @@ -278,6 +278,22 @@ class Message extends Common * 客户待审批 */ const CUSTOMER_CHECK_PASS = 59; + /** + * 商机推进待审批 + */ + const BUSINESS_ADVANCE_CHECK_TO_DO = 60; + /** + * 商机推进待审批 + */ + const BUSINESS_ADVANCE_CHECK_REJECT = 61; + /** + * 商机推进待审批 + */ + const BUSINESS_ADVANCE_CHECK_PASS = 62; + /** + * 新商机 + */ + const BUSINESS_NEW = 63; /** * 消息类型 @@ -389,6 +405,9 @@ class Message extends Common 32 => [ 'template' => '{from_user} 将您添加为线索 {title} 的成员。', ], + 63 => [ + 'template' => '{from_user} 创建了新的商机', + ] ]; /** @@ -439,6 +458,10 @@ class Message extends Common self::CUSTOMER_CHECK_TO_DO, self::CUSTOMER_CHECK_REJECT, self::CUSTOMER_CHECK_PASS, + self::BUSINESS_ADVANCE_CHECK_TO_DO, + self::BUSINESS_ADVANCE_CHECK_REJECT, + self::BUSINESS_ADVANCE_CHECK_PASS, + self::BUSINESS_NEW, ], 'jxc' => [ self::PURCHASE_TO_DO, @@ -580,7 +603,6 @@ class Message extends Common case self::CUSTOMER_CHECK_PASS: case self::CUSTOMER_CHECK_REJECT: return CustomerCheck::where(['customer_check_id' => $data['action_id']])->value('name') ?: ''; - // 回款 case self::RECEIVABLES_TO_DO: case self::RECEIVABLES_REJECT: @@ -610,6 +632,10 @@ class Message extends Common // 商机 case self::TEAM_BUSINESS: case self::BUSINESS_PASS: + case self::BUSINESS_ADVANCE_CHECK_TO_DO: + case self::BUSINESS_ADVANCE_CHECK_REJECT: + case self::BUSINESS_ADVANCE_CHECK_PASS: + case self::BUSINESS_NEW: return BusinessModel::where(['business_id' => $data['action_id']])->value('name') ?: ''; // 采购单 diff --git a/application/crm/controller/Business.php b/application/crm/controller/Business.php index f5d8b28..2f1dd4f 100644 --- a/application/crm/controller/Business.php +++ b/application/crm/controller/Business.php @@ -8,6 +8,9 @@ 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 app\crm\traits\SearchConditionTrait; use app\crm\traits\StarTrait; use think\Hook; @@ -28,7 +31,7 @@ class Business extends ApiCommon { $action = [ 'permission' => [''], - 'allow' => ['statuslist', 'advance', 'product', 'system', 'count', 'setprimary'] + 'allow' => ['statuslist', 'advance', 'product', 'system', 'count', 'setprimary', 'check'] ]; Hook::listen('check_auth', $action); $request = Request::instance(); @@ -372,7 +375,7 @@ class Business extends ApiCommon } /** - * 商机状态推进 + * 商机审批提交 * @param business_id 商机ID * @param status_id 推进商机状态ID * @return @@ -381,31 +384,91 @@ class Business extends ApiCommon public function advance() { $param = $this->param; + $examineStepModel = new \app\admin\model\ExamineStep(); + $examineStatus = $param['examineStatus'] ?? 1; // 审批是否停用 $userInfo = $this->userInfo; $userModel = new \app\admin\model\User(); $is_end = $param['is_end'] ?: 0; //1赢单2输单3无效 $remark = $param['statusRemark']; + $param['check_user_id'] = 1;// 临时测试需删除 + unset($param['examineStatus']); + if (!$param['business_id']) { return resultArray(['error' => '参数错误']); } $businessInfo = db('crm_business')->where(['business_id' => $param['business_id']])->find(); if ($businessInfo['is_end']) { - return resultArray(['error' => '已结束,不能推进']); + return resultArray(['error' => '已结束,请勿重复提交']); + } + if ($businessInfo['flow_id']) { + return resultArray(['error' => '已有审批流程,请勿重复提交']); } $data = []; - $data['update_time'] = time(); - $data['is_end'] = $is_end; - $data['remark'] = $remark; - $data['check_status'] = 1; - $data['flow_id'] = 13; - $data['check_user_id'] = $param['check_user_id']; - $data['flow_user_id'] = $param['check_user_id']; + $data['submit_end_status'] = $is_end; + $data['submit_remark'] = $remark; + if (($examineStatus != false && $examineStatus != 'false') || $examineStatus == 1) { + // 审核判断(是否有符合条件的审批流) + $examineFlowModel = new \app\admin\model\ExamineFlow(); + if (!$examineFlowModel->checkExamine($userInfo['user_id'], 'crm_business')) { + return '暂无审批人,无法创建'; + } + //添加审批相关信息 + $examineFlowData = $examineFlowModel->getFlowByTypes($userInfo['user_id'], 'crm_business'); + if (!$examineFlowData) { + return '无可用审批流,请联系管理员'; + } + $data['flow_id'] = $examineFlowData['flow_id']; + //获取审批人信息 + if ($examineFlowData['config'] == 1) { + //固定审批流 + $nextStepData = $examineStepModel->nextStepUser($userInfo['user_id'], $examineFlowData['flow_id'], 'crm_business', 0, 0, 0); + $next_user_ids = arrayToString($nextStepData['next_user_ids']) ?: ''; + $check_user_id = $next_user_ids ?: []; + $data['order_id'] = 1; + } else { + $check_user_id = $param['check_user_id'] ? ',' . $param['check_user_id'] . ',' : ''; + } + if (!$check_user_id) { + return '无可用审批人,请联系管理员'; + } + $data['check_user_id'] = is_array($check_user_id) ? ',' . implode(',', $check_user_id) . ',' : $check_user_id; + } else { + # 审批流停用,将状态改为审核通过 + // $param['check_status'] = 2; + # 审批流停用,将状态改为正常 zjf 20210727 默认值为7 + $data['check_status'] = 7; + } $res = db('crm_business')->where(['business_id' => $param['business_id']])->update($data); if (!$res) { - return resultArray(['error' => '推进失败,请重试']); + return resultArray(['error' => '提交失败,请重试']); } + //站内信 + $send_user_id = stringToArray($param['check_user_id']); + if ($send_user_id && empty($param['check_status'])) { + (new Message())->send( + Message::CUSTOMER_CHECK_TO_DO, + [ + 'title' => $param['name'], + 'action_id' => param['business_id'], + ], + $send_user_id + ); + } + + # 创建待办事项的关联数据 + $checkUserIds = db('crm_business')->where('business_id', $param['business_id'])->value('check_user_id'); + $checkUserIdArray = stringToArray($checkUserIds); + $dealtData = []; + foreach ($checkUserIdArray as $kk => $vv) { + $dealtData[] = [ + 'types' => 'crm_business', + 'types_id' => $param['business_id'], + 'user_id' => $vv + ]; + } + if (!empty($dealtData)) db('crm_dealt_relation')->insertAll($dealtData); return resultArray(['success' => '提交成功']); } @@ -569,111 +632,218 @@ class Business extends ApiCommon public function check() { - $param = $this->param; $userInfo = $this->userInfo; - $userModel = new \app\admin\model\User(); -// $is_end = $param['is_end'] ?: 0; //1赢单2输单3无效 -// $remark = $param['statusRemark']; - $check_status = $param['check_status']; - if (!$param['business_id']) { - return resultArray(['error' => '参数错误']); + $user_id = $userInfo['id']; + $businessModel = model('Business'); + $examineStepModel = new \app\admin\model\ExamineStep(); + $examineRecordModel = new \app\admin\model\ExamineRecord(); + $examineFlowModel = new \app\admin\model\ExamineFlow(); + $customerModel = model('Customer'); + + $businessCheckData = []; + $businessCheckData['update_time'] = time(); + $businessCheckData['check_status'] = 1; //0待审核,1审核通中,2审核通过,3审核未通过 + //权限判断 + if (!$examineStepModel->checkExamine($user_id, 'crm_business', $param['id'])) { + return resultArray(['error' => $examineStepModel->getError()]); } - - if ($check_status == 2) { - $businessInfo = db('crm_business')->where(['business_id' => $param['business_id']])->find(); -// if ($businessInfo['is_end']) { -// return resultArray(['error' => '已结束,不能推进']); -// } - - //判断权限 - $auth_user_ids = $userModel->getUserByPer('crm', 'business', 'update'); - //读写权限 - $rwPre = $userModel->rwPre($userInfo['id'], $businessInfo['ro_user_id'], $businessInfo['rw_user_id'], 'update'); - if (!in_array($businessInfo['owner_user_id'], $auth_user_ids) && !$rwPre) { - header('Content-Type:application/json; charset=utf-8'); - exit(json_encode(['code' => 102, 'error' => '无权操作'])); + //审批主体详情 + $dataInfo = $businessModel->getDataById($param['id']); + $flowInfo = $examineFlowModel->getDataById($dataInfo['flow_id']); + $is_end = 0; // 1审批结束 + + $status = $param['status'] ? 1 : 0; //1通过,0驳回 + $checkData = []; + $checkData['check_user_id'] = $user_id; + $checkData['types'] = 'crm_business'; + $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; + + if ($status == 1) { + if ($flowInfo['config'] == 1) { + //固定流程 + //获取下一审批信息 + $nextStepData = $examineStepModel->nextStepUser($dataInfo['owner_user_id'], $dataInfo['flow_id'], 'crm_business', $param['id'], $dataInfo['order_id'], $user_id); + $next_user_ids = $nextStepData['next_user_ids'] ?: []; + $businessCheckData['order_id'] = $nextStepData['order_id'] ?: ''; + if (!$next_user_ids) { + $is_end = 1; + //审批结束 + $checkData['check_status'] = !empty($status) ? 2 : 3; + $businessCheckData['check_user_id'] = ''; + } else { + //修改主体相关审批信息 + $businessCheckData['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' => '请选择下一审批人']); + } + $businessCheckData['check_user_id'] = arrayToString($param['check_user_id']); } - - $status_id = $param['status_id'] ?: $businessInfo['status_id']; - $statusInfo = db('crm_business_status')->where(['type_id' => $businessInfo['type_id'], 'status_id' => $status_id])->find(); - if (!$statusInfo && $businessInfo['is_end']) { - return resultArray(['error' => '参数错误']); + if ($is_end == 1) { + $checkData['check_status'] = !empty($status) ? 2 : 3; + $businessCheckData['check_user_id'] = ''; + $businessCheckData['check_status'] = 2; } - $data = []; - $data['update_time'] = time(); -// $data['is_end'] = $is_end; -// $data['remark'] = $remark; - $data['check_status'] = $check_status; - $data['status_id'] = $status_id; - $data['status_time'] = time(); - $res = db('crm_business')->where(['business_id' => $param['business_id']])->update($data); - if (!$res) { - return resultArray(['error' => '推进失败,请重试']); + } else { + //审批驳回 + $is_end = 1; + $businessCheckData['check_status'] = 3; + //将审批记录至为无效 + // $examineRecordModel->setEnd(['types' => 'crm_contract','types_id' => $param['id']]); + } + //已审批人ID + $businessCheckData['flow_user_id'] = stringToArray($dataInfo['flow_user_id']) ? arrayToString(array_merge(stringToArray($dataInfo['flow_user_id']), [$user_id])) : arrayToString([$user_id]); + $resCustomerCheck = db('crm_business')->where(['business_id' => $param['id']])->update($businessCheckData); + if ($resCustomerCheck) { + //审批记录 + $resRecord = $examineRecordModel->createData($checkData); + //审核通过,修改相关信息 + if ($is_end == 1 && !empty($status)) { + // 审批通过消息告知负责人 + (new Message())->send( + Message::BUSINESS_ADVANCE_CHECK_PASS, + [ + 'title' => $dataInfo['name'], + 'action_id' => $param['id'] + ], + $dataInfo['owner_user_id'] + ); + + $businessData = []; + $businessData['business_id'] = $dataInfo['business_id']; + $businessData['is_end'] = $dataInfo['submit_end_status']; + $businessData['status_id'] = $dataInfo['status_id']; + $businessData['statusRemark'] = $dataInfo['submit_remark']; + + $result = $this->advanceAfterCheck($businessData); + + if (!empty($result)) return resultArray(['error' => $result]); + + return resultArray(['data' => '领取成功!']); } else { - # 商机变更后的名称 - $businessStatusName = Db::name('crm_business_status')->where('status_id', $param['status_id'])->value('name'); - if (empty($businessStatusName) && $businessInfo['is_end'] == 1) $businessStatusName = '赢单'; - if (empty($businessStatusName) && $businessInfo['is_end'] == 2) $businessStatusName = '输单'; - if (empty($businessStatusName) && $businessInfo['is_end'] == 3) $businessStatusName = '无效'; - # 添加活动记录 - Db::name('crm_activity')->insert([ - 'type' => 3, - 'activity_type' => 5, - 'activity_type_id' => $businessInfo['business_id'], - 'content' => '阶段变更为 ' . $businessStatusName, - 'create_user_id' => $businessInfo['owner_user_id'], - 'update_time' => time(), - 'create_time' => time(), - 'customer_ids' => ',' . $businessInfo['customer_id'] . ',' - ]); - - # 删除待办事项的关联数据 - db('crm_dealt_relation')->where(['types' => ['eq', 'crm_business'], 'types_id' => ['eq', $data['business_id']]])->delete(); - # 创建待办事项的关联数据 - $checkUserIds = db('crm_business')->where('business_id', $data['business_id'])->value('check_user_id'); - $checkUserIdArray = stringToArray($checkUserIds); - $dealtData = []; - foreach ($checkUserIdArray AS $kk => $vv) { - $dealtData[] = [ - 'types' => 'crm_business', - 'types_id' => $data['business_id'], - 'user_id' => $vv - ]; + if ($status) { + //发送站内信 + // 通过未完成,发送消息给 + (new Message())->send( + Message::BUSINESS_ADVANCE_CHECK_TO_DO, + [ + 'from_user' => User::where(['id' => $dataInfo['owner_user_id']])->value('realname'), + 'title' => $dataInfo['name'], + 'action_id' => $param['id'] + ], + stringToArray($businessCheckData['check_user_id']) + ); + } else { + (new Message())->send( + Message::BUSINESS_ADVANCE_CHECK_REJECT, + [ + 'title' => $dataInfo['name'], + 'action_id' => $param['id'] + ], + $dataInfo['owner_user_id'] + ); } - if (!empty($dealtData)) db('crm_dealt_relation')->insertAll($dealtData); - - //推进记录添加 - $temp['status_id'] = $status_id ?: 0; - $temp['is_end'] = $businessInfo['is_end'] ?: 0; - $temp['business_id'] = $param['business_id']; - $temp['create_time'] = time(); - $temp['owner_user_id'] = $userInfo['id']; - $temp['remark'] = $param['statusRemark'] ?: ''; - Db::name('CrmBusinessLog')->insert($temp); - - # 返回商机阶段数据 - $typeId = db('crm_business')->where('business_id', $param['business_id'])->value('type_id'); - $businessStatus = db('crm_business_status')->where('type_id', $typeId)->select(); - $result = [ - 'business_id' => $param['business_id'], - 'type_id' => $typeId, - 'status_id' => $param['status_id'], - 'status_list' => $businessStatus - ]; - - return resultArray(['data' => $result]); } + return resultArray(['data' => '审批成功']); } else { - $data = []; - $data['update_time'] = time(); - $data['is_end'] = 0; - $data['remark'] = ''; - $data['check_status'] = $check_status; - $res = db('crm_business')->where(['business_id' => $param['business_id']])->update($data); - if (!$res) { - return resultArray(['error' => '推进失败,请重试']); - } + return resultArray(['error' => '审批失败,请重试!']); + } + + } + + /** + * 审核后商机状态推进 + * @param business_id 商机ID + * @param status_id 推进商机状态ID + * @return + * @author Michael_xu + */ + private function advanceAfterCheck($param) + { + $userInfo = $this->userInfo; + $userModel = new \app\admin\model\User(); + $is_end = $param['is_end'] ?: 0; //1赢单2输单3无效 + if (!$param['business_id']) { + return resultArray(['error' => '参数错误']); + } + $businessInfo = db('crm_business')->where(['business_id' => $param['business_id']])->find(); + if ($businessInfo['is_end']) { + return resultArray(['error' => '已结束,不能推进']); + } + //判断权限 + $auth_user_ids = $userModel->getUserByPer('crm', 'business', 'update'); + //读写权限 + $rwPre = $userModel->rwPre($userInfo['id'], $businessInfo['ro_user_id'], $businessInfo['rw_user_id'], 'update'); + if (!in_array($businessInfo['owner_user_id'], $auth_user_ids) && !$rwPre) { + header('Content-Type:application/json; charset=utf-8'); + exit(json_encode(['code' => 102, 'error' => '无权操作'])); + } + + $status_id = $param['status_id'] ?: $businessInfo['status_id']; + $statusInfo = db('crm_business_status')->where(['type_id' => $businessInfo['type_id'], 'status_id' => $status_id])->find(); + if (!$statusInfo && !$is_end) { + return resultArray(['error' => '参数错误']); + } + $data = []; + $data['update_time'] = time(); + $data['is_end'] = $is_end; +// if ($is_end) { +// $status_id = $is_end; +// } + $data['status_id'] = $status_id; + $data['status_time'] = time(); + $data['submit_remark'] = $param['submit_remark']; + $res = db('crm_business')->where(['business_id' => $param['business_id']])->update($data); + if (!$res) { + return resultArray(['error' => '推进失败,请重试']); + } else { + # 商机变更后的名称 + $businessStatusName = Db::name('crm_business_status')->where('status_id', $param['status_id'])->value('name'); + if (empty($businessStatusName) && $is_end == 1) $businessStatusName = '赢单'; + if (empty($businessStatusName) && $is_end == 2) $businessStatusName = '输单'; + if (empty($businessStatusName) && $is_end == 3) $businessStatusName = '无效'; + # 添加活动记录 + Db::name('crm_activity')->insert([ + 'type' => 3, + 'activity_type' => 5, + 'activity_type_id' => $businessInfo['business_id'], + 'content' => '阶段变更为 ' . $businessStatusName, + 'create_user_id' => $businessInfo['owner_user_id'], + 'update_time' => time(), + 'create_time' => time(), + 'customer_ids' => ',' . $businessInfo['customer_id'] . ',' + ]); + + //推进记录添加 + $temp['status_id'] = $status_id ?: 0; + $temp['is_end'] = $is_end ?: 0; + $temp['business_id'] = $param['business_id']; + $temp['create_time'] = time(); + $temp['owner_user_id'] = $userInfo['id']; + $temp['remark'] = $param['statusRemark'] ?: ''; + Db::name('CrmBusinessLog')->insert($temp); + + # 返回商机阶段数据 + $typeId = db('crm_business')->where('business_id', $param['business_id'])->value('type_id'); + $businessStatus = db('crm_business_status')->where('type_id', $typeId)->select(); + $result = [ + 'business_id' => $param['business_id'], + 'type_id' => $typeId, + 'status_id' => $param['status_id'], + 'status_list' => $businessStatus + ]; + + return resultArray(['data' => $result]); } } diff --git a/application/crm/controller/CustomerPool.php b/application/crm/controller/CustomerPool.php index 79a6636..ac95f7b 100644 --- a/application/crm/controller/CustomerPool.php +++ b/application/crm/controller/CustomerPool.php @@ -490,7 +490,7 @@ class CustomerPool extends ApiCommon if ($is_end == 1 && !empty($status)) { // 审批通过消息告知负责人 (new Message())->send( - Message::CONTRACT_PASS, + Message::CUSTOMER_CHECK_PASS, [ 'title' => $dataInfo['name'], 'action_id' => $param['id'] diff --git a/application/crm/controller/Message.php b/application/crm/controller/Message.php index cdf188f..ccfc0fd 100644 --- a/application/crm/controller/Message.php +++ b/application/crm/controller/Message.php @@ -613,6 +613,8 @@ class Message extends ApiCommon if ($isSub) { $param['owner_user_id'] = array('in', getSubUserId(false)); } + $businessIdArray = db('crm_dealt_relation')->where(['types' => ['eq', 'crm_business_new'], 'user_id' => ['eq', $param['user_id']]])->column('types_id'); + $param['businessIdArray'] = !empty($businessIdArray) ? $businessIdArray : -1; $data = $businessModel->getDataList($param); // p($contractModel->getLastSql()); if ($types == 'list') { @@ -774,7 +776,7 @@ class Message extends ApiCommon } # 处理待审核合同、回款、发票 - if (in_array($type, ['checkContract', 'checkReceivables', 'checkInvoice', 'checkBusiness'])) { + if (in_array($type, ['checkContract', 'checkReceivables', 'checkInvoice', 'checkBusiness','checkCustomerCheck','new_business'])) { $where['check_status'] = ['lt', '2']; $where['check_user_id'] = ['like', ',%' . $userId . '%,']; @@ -795,8 +797,19 @@ class Message extends ApiCommon } # 商机 if ($type == 'checkBusiness') { - $invoiceId = !empty($typeId) ? $typeId : Db::name('crm_business')->where($where)->column('business_id'); - db('crm_dealt_relation')->where('user_id', $userId)->where('types', 'crm_business')->whereIn('types_id', $invoiceId)->delete(); + $businessId = !empty($typeId) ? $typeId : Db::name('crm_business')->where($where)->column('business_id'); + db('crm_dealt_relation')->where('user_id', $userId)->where('types', 'crm_business')->whereIn('types_id', $businessId)->delete(); + } + # 客户捞取 + if ($type == 'checkCustomerCheck') { + $customerCheckId = !empty($typeId) ? $typeId : Db::name('crm_customer_check')->where($where)->column('customer_check_id'); + db('crm_dealt_relation')->where('user_id', $userId)->where('types', 'crm_customer_check')->whereIn('types_id', $customerCheckId)->delete(); + } + + # 新商机 + if ($type == 'new_business') { + $newBusinessId = !empty($typeId) ? $typeId : Db::name('crm_business')->where($where)->column('business_id'); + db('crm_dealt_relation')->where('user_id', $userId)->where('types', 'crm_business_new')->whereIn('types_id', $newBusinessId)->delete(); } } @@ -884,6 +897,9 @@ class Message extends ApiCommon cache::rm('visitContractCount' . $userId); cache::rm('endContractCount' . $userId); cache::rm('remindCustomerCount' . $userId); + cache::rm('checkCustomerCheckCount' . $userId); + cache::rm('checkBusinessCount' . $userId); + cache::rm('newBusinessCount' . $userId); cache::rm('todayLeadsTime' . $userId); cache::rm('todayCustomerTime' . $userId); @@ -898,6 +914,9 @@ class Message extends ApiCommon cache::rm('visitContractTime' . $userId); cache::rm('endContractTime' . $userId); cache::rm('remindCustomerTime' . $userId); + cache::rm('checkCustomerCheckTime' . $userId); + cache::rm('checkBusinessTime' . $userId); + cache::rm('newBusinessTime' . $userId); return resultArray(['data' => '操作成功!']); } } \ No newline at end of file diff --git a/application/crm/logic/CustomerPoolLogic.php b/application/crm/logic/CustomerPoolLogic.php index 0c09184..25fd023 100644 --- a/application/crm/logic/CustomerPoolLogic.php +++ b/application/crm/logic/CustomerPoolLogic.php @@ -1139,7 +1139,6 @@ class CustomerPoolLogic extends Common $customerCheckModel = model('CustomerCheck'); $examineStepModel = new \app\admin\model\ExamineStep(); $examineStatus = $param['examineStatus'] ?? 1; // 审批是否停用 - $param['check_user_id'] =1 ;// 临时测试需删除 unset($param['examineStatus']); diff --git a/application/crm/model/Business.php b/application/crm/model/Business.php index d2caf71..1c7e92d 100644 --- a/application/crm/model/Business.php +++ b/application/crm/model/Business.php @@ -6,6 +6,7 @@ // +---------------------------------------------------------------------- namespace app\crm\model; +use app\admin\model\Message; use app\admin\traits\FieldVerificationTrait; use think\Db; use app\admin\model\Common; @@ -394,6 +395,30 @@ class Business extends Common } } + //站内信 + $send_user_id = stringToArray(getUserSuperior($param['create_user_id'])); + (new Message())->send( + Message::CUSTOMER_CHECK_TO_DO, + [ + 'title' => $param['name'], + 'action_id' => $this->business_id + ], + $send_user_id + ); + + $data = []; + $data['business_id'] = $this->business_id; + # 创建待办事项的关联数据 + $dealtData = []; + foreach ($send_user_id as $kk => $vv) { + $dealtData[] = [ + 'types' => 'crm_business_new', + 'types_id' => $data['business_id'], + 'user_id' => $vv + ]; + } + if (!empty($dealtData)) db('crm_dealt_relation')->insertAll($dealtData); + # 设置今日需联系商机 if (!empty($param['next_time']) && $param['next_time'] >= strtotime(date('Y-m-d 00:00:00'))) $param['is_dealt'] = 0; diff --git a/application/crm/model/CustomerCheck.php b/application/crm/model/CustomerCheck.php index 18d1ca9..4f6c75f 100644 --- a/application/crm/model/CustomerCheck.php +++ b/application/crm/model/CustomerCheck.php @@ -98,7 +98,7 @@ class CustomerCheck extends Common } $customerField = ''; foreach ($indexField as $k => $v) { - $customerField += 'customer.' + $v; + $customerField = 'customer.'.$v; } $list = db('crm_customer_check') @@ -108,7 +108,7 @@ class CustomerCheck extends Common ->where($partMap) ->where($dealtWhere) ->limit($request['offset'], $request['length']) - ->field('customer_check.*,customer.name as name'+$customerField) + ->field('customer_check.*,customer.name as name'.$customerField) ->orderRaw($order) ->select();