zm #28

Merged
mengfucius merged 3 commits from zm into master 2 years ago

@ -485,7 +485,10 @@ class Field extends Model
} }
//生成字段名 //生成字段名
if (!$data['field']) $data['field'] = $this->createField($types, $types == 'oa_examine' ? 'oa_' : 'crm_'); if (!empty($param['field'])) {
$data['field'] = $param['field'];
} else if (!$data['field']) $data['field'] = $this->createField($types, $types == 'oa_examine' ? 'oa_' : 'crm_');
$rule = [ $rule = [
'field' => ['regex' => '/^[a-z]([a-z]|_)+[a-z]$/i'], 'field' => ['regex' => '/^[a-z]([a-z]|_)+[a-z]$/i'],

@ -609,14 +609,13 @@ class Message extends ApiCommon
unset($param['type']); unset($param['type']);
unset($param['isSub']); unset($param['isSub']);
$businessModel = model('Business'); $businessModel = model('Business');
$param['owner_user_id'] = $userInfo['id']; // $param['owner_user_id'] = $userInfo['id'];
if ($isSub) { if ($isSub) {
$param['owner_user_id'] = array('in', getSubUserId(false)); $param['owner_user_id'] = array('in', getSubUserId(false));
} }
$businessIdArray = db('crm_dealt_relation')->where(['types' => ['eq', 'crm_business_new'], 'user_id' => ['eq', $param['user_id']]])->column('types_id'); $businessIdArray = db('crm_dealt_relation')->where(['types' => ['eq', 'crm_business_new'], 'user_id' => ['eq', $userInfo['id']]])->column('types_id');
$param['businessIdArray'] = !empty($businessIdArray) ? $businessIdArray : -1; $param['businessIdArray'] = !empty($businessIdArray) ? $businessIdArray : -1;
$data = $businessModel->getDataList($param); $data = $businessModel->getDataList($param);
// p($contractModel->getLastSql());
if ($types == 'list') { if ($types == 'list') {
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
} }
@ -776,7 +775,7 @@ class Message extends ApiCommon
} }
# 处理待审核合同、回款、发票 # 处理待审核合同、回款、发票
if (in_array($type, ['checkContract', 'checkReceivables', 'checkInvoice', 'checkBusiness','checkCustomerCheck','new_business'])) { if (in_array($type, ['checkContract', 'checkReceivables', 'checkInvoice', 'checkBusiness', 'checkCustomerCheck', 'newBusiness'])) {
$where['check_status'] = ['lt', '2']; $where['check_status'] = ['lt', '2'];
$where['check_user_id'] = ['like', ',%' . $userId . '%,']; $where['check_user_id'] = ['like', ',%' . $userId . '%,'];
@ -807,7 +806,7 @@ class Message extends ApiCommon
} }
# 新商机 # 新商机
if ($type == 'new_business') { if ($type == 'newBusiness') {
$newBusinessId = !empty($typeId) ? $typeId : Db::name('crm_business')->where($where)->column('business_id'); $newBusinessId = !empty($typeId) ? $typeId : Db::name('crm_business')->where($where)->column('business_id');
db('crm_dealt_relation')->where('user_id', $userId)->where('types', 'crm_business_new')->whereIn('types_id', $newBusinessId)->delete(); db('crm_dealt_relation')->where('user_id', $userId)->where('types', 'crm_business_new')->whereIn('types_id', $newBusinessId)->delete();
} }

