Compare commits

..

No commits in common. '048ed843b84b4976e944b95a3f6812663df668c9' and 'dc39d426878f83ab64e38e2eeab9d7cbaf29c801' have entirely different histories.

@ -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'],

@ -29,10 +29,10 @@ class ExamineStep extends Common
{
$userModel = new \app\admin\model\User();
$list = $this->where(['flow_id' => $flow_id])->order('order_id asc')->select();
foreach ($list as $k => $v) {
foreach ($list as $k=>$v) {
$list[$k]['user_id_info'] = $userModel->getListByStr($v['user_id']);
}
return $list ?: [];
return $list ? : [];
}
/**
@ -50,19 +50,19 @@ class ExamineStep extends Common
//处理数据
$resSuccess = true;
$dataStep = [];
foreach ($data as $k => $v) {
if (!intval($v['status']) || (in_array($v['status'], [2, 3]) && !$v['user_id'])) {
foreach ($data as $k=>$v) {
if (!intval($v['status']) || (in_array($v['status'],[2,3]) && !$v['user_id'])) {
$resSuccess = false;
}
$dataStep[$k]['relation'] = 1;
if (in_array($v['status'], [2, 3])) {
if (in_array($v['status'],[2,3])) {
$dataStep[$k]['user_id'] = $v['user_id'] ? arrayToString($v['user_id']) : ''; //处理user_id
$dataStep[$k]['relation'] = ($v['status'] == 3) ? 1 : 2;
}
if ($v['step']) {
$dataStep[$k]['step_id'] = $v['step'];
}
$dataStep[$k]['order_id'] = $k + 1;
$dataStep[$k]['order_id'] = $k+1;
$dataStep[$k]['flow_id'] = $flow_id;
$dataStep[$k]['status'] = $v['status'];
$dataStep[$k]['create_time'] = time();
@ -75,7 +75,7 @@ class ExamineStep extends Common
$this->saveAll($dataStep);
$this->commit();
return true;
} catch (\Exception $e) {
} catch(\Exception $e) {
$this->error = '审批步骤创建失败';
$this->rollback();
return false;
@ -94,9 +94,9 @@ class ExamineStep extends Common
public function orderData($flow_id)
{
$step_list = db('admin_examine_step')->where(['flow_id' => $flow_id])->order('order_id')->select();
foreach ($step_list as $k => $v) {
foreach ($step_list as $k=>$v) {
$data = [];
$data = ['step_id' => $v['step_id'], 'order_id' => $k];
$data = ['step_id' => $v['step_id'],'order_id' => $k];
db('admin_examine_step')->update($data);
}
}
@ -114,7 +114,7 @@ class ExamineStep extends Common
public function nextStepUser($user_id, $flow_id, $types, $types_id, $order_id, $check_user_id)
{
$res = nextCheckData($user_id, $flow_id, $types, $types_id, $order_id, $check_user_id);
return $res ?: [];
return $res ? : [];
}
/**
@ -136,7 +136,7 @@ class ExamineStep extends Common
$this->error = '参数错误!';
return false;
}
if (in_array($dataInfo['check_status'], ['2', '3'])) {
if (in_array($dataInfo['check_status'], ['2','3'])) {
$this->error = '审批已经结束!';
return false;
}
@ -176,61 +176,27 @@ 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'])) {
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'];
$stepInfo = db('admin_examine_step')->where(['flow_id' => $dataInfo['flow_id'],'order_id' => $dataInfo['order_id']])->find();
}
$data = [];
$data['stepInfo'] = $stepInfo;
$data['step_id'] = $stepInfo['step_id'] ?: '';
$data['step_id'] = $stepInfo['step_id'] ? : '';
$data['dataInfo'] = $dataInfo;
return $data;
}
@ -257,12 +223,10 @@ 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');
$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');
$last_step_info = db('admin_examine_step')->where(['step_id' => $last_step_id])->find();
$last_user_id = $this->getUserByStep($last_step_id, $user_id);
if (count(stringToArray($last_user_id)) !== 1) {
@ -277,10 +241,9 @@ 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))) . ',' : '';
return array_unique($examine_user_id_arr) ? ','.implode(',',array_filter(array_unique($examine_user_id_arr))).',' : '';
}
/**
@ -294,9 +257,9 @@ class ExamineStep extends Common
if ($types_id == 0 && $order_id == 0) {
$check_user_ids = [];
} else {
$check_user_ids = db('admin_examine_record')->where(['types' => $types, 'types_id' => $types_id, 'order_id' => $order_id, 'is_end' => 0, 'status' => $status])->column('check_user_id');
$check_user_ids = db('admin_examine_record')->where(['types' => $types,'types_id' => $types_id,'order_id' => $order_id,'is_end' => 0,'status' => $status])->column('check_user_id');
}
return $check_user_ids ?: [];
return $check_user_ids ? : [];
}
/**
@ -307,7 +270,7 @@ class ExamineStep extends Common
*/
public function getUserByPer($types)
{
if (!in_array($types, ['oa_examine', 'crm_contract', 'crm_receivables'])) {
if (!in_array($types,['oa_examine','crm_contract','crm_receivables'])) {
$this->error = '参数错误';
return false;
}
@ -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;
@ -342,10 +297,10 @@ class ExamineStep extends Common
{
$user_ids = [];
if ($flow_id && $order_id) {
$stepInfo = db('admin_examine_step')->where(['flow_id' => $flow_id, 'order_id' => $order_id])->find();
$stepInfo = db('admin_examine_step')->where(['flow_id' => $flow_id,'order_id' => $order_id])->find();
$user_ids = $this->getUserByStep($stepInfo['step_id'], $user_id);
}
return $user_ids ?: [];
return $user_ids ? : [];
}
/**
@ -373,11 +328,11 @@ class ExamineStep extends Common
//创建人或负责人或管理员有撤销权限
//if ($dataInfo['create_user_id'] == $check_user_id || $dataInfo['owner_user_id'] == $check_user_id || in_array($check_user_id, $admin_user_ids)) {
if ($dataInfo['create_user_id'] == $check_user_id || $dataInfo['owner_user_id'] == $check_user_id) {
if (!in_array($dataInfo['check_status'], ['2', '3', '4', '6'])) {
if (!in_array($dataInfo['check_status'],['2','3','4','6'])) {
$is_recheck = 1;
}
}
if (in_array($check_user_id, stringToArray($dataInfo['check_user_id'])) && !in_array($dataInfo['check_status'], ['2', '3', '4', '6'])) {
if (in_array($check_user_id, stringToArray($dataInfo['check_user_id'])) && !in_array($dataInfo['check_status'],['2','3','4','6'])) {
$is_check = 1;
}
@ -385,7 +340,7 @@ class ExamineStep extends Common
$createUserInfo = $userModel->getUserById($dataInfo['create_user_id']);
$createUserInfo['check_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
if ($dataInfo['check_status'] == 4 && $dataInfo['create_user_id'] != trim($dataInfo['check_status'], ',')) {
if ($dataInfo['check_status'] == 4 && $dataInfo['create_user_id']!=trim( $dataInfo['check_status'], ',')) {
$createUserInfo['check_type'] = 2;
$newlist[1]['type'] = '2'; //撤销
$newlist[1]['status'] = '5'; //创建前端要求给创建人加一个status字段定义为5
@ -396,7 +351,7 @@ class ExamineStep extends Common
$newlist[0]['time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
$newlist[1]['user_id_info'] = array($createUserInfo);
$newlist[1]['time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
} elseif ($dataInfo['check_status'] == 4 && $dataInfo['create_user_id'] == trim($dataInfo['check_status'], ',')) {
} elseif ($dataInfo['check_status'] == 4 && $dataInfo['create_user_id']==trim( $dataInfo['check_status'], ',')){
$createUserInfo['check_type'] = 3;
$newlist[0]['type'] = '3'; //创建
$newlist[0]['status'] = '5'; //创建前端要求给创建人加一个status字段定义为5
@ -419,7 +374,7 @@ class ExamineStep extends Common
if ($dataInfo['check_status'] !== 4 || $action !== 'view') {
$list = db('admin_examine_step')->where(['flow_id' => $flow_id])->order('order_id asc')->select();
$is_break = false;
foreach ($list as $k => $v) {
foreach ($list as $k=>$v) {
$type = 4;
$examine_user_ids = '';
//判断步骤审批人是否存在
@ -428,7 +383,7 @@ class ExamineStep extends Common
if ($examine_user_arr) {
$newStepInfo = $v;
$user_id_info_arr = [];
foreach ($examine_user_arr as $key => $val) {
foreach ($examine_user_arr as $key=>$val) {
$user_id_info = [];
$user_id_info = $userModel->getUserById($val);
$check_type = 4; //type 0失败1通过2撤销3创建4待审核5未提交
@ -439,7 +394,7 @@ class ExamineStep extends Common
$check_type = 1;
$type = !empty($dataInfo['check_user_id']) ? 4 : 1;
}
if (in_array($val, $check_user_ids) && $dataInfo['check_status'] == 2) {
if(in_array($val, $check_user_ids) && $dataInfo['check_status'] == 2){
$check_type = 1;
$type = 1;
}
@ -453,7 +408,7 @@ class ExamineStep extends Common
}
$fail_check_user_ids = $this->getUserByCheck($types, $types_id, $v['order_id'], 0); //拒绝人员
if ($dataInfo['check_status'] == 3) {
if (in_array($val, $fail_check_user_ids)) {
if (in_array($val,$fail_check_user_ids)) {
$is_break = true;
$check_type = 0;
$type = 0;
@ -462,7 +417,7 @@ class ExamineStep extends Common
}
$user_id_info['check_type'] = $check_type;
$check_time = '';
$check_time = db('admin_examine_record')->where(['types' => $types, 'types_id' => $types_id, 'flow_id' => $flow_id, 'order_id' => $v['order_id'], 'check_user_id' => $val, 'is_end' => 0])->value('check_time');
$check_time = db('admin_examine_record')->where(['types' => $types,'types_id' => $types_id,'flow_id' => $flow_id,'order_id' => $v['order_id'],'check_user_id' => $val,'is_end' =>0])->value('check_time');
$user_id_info['check_time'] = !empty($check_time) ? date('Y-m-d H:i:s', $check_time) : '';
$user_id_info_arr[] = $user_id_info;
}
@ -485,10 +440,10 @@ class ExamineStep extends Common
} else {
$newStepList = $newlist;
}
$data['steplist'] = $newStepList ?: [];
$data['steplist'] = $newStepList ? : [];
$data['is_check'] = $is_check;
$data['is_recheck'] = $is_recheck;
return $data ?: [];
return $data ? : [];
}
/**
@ -499,8 +454,8 @@ class ExamineStep extends Common
*/
public function getStepByOrder($flow_id, $order_id)
{
$data = db('admin_examine_step')->where(['flow_id' => $flow_id, 'order_id' => $order_id])->find();
return $data ?: [];
$data = db('admin_examine_step')->where(['flow_id' => $flow_id,'order_id' => $order_id])->find();
return $data ? : [];
}
/**
@ -525,13 +480,13 @@ class ExamineStep extends Common
$dataInfo = $typeInfo['dataInfo'];
//type 0失败1通过2撤销3创建4待审核5未提交
$i = 0;
if (empty($recordList)) {
if(empty($recordList)){
$createUserInfo = $userModel->getUserById($dataInfo['create_user_id']);
$userList[0]['userInfo'] = $createUserInfo;
$userList[0]['type'] = 3; //创建
$userList[0]['time'] = $dataInfo['update_time'] ?: '';
} else {
foreach ($recordList as $k => $v) {
$userList[0]['time'] = $dataInfo['update_time'] ? : '';
}else{
foreach ($recordList as $k=>$v) {
$userList[$i]['userInfo'] = $userModel->getUserById($v['check_user_id']);
$userList[$i]['type'] = $v['status'];
$userList[$i]['time'] = $v['check_time'];
@ -556,17 +511,17 @@ class ExamineStep extends Common
//创建人或负责人或管理员有撤销权限
// if ($dataInfo['create_user_id'] == $check_user_id || $dataInfo['owner_user_id'] == $check_user_id || in_array($check_user_id, $admin_user_ids)) {
if ($dataInfo['create_user_id'] == $check_user_id || $dataInfo['owner_user_id'] == $check_user_id) {
if (!in_array($dataInfo['check_status'], ['2', '3', '4', '5', '6'])) {
if (!in_array($dataInfo['check_status'],['2','3','4','5','6'])) {
$is_recheck = 1;
}
}
if (in_array($check_user_id, stringToArray($dataInfo['check_user_id'])) && !in_array($dataInfo['check_status'], ['2', '3', '4', '5', '6'])) {
if (in_array($check_user_id, stringToArray($dataInfo['check_user_id'])) && !in_array($dataInfo['check_status'],['2','3','4','5','6'])) {
$is_check = 1;
}
$data['steplist'] = $userList;
$data['is_check'] = $is_check;
$data['is_recheck'] = $is_recheck;
return $data ?: [];
return $data ? : [];
}
}

@ -390,10 +390,10 @@ class Field extends Model
if ($v['form_type'] == 'checkbox') {
$list[$k]['default_value'] = $v['default_value'] ? explode(',', $v['default_value']) : array();
}
if ($v['form_type'] == 'date_interval') {
$list[$k]['default_value'] = !empty($v['default_value']) ? explode(',', $v['default_value']) : [];
if ($v['form_type']=='date_interval') {
$list[$k]['default_value'] = !empty($v['default_value']) ? explode(',',$v['default_value']) : [];
}
if ($v['form_type'] == 'position') {
if($v['form_type']=='position'){
$list[$k]['default_value'] = !empty($v['default_value']) ? json_decode($v['default_value'], true) : [];
}
if ($v['form_type'] == 'detail_table') {
@ -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'],
@ -716,7 +713,7 @@ class Field extends Model
$new_default_value[] = str_replace(',', '', $v);
}
$data['default_value'] = implode(',', $new_default_value);
} elseif ($data['default_value'] && $data['form_type'] == 'select' && !empty($data['default_value'])) {
}elseif($data['default_value'] && $data['form_type'] == 'select' && !empty($data['default_value'])){
$data['default_value'] = $data['default_value'];
} else {
$data['default_value'] = '';
@ -763,12 +760,12 @@ class Field extends Model
// 数值范围
if (!empty($data['minNumRestrict'])) {
$data['min_num_restrict'] = $data['minNumRestrict'];
} else {
$data['min_num_restrict'] = '';
}else{
$data['min_num_restrict']='';
}
if (!empty($data['maxNumRestrict'])) {
if (!empty($data['maxNumRestrict'])){
$data['max_num_restrict'] = $data['maxNumRestrict'];
} else {
}else{
$data['max_num_restrict'] = '';
}
// 清除坐标
@ -1128,8 +1125,8 @@ class Field extends Model
'fieldName' => 'owner_user_structure_name'
];
foreach ($field_list as $k => $v) {
if ($v['field'] == 'invoice_type') {
$field_list[$k]['setting'] = $v['setting'] ? explode(chr(10), $v['setting']) : [];
if($v['field']=='invoice_type'){
$field_list[$k]['setting']=$v['setting']?explode(chr(10), $v['setting']):[];
}
# 处理字段授权
$field_list[$k]['writeStatus'] = 1;
@ -1257,7 +1254,7 @@ class Field extends Model
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($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']]);
@ -1274,7 +1271,7 @@ class Field extends Model
}
if ($param['action'] == 'read') {
$field_list[$k]['maskType'] = $status['maskType'];
if ($status['maskType'] != 0) {
if($status['maskType']!=0){
$field_list[$k]['writeStatus'] = 0;
}
}
@ -1472,32 +1469,32 @@ class Field extends Model
} elseif ($v['form_type'] == 'desc_text') {
// 描述文字
$value = !empty($dataInfo[$v['field']]) ? $dataInfo[$v['field']] : $v['default_value'];
} elseif ($v['form_type'] == 'location') {
} elseif ($v['form_type']=='location') {
// 地址、定位、日期区间、明细表格
$primaryKey = getPrimaryKeyName($param['types']);
$positionJson = !empty($dataInfo[$primaryKey]) ? db($param['types'] . '_data')->where([$primaryKey => $dataInfo[$primaryKey], 'field' => $v['field']])->value($param['types'] == 'oa_examine' ? 'value' : 'content') : '';
$positionData = !empty($positionJson) ? json_decode($positionJson, true) : '';
$value = $positionData;
} elseif ($v['form_type'] == 'detail_table') {
} elseif($v['form_type']=='detail_table'){
// $fieldGrant = db('admin_field_mask')->where('types', 'contract')->select();
$primaryKey = getPrimaryKeyName($param['types']);
$positionJson = !empty($dataInfo[$primaryKey]) ? db($param['types'] . '_data')->where([$primaryKey => $dataInfo[$primaryKey], 'field' => $v['field']])->value($param['types'] == 'oa_examine' ? 'value' : 'content') : '';
$positionData = !empty($positionJson) ? json_decode($positionJson, true) : '';
foreach ($positionData as $kk => $val) {
foreach ($val as $key => $values) {
if ($values['form_type'] == 'user') {
$positionData[$kk][$key]['value'] = !empty($values['value']) ? $userModel->getListByStr($values['value']) : [];
foreach ($positionData as $kk => $val){
foreach ($val as $key => $values){
if($values['form_type']=='user'){
$positionData[$kk][$key]['value']= !empty($values['value'])?$userModel->getListByStr($values['value']) :[];
}
if ($values['form_type'] == 'structure') {
$positionData[$kk][$key]['value'] = !empty($values['value']) ? $structureModel->getListByStr($values['value']) : [];
if($values['form_type']=='structure'){
$positionData[$kk][$key]['value']= !empty($values['value'])? $structureModel->getListByStr($values['value']) : [];
}
if ($values['form_type'] == 'datetime' && is_numeric($values['value'])) {
$positionData[$kk][$key]['value'] = date('Y-m-d, H:i:s', $values['value']);
if($values['form_type']=='datetime' && is_numeric($values['value'])){
$positionData[$kk][$key]['value']= date('Y-m-d, H:i:s',$values['value']);
}
if ($values['form_type'] == 'boolean_value') {
$positionData[$kk][$key]['value'] = (string)$values['value'];
if($values['form_type']=='boolean_value'){
$positionData[$kk][$key]['value']= (string)$values['value'];
}
if ($values['form_type'] == 'file') {
if($values['form_type']=='file'){
$fileIds = stringToArray($values['value']);
$whereFile = [];
$whereFile['module'] = 'other';
@ -1517,36 +1514,36 @@ class Field extends Model
// $positionData[$kk][$key]['value'] = !empty($dataInfo[$val['fiele_id']]) ? (string)substr_replace($values['value'], '*',0,strlen($values['value'])) : null;
// }
// }
$positionData[$kk][$key]['optionsData'] = !empty($field_list[$k]['options']) ? json_decode($field_list[$k]['options'], true) : '';
$positionData[$kk][$key]['optionsData']=!empty($field_list[$k]['options']) ? json_decode($field_list[$k]['options'], true) : '';
}
}
$value = $positionData;
if ($v['form_type'] == 'detail_table') {
$content = db('admin_field_extend')->where(['types' => $types, 'field' => $v['field']])->value('content');
$content = json_decode($content, true);
foreach ($content as &$vv) {
$vv['optionsData'] = !empty($field_list[$k]['options']) ? json_decode($field_list[$k]['options'], true) : '';
$content=json_decode($content, true);
foreach ($content as &$vv){
$vv['optionsData']=!empty($field_list[$k]['options']) ? json_decode($field_list[$k]['options'], true) : '';
}
$field_list[$k]['fieldExtendList'] = $content;
}
} elseif ($v['form_type'] == 'position') {
} elseif($v['form_type']=='position'){
// 地址
$default_value = !empty($v['default_value']) ? json_decode($v['default_value'], true) : [];
if (!empty($dataInfo[$v['field']])) {
$position = explode(',', $dataInfo[$v['field']]);
for ($i = 0; $i < count($position); $i++) {
$b[]['name'] = trim(json_encode($position[$i], JSON_UNESCAPED_UNICODE), '"');
if(!empty($dataInfo[$v['field']])){
$position= explode(',',$dataInfo[$v['field']]);
for ($i=0; $i<count($position); $i++) {
$b[]['name'] =trim(json_encode($position[$i],JSON_UNESCAPED_UNICODE),'"');
}
$value = $b;
$value =$b;
}
} elseif ($v['form_type'] == 'date_interval') {
} elseif($v['form_type']=='date_interval'){
if (!empty($dataInfo[$v['field']])) {
$position = explode('_', $dataInfo[$v['field']]);
$value = $position;
$position= explode('_',$dataInfo[$v['field']]);
$value =$position;
}
$default_value = !empty($v['default_value']) ? explode(',', $v['default_value']) : [];
$default_value = !empty($v['default_value'])?explode(',',$v['default_value']):[];
} else {
$value = isset($dataInfo[$v['field']]) ? $dataInfo[$v['field']] : '';
}
@ -1819,7 +1816,7 @@ class Field extends Model
foreach ($dataList as $k => $v) {
if (!$userLevel && !empty($grantData[$types])) {
$status = getFieldGrantStatus($v['field'], $grantData[$types]);
$dataList[(int)$k]['maskType'] = $status['maskType'];
$dataList[(int)$k]['maskType']=$status['maskType'];
# 查看权限
if ($status['read'] == 0) unset($dataList[(int)$k]);
}
@ -1864,7 +1861,7 @@ class Field extends Model
}
$fieldArr = $this
->where($where)
->field(['field', 'name', 'form_type', 'is_hidden', 'setting'])
->field(['field', 'name', 'form_type', 'is_hidden','setting'])
->order('order_id', 'asc')
->select();
@ -1879,7 +1876,7 @@ class Field extends Model
}
if (isset($this->orther_field_list[$newTypes])) {
foreach ($this->orther_field_list[$newTypes] as $val) {
if ($val['field'] != 'product_picture') {
if($val['field'] != 'product_picture'){
$res[] = $val;
}
}
@ -2345,13 +2342,13 @@ class Field extends Model
$val = db('jxc_purchase')->where(['purchase_id' => $val])->value('order_number');
break;
case 'order_cause' :
if ($dataInfo['receipt_type'] == '销售退货入库') {
if($dataInfo['receipt_type'] == '销售退货入库'){
$val = db('jxc_salereturn')->where(['salereturn_id' => $val])->value('order_number');
} elseif ($dataInfo['receipt_type'] == '采购入库') {
}elseif ($dataInfo['receipt_type'] == '采购入库') {
$val = db('jxc_purchase')->where(['purchase_id' => $val])->value('order_number');
} elseif ($dataInfo['outbound_type'] == '销售出库') {
}elseif ($dataInfo['outbound_type'] == '销售出库') {
$val = db('jxc_sale')->where(['sale_id' => $val])->value('order_number');
} elseif ($dataInfo['outbound_type'] == '采购退货出库') {
}elseif ($dataInfo['outbound_type'] == '采购退货出库') {
$val = db('jxc_retreat')->where(['retreat_id' => $val])->value('order_number');
}
break;
@ -2362,13 +2359,13 @@ class Field extends Model
$val = db('jxc_product')->where(['product_id' => $val])->value('product_name');
break;
case 'collection_object' :
if ($dataInfo['collection_type'] == '采购退货') {
if($dataInfo['collection_type'] == '采购退货'){
// $val = db('jxc_supplier')->where(['supplier_id' => $val])->value('supplier_name');
} elseif ($dataInfo['collection_type'] == '销售出库') {
}elseif ($dataInfo['collection_type'] == '销售出库') {
$val = db('jxc_sale')->where(['sale_id' => $val])->value('order_number');
} elseif ($dataInfo['payment_type'] == '采购') {
}elseif ($dataInfo['payment_type'] == '采购') {
$val = db('crm_customer')->where(['customer_id' => $val])->value('name');
} elseif ($dataInfo['payment_type'] == '销售退货') {
}elseif ($dataInfo['payment_type'] == '销售退货') {
$val = db('jxc_salereturn')->where(['salereturn_id' => $val])->value('order_number');
}
@ -2419,13 +2416,13 @@ class Field extends Model
}
if (!$data) return $data;
$list = db('admin_field')->where(['types' => $types, 'relevant' => ['neq', '']])->field('field,relevant')->select();
foreach ($list as &$val) {
$val = !empty($val) ? $val : '';
foreach ($list as &$val){
$val=!empty($val)?$val:'';
}
$newData = [];
//crm_hfsomz
foreach ($list as $k => $v) {
$customer_field = db('admin_field')->where(['types' => 'crm_customer', 'field_id' => $v['relevant']])->field('field')->find();
$customer_field=db('admin_field')->where(['types' => 'crm_customer', 'field_id' => $v['relevant']])->field('field')->find();
$newData[$customer_field['field']] = $data[$v['field']];
}
return $newData ?: [];
@ -2673,7 +2670,7 @@ class Field extends Model
*/
public function getFieldTypesArray($types, $form_type)
{
$fieldArr = db('admin_field')->where(['types' => $types, 'form_type' => ['in', $form_type]])->field(['field', 'name', 'form_type'])->select();
$fieldArr = db('admin_field')->where(['types' => $types, 'form_type' => ['in', $form_type]])->field(['field','name', 'form_type'])->select();
$fieldList = [];
$userField = []; // 人员类型
$structureField = []; // 部门类型

@ -278,22 +278,6 @@ class Message extends Common
* 客户待审批
*/
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 +389,6 @@ class Message extends Common
32 => [
'template' => '{from_user} 将您添加为线索 {title} 的成员。',
],
63 => [
'template' => '{from_user} 创建了新的商机',
]
];
/**
@ -458,10 +439,6 @@ class Message extends Common
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,
@ -603,6 +580,7 @@ class Message extends Common
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 +610,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,
@ -394,128 +390,128 @@ function advancedQuery($param, $m = '', $c = '', $a = '')
// 创建人、负责人
if (in_array($key, ['create_user_id', 'owner_user_id'])) {
if ($value['condition'] == 'contains') {
if($value['condition'] == 'contains'){
$result[$c . $key] = ['in', $value['value']];
} else if ($value['condition'] == 'notContains') {
}else if ($value['condition'] == 'notContains') {
$result[$c . $key] = ['not in', $value['value']];
} else if ($value['condition'] == 'isNull') {
}else if ($value['condition'] == 'isNull') {
$result[$c . $key] = ['eq', ''];
} else if ($value['condition'] == 'isNotNull') {
}else if ($value['condition'] == 'isNotNull') {
$result[$c . $key] = ['neq', ''];
}
}
// 模块、审核状态、成交状态、产品分类、单行文本、多行文本、网址、手机、邮箱、下拉框、布尔值、多选、定位、创建人、负责人
if (isset($value['form_type']) && in_array($value['form_type'], ['module', 'check_status', 'deal_status', 'category', 'text', 'textarea', 'mobile', 'email', 'select', 'boolean_value', 'checkbox', 'location', 'website', 'user',])) {
if (isset($value['form_type']) && in_array($value['form_type'], ['module', 'check_status', 'deal_status', 'category', 'text', 'textarea', 'mobile', 'email', 'select', 'boolean_value', 'checkbox', 'location', 'website','user',])) {
$res = advancedQueryFormatForCommon($value['value'], $value['condition'], $value['form_type'], $key);
if ($key == 'order_id') {
if($key == 'order_id'){
$arr = [];
if ($c == 'outbound.') {
if($c == 'outbound.'){
$retreatOutboundIds = db('jxc_retreat')
->alias('a')
->join('jxc_outbound b', 'a.retreat_id = b.order_id')
->join('jxc_outbound b','a.retreat_id = b.order_id')
->where('a.order_number', [$res[0], $res[1]])
->where('b.outbound_type', '采购退货出库')
// ->fetchSql()
->column('outbound_id');
$saleOutboundIds = db('jxc_sale')
->alias('a')
->join('jxc_outbound b', 'a.sale_id = b.order_id')
->join('jxc_outbound b','a.sale_id = b.order_id')
->where('a.order_number', [$res[0], $res[1]])
->where('b.outbound_type', '销售出库')
// ->fetchSql()
->column('outbound_id');
$arr = empty($retreatOutboundIds) ? $saleOutboundIds : array_merge($retreatOutboundIds, $saleOutboundIds);
$arr = empty($retreatOutboundIds) ? $saleOutboundIds : array_merge($retreatOutboundIds,$saleOutboundIds);
$result[$c . 'outbound_id'] = ['in', $arr];
} elseif ($c == 'receipt.') {
}elseif ($c == 'receipt.') {
$purchaseOutboundIds = db('jxc_purchase')
->alias('a')
->join('jxc_receipt b', 'a.purchase_id = b.order_id')
->join('jxc_receipt b','a.purchase_id = b.order_id')
->where('a.order_number', [$res[0], $res[1]])
->where('b.receipt_type', '采购入库')
// ->fetchSql()
->column('b.receipt_id');
$salereturnOutboundIds = db('jxc_salereturn')
->alias('a')
->join('jxc_receipt b', 'a.salereturn_id = b.order_id')
->join('jxc_receipt b','a.salereturn_id = b.order_id')
->where('a.order_number', [$res[0], $res[1]])
->where('b.receipt_type', '销售退货入库')
// ->fetchSql()
->column('b.receipt_id');
$arr = empty($purchaseOutboundIds) ? $salereturnOutboundIds : array_merge($purchaseOutboundIds, $salereturnOutboundIds);
$arr = empty($purchaseOutboundIds) ? $salereturnOutboundIds : array_merge($purchaseOutboundIds,$salereturnOutboundIds);
$result[$c . 'receipt_id'] = ['in', $arr];
}
} else if ($key == 'related_id') {
}else if($key == 'related_id'){
$arr = [];
if ($c == 'collection.') {
if($c == 'collection.'){
$retreatOutboundIds = db('jxc_retreat')
->alias('a')
->join('jxc_collection b', 'a.retreat_id = b.related_id')
->join('jxc_collection b','a.retreat_id = b.related_id')
->where('a.order_number', [$res[0], $res[1]])
->where('b.collection_type', '采购退货')
// ->fetchSql()
->column('collection_note_id');
$saleOutboundIds = db('jxc_sale')
->alias('a')
->join('jxc_collection b', 'a.sale_id = b.related_id')
->join('jxc_collection b','a.sale_id = b.related_id')
->where('a.order_number', [$res[0], $res[1]])
->where('b.collection_type', '销售回款')
// ->fetchSql()
->column('collection_note_id');
$arr = empty($retreatOutboundIds) ? $saleOutboundIds : array_merge($retreatOutboundIds, $saleOutboundIds);
$arr = empty($retreatOutboundIds) ? $saleOutboundIds : array_merge($retreatOutboundIds,$saleOutboundIds);
$result[$c . 'collection_note_id'] = ['in', $arr];
} elseif ($c == 'payment.') {
}elseif ($c == 'payment.') {
$purchaseOutboundIds = db('jxc_purchase')
->alias('a')
->join('jxc_payment b', 'a.purchase_id = b.related_id')
->join('jxc_payment b','a.purchase_id = b.related_id')
->where('a.order_number', [$res[0], $res[1]])
->where('b.payment_type', '采购')
// ->fetchSql()
->column('b.payment_note_id');
$salereturnOutboundIds = db('jxc_salereturn')
->alias('a')
->join('jxc_payment b', 'a.salereturn_id = b.related_id')
->join('jxc_payment b','a.salereturn_id = b.related_id')
->where('a.order_number', [$res[0], $res[1]])
->where('b.payment_type', '销售退货')
// ->fetchSql()
->column('b.payment_note_id');
$arr = empty($purchaseOutboundIds) ? $salereturnOutboundIds : array_merge($purchaseOutboundIds, $salereturnOutboundIds);
$arr = empty($purchaseOutboundIds) ? $salereturnOutboundIds : array_merge($purchaseOutboundIds,$salereturnOutboundIds);
$result[$c . 'payment_note_id'] = ['in', $arr];
}
} else if ($key == 'collection_object') {
}else if($key == 'collection_object'){
$arr = [];
if ($c == 'collection.') {
if($c == 'collection.'){
$supplierOutboundIds = db('jxc_supplier')
->alias('a')
->join('jxc_collection b', 'a.supplier_id = b.collection_object')
->join('jxc_collection b','a.supplier_id = b.collection_object')
->where('a.supplier_name', [$res[0], $res[1]])
->where('b.collection_type', '采购退货')
// ->fetchSql()
->column('collection_note_id');
$customerOutboundIds = db('crm_customer')
->alias('a')
->join('jxc_collection b', 'a.customer_id = b.collection_object')
->join('jxc_collection b','a.customer_id = b.collection_object')
->where('a.name', [$res[0], $res[1]])
->where('b.collection_type', '销售回款')
// ->fetchSql()
->column('collection_note_id');
$arr = empty($supplierOutboundIds) ? $customerOutboundIds : array_merge($supplierOutboundIds, $customerOutboundIds);
$arr = empty($supplierOutboundIds) ? $customerOutboundIds : array_merge($supplierOutboundIds,$customerOutboundIds);
$result[$c . 'collection_note_id'] = ['in', $arr];
} elseif ($c == 'payment.') {
}elseif ($c == 'payment.') {
$supplierOutboundIds = db('jxc_supplier')
->alias('a')
->join('jxc_payment b', 'a.supplier_id = b.collection_object')
->join('jxc_payment b','a.supplier_id = b.collection_object')
->where('a.supplier_name', [$res[0], $res[1]])
->where('b.payment_type', '采购')
// ->fetchSql()
->column('b.payment_note_id');
$customerOutboundIds = db('crm_customer')
->alias('a')
->join('jxc_payment b', 'a.customer_id = b.collection_object')
->join('jxc_payment b','a.customer_id = b.collection_object')
->where('a.name', [$res[0], $res[1]])
->where('b.payment_type', '销售退货')
// ->fetchSql()
->column('b.payment_note_id');
$arr = empty($supplierOutboundIds) ? $customerOutboundIds : array_merge($supplierOutboundIds, $customerOutboundIds);
$arr = empty($supplierOutboundIds) ? $customerOutboundIds : array_merge($supplierOutboundIds,$customerOutboundIds);
$result[$c . 'payment_note_id'] = ['in', $arr];
}
// }else if($key == 'sp_data_value'){
@ -525,7 +521,7 @@ function advancedQuery($param, $m = '', $c = '', $a = '')
// $w['sp_data_value'] = ['like', $arr, 'OR'];
// $product_ids = db('jxc_product')->where($w)->fetchSql()->column('product_id');
// $result[$c . 'sp_data_value'] = [$res[0], $product_ids];
} else {
}else{
$result[$c . $key] = advancedQueryFormatForCommon($value['value'], $value['condition'], $value['form_type'], $key);
}
}
@ -733,9 +729,9 @@ function advancedQueryFormatForCommon($data, $condition, $formType, $key)
if (in_array($formType, ['checkbox']) && $condition == 'isNot') $condition = 'notContains';
// 处理查询参数
if (in_array($condition, ['contains', 'notContains']) && in_array($key, ['create_user_id', 'owner_user_id'])) {
if(in_array($condition, ['contains', 'notContains']) && in_array($key,['create_user_id','owner_user_id'])){
$data = advancedQueryDataUserform($data, $condition);
} elseif (in_array($condition, ['contains', 'notContains', 'startWith', 'endWith'])) {
}elseif (in_array($condition, ['contains', 'notContains', 'startWith', 'endWith'])){
$data = advancedQueryDataTransform($data, $condition);
}
@ -757,7 +753,7 @@ function advancedQueryFormatForCommon($data, $condition, $formType, $key)
$data[0] = str_replace('已作废', 6, $data[0]);
}
return advancedQueryWhere($condition, $data, $key);
return advancedQueryWhere($condition, $data,$key);
}
/**
@ -769,7 +765,7 @@ function advancedQueryFormatForCommon($data, $condition, $formType, $key)
* @since 2021-05-22
* @author fanqi
*/
function advancedQueryWhere($condition, $data, $key = '')
function advancedQueryWhere($condition, $data, $key='')
{
$result = [];
@ -778,9 +774,9 @@ function advancedQueryWhere($condition, $data, $key = '')
if ($condition == "in") $result = ['in', $data]; // 等于
if ($condition == 'is') $result = ['in', $data]; // 等于
if ($condition == 'isNot') $result = [['notin', $data], ['null'], 'OR']; // 不等于
if ($condition == 'isNot') $result = [['notin', $data],['null'],'OR']; // 不等于
if ($condition == 'contains') $result = ['like', $data, 'OR']; // 包含
if ($condition == 'notContains') $result = [['notlike', $data, 'AND'], ['null'], 'OR']; // 不包含
if ($condition == 'notContains') $result = [['notlike', $data, 'AND'],['null'],'OR']; // 不包含
if ($condition == 'startWith') $result = ['like', $data, 'OR']; // 开始于
if ($condition == 'endWith') $result = ['like', $data, 'OR']; // 结束于
if ($condition == 'gt') $result = ['gt', $data]; // 大于
@ -791,8 +787,8 @@ function advancedQueryWhere($condition, $data, $key = '')
if ($condition == 'range') $result = ['between', $data]; // 处于某个时间段
if ($condition == 'isNull') $result = [['eq', ''], ['null'], 'OR']; // 为空
if ($condition == 'isNotNull') $result = [['neq', ''], ['not null'], 'AND']; // 不为空
if ($condition == 'contains' && in_array($key, ['create_user_id', 'owner_user_id'])) $result = ['in', $data]; // 暂定为创建人 负责人 包含
if ($condition == 'notContains' && in_array($key, ['create_user_id', 'owner_user_id'])) $result = ['notin', $data]; // 暂定为创建人 负责人不包含
if ($condition == 'contains' && in_array($key,['create_user_id','owner_user_id'])) $result = ['in', $data]; // 暂定为创建人 负责人 包含
if ($condition == 'notContains' && in_array($key,['create_user_id','owner_user_id'])) $result = ['notin', $data]; // 暂定为创建人 负责人不包含
return $result;
}
@ -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;
}
/**
* 等于(时间段)数据处理
*
@ -2897,7 +2891,7 @@ if (!function_exists('getFieldGrantStatus')) {
function getFieldGrantStatus($field, $grantData)
{
# 默认状态都是不能查看、不能编辑,通过配置来取最大权限。
$result = ['read' => 0, 'write' => 0, 'maskType' => 0];
$result = ['read' => 0, 'write' => 0,'maskType'=>0];
foreach ($grantData as $key => $value) {
$fieldBool = false;
@ -2912,7 +2906,7 @@ if (!function_exists('getFieldGrantStatus')) {
$result['write'] = $va['write'] > $result['write'] ? $va['write'] : $result['write'];
}
if ($va['field'] == $field && $va['maskType'] != 0) {
$result['maskType'] = !empty($va['maskType']) ? $va['maskType'] : 0;
$result['maskType'] = !empty($va['maskType'])?$va['maskType']:0;
}
if ($va['field'] == $field) $fieldBool = true;
}
@ -3307,50 +3301,50 @@ function advancedQueryFormatForTeam($requestMap, $c, $db_id)
// $result[$c . 'rw_user_id'] = advancedQueryFormatForPersonnel($v['value'], $v['condition']);
// }
// }
$date = [];
$date2 = [];
$condition = $requestMap['condition'];
$z = '';
foreach ($requestMap['value'] as $val) {
if ($condition == 'contains') {
$z = 'like';
$val = "'" . '%,' . $val . ',%' . "'";
} elseif ($condition == 'notContains') {
$z = 'NOT LIKE';
$val = "'" . '%,' . $val . ',%' . "'";
}
$date[] = $prefix . 'ro_user_id ' . $z . $val;
$date2[] = $prefix . 'rw_user_id ' . $z . $val;
}
if ($condition == 'isNull') {
$z = 'IS NULL';
$date[] = $prefix . 'ro_user_id ' . '= ' . "''";
$date2[] = $prefix . 'rw_user_id ' . '= ' . "''";
} elseif ($condition == 'isNotNull') {
$z = 'IS NOT NULL';
$date[] = $prefix . 'ro_user_id ' . '<> ' . "''";
$date2[] = $prefix . 'rw_user_id ' . '<> ' . "''";
}
if ($date && $date2) {
$rest = '';
$date = implode('OR ', $date);
$date2 = implode('OR ', $date2);
$type = '';
switch ($z) {
$date=[];
$date2=[];
$condition=$requestMap['condition'];
$z='';
foreach ($requestMap['value'] as $val){
if($condition=='contains'){
$z='like';
$val="'".'%,'.$val.',%'."'";
}elseif($condition=='notContains'){
$z='NOT LIKE';
$val="'".'%,'.$val.',%'."'";
}
$date[]=$prefix.'ro_user_id '.$z.$val;
$date2[]=$prefix.'rw_user_id '.$z.$val;
}
if($condition =='isNull'){
$z='IS NULL';
$date[]=$prefix.'ro_user_id '.'= '."''";
$date2[]=$prefix.'rw_user_id '.'= '."''";
}elseif($condition =='isNotNull'){
$z='IS NOT NULL';
$date[]=$prefix.'ro_user_id '.'<> '."''";
$date2[]=$prefix.'rw_user_id '.'<> '."''";
}
if($date && $date2){
$rest='';
$date=implode('OR ', $date);
$date2=implode('OR ', $date2);
$type='';
switch ($z){
case 'like':
$rest = '(' . $date . ')' . 'OR' . '(' . $date2 . ')';
$rest='('.$date.')'.'OR'.'('.$date2.')';
break;
case 'NOT LIKE':
$rest = '(' . $date . ')' . 'AND' . '(' . $date2 . ')';
$rest='('.$date.')'.'AND'.'('.$date2.')';
break;
case 'IS NULL':
$rest = '(' . $date . ')' . 'OR' . '(' . $date2 . ')';
$rest='('.$date.')'.'OR'.'('.$date2.')';
break;
case 'IS NOT NULL':
$rest = '(' . $date . ')' . 'AND' . '(' . $date2 . ')';
$rest='('.$date.')'.'AND'.'('.$date2.')';
break;
default:
break;
@ -3369,15 +3363,15 @@ function advancedQueryFormatForTeam($requestMap, $c, $db_id)
*/
function getUserSuperior($structure_id, $level = 0)
{
if ($level == 0) {
if($level == 0){
$owner_user_id = db('admin_structure')->where('id', $structure_id)->value('owner_user_id');
if ($owner_user_id == 0) {
if($owner_user_id == 0){
$pid = db('admin_structure')->where('id', $structure_id)->value('pid');
$owner_user_id = db('admin_structure')->where('id', $pid)->value('owner_user_id');
}
} else {
}else{
$pid = db('admin_structure')->where('id', $structure_id)->value('pid');
return getUserSuperior($pid, $level - 1);
return getUserSuperior($pid, $level-1);
}
return $owner_user_id;

@ -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,
@ -821,9 +628,24 @@ class Business extends ApiCommon
'customer_ids' => ',' . $businessInfo['customer_id'] . ','
]);
# 删除待办事项的关联数据
db('crm_dealt_relation')->where(['types' => ['eq', 'crm_business'], 'types_id' => ['eq', $data['business_id']]])->delete();
# 创建待办事项的关联数据
$checkUserIds = db('crm_business')->where('business_id', $data['business_id'])->value('check_user_id');
$checkUserIdArray = stringToArray($checkUserIds);
$dealtData = [];
foreach ($checkUserIdArray AS $kk => $vv) {
$dealtData[] = [
'types' => 'crm_business',
'types_id' => $data['business_id'],
'user_id' => $vv
];
}
if (!empty($dealtData)) db('crm_dealt_relation')->insertAll($dealtData);
//推进记录添加
$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 +662,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,43 +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['status']==1){
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/');
}
}

@ -31,7 +31,7 @@ class Customer extends ApiCommon
{
$action = [
'permission' => ['exceldownload', 'setfollow', 'delete'],
'allow' => ['read', 'system', 'count', 'poolauthority', 'level','type']
'allow' => ['read', 'system', 'count', 'poolauthority', 'level']
];
Hook::listen('check_auth', $action);
$request = Request::instance();
@ -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 = [];
@ -903,7 +883,7 @@ class Customer extends ApiCommon
*/
public function top()
{
$customerModel = model('Customer');
$customerModel=model('Customer');
$param = $this->param;
$userInfo = $this->userInfo;
$param['create_role_id'] = $userInfo['id'];
@ -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]);
}
}

