Compare commits

..

No commits in common. 'master' and 'yy' have entirely different histories.
master ... yy

@ -12,7 +12,6 @@ use think\Request;
use think\Db;
use app\common\adapter\AuthAdapter;
use app\common\controller\Common;
use think\Session;
class ApiCommon extends Common
@ -26,9 +25,6 @@ class ApiCommon extends Common
$authKey = trim($header['authkey']);
$sessionId = trim($header['sessionid']);
if ($authKey == "wxwork" && Session::get('user_id')) {
return;
}
$paramArr = $request->param();
$platform = $paramArr['platform'] ? '_'.$paramArr['platform'] : ''; //请求平台(mobile,ding)
$cache = Cache::get('Auth_'.$authKey.$platform);

@ -295,7 +295,7 @@ class ExamineFlow extends ApiCommon
$flow_id = $param['flow_id'];
$types = $param['types'];
$types_id = $param['types_id'];
$typesArr = ['crm_customer_check','crm_business','crm_contract', 'crm_receivables', 'crm_invoice', 'oa_examine', 'jxc_purchase', 'jxc_retreat', 'jxc_sale', 'jxc_salereturn', 'jxc_payment', 'jxc_collection', 'jxc_allocation', 'jxc_inventory'];
$typesArr = ['crm_contract', 'crm_receivables', 'crm_invoice', 'oa_examine', 'jxc_purchase', 'jxc_retreat', 'jxc_sale', 'jxc_salereturn', 'jxc_payment', 'jxc_collection', 'jxc_allocation', 'jxc_inventory'];
if (!$types || !in_array($types, $typesArr)) {
return resultArray(['error' => '参数错误']);
}

