diff --git a/application/admin/logic/PoolConfigLogic.php b/application/admin/logic/PoolConfigLogic.php index d25cdcd..a3019db 100644 --- a/application/admin/logic/PoolConfigLogic.php +++ b/application/admin/logic/PoolConfigLogic.php @@ -14,9 +14,9 @@ class PoolConfigLogic * 公海配置列表 * * @param array $param page 页码,limit 每页条数 - * @author fanqi - * @since 2021-03-30 * @return array + * @since 2021-03-30 + * @author fanqi */ public function getPoolList($param) { @@ -33,11 +33,11 @@ class PoolConfigLogic # 统计公海下的客户数量 $customerData = []; $customerList = db('crm_customer_pool_relation')->field(['pool_id', 'count(customer_id) AS customer_count'])->group('pool_id')->select(); - foreach ($customerList AS $key => $value) { + foreach ($customerList as $key => $value) { $customerData[$value['pool_id']] = $value['customer_count']; } - foreach ($list AS $key => $value) { + foreach ($list as $key => $value) { # 公海管理员 $adminUserIds = trim($value['admin_user_ids'], ','); $adminUserNames = db('admin_user')->whereIn('id', $adminUserIds)->column('realname'); @@ -66,9 +66,9 @@ class PoolConfigLogic * 设置多公海配置 * * @param $param - * @author fanqi - * @since 2021-03-30 * @return bool + * @since 2021-03-30 + * @author fanqi */ public function setPoolConfig($param) { @@ -111,7 +111,7 @@ class PoolConfigLogic 'department_ids' => !empty($param['department_ids']) ? ',' . $param['department_ids'] . ',' : '', 'status' => 1, 'before_owner_conf' => $param['before_owner_conf'], - 'before_owner_day' => $param['before_owner_day'], + 'before_owner_day' => $param['before_owner_day'], 'receive_conf' => $param['receive_conf'], 'receive_count' => $param['receive_count'], 'remind_conf' => $param['remind_conf'], @@ -161,9 +161,9 @@ class PoolConfigLogic * 公海配置详情 * * @param int $poolId 公海ID - * @author fanqi - * @since 2021-03-30 * @return array|bool + * @since 2021-03-30 + * @author fanqi */ public function readPool($poolId) { @@ -181,7 +181,7 @@ class PoolConfigLogic $adminUserIds = trim($data['admin_user_ids'], ','); $data['admin_user_ids'] = $adminUserIds; $data['admin_user_info'] = db('admin_user')->field(['id', 'realname', 'thumb_img'])->whereIn('id', $adminUserIds)->select(); - foreach ($data['admin_user_info'] AS $key => $value) { + foreach ($data['admin_user_info'] as $key => $value) { $data['admin_user_info'][$key]['thumb_img'] = getFullPath($value['thumb_img']); } @@ -189,7 +189,7 @@ class PoolConfigLogic $userIds = trim($data['user_ids'], ','); $data['user_ids'] = $userIds; $data['user_info'] = db('admin_user')->field(['id', 'realname', 'thumb_img'])->whereIn('id', $userIds)->select(); - foreach ($data['user_info'] AS $key => $value) { + foreach ($data['user_info'] as $key => $value) { $data['user_info'][$key]['thumb_img'] = getFullPath($value['thumb_img']); } @@ -203,7 +203,7 @@ class PoolConfigLogic # 公海规则 $data['rule'] = db('crm_customer_pool_rule')->where('pool_id', $data['pool_id'])->select(); - foreach ($data['rule'] AS $key => $value) { + foreach ($data['rule'] as $key => $value) { if (!empty($value['level'])) { $data['rule'][$key]['level'] = json_decode($value['level'], true); $data['rule'][$key]['level_setting'] = json_decode($value['level'], true); @@ -220,9 +220,9 @@ class PoolConfigLogic * 变更公海配置状态 * * @param array $param pool_id 公海ID, status 状态(1启用、0停用) - * @author fanqi - * @since 2021-03-30 * @return false|int|string + * @since 2021-03-30 + * @author fanqi */ public function changePoolStatus($param) { @@ -246,9 +246,9 @@ class PoolConfigLogic * 删除公海配置 * * @param int $poolId 公海ID - * @author fanqi - * @since 2021-03-30 * @return bool + * @since 2021-03-30 + * @author fanqi */ public function deletePool($poolId) { @@ -294,9 +294,9 @@ class PoolConfigLogic * 转移公海客户 * * @param array $param source_pool_id 源公海ID,target_pool_id 目标公海ID - * @author fanqi - * @since 2021-03-30 * @return bool + * @since 2021-03-30 + * @author fanqi */ public function transferPool($param) { @@ -313,7 +313,7 @@ class PoolConfigLogic $diffCustomerIds = array_diff($sourceCustomerIds, $targetCustomerIds); $data = []; - foreach ($diffCustomerIds AS $key => $value) { + foreach ($diffCustomerIds as $key => $value) { $data[] = [ 'customer_id' => $value, 'pool_id' => $param['target_pool_id'] @@ -340,9 +340,9 @@ class PoolConfigLogic /** * 获取客户级别列表 * - * @author fanqi - * @since 2021-04-22 * @return array + * @since 2021-04-22 + * @author fanqi */ public function getCustomerLevel() { @@ -357,9 +357,9 @@ class PoolConfigLogic * 获取公海字段列表 * * @param array $param pool_id 公海ID - * @author fanqi - * @since 2021-04-29 * @return bool|PDOStatement|string|Collection + * @since 2021-04-29 + * @author fanqi */ public function getPoolFieldList($param) { @@ -369,75 +369,75 @@ class PoolConfigLogic $data = db('admin_field')->field(['field', 'name', 'form_type', 'is_hidden', 'is_null', 'is_unique'])->where(['types' => 'crm_customer'])->select(); $address = [ - 'field' => 'address', - 'name' => '省、市、区/县', + 'field' => 'address', + 'name' => '省、市、区/县', 'form_type' => 'customer_address', 'is_hidden' => 0, - 'is_null' => 0, + 'is_null' => 0, 'is_unique' => 0, ]; $detailAddress = [ - 'field' => 'detail_address', - 'name' => '详细地址', + 'field' => 'detail_address', + 'name' => '详细地址', 'form_type' => 'text', 'is_hidden' => 0, - 'is_null' => 0, + 'is_null' => 0, 'is_unique' => 0, ]; $lastRecord = [ - 'field' => 'last_record', - 'name' => '最后跟进记录', + 'field' => 'last_record', + 'name' => '最后跟进记录', 'form_type' => 'text', 'is_hidden' => 0, - 'is_null' => 0, + 'is_null' => 0, 'is_unique' => 0, ]; $lastTime = [ - 'field' => 'last_time', - 'name' => '最后跟进时间', + 'field' => 'last_time', + 'name' => '最后跟进时间', 'form_type' => 'datetime', 'is_hidden' => 0, - 'is_null' => 0, + 'is_null' => 0, 'is_unique' => 0, ]; $beforeOwnerUser = [ - 'field' => 'before_owner_user_id', - 'name' => '前负责人', + 'field' => 'before_owner_user_id', + 'name' => '前负责人', 'form_type' => 'user', 'is_hidden' => 0, - 'is_null' => 0, + 'is_null' => 0, 'is_unique' => 0, ]; $intoPoolTime = [ - 'field' => 'into_pool_time', - 'name' => '进入公海时间', + 'field' => 'into_pool_time', + 'name' => '进入公海时间', 'form_type' => 'datetime', 'is_hidden' => 0, - 'is_null' => 0, + 'is_null' => 0, 'is_unique' => 0, ]; $createTime = [ - 'field' => 'create_time', - 'name' => '创建时间', + 'field' => 'create_time', + 'name' => '创建时间', 'form_type' => 'datetime', 'is_hidden' => 0, - 'is_null' => 0, + 'is_null' => 0, 'is_unique' => 0, ]; $updateTime = [ - 'field' => 'update_time', - 'name' => '更新时间', + 'field' => 'update_time', + 'name' => '更新时间', 'form_type' => 'datetime', 'is_hidden' => 0, - 'is_null' => 0, + 'is_null' => 0, 'is_unique' => 0, ]; $createUser = [ - 'field' => 'create_user_id', - 'name' => '创建人', + 'field' => 'create_user_id', + 'name' => '创建人', 'form_type' => 'user', 'is_hidden' => 0, - 'is_null' => 0, + 'is_null' => 0, 'is_unique' => 0, ]; array_push($data, $address, $detailAddress, $lastRecord, $lastTime, $createTime, $updateTime, $createUser, $beforeOwnerUser, $intoPoolTime); @@ -451,15 +451,15 @@ class PoolConfigLogic * * @param array $rules 规则数据 * @param int $poolId 公海ID - * @author fanqi - * @since 2021-03-30 * @return array + * @since 2021-03-30 + * @author fanqi */ private function getPoolRule($rules, $poolId) { $result = []; - foreach ($rules AS $key => $value) { + foreach ($rules as $key => $value) { $result[] = [ 'pool_id' => $poolId, 'type' => $value['type'], @@ -467,7 +467,8 @@ class PoolConfigLogic 'business_handle' => $value['business_handle'], 'level_conf' => $value['level_conf'], 'level' => json_encode($value['level']), - 'limit_day' => !empty($value['limit_day']) ? $value['limit_day'] : 0 + 'limit_day' => !empty($value['limit_day']) ? $value['limit_day'] : 0, + 'customer_type'=>$value['customer_type'], ]; } @@ -479,23 +480,23 @@ class PoolConfigLogic * * @param array $fields 字段列表 * @param int $poolId 公海ID - * @author fanqi - * @since 2021-03-30 * @return array + * @since 2021-03-30 + * @author fanqi */ private function getPoolField($fields, $poolId) { $result = []; - foreach ($fields AS $key => $value) { + foreach ($fields as $key => $value) { $result[] = [ - 'pool_id' => $poolId, - 'name' => $value['name'], + 'pool_id' => $poolId, + 'name' => $value['name'], 'field_name' => $value['field'], - 'form_type' => $value['form_type'], - 'is_hidden' => $value['is_hidden'], - 'is_null' => $value['is_null'], - 'is_unique' => $value['is_unique'] + 'form_type' => $value['form_type'], + 'is_hidden' => $value['is_hidden'], + 'is_null' => $value['is_null'], + 'is_unique' => $value['is_unique'] ]; } diff --git a/application/common/command/PoolCommand.php b/application/common/command/PoolCommand.php index 9b503ab..3621fde 100644 --- a/application/common/command/PoolCommand.php +++ b/application/common/command/PoolCommand.php @@ -23,20 +23,20 @@ class PoolCommand extends Command { protected $timer; protected $interval = 10; - + protected function configure() { $this->setName('pool') ->addArgument('status', Argument::REQUIRED, 'start/stop/reload/status/connections') ->addOption('d', null, Option::VALUE_NONE, 'daemon(守护进程)方式启动') ->setDescription('公海回收定时器'); - + // 读取数据库配置文件 $filename = ROOT_PATH . 'config' . DS . 'database.php'; // 重新加载数据库配置文件 Config::load($filename, 'database'); } - + /** * 初始化 * @@ -46,16 +46,16 @@ class PoolCommand extends Command protected function init(Input $input, Output $output) { global $argv; - + $argv[1] = $input->getArgument('status') ?: 'start'; - + if ($input->hasOption('d')) { $argv[2] = '-d'; } else { unset($argv[2]); } } - + /** * 停止定时器 */ @@ -63,7 +63,7 @@ class PoolCommand extends Command { Timer::del($this->timer); } - + /** * 启动定时器 */ @@ -75,22 +75,22 @@ class PoolCommand extends Command # 公海规则 $ruleList = db('crm_customer_pool_rule')->alias('rule')->field('rule.*') ->join('__CRM_CUSTOMER_POOL__ pool', 'pool.pool_id = rule.pool_id', 'LEFT')->where('pool.status', 1)->select(); - + if (!empty($ruleList)) { # 符合公海条件的客户IDS $customerIds = $this->getQueryCondition($ruleList); - + # 整理客户公海关联数据 $poolRelationData = $this->getCustomerPoolRelationData($customerIds); - + # 整理修改客户数据的条件(进入公海时间,前负责人...) $customerWhere = $this->getCustomerQueryCondition($customerIds); - + Db::startTrans(); try { # 将客户退回公海 if (!empty($poolRelationData)) Db::name('crm_customer_pool_relation')->insertAll($poolRelationData); - + # 修改客户数据 if (!empty($customerWhere)) { Db::name('crm_customer')->whereIn('customer_id', $customerWhere)->exp('before_owner_user_id', 'owner_user_id')->update([ @@ -100,10 +100,10 @@ class PoolCommand extends Command 'into_pool_time' => time() ]); } - $this->updateInfo($ruleList,$customerWhere); + $this->updateInfo($ruleList, $customerWhere); # 删除联系人的负责人 Db::name('crm_contacts')->whereIn('customer_id', $customerWhere)->update(['owner_user_id' => '']); - + Db::commit(); } catch (\Exception $e) { Db::rollback(); @@ -112,6 +112,7 @@ class PoolCommand extends Command } }); } + /** * 自动入公海操作记录 * @param $ruleList @@ -136,21 +137,20 @@ class PoolCommand extends Command if ($v['type'] == 1) updateActionLog(0, 'crm_customer', $val, '', '', '超过' . $time . '天无新建跟进记录自动进入公海'); if ($v['type'] == 2) updateActionLog(0, 'crm_customer', $val, '', '', '超过' . $time . '天无新建商机自动进入公海'); if ($v['type'] == 3) updateActionLog(0, 'crm_customer', $val, '', '', '超过' . $time . '天未成交自动进入公海'); - + } } } - - - + + protected function execute(Input $input, Output $output) { # 动态修改运行时参数 set_time_limit(0); ini_set('memory_limit', '512M'); - + $this->init($input, $output); - + # 创建定时器任务 $task = new Worker(); $task->name = 'pool'; @@ -158,7 +158,7 @@ class PoolCommand extends Command $task->onWorkerStart = [$this, 'start']; $task->runAll(); } - + /** * 整理修改客户数据的条件 * @@ -170,16 +170,16 @@ class PoolCommand extends Command private function getCustomerQueryCondition($customerIds) { $result = []; - + foreach ($customerIds as $k1 => $v1) { foreach ($v1 as $k2 => $v2) { $result[] = $v2; } } - + return array_unique($result); } - + /** * 客户公海关联数据 * @@ -191,27 +191,27 @@ class PoolCommand extends Command private function getCustomerPoolRelationData($customerIds) { $result = []; - + # 用于排重 $repeat = []; - + foreach ($customerIds as $k1 => $v1) { $customerArray = array_unique($v1); foreach ($customerArray as $k2 => $v2) { if (!empty($repeat[$k1][$v2])) continue; - + $result[] = [ 'pool_id' => $k1, 'customer_id' => $v2 ]; - + $repeat[$k1][$v2] = $v2; } } - + return $result; } - + /** * 获取符合公海条件的客户 * @@ -223,18 +223,18 @@ class PoolCommand extends Command private function getQueryCondition($rules) { $result = []; - + foreach ($rules as $k => $v) { - + 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'])); - if ($v['type'] == 2) $result[$v['pool_id']] = array_merge($result[$v['pool_id']], $this->getBusinessQueryResult($v['level_conf'], $v['level'], $v['deal_handle'])); - if ($v['type'] == 3) $result[$v['pool_id']] = array_merge($result[$v['pool_id']], $this->getDealQueryResult($v['level_conf'], $v['level'], $v['business_handle'])); + 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']], $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']], $this->getDealQueryResult($v['level_conf'], $v['level'], $v['business_handle'], $v['customer_type'])); } - + return $result; } - + /** * N天内无新建跟进记录的客户 * @@ -246,14 +246,14 @@ class PoolCommand extends Command * @since 2021-04-01 * @author fanqi */ - private function getFollowUpQueryResult($type, $levels, $dealStatus, $businessStatus) + private function getFollowUpQueryResult($type, $levels, $dealStatus, $businessStatus, $customerType) { # 转换格式 $levels = json_decode($levels, true); - + # 默认条件 $where = "`customer`.`owner_user_id` > 0"; - + # 所有用户,不区分级别 if ($type == 1) { foreach ($levels as $k1 => $v1) { @@ -263,7 +263,7 @@ class PoolCommand extends Command } } } - + # 根据用户级别设置条件 if ($type == 2) { foreach ($levels as $k1 => $v1) { @@ -276,29 +276,35 @@ class PoolCommand extends Command } } } - + # 获取最小天数,对于没有设置级别的客户数据使用 $minLimit = $this->getMinDay($levels); $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`))) )"; } - + # 选择不进入公海的客户(已成交客户) if (!empty($dealStatus)) $where .= " AND (`customer`.`deal_status` <> '已成交' OR ISNULL(`customer`.`deal_status`))"; - + # 选择不进入公海的客户(有商机客户) if (!empty($businessStatus)) $where .= " AND ISNULL(`business`.`customer_id`)"; - + # 锁定的客户不提醒 $where .= " AND `customer`.`is_lock` = 0"; - + + + # 过滤客户类型 + if (!empty($customerType)) { + $where .= "And `customer`.`customer_type` in " . $customerType; + } + # 查询符合条件的客户 return db('crm_customer') ->alias('customer')->join('__CRM_BUSINESS__ business', 'business.customer_id = customer.customer_id', 'LEFT') ->where($where)->column('customer.customer_id'); } - + /** * N天内无新建商机的客户 * @@ -309,14 +315,14 @@ class PoolCommand extends Command * @since 2021-04-01 * @author fanqi */ - private function getBusinessQueryResult($type, $levels, $dealStatus) + private function getBusinessQueryResult($type, $levels, $dealStatus, $customerType) { # 转换格式 $levels = json_decode($levels, true); - + # 默认条件 $where = "`customer`.`owner_user_id` > 0"; - + # 所有用户,不区分级别 if ($type == 1) { foreach ($levels as $k1 => $v1) { @@ -326,7 +332,7 @@ class PoolCommand extends Command } } } - + # 根据用户级别设置条件 if ($type == 2) { foreach ($levels as $k1 => $v1) { @@ -339,26 +345,30 @@ class PoolCommand extends Command } } } - + # 获取最小天数,对于没有设置级别的客户数据使用 $minLimit = $this->getMinDay($levels); $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`)) )"; } - + # 选择不进入公海的客户(已成交客户) if (!empty($dealStatus)) $where .= " AND (`customer`.`deal_status` <> '已成交' OR ISNULL(`customer`.`deal_status`))"; - + # 锁定的客户不提醒 $where .= " AND `customer`.`is_lock` = 0"; - + + # 过滤客户类型 + if (!empty($customerType)) { + $where .= "And `customer`.`customer_type` in " . $customerType; + } # 查询匹配条件的客户 return db('crm_customer')->alias('customer') ->join('__CRM_BUSINESS__ business', 'business.customer_id = customer.customer_id', 'LEFT') ->where($where)->column('customer.customer_id'); } - + /** * N天内没有成交的客户 * @@ -369,14 +379,14 @@ class PoolCommand extends Command * @since 2021-04-01 * @author fanqi */ - private function getDealQueryResult($type, $levels, $businessStatus) + private function getDealQueryResult($type, $levels, $businessStatus, $customerType) { # 转换格式 $levels = json_decode($levels, true); - + # 默认条件 $where = "`customer`.`owner_user_id` > 0"; - + # 所有用户,不区分级别 if ($type == 1) { foreach ($levels as $k1 => $v1) { @@ -386,7 +396,7 @@ class PoolCommand extends Command } } } - + # 根据用户级别设置条件 if ($type == 2) { foreach ($levels as $k1 => $v1) { @@ -399,27 +409,31 @@ class PoolCommand extends Command } } } - + # 获取最小天数,对于没有设置级别的客户数据使用 $minLimit = $this->getMinDay($levels); $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`)) )"; } - + # 选择不进入公海的客户(有商机客户) if (!empty($businessStatus)) $where .= " AND ISNULL(`business`.`customer_id`)"; - + # 锁定的客户不提醒 $where .= " AND `customer`.`is_lock` = 0"; - + + # 过滤客户类型 + if (!empty($customerType)) { + $where .= "And `customer`.`customer_type` in " . $customerType; + } # 查询符合条件的客户 return db('crm_customer')->alias('customer') ->join('__CRM_BUSINESS__ business', 'business.customer_id = customer.customer_id', 'LEFT') ->join('__CRM_CONTRACT__ contract', 'contract.customer_id = customer.customer_id', 'LEFT') ->where($where)->column('customer.customer_id'); } - + /** * 获取公海规则最小数字(最快进入公海天数) * @@ -431,11 +445,11 @@ class PoolCommand extends Command private function getMinDay($data) { $number = 1; - + foreach ($data as $k1 => $v1) { if (empty($number) || $v1['limit_day'] < $number) $number = $v1['limit_day']; } - + return $number; } } \ No newline at end of file diff --git a/application/crm/controller/Customer.php b/application/crm/controller/Customer.php index 91d1623..a29eba9 100644 --- a/application/crm/controller/Customer.php +++ b/application/crm/controller/Customer.php @@ -127,9 +127,9 @@ class Customer extends ApiCommon $customerCheck = db('crm_customer_check')->where(['customer_id' => $param['id']])->where(['check_status' => 0])->find(); if (!empty($customerCheck)) { $data['flow_id'] = $customerCheck['flow_id']; - $data['owner_user_id']=$customerCheck['user_id']; - $data['customer_check_id']=$customerCheck['customer_check_id']; - $data['apply_user_name']=db('admin_user')->where('id', $customerCheck['create_user_id'])->column("username"); + $data['owner_user_id'] = $customerCheck['user_id']; + $data['customer_check_id'] = $customerCheck['customer_check_id']; + $data['apply_user_name'] = db('admin_user')->where('id', $customerCheck['create_user_id'])->column("username"); } return resultArray(['data' => $data]); } @@ -1175,4 +1175,20 @@ class Customer extends ApiCommon return resultArray(['data' => $data]); } + + /** + * 客户类型列表 + * + * @return \think\response\Json + * @since 2021-03-29 + * @author fanqi + */ + public function Type() + { + $data = db('admin_field')->where(['types' => 'crm_customer', 'field' => 'crm_lthugd'])->value('options'); + + $data = explode(',', $data); + + return resultArray(['data' => $data]); + } } \ No newline at end of file diff --git a/application/crm/controller/CustomerPool.php b/application/crm/controller/CustomerPool.php index 5c7cc48..dd5ce4f 100644 --- a/application/crm/controller/CustomerPool.php +++ b/application/crm/controller/CustomerPool.php @@ -54,7 +54,7 @@ class CustomerPool extends ApiCommon parent::_initialize(); } } - + /** * 公海列表 * @@ -65,12 +65,12 @@ class CustomerPool extends ApiCommon public function index() { if (empty($this->param['pool_id'])) return resultArray(['error' => '缺少公海ID']); - + $data = (new CustomerPoolLogic())->getPoolList($this->param); - + return resultArray(['data' => $data]); } - + /** * 详情 * @@ -81,16 +81,16 @@ class CustomerPool extends ApiCommon public function read() { if (empty($this->param['pool_id']) || empty($this->param['customer_id'])) return resultArray(['error' => '参数错误!']); - + $userInfo = $this->userInfo; $param = $this->param; $param['user_id'] = $userInfo['id']; - + $data = (new CustomerPoolLogic())->getPoolData($param); - + return resultArray(['data' => $data]); } - + /** * 删除公海客户 * @@ -101,16 +101,16 @@ class CustomerPool extends ApiCommon public function delete() { if (empty($this->param['id'])) return resultArray(['error' => '请选择要删除的客户!']); - + $this->param['user_id'] = $this->userInfo['id']; - + $result = (new CustomerPoolLogic())->deletePoolCustomer($this->param); - + if (!empty($result)) return resultArray(['error' => $result]); - + return resultArray(['data' => '删除成功!']); } - + /** * 公海池列表 * @@ -121,10 +121,10 @@ class CustomerPool extends ApiCommon public function pondList() { $data = (new CustomerPoolLogic())->getPondList(['user_id' => $this->userInfo['id'], 'structure_id' => $this->userInfo['structure_id']]); - + return resultArray(['data' => $data]); } - + /** * 公海字段 * @@ -135,16 +135,16 @@ class CustomerPool extends ApiCommon public function field() { if (empty($this->param['pool_id'])) return resultArray(['error' => '缺少公海ID!']); - + $userInfo = $this->userInfo; $param = $this->param; $param['user_id'] = $userInfo['id']; - + $data = (new CustomerPoolLogic())->getFieldList($param); - + return resultArray(['data' => $data]); } - + /** * 高级筛选字段列表 * @@ -155,12 +155,12 @@ class CustomerPool extends ApiCommon public function advanced() { if (empty($this->param['types'])) return resultArray(['error' => '缺少模块类型!']); - + $data = (new CustomerPoolLogic())->getAdvancedFilterFieldList($this->param); - + return resultArray(['data' => $data]); } - + /** * 领取公海池客户 * @@ -171,17 +171,17 @@ class CustomerPool extends ApiCommon public function receive() { if (empty($this->param['customer_id'])) return resultArray(['error' => '请选择要领取的公海客户!']); - + $param = $this->param; $param['user_id'] = $this->userInfo['id']; - + $result = (new CustomerPoolLogic())->customerReceiveExamine($param); - + if (!empty($result)) return resultArray(['error' => $result]); - + return resultArray(['data' => '领取成功!']); } - + /** * 分配公海客户 * @@ -193,14 +193,14 @@ class CustomerPool extends ApiCommon { if (empty($this->param['customer_id'])) return resultArray(['error' => '请选择要分配的公海客户!']); if (empty($this->param['user_id'])) return resultArray(['error' => '请选择要分配的员工!']); - + $result = (new CustomerPoolLogic())->distributeCustomer($this->param); - + if (!empty($result)) return resultArray(['error' => $result]); - + return resultArray(['data' => '分配成功!']); } - + // 公海客户导入模板下载 public function excelDownload($save_path = '') { @@ -209,11 +209,11 @@ class CustomerPool extends ApiCommon $field_list = $this->fieldsData($param); $excelModel->excelImportDownload($field_list, 'crm_pool', $save_path); } - + // 导入 public function import() { - + $param = $this->param; $userInfo = $this->userInfo; $excelModel = new \app\admin\model\Excel(); @@ -227,7 +227,7 @@ class CustomerPool extends ApiCommon RecordActionLog($userInfo['id'], 'crm_customer', 'excel', '导入公海客户', '', '', '导入公海客户'); return resultArray(['data' => $excelModel->getError()]); } - + // 导出 public function export() { @@ -260,7 +260,7 @@ class CustomerPool extends ApiCommon RecordActionLog($userInfo['id'], 'crm_customer', 'excelexport', $action_name, '', '', '导出客户'); return resultArray(['error' => 'error']); } - + /** * 公海权限 * @@ -273,12 +273,12 @@ class CustomerPool extends ApiCommon $param = $this->param; $param['user_id'] = $this->userInfo['id']; $param['structure_id'] = $this->userInfo['structure_id']; - + $data = (new CustomerPoolLogic())->getAuthorityData($param); - + return resultArray(['data' => $data]); } - + /** * 公海字段样式 * @@ -289,16 +289,16 @@ class CustomerPool extends ApiCommon public function fieldConfig() { if (empty($this->param['pool_id'])) return resultArray(['error' => '缺少公海ID!']); - + $param = $this->param; $userInfo = $this->userInfo; $param['user_id'] = $userInfo['id']; - + $data = (new CustomerPoolLogic())->getFieldConfigIndex($param); - + return resultArray(['data' => $data]); } - + /** * 设置公海字段宽度 * @@ -311,16 +311,16 @@ class CustomerPool extends ApiCommon if (empty($this->param['pool_id'])) return resultArray(['error' => '缺少公海ID!']); if (empty($this->param['field'])) return resultArray(['error' => '缺少字段名称!']); if (empty($this->param['width'])) return resultArray(['error' => '缺少宽度值!']); - + $param = $this->param; $userInfo = $this->userInfo; $param['user_id'] = $userInfo['id']; - + (new CustomerPoolLogic())->setFieldWidth($param); - + return resultArray(['data' => '操作成功!']); } - + /** * 设置公海字段样式 * @@ -332,16 +332,16 @@ class CustomerPool extends ApiCommon { if (empty($this->param['pool_id'])) return resultArray(['缺少公海ID!']); if (empty($this->param['value']) && empty($this->param['hide_value'])) return resultArray(['error' => '字段参数错误!']); - + $param = $this->param; $userInfo = $this->userInfo; $param['user_id'] = $userInfo['id']; - + (new CustomerPoolLogic())->setFieldConfig($param); - + return resultArray(['data' => '操作成功!']); } - + /** * 导入模板 * @param $param @@ -352,38 +352,38 @@ class CustomerPool extends ApiCommon */ public function fieldsData($param) { - $where=['pool_id' => $param['pool_id'], 'is_hidden' => 0, - 'field_name' => ['not in', ['deal_status','create_user_id']]]; - if($param['is_excel']==1){ - $where=['pool_id' => $param['pool_id'], 'is_hidden' => 0, + $where = ['pool_id' => $param['pool_id'], 'is_hidden' => 0, + 'field_name' => ['not in', ['deal_status', 'create_user_id']]]; + if ($param['is_excel'] == 1) { + $where = ['pool_id' => $param['pool_id'], 'is_hidden' => 0, 'field_name' => ['not in', ['deal_status']]]; } $pool_list = db('crm_customer_pool_field_setting')->where($where)->field('field_name as field,form_type,name')->select(); $fieldParam['types'] = 'crm_customer'; $fieldParam['action'] = 'excel'; $setting = []; - $list=[]; + $list = []; foreach ($pool_list as $k => &$v) { switch ($v['field']) { case 'address': - if($param['is_excel']!=1){ + if ($param['is_excel'] != 1) { $v['field'] = 'customer_address'; $v['form_type'] = 'map_address'; - $list[]=$v; + $list[] = $v; unset($pool_list[$k]); } break; case 'detail_address': - if($param['is_excel']!=1){ + if ($param['is_excel'] != 1) { unset($pool_list[$k]); } break; case ($v['form_type'] == 'select') || ($v['form_type'] == 'checkbox') : - $set= db('admin_field')->where(['types' => 'crm_customer', 'field' => $v['field']])->find(); + $set = db('admin_field')->where(['types' => 'crm_customer', 'field' => $v['field']])->find(); $pool_list[$k]['setting'] = explode(chr(10), $set['setting']); break; default : - if($param['is_excel']!=1){ + if ($param['is_excel'] != 1) { $pool_list[$k]['setting'] = []; } break; @@ -398,7 +398,7 @@ class CustomerPool extends ApiCommon // } // } } - $pool_list=array_merge($pool_list,$list); + $pool_list = array_merge($pool_list, $list); return $pool_list; } @@ -440,7 +440,7 @@ class CustomerPool extends ApiCommon $checkData['check_time'] = time(); $checkData['content'] = $param['content']; $checkData['flow_id'] = $dataInfo['flow_id']; - $checkData['order_id'] = $dataInfo['order_id'] ? : 1; + $checkData['order_id'] = $dataInfo['order_id'] ?: 1; $checkData['status'] = $status; if ($status == 1) { @@ -448,8 +448,8 @@ class CustomerPool extends ApiCommon //固定流程 //获取下一审批信息 $nextStepData = $examineStepModel->nextStepUser($dataInfo['owner_user_id'], $dataInfo['flow_id'], 'crm_customer_check', $param['id'], $dataInfo['order_id'], $user_id); - $next_user_ids = $nextStepData['next_user_ids'] ? : []; - $customerCheckData['order_id'] = $nextStepData['order_id'] ? : ''; + $next_user_ids = $nextStepData['next_user_ids'] ?: []; + $customerCheckData['order_id'] = $nextStepData['order_id'] ?: ''; if (!$next_user_ids) { $is_end = 1; //审批结束 @@ -462,7 +462,7 @@ class CustomerPool extends ApiCommon } else { //自选流程 $is_end = $param['is_end'] ? 1 : ''; - $check_user_id = $param['check_user_id'] ? : ''; + $check_user_id = $param['check_user_id'] ?: ''; if ($is_end !== 1 && empty($check_user_id)) { return resultArray(['error' => '请选择下一审批人']); } @@ -481,7 +481,7 @@ class CustomerPool extends ApiCommon // $examineRecordModel->setEnd(['types' => 'crm_contract','types_id' => $param['id']]); } //已审批人ID - $customerCheckData['flow_user_id'] = stringToArray($dataInfo['flow_user_id']) ? arrayToString(array_merge(stringToArray($dataInfo['flow_user_id']),[$user_id])) : arrayToString([$user_id]); + $customerCheckData['flow_user_id'] = stringToArray($dataInfo['flow_user_id']) ? arrayToString(array_merge(stringToArray($dataInfo['flow_user_id']), [$user_id])) : arrayToString([$user_id]); $resCustomerCheck = db('crm_customer_check')->where(['customer_check_id' => $param['id']])->update($customerCheckData); if ($resCustomerCheck) { //审批记录 @@ -499,8 +499,8 @@ class CustomerPool extends ApiCommon ); $customerData = []; - $customerData['user_id']=$dataInfo['user_id']; - $customerData['customer_id']=$dataInfo['customer_id']; + $customerData['user_id'] = $dataInfo['user_id']; + $customerData['customer_id'] = $dataInfo['customer_id']; $result = (new CustomerPoolLogic())->receiveCustomers($customerData); @@ -536,4 +536,20 @@ class CustomerPool extends ApiCommon return resultArray(['error' => '审批失败,请重试!']); } } + + /** + * 总经理公海池消息提醒 + * + * @return Json + * @since 2021-04-14 + * @author fanqi + */ + public function num() + { + + $customerPoolCount = db('crm_customer_pool_relation')->where("pool_id",array('eq',3)) + ->count(); + + return resultArray(['data' => $customerPoolCount]); + } } diff --git a/application/crm/model/Customer.php b/application/crm/model/Customer.php index ce3c7a1..cea2169 100644 --- a/application/crm/model/Customer.php +++ b/application/crm/model/Customer.php @@ -162,7 +162,7 @@ class Customer extends Common $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); + $map['customer.crm_roziuw'] = array('in', $groupNameArray); } # 代办事项 - 待进入公海 $remindWhere = []; diff --git a/config/route_crm.php b/config/route_crm.php index 492cb2d..a171957 100644 --- a/config/route_crm.php +++ b/config/route_crm.php @@ -56,6 +56,8 @@ return [ 'crm/customer/poolAuthority' => ['crm/customer/poolAuthority', ['method' => 'POST']], // 【客户】级别列表 'crm/customer/level' => ['crm/customer/level', ['method' => 'POST']], + // 【客户】类型列表 + 'crm/customer/type' => ['crm/customer/type', ['method' => 'POST']], // 【客户】公海列表 'crm/customerPool/index' => ['crm/customerPool/index', ['method' => 'POST']], @@ -89,6 +91,8 @@ return [ 'crm/customerPool/setFieldWidth' => ['crm/customerPool/setFieldWidth', ['method' => 'POST']], // 【客户】设置公海字段配置 'crm/customerPool/setFieldConfig' => ['crm/customerPool/setFieldConfig', ['method' => 'POST']], + // 【客户】总经理客户公海池消息 + 'crm/customerPool/num' => ['crm/customerPool/num', ['method' => 'POST']], // 【客户】回访 'crm/visit/index' => ['crm/visit/index', ['method' => 'POST']],