diff --git a/application/crm/model/Customer.php b/application/crm/model/Customer.php index 01e73f3..ba065c9 100644 --- a/application/crm/model/Customer.php +++ b/application/crm/model/Customer.php @@ -982,16 +982,16 @@ class Customer extends Common $where['pool.status'] = 1; # 公海开启 $where['pool.remind_conf'] = 1; # 提醒开启 - $poolRules = db('crm_customer_pool_rule')->alias('rule')->field(['rule.*', 'pool.remain_day'])->join('__CRM_CUSTOMER_POOL__ pool', 'rule.pool_id = pool.pool_id', 'LEFT')->where($where)->select(); + $poolRules = db('crm_customer_pool_rule')->alias('rule')->field(['rule.*', 'pool.remain_day'])->join('__CRM_CUSTOMER_POOL__ pool', 'rule.pool_id = pool.pool_id', 'LEFT')->field("pool.customer_type")->where($where)->select(); if (!empty($poolRules)) { foreach ($poolRules as $key => $value) { - if ($value['type'] == 1) $result[] = $this->getFollowUpQueryResult($value['level_conf'], $value['level'], $value['deal_handle'], $value['business_handle'], $value['remain_day'], $customerIds, $userIds); - if ($value['type'] == 2) $result[] = $this->getBusinessQueryResult($value['level_conf'], $value['level'], $value['deal_handle'], $value['remain_day'], $customerIds, $userIds); - if ($value['type'] == 3) $result[] = $this->getDealQueryResult($value['level_conf'], $value['level'], $value['business_handle'], $value['remain_day'], $customerIds, $userIds); + if ($value['type'] == 1) $result[] = $this->getFollowUpQueryResult($value['level_conf'], $value['level'], $value['deal_handle'], $value['business_handle'],$value['customer_type'], $value['remain_day'], $customerIds, $userIds); + if ($value['type'] == 2) $result[] = $this->getBusinessQueryResult($value['level_conf'], $value['level'], $value['deal_handle'],$value['customer_type'], $value['remain_day'], $customerIds, $userIds); + if ($value['type'] == 3) $result[] = $this->getDealQueryResult($value['level_conf'], $value['level'], $value['business_handle'], $value['customer_type'],$value['remain_day'], $customerIds, $userIds); } } - + return $this->getMinIntoPoolDay($result); } @@ -1058,7 +1058,7 @@ class Customer extends Common * @author fanqi * @since 2021-04-01 */ - private function getFollowUpQueryResult($type, $levels, $dealStatus, $businessStatus, $remainDay, $customerIds = [], $userIds = []) + private function getFollowUpQueryResult($type, $levels, $dealStatus, $businessStatus,$customerType, $remainDay, $customerIds = [], $userIds = []) { # 结果数据 $result = []; @@ -1107,7 +1107,7 @@ class Customer extends Common $minLimit = $this->getMinDay($levels); $minTime = strtotime(date('Y-m-d 00:00:00', time() - 86400 * $minLimit)); - $where .= " OR ((!`customer`.`level` AND `customer`.`last_time` > " . $minTime . " AND `customer`.`last_time` > `customer`.`obtain_time`) OR (!`customer`.`level` AND `customer`.`obtain_time` > " . $time . " AND `customer`.`obtain_time` > `customer`.`last_time`) OR (!`customer`.`level` AND `customer`.`obtain_time` > " . $minTime . " AND ISNULL(`customer`.`last_time`))) )"; + $where .= " OR ((ISNULL(`customer`.`level`) AND `customer`.`last_time` > " . $minTime . " AND `customer`.`last_time` > `customer`.`obtain_time`) OR (ISNULL(`customer`.`level`) AND `customer`.`obtain_time` > " . $time . " AND `customer`.`obtain_time` > `customer`.`last_time`) OR (ISNULL(`customer`.`level`) AND `customer`.`obtain_time` > " . $minTime . " AND ISNULL(`customer`.`last_time`))) )"; } # 选择不进入公海的客户(已成交客户) @@ -1129,7 +1129,7 @@ class Customer extends Common $data = db('crm_customer')->alias('customer') ->field(['customer.customer_id', 'customer.obtain_time', 'customer.level', 'customer.last_time']) ->join('__CRM_BUSINESS__ business', 'business.customer_id = customer.customer_id', 'LEFT') - ->where($where)->select(); + ->where($where)->where(['customer.crm_lthugd' => array('in', $customerType)])->select(); # 计算到期天数 foreach ($data as $k1 => $v1) { @@ -1170,7 +1170,7 @@ class Customer extends Common * @since 2021-04-01 * @author fanqi */ - private function getBusinessQueryResult($type, $levels, $dealStatus, $remainDay, $customerIds = [], $userIds = []) + private function getBusinessQueryResult($type, $levels, $dealStatus,$customerType, $remainDay, $customerIds = [], $userIds = []) { # 结果数据 $result = []; @@ -1219,7 +1219,7 @@ class Customer extends Common $minLimit = $this->getMinDay($levels); $minTime = strtotime(date('Y-m-d 00:00:00', time() - 86400 * $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 ISNULL(`customer`.`level`)) OR (`customer`.`obtain_time` > " . $minTime . " AND `customer`.`obtain_time` > `business`.`create_time` AND ISNULL(`customer`.`level`)) OR (`business`.`create_time` > " . $minTime . " AND `business`.`create_time` > `customer`.`obtain_time` AND ISNULL(`customer`.`level`))) )"; } # 选择不进入公海的客户(已成交客户) @@ -1238,7 +1238,7 @@ class Customer extends Common $data = db('crm_customer')->alias('customer') ->field(['customer.customer_id', 'customer.obtain_time AS customer_time', 'customer.level', 'business.create_time AS business_time']) ->join('__CRM_BUSINESS__ business', 'business.customer_id = customer.customer_id', 'LEFT') - ->where($where)->select(); + ->where($where)->where(['customer.crm_lthugd' => array('in', $customerType)])->select(); # 计算到期天数 foreach ($data as $k1 => $v1) { @@ -1279,7 +1279,7 @@ class Customer extends Common * @since 2021-04-01 * @author fanqi */ - private function getDealQueryResult($type, $levels, $businessStatus, $remainDay, $customerIds = [], $userIds = []) + private function getDealQueryResult($type, $levels, $businessStatus,$customerType, $remainDay, $customerIds = [], $userIds = []) { # 结果数据 $result = []; @@ -1328,7 +1328,7 @@ class Customer extends Common $minLimit = $this->getMinDay($levels); $minTime = strtotime(date('Y-m-d 00:00:00', time() - 86400 * $minLimit)); - $where .= " OR ((ISNULL(`contract`.`customer_id`) AND !`customer`.`level` AND `customer`.`obtain_time` > " . $minTime . ") OR (!`customer`.`level` AND `customer`.`obtain_time` > " . $minTime . " AND `customer`.`obtain_time` > `contract`.`create_time`) OR (`contract`.`create_time` > " . $minTime . " AND `contract`.`create_time` > `customer`.`obtain_time` AND !`customer`.`level`)) )"; + $where .= " OR ((ISNULL(`contract`.`customer_id`) AND ISNULL(`customer`.`level`) AND `customer`.`obtain_time` > " . $minTime . ") OR (ISNULL(`customer`.`level`) AND `customer`.`obtain_time` > " . $minTime . " AND `customer`.`obtain_time` > `contract`.`create_time`) OR (`contract`.`create_time` > " . $minTime . " AND `contract`.`create_time` > `customer`.`obtain_time` AND ISNULL(`customer`.`level`))) )"; } # 选择不进入公海的客户(有商机客户) @@ -1348,7 +1348,7 @@ class Customer extends Common ->field(['customer.customer_id', 'customer.obtain_time AS customer_time', 'customer.level', 'contract.create_time AS contract_time']) ->join('__CRM_BUSINESS__ business', 'business.customer_id = customer.customer_id', 'LEFT') ->join('__CRM_CONTRACT__ contract', 'contract.customer_id = customer.customer_id', 'LEFT') - ->where($where)->select(); + ->where($where)->where(['customer.crm_lthugd' => array('in', $customerType)])->select(); # 计算到期天数 foreach ($data as $k1 => $v1) {