@ -14,9 +14,9 @@ class PoolConfigLogic
* 公海配置列表
*
* @param array $param page 页码limit 每页条数
* @return array
* @since 2021-03-30
* @author fanqi
* @since 2021-03-30
* @return array
*/
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
* @return bool
* @since 2021-03-30
* @author fanqi
* @since 2021-03-30
* @return bool
*/
public function setPoolConfig($param)
{
@ -97,11 +97,6 @@ class PoolConfigLogic
return false;
}
if (empty($param['customer_type'])) {
$this->error = '请设置客户类型!';
return false;
}
$repeatWhere['pool_name'] = $param['pool_name'];
if (!empty($param['pool_id'])) $repeatWhere['pool_id'] = ['neq', $param['pool_id']];
if (db('crm_customer_pool')->where($repeatWhere)->value('pool_id')) {
@ -123,8 +118,7 @@ class PoolConfigLogic
'remain_day' => $param['remain_day'],
'recycle_conf' => $param['recycle_conf'],
'create_user_id' => $param['user_id'],
'create_time' => time(),
'customer_type' => $param['customer_type'],
'create_time' => time()
];
Db::startTrans();
@ -167,9 +161,9 @@ class PoolConfigLogic
* 公海配置详情
*
* @param int $poolId 公海ID
* @return array|bool
* @since 2021-03-30
* @author fanqi
* @since 2021-03-30
* @return array|bool
*/
public function readPool($poolId)
{
@ -187,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']);
}
@ -195,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']);
}
@ -209,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);
@ -226,9 +220,9 @@ class PoolConfigLogic
* 变更公海配置状态
*
* @param array $param pool_id 公海ID, status 状态1启用、0停用
* @return false|int|string
* @since 2021-03-30
* @author fanqi
* @since 2021-03-30
* @return false|int|string
*/
public function changePoolStatus($param)
{
@ -252,9 +246,9 @@ class PoolConfigLogic
* 删除公海配置
*
* @param int $poolId 公海ID
* @return bool
* @since 2021-03-30
* @author fanqi
* @since 2021-03-30
* @return bool
*/
public function deletePool($poolId)
{
@ -300,9 +294,9 @@ class PoolConfigLogic
* 转移公海客户
*
* @param array $param source_pool_id 源公海IDtarget_pool_id 目标公海ID
* @return bool
* @since 2021-03-30
* @author fanqi
* @since 2021-03-30
* @return bool
*/
public function transferPool($param)
{
@ -319,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']
@ -346,9 +340,9 @@ class PoolConfigLogic
/**
* 获取客户级别列表
*
* @return array
* @since 2021-04-22
* @author fanqi
* @since 2021-04-22
* @return array
*/
public function getCustomerLevel()
{
@ -363,9 +357,9 @@ class PoolConfigLogic
* 获取公海字段列表
*
* @param array $param pool_id 公海ID
* @return bool|PDOStatement|string|Collection
* @since 2021-04-29
* @author fanqi
* @since 2021-04-29
* @return bool|PDOStatement|string|Collection
*/
public function getPoolFieldList($param)
{
@ -457,15 +451,15 @@ class PoolConfigLogic
*
* @param array $rules 规则数据
* @param int $poolId 公海ID
* @return array
* @since 2021-03-30
* @author fanqi
* @since 2021-03-30
* @return array
*/
private function getPoolRule($rules, $poolId)
{
$result = [];
foreach ($rules as $key => $value) {
foreach ($rules AS $key => $value) {
$result[] = [
'pool_id' => $poolId,
'type' => $value['type'],
@ -473,7 +467,7 @@ 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
];
}
@ -485,15 +479,15 @@ class PoolConfigLogic
*
* @param array $fields 字段列表
* @param int $poolId 公海ID
* @return array
* @since 2021-03-30
* @author fanqi
* @since 2021-03-30
* @return array
*/
private function getPoolField($fields, $poolId)
{
$result = [];
foreach ($fields as $key => $value) {
foreach ($fields AS $key => $value) {
$result[] = [
'pool_id' => $poolId,
'name' => $value['name'],

@ -22,7 +22,7 @@ class ExamineFlow extends Common
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
protected $autoWriteTimestamp = true;
protected $typesArr = ['crm_customer_check', 'crm_business','crm_contract', 'crm_receivables', 'crm_invoice', 'oa_examine', 'jxc_purchase', 'jxc_retreat', 'jxc_sale', 'jxc_salereturn', 'jxc_payment', 'jxc_collection', 'jxc_allocation', 'jxc_inventory'];
protected $typesArr = ['crm_contract', 'crm_receivables', 'crm_invoice', 'oa_examine', 'jxc_purchase', 'jxc_retreat', 'jxc_sale', 'jxc_salereturn', 'jxc_payment', 'jxc_collection', 'jxc_allocation', 'jxc_inventory'];
/**
* [getDataList 审批流程list]

@ -176,58 +176,24 @@ class ExamineStep extends Common
}
switch (trim($types)) {
case 'oa_examine' :
$dataInfo = db('oa_examine')->where(['examine_id' => intval($types_id)])->field('create_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'crm_contract' :
$dataInfo = db('crm_contract')->where(['contract_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'crm_receivables' :
$dataInfo = db('crm_receivables')->where(['receivables_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'crm_invoice':
$dataInfo = db('crm_invoice')->where(['invoice_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'jxc_purchase':
$dataInfo = db('jxc_purchase')->where(['purchase_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'jxc_retreat':
$dataInfo = db('jxc_retreat')->where(['retreat_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'jxc_sale':
$dataInfo = db('jxc_sale')->where(['sale_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'jxc_salereturn':
$dataInfo = db('jxc_salereturn')->where(['salereturn_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'jxc_payment':
$dataInfo = db('jxc_payment')->where(['payment_note_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'jxc_collection':
$dataInfo = db('jxc_collection')->where(['collection_note_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'jxc_inventory':
$dataInfo = db('jxc_inventory')->where(['inventory_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'jxc_allocation':
$dataInfo = db('jxc_allocation')->where(['allocation_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'crm_customer_check':
$dataInfo = db('crm_customer_check')->where(['customer_check_id' => intval($types_id)])->field('user_id,create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'crm_business':
$dataInfo = db('crm_business')->where(['business_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find();
break;
case 'oa_examine' : $dataInfo = db('oa_examine')->where(['examine_id' => intval($types_id)])->field('create_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'crm_contract' : $dataInfo = db('crm_contract')->where(['contract_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'crm_receivables' : $dataInfo = db('crm_receivables')->where(['receivables_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'crm_invoice': $dataInfo = db('crm_invoice')->where(['invoice_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'jxc_purchase': $dataInfo = db('jxc_purchase')->where(['purchase_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'jxc_retreat': $dataInfo = db('jxc_retreat')->where(['retreat_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'jxc_sale': $dataInfo = db('jxc_sale')->where(['sale_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'jxc_salereturn': $dataInfo = db('jxc_salereturn')->where(['salereturn_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'jxc_payment': $dataInfo = db('jxc_payment')->where(['payment_note_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'jxc_collection': $dataInfo = db('jxc_collection')->where(['collection_note_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'jxc_inventory': $dataInfo = db('jxc_inventory')->where(['inventory_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'jxc_allocation': $dataInfo = db('jxc_allocation')->where(['allocation_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
}
$stepInfo = [];
if ($dataInfo['flow_id'] && !in_array($dataInfo['check_status'],['5'])) {
//固定审批流
$stepInfo = db('admin_examine_step')->where(['flow_id' => $dataInfo['flow_id'],'order_id' => $dataInfo['order_id']])->find();
}
if ($types=="crm_customer_check"){
$dataInfo['create_user_id']=$dataInfo['user_id'];
$dataInfo['owner_user_id']=$dataInfo['user_id'];
}
$data = [];
$data['stepInfo'] = $stepInfo;
$data['step_id'] = $stepInfo['step_id'] ? : '';
@ -257,9 +223,7 @@ class ExamineStep extends Common
}
break;
case 2 :
case 3 :
$examine_user_id_arr = stringToArray($stepInfo['user_id']);
break;
case 3 :$examine_user_id_arr = stringToArray($stepInfo['user_id']); break;
case 4 :
$order_id = $stepInfo['order_id'] ? $stepInfo['order_id']-1 : 0;
$last_step_id = db('admin_examine_step')->where(['flow_id' => $stepInfo['flow_id'],'order_id' => $order_id])->value('step_id');
@ -277,8 +241,7 @@ class ExamineStep extends Common
$examine_user_id_arr = stringToArray($examine_user_id);
}
break;
default :
$examine_user_id_arr = [];
default : $examine_user_id_arr = [];
}
return array_unique($examine_user_id_arr) ? ','.implode(',',array_filter(array_unique($examine_user_id_arr))).',' : '';
}
@ -315,18 +278,10 @@ class ExamineStep extends Common
$adminUserId = model('User')->getAdminId(); //管理员ID
//获取有审核权限的user_id
switch ($types) {
case 'oa_examine' :
$examine_user_id_arr = $userModel->getUserByPer('oa', 'examine', 'check');
break;
case 'crm_contract' :
$examine_user_id_arr = $userModel->getUserByPer('crm', 'contract', 'check');
break;
case 'crm_receivables' :
$examine_user_id_arr = $userModel->getUserByPer('crm', 'receivables', 'check');
break;
case 'crm_invoice' :
$examine_user_id_arr = $userModel->getUserByPer('crm', 'invoice', 'check');
break;
case 'oa_examine' : $examine_user_id_arr = $userModel->getUserByPer('oa', 'examine', 'check'); break;
case 'crm_contract' : $examine_user_id_arr = $userModel->getUserByPer('crm', 'contract', 'check'); break;
case 'crm_receivables' : $examine_user_id_arr = $userModel->getUserByPer('crm', 'receivables', 'check'); break;
case 'crm_invoice' : $examine_user_id_arr = $userModel->getUserByPer('crm', 'invoice', 'check'); break;
}
$examine_user_id_arr = $examine_user_id_arr ? array_merge($examine_user_id_arr, $adminUserId) : $adminUserId;
return $examine_user_id_arr;

@ -485,10 +485,7 @@ class Field extends Model
}
//生成字段名
if (!empty($param['field'])) {
$data['field'] = $param['field'];
} else if (!$data['field']) $data['field'] = $this->createField($types, $types == 'oa_examine' ? 'oa_' : 'crm_');
if (!$data['field']) $data['field'] = $this->createField($types, $types == 'oa_examine' ? 'oa_' : 'crm_');
$rule = [
'field' => ['regex' => '/^[a-z]([a-z]|_)+[a-z]$/i'],
@ -1253,11 +1250,9 @@ class Field extends Model
// $new_field_list[] = db('admin_field')->where(['types_id' => 0, 'field' => 'owner_user_id'])->find();
// }
if ($new_field_list) $field_list = array_merge(collection($field_list)->toArray(), $new_field_list);
$adminTypes = adminGroupTypes($user_id);
foreach ($field_list as $k => $v) {
# 处理字段授权
$field_list[$k]['writeStatus'] = 1;
if ($field_list[$k]['name'] == '客户级别' && !in_array(1, $adminTypes)) $field_list[$k]['writeStatus'] = 0;
if (!$userLevel && $param['module'] == 'crm' && !empty($grantData[$param['types']])) {
$status = getFieldGrantStatus($v['field'], $grantData[$param['types']]);

@ -9,7 +9,6 @@ namespace app\admin\model;
use app\admin\model\ImportRecord as ImportRecordModel;
use app\admin\model\User as UserModel;
use app\crm\model\Contract as ContractModel;
use app\crm\model\CustomerCheck;
use app\crm\model\Invoice;
use app\crm\model\Receivables as ReceivablesModel;
use app\oa\model\Announcement as AnnouncementModel;
@ -266,34 +265,6 @@ class Message extends Common
* 盘点审批通过
*/
const INVENTORY_PASS = 56;
/**
* 客户待审批
*/
const CUSTOMER_CHECK_TO_DO = 57;
/**
* 客户待审批
*/
const CUSTOMER_CHECK_REJECT = 58;
/**
* 客户待审批
*/
const CUSTOMER_CHECK_PASS = 59;
/**
* 商机推进待审批
*/
const BUSINESS_ADVANCE_CHECK_TO_DO = 60;
/**
* 商机推进待审批
*/
const BUSINESS_ADVANCE_CHECK_REJECT = 61;
/**
* 商机推进待审批
*/
const BUSINESS_ADVANCE_CHECK_PASS = 62;
/**
* 新商机
*/
const BUSINESS_NEW = 63;
/**
* 消息类型
@ -405,9 +376,6 @@ class Message extends Common
32 => [
'template' => '{from_user} 将您添加为线索 {title} 的成员。',
],
63 => [
'template' => '{from_user} 创建了新的商机',
]
];
/**
@ -455,13 +423,6 @@ class Message extends Common
self::BUSINESS_PASS,
self::CUSTOMER_PASS,
self::CONTRACT_END,
self::CUSTOMER_CHECK_TO_DO,
self::CUSTOMER_CHECK_REJECT,
self::CUSTOMER_CHECK_PASS,
self::BUSINESS_ADVANCE_CHECK_TO_DO,
self::BUSINESS_ADVANCE_CHECK_REJECT,
self::BUSINESS_ADVANCE_CHECK_PASS,
self::BUSINESS_NEW,
],
'jxc' => [
self::PURCHASE_TO_DO,
@ -598,11 +559,7 @@ class Message extends Common
case self::CONTRACT_PASS:
case self::TEAM_CONTRACT:
return ContractModel::where(['contract_id' => $data['action_id']])->value('name') ?: '';
// 客户
case self::CUSTOMER_CHECK_TO_DO:
case self::CUSTOMER_CHECK_PASS:
case self::CUSTOMER_CHECK_REJECT:
return CustomerCheck::where(['customer_check_id' => $data['action_id']])->value('name') ?: '';
// 回款
case self::RECEIVABLES_TO_DO:
case self::RECEIVABLES_REJECT:
@ -632,10 +589,6 @@ class Message extends Common
// 商机
case self::TEAM_BUSINESS:
case self::BUSINESS_PASS:
case self::BUSINESS_ADVANCE_CHECK_TO_DO:
case self::BUSINESS_ADVANCE_CHECK_REJECT:
case self::BUSINESS_ADVANCE_CHECK_PASS:
case self::BUSINESS_NEW:
return BusinessModel::where(['business_id' => $data['action_id']])->value('name') ?: '';
// 采购单

@ -13,7 +13,6 @@ use app\admin\model\Common;
use com\verify\HonrayVerify;
use think\Cache;
use think\Request;
use think\Session;
class User extends Common
{
@ -648,15 +647,8 @@ class User extends Common
$data['loginExpire'] = $loginExpire;
//保存authKey信息
$userData = [];
$wxuser_id = Session::get('wxuser_id');
if ($wxuser_id) {
$data['authKey'] = 'wxwork';
$userData['wxwork_id'] = $wxuser_id;
} else {
$userData['authkey'] = $authKey;
$userData['authkey_time'] = time() + $loginExpire;
}
//把状态未激活至为启用
if ($userInfo['status'] == 2) {
$userData['status'] = 1;

@ -69,11 +69,7 @@ function resultArray($array)
$array['data'] = '';
} elseif (isset($array['error'])) {
$code = 400;
$array['data'] = '操作失败';
} elseif (isset($array['success'])) {
$array['error'] = '';
$array['data'] =$array['success'] ;
$code = 200;
$array['data'] = '';
}
return json([
'code' => $code,
@ -838,8 +834,7 @@ function advancedQueryDataTransform($data, $condition)
* @version: 11.1.0
* Date: 2021/9/2 14:44
*/
function advancedQueryDataUserform($data, $condition)
{
function advancedQueryDataUserform($data, $condition){
if (in_array($condition, ['contains', 'notContains'])) {
array_walk($data, function ($value, $key) use (&$data) {
$data[$key] = $value;
@ -847,7 +842,6 @@ function advancedQueryDataUserform($data, $condition)
}
return $data;
}
/**
* 等于(时间段)数据处理
*

@ -9,7 +9,6 @@ namespace app\common\behavior;
use think\Cache;
use think\Request;
use think\Db;
use think\Session;
class AuthenticateBehavior
{
@ -33,9 +32,6 @@ class AuthenticateBehavior
/*获取头部信息*/
$header = $request->header();
$authKey = trim($header['authkey']);
if ($authKey == "wxwork" && Session::get('user_id')) {
return true;
}
$paramArr = $request->param();
$platform = $paramArr['platform'] ? '_'.$paramArr['platform'] : ''; //请求分类(mobile,ding)

@ -72,25 +72,19 @@ class PoolCommand extends Command
$this->timer = Timer::add($this->interval, function () {
# 只在凌晨12点至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.*')
->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')->where('pool.status', 1)->select();
if (!empty($ruleList)) {
# 符合公海条件的客户IDS
$customerIds = PoolCommand::getQueryCondition($ruleList);
$customerIds = $this->getQueryCondition($ruleList);
# 整理客户公海关联数据
$poolRelationData = PoolCommand::getCustomerPoolRelationData($customerIds);
$poolRelationData = $this->getCustomerPoolRelationData($customerIds);
# 整理修改客户数据的条件(进入公海时间,前负责人...
$customerWhere = PoolCommand::getCustomerQueryCondition($customerIds);
$customerWhere = $this->getCustomerQueryCondition($customerIds);
Db::startTrans();
try {
@ -106,7 +100,7 @@ class PoolCommand extends Command
'into_pool_time' => time()
]);
}
PoolCommand::updateInfo($ruleList, $customerWhere);
$this->updateInfo($ruleList,$customerWhere);
# 删除联系人的负责人
Db::name('crm_contacts')->whereIn('customer_id', $customerWhere)->update(['owner_user_id' => '']);
@ -116,7 +110,8 @@ class PoolCommand extends Command
}
}
}
});
}
/**
* 自动入公海操作记录
* @param $ruleList
@ -134,7 +129,7 @@ class PoolCommand extends Command
if (!empty($v1['limit_day'])) {
$time = $v1['limit_day'];
} else {
$time = PoolCommand::getMinDay($levels);
$time = $this->getMinDay($levels);
}
}
foreach ($customerWhere as $val) {
@ -147,6 +142,7 @@ class PoolCommand extends Command
}
protected function execute(Input $input, Output $output)
{
# 动态修改运行时参数
@ -231,9 +227,9 @@ class PoolCommand extends Command
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']], 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']], 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']], PoolCommand::getDealQueryResult($v['level_conf'], $v['level'], $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']));
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']));
}
return $result;
@ -250,7 +246,7 @@ class PoolCommand extends Command
* @since 2021-04-01
* @author fanqi
*/
private function getFollowUpQueryResult($type, $levels, $dealStatus, $businessStatus, $customerType)
private function getFollowUpQueryResult($type, $levels, $dealStatus, $businessStatus)
{
# 转换格式
$levels = json_decode($levels, true);
@ -282,10 +278,10 @@ class PoolCommand extends Command
}
# 获取最小天数,对于没有设置级别的客户数据使用
$minLimit = PoolCommand::getMinDay($levels);
$minLimit = $this->getMinDay($levels);
$minTime = (time() - 24 * 60 * 60 * $minLimit);
$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` < " . $minTime . " AND `customer`.`obtain_time` > `customer`.`last_time`) OR (ISNULL(`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`))) )";
}
# 选择不进入公海的客户(已成交客户)
@ -300,7 +296,7 @@ class PoolCommand extends Command
# 查询符合条件的客户
return db('crm_customer')
->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');
}
/**
@ -313,7 +309,7 @@ class PoolCommand extends Command
* @since 2021-04-01
* @author fanqi
*/
private function getBusinessQueryResult($type, $levels, $dealStatus, $customerType)
private function getBusinessQueryResult($type, $levels, $dealStatus)
{
# 转换格式
$levels = json_decode($levels, true);
@ -345,10 +341,10 @@ class PoolCommand extends Command
}
# 获取最小天数,对于没有设置级别的客户数据使用
$minLimit = PoolCommand::getMinDay($levels);
$minLimit = $this->getMinDay($levels);
$minTime = (time() - 24 * 60 * 60 * $minLimit);
$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`))) )";
$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`)) )";
}
# 选择不进入公海的客户(已成交客户)
@ -360,7 +356,7 @@ class PoolCommand extends Command
# 查询匹配条件的客户
return db('crm_customer')->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');
}
/**
@ -373,7 +369,7 @@ class PoolCommand extends Command
* @since 2021-04-01
* @author fanqi
*/
private function getDealQueryResult($type, $levels, $businessStatus, $customerType)
private function getDealQueryResult($type, $levels, $businessStatus)
{
# 转换格式
$levels = json_decode($levels, true);
@ -405,10 +401,10 @@ class PoolCommand extends Command
}
# 获取最小天数,对于没有设置级别的客户数据使用
$minLimit = PoolCommand::getMinDay($levels);
$minLimit = $this->getMinDay($levels);
$minTime = (time() - 24 * 60 * 60 * $minLimit);
$where .= " OR ((ISNULL(`contract`.`customer_id`) AND `customer`.`obtain_time` < " . $minTime . " AND ISNULL(`customer`.`level`)) OR (`customer`.`obtain_time` < " . $minTime . " AND `customer`.`obtain_time` > `contract`.`create_time` AND ISNULL(`customer`.`level`)) OR (`contract`.`create_time` < " . $minTime . " AND `contract`.`create_time` > `customer`.`obtain_time` AND ISNULL(`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`)) )";
}
# 选择不进入公海的客户(有商机客户)
@ -421,7 +417,7 @@ class PoolCommand extends Command
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)->where(['customer.crm_lthugd' => array('in', $customerType)])->column('customer.customer_id');
->where($where)->column('customer.customer_id');
}
/**

@ -13,9 +13,6 @@ class Api {
protected static $getAccessToken = 'gettoken';
protected static $contactInfo = 'externalcontact/get';
protected static $getUserInfo = 'auth/getuserinfo';
protected static $userGet = 'user/get';
protected $corpId = '';
protected $corpSecret = '';
@ -40,30 +37,6 @@ class Api {
]);
}
/**
* 获取用户身份
* @param $code
* @return mixed
*/
function getUserInfo($code) {
return $this->get(self::$getUserInfo, [
'access_token' => $this->getAccessToken(),
'code' => $code
]);
}
/**
* 获取用户信息
* @param $code
* @return mixed
*/
function userGet($userid) {
return $this->get(self::$userGet, [
'access_token' => $this->getAccessToken(),
'userid' => $userid
]);
}
/**
* 获取accessToken
* @return false|mixed

@ -8,9 +8,6 @@
namespace app\crm\controller;
use app\admin\controller\ApiCommon;
use app\admin\model\Message;
use app\admin\model\User;
use app\crm\logic\CustomerPoolLogic;
use app\crm\traits\SearchConditionTrait;
use app\crm\traits\StarTrait;
use think\Hook;
@ -31,7 +28,7 @@ class Business extends ApiCommon
{
$action = [
'permission' => [''],
'allow' => ['statuslist', 'advance', 'product', 'system', 'count', 'setprimary', 'check']
'allow' => ['statuslist', 'advance', 'product', 'system', 'count', 'setprimary']
];
Hook::listen('check_auth', $action);
$request = Request::instance();
@ -375,7 +372,7 @@ class Business extends ApiCommon
}
/**
* 商机审批提交
* 商机状态推进
* @param business_id 商机ID
* @param status_id 推进商机状态ID
* @return
@ -384,91 +381,31 @@ class Business extends ApiCommon
public function advance()
{
$param = $this->param;
$examineStepModel = new \app\admin\model\ExamineStep();
$examineStatus = $param['examineStatus'] ?? 1; // 审批是否停用
$userInfo = $this->userInfo;
$userModel = new \app\admin\model\User();
$is_end = $param['is_end'] ?: 0; //1赢单2输单3无效
$remark = $param['statusRemark'];
unset($param['examineStatus']);
if (!$param['business_id']) {
return resultArray(['error' => '参数错误']);
}
$businessInfo = db('crm_business')->where(['business_id' => $param['business_id']])->find();
if ($businessInfo['is_end']) {
return resultArray(['error' => '已结束,请勿重复提交']);
}
if ($businessInfo['flow_id'] && [$businessInfo]['check_status'] != 0) {
return resultArray(['error' => '已有审批流程,请勿重复提交']);
return resultArray(['error' => '已结束,不能推进']);
}
$data = [];
$data['submit_end_status'] = $is_end;
$data['submit_remark'] = $remark;
$data['check_status'] = 0;
if (($examineStatus != false && $examineStatus != 'false') || $examineStatus == 1) {
// 审核判断(是否有符合条件的审批流)
$examineFlowModel = new \app\admin\model\ExamineFlow();
if (!$examineFlowModel->checkExamine($userInfo['id'], 'crm_business')) {
return resultArray(['error' => '暂无审批人,无法创建']);
}
//添加审批相关信息
$examineFlowData = $examineFlowModel->getFlowByTypes($userInfo['id'], 'crm_business');
if (!$examineFlowData) {
return resultArray(['error' => '无可用审批流,请联系管理员']);
}
$data['flow_id'] = $examineFlowData['flow_id'];
//获取审批人信息
if ($examineFlowData['config'] == 1) {
//固定审批流
$nextStepData = $examineStepModel->nextStepUser($userInfo['id'], $examineFlowData['flow_id'], 'crm_business', 0, 0, 0);
$next_user_ids = arrayToString($nextStepData['next_user_ids']) ?: '';
$check_user_id = $next_user_ids ?: [];
$data['order_id'] = 1;
} else {
$check_user_id = $param['check_user_id'] ? ',' . $param['check_user_id'] . ',' : '';
}
if (!$check_user_id) {
return resultArray(['error' => '无可用审批人,请联系管理员']);
}
$data['check_user_id'] = is_array($check_user_id) ? ',' . implode(',', $check_user_id) . ',' : $check_user_id;
} else {
# 审批流停用,将状态改为审核通过
// $param['check_status'] = 2;
$data['update_time'] = time();
$data['is_end'] = $is_end;
$data['remark'] = $remark;
$data['check_status'] = 1;
$data['flow_id'] = 13;
$data['check_user_id'] = $param['check_user_id'];
$data['flow_user_id'] = $param['check_user_id'];
# 审批流停用,将状态改为正常 zjf 20210727 默认值为7
$data['check_status'] = 7;
}
$res = db('crm_business')->where(['business_id' => $param['business_id']])->update($data);
if (!$res) {
return resultArray(['error' => '提交失败,请重试']);
}
//站内信
$send_user_id = stringToArray($param['check_user_id']);
if ($send_user_id && empty($param['check_status'])) {
(new Message())->send(
Message::CUSTOMER_CHECK_TO_DO,
[
'title' => $param['name'],
'action_id' => $param['business_id'],
],
$send_user_id
);
}
# 创建待办事项的关联数据
$checkUserIds = db('crm_business')->where('business_id', $param['business_id'])->value('check_user_id');
$checkUserIdArray = stringToArray($checkUserIds);
$dealtData = [];
foreach ($checkUserIdArray as $kk => $vv) {
$dealtData[] = [
'types' => 'crm_business',
'types_id' => $param['business_id'],
'user_id' => $vv
];
return resultArray(['error' => '推进失败,请重试']);
}
if (!empty($dealtData)) db('crm_dealt_relation')->insertAll($dealtData);
return resultArray(['success' => '提交成功']);
}
@ -632,151 +569,23 @@ class Business extends ApiCommon
public function check()
{
$param = $this->param;
$userInfo = $this->userInfo;
$user_id = $userInfo['id'];
$businessModel = model('Business');
$examineStepModel = new \app\admin\model\ExamineStep();
$examineRecordModel = new \app\admin\model\ExamineRecord();
$examineFlowModel = new \app\admin\model\ExamineFlow();
$customerModel = model('Customer');
$businessCheckData = [];
$businessCheckData['update_time'] = time();
$businessCheckData['check_status'] = 1; //0待审核1审核通中2审核通过3审核未通过
//权限判断
if (!$examineStepModel->checkExamine($user_id, 'crm_business', $param['id'])) {
return resultArray(['error' => $examineStepModel->getError()]);
}
//审批主体详情
$dataInfo = $businessModel->getDataById($param['id']);
$flowInfo = $examineFlowModel->getDataById($dataInfo['flow_id']);
$is_end = 0; // 1审批结束
$status = $param['status'] ? 1 : 0; //1通过0驳回
$checkData = [];
$checkData['check_user_id'] = $user_id;
$checkData['types'] = 'crm_business';
$checkData['types_id'] = $param['id'];
$checkData['check_time'] = time();
$checkData['content'] = $param['content'];
$checkData['flow_id'] = $dataInfo['flow_id'];
$checkData['order_id'] = $dataInfo['order_id'] ?: 1;
$checkData['status'] = $status;
if ($status == 1) {
if ($flowInfo['config'] == 1) {
//固定流程
//获取下一审批信息
$nextStepData = $examineStepModel->nextStepUser($dataInfo['owner_user_id'], $dataInfo['flow_id'], 'crm_business', $param['id'], $dataInfo['order_id'], $user_id);
$next_user_ids = $nextStepData['next_user_ids'] ?: [];
$businessCheckData['order_id'] = $nextStepData['order_id'] ?: '';
if (!$next_user_ids) {
$is_end = 1;
//审批结束
$checkData['check_status'] = !empty($status) ? 2 : 3;
$businessCheckData['check_user_id'] = '';
} else {
//修改主体相关审批信息
$businessCheckData['check_user_id'] = arrayToString($next_user_ids);
}
} else {
//自选流程
$is_end = $param['is_end'] ? 1 : '';
$check_user_id = $param['check_user_id'] ?: '';
if ($is_end !== 1 && empty($check_user_id)) {
return resultArray(['error' => '请选择下一审批人']);
}
$businessCheckData['check_user_id'] = arrayToString($param['check_user_id']);
}
if ($is_end == 1) {
$checkData['check_status'] = !empty($status) ? 2 : 3;
$businessCheckData['check_user_id'] = '';
$businessCheckData['check_status'] = 2;
}
} else {
//审批驳回
$is_end = 1;
$businessCheckData['check_status'] = 3;
//将审批记录至为无效
// $examineRecordModel->setEnd(['types' => 'crm_contract','types_id' => $param['id']]);
}
//已审批人ID
$businessCheckData['flow_user_id'] = stringToArray($dataInfo['flow_user_id']) ? arrayToString(array_merge(stringToArray($dataInfo['flow_user_id']), [$user_id])) : arrayToString([$user_id]);
$resBusiness = db('crm_business')->where(['business_id' => $param['id']])->update($businessCheckData);
if ($resBusiness) {
//审批记录
$resRecord = $examineRecordModel->createData($checkData);
//审核通过,修改相关信息
if ($is_end == 1 && !empty($status)) {
// 审批通过消息告知负责人
(new Message())->send(
Message::BUSINESS_ADVANCE_CHECK_PASS,
[
'title' => $dataInfo['name'],
'action_id' => $param['id']
],
$dataInfo['owner_user_id']
);
$businessData = [];
$businessData['business_id'] = $dataInfo['business_id'];
$businessData['is_end'] = $dataInfo['submit_end_status'];
$businessData['status_id'] = $dataInfo['status_id'];
$businessData['statusRemark'] = $dataInfo['submit_remark'];
$result = $this->advanceAfterCheck($businessData);
if (!empty($result)) return $result;
} else {
if ($status) {
//发送站内信
// 通过未完成,发送消息给
(new Message())->send(
Message::BUSINESS_ADVANCE_CHECK_TO_DO,
[
'from_user' => User::where(['id' => $dataInfo['owner_user_id']])->value('realname'),
'title' => $dataInfo['name'],
'action_id' => $param['id']
],
stringToArray($businessCheckData['check_user_id'])
);
} else {
(new Message())->send(
Message::BUSINESS_ADVANCE_CHECK_REJECT,
[
'title' => $dataInfo['name'],
'action_id' => $param['id']
],
$dataInfo['owner_user_id']
);
}
}
return resultArray(['success' => '审批成功']);
} else {
return resultArray(['error' => '审批失败,请重试!']);
}
}
/**
* 审核后商机状态推进
* @param business_id 商机ID
* @param status_id 推进商机状态ID
* @return
* @author Michael_xu
*/
private function advanceAfterCheck($param)
{
$param = $this->param;
$userInfo = $this->userInfo;
$userModel = new \app\admin\model\User();
$is_end = $param['is_end'] ?: 0; //1赢单2输单3无效
// $is_end = $param['is_end'] ?: 0; //1赢单2输单3无效
// $remark = $param['statusRemark'];
$check_status = $param['check_status'];
if (!$param['business_id']) {
return ['error' => '参数错误'];
return resultArray(['error' => '参数错误']);
}
if ($check_status == 2) {
$businessInfo = db('crm_business')->where(['business_id' => $param['business_id']])->find();
if ($businessInfo['is_end']) {
return ['error' => '已结束,不能推进'];
}
// if ($businessInfo['is_end']) {
// return resultArray(['error' => '已结束,不能推进']);
// }
//判断权限
$auth_user_ids = $userModel->getUserByPer('crm', 'business', 'update');
//读写权限
@ -788,27 +597,25 @@ class Business extends ApiCommon
$status_id = $param['status_id'] ?: $businessInfo['status_id'];
$statusInfo = db('crm_business_status')->where(['type_id' => $businessInfo['type_id'], 'status_id' => $status_id])->find();
if (!$statusInfo && !$is_end) {
return ['error' => '参数错误'];
if (!$statusInfo && $businessInfo['is_end']) {
return resultArray(['error' => '参数错误']);
}
$data = [];
$data['update_time'] = time();
$data['is_end'] = $is_end;
// if ($is_end) {
// $status_id = $is_end;
// }
// $data['is_end'] = $is_end;
// $data['remark'] = $remark;
$data['check_status'] = $check_status;
$data['status_id'] = $status_id;
$data['status_time'] = time();
$data['remark'] = $param['submit_remark'];
$res = db('crm_business')->where(['business_id' => $param['business_id']])->update($data);
if (!$res) {
return ['error' => '推进失败,请重试'];
return resultArray(['error' => '推进失败,请重试']);
} else {
# 商机变更后的名称
$businessStatusName = Db::name('crm_business_status')->where('status_id', $param['status_id'])->value('name');
if (empty($businessStatusName) && $is_end == 1) $businessStatusName = '赢单';
if (empty($businessStatusName) && $is_end == 2) $businessStatusName = '输单';
if (empty($businessStatusName) && $is_end == 3) $businessStatusName = '无效';
if (empty($businessStatusName) && $businessInfo['is_end'] == 1) $businessStatusName = '赢单';
if (empty($businessStatusName) && $businessInfo['is_end'] == 2) $businessStatusName = '输单';
if (empty($businessStatusName) && $businessInfo['is_end'] == 3) $businessStatusName = '无效';
# 添加活动记录
Db::name('crm_activity')->insert([
'type' => 3,
@ -823,7 +630,7 @@ class Business extends ApiCommon
//推进记录添加
$temp['status_id'] = $status_id ?: 0;
$temp['is_end'] = $is_end ?: 0;
$temp['is_end'] = $businessInfo['is_end'] ?: 0;
$temp['business_id'] = $param['business_id'];
$temp['create_time'] = time();
$temp['owner_user_id'] = $userInfo['id'];
@ -840,7 +647,18 @@ class Business extends ApiCommon
'status_list' => $businessStatus
];
return '';
return resultArray(['data' => $result]);
}
} else {
$data = [];
$data['update_time'] = time();
$data['is_end'] = 0;
$data['remark'] = '';
$data['check_status'] = $check_status;
$res = db('crm_business')->where(['business_id' => $param['business_id']])->update($data);
if (!$res) {
return resultArray(['error' => '推进失败,请重试']);
}
}
}

@ -9,11 +9,9 @@ namespace app\crm\controller;
use app\common\wework\api\Api;
use app\common\wework\callback\WXBizMsgCrypt;
use think\Cache;
use think\Controller;
use think\Log;
use think\Request;
use think\Session;
class Callback extends Controller
{
@ -35,43 +33,15 @@ class Callback extends Controller
switch ($simpleXMLElement->Event->__toString()) {
case 'change_external_contact':
$api = new Api(config('wework.corpId'), config('wework.corpSecret'));
$contactInfo = $api->contactInfo($simpleXMLElement->ExternalUserID->__toString());
$contactInfo = $api->contactInfo('wm9nLQEAAA6lshIXRN5xdd1iZjqevSyA');
foreach ($contactInfo['follow_user'] as $contactUserInfo) {
if ($contactUserInfo['userid'] == $simpleXMLElement->UserID->__toString()) {
$customerInfo = model('Customer')->where('name', $contactUserInfo['remark_corp_name'])->find();
if ($customerInfo) {
$wxwork = db('admin_wxwork')->where("user_id", $contactUserInfo['userid'])->find();
if (!$wxwork) {
$userGet = $api->userGet($contactUserInfo['userid']);
$wxwork = [
'user_id' => $userGet['userid'],
'name' => $userGet['name'],
'create_time' => time(),
'update_time' => time(),
];
db('admin_wxwork')->insert($wxwork);
$wxwork = db('admin_wxwork')->where("user_id", $contactUserInfo['userid'])->find();
if (!$wxwork) {
Log::record('联系人添加失败');
return;
}
}
if ($wxwork['update_time']+86400*3 < time()) {
db('admin_wxwork')->where("id", $wxwork['id'])->update([
'name' => $userGet['name'],
'update_time' => time(),
]);
}
$contactsInfo = model('Contacts')->where([
'external_userid' => $simpleXMLElement->ExternalUserID->__toString(),
'customer_id' => $customerInfo['customer_id'],
'wxwork_id' => $wxwork['id']
'name' => $contactUserInfo['remark'],
'customer_id' => $customerInfo['customer_id']
])->find();
$mobile = '';
if ($contactUserInfo['remark_mobiles']) {
$mobile = $contactUserInfo['remark_mobiles'][0];
}
if (!$contactsInfo) {
$param = [
'business_id' => null,
@ -79,22 +49,13 @@ class Callback extends Controller
'owner_user_id' => 1,
'customer_id' => $customerInfo['customer_id'],
'name' => $contactUserInfo['remark'],
'mobile' => $mobile,
'external_userid' => $simpleXMLElement->ExternalUserID->__toString(),
'wxwork_id' => $wxwork['id']
'mobile' => $contactUserInfo['remark_mobiles'][0],
];
if (model('Contacts')->createData($param)) {
Log::record('联系人添加成功');
} else {
Log::record('联系人添加失败');
}
} else {
$param = [
'name' => $contactUserInfo['remark'],
'mobile' => $mobile
];
model('Contacts')->where('contacts_id', $contactsInfo['contacts_id'])->update($param);
Log::record('联系人更新成功');
}
}
}
@ -122,41 +83,4 @@ class Callback extends Controller
}
}
}
public function work() {
$code = Request::instance()->get('code');
$api = new Api(config('wework.corpId'), config('wework.corpSecret'));
$userInfo = $api->getUserInfo($code);
Log::record('用户信息'.json_encode($userInfo));
if (isset($userInfo['userid']) && $userInfo['userid']) {
Session::set('wxuser_id', $userInfo['userid']);
$adminUser = db('admin_user')->where('wxwork_id', $userInfo['userid'])->find();
if ($adminUser) {
Session::set('user_id', $adminUser['id']);
$info['userInfo'] = $adminUser;
$info['sessionId'] = session_id();
// $info['_AUTH_LIST_'] = $dataList['rulesList'];
$info['authKey'] = 'wxwork';
if (!Cache::get('Auth_wxwork')) {
Cache::set('Auth_wxwork', $info);
}
return redirect('http://web.lbschem.com:8088/?authkey=wxwork&sessionid='.session_id());
} elseif (Session::get('user_id')) {
db('admin_user')->where('id', Session::get('user_id'))->update([
'wxwork_id' => $userInfo['userid']
]);
$adminUser = db('admin_user')->where('id', Session::get('user_id'))->find();
$info['userInfo'] = $adminUser;
$info['sessionId'] = session_id();
// $info['_AUTH_LIST_'] = $dataList['rulesList'];
$info['authKey'] = 'wxwork';
if (!Cache::get('Auth_wxwork')) {
Cache::set('Auth_wxwork', $info);
}
return redirect('http://web.lbschem.com:8088/?authkey=wxwork&sessionid='.session_id());
}
}
return redirect('http://web.lbschem.com:8088/');
}
}

@ -123,14 +123,6 @@ class Customer extends ApiCommon
$authData['dataAuth'] = (int)0;
return resultArray(['data' => $authData]);
}
// 判断是否有客户捞取审批
$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");
}
return resultArray(['data' => $data]);
}
@ -423,25 +415,13 @@ class Customer extends ApiCommon
# 消息数据
$message = [];
# 获取公海规则数据
$customerPoolData = db('crm_customer_pool')->where('pool_id=' . $poolId)->column(['customer_type']);
$customerTypeArray = explode(',', $customerPoolData[0]);
# 获取客户数据
$customerData = [];
$customerList = db('crm_customer')->field(['customer_id', 'owner_user_id', 'name', 'crm_lthugd'])->whereIn('customer_id', $customerIds)->select();
$customerList = db('crm_customer')->field(['customer_id', 'owner_user_id', 'name'])->whereIn('customer_id', $customerIds)->select();
foreach ($customerList as $key => $value) {
# 判断客户类型是否符合公海池客户类型
if (!in_array($value['crm_lthugd'], $customerTypeArray)) {
$message[] = '客户类型与公海池类型不匹配!';
return resultArray(['error' => $message]);
}
$customerData[$value['customer_id']] = $value;
}
# 整理数据
$ip = request()->ip();
$poolRelationData = [];
@ -1187,20 +1167,4 @@ 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]);
}
}

@ -9,8 +9,6 @@
namespace app\crm\controller;
use app\admin\controller\ApiCommon;
use app\admin\model\Message;
use app\admin\model\User;
use app\crm\logic\CustomerPoolLogic;
use think\Hook;
use think\Request;
@ -43,8 +41,7 @@ class CustomerPool extends ApiCommon
'setfieldconfig',
'exceldownload',
'import',
'export',
'checkCustomerReveive'
'export'
]
];
Hook::listen('check_auth', $action);
@ -175,7 +172,7 @@ class CustomerPool extends ApiCommon
$param = $this->param;
$param['user_id'] = $this->userInfo['id'];
$result = (new CustomerPoolLogic())->customerReceiveExamine($param);
$result = (new CustomerPoolLogic())->receiveCustomers($param);
if (!empty($result)) return resultArray(['error' => $result]);
@ -401,155 +398,4 @@ class CustomerPool extends ApiCommon
$pool_list=array_merge($pool_list,$list);
return $pool_list;
}
/**
* 领取公海池客户
*
* @return Json
* @since 2021-04-15
* @author fanqi
*/
public function checkCustomerReveive()
{
$param = $this->param;
$userInfo = $this->userInfo;
$user_id = $userInfo['id'];
$customerCheckModel = model('CustomerCheck');
$examineStepModel = new \app\admin\model\ExamineStep();
$examineRecordModel = new \app\admin\model\ExamineRecord();
$examineFlowModel = new \app\admin\model\ExamineFlow();
$customerModel = model('Customer');
$customerCheckData = [];
$customerCheckData['update_time'] = time();
$customerCheckData['check_status'] = 1; //0待审核1审核通中2审核通过3审核未通过
//权限判断
if (!$examineStepModel->checkExamine($user_id, 'crm_customer_check', $param['id'])) {
return resultArray(['error' => $examineStepModel->getError()]);
}
//审批主体详情
$dataInfo = db('crm_customer_check')->where('customer_check_id', 'in', $param['id'])->find();
$flowInfo = $examineFlowModel->getDataById($dataInfo['flow_id']);
$is_end = 0; // 1审批结束
$status = $param['status'] ? 1 : 0; //1通过0驳回
$checkData = [];
$checkData['check_user_id'] = $user_id;
$checkData['types'] = 'crm_customer_check';
$checkData['types_id'] = $param['id'];
$checkData['check_time'] = time();
$checkData['content'] = $param['content'];
$checkData['flow_id'] = $dataInfo['flow_id'];
$checkData['order_id'] = $dataInfo['order_id'] ?: 1;
$checkData['status'] = $status;
if ($status == 1) {
if ($flowInfo['config'] == 1) {
//固定流程
//获取下一审批信息
$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'] ?: '';
if (!$next_user_ids) {
$is_end = 1;
//审批结束
$checkData['check_status'] = !empty($status) ? 2 : 3;
$customerCheckData['check_user_id'] = '';
} else {
//修改主体相关审批信息
$customerCheckData['check_user_id'] = arrayToString($next_user_ids);
}
} else {
//自选流程
$is_end = $param['is_end'] ? 1 : '';
$check_user_id = $param['check_user_id'] ?: '';
if ($is_end !== 1 && empty($check_user_id)) {
return resultArray(['error' => '请选择下一审批人']);
}
$customerCheckData['check_user_id'] = arrayToString($param['check_user_id']);
}
if ($is_end == 1) {
$checkData['check_status'] = !empty($status) ? 2 : 3;
$customerCheckData['check_user_id'] = '';
$customerCheckData['check_status'] = 2;
}
} else {
//审批驳回
$is_end = 1;
$customerCheckData['check_status'] = 3;
//将审批记录至为无效
// $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]);
$resCustomerCheck = db('crm_customer_check')->where(['customer_check_id' => $param['id']])->update($customerCheckData);
if ($resCustomerCheck) {
//审批记录
$resRecord = $examineRecordModel->createData($checkData);
//审核通过,修改相关信息
if ($is_end == 1 && !empty($status)) {
// 审批通过消息告知负责人
(new Message())->send(
Message::CUSTOMER_CHECK_PASS,
[
'title' => $dataInfo['name'],
'action_id' => $param['id']
],
$dataInfo['owner_user_id']
);
$customerData = [];
$customerData['user_id'] = $dataInfo['user_id'];
$customerData['customer_id'] = $dataInfo['customer_id'];
$result = (new CustomerPoolLogic())->receiveCustomers($customerData);
if (!empty($result)) return resultArray(['error' => $result]);
return resultArray(['data' => '领取成功!']);
} else {
if ($status) {
//发送站内信
// 通过未完成,发送消息给
(new Message())->send(
Message::CUSTOMER_CHECK_TO_DO,
[
'from_user' => User::where(['id' => $dataInfo['owner_user_id']])->value('realname'),
'title' => $dataInfo['name'],
'action_id' => $param['id']
],
stringToArray($customerCheckData['check_user_id'])
);
} else {
(new Message())->send(
Message::CONTRACT_REJECT,
[
'title' => $dataInfo['name'],
'action_id' => $param['id']
],
$dataInfo['owner_user_id']
);
}
}
return resultArray(['data' => '审批成功']);
} else {
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]);
}
}

@ -219,16 +219,6 @@ class Index extends ApiCommon
$param['end_time']=$param['end_time'].' 23:59:59';
}
$list = $businessModel->getFunnel($param);
$list['list'][] = [
"name" => "赢单",
"status_id" => "10000",
"status_name" => "赢单",
];
$list['list'][] = [
"name" => "输单",
"status_id" => "10001",
"status_name" => "输单",
];
return resultArray(['data' => $list]);
}
@ -712,11 +702,7 @@ class Index extends ApiCommon
$userInfo = $this->userInfo;
$param['user_id'] = $param['user_id'] ?: $userInfo['id'];
$indexModel = new IndexLogic;
if ($param['status_id'] == "10000" || $param['status_id'] == "10001") {
$param['funnel'] = $param['status_id'];
}
$data = $indexModel->businessList($param);
return resultArray(['data' => $data]);
}
@ -768,8 +754,7 @@ class Index extends ApiCommon
* 跟进详情
* @return \think\response\Json
*/
public function activityList()
{
public function activityList(){
$param = $this->param;
$userInfo = $this->userInfo;
$param['id']=$userInfo['id'];

@ -42,10 +42,7 @@ class Message extends ApiCommon
'remindcustomer',
'checkinvoice',
'visitcontract',
'alldeal',
'checkBusiness',
'newBusiness',
'checkCustomerCheck',
'alldeal'
]
];
Hook::listen('check_auth',$action);
@ -59,8 +56,8 @@ class Message extends ApiCommon
/**
* 系统通知
*
* @return
* @author Michael_xu
* @return
*/
public function index()
{
@ -94,7 +91,7 @@ class Message extends ApiCommon
$todayLeads = $this->todayLeads(true);
$data['todayLeads'] = $todayLeads['dataCount'] ? : 0;
cache('todayLeadsCount'.$userInfo['id'], $data['todayLeads']);
cache('todayLeadsTime' . $userInfo['id'], time());
cache('todayLeadsTime'.$userInfo['id'], time() + 180);
}
# 今日需联系客户
$todayCustomerTime = cache('todayCustomerTime'.$userInfo['id']);
@ -105,7 +102,7 @@ class Message extends ApiCommon
$todayCustomer = $this->todayCustomer(true);
$data['todayCustomer'] = $todayCustomer['dataCount'] ? : 0;
cache('todayCustomerCount'.$userInfo['id'], $data['todayCustomer']);
cache('todayCustomerTime' . $userInfo['id'], time());
cache('todayCustomerTime'.$userInfo['id'], time() + 180);
}
# 今日需联系商机
$todayBusinessTime = cache('todayBusinessTime'.$userInfo['id']);
@ -116,7 +113,7 @@ class Message extends ApiCommon
$todayBusiness = $this->todayBusiness(true);
$data['todayBusiness'] = $todayBusiness['dataCount'] ? : 0;
cache('todayBusinessCount'.$userInfo['id'], $data['todayBusiness']);
cache('todayBusinessTime' . $userInfo['id'], time());
cache('todayBusinessTime'.$userInfo['id'], time() + 180);
}
# 分配给我的线索
$followLeadsTime = cache('followLeadsTime'.$userInfo['id']);
@ -127,7 +124,7 @@ class Message extends ApiCommon
$followLeads = $this->followLeads(true);
$data['followLeads'] = $followLeads['dataCount'] ? : 0;
cache('followLeadsCount'.$userInfo['id'], $data['followLeads']);
cache('followLeadsTime' . $userInfo['id'], time());
cache('followLeadsTime'.$userInfo['id'], time() + 180);
}
# 分配给我的客户
$followCustomerTime = cache('followCustomerTime'.$userInfo['id']);
@ -138,7 +135,7 @@ class Message extends ApiCommon
$followCustomer = $this->followCustomer(true);
$data['followCustomer'] = $followCustomer['dataCount'] ? : 0;
cache('followCustomerCount'.$userInfo['id'], $data['followCustomer']);
cache('followCustomerTime' . $userInfo['id'], time());
cache('followCustomerTime'.$userInfo['id'], time() + 180);
}
# 待审核合同
$checkContractTime = cache('checkContractTime'.$userInfo['id']);
@ -149,7 +146,7 @@ class Message extends ApiCommon
$checkContract = $this->checkContract(true);
$data['checkContract'] = $checkContract['dataCount'] ? : 0;
cache('checkContractCount'.$userInfo['id'], $data['checkContract']);
cache('checkContractTime' . $userInfo['id'], time());
cache('checkContractTime'.$userInfo['id'], time() + 180);
}
# 待审核回款
$checkReceivablesTime = cache('checkReceivablesTime'.$userInfo['id']);
@ -160,7 +157,7 @@ class Message extends ApiCommon
$checkReceivables = $this->checkReceivables(true);
$data['checkReceivables'] = $checkReceivables['dataCount'] ? : 0;
cache('checkReceivablesCount'.$userInfo['id'], $data['checkReceivables']);
cache('checkReceivablesTime' . $userInfo['id'], time());
cache('checkReceivablesTime'.$userInfo['id'], time() + 180);
}
# 待审核发票
$checkInvoiceTime = cache('checkInvoiceTime'.$userInfo['id']);
@ -173,33 +170,7 @@ class Message extends ApiCommon
$data['checkInvoice'] = $checkInvoice['dataCount'] ? : 0;
cache('checkInvoiceCount'.$userInfo['id'], $data['checkInvoice']);
cache('checkInvoiceTime' . $userInfo['id'], time());
}
# 待审核商机
$checkBusinessTime = cache('checkBusinessTime' . $userInfo['id']);
$checkBusinessCount = cache('checkBusinessCount' . $userInfo['id']);
if (time() <= $checkBusinessTime) {
$data['checkBusiness'] = (int)$checkBusinessCount;
} else {
$checkBusiness = $this->checkBusiness(true);
$data['checkBusiness'] = $checkBusiness['dataCount'] ?: 0;
cache('checkBusinessCount' . $userInfo['id'], $data['checkBusiness']);
cache('checkBusinessTime' . $userInfo['id'], time());
}
# 待审核客户捞取
$checkCustomerCheckTime = cache('$checkCustomerCheckTime' . $userInfo['id']);
$checkCustomerCheckCount = cache('checkCustomerCheckCount' . $userInfo['id']);
if (time() <= $checkCustomerCheckTime) {
$data['checkCustomerCheck'] = (int)$checkCustomerCheckCount;
} else {
$checkCustomerCheck = $this->checkCustomerCheck(true);
$data['checkCustomerCheck'] = $checkCustomerCheck['dataCount'] ?: 0;
cache('checkCustomerCheckCount' . $userInfo['id'], $data['checkCustomerCheck']);
cache('$checkCustomerCheckTime' . $userInfo['id'], time());
cache('checkInvoiceTime'.$userInfo['id'], time() + 180);
}
# 待回款提醒
$remindReceivablesPlanTime = cache('remindReceivablesPlanTime'.$userInfo['id']);
@ -210,7 +181,7 @@ class Message extends ApiCommon
$remindReceivablesPlan = $this->remindReceivablesPlan(true);
$data['remindReceivablesPlan'] = $remindReceivablesPlan['dataCount'] ? : 0;
cache('remindReceivablesPlanCount'.$userInfo['id'], $data['remindReceivablesPlan']);
cache('remindReceivablesPlanTime' . $userInfo['id'], time());
cache('remindReceivablesPlanTime'.$userInfo['id'], time() + 180);
}
if ($configData['visit_config'] == 1) {
# 待回访合同
@ -222,7 +193,7 @@ class Message extends ApiCommon
$visitContract = $this->visitContract(true);
$data['returnVisitRemind'] = $visitContract['dataCount'] ? : 0;
cache('visitContractCount'.$userInfo['id'], $data['returnVisitRemind']);
cache('visitContractTime' . $userInfo['id'], time());
cache('visitContractTime'.$userInfo['id'], time() + 180);
}
}
# 即将到期合同
@ -235,22 +206,9 @@ class Message extends ApiCommon
$endContract = $this->endContract(true);
$data['endContract'] = $endContract['dataCount'] ? : 0;
cache('endContractCount'.$userInfo['id'], $data['endContract']);
cache('endContractTime' . $userInfo['id'], time());
cache('endContractTime'.$userInfo['id'], time() + 180);
}
}
# 新增商机
$newBusinessTime = cache('newBusinessTime' . $userInfo['id']);
$newBusinessCount = cache('newBusinessCount' . $userInfo['id']);
if (time() <= $newBusinessTime) {
$data['newBusiness'] = (int)$newBusinessCount;
} else {
$newBusiness = $this->newBusiness(true);
$data['newBusiness'] = $newBusiness['dataCount'] ?: 0;
cache('newBusinessCount' . $userInfo['id'], $data['newBusiness']);
cache('newBusinessTime' . $userInfo['id'], time());
}
# 待进入公海提醒
$pool = db('crm_customer_pool')->where(['status' => 1, 'remind_conf' => 1])->count();
if (!empty($pool)) {
@ -262,7 +220,7 @@ class Message extends ApiCommon
$remindCustomer = $this->remindCustomer(true);
$data['putInPoolRemind'] = !empty($remindCustomer['dataCount']) ? $remindCustomer['dataCount'] : 0;
cache('remindCustomerCount'.$userInfo['id'], $data['putInPoolRemind']);
cache('remindCustomerTime' . $userInfo['id'], time());
cache('remindCustomerTime'.$userInfo['id'], time() + 180);
}
}
@ -343,8 +301,8 @@ class Message extends ApiCommon
/**
* 分配给我的线索
* @return
* @author Michael_xu
* @return
*/
public function followLeads($getCount = false)
{
@ -364,8 +322,8 @@ class Message extends ApiCommon
/**
* 分配给我的客户
* @return
* @author Michael_xu
* @return
*/
public function followCustomer($getCount = false)
{
@ -411,8 +369,8 @@ class Message extends ApiCommon
/**
* 待审核回款
* @return
* @author Michael_xu
* @return
*/
public function checkReceivables($getCount = false)
{
@ -454,56 +412,10 @@ class Message extends ApiCommon
return $data;
}
/**
* 待审核商机
*
* @return array|\think\response\Json
* @throws \think\exception\DbException
*/
public function checkBusiness($getCount = false)
{
$param = $this->param;
$userId = $this->userInfo['id'];
$types = $param['types'];
if ($getCount == true) $param['getCount'] = 1;
# 清除与模型无关的数据
unset($param['types']);
$param['user_id'] = $userId;
$messageLogic = new MessageLogic();
$data = $messageLogic->checkBusiness($param);
if ($types == 'list') return resultArray(['data' => $data]);
return $data;
}
/**
* 待审核客户捞取
*
* @return array|\think\response\Json
* @throws \think\exception\DbException
*/
public function checkCustomerCheck($getCount = false)
{
$param = $this->param;
$userId = $this->userInfo['id'];
$types = $param['types'];
if ($getCount == true) $param['getCount'] = 1;
# 清除与模型无关的数据
unset($param['types']);
$param['user_id'] = $userId;
$messageLogic = new MessageLogic();
$data = $messageLogic->checkCustomerCheck($param);
if ($types == 'list') return resultArray(['data' => $data]);
return $data;
}
/**
* 待回款提醒
* @return
* @author Michael_xu
* @return
*/
public function remindReceivablesPlan($getCount = false)
{
@ -551,8 +463,8 @@ class Message extends ApiCommon
/**
* 即将到期合同
* @return
* @author Michael_xu
* @return
*/
public function endContract($getCount = false)
{
@ -580,9 +492,7 @@ class Message extends ApiCommon
$param['end_time'] = array('between',array(date('Y-m-d',time()),date('Y-m-d',time()+86400*$expireDay)));
$param['expire_remind'] = 0;
break;
case '2' :
$param['end_time'] = array('lt', date('Y-m-d', time()));
break;
case '2' : $param['end_time'] = array('lt',date('Y-m-d',time())); break;
}
$data = $contractModel->getDataList($param);
// p($contractModel->getLastSql());
@ -592,40 +502,10 @@ class Message extends ApiCommon
return $data;
}
/**
* 新增商机
* @return
* @author Michael_xu
*/
public function newBusiness($getCount = false)
{
$param = $this->param;
$userInfo = $this->userInfo;
$types = $param['types'];
$type = $param['type'] ?: 1;
$isSub = $param['isSub'] ?: '';
if ($getCount == true) $param['getCount'] = 1;
unset($param['types']);
unset($param['type']);
unset($param['isSub']);
$businessModel = model('Business');
// $param['owner_user_id'] = $userInfo['id'];
if ($isSub) {
$param['owner_user_id'] = array('in', getSubUserId(false));
}
$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;
$data = $businessModel->getDataList($param);
if ($types == 'list') {
return resultArray(['data' => $data]);
}
return $data;
}
/**
* 待进入客户池
* @return
* @author Michael_xu
* @return
*/
public function remindCustomer($getCount = false)
{
@ -775,7 +655,7 @@ class Message extends ApiCommon
}
# 处理待审核合同、回款、发票
if (in_array($type, ['checkContract', 'checkReceivables', 'checkInvoice', 'checkBusiness', 'checkCustomerCheck', 'newBusiness'])) {
if (in_array($type, ['checkContract', 'checkReceivables', 'checkInvoice'])) {
$where['check_status'] = ['lt','2'];
$where['check_user_id'] = ['like',',%' . $userId . '%,'];
@ -794,22 +674,6 @@ class Message extends ApiCommon
$invoiceId = !empty($typeId) ? $typeId : Db::name('crm_invoice')->where($where)->column('invoice_id');
db('crm_dealt_relation')->where('user_id', $userId)->where('types', 'crm_invoice')->whereIn('types_id', $invoiceId)->delete();
}
# 商机
if ($type == 'checkBusiness') {
$businessId = !empty($typeId) ? $typeId : Db::name('crm_business')->where($where)->column('business_id');
db('crm_dealt_relation')->where('user_id', $userId)->where('types', 'crm_business')->whereIn('types_id', $businessId)->delete();
}
# 客户捞取
if ($type == 'checkCustomerCheck') {
$customerCheckId = !empty($typeId) ? $typeId : Db::name('crm_customer_check')->where($where)->column('customer_check_id');
db('crm_dealt_relation')->where('user_id', $userId)->where('types', 'crm_customer_check')->whereIn('types_id', $customerCheckId)->delete();
}
# 新商机
if ($type == 'newBusiness') {
$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();
}
}
@ -853,7 +717,7 @@ class Message extends ApiCommon
$whereData['owner_user_id'] = !empty($isSub) ? ['in', getSubUserId(false, 0, $userId)] : $userId;
$poolCustomers = (new \app\crm\model\Customer())->getDataList($whereData);
$ids = [];
foreach ($poolCustomers['list'] as $key => $value) {
foreach ($poolCustomers['list'] AS $key => $value) {
if (!empty($value['customer_id'])) $ids[] = $value['customer_id'];
}
if (!empty($ids)) Db::name('crm_customer')->whereIn('customer_id', $ids)->update(['pool_remain' => 1]);
@ -877,7 +741,7 @@ class Message extends ApiCommon
$param['limit'] = 1000;
$receivablesPlanModel = model('ReceivablesPlan');
$data = $receivablesPlanModel->getDataList($param);
foreach ($data['list'] as $key => $value) {
foreach ($data['list'] AS $key => $value) {
$planId[] = $value['plan_id'];
}
}
@ -896,9 +760,6 @@ class Message extends ApiCommon
cache::rm('visitContractCount'.$userId);
cache::rm('endContractCount'.$userId);
cache::rm('remindCustomerCount'.$userId);
cache::rm('checkCustomerCheckCount' . $userId);
cache::rm('checkBusinessCount' . $userId);
cache::rm('newBusinessCount' . $userId);
cache::rm('todayLeadsTime'.$userId);
cache::rm('todayCustomerTime'.$userId);
@ -908,14 +769,10 @@ class Message extends ApiCommon
cache::rm('checkContractTime'.$userId);
cache::rm('checkReceivablesTime'.$userId);
cache::rm('checkInvoiceTime'.$userId);
cache::rm('checkBusinessTime' . $userId);
cache::rm('remindReceivablesPlanTime'.$userId);
cache::rm('visitContractTime'.$userId);
cache::rm('endContractTime'.$userId);
cache::rm('remindCustomerTime'.$userId);
cache::rm('checkCustomerCheckTime' . $userId);
cache::rm('checkBusinessTime' . $userId);
cache::rm('newBusinessTime' . $userId);
return resultArray(['data' => '操作成功!']);
}
}

@ -12,9 +12,7 @@ use app\admin\model\ActionRecord;
use app\admin\model\Common;
use app\admin\model\Field;
use app\admin\model\File;
use app\admin\model\Message;
use app\admin\model\Record;
use app\admin\model\User;
use app\crm\model\CustomerConfig;
use PDOStatement;
use think\Collection;
@ -27,9 +25,9 @@ class CustomerPoolLogic extends Common
* 公海列表
*
* @param $param
* @return array
* @since 2021-04-14
* @author fanqi
* @since 2021-04-14
* @return array
*/
public function getPoolList($param)
{
@ -116,12 +114,12 @@ class CustomerPoolLogic extends Common
$extraData = [];
$customerIds = array_column($customerPoolList, 'customer_id');
$extraList = db('crm_customer_data')->whereIn('customer_id', $customerIds)->select();
foreach ($extraList as $key => $value) {
foreach ($extraList AS $key => $value) {
$extraData[$value['customer_id']][$value['field']] = $value['content'];
}
// 整理公海数据
foreach ($customerPoolList as $key => $value) {
foreach ($customerPoolList AS $key => $value) {
$customerPoolList[$key]['create_user_name'] = !empty($userData[$value['create_user_id']]) ? $userData[$value['create_user_id']] : '';
$customerPoolList[$key]['before_owner_user_name'] = !empty($userData[$value['before_owner_user_id']]) ? $userData[$value['before_owner_user_id']] : '';
@ -132,38 +130,38 @@ class CustomerPoolLogic extends Common
$customerPoolList[$key]['into_pool_time'] = !empty($value['into_pool_time']) ? date('Y-m-d H:i:s', $value['into_pool_time']) : null;
// 处理日期时间类型的自定义字段
foreach ($datetimeField as $k => $v) {
foreach ($datetimeField AS $k => $v) {
if (!empty($value[$v])) $customerPoolList[$key][$v] = date('Y-m-d H:i:s', $value[$v]);
}
// 处理人员类型的自定义字段
foreach ($userField as $k => $v) {
foreach ($userField AS $k => $v) {
if (!empty($value[$v])) {
$customerPoolList[$key][$v] = $this->fieldTransformToText($value[$v], $userData);
}
}
// 处理部门类型的自定义字段
foreach ($structureField as $k => $v) {
foreach ($structureField AS $k => $v) {
if (!empty($value[$v])) $customerPoolList[$key][$v] = $this->fieldTransformToText($value[$v], $structureData);
}
// 布尔值类型字段
foreach ($booleanField as $k => $v) {
foreach ($booleanField AS $k => $v) {
$customerPoolList[$key][$v] = !empty($value[$v]) ? (string)$value[$v] : '0';
}
// 处理日期区间类型字段的格式
foreach ($dateIntervalField as $k => $v) {
foreach ($dateIntervalField AS $k => $v) {
$customerPoolList[$key][$v] = !empty($extraData[$value['customer_id']][$v]) ? json_decode($extraData[$value['customer_id']][$v], true) : null;
}
// 处理地址类型字段的格式
foreach ($positionField as $k => $v) {
foreach ($positionField AS $k => $v) {
$customerPoolList[$key][$v] = !empty($extraData[$value['customer_id']][$v]) ? json_decode($extraData[$value['customer_id']][$v], true) : null;
}
// 手写签名类型字段
foreach ($handwritingField as $k => $v) {
foreach ($handwritingField AS $k => $v) {
$handwritingData = !empty($value[$v]) ? db('admin_file')->where('file_id', $value[$v])->value('file_path') : null;
$customerPoolList[$key][$v] = ['url' => !empty($handwritingData) ? getFullPath($handwritingData) : null];
}
// 定位类型字段
foreach ($locationField as $k => $v) {
foreach ($locationField AS $k => $v) {
$customerPoolList[$key][$v] = !empty($extraData[$value['customer_id']][$v]) ? json_decode($extraData[$value['customer_id']][$v], true) : null;
}
}
@ -178,9 +176,9 @@ class CustomerPoolLogic extends Common
* 公海详情
*
* @param array $param pool_id 公海IDcustomer_id 客户ID
* @return array|bool|PDOStatement|string|Model|null
* @since 2021-04-14
* @author fanqi
* @since 2021-04-14
* @return array|bool|PDOStatement|string|Model|null
*/
public function getPoolData($param)
{
@ -216,19 +214,19 @@ class CustomerPoolLogic extends Common
$data['into_pool_time'] = !empty($data['into_pool_time']) ? date('Y-m-d H:i:s', $data['into_pool_time']) : null;
# 处理日期时间类型的自定义字段
foreach ($datetimeField as $k => $v) {
foreach ($datetimeField AS $k => $v) {
if (isset($data[$v])) {
$data[$v] = !empty($data[$v]) ? date('Y-m-d H:i:s', $data[$v]) : null;
}
}
# 处理人员类型的自定义字段
foreach ($userField as $k => $v) {
foreach ($userField AS $k => $v) {
if (isset($data[$v]) && !empty($data[$v])) {
$data[$v] = $this->fieldTransformToText($data[$v], $userData);
}
}
# 处理部门类型的自定义字段
foreach ($structureField as $k => $v) {
foreach ($structureField AS $k => $v) {
if (isset($data[$v]) && !empty($data[$v])) {
$data[$v] = $this->fieldTransformToText($data[$v], $structureData);
}
@ -254,7 +252,7 @@ class CustomerPoolLogic extends Common
$customerData = $this->getCustomerList($customerId);
# 验证是否是公海数据
foreach ($customerId as $key => $value) {
foreach ($customerId AS $key => $value) {
if (empty($customerData[$value])) {
$message[] = '删除 《' . $customerData[$value]['name'] . '》 失败,原因:公海客户不存在!';
@ -277,7 +275,7 @@ class CustomerPoolLogic extends Common
$customerContractData = db('crm_contract')->whereIn('customer_id', $customerId)->column('customer_id');
# 验证客户下是否存在联系人、商机、合同
foreach ($customerId as $key => $value) {
foreach ($customerId AS $key => $value) {
if (in_array($value, $customerContactsData)) {
$message[] = '删除 《' . $customerData[$value]['name'] . '》 失败,原因:客户下存在联系人!';
@ -309,7 +307,7 @@ class CustomerPoolLogic extends Common
# 记录到数据操作日志
$ip = request()->ip();
$addOperationLogData = [];
foreach ($customerId as $key => $value) {
foreach ($customerId AS $key => $value) {
$addOperationLogData[] = [
'user_id' => $param['user_id'],
'client_ip' => $ip,
@ -334,9 +332,9 @@ class CustomerPoolLogic extends Common
* 获取公海池列表
*
* @param array $param 查询参数user_id 用户idstructure_id 部门id
* @return bool|PDOStatement|string|Collection
* @since 2021-04-21
* @author fanqi
* @since 2021-04-21
* @return bool|PDOStatement|string|Collection
*/
public function getPondList($param)
{
@ -355,9 +353,9 @@ class CustomerPoolLogic extends Common
* 获取公海字段
*
* @param array $param pool_id 公海IDaction 操作类型action_id 数据id
* @return array
* @since 2021-04-13
* @author fanqi
* @since 2021-04-13
* @return array
*/
public function getFieldList($param)
{
@ -372,7 +370,7 @@ class CustomerPoolLogic extends Common
$list = db('crm_customer_pool_field_setting')->where($where)->select();
# 处理公海字段
foreach ($list as $key => $value) {
foreach ($list AS $key => $value) {
$list[$key]['field'] = $value['field_name'];
# 处理别名
@ -413,9 +411,9 @@ class CustomerPoolLogic extends Common
/**
* 高级筛选字段列表
*
* @return array
* @since 2021-04-14
* @author fanqi
* @since 2021-04-14
* @return array
*/
public function getAdvancedFilterFieldList()
{
@ -436,7 +434,7 @@ class CustomerPoolLogic extends Common
$list = array_merge($list, $base);
# 整理数据
foreach ($list as $key => $value) {
foreach ($list AS $key => $value) {
if (!empty($value['setting'])) $list[$key]['setting'] = explode(chr(10), $value['setting']);
}
@ -447,9 +445,9 @@ class CustomerPoolLogic extends Common
* 领取公海客户
*
* @param array $param user_id 领取人IDcustomer_id 要领取的客户ID
* @return array
* @since 2021-04-15
* @author fanqi
* @since 2021-04-15
* @return array
*/
public function receiveCustomers($param)
{
@ -467,7 +465,7 @@ class CustomerPoolLogic extends Common
$customerData = $this->getCustomerList($customerId);
# 剔除非公海客户
foreach ($customerId as $key => $value) {
foreach ($customerId AS $key => $value) {
if (!empty($customerData[$value]['owner_user_id'])) {
$message[] = '客户《' . $customerData[$value]['name'] . '》领取失败,失败原因:不是公海客户!';
@ -487,7 +485,7 @@ class CustomerPoolLogic extends Common
$failCustomer = [];
if (!is_bool($exceedCount) && !empty($exceedCount) && $exceedCount > 0) {
$failCustomer = array_slice($customerId, count($customerId) - $exceedCount);
foreach ($failCustomer as $key => $value) {
foreach ($failCustomer AS $key => $value) {
$message[] = '客户《' . $customerData[$value]['name'] . '》领取失败,失败原因:持有客户数达到上限!';
}
}
@ -503,7 +501,7 @@ class CustomerPoolLogic extends Common
# 前负责人N天内不能领取客户
if (!empty($poolConfig['before_owner_conf'])) {
foreach ($addCustomerId as $key => $value) {
foreach ($addCustomerId AS $key => $value) {
# 是前负责人,检查前负责人是否能够领取。
if ($userId == $customerData[$value]['before_owner_user_id']) {
$restrictDay = $customerData[$value]['into_pool_time'] + 86400 * $poolConfig['before_owner_day'];
@ -536,8 +534,7 @@ class CustomerPoolLogic extends Common
'owner_user_id' => $userId,
'before_owner_user_id' => 0,
'into_pool_time' => 0,
'obtain_time' => time(),
'is_allocation' => 1,
'obtain_time' => time()
];
# 整理字段操作记录和数据日志的数据
@ -545,7 +542,7 @@ class CustomerPoolLogic extends Common
$addActionRecordData = [];
$addOperationLogData = [];
$addReceiveData = [];
foreach ($addCustomerId as $key => $value) {
foreach ($addCustomerId AS $key => $value) {
$addActionRecordData[] = [
'user_id' => $userId,
'types' => 'crm_customer',
@ -606,9 +603,9 @@ class CustomerPoolLogic extends Common
* 分配客户
*
* @param array $param user_id 员工IDcustomer_id 客户ID
* @return array
* @since 2021-04-15
* @author fanqi
* @since 2021-04-15
* @return array
*/
public function distributeCustomer($param)
{
@ -624,7 +621,7 @@ class CustomerPoolLogic extends Common
$customerData = $this->getCustomerList($customerId);
# 剔除非公海客户
foreach ($customerId as $key => $value) {
foreach ($customerId AS $key => $value) {
if (!empty($customerData[$value]['owner_user_id'])) {
$message[] = '将客户《' . $customerData[$value]['name'] . '》分配给员工' . $username . '失败,失败原因:不是公海客户!';
@ -644,7 +641,7 @@ class CustomerPoolLogic extends Common
$failCustomer = [];
if (!is_bool($exceedCount) && !empty($exceedCount) && $exceedCount > 0) {
$failCustomer = array_slice($customerId, count($customerId) - $exceedCount);
foreach ($failCustomer as $key => $value) {
foreach ($failCustomer AS $key => $value) {
$message[] = '将客户《' . $customerData[$value]['name'] . '》分配给员工' . $username . '失败,失败原因:持有客户数达到上限!';
}
}
@ -672,7 +669,7 @@ class CustomerPoolLogic extends Common
$addActionRecordData = [];
$addOperationLogData = [];
$addReceiveData = [];
foreach ($addCustomerId as $key => $value) {
foreach ($addCustomerId AS $key => $value) {
$addActionRecordData[] = [
'user_id' => $userId,
'types' => 'crm_customer',
@ -733,9 +730,9 @@ class CustomerPoolLogic extends Common
* 公海权限
*
* @param $param
* @return array
* @since 2021-04-14
* @author fanqi
* @since 2021-04-14
* @return array
*/
public function getAuthorityData($param)
{
@ -781,9 +778,9 @@ class CustomerPoolLogic extends Common
* 获取用户公海字段样式
*
* @param array $param pool 公海IDuser_is 用户ID
* @return array[]
* @since 2021-04-22
* @author fanqi
* @since 2021-04-22
* @return array[]
*/
public function getFieldConfigIndex($param)
{
@ -797,7 +794,7 @@ class CustomerPoolLogic extends Common
if (!empty($data)) {
$exceptFields = db('admin_field')->where(['types' => 'crm_customer', 'form_type' => ['in', ['file', 'handwriting_sign', 'desc_text', 'detail_table']]])->column('field');
foreach ($data as $key => $value) {
foreach ($data AS $key => $value) {
if (in_array($value['field'], $exceptFields)) continue;
if (!empty($value['is_hidden'])) {
@ -814,7 +811,7 @@ class CustomerPoolLogic extends Common
'form_type' => ['notin', ['file', 'handwriting_sign', 'desc_text', 'detail_table']]
];
$poolField = db('crm_customer_pool_field_setting')->where($where)->select();
foreach ($poolField as $key => $value) {
foreach ($poolField AS $key => $value) {
if (empty($value['is_hidden'])) {
$showList[] = [
'field' => $value['field_name'],
@ -843,7 +840,7 @@ class CustomerPoolLogic extends Common
$data = !empty($data) ? json_decode($data, true) :[];
if (!empty($data)) {
foreach ($data as $key => $value) {
foreach ($data AS $key => $value) {
if ($param['field'] == $value['field']) {
$data[$key]['width'] = $param['width'];
}
@ -855,7 +852,7 @@ class CustomerPoolLogic extends Common
} else {
$result = [];
$poolField = db('crm_customer_pool_field_setting')->where('pool_id', $param['pool_id'])->select();
foreach ($poolField as $key => $value) {
foreach ($poolField AS $key => $value) {
if ($param['field'] == $value['field_name']) {
$value['width'] = $param['width'];
}
@ -891,7 +888,7 @@ class CustomerPoolLogic extends Common
$showList = $param['value'];
$hideList = $param['hide_value'];
foreach ($showList as $key => $value) {
foreach ($showList AS $key => $value) {
$data[] = [
'field' => $value['field'],
'name' => $value['name'],
@ -899,7 +896,7 @@ class CustomerPoolLogic extends Common
'width' => $value['width']
];
}
foreach ($hideList as $key => $value) {
foreach ($hideList AS $key => $value) {
$data[] = [
'field' => $value['field'],
'name' => $value['name'],
@ -929,9 +926,9 @@ class CustomerPoolLogic extends Common
*
* @param string $source 源ids
* @param array $target 目标数组
* @return string
* @since 2021-04-14
* @author fanqi
* @since 2021-04-14
* @return string
*/
private function fieldTransformToText($source, $target)
{
@ -939,7 +936,7 @@ class CustomerPoolLogic extends Common
$array = explode(',', trim($source, ','));
foreach ($array as $kk => $vv) {
foreach ($array AS $kk => $vv) {
if (!empty($target[$vv])) $result[] = $target[$vv];
}
@ -950,9 +947,9 @@ class CustomerPoolLogic extends Common
* 查询表字段
*
* @param int $poolId 公海ID
* @return string
* @since 2021-04-14
* @author fanqi
* @since 2021-04-14
* @return string
*/
private function getPoolQueryField($poolId)
{
@ -971,9 +968,9 @@ class CustomerPoolLogic extends Common
/**
* 获取员工列表
*
* @return array
* @since 2021-04-14
* @author fanqi
* @since 2021-04-14
* @return array
*/
private function getUserList()
{
@ -981,7 +978,7 @@ class CustomerPoolLogic extends Common
$list = db('admin_user')->field(['id', 'realname'])->select();
foreach ($list as $key => $value) {
foreach ($list AS $key => $value) {
$result[$value['id']] = $value['realname'];
}
@ -991,9 +988,9 @@ class CustomerPoolLogic extends Common
/**
* 获取部门列表
*
* @return array
* @since 2021-04-14
* @author fanqi
* @since 2021-04-14
* @return array
*/
private function getStructureList()
{
@ -1001,7 +998,7 @@ class CustomerPoolLogic extends Common
$list = db('admin_structure')->field(['id', 'name'])->select();
foreach ($list as $key => $value) {
foreach ($list AS $key => $value) {
$result[$value['id']] = $value['name'];
}
@ -1012,9 +1009,9 @@ class CustomerPoolLogic extends Common
* 获取客户列表
*
* @param array $customerId 客户ID
* @return array
* @since 2021-04-15
* @author fanqi
* @since 2021-04-15
* @return array
*/
private function getCustomerList($customerId)
{
@ -1024,7 +1021,7 @@ class CustomerPoolLogic extends Common
$customerList = db('crm_customer')->field(['customer_id', 'owner_user_id', 'name', 'into_pool_time', 'before_owner_user_id'])->whereIn('customer_id', $customerId)->select();
# 整理客户数据
foreach ($customerList as $key => $value) {
foreach ($customerList AS $key => $value) {
$result[$value['customer_id']] = $value;
}
@ -1053,7 +1050,7 @@ class CustomerPoolLogic extends Common
$list = json_decode($list, true);
foreach ($list as $key => $value) {
foreach ($list AS $key => $value) {
if (!empty($value['is_hidden']) || empty($data[$value['field']])) continue;
$result[] = [
@ -1089,12 +1086,12 @@ class CustomerPoolLogic extends Common
# 公海字段-后台配置数据
$poolField = db('crm_customer_pool_field_setting')->where('pool_id', $param['pool_id'])->select();
$poolData = [];
foreach ($poolField as $key => $value) {
foreach ($poolField AS $key => $value) {
$poolData[$value['field_name']] = $value;
}
# 去掉隐藏的字段 + 去掉已经存在的字段 = 剩下的就是新增(隐藏后又开启)的字段
foreach ($fieldStyleList as $key => $value) {
foreach ($fieldStyleList AS $key => $value) {
# 去掉隐藏的字段
if (empty($poolData[$value['field']]) || (!empty($poolData[$value['field']]) && !empty($poolData[$value['field']]['is_hidden']))) {
unset($fieldStyleList[$key]);
@ -1111,7 +1108,7 @@ class CustomerPoolLogic extends Common
# 新增(隐藏后又开启)字段
if (!empty($poolData)) {
foreach ($poolData as $key => $value) {
foreach ($poolData AS $key => $value) {
if (empty($value['is_hidden'])) {
$fieldStyleList[] = [
'field' => $value['field_name'],
@ -1130,64 +1127,4 @@ class CustomerPoolLogic extends Common
}
}
}
/**
* 发起捞起客户审批
* @param array $param user_id 领取人IDcustomer_id 要领取的客户ID check_user_id 审核人id
*/
public function customerReceiveExamine($param)
{
$customerCheckModel = model('CustomerCheck');
$examineStepModel = new \app\admin\model\ExamineStep();
$examineStatus = $param['examineStatus'] ?? 1; // 审批是否停用
unset($param['examineStatus']);
$dataInfo = db('crm_customer_check')->where('customer_id', 'in', $param['customer_id'])->find();
if (!empty($dataInfo)&& $dataInfo['check_status'] < 2) {
return '客户已被领取待审批,请联系管理员';
}
if (($examineStatus != false && $examineStatus != 'false') || $examineStatus == 1) {
// 审核判断(是否有符合条件的审批流)
$examineFlowModel = new \app\admin\model\ExamineFlow();
if (!$examineFlowModel->checkExamine($param['user_id'], 'crm_customer_check')) {
return '暂无审批人,无法创建';
}
//添加审批相关信息
$examineFlowData = $examineFlowModel->getFlowByTypes($param['user_id'], 'crm_customer_check');
if (!$examineFlowData) {
return '无可用审批流,请联系管理员';
}
$param['flow_id'] = $examineFlowData['flow_id'];
//获取审批人信息
if ($examineFlowData['config'] == 1) {
//固定审批流
$nextStepData = $examineStepModel->nextStepUser($param['user_id'], $examineFlowData['flow_id'], 'crm_customer_check', 0, 0, 0);
$next_user_ids = arrayToString($nextStepData['next_user_ids']) ?: '';
$check_user_id = $next_user_ids ?: [];
$param['order_id'] = 1;
} else {
$check_user_id = $param['check_user_id'] ? ',' . $param['check_user_id'] . ',' : '';
}
if (!$check_user_id) {
return '无可用审批人,请联系管理员';
}
$param['check_user_id'] = is_array($check_user_id) ? ',' . implode(',', $check_user_id) . ',' : $check_user_id;
} else {
# 审批流停用,将状态改为审核通过
// $param['check_status'] = 2;
# 审批流停用,将状态改为正常 zjf 20210727 默认值为7
$param['check_status'] = 7;
}
if ($customerCheckModel->createData($param)) {
return '添加成功';
} else {
return $customerCheckModel->getError();
}
}
}

@ -167,43 +167,6 @@ class MessageLogic extends Common
$data = (new InvoiceLogic())->index($request);
return $data;
}
/**
*待审核商机
*
* @author alvin guogaobo
* @version 1.0 版本号
* @since 2021/5/26 0026 13:35
*/
public function checkBusiness($param){
$type = !empty($param['type']) ? $param['type'] : 1;
$isSub = 3;
unset($param['type']);
$businessModel = model('Business');
$request = $this->whereCheck($param, $type,$isSub);
$request['isMessage'] = true;
$data = $businessModel->getDataList($request);
return $data;
}
/**
*待审核客户捞取
*
* @author alvin guogaobo
* @version 1.0 版本号
* @since 2021/5/26 0026 13:35
*/
public function checkCustomerCheck($param){
$type = !empty($param['type']) ? $param['type'] : 1;
$isSub = 4;
unset($param['type']);
$customerCheckModel = model('CustomerCheck');
$request = $this->whereCheck($param, $type,$isSub);
$request['isMessage'] = true;
$data = $customerCheckModel->getDataList($request);
return $data;
}
/**
* 审批查询条件
* @param $param
@ -260,36 +223,6 @@ class MessageLogic extends Common
$param['dealt'] = 1;
break;
}
}elseif($isSub==3){
switch ($type) {
case '1' :
# 待审核、审核中
$param['check_status'] = ['lt', 2];
$param['check_user_id'] = ['like', '%,'. $param['user_id'] .',%'];
# 要提醒的商机ID
$businessIdArray = db('crm_dealt_relation')->where(['types' => ['eq', 'crm_business'], 'user_id' => ['eq', $param['user_id']]])->column('types_id');
$param['businessIdArray'] = !empty($businessIdArray) ? $businessIdArray : -1;
break;
case '2' :
# 全部
$param['flow_user_id'] = ['like', '%,'. $param['user_id'] .',%'];
break;
}
}elseif($isSub==4){
switch ($type) {
case '1' :
# 待审核、审核中
$param['check_status'] = ['lt', 2];
$param['check_user_id'] = ['like', '%,'. $param['user_id'] .',%'];
# 要提醒的商机ID
$customerCheckIdArray = db('crm_dealt_relation')->where(['types' => ['eq', 'crm_customer_check'], 'user_id' => ['eq', $param['user_id']]])->column('types_id');
$param['customerCheckIdArray'] = !empty($customerCheckIdArray) ? $customerCheckIdArray : -1;
break;
case '2' :
# 全部
$param['flow_user_id'] = ['like', '%,'. $param['user_id'] .',%'];
break;
}
}
return $param;
}

@ -6,7 +6,6 @@
// +----------------------------------------------------------------------
namespace app\crm\model;
use app\admin\model\Message;
use app\admin\traits\FieldVerificationTrait;
use think\Db;
use app\admin\model\Common;
@ -50,9 +49,6 @@ class Business extends Common
$businessTypeId = $request['typesId']; // 针对mobile
$businessStatusId = $request['statusId']; // 针对mobile
$overdue = $request['overdue']; // 待办事项下需联系商机(逾期)
$businessIdArray = $request['businessIdArray']; // 待办事项提醒参数
$isMessage = !empty($request['isMessage']);
$funnelQuery = $request['funnel']; // 销售漏斗查询赢单输单
unset($request['scene_id']);
unset($request['search']);
unset($request['user_id']);
@ -64,9 +60,6 @@ class Business extends Common
unset($request['typesId']);
unset($request['statusId']);
unset($request['overdue']);
unset($request['isMessage']);
unset($request['businessIdArray']);
unset($request['funnel']);
$request = $this->fmtRequest($request);
$requestMap = $request['map'] ?: [];
$sceneModel = new \app\admin\model\Scene();
@ -133,7 +126,6 @@ class Business extends Common
$auth_user_ids = array_merge(array_unique(array_filter($auth_user_ids))) ?: ['-1'];
$authMap['business.owner_user_id'] = array('in', $auth_user_ids);
} else {
if (!$isMessage) {
$authMapData = [];
$authMapData['auth_user_ids'] = $auth_user_ids;
$authMapData['user_id'] = $user_id;
@ -143,19 +135,6 @@ class Business extends Common
->whereOr('business.rw_user_id', array('like', '%,' . $authMapData['user_id'] . ',%'));
};
}
}
// 销售漏斗处理
if (!empty($funnelQuery)){
unset($map['business.status_id']);
unset($map['business.is_end']);
switch ($funnelQuery){
case '10000':// 赢单
$map['business.is_end']=1;
break;
case "10001":// 输单
$map['business.is_end']=2;
}
}
//联系人商机
if ($contacts_id) {
@ -199,9 +178,7 @@ class Business extends Common
$map['is_end']=abs($businessStatusId);
}
}
# 待办事项查询参数
$dealtWhere = [];
if (!empty($businessIdArray)) $dealtWhere['business.business_id'] = ['in', $businessIdArray];
// 待办事项下需联系商机(逾期)
$overdueWhere = '';
if (!empty($overdue)) {
@ -214,7 +191,7 @@ class Business extends Common
$dataCount = db('crm_business')
->alias('business')
->join('__CRM_CUSTOMER__ customer', 'business.customer_id = customer.customer_id', 'LEFT')
->where($map)->where($partMap)->where($authMap)->where($overdueWhere)->where($dealtWhere)->count('business_id');
->where($map)->where($partMap)->where($authMap)->where($overdueWhere)->count('business_id');
if (!empty($getCount) && $getCount == 1) {
$data['dataCount'] = !empty($dataCount) ? $dataCount : 0;
# 商机总金额
@ -223,7 +200,6 @@ class Business extends Common
$data['extraData']['money'] = ['businessSumMoney' => !empty($sumMoney) ? sprintf("%.2f", $sumMoney) : 0.00];
return $data;
}
$list = db('crm_business')
->alias('business')
->join('__CRM_CUSTOMER__ customer', 'business.customer_id = customer.customer_id', 'LEFT')
@ -231,7 +207,6 @@ class Business extends Common
->where($partMap)
->where($authMap)
->where($overdueWhere)
->where($dealtWhere)
->limit($request['offset'], $request['length'])
->field('business.*,customer.name as customer_name')
->orderRaw($order)
@ -335,14 +310,14 @@ class Business extends Common
// 处理日期date类型
$dateField = $fieldModel->getFieldByFormType('crm_business', 'date');
if (!empty($dateField)) {
foreach ($param as $key => $value) {
foreach ($param AS $key => $value) {
if (in_array($key, $dateField) && empty($value)) $param[$key] = null;
}
}
// 处理手写签名类型
$handwritingField = $fieldModel->getFieldByFormType('crm_business', 'handwriting_sign');
if (!empty($handwritingField)) {
foreach ($param as $key => $value) {
foreach ($param AS $key => $value) {
if (in_array($key, $handwritingField)) {
$param[$key] = !empty($value['file_id']) ? $value['file_id'] : '';
}
@ -353,7 +328,7 @@ class Business extends Common
$locationField = $fieldModel->getFieldByFormType($this->name, 'location');
$dateIntervalField = $fieldModel->getFieldByFormType($this->name, 'date_interval');
$detailTableField = $fieldModel->getFieldByFormType($this->name, 'detail_table');
foreach ($param as $key => $value) {
foreach ($param AS $key => $value) {
// 处理地址类型字段数据
if (in_array($key, $positionField)) {
if (!empty($value)) {
@ -408,6 +383,7 @@ class Business extends Common
}
}
}
# 设置今日需联系商机
if (!empty($param['next_time']) && $param['next_time'] >= strtotime(date('Y-m-d 00:00:00'))) $param['is_dealt'] = 0;
@ -451,31 +427,6 @@ class Business extends Common
});
db('crm_business_data')->insertAll($businessData);
//站内信
$userInfo = db('admin_user')->where(['id' => $param['create_user_id']])->find();
$send_user_id = stringToArray(getUserSuperior($userInfo['structure_id'], 0));
(new Message())->send(
Message::CUSTOMER_CHECK_TO_DO,
[
'title' => $param['name'],
'action_id' => $this->business_id
],
$send_user_id
);
$data = [];
$data['business_id'] = $this->business_id;
# 创建待办事项的关联数据
$dealtData = [];
foreach ($send_user_id as $kk => $vv) {
$dealtData[] = [
'types' => 'crm_business_new',
'types_id' => $data['business_id'],
'user_id' => $vv
];
}
if (!empty($dealtData)) db('crm_dealt_relation')->insertAll($dealtData);
return $data;
} else {
$this->error = '添加失败';
@ -529,14 +480,14 @@ class Business extends Common
// 处理日期date类型
$dateField = $fieldModel->getFieldByFormType('crm_business', 'date');
if (!empty($dateField)) {
foreach ($param as $key => $value) {
foreach ($param AS $key => $value) {
if (in_array($key, $dateField) && empty($value)) $param[$key] = null;
}
}
// 处理手写签名类型
$handwritingField = $fieldModel->getFieldByFormType('crm_business', 'handwriting_sign');
if (!empty($handwritingField)) {
foreach ($param as $key => $value) {
foreach ($param AS $key => $value) {
if (in_array($key, $handwritingField)) {
$param[$key] = !empty($value['file_id']) ? $value['file_id'] : '';
}
@ -547,7 +498,7 @@ class Business extends Common
$locationField = $fieldModel->getFieldByFormType($this->name, 'location');
$dateIntervalField = $fieldModel->getFieldByFormType($this->name, 'date_interval');
$detailTableField = $fieldModel->getFieldByFormType($this->name, 'detail_table');
foreach ($param as $key => $value) {
foreach ($param AS $key => $value) {
// 处理地址类型字段数据
if (in_array($key, $positionField)) {
if (!empty($value)) {
@ -665,7 +616,7 @@ class Business extends Common
}
}
}
foreach ($fieldGrant as $key => $val) {
foreach ($fieldGrant AS $key => $val){
//掩码相关类型字段
if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
$pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
@ -714,7 +665,7 @@ class Business extends Common
if (!empty($userId)) {
$grantData = getFieldGrantData($userId);
$userLevel = isSuperAdministrators($userId);
foreach ($dataInfo as $key => $value) {
foreach ($dataInfo AS $key => $value) {
if (!$userLevel && !empty($grantData['crm_business'])) {
$status = getFieldGrantStatus($key, $grantData['crm_business']);

@ -206,11 +206,6 @@ class Contacts extends Common
$list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
$list[$k]['customer_id_info']['customer_id'] = $v['customer_id'] ?: '';
$list[$k]['customer_id_info']['name'] = $v['customer_name'] ?: '';
$list[$k]['wxwork_name'] = '';
if ($list[$k]['wxwork_id']) {
$wxwork = db('admin_wxwork')->where('id', $list[$k]['wxwork_id'])->find();
$list[$k]['wxwork_name'] = $wxwork['name'];
}
foreach ($userField as $key => $val) {
$usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : [];
$list[$k][$val] = implode($usernameField, ',');

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

@ -1,211 +0,0 @@
<?php
namespace app\crm\model;
use app\admin\model\Common;
use app\admin\model\Message;
use app\admin\traits\FieldVerificationTrait;
use think\Db;
class CustomerCheck extends Common
{
use FieldVerificationTrait;
/**
* 为了数据库的整洁同时又不影响Model和Controller的名称
* 我们约定每个模块的数据表都加上相同的前缀比如CRM模块用crm作为数据表前缀
*/
protected $name = 'crm_customer_check';
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
protected $autoWriteTimestamp = true;
/**
* 待审核客户列表
* @param $request
* @return array
*/
public function getDataList($request)
{
$userModel = new \app\admin\model\User();
$fieldModel = new \app\admin\model\Field();
$customer_check_id = $request['customer_check_id'];
$order_field = $request['order_field'];
$order_type = $request['order_type'];
$getCount = $request['getCount'];
$user_id = $request['user_id'];
$customerCheckIdArray = $request['customerCheckIdArray']; // 待办事项提醒参数
unset($request['scene_id']);
unset($request['search']);
unset($request['user_id']);
unset($request['$customer_check_id']);
unset($request['order_field']);
unset($request['order_type']);
unset($request['is_excel']);
unset($request['getCount']);
unset($request['typesId']);
unset($request['statusId']);
unset($request['overdue']);
unset($request['isMessage']);
unset($request['customerCheckIdArray']);
$request = $this->fmtRequest($request);
$requestMap = $request['map'] ?: [];
# getCount是代办事项传来的参数代办事项不需要使用场景
$sceneMap = [];
$partMap = [];
$teamMap = $requestMap['team_id'];
//团队成员 高级筛选
if ($teamMap) {
$partMap = advancedQueryFormatForTeam($teamMap, 'customer_check', '');
unset($requestMap['team_id']);
$map = $requestMap ? array_merge($sceneMap, $requestMap) : $sceneMap;
} else {
$map = $requestMap ? array_merge($sceneMap, $requestMap) : $sceneMap;
}
// 权限
$readAuthIds = $userModel->getUserByPer('crm', 'customer', 'read');
$updateAuthIds = $userModel->getUserByPer('crm', 'customer', 'update');
$deleteAuthIds = $userModel->getUserByPer('crm', 'customer', 'delete');
//排序
if ($order_type && $order_field) {
$order = $fieldModel->getOrderByFormtype('crm_customer_check', 'customer_check', $order_field, $order_type);
} else {
$order = 'customer_check.update_time desc';
}
# 待办事项查询参数
$dealtWhere = [];
if (!empty($customerCheckIdArray)) $dealtWhere['customer_check.customer_check_id'] = ['in', $customerCheckIdArray];
$dataCount = db('crm_customer_check')
->alias('customer_check')
->join('__CRM_CUSTOMER__ customer', 'customer_check.customer_check_id = customer.customer_id', 'LEFT')
->where($map)->where($partMap)->where($dealtWhere)->count('customer_check_id');
if (!empty($getCount) && $getCount == 1) {
$data['dataCount'] = !empty($dataCount) ? $dataCount : 0;
return $data;
}
$indexField = $fieldModel->getIndexField('crm_customer', $user_id, 1) ?: array('name'); // 列表展示字段
$userField = $fieldModel->getFieldByFormType('crm_customer', 'user'); // 人员类型
$structureField = $fieldModel->getFieldByFormType('crm_customer', 'structure'); // 部门类型
# 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
$temporaryField = str_replace('_name', '', $order_field);
if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
$order_field = $temporaryField;
}
$customerField = '';
foreach ($indexField as $k => $v) {
$customerField = 'customer.'.$v;
}
$list = db('crm_customer_check')
->alias('customer_check')
->join('__CRM_CUSTOMER__ customer', 'customer_check.customer_id = customer.customer_id', 'LEFT')
->where($map)
->where($partMap)
->where($dealtWhere)
->limit($request['offset'], $request['length'])
->field('customer_check.*,customer.*')
->orderRaw($order)
->select();
foreach ($list as $k => $v) {
$list[$k]['customer_id_info']['customer_id'] = $v['customer_id'];
$list[$k]['customer_id_info']['name'] = $v['customer_name'];
$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]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : '';
$list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : '';
//权限
$roPre = $userModel->rwPre($user_id, $v['ro_user_id'], $v['rw_user_id'], 'read');
$rwPre = $userModel->rwPre($user_id, $v['ro_user_id'], $v['rw_user_id'], 'update');
$permission = [];
$is_read = 0;
$is_update = 0;
$is_delete = 0;
if (in_array($v['owner_user_id'], $readAuthIds) || $roPre || $rwPre) $is_read = 1;
if (in_array($v['owner_user_id'], $updateAuthIds) || $rwPre) $is_update = 1;
if (in_array($v['owner_user_id'], $deleteAuthIds)) $is_delete = 1;
$permission['is_read'] = $is_read;
$permission['is_update'] = $is_update;
$permission['is_delete'] = $is_delete;
$list[$k]['permission'] = $permission;
# 日期
$list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null;
$list[$k]['update_time'] = !empty($v['update_time']) ? date('Y-m-d H:i:s', $v['update_time']) : null;
# 系统字段 负责人部门 zjf 20210726
$list[$k]['owner_user_structure_name'] = $list[$k]['owner_user_id_info']['structure_name'];
}
$data = [];
$data['list'] = $list ?: [];
$data['dataCount'] = $dataCount ?: 0;
return $data;
}
/**
* 创建客户捞取审批信息
* @param
* @return
*/
public function createData($param)
{
$createData = [];
foreach ($param['customer_id'] as $key => $value) {
$createData[$key]['customer_id'] = $value;
$createData[$key]['check_status'] = $param['check_status'] ?? 0;
$createData[$key]['flow_id'] = $param['flow_id'] ?? 0;
$createData[$key]['order_id'] = $param['order_id'] ?? 0;
$createData[$key]['check_user_id'] = $param['check_user_id'] ?? 0;
$createData[$key]['flow_user_id'] = $param['flow_user_id'] ?? 0;
$createData[$key]['user_id'] = $param['user_id'] ?? 0;
$createData[$key]['create_user_id'] = $param['user_id'] ?? 0;
$createData[$key]['owner_user_id'] = $param['user_id'] ?? 0;
}
$this->startTrans();
try {
$data = $this->saveAll($createData);
$this->commit();
} catch (\Exception $e) {
$this->error = '领取失败';
$this->rollback();
return false;
}
foreach ($data as $k => $v) {
//站内信
$send_user_id = stringToArray($param['check_user_id']);
if ($send_user_id && empty($param['check_status'])) {
(new Message())->send(
Message::CUSTOMER_CHECK_TO_DO,
[
'title' => $param['name'],
'action_id' => $v['customer_check_id']
],
$send_user_id
);
}
$data = [];
$data['customer_check_id'] = $v['customer_check_id'];
echo $v['customer_check_id'];
# 创建待办事项的关联数据
$checkUserIds = db('crm_customer_check')->where('customer_check_id', $data['customer_check_id'])->value('check_user_id');
$checkUserIdArray = stringToArray($checkUserIds);
$dealtData = [];
foreach ($checkUserIdArray as $kk => $vv) {
$dealtData[] = [
'types' => 'crm_customer_check',
'types_id' => $data['customer_check_id'],
'user_id' => $vv
];
}
if (!empty($dealtData)) db('crm_dealt_relation')->insertAll($dealtData);
}
}
}

@ -470,30 +470,6 @@ class ExamineLogic extends Common
->where($where)
->where($whereOr)
->count();
case 5:// 客户
$list = db('crm_customer_check')
->alias('a')
->join('__ADMIN_USER__ user', 'user.id = a.user_id', 'LEFT')
->join('__ADMIN_EXAMINE_FLOW__ examine_flow', 'examine_flow.flow_id = a.flow_id', 'LEFT')
->join('__CRM_CUSTOMER__ customer','customer.customer_id=a.customer_id','LEFT')
->where($where)
->where($whereOr)
->field(
'a.customer_check_id as catagory_id ,customer.name as customer_name,a.create_time,a.check_status,a.user_id,a.check_user_id,a.flow_user_id,user.realname,examine_flow.name as examine_name'
)
->page($param['page'], $param['limit'])
->order('a.create_time desc')
->select();
foreach ($list as $k => $v) {
$list[$k]['create_user_info'] = $userModel->getUserById($v['user_id']);
}
$dataCount = db('crm_customer_check')
->alias('a')
->join('__ADMIN_USER__ user', 'user.id = a.user_id', 'LEFT')
->where($where)
->where($whereOr)
->count();
}

@ -3,13 +3,13 @@ return [
// 数据库类型
'type' => 'mysql',
// 服务器地址
'hostname' => '127.0.0.1',
'hostname' => 'mysql',
// 数据库名
'database' => 'wkcrm',
// 用户名
'username' => 'wkcrm',
// 密码
'password' => 'YNKdaMS2XBHKcAh7',
'password' => 'lpC049ZvZdmNIzDvbY0rXKgl',
// 端口
'hostport' => '3306',
// 连接dsn

@ -56,8 +56,6 @@ 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']],
@ -73,8 +71,6 @@ return [
'crm/customerPool/authority' => ['crm/customerPool/authority', ['method' => 'POST']],
// 【客户】领取公海客户
'crm/customerPool/receive' => ['crm/customerPool/receive', ['method' => 'POST']],
// 【客户】领取公海客户审批
'crm/customerPool/checkCustomerReveive' => ['crm/customerPool/checkCustomerReveive', ['method' => 'POST']],
// 【客户】分配公海客户
'crm/customerPool/distribute' => ['crm/customerPool/distribute', ['method' => 'POST']],
// 【客户】删除公海客户
@ -91,8 +87,6 @@ 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']],
@ -195,8 +189,6 @@ return [
'crm/business/count' => ['crm/business/count', ['method' => 'POST']],
// 【商机】菜单数量
'crm/business/setPrimary' => ['crm/business/setPrimary', ['method' => 'POST']],
// 【商机】审批
'crm/business/check' => ['crm/business/check', ['method' => 'POST']],
// 【合同】列表
'crm/contract/index' => ['crm/contract/index', ['method' => 'POST']],
@ -414,9 +406,6 @@ return [
'crm/message/endContract' => ['crm/message/endContract', ['method' => 'POST']],
'crm/message/remindCustomer' => ['crm/message/remindCustomer', ['method' => 'POST']],
'crm/message/checkInvoice' => ['crm/message/checkInvoice', ['method' => 'POST']],
'crm/message/checkBusiness' => ['crm/message/checkBusiness', ['method' => 'POST']],
'crm/message/checkCustomerCheck' => ['crm/message/checkCustomerCheck', ['method' => 'POST']],
'crm/message/newBusiness' => ['crm/message/newBusiness', ['method' => 'POST']],
'crm/message/visitContract' => ['crm/message/visitContract', ['method' => 'POST']],
'crm/message/allDeal' => ['crm/message/allDeal', ['method' => 'POST']],
@ -536,7 +525,6 @@ return [
// 企业微信回调
'crm/callback/index' => ['crm/callback/index', ['method' => 'POST|GET']],
'crm/callback/work' => ['crm/callback/work', ['method' => 'POST|GET']],
// MISS路由
'__miss__' => 'admin/base/miss',

Loading…
Cancel
Save