Compare commits

..

No commits in common. '311f024b5ad198a4bfcbac5eb7bc14a07403ee56' and 'b8650a1044865d692e0d0ac98e6e465790e6c2c8' have entirely different histories.

@ -72,49 +72,44 @@ class PoolCommand extends Command
$this->timer = Timer::add($this->interval, function () { $this->timer = Timer::add($this->interval, function () {
# 只在凌晨12点至6点间执行 # 只在凌晨12点至6点间执行
if ((int)date('H') >= 0 && (int)date('H') < 6) { if ((int)date('H') >= 0 && (int)date('H') < 6) {
$this->poolRecover(); # 公海规则
} $ruleList = db('crm_customer_pool_rule')->alias('rule')->field('rule.*')
}); ->join('__CRM_CUSTOMER_POOL__ pool', 'pool.pool_id = rule.pool_id', 'LEFT')->field("pool.customer_type")->where('pool.status', 1)->select();
} if (!empty($ruleList)) {
# 符合公海条件的客户IDS
public function poolRecover() $customerIds = $this->getQueryCondition($ruleList);
{
# 公海规则 # 整理客户公海关联数据
$ruleList = db('crm_customer_pool_rule')->alias('rule')->field('rule.*') $poolRelationData = $this->getCustomerPoolRelationData($customerIds);
->join('__CRM_CUSTOMER_POOL__ pool', 'pool.pool_id = rule.pool_id', 'LEFT')->field("pool.customer_type")->where('pool.status', 1)->select();
if (!empty($ruleList)) { # 整理修改客户数据的条件(进入公海时间,前负责人...
# 符合公海条件的客户IDS $customerWhere = $this->getCustomerQueryCondition($customerIds);
$customerIds = PoolCommand::getQueryCondition($ruleList);
Db::startTrans();
# 整理客户公海关联数据 try {
$poolRelationData = PoolCommand::getCustomerPoolRelationData($customerIds); # 将客户退回公海
if (!empty($poolRelationData)) Db::name('crm_customer_pool_relation')->insertAll($poolRelationData);
# 整理修改客户数据的条件(进入公海时间,前负责人...
$customerWhere = PoolCommand::getCustomerQueryCondition($customerIds); # 修改客户数据
if (!empty($customerWhere)) {
Db::startTrans(); Db::name('crm_customer')->whereIn('customer_id', $customerWhere)->exp('before_owner_user_id', 'owner_user_id')->update([
try { 'ro_user_id' => '',
# 将客户退回公海 'rw_user_id' => '',
if (!empty($poolRelationData)) Db::name('crm_customer_pool_relation')->insertAll($poolRelationData); 'owner_user_id' => 0,
'into_pool_time' => time()
# 修改客户数据 ]);
if (!empty($customerWhere)) { }
Db::name('crm_customer')->whereIn('customer_id', $customerWhere)->exp('before_owner_user_id', 'owner_user_id')->update([ $this->updateInfo($ruleList, $customerWhere);
'ro_user_id' => '', # 删除联系人的负责人
'rw_user_id' => '', Db::name('crm_contacts')->whereIn('customer_id', $customerWhere)->update(['owner_user_id' => '']);
'owner_user_id' => 0,
'into_pool_time' => time() Db::commit();
]); } catch (\Exception $e) {
Db::rollback();
}
} }
PoolCommand::updateInfo($ruleList, $customerWhere);
# 删除联系人的负责人
Db::name('crm_contacts')->whereIn('customer_id', $customerWhere)->update(['owner_user_id' => '']);
Db::commit();
} catch (\Exception $e) {
Db::rollback();
} }
} });
} }
/** /**
@ -134,7 +129,7 @@ class PoolCommand extends Command
if (!empty($v1['limit_day'])) { if (!empty($v1['limit_day'])) {
$time = $v1['limit_day']; $time = $v1['limit_day'];
} else { } else {
$time = PoolCommand::getMinDay($levels); $time = $this->getMinDay($levels);
} }
} }
foreach ($customerWhere as $val) { foreach ($customerWhere as $val) {
@ -231,9 +226,9 @@ class PoolCommand extends Command
foreach ($rules as $k => $v) { foreach ($rules as $k => $v) {
if (!isset($result[$v['pool_id']])) $result[$v['pool_id']] = []; if (!isset($result[$v['pool_id']])) $result[$v['pool_id']] = [];
if ($v['type'] == 1) $result[$v['pool_id']] = array_merge($result[$v['pool_id']], PoolCommand::getFollowUpQueryResult($v['level_conf'], $v['level'], $v['deal_handle'], $v['business_handle'], $v['customer_type'])); if ($v['type'] == 1) $result[$v['pool_id']] = array_merge($result[$v['pool_id']], $this->getFollowUpQueryResult($v['level_conf'], $v['level'], $v['deal_handle'], $v['business_handle'], $v['customer_type']));
if ($v['type'] == 2) $result[$v['pool_id']] = array_merge($result[$v['pool_id']], PoolCommand::getBusinessQueryResult($v['level_conf'], $v['level'], $v['deal_handle'], $v['customer_type'])); if ($v['type'] == 2) $result[$v['pool_id']] = array_merge($result[$v['pool_id']], $this->getBusinessQueryResult($v['level_conf'], $v['level'], $v['deal_handle'], $v['customer_type']));
if ($v['type'] == 3) $result[$v['pool_id']] = array_merge($result[$v['pool_id']], PoolCommand::getDealQueryResult($v['level_conf'], $v['level'], $v['business_handle'], $v['customer_type'])); if ($v['type'] == 3) $result[$v['pool_id']] = array_merge($result[$v['pool_id']], $this->getDealQueryResult($v['level_conf'], $v['level'], $v['business_handle'], $v['customer_type']));
} }
return $result; return $result;
@ -282,7 +277,7 @@ class PoolCommand extends Command
} }
# 获取最小天数,对于没有设置级别的客户数据使用 # 获取最小天数,对于没有设置级别的客户数据使用
$minLimit = PoolCommand::getMinDay($levels); $minLimit = $this->getMinDay($levels);
$minTime = (time() - 24 * 60 * 60 * $minLimit); $minTime = (time() - 24 * 60 * 60 * $minLimit);
$where .= " OR ((!`customer`.`level` AND `customer`.`last_time` < " . $minTime . " AND `customer`.`last_time` > `customer`.`obtain_time`) OR (!`customer`.`level` AND `customer`.`obtain_time` < " . $minTime . " AND `customer`.`obtain_time` > `customer`.`last_time`) OR (!`customer`.`level` AND `customer`.`obtain_time` < " . $minTime . " AND ISNULL(`customer`.`last_time`))) )"; $where .= " OR ((!`customer`.`level` AND `customer`.`last_time` < " . $minTime . " AND `customer`.`last_time` > `customer`.`obtain_time`) OR (!`customer`.`level` AND `customer`.`obtain_time` < " . $minTime . " AND `customer`.`obtain_time` > `customer`.`last_time`) OR (!`customer`.`level` AND `customer`.`obtain_time` < " . $minTime . " AND ISNULL(`customer`.`last_time`))) )";
@ -297,10 +292,16 @@ class PoolCommand extends Command
# 锁定的客户不提醒 # 锁定的客户不提醒
$where .= " AND `customer`.`is_lock` = 0"; $where .= " AND `customer`.`is_lock` = 0";
# 过滤客户类型
if (!empty($customerType)) {
$where .= "And `customer`.`customer_type` in " . $customerType;
}
# 查询符合条件的客户 # 查询符合条件的客户
return db('crm_customer') return db('crm_customer')
->alias('customer')->join('__CRM_BUSINESS__ business', 'business.customer_id = customer.customer_id', 'LEFT') ->alias('customer')->join('__CRM_BUSINESS__ business', 'business.customer_id = customer.customer_id', 'LEFT')
->where($where)->where(['customer.crm_lthugd' => array('in', $customerType)])->column('customer.customer_id'); ->where($where)->column('customer.customer_id');
} }
/** /**
@ -345,7 +346,7 @@ class PoolCommand extends Command
} }
# 获取最小天数,对于没有设置级别的客户数据使用 # 获取最小天数,对于没有设置级别的客户数据使用
$minLimit = PoolCommand::getMinDay($levels); $minLimit = $this->getMinDay($levels);
$minTime = (time() - 24 * 60 * 60 * $minLimit); $minTime = (time() - 24 * 60 * 60 * $minLimit);
$where .= " OR ((ISNULL(`business`.`customer_id`) AND `customer`.`obtain_time` < " . $minTime . " AND !`customer`.`level`) OR (`customer`.`obtain_time` < " . $minTime . " AND `customer`.`obtain_time` > `business`.`create_time` AND !`customer`.`level`) OR (`business`.`create_time` < " . $minTime . " AND `business`.`create_time` > `customer`.`obtain_time` AND !`customer`.`level`)) )"; $where .= " OR ((ISNULL(`business`.`customer_id`) AND `customer`.`obtain_time` < " . $minTime . " AND !`customer`.`level`) OR (`customer`.`obtain_time` < " . $minTime . " AND `customer`.`obtain_time` > `business`.`create_time` AND !`customer`.`level`) OR (`business`.`create_time` < " . $minTime . " AND `business`.`create_time` > `customer`.`obtain_time` AND !`customer`.`level`)) )";
@ -357,10 +358,14 @@ class PoolCommand extends Command
# 锁定的客户不提醒 # 锁定的客户不提醒
$where .= " AND `customer`.`is_lock` = 0"; $where .= " AND `customer`.`is_lock` = 0";
# 过滤客户类型
if (!empty($customerType)) {
$where .= "And `customer`.`customer_type` in " . $customerType;
}
# 查询匹配条件的客户 # 查询匹配条件的客户
return db('crm_customer')->alias('customer') return db('crm_customer')->alias('customer')
->join('__CRM_BUSINESS__ business', 'business.customer_id = customer.customer_id', 'LEFT') ->join('__CRM_BUSINESS__ business', 'business.customer_id = customer.customer_id', 'LEFT')
->where($where)->where(['customer.crm_lthugd' => array('in', $customerType)])->column('customer.customer_id'); ->where($where)->column('customer.customer_id');
} }
/** /**
@ -405,7 +410,7 @@ class PoolCommand extends Command
} }
# 获取最小天数,对于没有设置级别的客户数据使用 # 获取最小天数,对于没有设置级别的客户数据使用
$minLimit = PoolCommand::getMinDay($levels); $minLimit = $this->getMinDay($levels);
$minTime = (time() - 24 * 60 * 60 * $minLimit); $minTime = (time() - 24 * 60 * 60 * $minLimit);
$where .= " OR ((ISNULL(`contract`.`customer_id`) AND `customer`.`obtain_time` < " . $minTime . " AND !`customer`.`level`) OR (`customer`.`obtain_time` < " . $minTime . " AND `customer`.`obtain_time` > `contract`.`create_time` AND !`customer`.`level`) OR (`contract`.`create_time` < " . $minTime . " AND `contract`.`create_time` > `customer`.`obtain_time` AND !`customer`.`level`)) )"; $where .= " OR ((ISNULL(`contract`.`customer_id`) AND `customer`.`obtain_time` < " . $minTime . " AND !`customer`.`level`) OR (`customer`.`obtain_time` < " . $minTime . " AND `customer`.`obtain_time` > `contract`.`create_time` AND !`customer`.`level`) OR (`contract`.`create_time` < " . $minTime . " AND `contract`.`create_time` > `customer`.`obtain_time` AND !`customer`.`level`)) )";
@ -417,11 +422,15 @@ class PoolCommand extends Command
# 锁定的客户不提醒 # 锁定的客户不提醒
$where .= " AND `customer`.`is_lock` = 0"; $where .= " AND `customer`.`is_lock` = 0";
# 过滤客户类型
if (!empty($customerType)) {
$where .= "And `customer`.`customer_type` in " . $customerType;
}
# 查询符合条件的客户 # 查询符合条件的客户
return db('crm_customer')->alias('customer') return db('crm_customer')->alias('customer')
->join('__CRM_BUSINESS__ business', 'business.customer_id = customer.customer_id', 'LEFT') ->join('__CRM_BUSINESS__ business', 'business.customer_id = customer.customer_id', 'LEFT')
->join('__CRM_CONTRACT__ contract', 'contract.customer_id = customer.customer_id', 'LEFT') ->join('__CRM_CONTRACT__ contract', 'contract.customer_id = customer.customer_id', 'LEFT')
->where($where)->where(['customer.crm_lthugd' => array('in', $customerType)])->column('customer.customer_id'); ->where($where)->column('customer.customer_id');
} }
/** /**

Loading…
Cancel
Save