领取公海客户审批

pull/10/head
张萌 2 years ago
parent 9a3badcb4f
commit 44688b3db7

@ -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::BUSINESS_PASS,
self::CUSTOMER_PASS, self::CUSTOMER_PASS,
self::CONTRACT_END, self::CONTRACT_END,
self::CUSTOMER_TO_DO, self::CUSTOMER_CHECK_TO_DO,
self::CUSTOMER_CHECK_REJECT,
self::CUSTOMER_CHECK_PASS,
], ],
'jxc' => [ 'jxc' => [
self::PURCHASE_TO_DO, self::PURCHASE_TO_DO,
@ -566,7 +576,9 @@ class Message extends Common
case self::TEAM_CONTRACT: case self::TEAM_CONTRACT:
return ContractModel::where(['contract_id' => $data['action_id']])->value('name') ?: ''; 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') ?: ''; return CustomerCheck::where(['customer_check_id' => $data['action_id']])->value('name') ?: '';
// 回款 // 回款

@ -9,6 +9,8 @@
namespace app\crm\controller; namespace app\crm\controller;
use app\admin\controller\ApiCommon; use app\admin\controller\ApiCommon;
use app\admin\model\Message;
use app\admin\model\User;
use app\crm\logic\CustomerPoolLogic; use app\crm\logic\CustomerPoolLogic;
use think\Hook; use think\Hook;
use think\Request; use think\Request;
@ -408,15 +410,129 @@ class CustomerPool extends ApiCommon
*/ */
public function checkCustomerReveive() public function checkCustomerReveive()
{ {
if (empty($this->param['customer_id'])) return resultArray(['error' => '请选择要领取的公海客户!']);
$param = $this->param; $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' => '审批失败,请重试!']);
}
} }
} }

@ -315,7 +315,7 @@ class CustomerCheck extends Common
$send_user_id = stringToArray($param['check_user_id']); $send_user_id = stringToArray($param['check_user_id']);
if ($send_user_id && empty($param['check_status'])) { if ($send_user_id && empty($param['check_status'])) {
(new Message())->send( (new Message())->send(
Message::CUSTOMER_TO_DO, Message::CUSTOMER_CHECK_TO_DO,
[ [
'title' => $param['name'], 'title' => $param['name'],
'action_id' => $v['customer_check_id'] 'action_id' => $v['customer_check_id']

@ -71,6 +71,8 @@ return [
'crm/customerPool/authority' => ['crm/customerPool/authority', ['method' => 'POST']], 'crm/customerPool/authority' => ['crm/customerPool/authority', ['method' => 'POST']],
// 【客户】领取公海客户 // 【客户】领取公海客户
'crm/customerPool/receive' => ['crm/customerPool/receive', ['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']], 'crm/customerPool/distribute' => ['crm/customerPool/distribute', ['method' => 'POST']],
// 【客户】删除公海客户 // 【客户】删除公海客户

Loading…
Cancel
Save