商机审批修改

pull/18/head
张萌 2 years ago
parent 809b786f7d
commit 063c1a63b5

@ -278,6 +278,18 @@ class Message extends Common
* 客户待审批 * 客户待审批
*/ */
const CUSTOMER_CHECK_PASS = 59; const CUSTOMER_CHECK_PASS = 59;
/**
* 客户待审批
*/
const BUSINESS_ADVANCE_CHECK_TO_DO = 60;
/**
* 客户待审批
*/
const BUSINESS_ADVANCE_CHECK_REJECT = 61;
/**
* 客户待审批
*/
const BUSINESS_ADVANCE_CHECK_PASS = 62;
/** /**
* 消息类型 * 消息类型
@ -439,6 +451,9 @@ class Message extends Common
self::CUSTOMER_CHECK_TO_DO, self::CUSTOMER_CHECK_TO_DO,
self::CUSTOMER_CHECK_REJECT, self::CUSTOMER_CHECK_REJECT,
self::CUSTOMER_CHECK_PASS, self::CUSTOMER_CHECK_PASS,
self::BUSINESS_ADVANCE_CHECK_TO_DO,
self::BUSINESS_ADVANCE_CHECK_REJECT,
self::BUSINESS_ADVANCE_CHECK_PASS,
], ],
'jxc' => [ 'jxc' => [
self::PURCHASE_TO_DO, self::PURCHASE_TO_DO,
@ -580,7 +595,6 @@ class Message extends Common
case self::CUSTOMER_CHECK_PASS: case self::CUSTOMER_CHECK_PASS:
case self::CUSTOMER_CHECK_REJECT: 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') ?: '';
// 回款 // 回款
case self::RECEIVABLES_TO_DO: case self::RECEIVABLES_TO_DO:
case self::RECEIVABLES_REJECT: case self::RECEIVABLES_REJECT:
@ -610,6 +624,9 @@ class Message extends Common
// 商机 // 商机
case self::TEAM_BUSINESS: case self::TEAM_BUSINESS:
case self::BUSINESS_PASS: case self::BUSINESS_PASS:
case self::BUSINESS_ADVANCE_CHECK_TO_DO:
case self::BUSINESS_ADVANCE_CHECK_REJECT:
case self::BUSINESS_ADVANCE_CHECK_PASS:
return BusinessModel::where(['business_id' => $data['action_id']])->value('name') ?: ''; return BusinessModel::where(['business_id' => $data['action_id']])->value('name') ?: '';
// 采购单 // 采购单

@ -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,23 +632,154 @@ class Business extends ApiCommon
public function check() public function check()
{ {
$param = $this->param; $param = $this->param;
$userInfo = $this->userInfo;
$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()]);
}
//审批主体详情
$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']);
}
if ($is_end == 1) {
$checkData['check_status'] = !empty($status) ? 2 : 3;
$businessCheckData['check_user_id'] = '';
$businessCheckData['check_status'] = 2;
}
} 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 {
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']
);
}
}
return resultArray(['data' => '审批成功']);
} else {
return resultArray(['error' => '审批失败,请重试!']);
}
}
/**
* 审核后商机状态推进
* @param business_id 商机ID
* @param status_id 推进商机状态ID
* @return
* @author Michael_xu
*/
private function advanceAfterCheck($param)
{
$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'];
$check_status = $param['check_status'];
if (!$param['business_id']) { if (!$param['business_id']) {
return resultArray(['error' => '参数错误']); return resultArray(['error' => '参数错误']);
} }
if ($check_status == 2) {
$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' => '已结束,不能推进']);
// } }
//判断权限 //判断权限
$auth_user_ids = $userModel->getUserByPer('crm', 'business', 'update'); $auth_user_ids = $userModel->getUserByPer('crm', 'business', 'update');
//读写权限 //读写权限
@ -597,25 +791,27 @@ class Business extends ApiCommon
$status_id = $param['status_id'] ?: $businessInfo['status_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(); $statusInfo = db('crm_business_status')->where(['type_id' => $businessInfo['type_id'], 'status_id' => $status_id])->find();
if (!$statusInfo && $businessInfo['is_end']) { if (!$statusInfo && !$is_end) {
return resultArray(['error' => '参数错误']); return resultArray(['error' => '参数错误']);
} }
$data = []; $data = [];
$data['update_time'] = time(); $data['update_time'] = time();
// $data['is_end'] = $is_end; $data['is_end'] = $is_end;
// $data['remark'] = $remark; // if ($is_end) {
$data['check_status'] = $check_status; // $status_id = $is_end;
// }
$data['status_id'] = $status_id; $data['status_id'] = $status_id;
$data['status_time'] = time(); $data['status_time'] = time();
$data['submit_remark'] = $param['submit_remark'];
$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' => '推进失败,请重试']);
} else { } else {
# 商机变更后的名称 # 商机变更后的名称
$businessStatusName = Db::name('crm_business_status')->where('status_id', $param['status_id'])->value('name'); $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) && $is_end == 1) $businessStatusName = '赢单';
if (empty($businessStatusName) && $businessInfo['is_end'] == 2) $businessStatusName = '输单'; if (empty($businessStatusName) && $is_end == 2) $businessStatusName = '输单';
if (empty($businessStatusName) && $businessInfo['is_end'] == 3) $businessStatusName = '无效'; if (empty($businessStatusName) && $is_end == 3) $businessStatusName = '无效';
# 添加活动记录 # 添加活动记录
Db::name('crm_activity')->insert([ Db::name('crm_activity')->insert([
'type' => 3, 'type' => 3,
@ -628,24 +824,9 @@ class Business extends ApiCommon
'customer_ids' => ',' . $businessInfo['customer_id'] . ',' '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 (!empty($dealtData)) db('crm_dealt_relation')->insertAll($dealtData);
//推进记录添加 //推进记录添加
$temp['status_id'] = $status_id ?: 0; $temp['status_id'] = $status_id ?: 0;
$temp['is_end'] = $businessInfo['is_end'] ?: 0; $temp['is_end'] = $is_end ?: 0;
$temp['business_id'] = $param['business_id']; $temp['business_id'] = $param['business_id'];
$temp['create_time'] = time(); $temp['create_time'] = time();
$temp['owner_user_id'] = $userInfo['id']; $temp['owner_user_id'] = $userInfo['id'];
@ -664,17 +845,6 @@ class Business extends ApiCommon
return resultArray(['data' => $result]); return resultArray(['data' => $result]);
} }
} 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' => '推进失败,请重试']);
}
}
} }
} }

