Compare commits

..

No commits in common. '7e63f7b86beee340fc03ba44a8cb847c917657b9' and '1ef6ac4960761f61b444020685beabe8393d8e0e' have entirely different histories.

@ -447,17 +447,17 @@ class CustomerPoolLogic extends Common
* 领取公海客户 * 领取公海客户
* *
* @param array $param user_id 领取人IDcustomer_id 要领取的客户ID * @param array $param user_id 领取人IDcustomer_id 要领取的客户ID
* @return array
* @since 2021-04-15
* @author fanqi * @author fanqi
* @since 2021-04-15
* @return array
*/ */
public function receiveCustomers($param) public function receiveCustomers($param)
{ {
if (empty($param['user_id'])) return ['缺少员工ID']; if (empty($param['user_id'])) return ['缺少员工ID'];
# 查询参数 # 查询参数
$userId = $param['user_id']; $userId = $param['user_id'];
$customerId = $param['customer_id']; $customerId = $param['customer_id'];
# 消息数据 # 消息数据
@ -467,7 +467,7 @@ class CustomerPoolLogic extends Common
$customerData = $this->getCustomerList($customerId); $customerData = $this->getCustomerList($customerId);
# 剔除非公海客户 # 剔除非公海客户
foreach ($customerId as $key => $value) { foreach ($customerId AS $key => $value) {
if (!empty($customerData[$value]['owner_user_id'])) { if (!empty($customerData[$value]['owner_user_id'])) {
$message[] = '客户《' . $customerData[$value]['name'] . '》领取失败,失败原因:不是公海客户!'; $message[] = '客户《' . $customerData[$value]['name'] . '》领取失败,失败原因:不是公海客户!';
@ -487,28 +487,28 @@ class CustomerPoolLogic extends Common
$failCustomer = []; $failCustomer = [];
if (!is_bool($exceedCount) && !empty($exceedCount) && $exceedCount > 0) { if (!is_bool($exceedCount) && !empty($exceedCount) && $exceedCount > 0) {
$failCustomer = array_slice($customerId, count($customerId) - $exceedCount); $failCustomer = array_slice($customerId, count($customerId) - $exceedCount);
foreach ($failCustomer as $key => $value) { foreach ($failCustomer AS $key => $value) {
$message[] = '客户《' . $customerData[$value]['name'] . '》领取失败,失败原因:持有客户数达到上限!'; $message[] = '客户《' . $customerData[$value]['name'] . '》领取失败,失败原因:持有客户数达到上限!';
} }
} }
# 可以领取的客户ID取差集 # 可以领取的客户ID取差集
$addCustomerId = count($customerId) == 1 ? $customerId : array_diff($customerId, $failCustomer); $addCustomerId = count($customerId) == 1 ? $customerId : array_diff($customerId, $failCustomer);
# 检查是否还有要领取的客户 # 检查是否还有要领取的客户
if (empty($addCustomerId)) return $message; if (empty($addCustomerId)) return $message;
# 查询领取客户的公海id # 查询领取客户的公海id
$poolId = db('crm_customer_pool_relation')->whereIn('customer_id', $customerId)->value('pool_id'); $poolId=db('crm_customer_pool_relation')->whereIn('customer_id',$customerId)->value('pool_id');
# 公海配置 # 公海配置
$poolConfig = db('crm_customer_pool')->field(['before_owner_conf', 'before_owner_day', 'receive_conf', 'receive_count'])->where('pool_id', $poolId)->find(); $poolConfig = db('crm_customer_pool')->field(['before_owner_conf', 'before_owner_day', 'receive_conf', 'receive_count'])->where('pool_id', $poolId)->find();
# 前负责人N天内不能领取客户 # 前负责人N天内不能领取客户
if (!empty($poolConfig['before_owner_conf'])) { if (!empty($poolConfig['before_owner_conf'])) {
foreach ($addCustomerId as $key => $value) { foreach ($addCustomerId AS $key => $value) {
# 是前负责人,检查前负责人是否能够领取。 # 是前负责人,检查前负责人是否能够领取。
if ($userId == $customerData[$value]['before_owner_user_id']) { if ($userId == $customerData[$value]['before_owner_user_id']) {
$restrictDay = $customerData[$value]['into_pool_time'] + 86400 * $poolConfig['before_owner_day']; $restrictDay = $customerData[$value]['into_pool_time'] + 86400 * $poolConfig['before_owner_day'];
if (time() < $restrictDay) { if (time() < $restrictDay) {
$message[] = '客户《' . $customerData[$value]['name'] . '》领取失败,失败原因:进入公海后,' . $poolConfig['before_owner_day'] . '天内不能领取!'; $message[] = '客户《' . $customerData[$value]['name'] . '》领取失败,失败原因:进入公海后,'.$poolConfig['before_owner_day'].'天内不能领取!';
unset($addCustomerId[(int)$key]); unset($addCustomerId[(int)$key]);
} }
@ -527,47 +527,46 @@ class CustomerPoolLogic extends Common
$receiveCount = db('crm_customer_pool_record')->where($countWhere)->count(); $receiveCount = db('crm_customer_pool_record')->where($countWhere)->count();
if (!empty($poolConfig['receive_conf']) && $receiveCount + count($addCustomerId) > $poolConfig['receive_count']) { if (!empty($poolConfig['receive_conf']) && $receiveCount + count($addCustomerId) > $poolConfig['receive_count']) {
$overQuantity = ($receiveCount + count($addCustomerId)) - $poolConfig['receive_count']; $overQuantity = ($receiveCount + count($addCustomerId)) - $poolConfig['receive_count'];
$message[] = '领取客户失败,失败原因:超出当日可领取数量,超出' . $overQuantity . '个!'; $message[] = '领取客户失败,失败原因:超出当日可领取数量,超出'.$overQuantity.'个!';
return $message; return $message;
} }
# 整理客户更新数据 # 整理客户更新数据
$addCustomerData = [ $addCustomerData = [
'owner_user_id' => $userId, 'owner_user_id' => $userId,
'before_owner_user_id' => 0, 'before_owner_user_id' => 0,
'into_pool_time' => 0, 'into_pool_time' => 0,
'obtain_time' => time(), 'obtain_time' => time()
'is_allocation' => 1,
]; ];
# 整理字段操作记录和数据日志的数据 # 整理字段操作记录和数据日志的数据
$ip = request()->ip(); $ip = request()->ip();
$addActionRecordData = []; $addActionRecordData = [];
$addOperationLogData = []; $addOperationLogData = [];
$addReceiveData = []; $addReceiveData = [];
foreach ($addCustomerId as $key => $value) { foreach ($addCustomerId AS $key => $value) {
$addActionRecordData[] = [ $addActionRecordData[] = [
'user_id' => $userId, 'user_id' => $userId,
'types' => 'crm_customer', 'types' => 'crm_customer',
'action_id' => $value, 'action_id' => $value,
'content' => '领取了客户', 'content' => '领取了客户',
'create_time' => time() 'create_time' => time()
]; ];
$addOperationLogData[] = [ $addOperationLogData[] = [
'user_id' => $userId, 'user_id' => $userId,
'client_ip' => $ip, 'client_ip' => $ip,
'module' => 'crm_customer', 'module' => 'crm_customer',
'action_id' => $value, 'action_id' => $value,
'content' => '领取了客户', 'content' => '领取了客户',
'create_time' => time(), 'create_time' => time(),
'action_name' => 'update', 'action_name' => 'update',
'target_name' => $customerData[$value]['name'] 'target_name' => $customerData[$value]['name']
]; ];
$addReceiveData[] = [ $addReceiveData[] = [
'customer_id' => $value, 'customer_id' => $value,
'user_id' => $userId, 'user_id' => $userId,
'pool_id' => $poolId, 'pool_id' => $poolId,
'type' => 1, 'type' => 1,
'create_time' => time() 'create_time' => time()
]; ];
} }
@ -1144,8 +1143,7 @@ class CustomerPoolLogic extends Common
$dataInfo = db('crm_customer_check')->where('customer_id', 'in', $param['customer_id'])->find(); $dataInfo = db('crm_customer_check')->where('customer_id', 'in', $param['customer_id'])->find();
if ($dataInfo) {
if (!empty($dataInfo)&& $dataInfo['check_status'] < 2) {
return '客户已被领取待审批,请联系管理员'; return '客户已被领取待审批,请联系管理员';
} }

@ -162,7 +162,7 @@ class Customer extends Common
$groupNameArray = db('admin_group')->where("pid", array("eq", 2))->where("id", array("in", $groupIds))->column("title"); $groupNameArray = db('admin_group')->where("pid", array("eq", 2))->where("id", array("in", $groupIds))->column("title");
if ($groupNameArray) if ($groupNameArray)
$map['customer.crm_lthugd'] = array('in', $groupNameArray); $map['customer.crm_roziuw'] = array('in', $groupNameArray);
} }
# 代办事项 - 待进入公海 # 代办事项 - 待进入公海
$remindWhere = []; $remindWhere = [];

Loading…
Cancel
Save