@ -43,8 +43,7 @@ class CustomerPool extends ApiCommon
'setfieldconfig',
'exceldownload',
'import',
'export',
'checkCustomerReveive'
'export'
]
];
Hook::listen('check_auth', $action);
@ -352,38 +351,38 @@ class CustomerPool extends ApiCommon
*/
public function fieldsData($param)
{
$where = ['pool_id' => $param['pool_id'], 'is_hidden' => 0,
'field_name' => ['not in', ['deal_status', 'create_user_id']]];
if ($param['is_excel'] == 1) {
$where = ['pool_id' => $param['pool_id'], 'is_hidden' => 0,
$where=['pool_id' => $param['pool_id'], 'is_hidden' => 0,
'field_name' => ['not in', ['deal_status','create_user_id']]];
if($param['is_excel']==1){
$where=['pool_id' => $param['pool_id'], 'is_hidden' => 0,
'field_name' => ['not in', ['deal_status']]];
}
$pool_list = db('crm_customer_pool_field_setting')->where($where)->field('field_name as field,form_type,name')->select();
$fieldParam['types'] = 'crm_customer';
$fieldParam['action'] = 'excel';
$setting = [];
$list = [];
$list=[];
foreach ($pool_list as $k => &$v) {
switch ($v['field']) {
case 'address':
if ($param['is_excel'] != 1) {
if($param['is_excel']!=1){
$v['field'] = 'customer_address';
$v['form_type'] = 'map_address';
$list[] = $v;
$list[]=$v;
unset($pool_list[$k]);
}
break;
case 'detail_address':
if ($param['is_excel'] != 1) {
if($param['is_excel']!=1){
unset($pool_list[$k]);
}
break;
case ($v['form_type'] == 'select') || ($v['form_type'] == 'checkbox') :
$set = db('admin_field')->where(['types' => 'crm_customer', 'field' => $v['field']])->find();
$set= db('admin_field')->where(['types' => 'crm_customer', 'field' => $v['field']])->find();
$pool_list[$k]['setting'] = explode(chr(10), $set['setting']);
break;
default :
if ($param['is_excel'] != 1) {
if($param['is_excel']!=1){
$pool_list[$k]['setting'] = [];
}
break;
@ -398,7 +397,7 @@ class CustomerPool extends ApiCommon
// }
// }
}
$pool_list = array_merge($pool_list, $list);
$pool_list=array_merge($pool_list,$list);
return $pool_list;
}
@ -424,11 +423,11 @@ class CustomerPool extends ApiCommon
$customerCheckData['update_time'] = time();
$customerCheckData['check_status'] = 1; //0待审核1审核通中2审核通过3审核未通过
//权限判断
if (!$examineStepModel->checkExamine($user_id, 'crm_customer_check', $param['id'])) {
if (!$examineStepModel->checkExamine($user_id, 'crm_contract', $param['id'])) {
return resultArray(['error' => $examineStepModel->getError()]);
}
//审批主体详情
$dataInfo = db('crm_customer_check')->where('customer_check_id', 'in', $param['id'])->find();
$dataInfo = db('crm_customer_check')->where('customer_check_id', 'in', $param['customer_check_id'])->find();
$flowInfo = $examineFlowModel->getDataById($dataInfo['flow_id']);
$is_end = 0; // 1审批结束
@ -440,7 +439,7 @@ class CustomerPool extends ApiCommon
$checkData['check_time'] = time();
$checkData['content'] = $param['content'];
$checkData['flow_id'] = $dataInfo['flow_id'];
$checkData['order_id'] = $dataInfo['order_id'] ?: 1;
$checkData['order_id'] = $dataInfo['order_id'] ? : 1;
$checkData['status'] = $status;
if ($status == 1) {
@ -448,8 +447,8 @@ class CustomerPool extends ApiCommon
//固定流程
//获取下一审批信息
$nextStepData = $examineStepModel->nextStepUser($dataInfo['owner_user_id'], $dataInfo['flow_id'], 'crm_customer_check', $param['id'], $dataInfo['order_id'], $user_id);
$next_user_ids = $nextStepData['next_user_ids'] ?: [];
$customerCheckData['order_id'] = $nextStepData['order_id'] ?: '';
$next_user_ids = $nextStepData['next_user_ids'] ? : [];
$customerCheckData['order_id'] = $nextStepData['order_id'] ? : '';
if (!$next_user_ids) {
$is_end = 1;
//审批结束
@ -462,7 +461,7 @@ class CustomerPool extends ApiCommon
} else {
//自选流程
$is_end = $param['is_end'] ? 1 : '';
$check_user_id = $param['check_user_id'] ?: '';
$check_user_id = $param['check_user_id'] ? : '';
if ($is_end !== 1 && empty($check_user_id)) {
return resultArray(['error' => '请选择下一审批人']);
}
@ -481,7 +480,7 @@ class CustomerPool extends ApiCommon
// $examineRecordModel->setEnd(['types' => 'crm_contract','types_id' => $param['id']]);
}
//已审批人ID
$customerCheckData['flow_user_id'] = stringToArray($dataInfo['flow_user_id']) ? arrayToString(array_merge(stringToArray($dataInfo['flow_user_id']), [$user_id])) : arrayToString([$user_id]);
$customerCheckData['flow_user_id'] = stringToArray($dataInfo['flow_user_id']) ? arrayToString(array_merge(stringToArray($dataInfo['flow_user_id']),[$user_id])) : arrayToString([$user_id]);
$resCustomerCheck = db('crm_customer_check')->where(['customer_check_id' => $param['id']])->update($customerCheckData);
if ($resCustomerCheck) {
//审批记录
@ -490,7 +489,7 @@ class CustomerPool extends ApiCommon
if ($is_end == 1 && !empty($status)) {
// 审批通过消息告知负责人
(new Message())->send(
Message::CUSTOMER_CHECK_PASS,
Message::CONTRACT_PASS,
[
'title' => $dataInfo['name'],
'action_id' => $param['id']
@ -499,8 +498,8 @@ class CustomerPool extends ApiCommon
);
$customerData = [];
$customerData['user_id'] = $dataInfo['user_id'];
$customerData['customer_id'] = $dataInfo['customer_id'];
$customerData['user_id']=$dataInfo['user_id'];
$customerData['customer_id']=$dataInfo['customer_id'];
$result = (new CustomerPoolLogic())->receiveCustomers($customerData);
@ -536,20 +535,4 @@ class CustomerPool extends ApiCommon
return resultArray(['error' => '审批失败,请重试!']);
}
}
/**
* 总经理公海池消息提醒
*
* @return Json
* @since 2021-04-14
* @author fanqi
*/
public function num()
{
$customerPoolCount = db('crm_customer_pool_relation')->where("pool_id",array('eq',3))
->count();
return resultArray(['data' => $customerPoolCount]);
}
}

@ -102,18 +102,18 @@ class Index extends ApiCommon
$userInfo = $this->userInfo;
$adminModel = new \app\admin\model\Admin();
$status = $param['label'] ?: 1; //1合同目标2回款目标
$userWhere['type'] = 3;
$userWhere['status'] = $param['label'];
$userWhere['type']=3;
$userWhere['status']=$param['label'];
$userIds = [];
if ($param['dataType'] == 3 || $param['dataType'] == 4) {
$param['structure_id'] = $userInfo['structure_id'];
$userWhere['type'] = 2;
$userWhere['type']=2;
}
$whereArr = $adminModel->getWhere($param, 1, '');
if ($param['user_id']) {
$userWhere['type'] = 3;
} elseif ($param['structure_id']) {
$userWhere['type'] = 2;
if($param['user_id']){
$userWhere['type']=3;
}elseif ($param['structure_id']){
$userWhere['type']=2;
}
$param['user_id'] = $param['user_id'] ?: $userInfo['id'];
if ($param['dataType'] == 1) {
@ -128,12 +128,12 @@ class Index extends ApiCommon
$end_time = $between_time[1];
} else {
//自定义时间
$start_time = $param['start_time'] ? strtotime($param['start_time'] . '00:00:00') : strtotime(date('Y-01-01', time()));
$end_time = $param['end_time'] ? strtotime($param['end_time'] . '23:59:59') : strtotime(date('Y-m-01', time()) . ' +1 month -1 day');
$start_time = $param['start_time'] ?strtotime($param['start_time'].'00:00:00'): strtotime(date('Y-01-01', time()));
$end_time = $param['end_time'] ? strtotime($param['end_time'].'23:59:59') : strtotime(date('Y-m-01', time()) . ' +1 month -1 day');
$between_time = array($start_time, $end_time);
}
if ($param['label'] == 1) {
if($param['label']==1){
//合同金额
$where_contract = $where;
$where_contract['order_date'] = array('between', [date('Y-m-d', $between_time[0]), date('Y-m-d', $between_time[1])]);
@ -144,7 +144,7 @@ class Index extends ApiCommon
->fetchSql()
->select();
$contractMoney = queryCache($sql, 200);
} else {
}else{
//回款金额
$where_receivables = $where;
$where_receivables['return_time'] = array('between', [date('Y-m-d', $between_time[0]), date('Y-m-d', $between_time[1])]);
@ -214,21 +214,11 @@ class Index extends ApiCommon
$param['user_id'] = $param['user_id'] ?: $userInfo['id'];;
$businessModel = new \app\crm\model\Business();
$param['merge'] = 1;
if ($param['start_time'] && $param['end_time']) {
$param['start_time'] = $param['start_time'] . ' 00:00:00';
$param['end_time'] = $param['end_time'] . ' 23:59:59';
if($param['start_time'] && $param['end_time']){
$param['start_time']=$param['start_time'].' 00:00:00';
$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]);
}
@ -244,27 +234,27 @@ class Index extends ApiCommon
//统计条件
$param = $this->param;
$userInfo = $this->userInfo;
$userWhere['status'] = $param['label'];
$userWhere['status']=$param['label'];
if ($param['dataType'] == 3 || $param['dataType'] == 4) {
$userWhere['type'] = 2;
} else {
$userWhere['type'] = 3;
$userWhere['type']=2;
}else{
$userWhere['type']=3;
}
if ($param['type']) {
$last_where_contract = getTimeByType($param['type']);
$userWhere['year'] = date('Y', $last_where_contract[0]);
$userWhere['year']=date('Y',$last_where_contract[0]);
$time = getTimeArray();
} else {
//自定义时间
$param['start_time'] = $param['start_time'] ? $param['start_time'] . ' 00:00:00' : 0;
$param['end_time'] = $param['end_time'] . ' 23:59:59';
$time = getTimeArray(strtotime($param['start_time']), strtotime($param['end_time']));
$param['start_time']=$param['start_time']?$param['start_time'].' 00:00:00':0;
$param['end_time']=$param['end_time'].' 23:59:59';
$time = getTimeArray(strtotime($param['start_time']),strtotime($param['end_time']));
}
$whereArr = $adminModel->getWhere($param, 1, '');
if ($param['user_id']) {
$userWhere['type'] = 3;
} elseif ($param['structure_id']) {
$userWhere['type'] = 2;
if($param['user_id']){
$userWhere['type']=3;
}elseif ($param['structure_id']){
$userWhere['type']=2;
}
$userIds = $whereArr['userIds'];
if (!empty($param['user_id'])) {
@ -281,7 +271,7 @@ class Index extends ApiCommon
$auth_customer_user_ids = $auth_customer_user_ids ? array_intersect($userIds, $auth_customer_user_ids) : []; //取交集
$between_time = [date('Y-m-d', $whereArr['between_time'][0]), date('Y-m-d', $whereArr['between_time'][1])];
if ($param['label'] == 1) {
if($param['label']==1){
$field_contract["SUBSTR(`order_date`, 1, " . $ax . ")"] = 'type';
$field_contract['SUM(`money`)'] = 'sum';
$achievementData = CrmContractModel::field($field_contract)
@ -296,7 +286,7 @@ class Index extends ApiCommon
$res_contract = queryCache($achievementData, 200);
$res_money = array_column($res_contract, null, 'type');
} else {
}else{
$field_receivables["SUBSTR(`return_time`, 1, " . $ax . ")"] = 'type';
$field_receivables['SUM(`money`)'] = 'sum';
@ -319,20 +309,20 @@ class Index extends ApiCommon
foreach ($time['list'] as $val) {
$item = [];
$item['type'] = date('m-d', strtotime($val['type']));
$item['type'] = date('m-d',strtotime($val['type']));
$item['money'] = $res_money[$val['type']]['sum'] ?: 0;
$money += $item['money'];
$achievement = Db::name('crm_achievement')->where($userWhere)->select();
$data_time = date('m', strtotime($val['type']));
$num = '';
if ($achievement) {
foreach ($achievement as $val) {
$num += (int)$val[$this->monthName[$data_time]];
$item['achievement'] = $num;
$achievement=Db::name('crm_achievement')->where($userWhere)->select();
$data_time=date('m',strtotime($val['type']));
$num='';
if($achievement){
foreach ($achievement as $val){
$num+=(int)$val[$this->monthName[$data_time]];
$item['achievement']=$num;
}
} else {
$item['achievement'] = 0;
}else{
$item['achievement']=0;
}
$list[] = $item;
}
@ -351,9 +341,9 @@ class Index extends ApiCommon
{
$param = $this->param;
$adminModel = new \app\admin\model\Admin();
if ($param['start_time'] && $param['end_time']) {
$param['start_time'] = $param['start_time'] . '00:00:00';
$param['end_time'] = $param['end_time'] . '23:59:59';
if($param['start_time'] && $param['end_time']){
$param['start_time']=$param['start_time'].'00:00:00';
$param['end_time']=$param['end_time'].'23:59:59';
}
$whereArr = $adminModel->getWhere($param, '', ''); //统计条件
$userIds = $whereArr['userIds'];
@ -550,10 +540,10 @@ class Index extends ApiCommon
$label = $param['label'];
$types = $param['types'];
$userInfo = $this->userInfo;
$user_id = $param['user_id'] ?: $userInfo['id'];
if ($param['start_time'] && $param['end_time']) {
$param['start_time'] = $param['start_time'] . ' 00:00:00';
$param['end_time'] = $param['end_time'] . ' 23:59:59';
$user_id = $param['user_id'] ? : $userInfo['id'];
if($param['start_time'] && $param['end_time']){
$param['start_time']=$param['start_time'].' 00:00:00';
$param['end_time']=$param['end_time'].' 23:59:59';
}
$whereArr = $adminModel->getWhere($param, 1, ''); //统计条件
$userIds = $whereArr['userIds'];
@ -609,8 +599,8 @@ class Index extends ApiCommon
if ($c != 'activity') {
$where['owner_user_id']['value'] = $auth_user_ids;
if ($types == 'crm_contract' || $types == 'crm_receivables') {
$where['check_status'] = 2;
if($types=='crm_contract' || $types=='crm_receivables'){
$where['check_status']=2;
}
$data = $model->getDataList($where);
} else {
@ -623,21 +613,21 @@ class Index extends ApiCommon
foreach ($typesList as $k => $v) {
$where1['activity_type'] = $v;
$dataCount = db('crm_activity')->where($where1)->count();
if ($v == 1) {
$arr[$k]['types'] = 'crm_leads';
$arr[$k]['activity_type'] = 1;
} elseif ($v == 2) {
$arr[$k]['types'] = 'crm_customer';
$arr[$k]['activity_type'] = 2;
} elseif ($v == 3) {
$arr[$k]['types'] = 'crm_contacts';
$arr[$k]['activity_type'] = 3;
} elseif ($v == 5) {
$arr[$k]['types'] = 'crm_business';
$arr[$k]['activity_type'] = 5;
} elseif ($v == 6) {
$arr[$k]['types'] = 'crm_contract';
$arr[$k]['activity_type'] = 6;
if($v==1){
$arr[$k]['types'] ='crm_leads';
$arr[$k]['activity_type'] =1;
}elseif ($v==2){
$arr[$k]['types'] ='crm_customer';
$arr[$k]['activity_type'] =2;
}elseif ($v==3){
$arr[$k]['types'] ='crm_contacts';
$arr[$k]['activity_type'] =3;
}elseif ($v==5){
$arr[$k]['types'] ='crm_business';
$arr[$k]['activity_type'] =5;
}elseif ($v==6){
$arr[$k]['types'] ='crm_contract';
$arr[$k]['activity_type'] =6;
}
$arr[$k]['dataCount'] = $dataCount;
$arr[$k]['create_user_id'] = implode(',', $userIds);
@ -683,7 +673,7 @@ class Index extends ApiCommon
{
$param = $this->param;
$userInfo = $this->userInfo;
$param['user_id'] = $param['user_id'] ?: $userInfo['id'];
$param['user_id'] = $param['user_id']?:$userInfo['id'];
$indexModel = new IndexLogic;
$data = $indexModel->ranking($param);
return resultArray(['data' => $data]);
@ -697,7 +687,7 @@ class Index extends ApiCommon
{
$param = $this->param;
$userInfo = $this->userInfo;
$param['user_id'] = $param['user_id'] ?: $userInfo['id'];
$param['user_id'] = $param['user_id']?:$userInfo['id'];
$indexModel = new IndexLogic;
$data = $indexModel->queryDataInfo($param);
return resultArray(['data' => $data]);
@ -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,13 +754,12 @@ class Index extends ApiCommon
* 跟进详情
* @return \think\response\Json
*/
public function activityList()
{
public function activityList(){
$param = $this->param;
$userInfo = $this->userInfo;
$param['id'] = $userInfo['id'];
$indexLogic = new IndexLogic();
$data = $indexLogic->activityList($param);
return resultArray(['data' => $data]);
$param['id']=$userInfo['id'];
$indexLogic=new IndexLogic();
$data=$indexLogic->activityList($param);
return resultArray(['data'=>$data]);
}
}

@ -42,10 +42,7 @@ class Message extends ApiCommon
'remindcustomer',
'checkinvoice',
'visitcontract',
'alldeal',
'checkBusiness',
'newBusiness',
'checkCustomerCheck',
'alldeal'
]
];
Hook::listen('check_auth', $action);
@ -609,13 +606,12 @@ class Message extends ApiCommon
unset($param['type']);
unset($param['isSub']);
$businessModel = model('Business');
// $param['owner_user_id'] = $userInfo['id'];
$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);
// p($contractModel->getLastSql());
if ($types == 'list') {
return resultArray(['data' => $data]);
}
@ -775,7 +771,7 @@ class Message extends ApiCommon
}
# 处理待审核合同、回款、发票
if (in_array($type, ['checkContract', 'checkReceivables', 'checkInvoice', 'checkBusiness', 'checkCustomerCheck', 'newBusiness'])) {
if (in_array($type, ['checkContract', 'checkReceivables', 'checkInvoice','checkBusiness'])) {
$where['check_status'] = ['lt', '2'];
$where['check_user_id'] = ['like', ',%' . $userId . '%,'];
@ -796,19 +792,8 @@ class Message extends ApiCommon
}
# 商机
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();
$invoiceId = !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', $invoiceId)->delete();
}
}
@ -896,9 +881,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);
@ -913,9 +895,6 @@ class Message extends ApiCommon
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' => '操作成功!']);
}
}

@ -447,9 +447,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 +467,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 +487,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'] . '》领取失败,失败原因:持有客户数达到上限!';
}
}
@ -497,18 +497,18 @@ class CustomerPoolLogic extends Common
# 检查是否还有要领取的客户
if (empty($addCustomerId)) return $message;
# 查询领取客户的公海id
$poolId = db('crm_customer_pool_relation')->whereIn('customer_id', $customerId)->value('pool_id');
$poolId=db('crm_customer_pool_relation')->whereIn('customer_id',$customerId)->value('pool_id');
# 公海配置
$poolConfig = db('crm_customer_pool')->field(['before_owner_conf', 'before_owner_day', 'receive_conf', 'receive_count'])->where('pool_id', $poolId)->find();
# 前负责人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'];
if (time() < $restrictDay) {
$message[] = '客户《' . $customerData[$value]['name'] . '》领取失败,失败原因:进入公海后,' . $poolConfig['before_owner_day'] . '天内不能领取!';
$message[] = '客户《' . $customerData[$value]['name'] . '》领取失败,失败原因:进入公海后,'.$poolConfig['before_owner_day'].'天内不能领取!';
unset($addCustomerId[(int)$key]);
}
@ -527,7 +527,7 @@ class CustomerPoolLogic extends Common
$receiveCount = db('crm_customer_pool_record')->where($countWhere)->count();
if (!empty($poolConfig['receive_conf']) && $receiveCount + count($addCustomerId) > $poolConfig['receive_count']) {
$overQuantity = ($receiveCount + count($addCustomerId)) - $poolConfig['receive_count'];
$message[] = '领取客户失败,失败原因:超出当日可领取数量,超出' . $overQuantity . '个!';
$message[] = '领取客户失败,失败原因:超出当日可领取数量,超出'.$overQuantity.'个!';
return $message;
}
@ -536,8 +536,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 +544,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',
@ -1140,12 +1139,12 @@ class CustomerPoolLogic extends Common
$customerCheckModel = model('CustomerCheck');
$examineStepModel = new \app\admin\model\ExamineStep();
$examineStatus = $param['examineStatus'] ?? 1; // 审批是否停用
$param['check_user_id'] =1 ;// 临时测试需删除
unset($param['examineStatus']);
$dataInfo = db('crm_customer_check')->where('customer_id', 'in', $param['customer_id'])->find();
if (!empty($dataInfo)&& $dataInfo['check_status'] < 2) {
if ($dataInfo) {
return '客户已被领取待审批,请联系管理员';
}

@ -282,8 +282,8 @@ class MessageLogic extends Common
$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;
$businessIdArray = db('crm_dealt_relation')->where(['types' => ['eq', 'crm_customer_check'], 'user_id' => ['eq', $param['user_id']]])->column('types_id');
$param['businessIdArray'] = !empty($businessIdArray) ? $businessIdArray : -1;
break;
case '2' :
# 全部

@ -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;
@ -52,7 +51,6 @@ class Business extends Common
$overdue = $request['overdue']; // 待办事项下需联系商机(逾期)
$businessIdArray = $request['businessIdArray']; // 待办事项提醒参数
$isMessage = !empty($request['isMessage']);
$funnelQuery = $request['funnel']; // 销售漏斗查询赢单输单
unset($request['scene_id']);
unset($request['search']);
unset($request['user_id']);
@ -66,7 +64,6 @@ class Business extends Common
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();
@ -144,18 +141,6 @@ class Business extends Common
};
}
}
// 销售漏斗处理
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) {
@ -408,6 +393,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 +437,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 = '添加失败';

@ -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, ',');

File diff suppressed because it is too large Load Diff

@ -23,18 +23,17 @@ class CustomerCheck extends Common
/**
* 待审核客户列表
* @param $request
* @return array
* @return
*/
public function getDataList($request)
{
$userModel = new \app\admin\model\User();
$fieldModel = new \app\admin\model\Field();
$customer_check_id = $request['customer_check_id'];
$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']);
@ -53,6 +52,8 @@ class CustomerCheck extends Common
$requestMap = $request['map'] ?: [];
# getCount是代办事项传来的参数代办事项不需要使用场景
$sceneMap = [];
$partMap = [];
$teamMap = $requestMap['team_id'];
//团队成员 高级筛选
@ -64,11 +65,6 @@ class CustomerCheck extends Common
$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);
@ -88,59 +84,18 @@ class CustomerCheck extends Common
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')
->join('__CRM_CUSTOMER__ customer', 'business.customer_id = customer.customer_id', 'LEFT')
->where($map)
->where($partMap)
->where($dealtWhere)
->limit($request['offset'], $request['length'])
->field('customer_check.*,customer.*')
->field('customer_check.*,customer.name as customer_name')
->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'];
}
# 扩展数据
$extraData = [];
$data = [];
$data['list'] = $list ?: [];
$data['dataCount'] = $dataCount ?: 0;
@ -164,8 +119,6 @@ class CustomerCheck extends Common
$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();

@ -479,13 +479,13 @@ class ExamineLogic extends Common
->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'
'a.customer_check_id as catagory_id ,customer.name as customer_name,a.create_time,a.check_status,a.create_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']);
$list[$k]['create_user_info'] = $userModel->getUserById($v['create_user_id']);
}
$dataCount = db('crm_customer_check')

@ -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']],
@ -91,8 +89,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']],
@ -536,7 +532,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