@ -490,7 +490,7 @@ class CustomerPool extends ApiCommon
if ($is_end == 1 && !empty($status)) { if ($is_end == 1 && !empty($status)) {
// 审批通过消息告知负责人 // 审批通过消息告知负责人
(new Message())->send( (new Message())->send(
Message::CONTRACT_PASS, Message::CUSTOMER_CHECK_PASS,
[ [
'title' => $dataInfo['name'], 'title' => $dataInfo['name'],
'action_id' => $param['id'] 'action_id' => $param['id']

@ -1139,7 +1139,6 @@ class CustomerPoolLogic extends Common
$customerCheckModel = model('CustomerCheck'); $customerCheckModel = model('CustomerCheck');
$examineStepModel = new \app\admin\model\ExamineStep(); $examineStepModel = new \app\admin\model\ExamineStep();
$examineStatus = $param['examineStatus'] ?? 1; // 审批是否停用 $examineStatus = $param['examineStatus'] ?? 1; // 审批是否停用
$param['check_user_id'] =1 ;// 临时测试需删除
unset($param['examineStatus']); unset($param['examineStatus']);

@ -98,7 +98,7 @@ class CustomerCheck extends Common
} }
$customerField = ''; $customerField = '';
foreach ($indexField as $k => $v) { foreach ($indexField as $k => $v) {
$customerField += 'customer.' + $v; $customerField = 'customer.'.$v;
} }
$list = db('crm_customer_check') $list = db('crm_customer_check')
@ -108,7 +108,7 @@ class CustomerCheck extends Common
->where($partMap) ->where($partMap)
->where($dealtWhere) ->where($dealtWhere)
->limit($request['offset'], $request['length']) ->limit($request['offset'], $request['length'])
->field('customer_check.*,customer.name as name'+$customerField) ->field('customer_check.*,customer.name as name'.$customerField)
->orderRaw($order) ->orderRaw($order)
->select(); ->select();

Loading…
Cancel
Save