@ -438,7 +438,8 @@ class Business extends Common
db('crm_business_data')->insertAll($businessData); db('crm_business_data')->insertAll($businessData);
//站内信 //站内信
$send_user_id = stringToArray(getUserSuperior($param['create_user_id'])); $userInfo = db('admin_user')->where(['id' => $param['create_user_id']])->find();
$send_user_id = stringToArray(getUserSuperior($userInfo['structure_id'],0));
(new Message())->send( (new Message())->send(
Message::CUSTOMER_CHECK_TO_DO, Message::CUSTOMER_CHECK_TO_DO,
[ [

@ -39,11 +39,11 @@ class Customer extends Common
/** /**
* [getDataList 客户list] * [getDataList 客户list]
* @author Michael_xu
* @param [string] $map [查询条件] * @param [string] $map [查询条件]
* @param [number] $page [当前页数] * @param [number] $page [当前页数]
* @param [number] $limit [每页数量] * @param [number] $limit [每页数量]
* @return [array] [description] * @return [array] [description]
* @author Michael_xu
*/ */
public function getDataList($request) public function getDataList($request)
{ {
@ -155,9 +155,15 @@ class Customer extends Common
}); });
}; };
} }
// 过滤角色
$groupIds = db('admin_access')->where("user_id", array("eq", $user_id))->column("group_id");
if (!in_array(1,$groupIds)){
$groupNameArray = db('admin_group')->where("pid", array("eq", 2))->where("id", array("in", $groupIds))->column("title");
if ($groupNameArray)
$map['customer.crm_role'] = array('in', $groupNameArray);
}
# 代办事项 - 待进入公海 # 代办事项 - 待进入公海
$remindWhere = []; $remindWhere = [];
if ($is_remind) { if ($is_remind) {
@ -250,7 +256,7 @@ class Customer extends Common
# 处理数据 # 处理数据
$list = getFieldData($list, 'crm_customer', $user_id); $list = getFieldData($list, 'crm_customer', $user_id);
# 整理数据 # 整理数据
foreach ($list AS $k => $v) { foreach ($list as $k => $v) {
$list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : []; $list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
$list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : []; $list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
@ -301,9 +307,9 @@ class Customer extends Common
/** /**
* 创建客户主表信息 * 创建客户主表信息
* @author Michael_xu
* @param * @param
* @return * @return
* @author Michael_xu
*/ */
public function createData($param) public function createData($param)
{ {
@ -363,7 +369,7 @@ class Customer extends Common
// 处理日期date类型 // 处理日期date类型
$dateField = $fieldModel->getFieldByFormType('crm_customer', 'date'); $dateField = $fieldModel->getFieldByFormType('crm_customer', 'date');
if (!empty($dateField)) { if (!empty($dateField)) {
foreach ($param AS $key => $value) { foreach ($param as $key => $value) {
if (in_array($key, $dateField) && empty($value)) $param[$key] = null; if (in_array($key, $dateField) && empty($value)) $param[$key] = null;
} }
} }
@ -371,7 +377,7 @@ class Customer extends Common
// 处理手写签名类型 // 处理手写签名类型
$handwritingField = $fieldModel->getFieldByFormType('crm_customer', 'handwriting_sign'); $handwritingField = $fieldModel->getFieldByFormType('crm_customer', 'handwriting_sign');
if (!empty($handwritingField)) { if (!empty($handwritingField)) {
foreach ($param AS $key => $value) { foreach ($param as $key => $value) {
if (in_array($key, $handwritingField)) { if (in_array($key, $handwritingField)) {
$param[$key] = !empty($value['file_id']) ? $value['file_id'] : ''; $param[$key] = !empty($value['file_id']) ? $value['file_id'] : '';
} }
@ -384,7 +390,7 @@ class Customer extends Common
$dateIntervalField = $fieldModel->getFieldByFormType('crm_customer', 'date_interval'); $dateIntervalField = $fieldModel->getFieldByFormType('crm_customer', 'date_interval');
$detailTableField = $fieldModel->getFieldByFormType('crm_customer', 'detail_table'); $detailTableField = $fieldModel->getFieldByFormType('crm_customer', 'detail_table');
$dateField = $fieldModel->getFieldByFormType('crm_customer', 'date'); $dateField = $fieldModel->getFieldByFormType('crm_customer', 'date');
foreach ($param AS $key => $value) { foreach ($param as $key => $value) {
// 处理地址类型字段数据 // 处理地址类型字段数据
if (in_array($key, $positionField)) { if (in_array($key, $positionField)) {
if (!empty($value) && is_array($value)) { if (!empty($value) && is_array($value)) {
@ -517,9 +523,9 @@ class Customer extends Common
/** /**
* 编辑客户主表信息 * 编辑客户主表信息
* @author Michael_xu
* @param * @param
* @return * @return
* @author Michael_xu
*/ */
public function updateDataById($param, $customer_id = '') public function updateDataById($param, $customer_id = '')
{ {
@ -582,7 +588,7 @@ class Customer extends Common
// 处理日期date类型 // 处理日期date类型
$dateField = $fieldModel->getFieldByFormType('crm_customer', 'date'); $dateField = $fieldModel->getFieldByFormType('crm_customer', 'date');
if (!empty($dateField)) { if (!empty($dateField)) {
foreach ($param AS $key => $value) { foreach ($param as $key => $value) {
if (in_array($key, $dateField) && empty($value)) $param[$key] = null; if (in_array($key, $dateField) && empty($value)) $param[$key] = null;
} }
} }
@ -590,7 +596,7 @@ class Customer extends Common
// 处理手写签名类型 // 处理手写签名类型
$handwritingField = $fieldModel->getFieldByFormType('crm_customer', 'handwriting_sign'); $handwritingField = $fieldModel->getFieldByFormType('crm_customer', 'handwriting_sign');
if (!empty($handwritingField)) { if (!empty($handwritingField)) {
foreach ($param AS $key => $value) { foreach ($param as $key => $value) {
if (in_array($key, $handwritingField)) { if (in_array($key, $handwritingField)) {
$param[$key] = !empty($value['file_id']) ? $value['file_id'] : ''; $param[$key] = !empty($value['file_id']) ? $value['file_id'] : '';
} }
@ -602,7 +608,7 @@ class Customer extends Common
$locationField = $fieldModel->getFieldByFormType('crm_customer', 'location'); $locationField = $fieldModel->getFieldByFormType('crm_customer', 'location');
$dateIntervalField = $fieldModel->getFieldByFormType('crm_customer', 'date_interval'); $dateIntervalField = $fieldModel->getFieldByFormType('crm_customer', 'date_interval');
$detailTableField = $fieldModel->getFieldByFormType('crm_customer', 'detail_table'); $detailTableField = $fieldModel->getFieldByFormType('crm_customer', 'detail_table');
foreach ($param AS $key => $value) { foreach ($param as $key => $value) {
// 处理地址类型字段数据 // 处理地址类型字段数据
if (in_array($key, $positionField)) { if (in_array($key, $positionField)) {
if (!empty($value)) { if (!empty($value)) {
@ -714,7 +720,7 @@ class Customer extends Common
} }
} }
} }
foreach ($fieldGrant AS $key => $val){ foreach ($fieldGrant as $key => $val) {
//掩码相关类型字段 //掩码相关类型字段
if ($val['maskType'] != 0 && $val['form_type'] == 'mobile') { if ($val['maskType'] != 0 && $val['form_type'] == 'mobile') {
$pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i"; $pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
@ -762,7 +768,7 @@ class Customer extends Common
if (!empty($userId)) { if (!empty($userId)) {
$grantData = getFieldGrantData($userId); $grantData = getFieldGrantData($userId);
$userLevel = isSuperAdministrators($userId); $userLevel = isSuperAdministrators($userId);
foreach ($dataInfo AS $key => $value) { foreach ($dataInfo as $key => $value) {
if (!$userLevel && !empty($grantData['crm_customer'])) { if (!$userLevel && !empty($grantData['crm_customer'])) {
$status = getFieldGrantStatus($key, $grantData['crm_customer']); $status = getFieldGrantStatus($key, $grantData['crm_customer']);
@ -782,9 +788,9 @@ class Customer extends Common
/** /**
* [客户统计] * [客户统计]
* @author Michael_xu
* @param * @param
* @return * @return
* @author Michael_xu
*/ */
public function getStatistics($request) public function getStatistics($request)
{ {
@ -900,9 +906,9 @@ class Customer extends Common
/** /**
* [客户数量] * [客户数量]
* @author Michael_xu
* @param * @param
* @return * @return
* @author Michael_xu
*/ */
public function getDataCount($map) public function getDataCount($map)
{ {
@ -914,9 +920,9 @@ class Customer extends Common
/** /**
* 客户默认条件 * 客户默认条件
* *
* @author fanqi
* @since 2021-05-12
* @return array * @return array
* @since 2021-05-12
* @author fanqi
*/ */
public function getWhereByCustomer() public function getWhereByCustomer()
{ {
@ -926,9 +932,9 @@ class Customer extends Common
/** /**
* 客户公海条件 * 客户公海条件
* *
* @author fanqi
* @since 2021-05-12
* @return array * @return array
* @since 2021-05-12
* @author fanqi
*/ */
public function getWhereByPool() public function getWhereByPool()
{ {
@ -937,9 +943,9 @@ class Customer extends Common
/** /**
* 客户权限判断(是否客户公海) * 客户权限判断(是否客户公海)
* @author Michael_xu
* @param type 1 是公海返回false,默认是公海返回true * @param type 1 是公海返回false,默认是公海返回true
* @return * @return
* @author Michael_xu
*/ */
public function checkData($customer_id, $type = '') public function checkData($customer_id, $type = '')
{ {
@ -966,9 +972,9 @@ class Customer extends Common
* 客户到期天数 * 客户到期天数
* *
* @param array $customerIds 客户ID * @param array $customerIds 客户ID
* @author fanqi
* @since 2021-04-19
* @return array * @return array
* @since 2021-04-19
* @author fanqi
*/ */
public function getPoolDay($customerIds = [], $userIds = []) public function getPoolDay($customerIds = [], $userIds = [])
{ {
@ -979,7 +985,7 @@ class Customer extends Common
$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')->where($where)->select();
if (!empty($poolRules)) { if (!empty($poolRules)) {
foreach ($poolRules AS $key => $value) { 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'] == 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'] == 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'] == 3) $result[] = $this->getDealQueryResult($value['level_conf'], $value['level'], $value['business_handle'], $value['remain_day'], $customerIds, $userIds);
@ -993,9 +999,9 @@ class Customer extends Common
* 获取每个客户最快进入公海天数 * 获取每个客户最快进入公海天数
* *
* @param $data * @param $data
* @author fanqi
* @since 2021-04-19
* @return array * @return array
* @since 2021-04-19
* @author fanqi
*/ */
private function getMinIntoPoolDay($data) private function getMinIntoPoolDay($data)
{ {
@ -1003,16 +1009,16 @@ class Customer extends Common
$temporary = []; $temporary = [];
# 整理数据 # 整理数据
foreach ($data AS $k1 => $v1) { foreach ($data as $k1 => $v1) {
if (empty($v1)) continue; if (empty($v1)) continue;
foreach ($v1 AS $k2 => $v2) { foreach ($v1 as $k2 => $v2) {
$temporary[$k2][] = $v2; $temporary[$k2][] = $v2;
} }
} }
# 每个客户最快进入公海天数 # 每个客户最快进入公海天数
foreach ($temporary AS $k1 => $v1) { foreach ($temporary as $k1 => $v1) {
$result[$k1] = min($v1); $result[$k1] = min($v1);
} }
@ -1023,15 +1029,15 @@ class Customer extends Common
* 获取公海规则最小数字(最快进入公海天数) * 获取公海规则最小数字(最快进入公海天数)
* *
* @param $data * @param $data
* @author fanqi
* @since 2021-04-19
* @return int * @return int
* @since 2021-04-19
* @author fanqi
*/ */
private function getMinDay($data) private function getMinDay($data)
{ {
$number = 1; $number = 1;
foreach ($data AS $k1 => $v1) { foreach ($data as $k1 => $v1) {
if (empty($number) || $v1['limit_day'] < $number) $number = $v1['limit_day']; if (empty($number) || $v1['limit_day'] < $number) $number = $v1['limit_day'];
} }
@ -1048,9 +1054,9 @@ class Customer extends Common
* @param int $remainDay 提前几天提醒 * @param int $remainDay 提前几天提醒
* @param array $customerIds 客户ID * @param array $customerIds 客户ID
* @param array $userIds 员工ID * @param array $userIds 员工ID
* @return array
* @author fanqi * @author fanqi
* @since 2021-04-01 * @since 2021-04-01
* @return array
*/ */
private function getFollowUpQueryResult($type, $levels, $dealStatus, $businessStatus, $remainDay, $customerIds = [], $userIds = []) private function getFollowUpQueryResult($type, $levels, $dealStatus, $businessStatus, $remainDay, $customerIds = [], $userIds = [])
{ {
@ -1072,7 +1078,7 @@ class Customer extends Common
# 所有用户,不区分级别 # 所有用户,不区分级别
if ($type == 1) { if ($type == 1) {
foreach ($levels AS $k1 => $v1) { foreach ($levels as $k1 => $v1) {
if (!empty($v1['limit_day'])) { if (!empty($v1['limit_day'])) {
$time = strtotime(date('Y-m-d 00:00:00', time() - 86400 * $v1['limit_day'])); $time = strtotime(date('Y-m-d 00:00:00', time() - 86400 * $v1['limit_day']));
$where .= " AND ((`customer`.`last_time` > " . $time . " AND `customer`.`last_time` > `customer`.`obtain_time`) OR (`customer`.`obtain_time` > " . $time . " AND `customer`.`obtain_time` > `customer`.`last_time`) OR (`customer`.`obtain_time` > " . $time . " AND ISNULL(`customer`.`last_time`)))"; $where .= " AND ((`customer`.`last_time` > " . $time . " AND `customer`.`last_time` > `customer`.`obtain_time`) OR (`customer`.`obtain_time` > " . $time . " AND `customer`.`obtain_time` > `customer`.`last_time`) OR (`customer`.`obtain_time` > " . $time . " AND ISNULL(`customer`.`last_time`)))";
@ -1084,7 +1090,7 @@ class Customer extends Common
# 根据用户级别设置条件 # 根据用户级别设置条件
if ($type == 2) { if ($type == 2) {
foreach ($levels AS $k1 => $v1) { foreach ($levels as $k1 => $v1) {
if (!empty($v1['level']) && !empty($v1['limit_day'])) { if (!empty($v1['level']) && !empty($v1['limit_day'])) {
$time = strtotime(date('Y-m-d 00:00:00', time() - 86400 * $v1['limit_day'])); $time = strtotime(date('Y-m-d 00:00:00', time() - 86400 * $v1['limit_day']));
if ($k1 == 0) { if ($k1 == 0) {
@ -1126,7 +1132,7 @@ class Customer extends Common
->where($where)->select(); ->where($where)->select();
# 计算到期天数 # 计算到期天数
foreach ($data AS $k1 => $v1) { foreach ($data as $k1 => $v1) {
if ($type == 1) { if ($type == 1) {
$customerTime = !empty($v1['last_time']) && $v1['last_time'] > $v1['obtain_time'] ? $v1['last_time'] : $v1['obtain_time']; $customerTime = !empty($v1['last_time']) && $v1['last_time'] > $v1['obtain_time'] ? $v1['last_time'] : $v1['obtain_time'];
$date = date('Y-m-d 00:00:00', ($customerTime + $limitDay['all'] * 86400) - $remainDay * 86400); $date = date('Y-m-d 00:00:00', ($customerTime + $limitDay['all'] * 86400) - $remainDay * 86400);
@ -1160,9 +1166,9 @@ class Customer extends Common
* @param int $remainDay 提前几天提醒 * @param int $remainDay 提前几天提醒
* @param array $customerIds 客户ID * @param array $customerIds 客户ID
* @param array $userIds 员工ID * @param array $userIds 员工ID
* @author fanqi
* @since 2021-04-01
* @return array|false|string * @return array|false|string
* @since 2021-04-01
* @author fanqi
*/ */
private function getBusinessQueryResult($type, $levels, $dealStatus, $remainDay, $customerIds = [], $userIds = []) private function getBusinessQueryResult($type, $levels, $dealStatus, $remainDay, $customerIds = [], $userIds = [])
{ {
@ -1184,7 +1190,7 @@ class Customer extends Common
# 所有用户,不区分级别 # 所有用户,不区分级别
if ($type == 1) { if ($type == 1) {
foreach ($levels AS $k1 => $v1) { foreach ($levels as $k1 => $v1) {
if (!empty($v1['limit_day'])) { if (!empty($v1['limit_day'])) {
$time = strtotime(date('Y-m-d 00:00:00', time() - 86400 * $v1['limit_day'])); $time = strtotime(date('Y-m-d 00:00:00', time() - 86400 * $v1['limit_day']));
$where .= " AND ( (ISNULL(`business`.`customer_id`) AND `customer`.`obtain_time` > " . $time . ") OR (`customer`.`obtain_time` > " . $time . " AND `customer`.`obtain_time` > `business`.`create_time`) OR (`business`.`create_time` > " . $time . " AND `business`.`create_time` > `customer`.`obtain_time`) )"; $where .= " AND ( (ISNULL(`business`.`customer_id`) AND `customer`.`obtain_time` > " . $time . ") OR (`customer`.`obtain_time` > " . $time . " AND `customer`.`obtain_time` > `business`.`create_time`) OR (`business`.`create_time` > " . $time . " AND `business`.`create_time` > `customer`.`obtain_time`) )";
@ -1196,7 +1202,7 @@ class Customer extends Common
# 根据用户级别设置条件 # 根据用户级别设置条件
if ($type == 2) { if ($type == 2) {
foreach ($levels AS $k1 => $v1) { foreach ($levels as $k1 => $v1) {
if (!empty($v1['level']) && !empty($v1['limit_day'])) { if (!empty($v1['level']) && !empty($v1['limit_day'])) {
$time = strtotime(date('Y-m-d 00:00:00', time() - 86400 * $v1['limit_day'])); $time = strtotime(date('Y-m-d 00:00:00', time() - 86400 * $v1['limit_day']));
if ($k1 == 0) { if ($k1 == 0) {
@ -1235,7 +1241,7 @@ class Customer extends Common
->where($where)->select(); ->where($where)->select();
# 计算到期天数 # 计算到期天数
foreach ($data AS $k1 => $v1) { foreach ($data as $k1 => $v1) {
if ($type == 1) { if ($type == 1) {
$customerTime = !empty($v1['business_time']) && $v1['business_time'] > $v1['customer_time'] ? $v1['business_time'] : $v1['customer_time']; $customerTime = !empty($v1['business_time']) && $v1['business_time'] > $v1['customer_time'] ? $v1['business_time'] : $v1['customer_time'];
$date = date('Y-m-d 00:00:00', ($customerTime + $limitDay['all'] * 86400) - $remainDay * 86400); $date = date('Y-m-d 00:00:00', ($customerTime + $limitDay['all'] * 86400) - $remainDay * 86400);
@ -1269,9 +1275,9 @@ class Customer extends Common
* @param int $remainDay 提前几天提醒 * @param int $remainDay 提前几天提醒
* @param array $customerIds 客户ID * @param array $customerIds 客户ID
* @param array $userIds 员工ID * @param array $userIds 员工ID
* @author fanqi
* @since 2021-04-01
* @return array|false|string * @return array|false|string
* @since 2021-04-01
* @author fanqi
*/ */
private function getDealQueryResult($type, $levels, $businessStatus, $remainDay, $customerIds = [], $userIds = []) private function getDealQueryResult($type, $levels, $businessStatus, $remainDay, $customerIds = [], $userIds = [])
{ {
@ -1293,7 +1299,7 @@ class Customer extends Common
# 所有用户,不区分级别 # 所有用户,不区分级别
if ($type == 1) { if ($type == 1) {
foreach ($levels AS $k1 => $v1) { foreach ($levels as $k1 => $v1) {
if (!empty($v1['limit_day'])) { if (!empty($v1['limit_day'])) {
$time = strtotime(date('Y-m-d 00:00:00', time() - 86400 * $v1['limit_day'])); $time = strtotime(date('Y-m-d 00:00:00', time() - 86400 * $v1['limit_day']));
$where .= " AND ( (ISNULL(`contract`.`customer_id`) AND `customer`.`obtain_time` > " . $time . ") OR (`customer`.`obtain_time` > " . $time . " AND `customer`.`obtain_time` > `contract`.`create_time`) OR (`contract`.`create_time` > " . $time . " AND `contract`.`create_time` > `customer`.`obtain_time`) )"; $where .= " AND ( (ISNULL(`contract`.`customer_id`) AND `customer`.`obtain_time` > " . $time . ") OR (`customer`.`obtain_time` > " . $time . " AND `customer`.`obtain_time` > `contract`.`create_time`) OR (`contract`.`create_time` > " . $time . " AND `contract`.`create_time` > `customer`.`obtain_time`) )";
@ -1305,7 +1311,7 @@ class Customer extends Common
# 根据用户级别设置条件 # 根据用户级别设置条件
if ($type == 2) { if ($type == 2) {
foreach ($levels AS $k1 => $v1) { foreach ($levels as $k1 => $v1) {
if (!empty($v1['level']) && !empty($v1['limit_day'])) { if (!empty($v1['level']) && !empty($v1['limit_day'])) {
$time = strtotime(date('Y-m-d 00:00:00', time() - 86400 * $v1['limit_day'])); $time = strtotime(date('Y-m-d 00:00:00', time() - 86400 * $v1['limit_day']));
if ($k1 == 0) { if ($k1 == 0) {
@ -1345,7 +1351,7 @@ class Customer extends Common
->where($where)->select(); ->where($where)->select();
# 计算到期天数 # 计算到期天数
foreach ($data AS $k1 => $v1) { foreach ($data as $k1 => $v1) {
if ($type == 1) { if ($type == 1) {
$customerTime = !empty($v1['contract_time']) && $v1['contract_time'] > $v1['customer_time'] ? $v1['contract_time'] : $v1['customer_time']; $customerTime = !empty($v1['contract_time']) && $v1['contract_time'] > $v1['customer_time'] ? $v1['contract_time'] : $v1['customer_time'];
$date = date('Y-m-d 00:00:00', ($customerTime + $limitDay['all'] * 86400) - $remainDay * 86400); $date = date('Y-m-d 00:00:00', ($customerTime + $limitDay['all'] * 86400) - $remainDay * 86400);
@ -1372,9 +1378,9 @@ class Customer extends Common
/** /**
* [今日进入客户池条件] * [今日进入客户池条件]
* @author Michael_xu
* @param * @param
* @return * @return
* @author Michael_xu
*/ */
public function getWhereByToday() public function getWhereByToday()
{ {
@ -1438,9 +1444,9 @@ class Customer extends Common
* @param int $userId 用户ID * @param int $userId 用户ID
* @param int $isDeal 成交客户是否占用拥有客户数条件1 占用 0 不占用 * @param int $isDeal 成交客户是否占用拥有客户数条件1 占用 0 不占用
* @param int $types 类型1 拥有客户数2 锁定客户数 * @param int $types 类型1 拥有客户数2 锁定客户数
* @author fanqi
* @since 2021-04-15
* @return int * @return int
* @since 2021-04-15
* @author fanqi
*/ */
public function getCountByHave($userId, $isDeal = 0, $types = 1) public function getCountByHave($userId, $isDeal = 0, $types = 1)
{ {
@ -1539,9 +1545,9 @@ class Customer extends Common
/** /**
* [客户成交新增数量] * [客户成交新增数量]
* @author Michael_xu
* @param * @param
* @return * @return
* @author Michael_xu
*/ */
public function getAddDealSql($map) public function getAddDealSql($map)
{ {
@ -1577,9 +1583,9 @@ class Customer extends Common
/** /**
* [客户统计sql] * [客户统计sql]
* @author Michael_xu
* @param * @param
* @return * @return
* @author Michael_xu
*/ */
public function getAddressCountBySql($map) public function getAddressCountBySql($map)
{ {

Loading…
Cancel
Save