|
|
@ -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' => '审批失败,请重试!']);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|