Merge pull request '公海自动回收规则调整' (#45) from zm into master

Reviewed-on: mengfucius/wkcrm#45
master
张萌 2 years ago
commit 311f024b5a

@ -72,18 +72,25 @@ 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();
}
});
}
public function poolRecover()
{
# 公海规则 # 公海规则
$ruleList = db('crm_customer_pool_rule')->alias('rule')->field('rule.*') $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(); ->join('__CRM_CUSTOMER_POOL__ pool', 'pool.pool_id = rule.pool_id', 'LEFT')->field("pool.customer_type")->where('pool.status', 1)->select();
if (!empty($ruleList)) { if (!empty($ruleList)) {
# 符合公海条件的客户IDS # 符合公海条件的客户IDS
$customerIds = $this->getQueryCondition($ruleList); $customerIds = PoolCommand::getQueryCondition($ruleList);
# 整理客户公海关联数据 # 整理客户公海关联数据
$poolRelationData = $this->getCustomerPoolRelationData($customerIds); $poolRelationData = PoolCommand::getCustomerPoolRelationData($customerIds);
# 整理修改客户数据的条件(进入公海时间,前负责人... # 整理修改客户数据的条件(进入公海时间,前负责人...
$customerWhere = $this->getCustomerQueryCondition($customerIds); $customerWhere = PoolCommand::getCustomerQueryCondition($customerIds);
Db::startTrans(); Db::startTrans();
try { try {
@ -99,7 +106,7 @@ class PoolCommand extends Command
'into_pool_time' => time() 'into_pool_time' => time()
]); ]);
} }
$this->updateInfo($ruleList, $customerWhere); PoolCommand::updateInfo($ruleList, $customerWhere);
# 删除联系人的负责人 # 删除联系人的负责人
Db::name('crm_contacts')->whereIn('customer_id', $customerWhere)->update(['owner_user_id' => '']); Db::name('crm_contacts')->whereIn('customer_id', $customerWhere)->update(['owner_user_id' => '']);
@ -109,8 +116,6 @@ class PoolCommand extends Command
} }
} }
} }
});
}
/** /**
* 自动入公海操作记录 * 自动入公海操作记录
@ -129,7 +134,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 = $this->getMinDay($levels); $time = PoolCommand::getMinDay($levels);
} }
} }
foreach ($customerWhere as $val) { foreach ($customerWhere as $val) {
@ -226,9 +231,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']], $this->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']], PoolCommand::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']], $this->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']], PoolCommand::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']], $this->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']], PoolCommand::getDealQueryResult($v['level_conf'], $v['level'], $v['business_handle'], $v['customer_type']));
} }
return $result; return $result;
@ -277,7 +282,7 @@ class PoolCommand extends Command
} }
# 获取最小天数,对于没有设置级别的客户数据使用 # 获取最小天数,对于没有设置级别的客户数据使用
$minLimit = $this->getMinDay($levels); $minLimit = PoolCommand::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`))) )";
@ -292,16 +297,10 @@ 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)->column('customer.customer_id'); ->where($where)->where(['customer.crm_lthugd' => array('in', $customerType)])->column('customer.customer_id');
} }
/** /**
@ -346,7 +345,7 @@ class PoolCommand extends Command
} }
# 获取最小天数,对于没有设置级别的客户数据使用 # 获取最小天数,对于没有设置级别的客户数据使用
$minLimit = $this->getMinDay($levels); $minLimit = PoolCommand::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`)) )";
@ -358,14 +357,10 @@ 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)->column('customer.customer_id'); ->where($where)->where(['customer.crm_lthugd' => array('in', $customerType)])->column('customer.customer_id');
} }
/** /**
@ -410,7 +405,7 @@ class PoolCommand extends Command
} }
# 获取最小天数,对于没有设置级别的客户数据使用 # 获取最小天数,对于没有设置级别的客户数据使用
$minLimit = $this->getMinDay($levels); $minLimit = PoolCommand::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`)) )";
@ -422,15 +417,11 @@ 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)->column('customer.customer_id'); ->where($where)->where(['customer.crm_lthugd' => array('in', $customerType)])->column('customer.customer_id');
} }
/** /**

Loading…
Cancel
Save