|
|
@ -8,6 +8,9 @@
|
|
|
|
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\traits\SearchConditionTrait;
|
|
|
|
use app\crm\traits\SearchConditionTrait;
|
|
|
|
use app\crm\traits\StarTrait;
|
|
|
|
use app\crm\traits\StarTrait;
|
|
|
|
use think\Hook;
|
|
|
|
use think\Hook;
|
|
|
@ -28,7 +31,7 @@ class Business extends ApiCommon
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$action = [
|
|
|
|
$action = [
|
|
|
|
'permission' => [''],
|
|
|
|
'permission' => [''],
|
|
|
|
'allow' => ['statuslist', 'advance', 'product', 'system', 'count', 'setprimary']
|
|
|
|
'allow' => ['statuslist', 'advance', 'product', 'system', 'count', 'setprimary', 'check']
|
|
|
|
];
|
|
|
|
];
|
|
|
|
Hook::listen('check_auth', $action);
|
|
|
|
Hook::listen('check_auth', $action);
|
|
|
|
$request = Request::instance();
|
|
|
|
$request = Request::instance();
|
|
|
@ -372,7 +375,7 @@ class Business extends ApiCommon
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 商机状态推进
|
|
|
|
* 商机审批提交
|
|
|
|
* @param business_id 商机ID
|
|
|
|
* @param business_id 商机ID
|
|
|
|
* @param status_id 推进商机状态ID
|
|
|
|
* @param status_id 推进商机状态ID
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
@ -381,31 +384,91 @@ class Business extends ApiCommon
|
|
|
|
public function advance()
|
|
|
|
public function advance()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$param = $this->param;
|
|
|
|
$param = $this->param;
|
|
|
|
|
|
|
|
$examineStepModel = new \app\admin\model\ExamineStep();
|
|
|
|
|
|
|
|
$examineStatus = $param['examineStatus'] ?? 1; // 审批是否停用
|
|
|
|
$userInfo = $this->userInfo;
|
|
|
|
$userInfo = $this->userInfo;
|
|
|
|
$userModel = new \app\admin\model\User();
|
|
|
|
$userModel = new \app\admin\model\User();
|
|
|
|
$is_end = $param['is_end'] ?: 0; //1赢单2输单3无效
|
|
|
|
$is_end = $param['is_end'] ?: 0; //1赢单2输单3无效
|
|
|
|
$remark = $param['statusRemark'];
|
|
|
|
$remark = $param['statusRemark'];
|
|
|
|
|
|
|
|
$param['check_user_id'] = 1;// 临时测试需删除
|
|
|
|
|
|
|
|
unset($param['examineStatus']);
|
|
|
|
|
|
|
|
|
|
|
|
if (!$param['business_id']) {
|
|
|
|
if (!$param['business_id']) {
|
|
|
|
return resultArray(['error' => '参数错误']);
|
|
|
|
return resultArray(['error' => '参数错误']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$businessInfo = db('crm_business')->where(['business_id' => $param['business_id']])->find();
|
|
|
|
$businessInfo = db('crm_business')->where(['business_id' => $param['business_id']])->find();
|
|
|
|
if ($businessInfo['is_end']) {
|
|
|
|
if ($businessInfo['is_end']) {
|
|
|
|
return resultArray(['error' => '已结束,不能推进']);
|
|
|
|
return resultArray(['error' => '已结束,请勿重复提交']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($businessInfo['flow_id']) {
|
|
|
|
|
|
|
|
return resultArray(['error' => '已有审批流程,请勿重复提交']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$data = [];
|
|
|
|
$data = [];
|
|
|
|
$data['update_time'] = time();
|
|
|
|
$data['submit_end_status'] = $is_end;
|
|
|
|
$data['is_end'] = $is_end;
|
|
|
|
$data['submit_remark'] = $remark;
|
|
|
|
$data['remark'] = $remark;
|
|
|
|
if (($examineStatus != false && $examineStatus != 'false') || $examineStatus == 1) {
|
|
|
|
$data['check_status'] = 1;
|
|
|
|
// 审核判断(是否有符合条件的审批流)
|
|
|
|
$data['flow_id'] = 13;
|
|
|
|
$examineFlowModel = new \app\admin\model\ExamineFlow();
|
|
|
|
$data['check_user_id'] = $param['check_user_id'];
|
|
|
|
if (!$examineFlowModel->checkExamine($userInfo['user_id'], 'crm_business')) {
|
|
|
|
$data['flow_user_id'] = $param['check_user_id'];
|
|
|
|
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);
|
|
|
|
$res = db('crm_business')->where(['business_id' => $param['business_id']])->update($data);
|
|
|
|
if (!$res) {
|
|
|
|
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' => '提交成功']);
|
|
|
|
return resultArray(['success' => '提交成功']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -569,111 +632,218 @@ class Business extends ApiCommon
|
|
|
|
|
|
|
|
|
|
|
|
public function check()
|
|
|
|
public function check()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
$param = $this->param;
|
|
|
|
$param = $this->param;
|
|
|
|
$userInfo = $this->userInfo;
|
|
|
|
$userInfo = $this->userInfo;
|
|
|
|
$userModel = new \app\admin\model\User();
|
|
|
|
$user_id = $userInfo['id'];
|
|
|
|
// $is_end = $param['is_end'] ?: 0; //1赢单2输单3无效
|
|
|
|
$businessModel = model('Business');
|
|
|
|
// $remark = $param['statusRemark'];
|
|
|
|
$examineStepModel = new \app\admin\model\ExamineStep();
|
|
|
|
$check_status = $param['check_status'];
|
|
|
|
$examineRecordModel = new \app\admin\model\ExamineRecord();
|
|
|
|
if (!$param['business_id']) {
|
|
|
|
$examineFlowModel = new \app\admin\model\ExamineFlow();
|
|
|
|
return resultArray(['error' => '参数错误']);
|
|
|
|
$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) {
|
|
|
|
$dataInfo = $businessModel->getDataById($param['id']);
|
|
|
|
$businessInfo = db('crm_business')->where(['business_id' => $param['business_id']])->find();
|
|
|
|
$flowInfo = $examineFlowModel->getDataById($dataInfo['flow_id']);
|
|
|
|
// if ($businessInfo['is_end']) {
|
|
|
|
$is_end = 0; // 1审批结束
|
|
|
|
// return resultArray(['error' => '已结束,不能推进']);
|
|
|
|
|
|
|
|
// }
|
|
|
|
$status = $param['status'] ? 1 : 0; //1通过,0驳回
|
|
|
|
|
|
|
|
$checkData = [];
|
|
|
|
//判断权限
|
|
|
|
$checkData['check_user_id'] = $user_id;
|
|
|
|
$auth_user_ids = $userModel->getUserByPer('crm', 'business', 'update');
|
|
|
|
$checkData['types'] = 'crm_business';
|
|
|
|
//读写权限
|
|
|
|
$checkData['types_id'] = $param['id'];
|
|
|
|
$rwPre = $userModel->rwPre($userInfo['id'], $businessInfo['ro_user_id'], $businessInfo['rw_user_id'], 'update');
|
|
|
|
$checkData['check_time'] = time();
|
|
|
|
if (!in_array($businessInfo['owner_user_id'], $auth_user_ids) && !$rwPre) {
|
|
|
|
$checkData['content'] = $param['content'];
|
|
|
|
header('Content-Type:application/json; charset=utf-8');
|
|
|
|
$checkData['flow_id'] = $dataInfo['flow_id'];
|
|
|
|
exit(json_encode(['code' => 102, 'error' => '无权操作']));
|
|
|
|
$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']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($is_end == 1) {
|
|
|
|
$status_id = $param['status_id'] ?: $businessInfo['status_id'];
|
|
|
|
$checkData['check_status'] = !empty($status) ? 2 : 3;
|
|
|
|
$statusInfo = db('crm_business_status')->where(['type_id' => $businessInfo['type_id'], 'status_id' => $status_id])->find();
|
|
|
|
$businessCheckData['check_user_id'] = '';
|
|
|
|
if (!$statusInfo && $businessInfo['is_end']) {
|
|
|
|
$businessCheckData['check_status'] = 2;
|
|
|
|
return resultArray(['error' => '参数错误']);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$data = [];
|
|
|
|
} else {
|
|
|
|
$data['update_time'] = time();
|
|
|
|
//审批驳回
|
|
|
|
// $data['is_end'] = $is_end;
|
|
|
|
$is_end = 1;
|
|
|
|
// $data['remark'] = $remark;
|
|
|
|
$businessCheckData['check_status'] = 3;
|
|
|
|
$data['check_status'] = $check_status;
|
|
|
|
//将审批记录至为无效
|
|
|
|
$data['status_id'] = $status_id;
|
|
|
|
// $examineRecordModel->setEnd(['types' => 'crm_contract','types_id' => $param['id']]);
|
|
|
|
$data['status_time'] = time();
|
|
|
|
}
|
|
|
|
$res = db('crm_business')->where(['business_id' => $param['business_id']])->update($data);
|
|
|
|
//已审批人ID
|
|
|
|
if (!$res) {
|
|
|
|
$businessCheckData['flow_user_id'] = stringToArray($dataInfo['flow_user_id']) ? arrayToString(array_merge(stringToArray($dataInfo['flow_user_id']), [$user_id])) : arrayToString([$user_id]);
|
|
|
|
return resultArray(['error' => '推进失败,请重试']);
|
|
|
|
$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 {
|
|
|
|
} else {
|
|
|
|
# 商机变更后的名称
|
|
|
|
if ($status) {
|
|
|
|
$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 = '输单';
|
|
|
|
(new Message())->send(
|
|
|
|
if (empty($businessStatusName) && $businessInfo['is_end'] == 3) $businessStatusName = '无效';
|
|
|
|
Message::BUSINESS_ADVANCE_CHECK_TO_DO,
|
|
|
|
# 添加活动记录
|
|
|
|
[
|
|
|
|
Db::name('crm_activity')->insert([
|
|
|
|
'from_user' => User::where(['id' => $dataInfo['owner_user_id']])->value('realname'),
|
|
|
|
'type' => 3,
|
|
|
|
'title' => $dataInfo['name'],
|
|
|
|
'activity_type' => 5,
|
|
|
|
'action_id' => $param['id']
|
|
|
|
'activity_type_id' => $businessInfo['business_id'],
|
|
|
|
],
|
|
|
|
'content' => '阶段变更为 ' . $businessStatusName,
|
|
|
|
stringToArray($businessCheckData['check_user_id'])
|
|
|
|
'create_user_id' => $businessInfo['owner_user_id'],
|
|
|
|
);
|
|
|
|
'update_time' => time(),
|
|
|
|
} else {
|
|
|
|
'create_time' => time(),
|
|
|
|
(new Message())->send(
|
|
|
|
'customer_ids' => ',' . $businessInfo['customer_id'] . ','
|
|
|
|
Message::BUSINESS_ADVANCE_CHECK_REJECT,
|
|
|
|
]);
|
|
|
|
[
|
|
|
|
|
|
|
|
'title' => $dataInfo['name'],
|
|
|
|
# 删除待办事项的关联数据
|
|
|
|
'action_id' => $param['id']
|
|
|
|
db('crm_dealt_relation')->where(['types' => ['eq', 'crm_business'], 'types_id' => ['eq', $data['business_id']]])->delete();
|
|
|
|
],
|
|
|
|
# 创建待办事项的关联数据
|
|
|
|
$dataInfo['owner_user_id']
|
|
|
|
$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 (!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 {
|
|
|
|
} else {
|
|
|
|
$data = [];
|
|
|
|
return resultArray(['error' => '审批失败,请重试!']);
|
|
|
|
$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' => '推进失败,请重试']);
|
|
|
|
* @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]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|