Compare commits

..

92 Commits
yy ... master

Author SHA1 Message Date
张萌 c158015019 Merge pull request '待进入公海提醒' (#47) from zm into master
2 years ago
张萌 f9762a9069 待进入公海提醒
2 years ago
张萌 ed5cf68658 Merge pull request '公海回收bug fix' (#46) from zm into master
2 years ago
张萌 6cee6d51db 公海回收bug fix
2 years ago
张萌 311f024b5a Merge pull request '公海自动回收规则调整' (#45) from zm into master
2 years ago
张萌 c1d7d65f03 公海自动回收规则调整
2 years ago
杨赟 b8650a1044 Merge pull request '修复' (#44) from yy-4.20 into master
2 years ago
杨赟 8b2d951a88 修复
2 years ago
杨赟 216fd7dbf0 Merge pull request '修复' (#43) from yy-4.20 into master
2 years ago
杨赟 c61dd5910e 修复
2 years ago
杨赟 6ebd628712 修复
2 years ago
杨赟 f76905042a Merge pull request '修复' (#42) from yy-4.20 into master
2 years ago
杨赟 15f8edc15f 修复
2 years ago
杨赟 ae8094a955 Merge pull request '修复' (#41) from yy-4.20 into master
2 years ago
杨赟 7d9ff20d3d 修复
2 years ago
杨赟 b7cf5e96ff Merge pull request '添加客户端' (#40) from yy-4.20 into master
2 years ago
杨赟 ef0d5ea764 添加客户端
2 years ago
张萌 7e63f7b86b Merge pull request '客户领取问题修复' (#39) from zm into master
2 years ago
张萌 7b0d8369fd 客户领取问题修复
2 years ago
张萌 1ef6ac4960 Merge pull request '列表展示字段' (#38) from zm into master
2 years ago
张萌 cf444c5073 列表展示字段
2 years ago
张萌 9b4ded5d2b Merge pull request 'zm' (#37) from zm into master
2 years ago
张萌 cdbc6abd87 字段修改
2 years ago
张萌 53adf43e91 手动放入公海
2 years ago
张萌 ebd8a5e366 Merge pull request 'bug fix' (#35) from zm into master
2 years ago
张萌 e9a082aa9a bug fix
2 years ago
张萌 9a69d54646 Merge pull request '公海客户类型配置调整' (#34) from zm into master
2 years ago
张萌 b3e73fb1c5 公海客户类型配置调整
2 years ago
张萌 fa411cad4d Merge pull request '客户类型公海设置' (#33) from zm into master
2 years ago
张萌 ffdaba68e0 客户类型公海设置
2 years ago
张萌 b58bbbef4b Merge pull request 'bug fix' (#32) from zm into master
2 years ago
张萌 820f6c8912 bug fix
2 years ago
张萌 59eb058bc1 Merge pull request 'bug fix' (#31) from zm into master
2 years ago
张萌 cfe6f030fc bug fix
2 years ago
张萌 c57233837d Merge pull request '销售漏斗' (#30) from zm into master
2 years ago
张萌 f4e75bca13 销售漏斗
2 years ago
张萌 92aabd8f0e Merge pull request '添加字段' (#29) from zm into master
2 years ago
张萌 8ba1c99540 添加字段
2 years ago
张萌 1495e9f39f Merge pull request 'zm' (#28) from zm into master
2 years ago
张萌 226efc26cd 客户类型设置
2 years ago
张萌 34d8f76e74 标记已处理
2 years ago
张萌 ca3af5f387 新商机修复
2 years ago
张萌 f2f72b2fd5 Merge pull request '拒绝后再次审批' (#27) from zm into master
2 years ago
张萌 597b5d2d3f 拒绝后再次审批
2 years ago
张萌 f4b3d06283 Merge pull request 'zm' (#26) from zm into master
2 years ago
张萌 b6ec11bf2b 返回数据
2 years ago
张萌 3a9b3fbb61 Merge pull request 'bug fix' (#25) from zm into master
2 years ago
张萌 7c31cc34bf bug fix
2 years ago
张萌 80d1af3d0d bug fix
2 years ago
张萌 aaf895df3f Merge pull request '添加返回字段' (#24) from zm into master
2 years ago
张萌 d8cb282c9f 添加返回字段
2 years ago
张萌 9c41c94b33 Merge pull request 'bug fix' (#23) from zm into master
2 years ago
张萌 d157007b35 bug fix
2 years ago
张萌 4cc8915334 Merge pull request 'bug fix' (#22) from zm into master
2 years ago
张萌 98083d9077 bug fix
2 years ago
张萌 6e9afbeed9 Merge pull request 'flow_id 解决' (#21) from zm into master
2 years ago
张萌 cb1a21e799 flow_id 解决
2 years ago
张萌 9e9fc2f798 Merge pull request '客户详情' (#20) from zm into master
2 years ago
张萌 7148df93bf 客户详情
2 years ago
张萌 b90464e037 Merge pull request 'zm' (#19) from zm into master
2 years ago
张萌 4a74644a0e 新商机提醒
2 years ago
张萌 063c1a63b5 商机审批修改
2 years ago
张萌 be8ef58780 Merge pull request '返回数据修改' (#17) from zm into master
2 years ago
张萌 809b786f7d 返回数据修改
2 years ago
张萌 07926c46c3 Merge pull request '字段更改' (#16) from zm into master
2 years ago
张萌 60ee0378aa 字段更改
2 years ago
张萌 fa8ecd6c4a Merge pull request 'bug fix' (#15) from zm into master
2 years ago
张萌 23777c9d12 bug fix
2 years ago
张萌 587783aba8 Merge pull request 'bug fix' (#14) from zm into master
2 years ago
张萌 c82447283a bug fix
2 years ago
张萌 d5684b44fd Merge pull request 'bug fix' (#13) from zm into master
2 years ago
张萌 8f3e7a1249 bug fix
2 years ago
张萌 efc8c29ed9 Merge pull request '待审批公海池客户捞取 返回数据' (#12) from zm into master
2 years ago
张萌 1709fc2dd1 待审批公海池客户捞取 返回数据
2 years ago
张萌 c799780ea0 Merge pull request '客户捞取待办事项' (#11) from zm into master
2 years ago
张萌 55b16a3071 客户捞取待办事项
2 years ago
张萌 58166864d4 Merge pull request 'zm' (#10) from zm into master
2 years ago
张萌 44688b3db7 领取公海客户审批
2 years ago
张萌 9a3badcb4f 公海客户捞取审批
2 years ago
张萌 c49d7e4548 Merge pull request 'bug fix' (#9) from zm into master
2 years ago
张萌 c33c0f45c3 bug fix
2 years ago
张萌 724309eae8 Merge pull request '待办事项添加记录添加' (#8) from zm into master
2 years ago
张萌 9de3b06f53 待办事项添加记录添加
2 years ago
张萌 d9698c68b2 Merge pull request 'bug fix' (#7) from zm into master
2 years ago
张萌 0191e053db bug fix
2 years ago
张萌 4c2938446f Merge pull request '待办事项' (#6) from zm into master
2 years ago
张萌 d02ff850de 待办事项
2 years ago
张萌 8a89f22b5a Merge pull request 'dyb' (#5) from dyb into master
2 years ago
张萌 fde049ade4 Merge pull request '企业微信' (#4) from yy into master
2 years ago
戴余标 c491ba926d Merge branch 'master' of https://git.oa00.com/mengfucius/wkcrm
2 years ago
戴余标 21b9869aec Merge branch 'master' of https://git.oa00.com/mengfucius/wkcrm
2 years ago
戴余标 6e63662f7d 待办数字刷新;客户级别不可修改
2 years ago

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

@ -295,7 +295,7 @@ class ExamineFlow extends ApiCommon
$flow_id = $param['flow_id']; $flow_id = $param['flow_id'];
$types = $param['types']; $types = $param['types'];
$types_id = $param['types_id']; $types_id = $param['types_id'];
$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']; $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'];
if (!$types || !in_array($types, $typesArr)) { if (!$types || !in_array($types, $typesArr)) {
return resultArray(['error' => '参数错误']); return resultArray(['error' => '参数错误']);
} }

@ -14,9 +14,9 @@ class PoolConfigLogic
* 公海配置列表 * 公海配置列表
* *
* @param array $param page 页码limit 每页条数 * @param array $param page 页码limit 每页条数
* @author fanqi
* @since 2021-03-30
* @return array * @return array
* @since 2021-03-30
* @author fanqi
*/ */
public function getPoolList($param) public function getPoolList($param)
{ {
@ -33,11 +33,11 @@ class PoolConfigLogic
# 统计公海下的客户数量 # 统计公海下的客户数量
$customerData = []; $customerData = [];
$customerList = db('crm_customer_pool_relation')->field(['pool_id', 'count(customer_id) AS customer_count'])->group('pool_id')->select(); $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']; $customerData[$value['pool_id']] = $value['customer_count'];
} }
foreach ($list AS $key => $value) { foreach ($list as $key => $value) {
# 公海管理员 # 公海管理员
$adminUserIds = trim($value['admin_user_ids'], ','); $adminUserIds = trim($value['admin_user_ids'], ',');
$adminUserNames = db('admin_user')->whereIn('id', $adminUserIds)->column('realname'); $adminUserNames = db('admin_user')->whereIn('id', $adminUserIds)->column('realname');
@ -66,9 +66,9 @@ class PoolConfigLogic
* 设置多公海配置 * 设置多公海配置
* *
* @param $param * @param $param
* @author fanqi
* @since 2021-03-30
* @return bool * @return bool
* @since 2021-03-30
* @author fanqi
*/ */
public function setPoolConfig($param) public function setPoolConfig($param)
{ {
@ -97,6 +97,11 @@ class PoolConfigLogic
return false; return false;
} }
if (empty($param['customer_type'])) {
$this->error = '请设置客户类型!';
return false;
}
$repeatWhere['pool_name'] = $param['pool_name']; $repeatWhere['pool_name'] = $param['pool_name'];
if (!empty($param['pool_id'])) $repeatWhere['pool_id'] = ['neq', $param['pool_id']]; if (!empty($param['pool_id'])) $repeatWhere['pool_id'] = ['neq', $param['pool_id']];
if (db('crm_customer_pool')->where($repeatWhere)->value('pool_id')) { if (db('crm_customer_pool')->where($repeatWhere)->value('pool_id')) {
@ -111,14 +116,15 @@ class PoolConfigLogic
'department_ids' => !empty($param['department_ids']) ? ',' . $param['department_ids'] . ',' : '', 'department_ids' => !empty($param['department_ids']) ? ',' . $param['department_ids'] . ',' : '',
'status' => 1, 'status' => 1,
'before_owner_conf' => $param['before_owner_conf'], 'before_owner_conf' => $param['before_owner_conf'],
'before_owner_day' => $param['before_owner_day'], 'before_owner_day' => $param['before_owner_day'],
'receive_conf' => $param['receive_conf'], 'receive_conf' => $param['receive_conf'],
'receive_count' => $param['receive_count'], 'receive_count' => $param['receive_count'],
'remind_conf' => $param['remind_conf'], 'remind_conf' => $param['remind_conf'],
'remain_day' => $param['remain_day'], 'remain_day' => $param['remain_day'],
'recycle_conf' => $param['recycle_conf'], 'recycle_conf' => $param['recycle_conf'],
'create_user_id' => $param['user_id'], 'create_user_id' => $param['user_id'],
'create_time' => time() 'create_time' => time(),
'customer_type' => $param['customer_type'],
]; ];
Db::startTrans(); Db::startTrans();
@ -161,9 +167,9 @@ class PoolConfigLogic
* 公海配置详情 * 公海配置详情
* *
* @param int $poolId 公海ID * @param int $poolId 公海ID
* @author fanqi
* @since 2021-03-30
* @return array|bool * @return array|bool
* @since 2021-03-30
* @author fanqi
*/ */
public function readPool($poolId) public function readPool($poolId)
{ {
@ -181,7 +187,7 @@ class PoolConfigLogic
$adminUserIds = trim($data['admin_user_ids'], ','); $adminUserIds = trim($data['admin_user_ids'], ',');
$data['admin_user_ids'] = $adminUserIds; $data['admin_user_ids'] = $adminUserIds;
$data['admin_user_info'] = db('admin_user')->field(['id', 'realname', 'thumb_img'])->whereIn('id', $adminUserIds)->select(); $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']); $data['admin_user_info'][$key]['thumb_img'] = getFullPath($value['thumb_img']);
} }
@ -189,7 +195,7 @@ class PoolConfigLogic
$userIds = trim($data['user_ids'], ','); $userIds = trim($data['user_ids'], ',');
$data['user_ids'] = $userIds; $data['user_ids'] = $userIds;
$data['user_info'] = db('admin_user')->field(['id', 'realname', 'thumb_img'])->whereIn('id', $userIds)->select(); $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']); $data['user_info'][$key]['thumb_img'] = getFullPath($value['thumb_img']);
} }
@ -203,7 +209,7 @@ class PoolConfigLogic
# 公海规则 # 公海规则
$data['rule'] = db('crm_customer_pool_rule')->where('pool_id', $data['pool_id'])->select(); $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'])) { if (!empty($value['level'])) {
$data['rule'][$key]['level'] = json_decode($value['level'], true); $data['rule'][$key]['level'] = json_decode($value['level'], true);
$data['rule'][$key]['level_setting'] = json_decode($value['level'], true); $data['rule'][$key]['level_setting'] = json_decode($value['level'], true);
@ -220,9 +226,9 @@ class PoolConfigLogic
* 变更公海配置状态 * 变更公海配置状态
* *
* @param array $param pool_id 公海ID, status 状态1启用、0停用 * @param array $param pool_id 公海ID, status 状态1启用、0停用
* @author fanqi
* @since 2021-03-30
* @return false|int|string * @return false|int|string
* @since 2021-03-30
* @author fanqi
*/ */
public function changePoolStatus($param) public function changePoolStatus($param)
{ {
@ -246,9 +252,9 @@ class PoolConfigLogic
* 删除公海配置 * 删除公海配置
* *
* @param int $poolId 公海ID * @param int $poolId 公海ID
* @author fanqi
* @since 2021-03-30
* @return bool * @return bool
* @since 2021-03-30
* @author fanqi
*/ */
public function deletePool($poolId) public function deletePool($poolId)
{ {
@ -294,9 +300,9 @@ class PoolConfigLogic
* 转移公海客户 * 转移公海客户
* *
* @param array $param source_pool_id 源公海IDtarget_pool_id 目标公海ID * @param array $param source_pool_id 源公海IDtarget_pool_id 目标公海ID
* @author fanqi
* @since 2021-03-30
* @return bool * @return bool
* @since 2021-03-30
* @author fanqi
*/ */
public function transferPool($param) public function transferPool($param)
{ {
@ -313,7 +319,7 @@ class PoolConfigLogic
$diffCustomerIds = array_diff($sourceCustomerIds, $targetCustomerIds); $diffCustomerIds = array_diff($sourceCustomerIds, $targetCustomerIds);
$data = []; $data = [];
foreach ($diffCustomerIds AS $key => $value) { foreach ($diffCustomerIds as $key => $value) {
$data[] = [ $data[] = [
'customer_id' => $value, 'customer_id' => $value,
'pool_id' => $param['target_pool_id'] 'pool_id' => $param['target_pool_id']
@ -340,9 +346,9 @@ class PoolConfigLogic
/** /**
* 获取客户级别列表 * 获取客户级别列表
* *
* @author fanqi
* @since 2021-04-22
* @return array * @return array
* @since 2021-04-22
* @author fanqi
*/ */
public function getCustomerLevel() public function getCustomerLevel()
{ {
@ -357,9 +363,9 @@ class PoolConfigLogic
* 获取公海字段列表 * 获取公海字段列表
* *
* @param array $param pool_id 公海ID * @param array $param pool_id 公海ID
* @author fanqi
* @since 2021-04-29
* @return bool|PDOStatement|string|Collection * @return bool|PDOStatement|string|Collection
* @since 2021-04-29
* @author fanqi
*/ */
public function getPoolFieldList($param) public function getPoolFieldList($param)
{ {
@ -369,75 +375,75 @@ class PoolConfigLogic
$data = db('admin_field')->field(['field', 'name', 'form_type', 'is_hidden', 'is_null', 'is_unique'])->where(['types' => 'crm_customer'])->select(); $data = db('admin_field')->field(['field', 'name', 'form_type', 'is_hidden', 'is_null', 'is_unique'])->where(['types' => 'crm_customer'])->select();
$address = [ $address = [
'field' => 'address', 'field' => 'address',
'name' => '省、市、区/县', 'name' => '省、市、区/县',
'form_type' => 'customer_address', 'form_type' => 'customer_address',
'is_hidden' => 0, 'is_hidden' => 0,
'is_null' => 0, 'is_null' => 0,
'is_unique' => 0, 'is_unique' => 0,
]; ];
$detailAddress = [ $detailAddress = [
'field' => 'detail_address', 'field' => 'detail_address',
'name' => '详细地址', 'name' => '详细地址',
'form_type' => 'text', 'form_type' => 'text',
'is_hidden' => 0, 'is_hidden' => 0,
'is_null' => 0, 'is_null' => 0,
'is_unique' => 0, 'is_unique' => 0,
]; ];
$lastRecord = [ $lastRecord = [
'field' => 'last_record', 'field' => 'last_record',
'name' => '最后跟进记录', 'name' => '最后跟进记录',
'form_type' => 'text', 'form_type' => 'text',
'is_hidden' => 0, 'is_hidden' => 0,
'is_null' => 0, 'is_null' => 0,
'is_unique' => 0, 'is_unique' => 0,
]; ];
$lastTime = [ $lastTime = [
'field' => 'last_time', 'field' => 'last_time',
'name' => '最后跟进时间', 'name' => '最后跟进时间',
'form_type' => 'datetime', 'form_type' => 'datetime',
'is_hidden' => 0, 'is_hidden' => 0,
'is_null' => 0, 'is_null' => 0,
'is_unique' => 0, 'is_unique' => 0,
]; ];
$beforeOwnerUser = [ $beforeOwnerUser = [
'field' => 'before_owner_user_id', 'field' => 'before_owner_user_id',
'name' => '前负责人', 'name' => '前负责人',
'form_type' => 'user', 'form_type' => 'user',
'is_hidden' => 0, 'is_hidden' => 0,
'is_null' => 0, 'is_null' => 0,
'is_unique' => 0, 'is_unique' => 0,
]; ];
$intoPoolTime = [ $intoPoolTime = [
'field' => 'into_pool_time', 'field' => 'into_pool_time',
'name' => '进入公海时间', 'name' => '进入公海时间',
'form_type' => 'datetime', 'form_type' => 'datetime',
'is_hidden' => 0, 'is_hidden' => 0,
'is_null' => 0, 'is_null' => 0,
'is_unique' => 0, 'is_unique' => 0,
]; ];
$createTime = [ $createTime = [
'field' => 'create_time', 'field' => 'create_time',
'name' => '创建时间', 'name' => '创建时间',
'form_type' => 'datetime', 'form_type' => 'datetime',
'is_hidden' => 0, 'is_hidden' => 0,
'is_null' => 0, 'is_null' => 0,
'is_unique' => 0, 'is_unique' => 0,
]; ];
$updateTime = [ $updateTime = [
'field' => 'update_time', 'field' => 'update_time',
'name' => '更新时间', 'name' => '更新时间',
'form_type' => 'datetime', 'form_type' => 'datetime',
'is_hidden' => 0, 'is_hidden' => 0,
'is_null' => 0, 'is_null' => 0,
'is_unique' => 0, 'is_unique' => 0,
]; ];
$createUser = [ $createUser = [
'field' => 'create_user_id', 'field' => 'create_user_id',
'name' => '创建人', 'name' => '创建人',
'form_type' => 'user', 'form_type' => 'user',
'is_hidden' => 0, 'is_hidden' => 0,
'is_null' => 0, 'is_null' => 0,
'is_unique' => 0, 'is_unique' => 0,
]; ];
array_push($data, $address, $detailAddress, $lastRecord, $lastTime, $createTime, $updateTime, $createUser, $beforeOwnerUser, $intoPoolTime); array_push($data, $address, $detailAddress, $lastRecord, $lastTime, $createTime, $updateTime, $createUser, $beforeOwnerUser, $intoPoolTime);
@ -451,15 +457,15 @@ class PoolConfigLogic
* *
* @param array $rules 规则数据 * @param array $rules 规则数据
* @param int $poolId 公海ID * @param int $poolId 公海ID
* @author fanqi
* @since 2021-03-30
* @return array * @return array
* @since 2021-03-30
* @author fanqi
*/ */
private function getPoolRule($rules, $poolId) private function getPoolRule($rules, $poolId)
{ {
$result = []; $result = [];
foreach ($rules AS $key => $value) { foreach ($rules as $key => $value) {
$result[] = [ $result[] = [
'pool_id' => $poolId, 'pool_id' => $poolId,
'type' => $value['type'], 'type' => $value['type'],
@ -467,7 +473,7 @@ class PoolConfigLogic
'business_handle' => $value['business_handle'], 'business_handle' => $value['business_handle'],
'level_conf' => $value['level_conf'], 'level_conf' => $value['level_conf'],
'level' => json_encode($value['level']), '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,
]; ];
} }
@ -479,23 +485,23 @@ class PoolConfigLogic
* *
* @param array $fields 字段列表 * @param array $fields 字段列表
* @param int $poolId 公海ID * @param int $poolId 公海ID
* @author fanqi
* @since 2021-03-30
* @return array * @return array
* @since 2021-03-30
* @author fanqi
*/ */
private function getPoolField($fields, $poolId) private function getPoolField($fields, $poolId)
{ {
$result = []; $result = [];
foreach ($fields AS $key => $value) { foreach ($fields as $key => $value) {
$result[] = [ $result[] = [
'pool_id' => $poolId, 'pool_id' => $poolId,
'name' => $value['name'], 'name' => $value['name'],
'field_name' => $value['field'], 'field_name' => $value['field'],
'form_type' => $value['form_type'], 'form_type' => $value['form_type'],
'is_hidden' => $value['is_hidden'], 'is_hidden' => $value['is_hidden'],
'is_null' => $value['is_null'], 'is_null' => $value['is_null'],
'is_unique' => $value['is_unique'] 'is_unique' => $value['is_unique']
]; ];
} }

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

@ -13,59 +13,59 @@ use think\Validate;
class ExamineStep extends Common class ExamineStep extends Common
{ {
/** /**
* 为了数据库的整洁同时又不影响Model和Controller的名称 * 为了数据库的整洁同时又不影响Model和Controller的名称
* 我们约定每个模块的数据表都加上相同的前缀比如CRM模块用crm作为数据表前缀 * 我们约定每个模块的数据表都加上相同的前缀比如CRM模块用crm作为数据表前缀
*/ */
protected $name = 'admin_examine_step'; protected $name = 'admin_examine_step';
/** /**
* 获取有效审批步骤列表 * 获取有效审批步骤列表
* @param flow_id 审批流程ID * @param flow_id 审批流程ID
* @param user_id 审批申请人ID * @param user_id 审批申请人ID
* @return * @return
*/ */
public function getDataList($flow_id) public function getDataList($flow_id)
{ {
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$list = $this->where(['flow_id' => $flow_id])->order('order_id asc')->select(); $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']); $list[$k]['user_id_info'] = $userModel->getListByStr($v['user_id']);
} }
return $list ? : []; return $list ?: [];
} }
/** /**
* 审批步骤(创建、编辑) * 审批步骤(创建、编辑)
* @param flow_id 审批流程ID * @param flow_id 审批流程ID
* @param status 1负责人主管2指定用户任意一人3指定用户多人会签4上一级审批人主管 * @param status 1负责人主管2指定用户任意一人3指定用户多人会签4上一级审批人主管
* @return * @return
*/ */
public function createStepData($data, $flow_id) public function createStepData($data, $flow_id)
{ {
if (!intval($flow_id)) { if (!intval($flow_id)) {
$this->error = '审批流程创建失败'; $this->error = '审批流程创建失败';
return false; return false;
} }
//处理数据 //处理数据
$resSuccess = true; $resSuccess = true;
$dataStep = []; $dataStep = [];
foreach ($data as $k=>$v) { foreach ($data as $k => $v) {
if (!intval($v['status']) || (in_array($v['status'],[2,3]) && !$v['user_id'])) { if (!intval($v['status']) || (in_array($v['status'], [2, 3]) && !$v['user_id'])) {
$resSuccess = false; $resSuccess = false;
} }
$dataStep[$k]['relation'] = 1; $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]['user_id'] = $v['user_id'] ? arrayToString($v['user_id']) : ''; //处理user_id
$dataStep[$k]['relation'] = ($v['status'] == 3) ? 1 : 2; $dataStep[$k]['relation'] = ($v['status'] == 3) ? 1 : 2;
} }
if ($v['step']) { if ($v['step']) {
$dataStep[$k]['step_id'] = $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]['flow_id'] = $flow_id;
$dataStep[$k]['status'] = $v['status']; $dataStep[$k]['status'] = $v['status'];
$dataStep[$k]['create_time'] = time(); $dataStep[$k]['create_time'] = time();
} }
if ($resSuccess) { if ($resSuccess) {
//提交事务 //提交事务
@ -74,59 +74,59 @@ class ExamineStep extends Common
$this->where(['flow_id' => $flow_id])->delete(); $this->where(['flow_id' => $flow_id])->delete();
$this->saveAll($dataStep); $this->saveAll($dataStep);
$this->commit(); $this->commit();
return true; return true;
} catch(\Exception $e) { } catch (\Exception $e) {
$this->error = '审批步骤创建失败'; $this->error = '审批步骤创建失败';
$this->rollback(); $this->rollback();
return false; return false;
} }
} else { } else {
$this->error = '参数错误'; $this->error = '参数错误';
return false; return false;
} }
} }
/** /**
* 审批步骤(排序,防止位置情况造成排序错乱) * 审批步骤(排序,防止位置情况造成排序错乱)
* @param flow_id 审批流程ID * @param flow_id 审批流程ID
* @return * @return
*/ */
public function orderData($flow_id) public function orderData($flow_id)
{ {
$step_list = db('admin_examine_step')->where(['flow_id' => $flow_id])->order('order_id')->select(); $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 = [];
$data = ['step_id' => $v['step_id'],'order_id' => $k]; $data = ['step_id' => $v['step_id'], 'order_id' => $k];
db('admin_examine_step')->update($data); db('admin_examine_step')->update($data);
} }
} }
/** /**
* 下一审批人(审批是否结束) * 下一审批人(审批是否结束)
* @param user_id 审批申请人ID * @param user_id 审批申请人ID
* @param flow_id 审批流ID * @param flow_id 审批流ID
* @param types 关联对象 * @param types 关联对象
* @param types_id 联对象ID * @param types_id 联对象ID
* @param order_id 审批排序ID * @param order_id 审批排序ID
* @param status 1负责人主管2指定用户任意一人3指定用户多人会签4上一级审批人主管 * @param status 1负责人主管2指定用户任意一人3指定用户多人会签4上一级审批人主管
* @param check_user_id 当前审核人ID * @param check_user_id 当前审核人ID
*/ */
public function nextStepUser($user_id, $flow_id, $types, $types_id, $order_id, $check_user_id) 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); $res = nextCheckData($user_id, $flow_id, $types, $types_id, $order_id, $check_user_id);
return $res ? : []; return $res ?: [];
} }
/** /**
* 审批步骤权限 * 审批步骤权限
* @param step_id 审批步骤ID * @param step_id 审批步骤ID
* @param user_id 审批人ID当前登录人 * @param user_id 审批人ID当前登录人
* @param create_user_id 申请人ID * @param create_user_id 申请人ID
* @param types 关联对象 * @param types 关联对象
* @param types_id 联对象ID * @param types_id 联对象ID
* @param status 1负责人主管2指定用户任意一人3指定用户多人会签4上一级审批人主管 * @param status 1负责人主管2指定用户任意一人3指定用户多人会签4上一级审批人主管
* @return * @return
*/ */
public function checkExamine($user_id, $types, $types_id) public function checkExamine($user_id, $types, $types_id)
{ {
$data = $this->getDataByTypes($types, $types_id); $data = $this->getDataByTypes($types, $types_id);
@ -134,19 +134,19 @@ class ExamineStep extends Common
$stepInfo = $data['stepInfo']; //审批步骤信息 $stepInfo = $data['stepInfo']; //审批步骤信息
if (!$dataInfo) { if (!$dataInfo) {
$this->error = '参数错误!'; $this->error = '参数错误!';
return false; return false;
} }
if (in_array($dataInfo['check_status'], ['2','3'])) { if (in_array($dataInfo['check_status'], ['2', '3'])) {
$this->error = '审批已经结束!'; $this->error = '审批已经结束!';
return false; return false;
} }
if ($dataInfo['flow_id'] > 0) { if ($dataInfo['flow_id'] > 0) {
//固定流程 //固定流程
//当前步骤已审批user_id //当前步骤已审批user_id
$check_user_ids = $this->getUserByCheck($types, $types_id, $dataInfo['order_id']); $check_user_ids = $this->getUserByCheck($types, $types_id, $dataInfo['order_id']);
if (in_array($user_id, $check_user_ids)) { if (in_array($user_id, $check_user_ids)) {
$this->error = '您已审核,请勿重复操作!'; $this->error = '您已审核,请勿重复操作!';
return false; return false;
} }
$examine_user_id_arr = array(); $examine_user_id_arr = array();
// $examine_user_id_arr = $this->getUserByStep($stepInfo['step_id'], $dataInfo['create_user_id']); //获取审批步骤审批人 // $examine_user_id_arr = $this->getUserByStep($stepInfo['step_id'], $dataInfo['create_user_id']); //获取审批步骤审批人
@ -155,59 +155,93 @@ class ExamineStep extends Common
} else { } else {
$examine_user_id_arr = $this->getUserByPer($types); $examine_user_id_arr = $this->getUserByPer($types);
} }
if (!in_array($user_id, $examine_user_id_arr)) { if (!in_array($user_id, $examine_user_id_arr)) {
$this->error = '没有权限'; $this->error = '没有权限';
return false; return false;
} }
return true; return true;
} }
/** /**
* 审批对象获取审批相关信息 * 审批对象获取审批相关信息
* @param types 关联对象 * @param types 关联对象
* @param types_id 联对象ID * @param types_id 联对象ID
* @return * @return
*/ */
public function getDataByTypes($types, $types_id) public function getDataByTypes($types, $types_id)
{ {
if (empty($types) || empty($types_id)) { if (empty($types) || empty($types_id)) {
$this->error = '参数错误'; $this->error = '参数错误';
return false; return false;
} }
switch (trim($types)) { 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 'oa_examine' :
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; $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();
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; 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 'crm_contract' :
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; $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();
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; 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 'crm_receivables' :
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; $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();
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; 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 'crm_invoice':
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; $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();
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; 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;
} }
$stepInfo = []; $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(); $stepInfo = db('admin_examine_step')->where(['flow_id' => $dataInfo['flow_id'], 'order_id' => $dataInfo['order_id']])->find();
}
if ($types=="crm_customer_check"){
$dataInfo['create_user_id']=$dataInfo['user_id'];
$dataInfo['owner_user_id']=$dataInfo['user_id'];
} }
$data = []; $data = [];
$data['stepInfo'] = $stepInfo; $data['stepInfo'] = $stepInfo;
$data['step_id'] = $stepInfo['step_id'] ? : ''; $data['step_id'] = $stepInfo['step_id'] ?: '';
$data['dataInfo'] = $dataInfo; $data['dataInfo'] = $dataInfo;
return $data; return $data;
} }
/** /**
* 获取审批步骤审批人信息 * 获取审批步骤审批人信息
* @param step_id 审批步骤ID * @param step_id 审批步骤ID
* @param status 1负责人主管2指定用户任意一人3指定用户多人会签4上一级审批人主管 * @param status 1负责人主管2指定用户任意一人3指定用户多人会签4上一级审批人主管
* @param user_id 审批主体申请人user_id * @param user_id 审批主体申请人user_id
* @return * @return
*/ */
public function getUserByStep($step_id, $user_id) public function getUserByStep($step_id, $user_id)
{ {
$stepInfo = db('admin_examine_step')->where(['step_id' => $step_id])->find(); $stepInfo = db('admin_examine_step')->where(['step_id' => $step_id])->find();
@ -222,11 +256,13 @@ class ExamineStep extends Common
$examine_user_id_arr[] = 1; $examine_user_id_arr[] = 1;
} }
break; break;
case 2 : case 2 :
case 3 :$examine_user_id_arr = stringToArray($stepInfo['user_id']); break; case 3 :
case 4 : $examine_user_id_arr = stringToArray($stepInfo['user_id']);
$order_id = $stepInfo['order_id'] ? $stepInfo['order_id']-1 : 0; break;
$last_step_id = db('admin_examine_step')->where(['flow_id' => $stepInfo['flow_id'],'order_id' => $order_id])->value('step_id'); 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');
$last_step_info = db('admin_examine_step')->where(['step_id' => $last_step_id])->find(); $last_step_info = db('admin_examine_step')->where(['step_id' => $last_step_id])->find();
$last_user_id = $this->getUserByStep($last_step_id, $user_id); $last_user_id = $this->getUserByStep($last_step_id, $user_id);
if (count(stringToArray($last_user_id)) !== 1) { if (count(stringToArray($last_user_id)) !== 1) {
@ -239,17 +275,18 @@ class ExamineStep extends Common
$examine_user_id_arr = []; $examine_user_id_arr = [];
if ($examine_user_id) { if ($examine_user_id) {
$examine_user_id_arr = stringToArray($examine_user_id); $examine_user_id_arr = stringToArray($examine_user_id);
} }
break; 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))) . ',' : '';
} }
/** /**
* 获取当前步骤已审批的user_id * 获取当前步骤已审批的user_id
* @param step_id 审批步骤ID * @param step_id 审批步骤ID
* @param status 1审核通过0审核失败2撤销 * @param status 1审核通过0审核失败2撤销
* @return * @return
*/ */
public function getUserByCheck($types, $types_id = 0, $order_id = 0, $status = 1) public function getUserByCheck($types, $types_id = 0, $order_id = 0, $status = 1)
@ -257,20 +294,20 @@ class ExamineStep extends Common
if ($types_id == 0 && $order_id == 0) { if ($types_id == 0 && $order_id == 0) {
$check_user_ids = []; $check_user_ids = [];
} else { } 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 ?: [];
} }
/** /**
* 获取授权审批的user_id * 获取授权审批的user_id
* @param step_id 审批步骤ID * @param step_id 审批步骤ID
* @param * @param
* @return * @return
*/ */
public function getUserByPer($types) 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 = '参数错误'; $this->error = '参数错误';
return false; return false;
} }
@ -278,43 +315,51 @@ class ExamineStep extends Common
$adminUserId = model('User')->getAdminId(); //管理员ID $adminUserId = model('User')->getAdminId(); //管理员ID
//获取有审核权限的user_id //获取有审核权限的user_id
switch ($types) { switch ($types) {
case 'oa_examine' : $examine_user_id_arr = $userModel->getUserByPer('oa', 'examine', 'check'); break; case 'oa_examine' :
case 'crm_contract' : $examine_user_id_arr = $userModel->getUserByPer('crm', 'contract', 'check'); break; $examine_user_id_arr = $userModel->getUserByPer('oa', 'examine', 'check');
case 'crm_receivables' : $examine_user_id_arr = $userModel->getUserByPer('crm', 'receivables', 'check'); break; break;
case 'crm_invoice' : $examine_user_id_arr = $userModel->getUserByPer('crm', 'invoice', '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; $examine_user_id_arr = $examine_user_id_arr ? array_merge($examine_user_id_arr, $adminUserId) : $adminUserId;
return $examine_user_id_arr; return $examine_user_id_arr;
} }
/** /**
* 获取审批步骤相关userId * 获取审批步骤相关userId
* @param flow_id 流程ID * @param flow_id 流程ID
* @param order_id 排序ID * @param order_id 排序ID
* @return * @return
*/ */
public function getStepUserByOrder($flow_id, $order_id, $user_id) public function getStepUserByOrder($flow_id, $order_id, $user_id)
{ {
$user_ids = []; $user_ids = [];
if ($flow_id && $order_id) { 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); $user_ids = $this->getUserByStep($stepInfo['step_id'], $user_id);
} }
return $user_ids ? : []; return $user_ids ?: [];
} }
/** /**
* 获取有效审批步骤列表(固定审批) * 获取有效审批步骤列表(固定审批)
* @param flow_id 审批流程ID * @param flow_id 审批流程ID
* @param user_id 审批申请人ID * @param user_id 审批申请人ID
* @param check_user_id 当前操作人ID * @param check_user_id 当前操作人ID
* @return * @return
*/ */
public function getStepList($flow_id, $user_id, $types, $types_id = 0, $check_user_id = 0, $action = '', $category_id = '') public function getStepList($flow_id, $user_id, $types, $types_id = 0, $check_user_id = 0, $action = '', $category_id = '')
{ {
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$newlist = []; $newlist = [];
$dataInfo['order_id'] = 0; $dataInfo['order_id'] = 0;
if ($types_id) { if ($types_id) {
$typesInfo = $this->getDataByTypes($types, $types_id); $typesInfo = $this->getDataByTypes($types, $types_id);
@ -328,11 +373,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 || in_array($check_user_id, $admin_user_ids)) {
if ($dataInfo['create_user_id'] == $check_user_id || $dataInfo['owner_user_id'] == $check_user_id) { 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; $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; $is_check = 1;
} }
@ -340,7 +385,7 @@ class ExamineStep extends Common
$createUserInfo = $userModel->getUserById($dataInfo['create_user_id']); $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; $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; $createUserInfo['check_type'] = 2;
$newlist[1]['type'] = '2'; //撤销 $newlist[1]['type'] = '2'; //撤销
$newlist[1]['status'] = '5'; //创建前端要求给创建人加一个status字段定义为5 $newlist[1]['status'] = '5'; //创建前端要求给创建人加一个status字段定义为5
@ -351,7 +396,7 @@ class ExamineStep extends Common
$newlist[0]['time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null; $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]['user_id_info'] = array($createUserInfo);
$newlist[1]['time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null; $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; $createUserInfo['check_type'] = 3;
$newlist[0]['type'] = '3'; //创建 $newlist[0]['type'] = '3'; //创建
$newlist[0]['status'] = '5'; //创建前端要求给创建人加一个status字段定义为5 $newlist[0]['status'] = '5'; //创建前端要求给创建人加一个status字段定义为5
@ -374,7 +419,7 @@ class ExamineStep extends Common
if ($dataInfo['check_status'] !== 4 || $action !== 'view') { if ($dataInfo['check_status'] !== 4 || $action !== 'view') {
$list = db('admin_examine_step')->where(['flow_id' => $flow_id])->order('order_id asc')->select(); $list = db('admin_examine_step')->where(['flow_id' => $flow_id])->order('order_id asc')->select();
$is_break = false; $is_break = false;
foreach ($list as $k=>$v) { foreach ($list as $k => $v) {
$type = 4; $type = 4;
$examine_user_ids = ''; $examine_user_ids = '';
//判断步骤审批人是否存在 //判断步骤审批人是否存在
@ -383,7 +428,7 @@ class ExamineStep extends Common
if ($examine_user_arr) { if ($examine_user_arr) {
$newStepInfo = $v; $newStepInfo = $v;
$user_id_info_arr = []; $user_id_info_arr = [];
foreach ($examine_user_arr as $key=>$val) { foreach ($examine_user_arr as $key => $val) {
$user_id_info = []; $user_id_info = [];
$user_id_info = $userModel->getUserById($val); $user_id_info = $userModel->getUserById($val);
$check_type = 4; //type 0失败1通过2撤销3创建4待审核5未提交 $check_type = 4; //type 0失败1通过2撤销3创建4待审核5未提交
@ -394,7 +439,7 @@ class ExamineStep extends Common
$check_type = 1; $check_type = 1;
$type = !empty($dataInfo['check_user_id']) ? 4 : 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; $check_type = 1;
$type = 1; $type = 1;
} }
@ -408,7 +453,7 @@ class ExamineStep extends Common
} }
$fail_check_user_ids = $this->getUserByCheck($types, $types_id, $v['order_id'], 0); //拒绝人员 $fail_check_user_ids = $this->getUserByCheck($types, $types_id, $v['order_id'], 0); //拒绝人员
if ($dataInfo['check_status'] == 3) { if ($dataInfo['check_status'] == 3) {
if (in_array($val,$fail_check_user_ids)) { if (in_array($val, $fail_check_user_ids)) {
$is_break = true; $is_break = true;
$check_type = 0; $check_type = 0;
$type = 0; $type = 0;
@ -417,7 +462,7 @@ class ExamineStep extends Common
} }
$user_id_info['check_type'] = $check_type; $user_id_info['check_type'] = $check_type;
$check_time = ''; $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['check_time'] = !empty($check_time) ? date('Y-m-d H:i:s', $check_time) : '';
$user_id_info_arr[] = $user_id_info; $user_id_info_arr[] = $user_id_info;
} }
@ -427,10 +472,10 @@ class ExamineStep extends Common
$type = 1; $type = 1;
} }
//if ($is_break !== false) break; //if ($is_break !== false) break;
$newStepInfo['type'] = $type; $newStepInfo['type'] = $type;
$stepList[] = $newStepInfo; $stepList[] = $newStepInfo;
} }
} }
} }
$newStepList = []; $newStepList = [];
if ($newlist && $stepList) { if ($newlist && $stepList) {
@ -440,31 +485,31 @@ class ExamineStep extends Common
} else { } else {
$newStepList = $newlist; $newStepList = $newlist;
} }
$data['steplist'] = $newStepList ? : []; $data['steplist'] = $newStepList ?: [];
$data['is_check'] = $is_check; $data['is_check'] = $is_check;
$data['is_recheck'] = $is_recheck; $data['is_recheck'] = $is_recheck;
return $data ? : []; return $data ?: [];
} }
/** /**
* 根据order_id获取审批步骤 * 根据order_id获取审批步骤
* @param flow_id 审批流程ID * @param flow_id 审批流程ID
* @param order_id 审批排序ID * @param order_id 审批排序ID
* @return * @return
*/ */
public function getStepByOrder($flow_id, $order_id) public function getStepByOrder($flow_id, $order_id)
{ {
$data = db('admin_examine_step')->where(['flow_id' => $flow_id,'order_id' => $order_id])->find(); $data = db('admin_examine_step')->where(['flow_id' => $flow_id, 'order_id' => $order_id])->find();
return $data ? : []; return $data ?: [];
} }
/** /**
* 获取有效审批步骤列表(自选审批) * 获取有效审批步骤列表(自选审批)
* @param types 类型 * @param types 类型
* @param types_id 类型ID * @param types_id 类型ID
* @param action 操作类型: view、save * @param action 操作类型: view、save
* @return * @return
*/ */
public function getPerStepList($types, $types_id, $user_id, $check_user_id, $action = '') public function getPerStepList($types, $types_id, $user_id, $check_user_id, $action = '')
{ {
$examineRecordModel = new \app\admin\model\ExamineRecord(); $examineRecordModel = new \app\admin\model\ExamineRecord();
@ -480,13 +525,13 @@ class ExamineStep extends Common
$dataInfo = $typeInfo['dataInfo']; $dataInfo = $typeInfo['dataInfo'];
//type 0失败1通过2撤销3创建4待审核5未提交 //type 0失败1通过2撤销3创建4待审核5未提交
$i = 0; $i = 0;
if(empty($recordList)){ if (empty($recordList)) {
$createUserInfo = $userModel->getUserById($dataInfo['create_user_id']); $createUserInfo = $userModel->getUserById($dataInfo['create_user_id']);
$userList[0]['userInfo'] = $createUserInfo; $userList[0]['userInfo'] = $createUserInfo;
$userList[0]['type'] = 3; //创建 $userList[0]['type'] = 3; //创建
$userList[0]['time'] = $dataInfo['update_time'] ? : ''; $userList[0]['time'] = $dataInfo['update_time'] ?: '';
}else{ } else {
foreach ($recordList as $k=>$v) { foreach ($recordList as $k => $v) {
$userList[$i]['userInfo'] = $userModel->getUserById($v['check_user_id']); $userList[$i]['userInfo'] = $userModel->getUserById($v['check_user_id']);
$userList[$i]['type'] = $v['status']; $userList[$i]['type'] = $v['status'];
$userList[$i]['time'] = $v['check_time']; $userList[$i]['time'] = $v['check_time'];
@ -503,7 +548,7 @@ class ExamineStep extends Common
$check_user_id_arr = stringToArray($dataInfo['check_user_id']); $check_user_id_arr = stringToArray($dataInfo['check_user_id']);
$userList[0]['userInfo'] = $userModel->getUserById($check_user_id_arr[0]); $userList[0]['userInfo'] = $userModel->getUserById($check_user_id_arr[0]);
$userList[0]['type'] = '5'; $userList[0]['type'] = '5';
} }
$is_check = 0; //审批权限(1有) $is_check = 0; //审批权限(1有)
$is_recheck = 0; //撤销审批权限(1有) $is_recheck = 0; //撤销审批权限(1有)
@ -511,17 +556,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 || in_array($check_user_id, $admin_user_ids)) {
if ($dataInfo['create_user_id'] == $check_user_id || $dataInfo['owner_user_id'] == $check_user_id) { 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; $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; $is_check = 1;
} }
$data['steplist'] = $userList; $data['steplist'] = $userList;
$data['is_check'] = $is_check; $data['is_check'] = $is_check;
$data['is_recheck'] = $is_recheck; $data['is_recheck'] = $is_recheck;
return $data ? : []; return $data ?: [];
} }
} }

@ -390,10 +390,10 @@ class Field extends Model
if ($v['form_type'] == 'checkbox') { if ($v['form_type'] == 'checkbox') {
$list[$k]['default_value'] = $v['default_value'] ? explode(',', $v['default_value']) : array(); $list[$k]['default_value'] = $v['default_value'] ? explode(',', $v['default_value']) : array();
} }
if ($v['form_type']=='date_interval') { if ($v['form_type'] == 'date_interval') {
$list[$k]['default_value'] = !empty($v['default_value']) ? explode(',',$v['default_value']) : []; $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) : []; $list[$k]['default_value'] = !empty($v['default_value']) ? json_decode($v['default_value'], true) : [];
} }
if ($v['form_type'] == 'detail_table') { if ($v['form_type'] == 'detail_table') {
@ -485,7 +485,10 @@ class Field extends Model
} }
//生成字段名 //生成字段名
if (!$data['field']) $data['field'] = $this->createField($types, $types == 'oa_examine' ? 'oa_' : 'crm_'); if (!empty($param['field'])) {
$data['field'] = $param['field'];
} else if (!$data['field']) $data['field'] = $this->createField($types, $types == 'oa_examine' ? 'oa_' : 'crm_');
$rule = [ $rule = [
'field' => ['regex' => '/^[a-z]([a-z]|_)+[a-z]$/i'], 'field' => ['regex' => '/^[a-z]([a-z]|_)+[a-z]$/i'],
@ -713,8 +716,8 @@ class Field extends Model
$new_default_value[] = str_replace(',', '', $v); $new_default_value[] = str_replace(',', '', $v);
} }
$data['default_value'] = implode(',', $new_default_value); $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']; $data['default_value'] = $data['default_value'];
} else { } else {
$data['default_value'] = ''; $data['default_value'] = '';
} }
@ -760,12 +763,12 @@ class Field extends Model
// 数值范围 // 数值范围
if (!empty($data['minNumRestrict'])) { if (!empty($data['minNumRestrict'])) {
$data['min_num_restrict'] = $data['minNumRestrict']; $data['min_num_restrict'] = $data['minNumRestrict'];
}else{ } else {
$data['min_num_restrict']=''; $data['min_num_restrict'] = '';
} }
if (!empty($data['maxNumRestrict'])){ if (!empty($data['maxNumRestrict'])) {
$data['max_num_restrict'] = $data['maxNumRestrict']; $data['max_num_restrict'] = $data['maxNumRestrict'];
}else{ } else {
$data['max_num_restrict'] = ''; $data['max_num_restrict'] = '';
} }
// 清除坐标 // 清除坐标
@ -978,7 +981,7 @@ class Field extends Model
if (!$resData) { if (!$resData) {
$delMessage[] = $dataInfo['name'] . ',删除失败'; $delMessage[] = $dataInfo['name'] . ',删除失败';
} }
//删除列表字段配置数据 //删除列表字段配置数据
$userFieldList = db('admin_user_field')->where(['types' => $dataInfo['types']])->select(); $userFieldList = db('admin_user_field')->where(['types' => $dataInfo['types']])->select();
foreach ($userFieldList as $key => $val) { foreach ($userFieldList as $key => $val) {
@ -1125,8 +1128,8 @@ class Field extends Model
'fieldName' => 'owner_user_structure_name' 'fieldName' => 'owner_user_structure_name'
]; ];
foreach ($field_list as $k => $v) { foreach ($field_list as $k => $v) {
if($v['field']=='invoice_type'){ if ($v['field'] == 'invoice_type') {
$field_list[$k]['setting']=$v['setting']?explode(chr(10), $v['setting']):[]; $field_list[$k]['setting'] = $v['setting'] ? explode(chr(10), $v['setting']) : [];
} }
# 处理字段授权 # 处理字段授权
$field_list[$k]['writeStatus'] = 1; $field_list[$k]['writeStatus'] = 1;
@ -1250,9 +1253,11 @@ class Field extends Model
// $new_field_list[] = db('admin_field')->where(['types_id' => 0, 'field' => 'owner_user_id'])->find(); // $new_field_list[] = db('admin_field')->where(['types_id' => 0, 'field' => 'owner_user_id'])->find();
// } // }
if ($new_field_list) $field_list = array_merge(collection($field_list)->toArray(), $new_field_list); if ($new_field_list) $field_list = array_merge(collection($field_list)->toArray(), $new_field_list);
$adminTypes = adminGroupTypes($user_id);
foreach ($field_list as $k => $v) { foreach ($field_list as $k => $v) {
# 处理字段授权 # 处理字段授权
$field_list[$k]['writeStatus'] = 1; $field_list[$k]['writeStatus'] = 1;
if ($field_list[$k]['name'] == '客户级别' && !in_array(1, $adminTypes)) $field_list[$k]['writeStatus'] = 0;
if (!$userLevel && $param['module'] == 'crm' && !empty($grantData[$param['types']])) { if (!$userLevel && $param['module'] == 'crm' && !empty($grantData[$param['types']])) {
$status = getFieldGrantStatus($v['field'], $grantData[$param['types']]); $status = getFieldGrantStatus($v['field'], $grantData[$param['types']]);
@ -1269,7 +1274,7 @@ class Field extends Model
} }
if ($param['action'] == 'read') { if ($param['action'] == 'read') {
$field_list[$k]['maskType'] = $status['maskType']; $field_list[$k]['maskType'] = $status['maskType'];
if($status['maskType']!=0){ if ($status['maskType'] != 0) {
$field_list[$k]['writeStatus'] = 0; $field_list[$k]['writeStatus'] = 0;
} }
} }
@ -1467,32 +1472,32 @@ class Field extends Model
} elseif ($v['form_type'] == 'desc_text') { } elseif ($v['form_type'] == 'desc_text') {
// 描述文字 // 描述文字
$value = !empty($dataInfo[$v['field']]) ? $dataInfo[$v['field']] : $v['default_value']; $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']); $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') : ''; $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) : ''; $positionData = !empty($positionJson) ? json_decode($positionJson, true) : '';
$value = $positionData; $value = $positionData;
} elseif($v['form_type']=='detail_table'){ } elseif ($v['form_type'] == 'detail_table') {
// $fieldGrant = db('admin_field_mask')->where('types', 'contract')->select(); // $fieldGrant = db('admin_field_mask')->where('types', 'contract')->select();
$primaryKey = getPrimaryKeyName($param['types']); $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') : ''; $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) : ''; $positionData = !empty($positionJson) ? json_decode($positionJson, true) : '';
foreach ($positionData as $kk => $val){ foreach ($positionData as $kk => $val) {
foreach ($val as $key => $values){ foreach ($val as $key => $values) {
if($values['form_type']=='user'){ if ($values['form_type'] == 'user') {
$positionData[$kk][$key]['value']= !empty($values['value'])?$userModel->getListByStr($values['value']) :[]; $positionData[$kk][$key]['value'] = !empty($values['value']) ? $userModel->getListByStr($values['value']) : [];
} }
if($values['form_type']=='structure'){ if ($values['form_type'] == 'structure') {
$positionData[$kk][$key]['value']= !empty($values['value'])? $structureModel->getListByStr($values['value']) : []; $positionData[$kk][$key]['value'] = !empty($values['value']) ? $structureModel->getListByStr($values['value']) : [];
} }
if($values['form_type']=='datetime' && is_numeric($values['value'])){ if ($values['form_type'] == 'datetime' && is_numeric($values['value'])) {
$positionData[$kk][$key]['value']= date('Y-m-d, H:i:s',$values['value']); $positionData[$kk][$key]['value'] = date('Y-m-d, H:i:s', $values['value']);
} }
if($values['form_type']=='boolean_value'){ if ($values['form_type'] == 'boolean_value') {
$positionData[$kk][$key]['value']= (string)$values['value']; $positionData[$kk][$key]['value'] = (string)$values['value'];
} }
if($values['form_type']=='file'){ if ($values['form_type'] == 'file') {
$fileIds = stringToArray($values['value']); $fileIds = stringToArray($values['value']);
$whereFile = []; $whereFile = [];
$whereFile['module'] = 'other'; $whereFile['module'] = 'other';
@ -1512,36 +1517,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]['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; $value = $positionData;
if ($v['form_type'] == 'detail_table') { if ($v['form_type'] == 'detail_table') {
$content = db('admin_field_extend')->where(['types' => $types, 'field' => $v['field']])->value('content'); $content = db('admin_field_extend')->where(['types' => $types, 'field' => $v['field']])->value('content');
$content=json_decode($content, true); $content = json_decode($content, true);
foreach ($content as &$vv){ foreach ($content as &$vv) {
$vv['optionsData']=!empty($field_list[$k]['options']) ? json_decode($field_list[$k]['options'], true) : ''; $vv['optionsData'] = !empty($field_list[$k]['options']) ? json_decode($field_list[$k]['options'], true) : '';
} }
$field_list[$k]['fieldExtendList'] = $content; $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) : []; $default_value = !empty($v['default_value']) ? json_decode($v['default_value'], true) : [];
if(!empty($dataInfo[$v['field']])){ if (!empty($dataInfo[$v['field']])) {
$position= explode(',',$dataInfo[$v['field']]); $position = explode(',', $dataInfo[$v['field']]);
for ($i=0; $i<count($position); $i++) { for ($i = 0; $i < count($position); $i++) {
$b[]['name'] =trim(json_encode($position[$i],JSON_UNESCAPED_UNICODE),'"'); $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']])) { if (!empty($dataInfo[$v['field']])) {
$position= explode('_',$dataInfo[$v['field']]); $position = explode('_', $dataInfo[$v['field']]);
$value =$position; $value = $position;
} }
$default_value = !empty($v['default_value'])?explode(',',$v['default_value']):[]; $default_value = !empty($v['default_value']) ? explode(',', $v['default_value']) : [];
} else { } else {
$value = isset($dataInfo[$v['field']]) ? $dataInfo[$v['field']] : ''; $value = isset($dataInfo[$v['field']]) ? $dataInfo[$v['field']] : '';
} }
@ -1814,7 +1819,7 @@ class Field extends Model
foreach ($dataList as $k => $v) { foreach ($dataList as $k => $v) {
if (!$userLevel && !empty($grantData[$types])) { if (!$userLevel && !empty($grantData[$types])) {
$status = getFieldGrantStatus($v['field'], $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]); if ($status['read'] == 0) unset($dataList[(int)$k]);
} }
@ -1859,7 +1864,7 @@ class Field extends Model
} }
$fieldArr = $this $fieldArr = $this
->where($where) ->where($where)
->field(['field', 'name', 'form_type', 'is_hidden','setting']) ->field(['field', 'name', 'form_type', 'is_hidden', 'setting'])
->order('order_id', 'asc') ->order('order_id', 'asc')
->select(); ->select();
@ -1874,7 +1879,7 @@ class Field extends Model
} }
if (isset($this->orther_field_list[$newTypes])) { if (isset($this->orther_field_list[$newTypes])) {
foreach ($this->orther_field_list[$newTypes] as $val) { foreach ($this->orther_field_list[$newTypes] as $val) {
if($val['field'] != 'product_picture'){ if ($val['field'] != 'product_picture') {
$res[] = $val; $res[] = $val;
} }
} }
@ -1916,8 +1921,8 @@ class Field extends Model
if ($types == 'jxc_product') { if ($types == 'jxc_product') {
$res[] = [ $res[] = [
'field' => 'product_picture', 'field' => 'product_picture',
'name' => '产品图片', 'name' => '产品图片',
'form_type' => 'pic', 'form_type' => 'pic',
'is_hidden' => 0 'is_hidden' => 0
]; ];
@ -2229,7 +2234,7 @@ class Field extends Model
if ($types == 'jxc_product') { if ($types == 'jxc_product') {
$where['is_del'] = 0; $where['is_del'] = 0;
} }
$res = $dataModel->where($where)->find(); $res = $dataModel->where($where)->find();
if ($res) { if ($res) {
@ -2340,35 +2345,35 @@ class Field extends Model
$val = db('jxc_purchase')->where(['purchase_id' => $val])->value('order_number'); $val = db('jxc_purchase')->where(['purchase_id' => $val])->value('order_number');
break; break;
case 'order_cause' : case 'order_cause' :
if($dataInfo['receipt_type'] == '销售退货入库'){ if ($dataInfo['receipt_type'] == '销售退货入库') {
$val = db('jxc_salereturn')->where(['salereturn_id' => $val])->value('order_number'); $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'); $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'); $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'); $val = db('jxc_retreat')->where(['retreat_id' => $val])->value('order_number');
} }
break; break;
case 'category_cause' : case 'category_cause' :
$val = db('jxc_product_category')->where(['category_id' => $val])->value('category_name'); $val = db('jxc_product_category')->where(['category_id' => $val])->value('category_name');
break; break;
case 'product_cause' : case 'product_cause' :
$val = db('jxc_product')->where(['product_id' => $val])->value('product_name'); $val = db('jxc_product')->where(['product_id' => $val])->value('product_name');
break; break;
case 'collection_object' : case 'collection_object' :
if($dataInfo['collection_type'] == '采购退货'){ if ($dataInfo['collection_type'] == '采购退货') {
// $val = db('jxc_supplier')->where(['supplier_id' => $val])->value('supplier_name'); // $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'); $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'); $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'); $val = db('jxc_salereturn')->where(['salereturn_id' => $val])->value('order_number');
} }
break; break;
} }
return $val; return $val;
} }
@ -2414,13 +2419,13 @@ class Field extends Model
} }
if (!$data) return $data; if (!$data) return $data;
$list = db('admin_field')->where(['types' => $types, 'relevant' => ['neq', '']])->field('field,relevant')->select(); $list = db('admin_field')->where(['types' => $types, 'relevant' => ['neq', '']])->field('field,relevant')->select();
foreach ($list as &$val){ foreach ($list as &$val) {
$val=!empty($val)?$val:''; $val = !empty($val) ? $val : '';
} }
$newData = []; $newData = [];
//crm_hfsomz //crm_hfsomz
foreach ($list as $k => $v) { 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']]; $newData[$customer_field['field']] = $data[$v['field']];
} }
return $newData ?: []; return $newData ?: [];
@ -2668,7 +2673,7 @@ class Field extends Model
*/ */
public function getFieldTypesArray($types, $form_type) 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 = []; $fieldList = [];
$userField = []; // 人员类型 $userField = []; // 人员类型
$structureField = []; // 部门类型 $structureField = []; // 部门类型

@ -9,6 +9,7 @@ namespace app\admin\model;
use app\admin\model\ImportRecord as ImportRecordModel; use app\admin\model\ImportRecord as ImportRecordModel;
use app\admin\model\User as UserModel; use app\admin\model\User as UserModel;
use app\crm\model\Contract as ContractModel; use app\crm\model\Contract as ContractModel;
use app\crm\model\CustomerCheck;
use app\crm\model\Invoice; use app\crm\model\Invoice;
use app\crm\model\Receivables as ReceivablesModel; use app\crm\model\Receivables as ReceivablesModel;
use app\oa\model\Announcement as AnnouncementModel; use app\oa\model\Announcement as AnnouncementModel;
@ -265,7 +266,35 @@ class Message extends Common
* 盘点审批通过 * 盘点审批通过
*/ */
const INVENTORY_PASS = 56; const INVENTORY_PASS = 56;
/**
* 客户待审批
*/
const CUSTOMER_CHECK_TO_DO = 57;
/**
* 客户待审批
*/
const CUSTOMER_CHECK_REJECT = 58;
/**
* 客户待审批
*/
const CUSTOMER_CHECK_PASS = 59;
/**
* 商机推进待审批
*/
const BUSINESS_ADVANCE_CHECK_TO_DO = 60;
/**
* 商机推进待审批
*/
const BUSINESS_ADVANCE_CHECK_REJECT = 61;
/**
* 商机推进待审批
*/
const BUSINESS_ADVANCE_CHECK_PASS = 62;
/**
* 新商机
*/
const BUSINESS_NEW = 63;
/** /**
* 消息类型 * 消息类型
* *
@ -376,6 +405,9 @@ class Message extends Common
32 => [ 32 => [
'template' => '{from_user} 将您添加为线索 {title} 的成员。', 'template' => '{from_user} 将您添加为线索 {title} 的成员。',
], ],
63 => [
'template' => '{from_user} 创建了新的商机',
]
]; ];
/** /**
@ -423,6 +455,13 @@ class Message extends Common
self::BUSINESS_PASS, self::BUSINESS_PASS,
self::CUSTOMER_PASS, self::CUSTOMER_PASS,
self::CONTRACT_END, self::CONTRACT_END,
self::CUSTOMER_CHECK_TO_DO,
self::CUSTOMER_CHECK_REJECT,
self::CUSTOMER_CHECK_PASS,
self::BUSINESS_ADVANCE_CHECK_TO_DO,
self::BUSINESS_ADVANCE_CHECK_REJECT,
self::BUSINESS_ADVANCE_CHECK_PASS,
self::BUSINESS_NEW,
], ],
'jxc' => [ 'jxc' => [
self::PURCHASE_TO_DO, self::PURCHASE_TO_DO,
@ -482,7 +521,7 @@ class Message extends Common
foreach ($data as $key => $val) { foreach ($data as $key => $val) {
$content = str_replace('{' . $key . '}', $val, $content); $content = str_replace('{' . $key . '}', $val, $content);
} }
$advance_time= $data['advance_time']; $advance_time = $data['advance_time'];
$content = str_replace('{from_user}', User::userInfo('realname'), $content); $content = str_replace('{from_user}', User::userInfo('realname'), $content);
$content = str_replace('{date}', date('Y-m-d'), $content); $content = str_replace('{date}', date('Y-m-d'), $content);
$data = []; $data = [];
@ -499,7 +538,7 @@ class Message extends Common
$data['action_name'] = strtolower($request->action()); $data['action_name'] = strtolower($request->action());
$from_user_id = $data['from_user_id']; $from_user_id = $data['from_user_id'];
if (!in_array($type,[9,17,18,19,20,27])) { if (!in_array($type, [9, 17, 18, 19, 20, 27])) {
$user_id_list = array_filter($user_id_list, function ($val) use ($from_user_id) { $user_id_list = array_filter($user_id_list, function ($val) use ($from_user_id) {
return $val !== $from_user_id; return $val !== $from_user_id;
}); });
@ -559,7 +598,11 @@ class Message extends Common
case self::CONTRACT_PASS: case self::CONTRACT_PASS:
case self::TEAM_CONTRACT: case self::TEAM_CONTRACT:
return ContractModel::where(['contract_id' => $data['action_id']])->value('name') ?: ''; return ContractModel::where(['contract_id' => $data['action_id']])->value('name') ?: '';
// 客户
case self::CUSTOMER_CHECK_TO_DO:
case self::CUSTOMER_CHECK_PASS:
case self::CUSTOMER_CHECK_REJECT:
return CustomerCheck::where(['customer_check_id' => $data['action_id']])->value('name') ?: '';
// 回款 // 回款
case self::RECEIVABLES_TO_DO: case self::RECEIVABLES_TO_DO:
case self::RECEIVABLES_REJECT: case self::RECEIVABLES_REJECT:
@ -589,6 +632,10 @@ class Message extends Common
// 商机 // 商机
case self::TEAM_BUSINESS: case self::TEAM_BUSINESS:
case self::BUSINESS_PASS: 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') ?: ''; return BusinessModel::where(['business_id' => $data['action_id']])->value('name') ?: '';
// 采购单 // 采购单

@ -13,6 +13,7 @@ use app\admin\model\Common;
use com\verify\HonrayVerify; use com\verify\HonrayVerify;
use think\Cache; use think\Cache;
use think\Request; use think\Request;
use think\Session;
class User extends Common class User extends Common
{ {
@ -647,8 +648,15 @@ class User extends Common
$data['loginExpire'] = $loginExpire; $data['loginExpire'] = $loginExpire;
//保存authKey信息 //保存authKey信息
$userData = []; $userData = [];
$userData['authkey'] = $authKey;
$userData['authkey_time'] = time() + $loginExpire; $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) { if ($userInfo['status'] == 2) {
$userData['status'] = 1; $userData['status'] = 1;

@ -69,7 +69,11 @@ function resultArray($array)
$array['data'] = ''; $array['data'] = '';
} elseif (isset($array['error'])) { } elseif (isset($array['error'])) {
$code = 400; $code = 400;
$array['data'] = ''; $array['data'] = '操作失败';
} elseif (isset($array['success'])) {
$array['error'] = '';
$array['data'] =$array['success'] ;
$code = 200;
} }
return json([ return json([
'code' => $code, 'code' => $code,
@ -390,138 +394,138 @@ function advancedQuery($param, $m = '', $c = '', $a = '')
// 创建人、负责人 // 创建人、负责人
if (in_array($key, ['create_user_id', 'owner_user_id'])) { if (in_array($key, ['create_user_id', 'owner_user_id'])) {
if($value['condition'] == 'contains'){ if ($value['condition'] == 'contains') {
$result[$c . $key] = ['in', $value['value']]; $result[$c . $key] = ['in', $value['value']];
}else if ($value['condition'] == 'notContains') { } else if ($value['condition'] == 'notContains') {
$result[$c . $key] = ['not in', $value['value']]; $result[$c . $key] = ['not in', $value['value']];
}else if ($value['condition'] == 'isNull') { } else if ($value['condition'] == 'isNull') {
$result[$c . $key] = ['eq', '']; $result[$c . $key] = ['eq', ''];
}else if ($value['condition'] == 'isNotNull') { } else if ($value['condition'] == 'isNotNull') {
$result[$c . $key] = ['neq', '']; $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); $res = advancedQueryFormatForCommon($value['value'], $value['condition'], $value['form_type'], $key);
if($key == 'order_id'){ if ($key == 'order_id') {
$arr = []; $arr = [];
if($c == 'outbound.'){ if ($c == 'outbound.') {
$retreatOutboundIds = db('jxc_retreat') $retreatOutboundIds = db('jxc_retreat')
->alias('a') ->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('a.order_number', [$res[0], $res[1]])
->where('b.outbound_type', '采购退货出库') ->where('b.outbound_type', '采购退货出库')
// ->fetchSql() // ->fetchSql()
->column('outbound_id'); ->column('outbound_id');
$saleOutboundIds = db('jxc_sale') $saleOutboundIds = db('jxc_sale')
->alias('a') ->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('a.order_number', [$res[0], $res[1]])
->where('b.outbound_type', '销售出库') ->where('b.outbound_type', '销售出库')
// ->fetchSql() // ->fetchSql()
->column('outbound_id'); ->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]; $result[$c . 'outbound_id'] = ['in', $arr];
}elseif ($c == 'receipt.') { } elseif ($c == 'receipt.') {
$purchaseOutboundIds = db('jxc_purchase') $purchaseOutboundIds = db('jxc_purchase')
->alias('a') ->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('a.order_number', [$res[0], $res[1]])
->where('b.receipt_type', '采购入库') ->where('b.receipt_type', '采购入库')
// ->fetchSql() // ->fetchSql()
->column('b.receipt_id'); ->column('b.receipt_id');
$salereturnOutboundIds = db('jxc_salereturn') $salereturnOutboundIds = db('jxc_salereturn')
->alias('a') ->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('a.order_number', [$res[0], $res[1]])
->where('b.receipt_type', '销售退货入库') ->where('b.receipt_type', '销售退货入库')
// ->fetchSql() // ->fetchSql()
->column('b.receipt_id'); ->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]; $result[$c . 'receipt_id'] = ['in', $arr];
} }
}else if($key == 'related_id'){ } else if ($key == 'related_id') {
$arr = []; $arr = [];
if($c == 'collection.'){ if ($c == 'collection.') {
$retreatOutboundIds = db('jxc_retreat') $retreatOutboundIds = db('jxc_retreat')
->alias('a') ->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('a.order_number', [$res[0], $res[1]])
->where('b.collection_type', '采购退货') ->where('b.collection_type', '采购退货')
// ->fetchSql() // ->fetchSql()
->column('collection_note_id'); ->column('collection_note_id');
$saleOutboundIds = db('jxc_sale') $saleOutboundIds = db('jxc_sale')
->alias('a') ->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('a.order_number', [$res[0], $res[1]])
->where('b.collection_type', '销售回款') ->where('b.collection_type', '销售回款')
// ->fetchSql() // ->fetchSql()
->column('collection_note_id'); ->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]; $result[$c . 'collection_note_id'] = ['in', $arr];
}elseif ($c == 'payment.') { } elseif ($c == 'payment.') {
$purchaseOutboundIds = db('jxc_purchase') $purchaseOutboundIds = db('jxc_purchase')
->alias('a') ->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('a.order_number', [$res[0], $res[1]])
->where('b.payment_type', '采购') ->where('b.payment_type', '采购')
// ->fetchSql() // ->fetchSql()
->column('b.payment_note_id'); ->column('b.payment_note_id');
$salereturnOutboundIds = db('jxc_salereturn') $salereturnOutboundIds = db('jxc_salereturn')
->alias('a') ->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('a.order_number', [$res[0], $res[1]])
->where('b.payment_type', '销售退货') ->where('b.payment_type', '销售退货')
// ->fetchSql() // ->fetchSql()
->column('b.payment_note_id'); ->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]; $result[$c . 'payment_note_id'] = ['in', $arr];
} }
}else if($key == 'collection_object'){ } else if ($key == 'collection_object') {
$arr = []; $arr = [];
if($c == 'collection.'){ if ($c == 'collection.') {
$supplierOutboundIds = db('jxc_supplier') $supplierOutboundIds = db('jxc_supplier')
->alias('a') ->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('a.supplier_name', [$res[0], $res[1]])
->where('b.collection_type', '采购退货') ->where('b.collection_type', '采购退货')
// ->fetchSql() // ->fetchSql()
->column('collection_note_id'); ->column('collection_note_id');
$customerOutboundIds = db('crm_customer') $customerOutboundIds = db('crm_customer')
->alias('a') ->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('a.name', [$res[0], $res[1]])
->where('b.collection_type', '销售回款') ->where('b.collection_type', '销售回款')
// ->fetchSql() // ->fetchSql()
->column('collection_note_id'); ->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]; $result[$c . 'collection_note_id'] = ['in', $arr];
}elseif ($c == 'payment.') { } elseif ($c == 'payment.') {
$supplierOutboundIds = db('jxc_supplier') $supplierOutboundIds = db('jxc_supplier')
->alias('a') ->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('a.supplier_name', [$res[0], $res[1]])
->where('b.payment_type', '采购') ->where('b.payment_type', '采购')
// ->fetchSql() // ->fetchSql()
->column('b.payment_note_id'); ->column('b.payment_note_id');
$customerOutboundIds = db('crm_customer') $customerOutboundIds = db('crm_customer')
->alias('a') ->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('a.name', [$res[0], $res[1]])
->where('b.payment_type', '销售退货') ->where('b.payment_type', '销售退货')
// ->fetchSql() // ->fetchSql()
->column('b.payment_note_id'); ->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]; $result[$c . 'payment_note_id'] = ['in', $arr];
} }
// }else if($key == 'sp_data_value'){ // }else if($key == 'sp_data_value'){
// foreach ($res[1] as $key => $v) { // foreach ($res[1] as $key => $v) {
// $arr[] = '%'.$v.'%'; // $arr[] = '%'.$v.'%';
// } // }
// $w['sp_data_value'] = ['like', $arr, 'OR']; // $w['sp_data_value'] = ['like', $arr, 'OR'];
// $product_ids = db('jxc_product')->where($w)->fetchSql()->column('product_id'); // $product_ids = db('jxc_product')->where($w)->fetchSql()->column('product_id');
// $result[$c . 'sp_data_value'] = [$res[0], $product_ids]; // $result[$c . 'sp_data_value'] = [$res[0], $product_ids];
}else{ } else {
$result[$c . $key] = advancedQueryFormatForCommon($value['value'], $value['condition'], $value['form_type'], $key); $result[$c . $key] = advancedQueryFormatForCommon($value['value'], $value['condition'], $value['form_type'], $key);
} }
} }
@ -729,9 +733,9 @@ function advancedQueryFormatForCommon($data, $condition, $formType, $key)
if (in_array($formType, ['checkbox']) && $condition == 'isNot') $condition = 'notContains'; 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); $data = advancedQueryDataUserform($data, $condition);
}elseif (in_array($condition, ['contains', 'notContains', 'startWith', 'endWith'])){ } elseif (in_array($condition, ['contains', 'notContains', 'startWith', 'endWith'])) {
$data = advancedQueryDataTransform($data, $condition); $data = advancedQueryDataTransform($data, $condition);
} }
@ -753,7 +757,7 @@ function advancedQueryFormatForCommon($data, $condition, $formType, $key)
$data[0] = str_replace('已作废', 6, $data[0]); $data[0] = str_replace('已作废', 6, $data[0]);
} }
return advancedQueryWhere($condition, $data,$key); return advancedQueryWhere($condition, $data, $key);
} }
/** /**
@ -765,7 +769,7 @@ function advancedQueryFormatForCommon($data, $condition, $formType, $key)
* @since 2021-05-22 * @since 2021-05-22
* @author fanqi * @author fanqi
*/ */
function advancedQueryWhere($condition, $data, $key='') function advancedQueryWhere($condition, $data, $key = '')
{ {
$result = []; $result = [];
@ -774,9 +778,9 @@ function advancedQueryWhere($condition, $data, $key='')
if ($condition == "in") $result = ['in', $data]; // 等于 if ($condition == "in") $result = ['in', $data]; // 等于
if ($condition == 'is') $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 == '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 == 'startWith') $result = ['like', $data, 'OR']; // 开始于
if ($condition == 'endWith') $result = ['like', $data, 'OR']; // 结束于 if ($condition == 'endWith') $result = ['like', $data, 'OR']; // 结束于
if ($condition == 'gt') $result = ['gt', $data]; // 大于 if ($condition == 'gt') $result = ['gt', $data]; // 大于
@ -787,8 +791,8 @@ function advancedQueryWhere($condition, $data, $key='')
if ($condition == 'range') $result = ['between', $data]; // 处于某个时间段 if ($condition == 'range') $result = ['between', $data]; // 处于某个时间段
if ($condition == 'isNull') $result = [['eq', ''], ['null'], 'OR']; // 为空 if ($condition == 'isNull') $result = [['eq', ''], ['null'], 'OR']; // 为空
if ($condition == 'isNotNull') $result = [['neq', ''], ['not null'], 'AND']; // 不为空 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 == '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 == 'notContains' && in_array($key, ['create_user_id', 'owner_user_id'])) $result = ['notin', $data]; // 暂定为创建人 负责人不包含
return $result; return $result;
} }
@ -834,7 +838,8 @@ function advancedQueryDataTransform($data, $condition)
* @version: 11.1.0 * @version: 11.1.0
* Date: 2021/9/2 14:44 * Date: 2021/9/2 14:44
*/ */
function advancedQueryDataUserform($data, $condition){ function advancedQueryDataUserform($data, $condition)
{
if (in_array($condition, ['contains', 'notContains'])) { if (in_array($condition, ['contains', 'notContains'])) {
array_walk($data, function ($value, $key) use (&$data) { array_walk($data, function ($value, $key) use (&$data) {
$data[$key] = $value; $data[$key] = $value;
@ -842,6 +847,7 @@ function advancedQueryDataUserform($data, $condition){
} }
return $data; return $data;
} }
/** /**
* 等于(时间段)数据处理 * 等于(时间段)数据处理
* *
@ -2891,7 +2897,7 @@ if (!function_exists('getFieldGrantStatus')) {
function getFieldGrantStatus($field, $grantData) function getFieldGrantStatus($field, $grantData)
{ {
# 默认状态都是不能查看、不能编辑,通过配置来取最大权限。 # 默认状态都是不能查看、不能编辑,通过配置来取最大权限。
$result = ['read' => 0, 'write' => 0,'maskType'=>0]; $result = ['read' => 0, 'write' => 0, 'maskType' => 0];
foreach ($grantData as $key => $value) { foreach ($grantData as $key => $value) {
$fieldBool = false; $fieldBool = false;
@ -2906,7 +2912,7 @@ if (!function_exists('getFieldGrantStatus')) {
$result['write'] = $va['write'] > $result['write'] ? $va['write'] : $result['write']; $result['write'] = $va['write'] > $result['write'] ? $va['write'] : $result['write'];
} }
if ($va['field'] == $field && $va['maskType'] != 0) { 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; if ($va['field'] == $field) $fieldBool = true;
} }
@ -3301,50 +3307,50 @@ function advancedQueryFormatForTeam($requestMap, $c, $db_id)
// $result[$c . 'rw_user_id'] = advancedQueryFormatForPersonnel($v['value'], $v['condition']); // $result[$c . 'rw_user_id'] = advancedQueryFormatForPersonnel($v['value'], $v['condition']);
// } // }
// } // }
$date=[]; $date = [];
$date2=[]; $date2 = [];
$condition=$requestMap['condition']; $condition = $requestMap['condition'];
$z=''; $z = '';
foreach ($requestMap['value'] as $val){ foreach ($requestMap['value'] as $val) {
if($condition=='contains'){ if ($condition == 'contains') {
$z='like'; $z = 'like';
$val="'".'%,'.$val.',%'."'"; $val = "'" . '%,' . $val . ',%' . "'";
}elseif($condition=='notContains'){ } elseif ($condition == 'notContains') {
$z='NOT LIKE'; $z = 'NOT LIKE';
$val="'".'%,'.$val.',%'."'"; $val = "'" . '%,' . $val . ',%' . "'";
} }
$date[]=$prefix.'ro_user_id '.$z.$val; $date[] = $prefix . 'ro_user_id ' . $z . $val;
$date2[]=$prefix.'rw_user_id '.$z.$val; $date2[] = $prefix . 'rw_user_id ' . $z . $val;
} }
if($condition =='isNull'){ if ($condition == 'isNull') {
$z='IS NULL'; $z = 'IS NULL';
$date[]=$prefix.'ro_user_id '.'= '."''"; $date[] = $prefix . 'ro_user_id ' . '= ' . "''";
$date2[]=$prefix.'rw_user_id '.'= '."''"; $date2[] = $prefix . 'rw_user_id ' . '= ' . "''";
}elseif($condition =='isNotNull'){ } elseif ($condition == 'isNotNull') {
$z='IS NOT NULL'; $z = 'IS NOT NULL';
$date[]=$prefix.'ro_user_id '.'<> '."''"; $date[] = $prefix . 'ro_user_id ' . '<> ' . "''";
$date2[]=$prefix.'rw_user_id '.'<> '."''"; $date2[] = $prefix . 'rw_user_id ' . '<> ' . "''";
} }
if($date && $date2){ if ($date && $date2) {
$rest=''; $rest = '';
$date=implode('OR ', $date); $date = implode('OR ', $date);
$date2=implode('OR ', $date2); $date2 = implode('OR ', $date2);
$type=''; $type = '';
switch ($z){ switch ($z) {
case 'like': case 'like':
$rest='('.$date.')'.'OR'.'('.$date2.')'; $rest = '(' . $date . ')' . 'OR' . '(' . $date2 . ')';
break; break;
case 'NOT LIKE': case 'NOT LIKE':
$rest='('.$date.')'.'AND'.'('.$date2.')'; $rest = '(' . $date . ')' . 'AND' . '(' . $date2 . ')';
break; break;
case 'IS NULL': case 'IS NULL':
$rest='('.$date.')'.'OR'.'('.$date2.')'; $rest = '(' . $date . ')' . 'OR' . '(' . $date2 . ')';
break; break;
case 'IS NOT NULL': case 'IS NOT NULL':
$rest='('.$date.')'.'AND'.'('.$date2.')'; $rest = '(' . $date . ')' . 'AND' . '(' . $date2 . ')';
break; break;
default: default:
break; break;
@ -3363,15 +3369,15 @@ function advancedQueryFormatForTeam($requestMap, $c, $db_id)
*/ */
function getUserSuperior($structure_id, $level = 0) 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'); $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'); $pid = db('admin_structure')->where('id', $structure_id)->value('pid');
$owner_user_id = db('admin_structure')->where('id', $pid)->value('owner_user_id'); $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'); $pid = db('admin_structure')->where('id', $structure_id)->value('pid');
return getUserSuperior($pid, $level-1); return getUserSuperior($pid, $level - 1);
} }
return $owner_user_id; return $owner_user_id;

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

@ -23,20 +23,20 @@ class PoolCommand extends Command
{ {
protected $timer; protected $timer;
protected $interval = 10; protected $interval = 10;
protected function configure() protected function configure()
{ {
$this->setName('pool') $this->setName('pool')
->addArgument('status', Argument::REQUIRED, 'start/stop/reload/status/connections') ->addArgument('status', Argument::REQUIRED, 'start/stop/reload/status/connections')
->addOption('d', null, Option::VALUE_NONE, 'daemon守护进程方式启动') ->addOption('d', null, Option::VALUE_NONE, 'daemon守护进程方式启动')
->setDescription('公海回收定时器'); ->setDescription('公海回收定时器');
// 读取数据库配置文件 // 读取数据库配置文件
$filename = ROOT_PATH . 'config' . DS . 'database.php'; $filename = ROOT_PATH . 'config' . DS . 'database.php';
// 重新加载数据库配置文件 // 重新加载数据库配置文件
Config::load($filename, 'database'); Config::load($filename, 'database');
} }
/** /**
* 初始化 * 初始化
* *
@ -46,16 +46,16 @@ class PoolCommand extends Command
protected function init(Input $input, Output $output) protected function init(Input $input, Output $output)
{ {
global $argv; global $argv;
$argv[1] = $input->getArgument('status') ?: 'start'; $argv[1] = $input->getArgument('status') ?: 'start';
if ($input->hasOption('d')) { if ($input->hasOption('d')) {
$argv[2] = '-d'; $argv[2] = '-d';
} else { } else {
unset($argv[2]); unset($argv[2]);
} }
} }
/** /**
* 停止定时器 * 停止定时器
*/ */
@ -63,7 +63,7 @@ class PoolCommand extends Command
{ {
Timer::del($this->timer); Timer::del($this->timer);
} }
/** /**
* 启动定时器 * 启动定时器
*/ */
@ -72,46 +72,51 @@ class PoolCommand extends Command
$this->timer = Timer::add($this->interval, function () { $this->timer = Timer::add($this->interval, function () {
# 只在凌晨12点至6点间执行 # 只在凌晨12点至6点间执行
if ((int)date('H') >= 0 && (int)date('H') < 6) { if ((int)date('H') >= 0 && (int)date('H') < 6) {
# 公海规则 $this->poolRecover();
$ruleList = db('crm_customer_pool_rule')->alias('rule')->field('rule.*')
->join('__CRM_CUSTOMER_POOL__ pool', 'pool.pool_id = rule.pool_id', 'LEFT')->where('pool.status', 1)->select();
if (!empty($ruleList)) {
# 符合公海条件的客户IDS
$customerIds = $this->getQueryCondition($ruleList);
# 整理客户公海关联数据
$poolRelationData = $this->getCustomerPoolRelationData($customerIds);
# 整理修改客户数据的条件(进入公海时间,前负责人...
$customerWhere = $this->getCustomerQueryCondition($customerIds);
Db::startTrans();
try {
# 将客户退回公海
if (!empty($poolRelationData)) Db::name('crm_customer_pool_relation')->insertAll($poolRelationData);
# 修改客户数据
if (!empty($customerWhere)) {
Db::name('crm_customer')->whereIn('customer_id', $customerWhere)->exp('before_owner_user_id', 'owner_user_id')->update([
'ro_user_id' => '',
'rw_user_id' => '',
'owner_user_id' => 0,
'into_pool_time' => time()
]);
}
$this->updateInfo($ruleList,$customerWhere);
# 删除联系人的负责人
Db::name('crm_contacts')->whereIn('customer_id', $customerWhere)->update(['owner_user_id' => '']);
Db::commit();
} catch (\Exception $e) {
Db::rollback();
}
}
} }
}); });
} }
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();
if (!empty($ruleList)) {
# 符合公海条件的客户IDS
$customerIds = PoolCommand::getQueryCondition($ruleList);
# 整理客户公海关联数据
$poolRelationData = PoolCommand::getCustomerPoolRelationData($customerIds);
# 整理修改客户数据的条件(进入公海时间,前负责人...
$customerWhere = PoolCommand::getCustomerQueryCondition($customerIds);
Db::startTrans();
try {
# 将客户退回公海
if (!empty($poolRelationData)) Db::name('crm_customer_pool_relation')->insertAll($poolRelationData);
# 修改客户数据
if (!empty($customerWhere)) {
Db::name('crm_customer')->whereIn('customer_id', $customerWhere)->exp('before_owner_user_id', 'owner_user_id')->update([
'ro_user_id' => '',
'rw_user_id' => '',
'owner_user_id' => 0,
'into_pool_time' => time()
]);
}
PoolCommand::updateInfo($ruleList, $customerWhere);
# 删除联系人的负责人
Db::name('crm_contacts')->whereIn('customer_id', $customerWhere)->update(['owner_user_id' => '']);
Db::commit();
} catch (\Exception $e) {
Db::rollback();
}
}
}
/** /**
* 自动入公海操作记录 * 自动入公海操作记录
* @param $ruleList * @param $ruleList
@ -129,28 +134,27 @@ class PoolCommand extends Command
if (!empty($v1['limit_day'])) { if (!empty($v1['limit_day'])) {
$time = $v1['limit_day']; $time = $v1['limit_day'];
} else { } else {
$time = $this->getMinDay($levels); $time = PoolCommand::getMinDay($levels);
} }
} }
foreach ($customerWhere as $val) { foreach ($customerWhere as $val) {
if ($v['type'] == 1) updateActionLog(0, 'crm_customer', $val, '', '', '超过' . $time . '天无新建跟进记录自动进入公海'); if ($v['type'] == 1) updateActionLog(0, 'crm_customer', $val, '', '', '超过' . $time . '天无新建跟进记录自动进入公海');
if ($v['type'] == 2) updateActionLog(0, 'crm_customer', $val, '', '', '超过' . $time . '天无新建商机自动进入公海'); if ($v['type'] == 2) updateActionLog(0, 'crm_customer', $val, '', '', '超过' . $time . '天无新建商机自动进入公海');
if ($v['type'] == 3) updateActionLog(0, 'crm_customer', $val, '', '', '超过' . $time . '天未成交自动进入公海'); if ($v['type'] == 3) updateActionLog(0, 'crm_customer', $val, '', '', '超过' . $time . '天未成交自动进入公海');
} }
} }
} }
protected function execute(Input $input, Output $output) protected function execute(Input $input, Output $output)
{ {
# 动态修改运行时参数 # 动态修改运行时参数
set_time_limit(0); set_time_limit(0);
ini_set('memory_limit', '512M'); ini_set('memory_limit', '512M');
$this->init($input, $output); $this->init($input, $output);
# 创建定时器任务 # 创建定时器任务
$task = new Worker(); $task = new Worker();
$task->name = 'pool'; $task->name = 'pool';
@ -158,7 +162,7 @@ class PoolCommand extends Command
$task->onWorkerStart = [$this, 'start']; $task->onWorkerStart = [$this, 'start'];
$task->runAll(); $task->runAll();
} }
/** /**
* 整理修改客户数据的条件 * 整理修改客户数据的条件
* *
@ -170,16 +174,16 @@ class PoolCommand extends Command
private function getCustomerQueryCondition($customerIds) private function getCustomerQueryCondition($customerIds)
{ {
$result = []; $result = [];
foreach ($customerIds as $k1 => $v1) { foreach ($customerIds as $k1 => $v1) {
foreach ($v1 as $k2 => $v2) { foreach ($v1 as $k2 => $v2) {
$result[] = $v2; $result[] = $v2;
} }
} }
return array_unique($result); return array_unique($result);
} }
/** /**
* 客户公海关联数据 * 客户公海关联数据
* *
@ -191,27 +195,27 @@ class PoolCommand extends Command
private function getCustomerPoolRelationData($customerIds) private function getCustomerPoolRelationData($customerIds)
{ {
$result = []; $result = [];
# 用于排重 # 用于排重
$repeat = []; $repeat = [];
foreach ($customerIds as $k1 => $v1) { foreach ($customerIds as $k1 => $v1) {
$customerArray = array_unique($v1); $customerArray = array_unique($v1);
foreach ($customerArray as $k2 => $v2) { foreach ($customerArray as $k2 => $v2) {
if (!empty($repeat[$k1][$v2])) continue; if (!empty($repeat[$k1][$v2])) continue;
$result[] = [ $result[] = [
'pool_id' => $k1, 'pool_id' => $k1,
'customer_id' => $v2 'customer_id' => $v2
]; ];
$repeat[$k1][$v2] = $v2; $repeat[$k1][$v2] = $v2;
} }
} }
return $result; return $result;
} }
/** /**
* 获取符合公海条件的客户 * 获取符合公海条件的客户
* *
@ -223,18 +227,18 @@ class PoolCommand extends Command
private function getQueryCondition($rules) private function getQueryCondition($rules)
{ {
$result = []; $result = [];
foreach ($rules as $k => $v) { foreach ($rules as $k => $v) {
if (!isset($result[$v['pool_id']])) $result[$v['pool_id']] = []; if (!isset($result[$v['pool_id']])) $result[$v['pool_id']] = [];
if ($v['type'] == 1) $result[$v['pool_id']] = array_merge($result[$v['pool_id']], $this->getFollowUpQueryResult($v['level_conf'], $v['level'], $v['deal_handle'], $v['business_handle'])); if ($v['type'] == 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']], $this->getBusinessQueryResult($v['level_conf'], $v['level'], $v['deal_handle'])); 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']], $this->getDealQueryResult($v['level_conf'], $v['level'], $v['business_handle'])); 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']));
} }
return $result; return $result;
} }
/** /**
* N天内无新建跟进记录的客户 * N天内无新建跟进记录的客户
* *
@ -246,14 +250,14 @@ class PoolCommand extends Command
* @since 2021-04-01 * @since 2021-04-01
* @author fanqi * @author fanqi
*/ */
private function getFollowUpQueryResult($type, $levels, $dealStatus, $businessStatus) private function getFollowUpQueryResult($type, $levels, $dealStatus, $businessStatus, $customerType)
{ {
# 转换格式 # 转换格式
$levels = json_decode($levels, true); $levels = json_decode($levels, true);
# 默认条件 # 默认条件
$where = "`customer`.`owner_user_id` > 0"; $where = "`customer`.`owner_user_id` > 0";
# 所有用户,不区分级别 # 所有用户,不区分级别
if ($type == 1) { if ($type == 1) {
foreach ($levels as $k1 => $v1) { foreach ($levels as $k1 => $v1) {
@ -263,7 +267,7 @@ class PoolCommand extends Command
} }
} }
} }
# 根据用户级别设置条件 # 根据用户级别设置条件
if ($type == 2) { if ($type == 2) {
foreach ($levels as $k1 => $v1) { foreach ($levels as $k1 => $v1) {
@ -276,29 +280,29 @@ class PoolCommand extends Command
} }
} }
} }
# 获取最小天数,对于没有设置级别的客户数据使用 # 获取最小天数,对于没有设置级别的客户数据使用
$minLimit = $this->getMinDay($levels); $minLimit = PoolCommand::getMinDay($levels);
$minTime = (time() - 24 * 60 * 60 * $minLimit); $minTime = (time() - 24 * 60 * 60 * $minLimit);
$where .= " OR ((!`customer`.`level` AND `customer`.`last_time` < " . $minTime . " AND `customer`.`last_time` > `customer`.`obtain_time`) OR (!`customer`.`level` AND `customer`.`obtain_time` < " . $minTime . " AND `customer`.`obtain_time` > `customer`.`last_time`) OR (!`customer`.`level` AND `customer`.`obtain_time` < " . $minTime . " AND ISNULL(`customer`.`last_time`))) )"; $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`))) )";
} }
# 选择不进入公海的客户(已成交客户) # 选择不进入公海的客户(已成交客户)
if (!empty($dealStatus)) $where .= " AND (`customer`.`deal_status` <> '已成交' OR ISNULL(`customer`.`deal_status`))"; if (!empty($dealStatus)) $where .= " AND (`customer`.`deal_status` <> '已成交' OR ISNULL(`customer`.`deal_status`))";
# 选择不进入公海的客户(有商机客户) # 选择不进入公海的客户(有商机客户)
if (!empty($businessStatus)) $where .= " AND ISNULL(`business`.`customer_id`)"; if (!empty($businessStatus)) $where .= " AND ISNULL(`business`.`customer_id`)";
# 锁定的客户不提醒 # 锁定的客户不提醒
$where .= " AND `customer`.`is_lock` = 0"; $where .= " AND `customer`.`is_lock` = 0";
# 查询符合条件的客户 # 查询符合条件的客户
return db('crm_customer') return db('crm_customer')
->alias('customer')->join('__CRM_BUSINESS__ business', 'business.customer_id = customer.customer_id', 'LEFT') ->alias('customer')->join('__CRM_BUSINESS__ business', 'business.customer_id = customer.customer_id', 'LEFT')
->where($where)->column('customer.customer_id'); ->where($where)->where(['customer.crm_lthugd' => array('in', $customerType)])->column('customer.customer_id');
} }
/** /**
* N天内无新建商机的客户 * N天内无新建商机的客户
* *
@ -309,14 +313,14 @@ class PoolCommand extends Command
* @since 2021-04-01 * @since 2021-04-01
* @author fanqi * @author fanqi
*/ */
private function getBusinessQueryResult($type, $levels, $dealStatus) private function getBusinessQueryResult($type, $levels, $dealStatus, $customerType)
{ {
# 转换格式 # 转换格式
$levels = json_decode($levels, true); $levels = json_decode($levels, true);
# 默认条件 # 默认条件
$where = "`customer`.`owner_user_id` > 0"; $where = "`customer`.`owner_user_id` > 0";
# 所有用户,不区分级别 # 所有用户,不区分级别
if ($type == 1) { if ($type == 1) {
foreach ($levels as $k1 => $v1) { foreach ($levels as $k1 => $v1) {
@ -326,7 +330,7 @@ class PoolCommand extends Command
} }
} }
} }
# 根据用户级别设置条件 # 根据用户级别设置条件
if ($type == 2) { if ($type == 2) {
foreach ($levels as $k1 => $v1) { foreach ($levels as $k1 => $v1) {
@ -339,26 +343,26 @@ class PoolCommand extends Command
} }
} }
} }
# 获取最小天数,对于没有设置级别的客户数据使用 # 获取最小天数,对于没有设置级别的客户数据使用
$minLimit = $this->getMinDay($levels); $minLimit = PoolCommand::getMinDay($levels);
$minTime = (time() - 24 * 60 * 60 * $minLimit); $minTime = (time() - 24 * 60 * 60 * $minLimit);
$where .= " OR ((ISNULL(`business`.`customer_id`) AND `customer`.`obtain_time` < " . $minTime . " AND !`customer`.`level`) OR (`customer`.`obtain_time` < " . $minTime . " AND `customer`.`obtain_time` > `business`.`create_time` AND !`customer`.`level`) OR (`business`.`create_time` < " . $minTime . " AND `business`.`create_time` > `customer`.`obtain_time` AND !`customer`.`level`)) )"; $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`))) )";
} }
# 选择不进入公海的客户(已成交客户) # 选择不进入公海的客户(已成交客户)
if (!empty($dealStatus)) $where .= " AND (`customer`.`deal_status` <> '已成交' OR ISNULL(`customer`.`deal_status`))"; if (!empty($dealStatus)) $where .= " AND (`customer`.`deal_status` <> '已成交' OR ISNULL(`customer`.`deal_status`))";
# 锁定的客户不提醒 # 锁定的客户不提醒
$where .= " AND `customer`.`is_lock` = 0"; $where .= " AND `customer`.`is_lock` = 0";
# 查询匹配条件的客户 # 查询匹配条件的客户
return db('crm_customer')->alias('customer') return db('crm_customer')->alias('customer')
->join('__CRM_BUSINESS__ business', 'business.customer_id = customer.customer_id', 'LEFT') ->join('__CRM_BUSINESS__ business', 'business.customer_id = customer.customer_id', 'LEFT')
->where($where)->column('customer.customer_id'); ->where($where)->where(['customer.crm_lthugd' => array('in', $customerType)])->column('customer.customer_id');
} }
/** /**
* N天内没有成交的客户 * N天内没有成交的客户
* *
@ -369,14 +373,14 @@ class PoolCommand extends Command
* @since 2021-04-01 * @since 2021-04-01
* @author fanqi * @author fanqi
*/ */
private function getDealQueryResult($type, $levels, $businessStatus) private function getDealQueryResult($type, $levels, $businessStatus, $customerType)
{ {
# 转换格式 # 转换格式
$levels = json_decode($levels, true); $levels = json_decode($levels, true);
# 默认条件 # 默认条件
$where = "`customer`.`owner_user_id` > 0"; $where = "`customer`.`owner_user_id` > 0";
# 所有用户,不区分级别 # 所有用户,不区分级别
if ($type == 1) { if ($type == 1) {
foreach ($levels as $k1 => $v1) { foreach ($levels as $k1 => $v1) {
@ -386,7 +390,7 @@ class PoolCommand extends Command
} }
} }
} }
# 根据用户级别设置条件 # 根据用户级别设置条件
if ($type == 2) { if ($type == 2) {
foreach ($levels as $k1 => $v1) { foreach ($levels as $k1 => $v1) {
@ -399,27 +403,27 @@ class PoolCommand extends Command
} }
} }
} }
# 获取最小天数,对于没有设置级别的客户数据使用 # 获取最小天数,对于没有设置级别的客户数据使用
$minLimit = $this->getMinDay($levels); $minLimit = PoolCommand::getMinDay($levels);
$minTime = (time() - 24 * 60 * 60 * $minLimit); $minTime = (time() - 24 * 60 * 60 * $minLimit);
$where .= " OR ((ISNULL(`contract`.`customer_id`) AND `customer`.`obtain_time` < " . $minTime . " AND !`customer`.`level`) OR (`customer`.`obtain_time` < " . $minTime . " AND `customer`.`obtain_time` > `contract`.`create_time` AND !`customer`.`level`) OR (`contract`.`create_time` < " . $minTime . " AND `contract`.`create_time` > `customer`.`obtain_time` AND !`customer`.`level`)) )"; $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`))) )";
} }
# 选择不进入公海的客户(有商机客户) # 选择不进入公海的客户(有商机客户)
if (!empty($businessStatus)) $where .= " AND ISNULL(`business`.`customer_id`)"; if (!empty($businessStatus)) $where .= " AND ISNULL(`business`.`customer_id`)";
# 锁定的客户不提醒 # 锁定的客户不提醒
$where .= " AND `customer`.`is_lock` = 0"; $where .= " AND `customer`.`is_lock` = 0";
# 查询符合条件的客户 # 查询符合条件的客户
return db('crm_customer')->alias('customer') return db('crm_customer')->alias('customer')
->join('__CRM_BUSINESS__ business', 'business.customer_id = customer.customer_id', 'LEFT') ->join('__CRM_BUSINESS__ business', 'business.customer_id = customer.customer_id', 'LEFT')
->join('__CRM_CONTRACT__ contract', 'contract.customer_id = customer.customer_id', 'LEFT') ->join('__CRM_CONTRACT__ contract', 'contract.customer_id = customer.customer_id', 'LEFT')
->where($where)->column('customer.customer_id'); ->where($where)->where(['customer.crm_lthugd' => array('in', $customerType)])->column('customer.customer_id');
} }
/** /**
* 获取公海规则最小数字(最快进入公海天数) * 获取公海规则最小数字(最快进入公海天数)
* *
@ -431,11 +435,11 @@ class PoolCommand extends Command
private function getMinDay($data) private function getMinDay($data)
{ {
$number = 1; $number = 1;
foreach ($data as $k1 => $v1) { foreach ($data as $k1 => $v1) {
if (empty($number) || $v1['limit_day'] < $number) $number = $v1['limit_day']; if (empty($number) || $v1['limit_day'] < $number) $number = $v1['limit_day'];
} }
return $number; return $number;
} }
} }

@ -13,6 +13,9 @@ class Api {
protected static $getAccessToken = 'gettoken'; protected static $getAccessToken = 'gettoken';
protected static $contactInfo = 'externalcontact/get'; protected static $contactInfo = 'externalcontact/get';
protected static $getUserInfo = 'auth/getuserinfo';
protected static $userGet = 'user/get';
protected $corpId = ''; protected $corpId = '';
protected $corpSecret = ''; protected $corpSecret = '';
@ -37,6 +40,30 @@ 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 * 获取accessToken
* @return false|mixed * @return false|mixed

@ -8,6 +8,9 @@
namespace app\crm\controller; namespace app\crm\controller;
use app\admin\controller\ApiCommon; 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\SearchConditionTrait;
use app\crm\traits\StarTrait; use app\crm\traits\StarTrait;
use think\Hook; use think\Hook;
@ -28,7 +31,7 @@ class Business extends ApiCommon
{ {
$action = [ $action = [
'permission' => [''], 'permission' => [''],
'allow' => ['statuslist', 'advance', 'product', 'system', 'count', 'setprimary'] 'allow' => ['statuslist', 'advance', 'product', 'system', 'count', 'setprimary', 'check']
]; ];
Hook::listen('check_auth', $action); Hook::listen('check_auth', $action);
$request = Request::instance(); $request = Request::instance();
@ -372,7 +375,7 @@ class Business extends ApiCommon
} }
/** /**
* 商机状态推进 * 商机审批提交
* @param business_id 商机ID * @param business_id 商机ID
* @param status_id 推进商机状态ID * @param status_id 推进商机状态ID
* @return * @return
@ -381,31 +384,91 @@ class Business extends ApiCommon
public function advance() public function advance()
{ {
$param = $this->param; $param = $this->param;
$examineStepModel = new \app\admin\model\ExamineStep();
$examineStatus = $param['examineStatus'] ?? 1; // 审批是否停用
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$userModel = new \app\admin\model\User(); $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']; $remark = $param['statusRemark'];
unset($param['examineStatus']);
if (!$param['business_id']) { if (!$param['business_id']) {
return resultArray(['error' => '参数错误']); return resultArray(['error' => '参数错误']);
} }
$businessInfo = db('crm_business')->where(['business_id' => $param['business_id']])->find(); $businessInfo = db('crm_business')->where(['business_id' => $param['business_id']])->find();
if ($businessInfo['is_end']) { if ($businessInfo['is_end']) {
return resultArray(['error' => '已结束,不能推进']); return resultArray(['error' => '已结束,请勿重复提交']);
}
if ($businessInfo['flow_id'] && [$businessInfo]['check_status'] != 0) {
return resultArray(['error' => '已有审批流程,请勿重复提交']);
} }
$data = []; $data = [];
$data['update_time'] = time(); $data['submit_end_status'] = $is_end;
$data['is_end'] = $is_end; $data['submit_remark'] = $remark;
$data['remark'] = $remark; $data['check_status'] = 0;
$data['check_status'] = 1; if (($examineStatus != false && $examineStatus != 'false') || $examineStatus == 1) {
$data['flow_id'] = 13; // 审核判断(是否有符合条件的审批流)
$data['check_user_id'] = $param['check_user_id']; $examineFlowModel = new \app\admin\model\ExamineFlow();
$data['flow_user_id'] = $param['check_user_id']; 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;
# 审批流停用,将状态改为正常 zjf 20210727 默认值为7
$data['check_status'] = 7;
}
$res = db('crm_business')->where(['business_id' => $param['business_id']])->update($data); $res = db('crm_business')->where(['business_id' => $param['business_id']])->update($data);
if (!$res) { if (!$res) {
return resultArray(['error' => '推进失败,请重试']); 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
];
} }
if (!empty($dealtData)) db('crm_dealt_relation')->insertAll($dealtData);
return resultArray(['success' => '提交成功']); return resultArray(['success' => '提交成功']);
} }
@ -569,96 +632,215 @@ class Business extends ApiCommon
public function check() public function check()
{ {
$param = $this->param; $param = $this->param;
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$userModel = new \app\admin\model\User(); $user_id = $userInfo['id'];
// $is_end = $param['is_end'] ?: 0; //1赢单2输单3无效 $businessModel = model('Business');
// $remark = $param['statusRemark']; $examineStepModel = new \app\admin\model\ExamineStep();
$check_status = $param['check_status']; $examineRecordModel = new \app\admin\model\ExamineRecord();
if (!$param['business_id']) { $examineFlowModel = new \app\admin\model\ExamineFlow();
return resultArray(['error' => '参数错误']); $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()]);
} }
//审批主体详情
if ($check_status == 2) { $dataInfo = $businessModel->getDataById($param['id']);
$businessInfo = db('crm_business')->where(['business_id' => $param['business_id']])->find(); $flowInfo = $examineFlowModel->getDataById($dataInfo['flow_id']);
// if ($businessInfo['is_end']) { $is_end = 0; // 1审批结束
// return resultArray(['error' => '已结束,不能推进']);
// } $status = $param['status'] ? 1 : 0; //1通过0驳回
$checkData = [];
//判断权限 $checkData['check_user_id'] = $user_id;
$auth_user_ids = $userModel->getUserByPer('crm', 'business', 'update'); $checkData['types'] = 'crm_business';
//读写权限 $checkData['types_id'] = $param['id'];
$rwPre = $userModel->rwPre($userInfo['id'], $businessInfo['ro_user_id'], $businessInfo['rw_user_id'], 'update'); $checkData['check_time'] = time();
if (!in_array($businessInfo['owner_user_id'], $auth_user_ids) && !$rwPre) { $checkData['content'] = $param['content'];
header('Content-Type:application/json; charset=utf-8'); $checkData['flow_id'] = $dataInfo['flow_id'];
exit(json_encode(['code' => 102, 'error' => '无权操作'])); $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) {
$status_id = $param['status_id'] ?: $businessInfo['status_id']; $checkData['check_status'] = !empty($status) ? 2 : 3;
$statusInfo = db('crm_business_status')->where(['type_id' => $businessInfo['type_id'], 'status_id' => $status_id])->find(); $businessCheckData['check_user_id'] = '';
if (!$statusInfo && $businessInfo['is_end']) { $businessCheckData['check_status'] = 2;
return resultArray(['error' => '参数错误']);
} }
$data = []; } else {
$data['update_time'] = time(); //审批驳回
// $data['is_end'] = $is_end; $is_end = 1;
// $data['remark'] = $remark; $businessCheckData['check_status'] = 3;
$data['check_status'] = $check_status; //将审批记录至为无效
$data['status_id'] = $status_id; // $examineRecordModel->setEnd(['types' => 'crm_contract','types_id' => $param['id']]);
$data['status_time'] = time(); }
$res = db('crm_business')->where(['business_id' => $param['business_id']])->update($data); //已审批人ID
if (!$res) { $businessCheckData['flow_user_id'] = stringToArray($dataInfo['flow_user_id']) ? arrayToString(array_merge(stringToArray($dataInfo['flow_user_id']), [$user_id])) : arrayToString([$user_id]);
return resultArray(['error' => '推进失败,请重试']); $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 { } else {
# 商机变更后的名称 if ($status) {
$businessStatusName = Db::name('crm_business_status')->where('status_id', $param['status_id'])->value('name'); //发送站内信
if (empty($businessStatusName) && $businessInfo['is_end'] == 1) $businessStatusName = '赢单'; // 通过未完成,发送消息给
if (empty($businessStatusName) && $businessInfo['is_end'] == 2) $businessStatusName = '输单'; (new Message())->send(
if (empty($businessStatusName) && $businessInfo['is_end'] == 3) $businessStatusName = '无效'; Message::BUSINESS_ADVANCE_CHECK_TO_DO,
# 添加活动记录 [
Db::name('crm_activity')->insert([ 'from_user' => User::where(['id' => $dataInfo['owner_user_id']])->value('realname'),
'type' => 3, 'title' => $dataInfo['name'],
'activity_type' => 5, 'action_id' => $param['id']
'activity_type_id' => $businessInfo['business_id'], ],
'content' => '阶段变更为 ' . $businessStatusName, stringToArray($businessCheckData['check_user_id'])
'create_user_id' => $businessInfo['owner_user_id'], );
'update_time' => time(), } else {
'create_time' => time(), (new Message())->send(
'customer_ids' => ',' . $businessInfo['customer_id'] . ',' Message::BUSINESS_ADVANCE_CHECK_REJECT,
]); [
'title' => $dataInfo['name'],
//推进记录添加 'action_id' => $param['id']
$temp['status_id'] = $status_id ?: 0; ],
$temp['is_end'] = $businessInfo['is_end'] ?: 0; $dataInfo['owner_user_id']
$temp['business_id'] = $param['business_id']; );
$temp['create_time'] = time(); }
$temp['owner_user_id'] = $userInfo['id'];
$temp['remark'] = $param['statusRemark'] ?: '';
Db::name('CrmBusinessLog')->insert($temp);
# 返回商机阶段数据
$typeId = db('crm_business')->where('business_id', $param['business_id'])->value('type_id');
$businessStatus = db('crm_business_status')->where('type_id', $typeId)->select();
$result = [
'business_id' => $param['business_id'],
'type_id' => $typeId,
'status_id' => $param['status_id'],
'status_list' => $businessStatus
];
return resultArray(['data' => $result]);
} }
return resultArray(['success' => '审批成功']);
} else { } else {
$data = []; return resultArray(['error' => '审批失败,请重试!']);
$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' => '推进失败,请重试']); * @param business_id 商机ID
} * @param status_id 推进商机状态ID
* @return
* @author Michael_xu
*/
private function advanceAfterCheck($param)
{
$userInfo = $this->userInfo;
$userModel = new \app\admin\model\User();
$is_end = $param['is_end'] ?: 0; //1赢单2输单3无效
if (!$param['business_id']) {
return ['error' => '参数错误'];
}
$businessInfo = db('crm_business')->where(['business_id' => $param['business_id']])->find();
if ($businessInfo['is_end']) {
return ['error' => '已结束,不能推进'];
}
//判断权限
$auth_user_ids = $userModel->getUserByPer('crm', 'business', 'update');
//读写权限
$rwPre = $userModel->rwPre($userInfo['id'], $businessInfo['ro_user_id'], $businessInfo['rw_user_id'], 'update');
if (!in_array($businessInfo['owner_user_id'], $auth_user_ids) && !$rwPre) {
header('Content-Type:application/json; charset=utf-8');
exit(json_encode(['code' => 102, 'error' => '无权操作']));
}
$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' => '参数错误'];
}
$data = [];
$data['update_time'] = time();
$data['is_end'] = $is_end;
// if ($is_end) {
// $status_id = $is_end;
// }
$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' => '推进失败,请重试'];
} 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 = '无效';
# 添加活动记录
Db::name('crm_activity')->insert([
'type' => 3,
'activity_type' => 5,
'activity_type_id' => $businessInfo['business_id'],
'content' => '阶段变更为 ' . $businessStatusName,
'create_user_id' => $businessInfo['owner_user_id'],
'update_time' => time(),
'create_time' => time(),
'customer_ids' => ',' . $businessInfo['customer_id'] . ','
]);
//推进记录添加
$temp['status_id'] = $status_id ?: 0;
$temp['is_end'] = $is_end ?: 0;
$temp['business_id'] = $param['business_id'];
$temp['create_time'] = time();
$temp['owner_user_id'] = $userInfo['id'];
$temp['remark'] = $param['statusRemark'] ?: '';
Db::name('CrmBusinessLog')->insert($temp);
# 返回商机阶段数据
$typeId = db('crm_business')->where('business_id', $param['business_id'])->value('type_id');
$businessStatus = db('crm_business_status')->where('type_id', $typeId)->select();
$result = [
'business_id' => $param['business_id'],
'type_id' => $typeId,
'status_id' => $param['status_id'],
'status_list' => $businessStatus
];
return '';
} }
} }

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

@ -119,10 +119,18 @@ class Customer extends ApiCommon
//判断是否客户池数据 //判断是否客户池数据
$wherePool = $customerModel->getWhereByPool(); $wherePool = $customerModel->getWhereByPool();
$resPool = db('crm_customer')->alias('customer')->where(['customer_id' => $param['id']])->where($wherePool)->find(); $resPool = db('crm_customer')->alias('customer')->where(['customer_id' => $param['id']])->where($wherePool)->find();
if (!$resPool && !in_array($data['owner_user_id'], $auth_user_ids) && !$roPre && !$rwPre) { if (!$resPool && !in_array($data['owner_user_id'], $auth_user_ids) && !$roPre && !$rwPre) {
$authData['dataAuth'] = (int)0; $authData['dataAuth'] = (int)0;
return resultArray(['data' => $authData]); 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]); return resultArray(['data' => $data]);
} }
@ -415,13 +423,25 @@ class Customer extends ApiCommon
# 消息数据 # 消息数据
$message = []; $message = [];
# 获取公海规则数据
$customerPoolData = db('crm_customer_pool')->where('pool_id=' . $poolId)->column(['customer_type']);
$customerTypeArray = explode(',', $customerPoolData[0]);
# 获取客户数据 # 获取客户数据
$customerData = []; $customerData = [];
$customerList = db('crm_customer')->field(['customer_id', 'owner_user_id', 'name'])->whereIn('customer_id', $customerIds)->select(); $customerList = db('crm_customer')->field(['customer_id', 'owner_user_id', 'name', 'crm_lthugd'])->whereIn('customer_id', $customerIds)->select();
foreach ($customerList as $key => $value) { foreach ($customerList as $key => $value) {
# 判断客户类型是否符合公海池客户类型
if (!in_array($value['crm_lthugd'], $customerTypeArray)) {
$message[] = '客户类型与公海池类型不匹配!';
return resultArray(['error' => $message]);
}
$customerData[$value['customer_id']] = $value; $customerData[$value['customer_id']] = $value;
} }
# 整理数据 # 整理数据
$ip = request()->ip(); $ip = request()->ip();
$poolRelationData = []; $poolRelationData = [];
@ -883,7 +903,7 @@ class Customer extends ApiCommon
*/ */
public function top() public function top()
{ {
$customerModel=model('Customer'); $customerModel = model('Customer');
$param = $this->param; $param = $this->param;
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$param['create_role_id'] = $userInfo['id']; $param['create_role_id'] = $userInfo['id'];
@ -1167,4 +1187,20 @@ class Customer extends ApiCommon
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
} }
/**
* 客户类型列表
*
* @return \think\response\Json
* @since 2021-03-29
* @author fanqi
*/
public function Type()
{
$data = db('admin_field')->where(['types' => 'crm_customer', 'field' => 'crm_lthugd'])->value('options');
$data = explode(',', $data);
return resultArray(['data' => $data]);
}
} }

@ -9,6 +9,8 @@
namespace app\crm\controller; namespace app\crm\controller;
use app\admin\controller\ApiCommon; use app\admin\controller\ApiCommon;
use app\admin\model\Message;
use app\admin\model\User;
use app\crm\logic\CustomerPoolLogic; use app\crm\logic\CustomerPoolLogic;
use think\Hook; use think\Hook;
use think\Request; use think\Request;
@ -41,7 +43,8 @@ class CustomerPool extends ApiCommon
'setfieldconfig', 'setfieldconfig',
'exceldownload', 'exceldownload',
'import', 'import',
'export' 'export',
'checkCustomerReveive'
] ]
]; ];
Hook::listen('check_auth', $action); Hook::listen('check_auth', $action);
@ -51,7 +54,7 @@ class CustomerPool extends ApiCommon
parent::_initialize(); parent::_initialize();
} }
} }
/** /**
* 公海列表 * 公海列表
* *
@ -62,12 +65,12 @@ class CustomerPool extends ApiCommon
public function index() public function index()
{ {
if (empty($this->param['pool_id'])) return resultArray(['error' => '缺少公海ID']); if (empty($this->param['pool_id'])) return resultArray(['error' => '缺少公海ID']);
$data = (new CustomerPoolLogic())->getPoolList($this->param); $data = (new CustomerPoolLogic())->getPoolList($this->param);
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
} }
/** /**
* 详情 * 详情
* *
@ -78,16 +81,16 @@ class CustomerPool extends ApiCommon
public function read() public function read()
{ {
if (empty($this->param['pool_id']) || empty($this->param['customer_id'])) return resultArray(['error' => '参数错误!']); if (empty($this->param['pool_id']) || empty($this->param['customer_id'])) return resultArray(['error' => '参数错误!']);
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$param = $this->param; $param = $this->param;
$param['user_id'] = $userInfo['id']; $param['user_id'] = $userInfo['id'];
$data = (new CustomerPoolLogic())->getPoolData($param); $data = (new CustomerPoolLogic())->getPoolData($param);
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
} }
/** /**
* 删除公海客户 * 删除公海客户
* *
@ -98,16 +101,16 @@ class CustomerPool extends ApiCommon
public function delete() public function delete()
{ {
if (empty($this->param['id'])) return resultArray(['error' => '请选择要删除的客户!']); if (empty($this->param['id'])) return resultArray(['error' => '请选择要删除的客户!']);
$this->param['user_id'] = $this->userInfo['id']; $this->param['user_id'] = $this->userInfo['id'];
$result = (new CustomerPoolLogic())->deletePoolCustomer($this->param); $result = (new CustomerPoolLogic())->deletePoolCustomer($this->param);
if (!empty($result)) return resultArray(['error' => $result]); if (!empty($result)) return resultArray(['error' => $result]);
return resultArray(['data' => '删除成功!']); return resultArray(['data' => '删除成功!']);
} }
/** /**
* 公海池列表 * 公海池列表
* *
@ -118,10 +121,10 @@ class CustomerPool extends ApiCommon
public function pondList() public function pondList()
{ {
$data = (new CustomerPoolLogic())->getPondList(['user_id' => $this->userInfo['id'], 'structure_id' => $this->userInfo['structure_id']]); $data = (new CustomerPoolLogic())->getPondList(['user_id' => $this->userInfo['id'], 'structure_id' => $this->userInfo['structure_id']]);
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
} }
/** /**
* 公海字段 * 公海字段
* *
@ -132,16 +135,16 @@ class CustomerPool extends ApiCommon
public function field() public function field()
{ {
if (empty($this->param['pool_id'])) return resultArray(['error' => '缺少公海ID']); if (empty($this->param['pool_id'])) return resultArray(['error' => '缺少公海ID']);
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$param = $this->param; $param = $this->param;
$param['user_id'] = $userInfo['id']; $param['user_id'] = $userInfo['id'];
$data = (new CustomerPoolLogic())->getFieldList($param); $data = (new CustomerPoolLogic())->getFieldList($param);
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
} }
/** /**
* 高级筛选字段列表 * 高级筛选字段列表
* *
@ -152,12 +155,12 @@ class CustomerPool extends ApiCommon
public function advanced() public function advanced()
{ {
if (empty($this->param['types'])) return resultArray(['error' => '缺少模块类型!']); if (empty($this->param['types'])) return resultArray(['error' => '缺少模块类型!']);
$data = (new CustomerPoolLogic())->getAdvancedFilterFieldList($this->param); $data = (new CustomerPoolLogic())->getAdvancedFilterFieldList($this->param);
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
} }
/** /**
* 领取公海池客户 * 领取公海池客户
* *
@ -168,17 +171,17 @@ class CustomerPool extends ApiCommon
public function receive() public function receive()
{ {
if (empty($this->param['customer_id'])) return resultArray(['error' => '请选择要领取的公海客户!']); if (empty($this->param['customer_id'])) return resultArray(['error' => '请选择要领取的公海客户!']);
$param = $this->param; $param = $this->param;
$param['user_id'] = $this->userInfo['id']; $param['user_id'] = $this->userInfo['id'];
$result = (new CustomerPoolLogic())->receiveCustomers($param); $result = (new CustomerPoolLogic())->customerReceiveExamine($param);
if (!empty($result)) return resultArray(['error' => $result]); if (!empty($result)) return resultArray(['error' => $result]);
return resultArray(['data' => '领取成功!']); return resultArray(['data' => '领取成功!']);
} }
/** /**
* 分配公海客户 * 分配公海客户
* *
@ -190,14 +193,14 @@ class CustomerPool extends ApiCommon
{ {
if (empty($this->param['customer_id'])) return resultArray(['error' => '请选择要分配的公海客户!']); if (empty($this->param['customer_id'])) return resultArray(['error' => '请选择要分配的公海客户!']);
if (empty($this->param['user_id'])) return resultArray(['error' => '请选择要分配的员工!']); if (empty($this->param['user_id'])) return resultArray(['error' => '请选择要分配的员工!']);
$result = (new CustomerPoolLogic())->distributeCustomer($this->param); $result = (new CustomerPoolLogic())->distributeCustomer($this->param);
if (!empty($result)) return resultArray(['error' => $result]); if (!empty($result)) return resultArray(['error' => $result]);
return resultArray(['data' => '分配成功!']); return resultArray(['data' => '分配成功!']);
} }
// 公海客户导入模板下载 // 公海客户导入模板下载
public function excelDownload($save_path = '') public function excelDownload($save_path = '')
{ {
@ -206,11 +209,11 @@ class CustomerPool extends ApiCommon
$field_list = $this->fieldsData($param); $field_list = $this->fieldsData($param);
$excelModel->excelImportDownload($field_list, 'crm_pool', $save_path); $excelModel->excelImportDownload($field_list, 'crm_pool', $save_path);
} }
// 导入 // 导入
public function import() public function import()
{ {
$param = $this->param; $param = $this->param;
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$excelModel = new \app\admin\model\Excel(); $excelModel = new \app\admin\model\Excel();
@ -224,7 +227,7 @@ class CustomerPool extends ApiCommon
RecordActionLog($userInfo['id'], 'crm_customer', 'excel', '导入公海客户', '', '', '导入公海客户'); RecordActionLog($userInfo['id'], 'crm_customer', 'excel', '导入公海客户', '', '', '导入公海客户');
return resultArray(['data' => $excelModel->getError()]); return resultArray(['data' => $excelModel->getError()]);
} }
// 导出 // 导出
public function export() public function export()
{ {
@ -257,7 +260,7 @@ class CustomerPool extends ApiCommon
RecordActionLog($userInfo['id'], 'crm_customer', 'excelexport', $action_name, '', '', '导出客户'); RecordActionLog($userInfo['id'], 'crm_customer', 'excelexport', $action_name, '', '', '导出客户');
return resultArray(['error' => 'error']); return resultArray(['error' => 'error']);
} }
/** /**
* 公海权限 * 公海权限
* *
@ -270,12 +273,12 @@ class CustomerPool extends ApiCommon
$param = $this->param; $param = $this->param;
$param['user_id'] = $this->userInfo['id']; $param['user_id'] = $this->userInfo['id'];
$param['structure_id'] = $this->userInfo['structure_id']; $param['structure_id'] = $this->userInfo['structure_id'];
$data = (new CustomerPoolLogic())->getAuthorityData($param); $data = (new CustomerPoolLogic())->getAuthorityData($param);
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
} }
/** /**
* 公海字段样式 * 公海字段样式
* *
@ -286,16 +289,16 @@ class CustomerPool extends ApiCommon
public function fieldConfig() public function fieldConfig()
{ {
if (empty($this->param['pool_id'])) return resultArray(['error' => '缺少公海ID']); if (empty($this->param['pool_id'])) return resultArray(['error' => '缺少公海ID']);
$param = $this->param; $param = $this->param;
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$param['user_id'] = $userInfo['id']; $param['user_id'] = $userInfo['id'];
$data = (new CustomerPoolLogic())->getFieldConfigIndex($param); $data = (new CustomerPoolLogic())->getFieldConfigIndex($param);
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
} }
/** /**
* 设置公海字段宽度 * 设置公海字段宽度
* *
@ -308,16 +311,16 @@ class CustomerPool extends ApiCommon
if (empty($this->param['pool_id'])) return resultArray(['error' => '缺少公海ID']); if (empty($this->param['pool_id'])) return resultArray(['error' => '缺少公海ID']);
if (empty($this->param['field'])) return resultArray(['error' => '缺少字段名称!']); if (empty($this->param['field'])) return resultArray(['error' => '缺少字段名称!']);
if (empty($this->param['width'])) return resultArray(['error' => '缺少宽度值!']); if (empty($this->param['width'])) return resultArray(['error' => '缺少宽度值!']);
$param = $this->param; $param = $this->param;
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$param['user_id'] = $userInfo['id']; $param['user_id'] = $userInfo['id'];
(new CustomerPoolLogic())->setFieldWidth($param); (new CustomerPoolLogic())->setFieldWidth($param);
return resultArray(['data' => '操作成功!']); return resultArray(['data' => '操作成功!']);
} }
/** /**
* 设置公海字段样式 * 设置公海字段样式
* *
@ -329,16 +332,16 @@ class CustomerPool extends ApiCommon
{ {
if (empty($this->param['pool_id'])) return resultArray(['缺少公海ID']); if (empty($this->param['pool_id'])) return resultArray(['缺少公海ID']);
if (empty($this->param['value']) && empty($this->param['hide_value'])) return resultArray(['error' => '字段参数错误!']); if (empty($this->param['value']) && empty($this->param['hide_value'])) return resultArray(['error' => '字段参数错误!']);
$param = $this->param; $param = $this->param;
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$param['user_id'] = $userInfo['id']; $param['user_id'] = $userInfo['id'];
(new CustomerPoolLogic())->setFieldConfig($param); (new CustomerPoolLogic())->setFieldConfig($param);
return resultArray(['data' => '操作成功!']); return resultArray(['data' => '操作成功!']);
} }
/** /**
* 导入模板 * 导入模板
* @param $param * @param $param
@ -349,38 +352,38 @@ class CustomerPool extends ApiCommon
*/ */
public function fieldsData($param) public function fieldsData($param)
{ {
$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']]]; 'field_name' => ['not in', ['deal_status', 'create_user_id']]];
if($param['is_excel']==1){ 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']]]; '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(); $pool_list = db('crm_customer_pool_field_setting')->where($where)->field('field_name as field,form_type,name')->select();
$fieldParam['types'] = 'crm_customer'; $fieldParam['types'] = 'crm_customer';
$fieldParam['action'] = 'excel'; $fieldParam['action'] = 'excel';
$setting = []; $setting = [];
$list=[]; $list = [];
foreach ($pool_list as $k => &$v) { foreach ($pool_list as $k => &$v) {
switch ($v['field']) { switch ($v['field']) {
case 'address': case 'address':
if($param['is_excel']!=1){ if ($param['is_excel'] != 1) {
$v['field'] = 'customer_address'; $v['field'] = 'customer_address';
$v['form_type'] = 'map_address'; $v['form_type'] = 'map_address';
$list[]=$v; $list[] = $v;
unset($pool_list[$k]); unset($pool_list[$k]);
} }
break; break;
case 'detail_address': case 'detail_address':
if($param['is_excel']!=1){ if ($param['is_excel'] != 1) {
unset($pool_list[$k]); unset($pool_list[$k]);
} }
break; break;
case ($v['form_type'] == 'select') || ($v['form_type'] == 'checkbox') : 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']); $pool_list[$k]['setting'] = explode(chr(10), $set['setting']);
break; break;
default : default :
if($param['is_excel']!=1){ if ($param['is_excel'] != 1) {
$pool_list[$k]['setting'] = []; $pool_list[$k]['setting'] = [];
} }
break; break;
@ -395,7 +398,158 @@ class CustomerPool extends ApiCommon
// } // }
// } // }
} }
$pool_list=array_merge($pool_list,$list); $pool_list = array_merge($pool_list, $list);
return $pool_list; return $pool_list;
} }
/**
* 领取公海池客户
*
* @return Json
* @since 2021-04-15
* @author fanqi
*/
public function checkCustomerReveive()
{
$param = $this->param;
$userInfo = $this->userInfo;
$user_id = $userInfo['id'];
$customerCheckModel = model('CustomerCheck');
$examineStepModel = new \app\admin\model\ExamineStep();
$examineRecordModel = new \app\admin\model\ExamineRecord();
$examineFlowModel = new \app\admin\model\ExamineFlow();
$customerModel = model('Customer');
$customerCheckData = [];
$customerCheckData['update_time'] = time();
$customerCheckData['check_status'] = 1; //0待审核1审核通中2审核通过3审核未通过
//权限判断
if (!$examineStepModel->checkExamine($user_id, 'crm_customer_check', $param['id'])) {
return resultArray(['error' => $examineStepModel->getError()]);
}
//审批主体详情
$dataInfo = db('crm_customer_check')->where('customer_check_id', 'in', $param['id'])->find();
$flowInfo = $examineFlowModel->getDataById($dataInfo['flow_id']);
$is_end = 0; // 1审批结束
$status = $param['status'] ? 1 : 0; //1通过0驳回
$checkData = [];
$checkData['check_user_id'] = $user_id;
$checkData['types'] = 'crm_customer_check';
$checkData['types_id'] = $param['id'];
$checkData['check_time'] = time();
$checkData['content'] = $param['content'];
$checkData['flow_id'] = $dataInfo['flow_id'];
$checkData['order_id'] = $dataInfo['order_id'] ?: 1;
$checkData['status'] = $status;
if ($status == 1) {
if ($flowInfo['config'] == 1) {
//固定流程
//获取下一审批信息
$nextStepData = $examineStepModel->nextStepUser($dataInfo['owner_user_id'], $dataInfo['flow_id'], 'crm_customer_check', $param['id'], $dataInfo['order_id'], $user_id);
$next_user_ids = $nextStepData['next_user_ids'] ?: [];
$customerCheckData['order_id'] = $nextStepData['order_id'] ?: '';
if (!$next_user_ids) {
$is_end = 1;
//审批结束
$checkData['check_status'] = !empty($status) ? 2 : 3;
$customerCheckData['check_user_id'] = '';
} else {
//修改主体相关审批信息
$customerCheckData['check_user_id'] = arrayToString($next_user_ids);
}
} else {
//自选流程
$is_end = $param['is_end'] ? 1 : '';
$check_user_id = $param['check_user_id'] ?: '';
if ($is_end !== 1 && empty($check_user_id)) {
return resultArray(['error' => '请选择下一审批人']);
}
$customerCheckData['check_user_id'] = arrayToString($param['check_user_id']);
}
if ($is_end == 1) {
$checkData['check_status'] = !empty($status) ? 2 : 3;
$customerCheckData['check_user_id'] = '';
$customerCheckData['check_status'] = 2;
}
} else {
//审批驳回
$is_end = 1;
$customerCheckData['check_status'] = 3;
//将审批记录至为无效
// $examineRecordModel->setEnd(['types' => 'crm_contract','types_id' => $param['id']]);
}
//已审批人ID
$customerCheckData['flow_user_id'] = stringToArray($dataInfo['flow_user_id']) ? arrayToString(array_merge(stringToArray($dataInfo['flow_user_id']), [$user_id])) : arrayToString([$user_id]);
$resCustomerCheck = db('crm_customer_check')->where(['customer_check_id' => $param['id']])->update($customerCheckData);
if ($resCustomerCheck) {
//审批记录
$resRecord = $examineRecordModel->createData($checkData);
//审核通过,修改相关信息
if ($is_end == 1 && !empty($status)) {
// 审批通过消息告知负责人
(new Message())->send(
Message::CUSTOMER_CHECK_PASS,
[
'title' => $dataInfo['name'],
'action_id' => $param['id']
],
$dataInfo['owner_user_id']
);
$customerData = [];
$customerData['user_id'] = $dataInfo['user_id'];
$customerData['customer_id'] = $dataInfo['customer_id'];
$result = (new CustomerPoolLogic())->receiveCustomers($customerData);
if (!empty($result)) return resultArray(['error' => $result]);
return resultArray(['data' => '领取成功!']);
} else {
if ($status) {
//发送站内信
// 通过未完成,发送消息给
(new Message())->send(
Message::CUSTOMER_CHECK_TO_DO,
[
'from_user' => User::where(['id' => $dataInfo['owner_user_id']])->value('realname'),
'title' => $dataInfo['name'],
'action_id' => $param['id']
],
stringToArray($customerCheckData['check_user_id'])
);
} else {
(new Message())->send(
Message::CONTRACT_REJECT,
[
'title' => $dataInfo['name'],
'action_id' => $param['id']
],
$dataInfo['owner_user_id']
);
}
}
return resultArray(['data' => '审批成功']);
} else {
return resultArray(['error' => '审批失败,请重试!']);
}
}
/**
* 总经理公海池消息提醒
*
* @return Json
* @since 2021-04-14
* @author fanqi
*/
public function num()
{
$customerPoolCount = db('crm_customer_pool_relation')->where("pool_id",array('eq',3))
->count();
return resultArray(['data' => $customerPoolCount]);
}
} }

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

@ -28,7 +28,7 @@ class Message extends ApiCommon
{ {
$action = [ $action = [
'permission' => [], 'permission' => [],
'allow' => [ 'allow' => [
'num', 'num',
'todayleads', 'todayleads',
'todaycustomer', 'todaycustomer',
@ -42,22 +42,25 @@ class Message extends ApiCommon
'remindcustomer', 'remindcustomer',
'checkinvoice', 'checkinvoice',
'visitcontract', 'visitcontract',
'alldeal' 'alldeal',
'checkBusiness',
'newBusiness',
'checkCustomerCheck',
] ]
]; ];
Hook::listen('check_auth',$action); Hook::listen('check_auth', $action);
$request = Request::instance(); $request = Request::instance();
$a = strtolower($request->action()); $a = strtolower($request->action());
if (!in_array($a, $action['permission'])) { if (!in_array($a, $action['permission'])) {
parent::_initialize(); parent::_initialize();
} }
} }
/** /**
* 系统通知 * 系统通知
* *
* @author Michael_xu
* @return * @return
* @author Michael_xu
*/ */
public function index() public function index()
{ {
@ -69,7 +72,7 @@ class Message extends ApiCommon
$data = $messageModel->getDataList($param); $data = $messageModel->getDataList($param);
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
} }
/** /**
* 消息数 * 消息数
* *
@ -83,150 +86,189 @@ class Message extends ApiCommon
$configData = $configDataModel->getData(); $configData = $configDataModel->getData();
$data = []; $data = [];
# 今日需联系线索 # 今日需联系线索
$todayLeadsTime = cache('todayLeadsTime'.$userInfo['id']); $todayLeadsTime = cache('todayLeadsTime' . $userInfo['id']);
$todayLeadsCount = cache('todayLeadsCount'.$userInfo['id']); $todayLeadsCount = cache('todayLeadsCount' . $userInfo['id']);
if (time() <= $todayLeadsTime) { if (time() <= $todayLeadsTime) {
$data['todayLeads'] = (int)$todayLeadsCount; $data['todayLeads'] = (int)$todayLeadsCount;
} else { } else {
$todayLeads = $this->todayLeads(true); $todayLeads = $this->todayLeads(true);
$data['todayLeads'] = $todayLeads['dataCount'] ? : 0; $data['todayLeads'] = $todayLeads['dataCount'] ?: 0;
cache('todayLeadsCount'.$userInfo['id'], $data['todayLeads']); cache('todayLeadsCount' . $userInfo['id'], $data['todayLeads']);
cache('todayLeadsTime'.$userInfo['id'], time() + 180); cache('todayLeadsTime' . $userInfo['id'], time());
} }
# 今日需联系客户 # 今日需联系客户
$todayCustomerTime = cache('todayCustomerTime'.$userInfo['id']); $todayCustomerTime = cache('todayCustomerTime' . $userInfo['id']);
$todayCustomerCount = cache('todayCustomerCount'.$userInfo['id']); $todayCustomerCount = cache('todayCustomerCount' . $userInfo['id']);
if (time() <= $todayCustomerTime) { if (time() <= $todayCustomerTime) {
$data['todayCustomer'] = (int)$todayCustomerCount; $data['todayCustomer'] = (int)$todayCustomerCount;
} else { } else {
$todayCustomer = $this->todayCustomer(true); $todayCustomer = $this->todayCustomer(true);
$data['todayCustomer'] = $todayCustomer['dataCount'] ? : 0; $data['todayCustomer'] = $todayCustomer['dataCount'] ?: 0;
cache('todayCustomerCount'.$userInfo['id'], $data['todayCustomer']); cache('todayCustomerCount' . $userInfo['id'], $data['todayCustomer']);
cache('todayCustomerTime'.$userInfo['id'], time() + 180); cache('todayCustomerTime' . $userInfo['id'], time());
} }
# 今日需联系商机 # 今日需联系商机
$todayBusinessTime = cache('todayBusinessTime'.$userInfo['id']); $todayBusinessTime = cache('todayBusinessTime' . $userInfo['id']);
$todayBusinessCount = cache('todayBusinessCount'.$userInfo['id']); $todayBusinessCount = cache('todayBusinessCount' . $userInfo['id']);
if (time() <= $todayBusinessTime) { if (time() <= $todayBusinessTime) {
$data['todayBusiness'] = (int)$todayBusinessCount; $data['todayBusiness'] = (int)$todayBusinessCount;
} else { } else {
$todayBusiness = $this->todayBusiness(true); $todayBusiness = $this->todayBusiness(true);
$data['todayBusiness'] = $todayBusiness['dataCount'] ? : 0; $data['todayBusiness'] = $todayBusiness['dataCount'] ?: 0;
cache('todayBusinessCount'.$userInfo['id'], $data['todayBusiness']); cache('todayBusinessCount' . $userInfo['id'], $data['todayBusiness']);
cache('todayBusinessTime'.$userInfo['id'], time() + 180); cache('todayBusinessTime' . $userInfo['id'], time());
} }
# 分配给我的线索 # 分配给我的线索
$followLeadsTime = cache('followLeadsTime'.$userInfo['id']); $followLeadsTime = cache('followLeadsTime' . $userInfo['id']);
$followLeadsCount = cache('followLeadsCount'.$userInfo['id']); $followLeadsCount = cache('followLeadsCount' . $userInfo['id']);
if (time() <= $followLeadsTime) { if (time() <= $followLeadsTime) {
$data['followLeads'] = (int)$followLeadsCount; $data['followLeads'] = (int)$followLeadsCount;
} else { } else {
$followLeads = $this->followLeads(true); $followLeads = $this->followLeads(true);
$data['followLeads'] = $followLeads['dataCount'] ? : 0; $data['followLeads'] = $followLeads['dataCount'] ?: 0;
cache('followLeadsCount'.$userInfo['id'], $data['followLeads']); cache('followLeadsCount' . $userInfo['id'], $data['followLeads']);
cache('followLeadsTime'.$userInfo['id'], time() + 180); cache('followLeadsTime' . $userInfo['id'], time());
} }
# 分配给我的客户 # 分配给我的客户
$followCustomerTime = cache('followCustomerTime'.$userInfo['id']); $followCustomerTime = cache('followCustomerTime' . $userInfo['id']);
$followCustomerCount = cache('followCustomerCount'.$userInfo['id']); $followCustomerCount = cache('followCustomerCount' . $userInfo['id']);
if (time() <= $followCustomerTime) { if (time() <= $followCustomerTime) {
$data['followCustomer'] = (int)$followCustomerCount; $data['followCustomer'] = (int)$followCustomerCount;
} else { } else {
$followCustomer = $this->followCustomer(true); $followCustomer = $this->followCustomer(true);
$data['followCustomer'] = $followCustomer['dataCount'] ? : 0; $data['followCustomer'] = $followCustomer['dataCount'] ?: 0;
cache('followCustomerCount'.$userInfo['id'], $data['followCustomer']); cache('followCustomerCount' . $userInfo['id'], $data['followCustomer']);
cache('followCustomerTime'.$userInfo['id'], time() + 180); cache('followCustomerTime' . $userInfo['id'], time());
} }
# 待审核合同 # 待审核合同
$checkContractTime = cache('checkContractTime'.$userInfo['id']); $checkContractTime = cache('checkContractTime' . $userInfo['id']);
$checkContractCount = cache('checkContractCount'.$userInfo['id']); $checkContractCount = cache('checkContractCount' . $userInfo['id']);
if (time() <= $checkContractTime) { if (time() <= $checkContractTime) {
$data['checkContract'] = (int)$checkContractCount; $data['checkContract'] = (int)$checkContractCount;
} else { } else {
$checkContract = $this->checkContract(true); $checkContract = $this->checkContract(true);
$data['checkContract'] = $checkContract['dataCount'] ? : 0; $data['checkContract'] = $checkContract['dataCount'] ?: 0;
cache('checkContractCount'.$userInfo['id'], $data['checkContract']); cache('checkContractCount' . $userInfo['id'], $data['checkContract']);
cache('checkContractTime'.$userInfo['id'], time() + 180); cache('checkContractTime' . $userInfo['id'], time());
} }
# 待审核回款 # 待审核回款
$checkReceivablesTime = cache('checkReceivablesTime'.$userInfo['id']); $checkReceivablesTime = cache('checkReceivablesTime' . $userInfo['id']);
$checkReceivablesCount = cache('checkReceivablesCount'.$userInfo['id']); $checkReceivablesCount = cache('checkReceivablesCount' . $userInfo['id']);
if (time() <= $checkReceivablesTime) { if (time() <= $checkReceivablesTime) {
$data['checkReceivables'] = (int)$checkReceivablesCount; $data['checkReceivables'] = (int)$checkReceivablesCount;
} else { } else {
$checkReceivables = $this->checkReceivables(true); $checkReceivables = $this->checkReceivables(true);
$data['checkReceivables'] = $checkReceivables['dataCount'] ? : 0; $data['checkReceivables'] = $checkReceivables['dataCount'] ?: 0;
cache('checkReceivablesCount'.$userInfo['id'], $data['checkReceivables']); cache('checkReceivablesCount' . $userInfo['id'], $data['checkReceivables']);
cache('checkReceivablesTime'.$userInfo['id'], time() + 180); cache('checkReceivablesTime' . $userInfo['id'], time());
} }
# 待审核发票 # 待审核发票
$checkInvoiceTime = cache('checkInvoiceTime'.$userInfo['id']); $checkInvoiceTime = cache('checkInvoiceTime' . $userInfo['id']);
$checkInvoiceCount = cache('checkInvoiceCount'.$userInfo['id']); $checkInvoiceCount = cache('checkInvoiceCount' . $userInfo['id']);
if (time() <= $checkInvoiceTime) { if (time() <= $checkInvoiceTime) {
$data['checkInvoice'] = (int)$checkInvoiceCount; $data['checkInvoice'] = (int)$checkInvoiceCount;
} else { } else {
$checkInvoice = $this->checkInvoice(true); $checkInvoice = $this->checkInvoice(true);
$data['checkInvoice'] = $checkInvoice['dataCount'] ? : 0; $data['checkInvoice'] = $checkInvoice['dataCount'] ?: 0;
cache('checkInvoiceCount' . $userInfo['id'], $data['checkInvoice']);
cache('checkInvoiceTime' . $userInfo['id'], time());
}
# 待审核商机
$checkBusinessTime = cache('checkBusinessTime' . $userInfo['id']);
$checkBusinessCount = cache('checkBusinessCount' . $userInfo['id']);
if (time() <= $checkBusinessTime) {
$data['checkBusiness'] = (int)$checkBusinessCount;
} else {
$checkBusiness = $this->checkBusiness(true);
$data['checkBusiness'] = $checkBusiness['dataCount'] ?: 0;
cache('checkBusinessCount' . $userInfo['id'], $data['checkBusiness']);
cache('checkBusinessTime' . $userInfo['id'], time());
}
# 待审核客户捞取
$checkCustomerCheckTime = cache('$checkCustomerCheckTime' . $userInfo['id']);
$checkCustomerCheckCount = cache('checkCustomerCheckCount' . $userInfo['id']);
if (time() <= $checkCustomerCheckTime) {
$data['checkCustomerCheck'] = (int)$checkCustomerCheckCount;
} else {
$checkCustomerCheck = $this->checkCustomerCheck(true);
$data['checkCustomerCheck'] = $checkCustomerCheck['dataCount'] ?: 0;
cache('checkInvoiceCount'.$userInfo['id'], $data['checkInvoice']); cache('checkCustomerCheckCount' . $userInfo['id'], $data['checkCustomerCheck']);
cache('checkInvoiceTime'.$userInfo['id'], time() + 180); cache('$checkCustomerCheckTime' . $userInfo['id'], time());
} }
# 待回款提醒 # 待回款提醒
$remindReceivablesPlanTime = cache('remindReceivablesPlanTime'.$userInfo['id']); $remindReceivablesPlanTime = cache('remindReceivablesPlanTime' . $userInfo['id']);
$remindReceivablesPlanCount = cache('remindReceivablesPlanCount'.$userInfo['id']); $remindReceivablesPlanCount = cache('remindReceivablesPlanCount' . $userInfo['id']);
if (time() <= $remindReceivablesPlanTime) { if (time() <= $remindReceivablesPlanTime) {
$data['remindReceivablesPlan'] = (int)$remindReceivablesPlanCount; $data['remindReceivablesPlan'] = (int)$remindReceivablesPlanCount;
} else { } else {
$remindReceivablesPlan = $this->remindReceivablesPlan(true); $remindReceivablesPlan = $this->remindReceivablesPlan(true);
$data['remindReceivablesPlan'] = $remindReceivablesPlan['dataCount'] ? : 0; $data['remindReceivablesPlan'] = $remindReceivablesPlan['dataCount'] ?: 0;
cache('remindReceivablesPlanCount'.$userInfo['id'], $data['remindReceivablesPlan']); cache('remindReceivablesPlanCount' . $userInfo['id'], $data['remindReceivablesPlan']);
cache('remindReceivablesPlanTime'.$userInfo['id'], time() + 180); cache('remindReceivablesPlanTime' . $userInfo['id'], time());
} }
if ($configData['visit_config'] == 1) { if ($configData['visit_config'] == 1) {
# 待回访合同 # 待回访合同
$visitContractTime = cache('visitContractTime'.$userInfo['id']); $visitContractTime = cache('visitContractTime' . $userInfo['id']);
$visitContractCount = cache('visitContractCount'.$userInfo['id']); $visitContractCount = cache('visitContractCount' . $userInfo['id']);
if (time() <= $visitContractTime) { if (time() <= $visitContractTime) {
$data['returnVisitRemind'] = (int)$visitContractCount; $data['returnVisitRemind'] = (int)$visitContractCount;
} else { } else {
$visitContract = $this->visitContract(true); $visitContract = $this->visitContract(true);
$data['returnVisitRemind'] = $visitContract['dataCount'] ? : 0; $data['returnVisitRemind'] = $visitContract['dataCount'] ?: 0;
cache('visitContractCount'.$userInfo['id'], $data['returnVisitRemind']); cache('visitContractCount' . $userInfo['id'], $data['returnVisitRemind']);
cache('visitContractTime'.$userInfo['id'], time() + 180); cache('visitContractTime' . $userInfo['id'], time());
} }
} }
# 即将到期合同 # 即将到期合同
if ($configData['contract_config'] == 1) { if ($configData['contract_config'] == 1) {
$endContractTime = cache('endContractTime'.$userInfo['id']); $endContractTime = cache('endContractTime' . $userInfo['id']);
$endContractCount = cache('endContractCount'.$userInfo['id']); $endContractCount = cache('endContractCount' . $userInfo['id']);
if (time() <= $endContractTime) { if (time() <= $endContractTime) {
$data['endContract'] = (int)$endContractCount; $data['endContract'] = (int)$endContractCount;
} else { } else {
$endContract = $this->endContract(true); $endContract = $this->endContract(true);
$data['endContract'] = $endContract['dataCount'] ? : 0; $data['endContract'] = $endContract['dataCount'] ?: 0;
cache('endContractCount'.$userInfo['id'], $data['endContract']); cache('endContractCount' . $userInfo['id'], $data['endContract']);
cache('endContractTime'.$userInfo['id'], time() + 180); cache('endContractTime' . $userInfo['id'], time());
} }
} }
# 新增商机
$newBusinessTime = cache('newBusinessTime' . $userInfo['id']);
$newBusinessCount = cache('newBusinessCount' . $userInfo['id']);
if (time() <= $newBusinessTime) {
$data['newBusiness'] = (int)$newBusinessCount;
} else {
$newBusiness = $this->newBusiness(true);
$data['newBusiness'] = $newBusiness['dataCount'] ?: 0;
cache('newBusinessCount' . $userInfo['id'], $data['newBusiness']);
cache('newBusinessTime' . $userInfo['id'], time());
}
# 待进入公海提醒 # 待进入公海提醒
$pool = db('crm_customer_pool')->where(['status' => 1, 'remind_conf' => 1])->count(); $pool = db('crm_customer_pool')->where(['status' => 1, 'remind_conf' => 1])->count();
if (!empty($pool)) { if (!empty($pool)) {
$remindCustomerTime = cache('remindCustomerTime'.$userInfo['id']); $remindCustomerTime = cache('remindCustomerTime' . $userInfo['id']);
$remindCustomerCount = cache('remindCustomerCount'.$userInfo['id']); $remindCustomerCount = cache('remindCustomerCount' . $userInfo['id']);
if (time() <= $remindCustomerTime) { if (time() <= $remindCustomerTime) {
$data['putInPoolRemind'] = (int)$remindCustomerCount; $data['putInPoolRemind'] = (int)$remindCustomerCount;
} else { } else {
$remindCustomer = $this->remindCustomer(true); $remindCustomer = $this->remindCustomer(true);
$data['putInPoolRemind'] = !empty($remindCustomer['dataCount']) ? $remindCustomer['dataCount'] : 0; $data['putInPoolRemind'] = !empty($remindCustomer['dataCount']) ? $remindCustomer['dataCount'] : 0;
cache('remindCustomerCount'.$userInfo['id'], $data['putInPoolRemind']); cache('remindCustomerCount' . $userInfo['id'], $data['putInPoolRemind']);
cache('remindCustomerTime'.$userInfo['id'], time() + 180); cache('remindCustomerTime' . $userInfo['id'], time());
} }
} }
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
} }
/** /**
* 今日需联系线索 * 今日需联系线索
* *
@ -235,21 +277,21 @@ class Message extends ApiCommon
*/ */
public function todayLeads($getCount = false) public function todayLeads($getCount = false)
{ {
$param = $this->param; $param = $this->param;
$userId = $this->userInfo['id']; $userId = $this->userInfo['id'];
$types = $param['types']; $types = $param['types'];
unset($param['types']); unset($param['types']);
$param['user_id'] = $userId; $param['user_id'] = $userId;
if ($getCount == true) $param['getCount'] = 1; if ($getCount == true) $param['getCount'] = 1;
$messageLogic= new MessageLogic(); $messageLogic = new MessageLogic();
$data = $messageLogic->todayLeads($param); $data = $messageLogic->todayLeads($param);
if ($types == 'list') return resultArray(['data' => $data]); if ($types == 'list') return resultArray(['data' => $data]);
return $data; return $data;
} }
/** /**
* 今日需联系客户 * 今日需联系客户
* *
@ -266,14 +308,14 @@ class Message extends ApiCommon
} }
unset($param['types']); unset($param['types']);
$param['user_id'] = $userId; $param['user_id'] = $userId;
$messageLogic= new MessageLogic(); $messageLogic = new MessageLogic();
$data = $messageLogic->remindCustomer($param); $data = $messageLogic->remindCustomer($param);
if ($types == 'list') { if ($types == 'list') {
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
} }
return $data; return $data;
} }
/** /**
* 今日需联系商机 * 今日需联系商机
* *
@ -285,24 +327,24 @@ class Message extends ApiCommon
*/ */
public function todayBusiness($getCount = false) public function todayBusiness($getCount = false)
{ {
$param = $this->param; $param = $this->param;
$userId = $this->userInfo['id']; $userId = $this->userInfo['id'];
$types = $param['types']; $types = $param['types'];
unset($param['types']); unset($param['types']);
if ($getCount == true) $param['getCount'] = 1; if ($getCount == true) $param['getCount'] = 1;
$messageLogic= new MessageLogic(); $messageLogic = new MessageLogic();
$param['user_id'] = $userId; $param['user_id'] = $userId;
$data = $messageLogic->todayBusiness($param); $data = $messageLogic->todayBusiness($param);
if ($types == 'list') return resultArray(['data' => $data]); if ($types == 'list') return resultArray(['data' => $data]);
return $data; return $data;
} }
/** /**
* 分配给我的线索 * 分配给我的线索
* @author Michael_xu
* @return * @return
* @author Michael_xu
*/ */
public function followLeads($getCount = false) public function followLeads($getCount = false)
{ {
@ -312,18 +354,18 @@ class Message extends ApiCommon
unset($param['types']); unset($param['types']);
if ($getCount == true) $param['getCount'] = 1; if ($getCount == true) $param['getCount'] = 1;
$param['user_id'] = $userInfo['id']; $param['user_id'] = $userInfo['id'];
$messageLogic=new MessageLogic(); $messageLogic = new MessageLogic();
$data = $messageLogic->followLeads($param); $data = $messageLogic->followLeads($param);
if ($types == 'list') { if ($types == 'list') {
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
} }
return $data; return $data;
} }
/** /**
* 分配给我的客户 * 分配给我的客户
* @author Michael_xu
* @return * @return
* @author Michael_xu
*/ */
public function followCustomer($getCount = false) public function followCustomer($getCount = false)
{ {
@ -334,7 +376,7 @@ class Message extends ApiCommon
$param['getCount'] = 1; $param['getCount'] = 1;
} }
unset($param['types']); unset($param['types']);
$messageLogic=new MessageLogic(); $messageLogic = new MessageLogic();
$param['user_id'] = $userInfo['id']; $param['user_id'] = $userInfo['id'];
$data = $messageLogic->followCustomer($param); $data = $messageLogic->followCustomer($param);
if ($types == 'list') { if ($types == 'list') {
@ -342,7 +384,7 @@ class Message extends ApiCommon
} }
return $data; return $data;
} }
/** /**
* 待审核合同 * 待审核合同
* *
@ -358,7 +400,7 @@ class Message extends ApiCommon
if ($getCount == true) { if ($getCount == true) {
$param['getCount'] = 1; $param['getCount'] = 1;
} }
$messageLogic=new MessageLogic(); $messageLogic = new MessageLogic();
$param['user_id'] = $userInfo['id']; $param['user_id'] = $userInfo['id'];
$data = $messageLogic->checkContract($param); $data = $messageLogic->checkContract($param);
if ($types == 'list') { if ($types == 'list') {
@ -366,11 +408,11 @@ class Message extends ApiCommon
} }
return $data; return $data;
} }
/** /**
* 待审核回款 * 待审核回款
* @author Michael_xu
* @return * @return
* @author Michael_xu
*/ */
public function checkReceivables($getCount = false) public function checkReceivables($getCount = false)
{ {
@ -379,7 +421,7 @@ class Message extends ApiCommon
$types = $param['types']; $types = $param['types'];
unset($param['types']); unset($param['types']);
if ($getCount == true) $param['getCount'] = 1; if ($getCount == true) $param['getCount'] = 1;
$messageLogic=new MessageLogic(); $messageLogic = new MessageLogic();
$param['user_id'] = $userInfo['id']; $param['user_id'] = $userInfo['id'];
$data = $messageLogic->checkReceivables($param); $data = $messageLogic->checkReceivables($param);
if ($types == 'list') { if ($types == 'list') {
@ -387,7 +429,7 @@ class Message extends ApiCommon
} }
return $data; return $data;
} }
/** /**
* 待审核发票 * 待审核发票
* *
@ -397,40 +439,86 @@ class Message extends ApiCommon
*/ */
public function checkInvoice($getCount = false) public function checkInvoice($getCount = false)
{ {
$param = $this->param; $param = $this->param;
$userId = $this->userInfo['id']; $userId = $this->userInfo['id'];
$types = $param['types']; $types = $param['types'];
if ($getCount == true) $param['getCount'] = 1; if ($getCount == true) $param['getCount'] = 1;
# 清除与模型无关的数据 # 清除与模型无关的数据
unset($param['types']); unset($param['types']);
$param['user_id'] = $userId; $param['user_id'] = $userId;
$messageLogic=new MessageLogic(); $messageLogic = new MessageLogic();
$data = $messageLogic->checkInvoice($param); $data = $messageLogic->checkInvoice($param);
if ($types == 'list') return resultArray(['data' => $data]);
return $data;
}
/**
* 待审核商机
*
* @return array|\think\response\Json
* @throws \think\exception\DbException
*/
public function checkBusiness($getCount = false)
{
$param = $this->param;
$userId = $this->userInfo['id'];
$types = $param['types'];
if ($getCount == true) $param['getCount'] = 1;
# 清除与模型无关的数据
unset($param['types']);
$param['user_id'] = $userId;
$messageLogic = new MessageLogic();
$data = $messageLogic->checkBusiness($param);
if ($types == 'list') return resultArray(['data' => $data]);
return $data;
}
/**
* 待审核客户捞取
*
* @return array|\think\response\Json
* @throws \think\exception\DbException
*/
public function checkCustomerCheck($getCount = false)
{
$param = $this->param;
$userId = $this->userInfo['id'];
$types = $param['types'];
if ($getCount == true) $param['getCount'] = 1;
# 清除与模型无关的数据
unset($param['types']);
$param['user_id'] = $userId;
$messageLogic = new MessageLogic();
$data = $messageLogic->checkCustomerCheck($param);
if ($types == 'list') return resultArray(['data' => $data]); if ($types == 'list') return resultArray(['data' => $data]);
return $data; return $data;
} }
/** /**
* 待回款提醒 * 待回款提醒
* @author Michael_xu
* @return * @return
* @author Michael_xu
*/ */
public function remindReceivablesPlan($getCount = false) public function remindReceivablesPlan($getCount = false)
{ {
$param = $this->param; $param = $this->param;
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$types = $param['types']; $types = $param['types'];
$type = $param['type'] ? : 1; $type = $param['type'] ?: 1;
$isSub = $param['isSub'] ? : ''; $isSub = $param['isSub'] ?: '';
unset($param['types']); unset($param['types']);
unset($param['type']); unset($param['type']);
unset($param['isSub']); unset($param['isSub']);
$receivablesPlanModel = model('ReceivablesPlan'); $receivablesPlanModel = model('ReceivablesPlan');
if ($getCount == true) $param['getCount'] = 1; if ($getCount == true) $param['getCount'] = 1;
$param['owner_user_id'] = $userInfo['id']; $param['owner_user_id'] = $userInfo['id'];
if ($isSub) { if ($isSub) {
$param['owner_user_id'] = ['in', getSubUserId(false)]; $param['owner_user_id'] = ['in', getSubUserId(false)];
@ -460,19 +548,19 @@ class Message extends ApiCommon
} }
return $data; return $data;
} }
/** /**
* 即将到期合同 * 即将到期合同
* @author Michael_xu
* @return * @return
* @author Michael_xu
*/ */
public function endContract($getCount = false) public function endContract($getCount = false)
{ {
$param = $this->param; $param = $this->param;
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$types = $param['types']; $types = $param['types'];
$type = $param['type'] ? : 1; $type = $param['type'] ?: 1;
$isSub = $param['isSub'] ? : ''; $isSub = $param['isSub'] ?: '';
if ($getCount == true) $param['getCount'] = 1; if ($getCount == true) $param['getCount'] = 1;
unset($param['types']); unset($param['types']);
unset($param['type']); unset($param['type']);
@ -480,19 +568,21 @@ class Message extends ApiCommon
$contractModel = model('Contract'); $contractModel = model('Contract');
$configModel = new \app\crm\model\ConfigData(); $configModel = new \app\crm\model\ConfigData();
$configInfo = $configModel->getData(); $configInfo = $configModel->getData();
$expireDay = $configInfo['contract_day'] ? : '7'; $expireDay = $configInfo['contract_day'] ?: '7';
// 合同到期不提醒 // 合同到期不提醒
if (empty($configInfo['contract_config'])) return resultArray(['data' => []]); if (empty($configInfo['contract_config'])) return resultArray(['data' => []]);
$param['owner_user_id'] = $userInfo['id']; $param['owner_user_id'] = $userInfo['id'];
if ($isSub) { if ($isSub) {
$param['owner_user_id'] = array('in',getSubUserId(false)); $param['owner_user_id'] = array('in', getSubUserId(false));
} }
switch ($type) { switch ($type) {
case '1' : case '1' :
$param['end_time'] = array('between',array(date('Y-m-d',time()),date('Y-m-d',time()+86400*$expireDay))); $param['end_time'] = array('between', array(date('Y-m-d', time()), date('Y-m-d', time() + 86400 * $expireDay)));
$param['expire_remind'] = 0; $param['expire_remind'] = 0;
break; break;
case '2' : $param['end_time'] = array('lt',date('Y-m-d',time())); break; case '2' :
$param['end_time'] = array('lt', date('Y-m-d', time()));
break;
} }
$data = $contractModel->getDataList($param); $data = $contractModel->getDataList($param);
// p($contractModel->getLastSql()); // p($contractModel->getLastSql());
@ -501,41 +591,71 @@ class Message extends ApiCommon
} }
return $data; return $data;
} }
/** /**
* 待进入客户池 * 新增商机
* @return
* @author Michael_xu * @author Michael_xu
*/
public function newBusiness($getCount = false)
{
$param = $this->param;
$userInfo = $this->userInfo;
$types = $param['types'];
$type = $param['type'] ?: 1;
$isSub = $param['isSub'] ?: '';
if ($getCount == true) $param['getCount'] = 1;
unset($param['types']);
unset($param['type']);
unset($param['isSub']);
$businessModel = model('Business');
// $param['owner_user_id'] = $userInfo['id'];
if ($isSub) {
$param['owner_user_id'] = array('in', getSubUserId(false));
}
$businessIdArray = db('crm_dealt_relation')->where(['types' => ['eq', 'crm_business_new'], 'user_id' => ['eq', $userInfo['id']]])->column('types_id');
$param['businessIdArray'] = !empty($businessIdArray) ? $businessIdArray : -1;
$data = $businessModel->getDataList($param);
if ($types == 'list') {
return resultArray(['data' => $data]);
}
return $data;
}
/**
* 待进入客户池
* @return * @return
* @author Michael_xu
*/ */
public function remindCustomer($getCount = false) public function remindCustomer($getCount = false)
{ {
$customerModel = model('Customer'); $customerModel = model('Customer');
$param = $this->param; $param = $this->param;
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$types = $param['types']; $types = $param['types'];
$isSub = $param['isSub'] ? : ''; $isSub = $param['isSub'] ?: '';
if ($getCount == true) $param['getCount'] = 1; if ($getCount == true) $param['getCount'] = 1;
unset($param['types']); unset($param['types']);
unset($param['type']); unset($param['type']);
unset($param['isSub']); unset($param['isSub']);
unset($param['deal_status']); unset($param['deal_status']);
unset($param['owner_user_id']); unset($param['owner_user_id']);
# 负责人 # 负责人
$param['owner_user_id'] = !empty($isSub) ? ['in', getSubUserId(false, 0, $userInfo['id'])] : $userInfo['id']; $param['owner_user_id'] = !empty($isSub) ? ['in', getSubUserId(false, 0, $userInfo['id'])] : $userInfo['id'];
# 是否提醒 # 是否提醒
$data = []; $data = [];
$remind = db('crm_customer_pool')->where(['status' => 1, 'remind_conf' => 1])->count(); $remind = db('crm_customer_pool')->where(['status' => 1, 'remind_conf' => 1])->count();
if (!empty($remind)) { if (!empty($remind)) {
$whereData = $param ? : []; $whereData = $param ?: [];
$whereData['is_remind'] = 1; $whereData['is_remind'] = 1;
$whereData['user_id'] = $userInfo['id']; $whereData['user_id'] = $userInfo['id'];
$whereData['pool_remain'] = 0; $whereData['pool_remain'] = 0;
$whereData['scene_id'] = db('admin_scene')->where(['types' => 'crm_customer','bydata' => 'me'])->value('scene_id'); $whereData['scene_id'] = db('admin_scene')->where(['types' => 'crm_customer', 'bydata' => 'me'])->value('scene_id');
if ($isSub) { if ($isSub) {
$whereData['scene_id'] = db('admin_scene')->where(['types' => 'crm_customer','bydata' => 'sub'])->value('scene_id'); $whereData['scene_id'] = db('admin_scene')->where(['types' => 'crm_customer', 'bydata' => 'sub'])->value('scene_id');
} }
$data = $customerModel->getDataList($whereData); $data = $customerModel->getDataList($whereData);
} }
@ -544,7 +664,7 @@ class Message extends ApiCommon
} }
return $data; return $data;
} }
/** /**
* 待回访合同 * 待回访合同
* *
@ -556,30 +676,30 @@ class Message extends ApiCommon
*/ */
public function visitContract($getCount = false) public function visitContract($getCount = false)
{ {
$param = $this->param; $param = $this->param;
$userId = $this->userInfo['id']; $userId = $this->userInfo['id'];
$isSub = !empty($param['isSub']) ? $param['isSub'] : 0; $isSub = !empty($param['isSub']) ? $param['isSub'] : 0;
$types = !empty($param['types']) ? $param['types'] : ''; $types = !empty($param['types']) ? $param['types'] : '';
if ($getCount == true) $param['getCount'] = 1; if ($getCount == true) $param['getCount'] = 1;
unset($param['isSub']); unset($param['isSub']);
unset($param['types']); unset($param['types']);
$param['is_visit'] = 0; # 未回访 $param['is_visit'] = 0; # 未回访
$param['check_status'] = 2; # 审核通过 $param['check_status'] = 2; # 审核通过
$contractModel = new \app\crm\model\Contract(); $contractModel = new \app\crm\model\Contract();
# 负责人 # 负责人
$param['owner_user_id'] = !empty($isSub) ? ['in', getSubUserId(false)] : $userId; $param['owner_user_id'] = !empty($isSub) ? ['in', getSubUserId(false)] : $userId;
$param['user_id'] = $userId; $param['user_id'] = $userId;
$data = $contractModel->getDataList($param); $data = $contractModel->getDataList($param);
if ($types == 'list') return resultArray(['data' => $data]); if ($types == 'list') return resultArray(['data' => $data]);
return $data; return $data;
} }
/** /**
* 全部标记已处理 * 全部标记已处理
* *
@ -589,16 +709,16 @@ class Message extends ApiCommon
*/ */
public function allDeal() public function allDeal()
{ {
$type = $this->param['type']; $type = $this->param['type'];
$typeId = !empty($this->param['type_id']) ? $this->param['type_id'] : ''; $typeId = !empty($this->param['type_id']) ? $this->param['type_id'] : '';
$isSub = !empty($this->param['isSub']) ? $this->param['isSub'] : 0; $isSub = !empty($this->param['isSub']) ? $this->param['isSub'] : 0;
$userId = $this->userInfo['id']; $userId = $this->userInfo['id'];
if (empty($type)) return resultArray(['error' => '缺少模块类型参数']); if (empty($type)) return resultArray(['error' => '缺少模块类型参数']);
# 获得今日开始和结束时间戳 # 获得今日开始和结束时间戳
$todayTime = getTimeByType('today'); $todayTime = getTimeByType('today');
# 处理今日需联系线索、客户、商机 # 处理今日需联系线索、客户、商机
if (in_array($type, ['todayLeads', 'todayCustomer', 'todayBusiness'])) { if (in_array($type, ['todayLeads', 'todayCustomer', 'todayBusiness'])) {
# 负责人 # 负责人
@ -607,14 +727,14 @@ class Message extends ApiCommon
$where['next_time'] = ['between', [$todayTime[0], $todayTime[1]]]; $where['next_time'] = ['between', [$todayTime[0], $todayTime[1]]];
# 是否已处理(联系) # 是否已处理(联系)
$where['is_dealt'] = 0; $where['is_dealt'] = 0;
# 线索 # 线索
if ($type == 'todayLeads') { if ($type == 'todayLeads') {
$leadsId = !empty($typeId) ? $typeId : Db::name('crm_leads')->where($where)->column('leads_id'); $leadsId = !empty($typeId) ? $typeId : Db::name('crm_leads')->where($where)->column('leads_id');
Db::name('crm_leads')->whereIn('leads_id', $leadsId)->update([ Db::name('crm_leads')->whereIn('leads_id', $leadsId)->update([
'last_time' => time(), 'last_time' => time(),
'is_dealt' => 1, 'is_dealt' => 1,
'follow' => '已跟进' 'follow' => '已跟进'
]); ]);
} }
# 客户 # 客户
@ -622,8 +742,8 @@ class Message extends ApiCommon
$customerId = !empty($typeId) ? $typeId : Db::name('crm_customer')->where($where)->column('customer_id'); $customerId = !empty($typeId) ? $typeId : Db::name('crm_customer')->where($where)->column('customer_id');
Db::name('crm_customer')->whereIn('customer_id', $customerId)->update([ Db::name('crm_customer')->whereIn('customer_id', $customerId)->update([
'last_time' => time(), 'last_time' => time(),
'is_dealt' => 1, 'is_dealt' => 1,
'follow' => '已跟进' 'follow' => '已跟进'
]); ]);
} }
# 商机 # 商机
@ -631,17 +751,17 @@ class Message extends ApiCommon
$businessId = !empty($typeId) ? $typeId : Db::name('crm_business')->where($where)->column('business_id'); $businessId = !empty($typeId) ? $typeId : Db::name('crm_business')->where($where)->column('business_id');
Db::name('crm_business')->whereIn('business_id', $businessId)->update([ Db::name('crm_business')->whereIn('business_id', $businessId)->update([
'last_time' => time(), 'last_time' => time(),
'is_dealt' => 1 'is_dealt' => 1
]); ]);
} }
} }
# 处理分配给我的线索、客户 # 处理分配给我的线索、客户
if (in_array($type, ['followLeads', 'followCustomer'])) { if (in_array($type, ['followLeads', 'followCustomer'])) {
$where['owner_user_id'] = $userId; $where['owner_user_id'] = $userId;
$where['follow'] = [['neq','已跟进'], null, 'or']; $where['follow'] = [['neq', '已跟进'], null, 'or'];
$where['is_allocation'] = 1; $where['is_allocation'] = 1;
# 线索 # 线索
if ($type == 'followLeads') { if ($type == 'followLeads') {
$leadsId = !empty($typeId) ? $typeId : Db::name('crm_leads')->where($where)->column('leads_id'); $leadsId = !empty($typeId) ? $typeId : Db::name('crm_leads')->where($where)->column('leads_id');
@ -653,12 +773,12 @@ class Message extends ApiCommon
Db::name('crm_customer')->whereIn('customer_id', $customerId)->update(['follow' => '已跟进']); Db::name('crm_customer')->whereIn('customer_id', $customerId)->update(['follow' => '已跟进']);
} }
} }
# 处理待审核合同、回款、发票 # 处理待审核合同、回款、发票
if (in_array($type, ['checkContract', 'checkReceivables', 'checkInvoice'])) { if (in_array($type, ['checkContract', 'checkReceivables', 'checkInvoice', 'checkBusiness', 'checkCustomerCheck', 'newBusiness'])) {
$where['check_status'] = ['lt','2']; $where['check_status'] = ['lt', '2'];
$where['check_user_id'] = ['like',',%' . $userId . '%,']; $where['check_user_id'] = ['like', ',%' . $userId . '%,'];
# 合同 # 合同
if ($type == 'checkContract') { if ($type == 'checkContract') {
$contractId = !empty($typeId) ? $typeId : Db::name('crm_contract')->where($where)->column('contract_id'); $contractId = !empty($typeId) ? $typeId : Db::name('crm_contract')->where($where)->column('contract_id');
@ -674,33 +794,49 @@ class Message extends ApiCommon
$invoiceId = !empty($typeId) ? $typeId : Db::name('crm_invoice')->where($where)->column('invoice_id'); $invoiceId = !empty($typeId) ? $typeId : Db::name('crm_invoice')->where($where)->column('invoice_id');
db('crm_dealt_relation')->where('user_id', $userId)->where('types', 'crm_invoice')->whereIn('types_id', $invoiceId)->delete(); db('crm_dealt_relation')->where('user_id', $userId)->where('types', 'crm_invoice')->whereIn('types_id', $invoiceId)->delete();
} }
# 商机
if ($type == 'checkBusiness') {
$businessId = !empty($typeId) ? $typeId : Db::name('crm_business')->where($where)->column('business_id');
db('crm_dealt_relation')->where('user_id', $userId)->where('types', 'crm_business')->whereIn('types_id', $businessId)->delete();
}
# 客户捞取
if ($type == 'checkCustomerCheck') {
$customerCheckId = !empty($typeId) ? $typeId : Db::name('crm_customer_check')->where($where)->column('customer_check_id');
db('crm_dealt_relation')->where('user_id', $userId)->where('types', 'crm_customer_check')->whereIn('types_id', $customerCheckId)->delete();
}
# 新商机
if ($type == 'newBusiness') {
$newBusinessId = !empty($typeId) ? $typeId : Db::name('crm_business')->where($where)->column('business_id');
db('crm_dealt_relation')->where('user_id', $userId)->where('types', 'crm_business_new')->whereIn('types_id', $newBusinessId)->delete();
}
} }
# 处理到期合同 # 处理到期合同
if ($type == 'endContract') { if ($type == 'endContract') {
$configModel = new \app\crm\model\ConfigData(); $configModel = new \app\crm\model\ConfigData();
$configInfo = $configModel->getData(); $configInfo = $configModel->getData();
$expireDay = $configInfo['contract_day'] ? : '7'; $expireDay = $configInfo['contract_day'] ?: '7';
$where['owner_user_id'] = $userId; $where['owner_user_id'] = $userId;
$where['end_time'] = ['between', [date('Y-m-d',time()), date('Y-m-d',time()+86400*$expireDay)]]; $where['end_time'] = ['between', [date('Y-m-d', time()), date('Y-m-d', time() + 86400 * $expireDay)]];
$where['expire_remind'] = 1; $where['expire_remind'] = 1;
$contractId = !empty($typeId) ? $typeId : Db::name('crm_contract')->where($where)->column('contract_id'); $contractId = !empty($typeId) ? $typeId : Db::name('crm_contract')->where($where)->column('contract_id');
Db::name('crm_contract')->whereIn('contract_id', $contractId)->update(['expire_remind' => 0]); Db::name('crm_contract')->whereIn('contract_id', $contractId)->update(['expire_remind' => 0]);
} }
# 处理待回访合同 # 处理待回访合同
if ($type == 'returnVisitRemind') { if ($type == 'returnVisitRemind') {
$where['owner_user_id'] = !empty($isSub) ? ['in', getSubUserId(false)] : $userId; # 负责人 $where['owner_user_id'] = !empty($isSub) ? ['in', getSubUserId(false)] : $userId; # 负责人
$where['is_visit'] = 0; # 未回访 $where['is_visit'] = 0; # 未回访
$where['check_status'] = 2; # 审核通过 $where['check_status'] = 2; # 审核通过
$contractId = !empty($typeId) ? $typeId : Db::name('crm_contract')->where($where)->column('contract_id'); $contractId = !empty($typeId) ? $typeId : Db::name('crm_contract')->where($where)->column('contract_id');
Db::name('crm_contract')->whereIn('contract_id', $contractId)->update(['is_visit' => 1]); Db::name('crm_contract')->whereIn('contract_id', $contractId)->update(['is_visit' => 1]);
} }
# 处理待进入公海 # 处理待进入公海
if ($type == 'putInPoolRemind') { if ($type == 'putInPoolRemind') {
if (!empty($typeId)) { if (!empty($typeId)) {
@ -713,66 +849,73 @@ class Message extends ApiCommon
$whereData['is_remind'] = 1; $whereData['is_remind'] = 1;
$whereData['user_id'] = $userId; $whereData['user_id'] = $userId;
$whereData['pool_remain'] = 0; $whereData['pool_remain'] = 0;
$whereData['scene_id'] = db('admin_scene')->where(['types' => 'crm_customer','bydata' => empty($isSub) ? 'me' : 'sub'])->value('scene_id'); $whereData['scene_id'] = db('admin_scene')->where(['types' => 'crm_customer', 'bydata' => empty($isSub) ? 'me' : 'sub'])->value('scene_id');
$whereData['owner_user_id'] = !empty($isSub) ? ['in', getSubUserId(false, 0, $userId)] : $userId; $whereData['owner_user_id'] = !empty($isSub) ? ['in', getSubUserId(false, 0, $userId)] : $userId;
$poolCustomers = (new \app\crm\model\Customer())->getDataList($whereData); $poolCustomers = (new \app\crm\model\Customer())->getDataList($whereData);
$ids = []; $ids = [];
foreach ($poolCustomers['list'] AS $key => $value) { foreach ($poolCustomers['list'] as $key => $value) {
if (!empty($value['customer_id'])) $ids[] = $value['customer_id']; if (!empty($value['customer_id'])) $ids[] = $value['customer_id'];
} }
if (!empty($ids)) Db::name('crm_customer')->whereIn('customer_id', $ids)->update(['pool_remain' => 1]); if (!empty($ids)) Db::name('crm_customer')->whereIn('customer_id', $ids)->update(['pool_remain' => 1]);
} }
} }
} }
# 带回款提醒 # 带回款提醒
if ($type == 'remindReceivablesPlan') { if ($type == 'remindReceivablesPlan') {
$planId = []; $planId = [];
if (!empty($typeId)) { if (!empty($typeId)) {
$planId = $typeId; $planId = $typeId;
} else { } else {
$param['owner_user_id'] = $isSub ? ['in',getSubUserId(false)] : $userId; $param['owner_user_id'] = $isSub ? ['in', getSubUserId(false)] : $userId;
$param['receivables_id'] = 0; $param['receivables_id'] = 0;
$param['check_status'] = ['lt', 2]; $param['check_status'] = ['lt', 2];
$param['remind_date'] = ['elt', date('Y-m-d',time())]; $param['remind_date'] = ['elt', date('Y-m-d', time())];
$param['return_date'] = ['egt', date('Y-m-d',time())]; $param['return_date'] = ['egt', date('Y-m-d', time())];
$param['types'] = 1; $param['types'] = 1;
$param['page'] = 1; $param['page'] = 1;
$param['limit'] = 1000; $param['limit'] = 1000;
$receivablesPlanModel = model('ReceivablesPlan'); $receivablesPlanModel = model('ReceivablesPlan');
$data = $receivablesPlanModel->getDataList($param); $data = $receivablesPlanModel->getDataList($param);
foreach ($data['list'] AS $key => $value) { foreach ($data['list'] as $key => $value) {
$planId[] = $value['plan_id']; $planId[] = $value['plan_id'];
} }
} }
if (!empty($planId)) db('crm_receivables_plan')->whereIn('plan_id', $planId)->update(['is_dealt' => 1]); if (!empty($planId)) db('crm_receivables_plan')->whereIn('plan_id', $planId)->update(['is_dealt' => 1]);
} }
cache::rm('todayLeadsCount'.$userId); cache::rm('todayLeadsCount' . $userId);
cache::rm('todayCustomerCount'.$userId); cache::rm('todayCustomerCount' . $userId);
cache::rm('todayBusinessCount'.$userId); cache::rm('todayBusinessCount' . $userId);
cache::rm('followLeadsCount'.$userId); cache::rm('followLeadsCount' . $userId);
cache::rm('followCustomerCount'.$userId); cache::rm('followCustomerCount' . $userId);
cache::rm('checkContractCount'.$userId); cache::rm('checkContractCount' . $userId);
cache::rm('checkReceivablesCount'.$userId); cache::rm('checkReceivablesCount' . $userId);
cache::rm('checkInvoiceCount'.$userId); cache::rm('checkInvoiceCount' . $userId);
cache::rm('remindReceivablesPlanCount'.$userId); cache::rm('remindReceivablesPlanCount' . $userId);
cache::rm('visitContractCount'.$userId); cache::rm('visitContractCount' . $userId);
cache::rm('endContractCount'.$userId); cache::rm('endContractCount' . $userId);
cache::rm('remindCustomerCount'.$userId); cache::rm('remindCustomerCount' . $userId);
cache::rm('checkCustomerCheckCount' . $userId);
cache::rm('todayLeadsTime'.$userId); cache::rm('checkBusinessCount' . $userId);
cache::rm('todayCustomerTime'.$userId); cache::rm('newBusinessCount' . $userId);
cache::rm('todayBusinessTime'.$userId);
cache::rm('followLeadsTime'.$userId); cache::rm('todayLeadsTime' . $userId);
cache::rm('followCustomerTime'.$userId); cache::rm('todayCustomerTime' . $userId);
cache::rm('checkContractTime'.$userId); cache::rm('todayBusinessTime' . $userId);
cache::rm('checkReceivablesTime'.$userId); cache::rm('followLeadsTime' . $userId);
cache::rm('checkInvoiceTime'.$userId); cache::rm('followCustomerTime' . $userId);
cache::rm('remindReceivablesPlanTime'.$userId); cache::rm('checkContractTime' . $userId);
cache::rm('visitContractTime'.$userId); cache::rm('checkReceivablesTime' . $userId);
cache::rm('endContractTime'.$userId); cache::rm('checkInvoiceTime' . $userId);
cache::rm('remindCustomerTime'.$userId); cache::rm('checkBusinessTime' . $userId);
cache::rm('remindReceivablesPlanTime' . $userId);
cache::rm('visitContractTime' . $userId);
cache::rm('endContractTime' . $userId);
cache::rm('remindCustomerTime' . $userId);
cache::rm('checkCustomerCheckTime' . $userId);
cache::rm('checkBusinessTime' . $userId);
cache::rm('newBusinessTime' . $userId);
return resultArray(['data' => '操作成功!']); return resultArray(['data' => '操作成功!']);
} }
} }

@ -12,7 +12,9 @@ use app\admin\model\ActionRecord;
use app\admin\model\Common; use app\admin\model\Common;
use app\admin\model\Field; use app\admin\model\Field;
use app\admin\model\File; use app\admin\model\File;
use app\admin\model\Message;
use app\admin\model\Record; use app\admin\model\Record;
use app\admin\model\User;
use app\crm\model\CustomerConfig; use app\crm\model\CustomerConfig;
use PDOStatement; use PDOStatement;
use think\Collection; use think\Collection;
@ -25,9 +27,9 @@ class CustomerPoolLogic extends Common
* 公海列表 * 公海列表
* *
* @param $param * @param $param
* @author fanqi
* @since 2021-04-14
* @return array * @return array
* @since 2021-04-14
* @author fanqi
*/ */
public function getPoolList($param) public function getPoolList($param)
{ {
@ -46,10 +48,10 @@ class CustomerPoolLogic extends Common
$searchMap = []; $searchMap = [];
if ($param['search'] == '0' || !empty($param['search'])) { if ($param['search'] == '0' || !empty($param['search'])) {
$search = $param['search']; $search = $param['search'];
$searchMap = function($query) use ($search) { $searchMap = function ($query) use ($search) {
$query->where('customer.name',array('like','%'.$search.'%')) $query->where('customer.name', array('like', '%' . $search . '%'))
->whereOr('customer.mobile',array('like','%'.$search.'%')) ->whereOr('customer.mobile', array('like', '%' . $search . '%'))
->whereOr('customer.telephone',array('like','%'.$search.'%')); ->whereOr('customer.telephone', array('like', '%' . $search . '%'));
}; };
} }
@ -60,11 +62,11 @@ class CustomerPoolLogic extends Common
} }
// 公海条件 // 公海条件
if ($param['is_excel'] == 1 && !empty($param['customer_id'])) { if ($param['is_excel'] == 1 && !empty($param['customer_id'])) {
$authMap['customer.customer_id'] = ['in', trim(arrayToString($param['customer_id']),',')]; $authMap['customer.customer_id'] = ['in', trim(arrayToString($param['customer_id']), ',')];
} }
// 排序 // 排序
if (!empty($orderField) && !empty($orderType)) { if (!empty($orderField) && !empty($orderType)) {
$order = $fieldModel->getOrderByFormtype('crm_customer','customer', $orderField, $orderType); $order = $fieldModel->getOrderByFormtype('crm_customer', 'customer', $orderField, $orderType);
} else { } else {
$order = 'customer.update_time desc'; $order = 'customer.update_time desc';
} }
@ -76,7 +78,7 @@ class CustomerPoolLogic extends Common
unset($param['is_excel']); unset($param['is_excel']);
unset($param['customer_id']); unset($param['customer_id']);
// 格式化参数 // 格式化参数
$request = $this->fmtRequest( $param ); $request = $this->fmtRequest($param);
$requestMap = !empty($request['map']) ? $request['map'] : []; $requestMap = !empty($request['map']) ? $request['map'] : [];
// 高级搜索 // 高级搜索
@ -89,7 +91,7 @@ class CustomerPoolLogic extends Common
->join('__CRM_CUSTOMER__ customer', 'customer.customer_id = relation.customer_id', 'LEFT') ->join('__CRM_CUSTOMER__ customer', 'customer.customer_id = relation.customer_id', 'LEFT')
->where($where)->where($searchMap)->where($map)->where($authMap)->count(); ->where($where)->where($searchMap)->where($map)->where($authMap)->count();
if (empty($customerPoolCount)) return $result; if (empty($customerPoolCount)) return $result;
$customerPoolList = db('crm_customer_pool_relation')->alias('relation')->field($customerFieldString) $customerPoolList = db('crm_customer_pool_relation')->alias('relation')->field($customerFieldString)
->join('__CRM_CUSTOMER__ customer', 'customer.customer_id = relation.customer_id', 'LEFT') ->join('__CRM_CUSTOMER__ customer', 'customer.customer_id = relation.customer_id', 'LEFT')
->limit($request['offset'], $request['length'])->where($where)->where($searchMap)->where($map)->where($authMap)->orderRaw($order)->select(); ->limit($request['offset'], $request['length'])->where($where)->where($searchMap)->where($map)->where($authMap)->orderRaw($order)->select();
@ -114,12 +116,12 @@ class CustomerPoolLogic extends Common
$extraData = []; $extraData = [];
$customerIds = array_column($customerPoolList, 'customer_id'); $customerIds = array_column($customerPoolList, 'customer_id');
$extraList = db('crm_customer_data')->whereIn('customer_id', $customerIds)->select(); $extraList = db('crm_customer_data')->whereIn('customer_id', $customerIds)->select();
foreach ($extraList AS $key => $value) { foreach ($extraList as $key => $value) {
$extraData[$value['customer_id']][$value['field']] = $value['content']; $extraData[$value['customer_id']][$value['field']] = $value['content'];
} }
// 整理公海数据 // 整理公海数据
foreach ($customerPoolList AS $key => $value) { foreach ($customerPoolList as $key => $value) {
$customerPoolList[$key]['create_user_name'] = !empty($userData[$value['create_user_id']]) ? $userData[$value['create_user_id']] : ''; $customerPoolList[$key]['create_user_name'] = !empty($userData[$value['create_user_id']]) ? $userData[$value['create_user_id']] : '';
$customerPoolList[$key]['before_owner_user_name'] = !empty($userData[$value['before_owner_user_id']]) ? $userData[$value['before_owner_user_id']] : ''; $customerPoolList[$key]['before_owner_user_name'] = !empty($userData[$value['before_owner_user_id']]) ? $userData[$value['before_owner_user_id']] : '';
@ -130,38 +132,38 @@ class CustomerPoolLogic extends Common
$customerPoolList[$key]['into_pool_time'] = !empty($value['into_pool_time']) ? date('Y-m-d H:i:s', $value['into_pool_time']) : null; $customerPoolList[$key]['into_pool_time'] = !empty($value['into_pool_time']) ? date('Y-m-d H:i:s', $value['into_pool_time']) : null;
// 处理日期时间类型的自定义字段 // 处理日期时间类型的自定义字段
foreach ($datetimeField AS $k => $v) { foreach ($datetimeField as $k => $v) {
if (!empty($value[$v])) $customerPoolList[$key][$v] = date('Y-m-d H:i:s', $value[$v]); if (!empty($value[$v])) $customerPoolList[$key][$v] = date('Y-m-d H:i:s', $value[$v]);
} }
// 处理人员类型的自定义字段 // 处理人员类型的自定义字段
foreach ($userField AS $k => $v) { foreach ($userField as $k => $v) {
if (!empty($value[$v])) { if (!empty($value[$v])) {
$customerPoolList[$key][$v] = $this->fieldTransformToText($value[$v], $userData); $customerPoolList[$key][$v] = $this->fieldTransformToText($value[$v], $userData);
} }
} }
// 处理部门类型的自定义字段 // 处理部门类型的自定义字段
foreach ($structureField AS $k => $v) { foreach ($structureField as $k => $v) {
if (!empty($value[$v])) $customerPoolList[$key][$v] = $this->fieldTransformToText($value[$v], $structureData); if (!empty($value[$v])) $customerPoolList[$key][$v] = $this->fieldTransformToText($value[$v], $structureData);
} }
// 布尔值类型字段 // 布尔值类型字段
foreach ($booleanField AS $k => $v) { foreach ($booleanField as $k => $v) {
$customerPoolList[$key][$v] = !empty($value[$v]) ? (string)$value[$v] : '0'; $customerPoolList[$key][$v] = !empty($value[$v]) ? (string)$value[$v] : '0';
} }
// 处理日期区间类型字段的格式 // 处理日期区间类型字段的格式
foreach ($dateIntervalField AS $k => $v) { foreach ($dateIntervalField as $k => $v) {
$customerPoolList[$key][$v] = !empty($extraData[$value['customer_id']][$v]) ? json_decode($extraData[$value['customer_id']][$v], true) : null; $customerPoolList[$key][$v] = !empty($extraData[$value['customer_id']][$v]) ? json_decode($extraData[$value['customer_id']][$v], true) : null;
} }
// 处理地址类型字段的格式 // 处理地址类型字段的格式
foreach ($positionField AS $k => $v) { foreach ($positionField as $k => $v) {
$customerPoolList[$key][$v] = !empty($extraData[$value['customer_id']][$v]) ? json_decode($extraData[$value['customer_id']][$v], true) : null; $customerPoolList[$key][$v] = !empty($extraData[$value['customer_id']][$v]) ? json_decode($extraData[$value['customer_id']][$v], true) : null;
} }
// 手写签名类型字段 // 手写签名类型字段
foreach ($handwritingField AS $k => $v) { foreach ($handwritingField as $k => $v) {
$handwritingData = !empty($value[$v]) ? db('admin_file')->where('file_id', $value[$v])->value('file_path') : null; $handwritingData = !empty($value[$v]) ? db('admin_file')->where('file_id', $value[$v])->value('file_path') : null;
$customerPoolList[$key][$v] = ['url' => !empty($handwritingData) ? getFullPath($handwritingData) : null]; $customerPoolList[$key][$v] = ['url' => !empty($handwritingData) ? getFullPath($handwritingData) : null];
} }
// 定位类型字段 // 定位类型字段
foreach ($locationField AS $k => $v) { foreach ($locationField as $k => $v) {
$customerPoolList[$key][$v] = !empty($extraData[$value['customer_id']][$v]) ? json_decode($extraData[$value['customer_id']][$v], true) : null; $customerPoolList[$key][$v] = !empty($extraData[$value['customer_id']][$v]) ? json_decode($extraData[$value['customer_id']][$v], true) : null;
} }
} }
@ -176,9 +178,9 @@ class CustomerPoolLogic extends Common
* 公海详情 * 公海详情
* *
* @param array $param pool_id 公海IDcustomer_id 客户ID * @param array $param pool_id 公海IDcustomer_id 客户ID
* @author fanqi
* @since 2021-04-14
* @return array|bool|PDOStatement|string|Model|null * @return array|bool|PDOStatement|string|Model|null
* @since 2021-04-14
* @author fanqi
*/ */
public function getPoolData($param) public function getPoolData($param)
{ {
@ -214,19 +216,19 @@ class CustomerPoolLogic extends Common
$data['into_pool_time'] = !empty($data['into_pool_time']) ? date('Y-m-d H:i:s', $data['into_pool_time']) : null; $data['into_pool_time'] = !empty($data['into_pool_time']) ? date('Y-m-d H:i:s', $data['into_pool_time']) : null;
# 处理日期时间类型的自定义字段 # 处理日期时间类型的自定义字段
foreach ($datetimeField AS $k => $v) { foreach ($datetimeField as $k => $v) {
if (isset($data[$v])) { if (isset($data[$v])) {
$data[$v] = !empty($data[$v]) ? date('Y-m-d H:i:s', $data[$v]) : null; $data[$v] = !empty($data[$v]) ? date('Y-m-d H:i:s', $data[$v]) : null;
} }
} }
# 处理人员类型的自定义字段 # 处理人员类型的自定义字段
foreach ($userField AS $k => $v) { foreach ($userField as $k => $v) {
if (isset($data[$v]) && !empty($data[$v])) { if (isset($data[$v]) && !empty($data[$v])) {
$data[$v] = $this->fieldTransformToText($data[$v], $userData); $data[$v] = $this->fieldTransformToText($data[$v], $userData);
} }
} }
# 处理部门类型的自定义字段 # 处理部门类型的自定义字段
foreach ($structureField AS $k => $v) { foreach ($structureField as $k => $v) {
if (isset($data[$v]) && !empty($data[$v])) { if (isset($data[$v]) && !empty($data[$v])) {
$data[$v] = $this->fieldTransformToText($data[$v], $structureData); $data[$v] = $this->fieldTransformToText($data[$v], $structureData);
} }
@ -252,7 +254,7 @@ class CustomerPoolLogic extends Common
$customerData = $this->getCustomerList($customerId); $customerData = $this->getCustomerList($customerId);
# 验证是否是公海数据 # 验证是否是公海数据
foreach ($customerId AS $key => $value) { foreach ($customerId as $key => $value) {
if (empty($customerData[$value])) { if (empty($customerData[$value])) {
$message[] = '删除 《' . $customerData[$value]['name'] . '》 失败,原因:公海客户不存在!'; $message[] = '删除 《' . $customerData[$value]['name'] . '》 失败,原因:公海客户不存在!';
@ -275,7 +277,7 @@ class CustomerPoolLogic extends Common
$customerContractData = db('crm_contract')->whereIn('customer_id', $customerId)->column('customer_id'); $customerContractData = db('crm_contract')->whereIn('customer_id', $customerId)->column('customer_id');
# 验证客户下是否存在联系人、商机、合同 # 验证客户下是否存在联系人、商机、合同
foreach ($customerId AS $key => $value) { foreach ($customerId as $key => $value) {
if (in_array($value, $customerContactsData)) { if (in_array($value, $customerContactsData)) {
$message[] = '删除 《' . $customerData[$value]['name'] . '》 失败,原因:客户下存在联系人!'; $message[] = '删除 《' . $customerData[$value]['name'] . '》 失败,原因:客户下存在联系人!';
@ -307,13 +309,13 @@ class CustomerPoolLogic extends Common
# 记录到数据操作日志 # 记录到数据操作日志
$ip = request()->ip(); $ip = request()->ip();
$addOperationLogData = []; $addOperationLogData = [];
foreach ($customerId AS $key => $value) { foreach ($customerId as $key => $value) {
$addOperationLogData[] = [ $addOperationLogData[] = [
'user_id' => $param['user_id'], 'user_id' => $param['user_id'],
'client_ip' => $ip, 'client_ip' => $ip,
'module' => 'crm_customer', 'module' => 'crm_customer',
'action_id' => $value, 'action_id' => $value,
'content' => '删除了客户:' . $customerData[$value]['name'], 'content' => '删除了客户:' . $customerData[$value]['name'],
'create_time' => time(), 'create_time' => time(),
'action_name' => 'delete', 'action_name' => 'delete',
'target_name' => $customerData[$value]['name'] 'target_name' => $customerData[$value]['name']
@ -332,9 +334,9 @@ class CustomerPoolLogic extends Common
* 获取公海池列表 * 获取公海池列表
* *
* @param array $param 查询参数user_id 用户idstructure_id 部门id * @param array $param 查询参数user_id 用户idstructure_id 部门id
* @author fanqi
* @since 2021-04-21
* @return bool|PDOStatement|string|Collection * @return bool|PDOStatement|string|Collection
* @since 2021-04-21
* @author fanqi
*/ */
public function getPondList($param) public function getPondList($param)
{ {
@ -345,7 +347,7 @@ class CustomerPoolLogic extends Common
->where(function ($query) use ($param, $adminTypes) { ->where(function ($query) use ($param, $adminTypes) {
if (!in_array(1, $adminTypes)) $query->where('admin_user_ids', 'like', '%,' . $param['user_id'] . ',%'); if (!in_array(1, $adminTypes)) $query->where('admin_user_ids', 'like', '%,' . $param['user_id'] . ',%');
if (!in_array(1, $adminTypes)) $query->whereOr('user_ids', 'like', '%,' . $param['user_id'] . ',%'); if (!in_array(1, $adminTypes)) $query->whereOr('user_ids', 'like', '%,' . $param['user_id'] . ',%');
if (!in_array(1, $adminTypes)) $query->whereOr('department_ids', '%,' . $param['structure_id'] . ',%'); if (!in_array(1, $adminTypes)) $query->whereOr('department_ids', '%,' . $param['structure_id'] . ',%');
})->select(); })->select();
} }
@ -353,9 +355,9 @@ class CustomerPoolLogic extends Common
* 获取公海字段 * 获取公海字段
* *
* @param array $param pool_id 公海IDaction 操作类型action_id 数据id * @param array $param pool_id 公海IDaction 操作类型action_id 数据id
* @author fanqi
* @since 2021-04-13
* @return array * @return array
* @since 2021-04-13
* @author fanqi
*/ */
public function getFieldList($param) public function getFieldList($param)
{ {
@ -363,14 +365,14 @@ class CustomerPoolLogic extends Common
# 自定义字段 # 自定义字段
$where = [ $where = [
'pool_id' => $param['pool_id'], 'pool_id' => $param['pool_id'],
'is_hidden' => 0, 'is_hidden' => 0,
'form_type' => ['notin', ['file', 'desc_text', 'detail_table']] 'form_type' => ['notin', ['file', 'desc_text', 'detail_table']]
]; ];
$list = db('crm_customer_pool_field_setting')->where($where)->select(); $list = db('crm_customer_pool_field_setting')->where($where)->select();
# 处理公海字段 # 处理公海字段
foreach ($list AS $key => $value) { foreach ($list as $key => $value) {
$list[$key]['field'] = $value['field_name']; $list[$key]['field'] = $value['field_name'];
# 处理别名 # 处理别名
@ -392,12 +394,12 @@ class CustomerPoolLogic extends Common
} }
$data[$list[$key]['field']] = [ $data[$list[$key]['field']] = [
'field' => $list[$key]['field'], 'field' => $list[$key]['field'],
'fieldName' => $list[$key]['fieldName'], 'fieldName' => $list[$key]['fieldName'],
'name' => $list[$key]['name'], 'name' => $list[$key]['name'],
'width' => '', 'width' => '',
'is_hidden' => 1, 'is_hidden' => 1,
'system' => $list[$key]['system'], 'system' => $list[$key]['system'],
'form_type' => $list[$key]['form_type'] 'form_type' => $list[$key]['form_type']
]; ];
} }
@ -411,9 +413,9 @@ class CustomerPoolLogic extends Common
/** /**
* 高级筛选字段列表 * 高级筛选字段列表
* *
* @author fanqi
* @since 2021-04-14
* @return array * @return array
* @since 2021-04-14
* @author fanqi
*/ */
public function getAdvancedFilterFieldList() public function getAdvancedFilterFieldList()
{ {
@ -434,7 +436,7 @@ class CustomerPoolLogic extends Common
$list = array_merge($list, $base); $list = array_merge($list, $base);
# 整理数据 # 整理数据
foreach ($list AS $key => $value) { foreach ($list as $key => $value) {
if (!empty($value['setting'])) $list[$key]['setting'] = explode(chr(10), $value['setting']); if (!empty($value['setting'])) $list[$key]['setting'] = explode(chr(10), $value['setting']);
} }
@ -445,17 +447,17 @@ class CustomerPoolLogic extends Common
* 领取公海客户 * 领取公海客户
* *
* @param array $param user_id 领取人IDcustomer_id 要领取的客户ID * @param array $param user_id 领取人IDcustomer_id 要领取的客户ID
* @author fanqi
* @since 2021-04-15
* @return array * @return array
* @since 2021-04-15
* @author fanqi
*/ */
public function receiveCustomers($param) public function receiveCustomers($param)
{ {
if (empty($param['user_id'])) return ['缺少员工ID']; if (empty($param['user_id'])) return ['缺少员工ID'];
# 查询参数 # 查询参数
$userId = $param['user_id']; $userId = $param['user_id'];
$customerId = $param['customer_id']; $customerId = $param['customer_id'];
# 消息数据 # 消息数据
@ -465,7 +467,7 @@ class CustomerPoolLogic extends Common
$customerData = $this->getCustomerList($customerId); $customerData = $this->getCustomerList($customerId);
# 剔除非公海客户 # 剔除非公海客户
foreach ($customerId AS $key => $value) { foreach ($customerId as $key => $value) {
if (!empty($customerData[$value]['owner_user_id'])) { if (!empty($customerData[$value]['owner_user_id'])) {
$message[] = '客户《' . $customerData[$value]['name'] . '》领取失败,失败原因:不是公海客户!'; $message[] = '客户《' . $customerData[$value]['name'] . '》领取失败,失败原因:不是公海客户!';
@ -485,28 +487,28 @@ class CustomerPoolLogic extends Common
$failCustomer = []; $failCustomer = [];
if (!is_bool($exceedCount) && !empty($exceedCount) && $exceedCount > 0) { if (!is_bool($exceedCount) && !empty($exceedCount) && $exceedCount > 0) {
$failCustomer = array_slice($customerId, count($customerId) - $exceedCount); $failCustomer = array_slice($customerId, count($customerId) - $exceedCount);
foreach ($failCustomer AS $key => $value) { foreach ($failCustomer as $key => $value) {
$message[] = '客户《' . $customerData[$value]['name'] . '》领取失败,失败原因:持有客户数达到上限!'; $message[] = '客户《' . $customerData[$value]['name'] . '》领取失败,失败原因:持有客户数达到上限!';
} }
} }
# 可以领取的客户ID取差集 # 可以领取的客户ID取差集
$addCustomerId = count($customerId) == 1 ? $customerId : array_diff($customerId, $failCustomer); $addCustomerId = count($customerId) == 1 ? $customerId : array_diff($customerId, $failCustomer);
# 检查是否还有要领取的客户 # 检查是否还有要领取的客户
if (empty($addCustomerId)) return $message; if (empty($addCustomerId)) return $message;
# 查询领取客户的公海id # 查询领取客户的公海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(); $poolConfig = db('crm_customer_pool')->field(['before_owner_conf', 'before_owner_day', 'receive_conf', 'receive_count'])->where('pool_id', $poolId)->find();
# 前负责人N天内不能领取客户 # 前负责人N天内不能领取客户
if (!empty($poolConfig['before_owner_conf'])) { if (!empty($poolConfig['before_owner_conf'])) {
foreach ($addCustomerId AS $key => $value) { foreach ($addCustomerId as $key => $value) {
# 是前负责人,检查前负责人是否能够领取。 # 是前负责人,检查前负责人是否能够领取。
if ($userId == $customerData[$value]['before_owner_user_id']) { if ($userId == $customerData[$value]['before_owner_user_id']) {
$restrictDay = $customerData[$value]['into_pool_time'] + 86400 * $poolConfig['before_owner_day']; $restrictDay = $customerData[$value]['into_pool_time'] + 86400 * $poolConfig['before_owner_day'];
if (time() < $restrictDay) { if (time() < $restrictDay) {
$message[] = '客户《' . $customerData[$value]['name'] . '》领取失败,失败原因:进入公海后,'.$poolConfig['before_owner_day'].'天内不能领取!'; $message[] = '客户《' . $customerData[$value]['name'] . '》领取失败,失败原因:进入公海后,' . $poolConfig['before_owner_day'] . '天内不能领取!';
unset($addCustomerId[(int)$key]); unset($addCustomerId[(int)$key]);
} }
@ -525,46 +527,47 @@ class CustomerPoolLogic extends Common
$receiveCount = db('crm_customer_pool_record')->where($countWhere)->count(); $receiveCount = db('crm_customer_pool_record')->where($countWhere)->count();
if (!empty($poolConfig['receive_conf']) && $receiveCount + count($addCustomerId) > $poolConfig['receive_count']) { if (!empty($poolConfig['receive_conf']) && $receiveCount + count($addCustomerId) > $poolConfig['receive_count']) {
$overQuantity = ($receiveCount + count($addCustomerId)) - $poolConfig['receive_count']; $overQuantity = ($receiveCount + count($addCustomerId)) - $poolConfig['receive_count'];
$message[] = '领取客户失败,失败原因:超出当日可领取数量,超出'.$overQuantity.'个!'; $message[] = '领取客户失败,失败原因:超出当日可领取数量,超出' . $overQuantity . '个!';
return $message; return $message;
} }
# 整理客户更新数据 # 整理客户更新数据
$addCustomerData = [ $addCustomerData = [
'owner_user_id' => $userId, 'owner_user_id' => $userId,
'before_owner_user_id' => 0, 'before_owner_user_id' => 0,
'into_pool_time' => 0, 'into_pool_time' => 0,
'obtain_time' => time() 'obtain_time' => time(),
'is_allocation' => 1,
]; ];
# 整理字段操作记录和数据日志的数据 # 整理字段操作记录和数据日志的数据
$ip = request()->ip(); $ip = request()->ip();
$addActionRecordData = []; $addActionRecordData = [];
$addOperationLogData = []; $addOperationLogData = [];
$addReceiveData = []; $addReceiveData = [];
foreach ($addCustomerId AS $key => $value) { foreach ($addCustomerId as $key => $value) {
$addActionRecordData[] = [ $addActionRecordData[] = [
'user_id' => $userId, 'user_id' => $userId,
'types' => 'crm_customer', 'types' => 'crm_customer',
'action_id' => $value, 'action_id' => $value,
'content' => '领取了客户', 'content' => '领取了客户',
'create_time' => time() 'create_time' => time()
]; ];
$addOperationLogData[] = [ $addOperationLogData[] = [
'user_id' => $userId, 'user_id' => $userId,
'client_ip' => $ip, 'client_ip' => $ip,
'module' => 'crm_customer', 'module' => 'crm_customer',
'action_id' => $value, 'action_id' => $value,
'content' => '领取了客户', 'content' => '领取了客户',
'create_time' => time(), 'create_time' => time(),
'action_name' => 'update', 'action_name' => 'update',
'target_name' => $customerData[$value]['name'] 'target_name' => $customerData[$value]['name']
]; ];
$addReceiveData[] = [ $addReceiveData[] = [
'customer_id' => $value, 'customer_id' => $value,
'user_id' => $userId, 'user_id' => $userId,
'pool_id' => $poolId, 'pool_id' => $poolId,
'type' => 1, 'type' => 1,
'create_time' => time() 'create_time' => time()
]; ];
} }
@ -573,22 +576,22 @@ class CustomerPoolLogic extends Common
try { try {
# 领取客户 # 领取客户
Db::name('crm_customer')->whereIn('customer_id', $addCustomerId)->update($addCustomerData); Db::name('crm_customer')->whereIn('customer_id', $addCustomerId)->update($addCustomerData);
# 设置客户的联系人数据 # 设置客户的联系人数据
Db::name('crm_contacts')->whereIn('customer_id', $addCustomerId)->update(['owner_user_id' => $userId]); Db::name('crm_contacts')->whereIn('customer_id', $addCustomerId)->update(['owner_user_id' => $userId]);
# 删除公海与客户关联数据 # 删除公海与客户关联数据
Db::name('crm_customer_pool_relation')->whereIn('customer_id', $addCustomerId)->delete(); Db::name('crm_customer_pool_relation')->whereIn('customer_id', $addCustomerId)->delete();
# 字段操作日志 # 字段操作日志
Db::name('admin_action_record')->insertAll($addActionRecordData); Db::name('admin_action_record')->insertAll($addActionRecordData);
# 数据操作日志 # 数据操作日志
Db::name('admin_operation_log')->insertAll($addOperationLogData); Db::name('admin_operation_log')->insertAll($addOperationLogData);
# 记录领取的客户 # 记录领取的客户
Db::name('crm_customer_pool_record')->insertAll($addReceiveData); Db::name('crm_customer_pool_record')->insertAll($addReceiveData);
Db::commit(); Db::commit();
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
@ -603,16 +606,16 @@ class CustomerPoolLogic extends Common
* 分配客户 * 分配客户
* *
* @param array $param user_id 员工IDcustomer_id 客户ID * @param array $param user_id 员工IDcustomer_id 客户ID
* @author fanqi
* @since 2021-04-15
* @return array * @return array
* @since 2021-04-15
* @author fanqi
*/ */
public function distributeCustomer($param) public function distributeCustomer($param)
{ {
# 查询参数 # 查询参数
$userId = $param['user_id']; $userId = $param['user_id'];
$customerId = $param['customer_id']; $customerId = $param['customer_id'];
$username = db('admin_user')->where('id', $userId)->value('realname'); $username = db('admin_user')->where('id', $userId)->value('realname');
# 消息数据 # 消息数据
$message = []; $message = [];
@ -621,7 +624,7 @@ class CustomerPoolLogic extends Common
$customerData = $this->getCustomerList($customerId); $customerData = $this->getCustomerList($customerId);
# 剔除非公海客户 # 剔除非公海客户
foreach ($customerId AS $key => $value) { foreach ($customerId as $key => $value) {
if (!empty($customerData[$value]['owner_user_id'])) { if (!empty($customerData[$value]['owner_user_id'])) {
$message[] = '将客户《' . $customerData[$value]['name'] . '》分配给员工' . $username . '失败,失败原因:不是公海客户!'; $message[] = '将客户《' . $customerData[$value]['name'] . '》分配给员工' . $username . '失败,失败原因:不是公海客户!';
@ -641,7 +644,7 @@ class CustomerPoolLogic extends Common
$failCustomer = []; $failCustomer = [];
if (!is_bool($exceedCount) && !empty($exceedCount) && $exceedCount > 0) { if (!is_bool($exceedCount) && !empty($exceedCount) && $exceedCount > 0) {
$failCustomer = array_slice($customerId, count($customerId) - $exceedCount); $failCustomer = array_slice($customerId, count($customerId) - $exceedCount);
foreach ($failCustomer AS $key => $value) { foreach ($failCustomer as $key => $value) {
$message[] = '将客户《' . $customerData[$value]['name'] . '》分配给员工' . $username . '失败,失败原因:持有客户数达到上限!'; $message[] = '将客户《' . $customerData[$value]['name'] . '》分配给员工' . $username . '失败,失败原因:持有客户数达到上限!';
} }
} }
@ -652,16 +655,16 @@ class CustomerPoolLogic extends Common
# 检查是否还有要领取的客户 # 检查是否还有要领取的客户
if (empty($addCustomerId)) return $message; if (empty($addCustomerId)) return $message;
# 查询分配客户的公海id # 查询分配客户的公海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');
# 整理客户更新数据 # 整理客户更新数据
$addCustomerData = [ $addCustomerData = [
'owner_user_id' => $userId, 'owner_user_id' => $userId,
'before_owner_user_id' => 0, 'before_owner_user_id' => 0,
'into_pool_time' => 0, 'into_pool_time' => 0,
'obtain_time' => time(), 'obtain_time' => time(),
'is_dealt' => 0, 'is_dealt' => 0,
'is_allocation' => 1, 'is_allocation' => 1,
'follow' => '待跟进' 'follow' => '待跟进'
]; ];
# 整理字段操作记录和数据日志的数据 # 整理字段操作记录和数据日志的数据
@ -669,29 +672,29 @@ class CustomerPoolLogic extends Common
$addActionRecordData = []; $addActionRecordData = [];
$addOperationLogData = []; $addOperationLogData = [];
$addReceiveData = []; $addReceiveData = [];
foreach ($addCustomerId AS $key => $value) { foreach ($addCustomerId as $key => $value) {
$addActionRecordData[] = [ $addActionRecordData[] = [
'user_id' => $userId, 'user_id' => $userId,
'types' => 'crm_customer', 'types' => 'crm_customer',
'action_id' => $value, 'action_id' => $value,
'content' => '将客户 ' . $customerData[$value]['name'] . ' 分配给员工 ' . $username, 'content' => '将客户 ' . $customerData[$value]['name'] . ' 分配给员工 ' . $username,
'create_time' => time() 'create_time' => time()
]; ];
$addOperationLogData[] = [ $addOperationLogData[] = [
'user_id' => $userId, 'user_id' => $userId,
'client_ip' => $ip, 'client_ip' => $ip,
'module' => 'crm_customer', 'module' => 'crm_customer',
'action_id' => $value, 'action_id' => $value,
'content' => '将客户 ' . $customerData[$value]['name'] . ' 分配给员工 ' . $username, 'content' => '将客户 ' . $customerData[$value]['name'] . ' 分配给员工 ' . $username,
'create_time' => time(), 'create_time' => time(),
'action_name' => 'update', 'action_name' => 'update',
'target_name' => $customerData[$value]['name'] 'target_name' => $customerData[$value]['name']
]; ];
$addReceiveData[] = [ $addReceiveData[] = [
'customer_id' => $value, 'customer_id' => $value,
'user_id' => $userId, 'user_id' => $userId,
'pool_id' => $poolId, 'pool_id' => $poolId,
'type' => 3, 'type' => 3,
'create_time' => time() 'create_time' => time()
]; ];
} }
@ -730,26 +733,26 @@ class CustomerPoolLogic extends Common
* 公海权限 * 公海权限
* *
* @param $param * @param $param
* @author fanqi
* @since 2021-04-14
* @return array * @return array
* @since 2021-04-14
* @author fanqi
*/ */
public function getAuthorityData($param) public function getAuthorityData($param)
{ {
# 权限 # 权限
$authority = [ $authority = [
'index' => false, # 列表 'index' => false, # 列表
'receive' => false, # 领取 'receive' => false, # 领取
'distribute' => false, # 分配 'distribute' => false, # 分配
'excelexport' => false, # 导出 'excelexport' => false, # 导出
'excelimport' => false, # 导入 'excelimport' => false, # 导入
'delete' => false, # 删除 'delete' => false, # 删除
]; ];
if (empty($param['pool_id']) || empty($param['user_id']) || empty($param['structure_id'])) return $authority; if (empty($param['pool_id']) || empty($param['user_id']) || empty($param['structure_id'])) return $authority;
$poolId = $param['pool_id']; $poolId = $param['pool_id'];
$userId = $param['user_id']; $userId = $param['user_id'];
$structureId = $param['structure_id']; $structureId = $param['structure_id'];
# 是否是超级管理员 # 是否是超级管理员
@ -759,17 +762,17 @@ class CustomerPoolLogic extends Common
$data = db('crm_customer_pool')->field(['admin_user_ids', 'user_ids', 'department_ids'])->where('pool_id', $poolId)->find(); $data = db('crm_customer_pool')->field(['admin_user_ids', 'user_ids', 'department_ids'])->where('pool_id', $poolId)->find();
# 管理员、成员、部门 # 管理员、成员、部门
$adminUserIds = !empty($data['admin_user_ids']) ? explode(',', trim($data['admin_user_ids'], ',')) : []; $adminUserIds = !empty($data['admin_user_ids']) ? explode(',', trim($data['admin_user_ids'], ',')) : [];
$userIds = !empty($data['user_ids']) ? explode(',', trim($data['user_ids'], ',')) : []; $userIds = !empty($data['user_ids']) ? explode(',', trim($data['user_ids'], ',')) : [];
$structureIds = !empty($data['department_ids']) ? explode(',', trim($data['department_ids'], ',')) : []; $structureIds = !empty($data['department_ids']) ? explode(',', trim($data['department_ids'], ',')) : [];
# 权限判断 # 权限判断
$authority['index'] = ($userLevel || in_array($userId, $adminUserIds)) || (in_array($userId, $userIds) || in_array($structureId, $structureIds)); $authority['index'] = ($userLevel || in_array($userId, $adminUserIds)) || (in_array($userId, $userIds) || in_array($structureId, $structureIds));
$authority['receive'] = ($userLevel || in_array($userId, $adminUserIds)) || (in_array($userId, $userIds) || in_array($structureId, $structureIds)); $authority['receive'] = ($userLevel || in_array($userId, $adminUserIds)) || (in_array($userId, $userIds) || in_array($structureId, $structureIds));
$authority['distribute'] = $userLevel || in_array($userId, $adminUserIds); $authority['distribute'] = $userLevel || in_array($userId, $adminUserIds);
$authority['excelexport'] = $userLevel || in_array($userId, $adminUserIds); $authority['excelexport'] = $userLevel || in_array($userId, $adminUserIds);
$authority['excelimport'] = $userLevel || in_array($userId, $adminUserIds); $authority['excelimport'] = $userLevel || in_array($userId, $adminUserIds);
$authority['delete'] = $userLevel || in_array($userId, $adminUserIds); $authority['delete'] = $userLevel || in_array($userId, $adminUserIds);
return $authority; return $authority;
} }
@ -778,9 +781,9 @@ class CustomerPoolLogic extends Common
* 获取用户公海字段样式 * 获取用户公海字段样式
* *
* @param array $param pool 公海IDuser_is 用户ID * @param array $param pool 公海IDuser_is 用户ID
* @author fanqi
* @since 2021-04-22
* @return array[] * @return array[]
* @since 2021-04-22
* @author fanqi
*/ */
public function getFieldConfigIndex($param) public function getFieldConfigIndex($param)
{ {
@ -789,12 +792,12 @@ class CustomerPoolLogic extends Common
# 公海字段-用户配置数据 # 公海字段-用户配置数据
$data = db('crm_customer_pool_field_style')->where(['pool_id' => $param['pool_id'], 'user_id' => $param['user_id']])->value('content'); $data = db('crm_customer_pool_field_style')->where(['pool_id' => $param['pool_id'], 'user_id' => $param['user_id']])->value('content');
$data = !empty($data) ? json_decode($data, true) :[]; $data = !empty($data) ? json_decode($data, true) : [];
if (!empty($data)) { if (!empty($data)) {
$exceptFields = db('admin_field')->where(['types' => 'crm_customer', 'form_type' => ['in', ['file', 'handwriting_sign', 'desc_text', 'detail_table']]])->column('field'); $exceptFields = db('admin_field')->where(['types' => 'crm_customer', 'form_type' => ['in', ['file', 'handwriting_sign', 'desc_text', 'detail_table']]])->column('field');
foreach ($data AS $key => $value) { foreach ($data as $key => $value) {
if (in_array($value['field'], $exceptFields)) continue; if (in_array($value['field'], $exceptFields)) continue;
if (!empty($value['is_hidden'])) { if (!empty($value['is_hidden'])) {
@ -806,12 +809,12 @@ class CustomerPoolLogic extends Common
} else { } else {
# 公海字段-后台配置数据 # 公海字段-后台配置数据
$where = [ $where = [
'pool_id' => $param['pool_id'], 'pool_id' => $param['pool_id'],
'is_hidden' => 0, 'is_hidden' => 0,
'form_type' => ['notin', ['file', 'handwriting_sign', 'desc_text', 'detail_table']] 'form_type' => ['notin', ['file', 'handwriting_sign', 'desc_text', 'detail_table']]
]; ];
$poolField = db('crm_customer_pool_field_setting')->where($where)->select(); $poolField = db('crm_customer_pool_field_setting')->where($where)->select();
foreach ($poolField AS $key => $value) { foreach ($poolField as $key => $value) {
if (empty($value['is_hidden'])) { if (empty($value['is_hidden'])) {
$showList[] = [ $showList[] = [
'field' => $value['field_name'], 'field' => $value['field_name'],
@ -837,10 +840,10 @@ class CustomerPoolLogic extends Common
public function setFieldWidth($param) public function setFieldWidth($param)
{ {
$data = db('crm_customer_pool_field_style')->where(['pool_id' => $param['pool_id'], 'user_id' => $param['user_id']])->value('content'); $data = db('crm_customer_pool_field_style')->where(['pool_id' => $param['pool_id'], 'user_id' => $param['user_id']])->value('content');
$data = !empty($data) ? json_decode($data, true) :[]; $data = !empty($data) ? json_decode($data, true) : [];
if (!empty($data)) { if (!empty($data)) {
foreach ($data AS $key => $value) { foreach ($data as $key => $value) {
if ($param['field'] == $value['field']) { if ($param['field'] == $value['field']) {
$data[$key]['width'] = $param['width']; $data[$key]['width'] = $param['width'];
} }
@ -852,7 +855,7 @@ class CustomerPoolLogic extends Common
} else { } else {
$result = []; $result = [];
$poolField = db('crm_customer_pool_field_setting')->where('pool_id', $param['pool_id'])->select(); $poolField = db('crm_customer_pool_field_setting')->where('pool_id', $param['pool_id'])->select();
foreach ($poolField AS $key => $value) { foreach ($poolField as $key => $value) {
if ($param['field'] == $value['field_name']) { if ($param['field'] == $value['field_name']) {
$value['width'] = $param['width']; $value['width'] = $param['width'];
} }
@ -884,11 +887,11 @@ class CustomerPoolLogic extends Common
*/ */
public function setFieldConfig($param) public function setFieldConfig($param)
{ {
$data = []; $data = [];
$showList = $param['value']; $showList = $param['value'];
$hideList = $param['hide_value']; $hideList = $param['hide_value'];
foreach ($showList AS $key => $value) { foreach ($showList as $key => $value) {
$data[] = [ $data[] = [
'field' => $value['field'], 'field' => $value['field'],
'name' => $value['name'], 'name' => $value['name'],
@ -896,7 +899,7 @@ class CustomerPoolLogic extends Common
'width' => $value['width'] 'width' => $value['width']
]; ];
} }
foreach ($hideList AS $key => $value) { foreach ($hideList as $key => $value) {
$data[] = [ $data[] = [
'field' => $value['field'], 'field' => $value['field'],
'name' => $value['name'], 'name' => $value['name'],
@ -926,9 +929,9 @@ class CustomerPoolLogic extends Common
* *
* @param string $source 源ids * @param string $source 源ids
* @param array $target 目标数组 * @param array $target 目标数组
* @author fanqi
* @since 2021-04-14
* @return string * @return string
* @since 2021-04-14
* @author fanqi
*/ */
private function fieldTransformToText($source, $target) private function fieldTransformToText($source, $target)
{ {
@ -936,7 +939,7 @@ class CustomerPoolLogic extends Common
$array = explode(',', trim($source, ',')); $array = explode(',', trim($source, ','));
foreach ($array AS $kk => $vv) { foreach ($array as $kk => $vv) {
if (!empty($target[$vv])) $result[] = $target[$vv]; if (!empty($target[$vv])) $result[] = $target[$vv];
} }
@ -947,14 +950,14 @@ class CustomerPoolLogic extends Common
* 查询表字段 * 查询表字段
* *
* @param int $poolId 公海ID * @param int $poolId 公海ID
* @author fanqi
* @since 2021-04-14
* @return string * @return string
* @since 2021-04-14
* @author fanqi
*/ */
private function getPoolQueryField($poolId) private function getPoolQueryField($poolId)
{ {
# 自定义字段 # 自定义字段
$customerFields = db('crm_customer_pool_field_setting')->where('pool_id', $poolId)->where('is_hidden',0)->column('field_name'); $customerFields = db('crm_customer_pool_field_setting')->where('pool_id', $poolId)->where('is_hidden', 0)->column('field_name');
$customerFields[] = 'customer_id'; $customerFields[] = 'customer_id';
# 自定增加表别名 # 自定增加表别名
@ -968,9 +971,9 @@ class CustomerPoolLogic extends Common
/** /**
* 获取员工列表 * 获取员工列表
* *
* @author fanqi
* @since 2021-04-14
* @return array * @return array
* @since 2021-04-14
* @author fanqi
*/ */
private function getUserList() private function getUserList()
{ {
@ -978,7 +981,7 @@ class CustomerPoolLogic extends Common
$list = db('admin_user')->field(['id', 'realname'])->select(); $list = db('admin_user')->field(['id', 'realname'])->select();
foreach ($list AS $key => $value) { foreach ($list as $key => $value) {
$result[$value['id']] = $value['realname']; $result[$value['id']] = $value['realname'];
} }
@ -988,9 +991,9 @@ class CustomerPoolLogic extends Common
/** /**
* 获取部门列表 * 获取部门列表
* *
* @author fanqi
* @since 2021-04-14
* @return array * @return array
* @since 2021-04-14
* @author fanqi
*/ */
private function getStructureList() private function getStructureList()
{ {
@ -998,7 +1001,7 @@ class CustomerPoolLogic extends Common
$list = db('admin_structure')->field(['id', 'name'])->select(); $list = db('admin_structure')->field(['id', 'name'])->select();
foreach ($list AS $key => $value) { foreach ($list as $key => $value) {
$result[$value['id']] = $value['name']; $result[$value['id']] = $value['name'];
} }
@ -1009,9 +1012,9 @@ class CustomerPoolLogic extends Common
* 获取客户列表 * 获取客户列表
* *
* @param array $customerId 客户ID * @param array $customerId 客户ID
* @author fanqi
* @since 2021-04-15
* @return array * @return array
* @since 2021-04-15
* @author fanqi
*/ */
private function getCustomerList($customerId) private function getCustomerList($customerId)
{ {
@ -1021,7 +1024,7 @@ class CustomerPoolLogic extends Common
$customerList = db('crm_customer')->field(['customer_id', 'owner_user_id', 'name', 'into_pool_time', 'before_owner_user_id'])->whereIn('customer_id', $customerId)->select(); $customerList = db('crm_customer')->field(['customer_id', 'owner_user_id', 'name', 'into_pool_time', 'before_owner_user_id'])->whereIn('customer_id', $customerId)->select();
# 整理客户数据 # 整理客户数据
foreach ($customerList AS $key => $value) { foreach ($customerList as $key => $value) {
$result[$value['customer_id']] = $value; $result[$value['customer_id']] = $value;
} }
@ -1050,16 +1053,16 @@ class CustomerPoolLogic extends Common
$list = json_decode($list, true); $list = json_decode($list, true);
foreach ($list AS $key => $value) { foreach ($list as $key => $value) {
if (!empty($value['is_hidden']) || empty($data[$value['field']])) continue; if (!empty($value['is_hidden']) || empty($data[$value['field']])) continue;
$result[] = [ $result[] = [
'field' => $value['field'], 'field' => $value['field'],
'fieldName' => $data[$value['field']]['fieldName'], 'fieldName' => $data[$value['field']]['fieldName'],
'name' => $value['name'], 'name' => $value['name'],
'width' => $value['width'], 'width' => $value['width'],
'is_hidden' => 0, 'is_hidden' => 0,
'system' => $data[$value['field']]['system'], 'system' => $data[$value['field']]['system'],
'form_type' => $data[$value['field']]['form_type'], 'form_type' => $data[$value['field']]['form_type'],
]; ];
} }
@ -1086,12 +1089,12 @@ class CustomerPoolLogic extends Common
# 公海字段-后台配置数据 # 公海字段-后台配置数据
$poolField = db('crm_customer_pool_field_setting')->where('pool_id', $param['pool_id'])->select(); $poolField = db('crm_customer_pool_field_setting')->where('pool_id', $param['pool_id'])->select();
$poolData = []; $poolData = [];
foreach ($poolField AS $key => $value) { foreach ($poolField as $key => $value) {
$poolData[$value['field_name']] = $value; $poolData[$value['field_name']] = $value;
} }
# 去掉隐藏的字段 + 去掉已经存在的字段 = 剩下的就是新增(隐藏后又开启)的字段 # 去掉隐藏的字段 + 去掉已经存在的字段 = 剩下的就是新增(隐藏后又开启)的字段
foreach ($fieldStyleList AS $key => $value) { foreach ($fieldStyleList as $key => $value) {
# 去掉隐藏的字段 # 去掉隐藏的字段
if (empty($poolData[$value['field']]) || (!empty($poolData[$value['field']]) && !empty($poolData[$value['field']]['is_hidden']))) { if (empty($poolData[$value['field']]) || (!empty($poolData[$value['field']]) && !empty($poolData[$value['field']]['is_hidden']))) {
unset($fieldStyleList[$key]); unset($fieldStyleList[$key]);
@ -1108,7 +1111,7 @@ class CustomerPoolLogic extends Common
# 新增(隐藏后又开启)字段 # 新增(隐藏后又开启)字段
if (!empty($poolData)) { if (!empty($poolData)) {
foreach ($poolData AS $key => $value) { foreach ($poolData as $key => $value) {
if (empty($value['is_hidden'])) { if (empty($value['is_hidden'])) {
$fieldStyleList[] = [ $fieldStyleList[] = [
'field' => $value['field_name'], 'field' => $value['field_name'],
@ -1127,4 +1130,64 @@ class CustomerPoolLogic extends Common
} }
} }
} }
/**
* 发起捞起客户审批
* @param array $param user_id 领取人IDcustomer_id 要领取的客户ID check_user_id 审核人id
*/
public function customerReceiveExamine($param)
{
$customerCheckModel = model('CustomerCheck');
$examineStepModel = new \app\admin\model\ExamineStep();
$examineStatus = $param['examineStatus'] ?? 1; // 审批是否停用
unset($param['examineStatus']);
$dataInfo = db('crm_customer_check')->where('customer_id', 'in', $param['customer_id'])->find();
if (!empty($dataInfo)&& $dataInfo['check_status'] < 2) {
return '客户已被领取待审批,请联系管理员';
}
if (($examineStatus != false && $examineStatus != 'false') || $examineStatus == 1) {
// 审核判断(是否有符合条件的审批流)
$examineFlowModel = new \app\admin\model\ExamineFlow();
if (!$examineFlowModel->checkExamine($param['user_id'], 'crm_customer_check')) {
return '暂无审批人,无法创建';
}
//添加审批相关信息
$examineFlowData = $examineFlowModel->getFlowByTypes($param['user_id'], 'crm_customer_check');
if (!$examineFlowData) {
return '无可用审批流,请联系管理员';
}
$param['flow_id'] = $examineFlowData['flow_id'];
//获取审批人信息
if ($examineFlowData['config'] == 1) {
//固定审批流
$nextStepData = $examineStepModel->nextStepUser($param['user_id'], $examineFlowData['flow_id'], 'crm_customer_check', 0, 0, 0);
$next_user_ids = arrayToString($nextStepData['next_user_ids']) ?: '';
$check_user_id = $next_user_ids ?: [];
$param['order_id'] = 1;
} else {
$check_user_id = $param['check_user_id'] ? ',' . $param['check_user_id'] . ',' : '';
}
if (!$check_user_id) {
return '无可用审批人,请联系管理员';
}
$param['check_user_id'] = is_array($check_user_id) ? ',' . implode(',', $check_user_id) . ',' : $check_user_id;
} else {
# 审批流停用,将状态改为审核通过
// $param['check_status'] = 2;
# 审批流停用,将状态改为正常 zjf 20210727 默认值为7
$param['check_status'] = 7;
}
if ($customerCheckModel->createData($param)) {
return '添加成功';
} else {
return $customerCheckModel->getError();
}
}
} }

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

@ -6,6 +6,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\crm\model; namespace app\crm\model;
use app\admin\model\Message;
use app\admin\traits\FieldVerificationTrait; use app\admin\traits\FieldVerificationTrait;
use think\Db; use think\Db;
use app\admin\model\Common; use app\admin\model\Common;
@ -49,6 +50,9 @@ class Business extends Common
$businessTypeId = $request['typesId']; // 针对mobile $businessTypeId = $request['typesId']; // 针对mobile
$businessStatusId = $request['statusId']; // 针对mobile $businessStatusId = $request['statusId']; // 针对mobile
$overdue = $request['overdue']; // 待办事项下需联系商机(逾期) $overdue = $request['overdue']; // 待办事项下需联系商机(逾期)
$businessIdArray = $request['businessIdArray']; // 待办事项提醒参数
$isMessage = !empty($request['isMessage']);
$funnelQuery = $request['funnel']; // 销售漏斗查询赢单输单
unset($request['scene_id']); unset($request['scene_id']);
unset($request['search']); unset($request['search']);
unset($request['user_id']); unset($request['user_id']);
@ -60,6 +64,9 @@ class Business extends Common
unset($request['typesId']); unset($request['typesId']);
unset($request['statusId']); unset($request['statusId']);
unset($request['overdue']); unset($request['overdue']);
unset($request['isMessage']);
unset($request['businessIdArray']);
unset($request['funnel']);
$request = $this->fmtRequest($request); $request = $this->fmtRequest($request);
$requestMap = $request['map'] ?: []; $requestMap = $request['map'] ?: [];
$sceneModel = new \app\admin\model\Scene(); $sceneModel = new \app\admin\model\Scene();
@ -80,28 +87,28 @@ class Business extends Common
} }
if (isset($requestMap['type_id'])) { if (isset($requestMap['type_id'])) {
$requestMap['type_id']['value'] = $requestMap['type_id']['type_id']; $requestMap['type_id']['value'] = $requestMap['type_id']['type_id'];
if(in_array($requestMap['type_id']['status_id'],[1,2,3])){ if (in_array($requestMap['type_id']['status_id'], [1, 2, 3])) {
$requestMap['is_end']=$requestMap['type_id']['status_id']; $requestMap['is_end'] = $requestMap['type_id']['status_id'];
}else{ } else {
if ($requestMap['type_id']['status_id']) $requestMap['status_id']['value'] = $requestMap['type_id']['status_id']; if ($requestMap['type_id']['status_id']) $requestMap['status_id']['value'] = $requestMap['type_id']['status_id'];
$requestMap['is_end']=0; $requestMap['is_end'] = 0;
} }
} }
if ($sceneMap['type_id']) { if ($sceneMap['type_id']) {
$requestMap['type_id']['value'] = $sceneMap['type_id']['type_id']; $requestMap['type_id']['value'] = $sceneMap['type_id']['type_id'];
if(in_array($sceneMap['type_id']['status_id'],[1,2,3])){ if (in_array($sceneMap['type_id']['status_id'], [1, 2, 3])) {
$sceneMap['is_end']=$sceneMap['type_id']['status_id']; $sceneMap['is_end'] = $sceneMap['type_id']['status_id'];
}else{ } else {
if ($sceneMap['type_id']['status_id']) $requestMap['status_id']['value'] = $sceneMap['type_id']['status_id']; if ($sceneMap['type_id']['status_id']) $requestMap['status_id']['value'] = $sceneMap['type_id']['status_id'];
$sceneMap['is_end']=0; $sceneMap['is_end'] = 0;
} }
unset($sceneMap['type_id']); unset($sceneMap['type_id']);
} }
$partMap = []; $partMap = [];
$teamMap=$requestMap['team_id']; $teamMap = $requestMap['team_id'];
//团队成员 高级筛选 //团队成员 高级筛选
if($teamMap){ if ($teamMap) {
$partMap= advancedQueryFormatForTeam($teamMap,'business',''); $partMap = advancedQueryFormatForTeam($teamMap, 'business', '');
unset($requestMap['team_id']); unset($requestMap['team_id']);
$map = $requestMap ? array_merge($sceneMap, $requestMap) : $sceneMap; $map = $requestMap ? array_merge($sceneMap, $requestMap) : $sceneMap;
} else { } else {
@ -110,22 +117,23 @@ class Business extends Common
//高级筛选 //高级筛选
$map = advancedQuery($map, 'crm', 'business', 'index'); $map = advancedQuery($map, 'crm', 'business', 'index');
$authMap = []; $authMap = [];
$a = 'index'; $a = 'index';
if ($is_excel) $a = 'excelExport'; if ($is_excel) $a = 'excelExport';
$auth_user_ids = $userModel->getUserByPer('crm', 'business', $a); $auth_user_ids = $userModel->getUserByPer('crm', 'business', $a);
if (isset($map['business.owner_user_id'])) { if (isset($map['business.owner_user_id'])) {
if (!is_array($map['business.owner_user_id'][1])) { if (!is_array($map['business.owner_user_id'][1])) {
$map['business.owner_user_id'][1] = [$map['business.owner_user_id'][1]]; $map['business.owner_user_id'][1] = [$map['business.owner_user_id'][1]];
} }
if (in_array($map['business.owner_user_id'][0], ['neq', 'notin'])) { if (in_array($map['business.owner_user_id'][0], ['neq', 'notin'])) {
$auth_user_ids = array_diff($auth_user_ids, $map['business.owner_user_id'][1]) ?: []; //取差集 $auth_user_ids = array_diff($auth_user_ids, $map['business.owner_user_id'][1]) ?: []; //取差集
} else {
$auth_user_ids = array_intersect($map['business.owner_user_id'][1], $auth_user_ids) ?: []; //取交集
}
unset($map['business.owner_user_id']);
$auth_user_ids = array_merge(array_unique(array_filter($auth_user_ids))) ?: ['-1'];
$authMap['business.owner_user_id'] = array('in', $auth_user_ids);
} else { } else {
$auth_user_ids = array_intersect($map['business.owner_user_id'][1], $auth_user_ids) ?: []; //取交集
}
unset($map['business.owner_user_id']);
$auth_user_ids = array_merge(array_unique(array_filter($auth_user_ids))) ?: ['-1'];
$authMap['business.owner_user_id'] = array('in', $auth_user_ids);
} else {
if (!$isMessage) {
$authMapData = []; $authMapData = [];
$authMapData['auth_user_ids'] = $auth_user_ids; $authMapData['auth_user_ids'] = $auth_user_ids;
$authMapData['user_id'] = $user_id; $authMapData['user_id'] = $user_id;
@ -135,6 +143,19 @@ class Business extends Common
->whereOr('business.rw_user_id', array('like', '%,' . $authMapData['user_id'] . ',%')); ->whereOr('business.rw_user_id', array('like', '%,' . $authMapData['user_id'] . ',%'));
}; };
} }
}
// 销售漏斗处理
if (!empty($funnelQuery)){
unset($map['business.status_id']);
unset($map['business.is_end']);
switch ($funnelQuery){
case '10000':// 赢单
$map['business.is_end']=1;
break;
case "10001":// 输单
$map['business.is_end']=2;
}
}
//联系人商机 //联系人商机
if ($contacts_id) { if ($contacts_id) {
@ -167,22 +188,24 @@ class Business extends Common
} else { } else {
$order = 'business.update_time desc'; $order = 'business.update_time desc';
} }
# 商机组和商机状态搜索 # 商机组和商机状态搜索
if (!empty($businessTypeId)) $map['business.type_id'] = ['eq', $businessTypeId]; if (!empty($businessTypeId)) $map['business.type_id'] = ['eq', $businessTypeId];
if (!empty($businessStatusId)) { if (!empty($businessStatusId)) {
if(preg_match("/^[1-9][0-9]*$/" ,$businessStatusId)){ if (preg_match("/^[1-9][0-9]*$/", $businessStatusId)) {
$map['is_end']=0; $map['is_end'] = 0;
$map['business.status_id'] = ['eq', $businessStatusId]; $map['business.status_id'] = ['eq', $businessStatusId];
}else{ } else {
$map['is_end']=abs($businessStatusId); $map['is_end'] = abs($businessStatusId);
} }
} }
# 待办事项查询参数
$dealtWhere = [];
if (!empty($businessIdArray)) $dealtWhere['business.business_id'] = ['in', $businessIdArray];
// 待办事项下需联系商机(逾期) // 待办事项下需联系商机(逾期)
$overdueWhere = ''; $overdueWhere = '';
if (!empty($overdue)) { if (!empty($overdue)) {
$overdueWhere = "(FROM_UNIXTIME(`business`.`last_time`,'%Y-%m-%d') < FROM_UNIXTIME(`business`.`next_time`,'%Y-%m-%d') OR (ISNULL(`business`.`last_time`) AND `business`.`next_time` < ".time()."))"; $overdueWhere = "(FROM_UNIXTIME(`business`.`last_time`,'%Y-%m-%d') < FROM_UNIXTIME(`business`.`next_time`,'%Y-%m-%d') OR (ISNULL(`business`.`last_time`) AND `business`.`next_time` < " . time() . "))";
} }
$readAuthIds = $userModel->getUserByPer('crm', 'business', 'read'); $readAuthIds = $userModel->getUserByPer('crm', 'business', 'read');
@ -191,7 +214,7 @@ class Business extends Common
$dataCount = db('crm_business') $dataCount = db('crm_business')
->alias('business') ->alias('business')
->join('__CRM_CUSTOMER__ customer', 'business.customer_id = customer.customer_id', 'LEFT') ->join('__CRM_CUSTOMER__ customer', 'business.customer_id = customer.customer_id', 'LEFT')
->where($map)->where($partMap)->where($authMap)->where($overdueWhere)->count('business_id'); ->where($map)->where($partMap)->where($authMap)->where($overdueWhere)->where($dealtWhere)->count('business_id');
if (!empty($getCount) && $getCount == 1) { if (!empty($getCount) && $getCount == 1) {
$data['dataCount'] = !empty($dataCount) ? $dataCount : 0; $data['dataCount'] = !empty($dataCount) ? $dataCount : 0;
# 商机总金额 # 商机总金额
@ -200,6 +223,7 @@ class Business extends Common
$data['extraData']['money'] = ['businessSumMoney' => !empty($sumMoney) ? sprintf("%.2f", $sumMoney) : 0.00]; $data['extraData']['money'] = ['businessSumMoney' => !empty($sumMoney) ? sprintf("%.2f", $sumMoney) : 0.00];
return $data; return $data;
} }
$list = db('crm_business') $list = db('crm_business')
->alias('business') ->alias('business')
->join('__CRM_CUSTOMER__ customer', 'business.customer_id = customer.customer_id', 'LEFT') ->join('__CRM_CUSTOMER__ customer', 'business.customer_id = customer.customer_id', 'LEFT')
@ -207,6 +231,7 @@ class Business extends Common
->where($partMap) ->where($partMap)
->where($authMap) ->where($authMap)
->where($overdueWhere) ->where($overdueWhere)
->where($dealtWhere)
->limit($request['offset'], $request['length']) ->limit($request['offset'], $request['length'])
->field('business.*,customer.name as customer_name') ->field('business.*,customer.name as customer_name')
->orderRaw($order) ->orderRaw($order)
@ -215,7 +240,7 @@ class Business extends Common
# 扩展数据 # 扩展数据
$extraData = []; $extraData = [];
$list=getFieldData($list,'crm_business',$user_id); $list = getFieldData($list, 'crm_business', $user_id);
foreach ($list as $k => $v) { foreach ($list as $k => $v) {
$list[$k]['customer_id_info']['customer_id'] = $v['customer_id']; $list[$k]['customer_id_info']['customer_id'] = $v['customer_id'];
$list[$k]['customer_id_info']['name'] = $v['customer_name']; $list[$k]['customer_id_info']['name'] = $v['customer_name'];
@ -310,31 +335,31 @@ class Business extends Common
// 处理日期date类型 // 处理日期date类型
$dateField = $fieldModel->getFieldByFormType('crm_business', 'date'); $dateField = $fieldModel->getFieldByFormType('crm_business', 'date');
if (!empty($dateField)) { if (!empty($dateField)) {
foreach ($param AS $key => $value) { foreach ($param as $key => $value) {
if (in_array($key, $dateField) && empty($value)) $param[$key] = null; if (in_array($key, $dateField) && empty($value)) $param[$key] = null;
} }
} }
// 处理手写签名类型 // 处理手写签名类型
$handwritingField = $fieldModel->getFieldByFormType('crm_business', 'handwriting_sign'); $handwritingField = $fieldModel->getFieldByFormType('crm_business', 'handwriting_sign');
if (!empty($handwritingField)) { if (!empty($handwritingField)) {
foreach ($param AS $key => $value) { foreach ($param as $key => $value) {
if (in_array($key, $handwritingField)) { if (in_array($key, $handwritingField)) {
$param[$key] = !empty($value['file_id']) ? $value['file_id'] : ''; $param[$key] = !empty($value['file_id']) ? $value['file_id'] : '';
} }
} }
} }
// 处理地址、定位、日期区间、明细表格类型字段 // 处理地址、定位、日期区间、明细表格类型字段
$positionField = $fieldModel->getFieldByFormType($this->name, 'position'); $positionField = $fieldModel->getFieldByFormType($this->name, 'position');
$locationField = $fieldModel->getFieldByFormType($this->name, 'location'); $locationField = $fieldModel->getFieldByFormType($this->name, 'location');
$dateIntervalField = $fieldModel->getFieldByFormType($this->name, 'date_interval'); $dateIntervalField = $fieldModel->getFieldByFormType($this->name, 'date_interval');
$detailTableField = $fieldModel->getFieldByFormType($this->name, 'detail_table'); $detailTableField = $fieldModel->getFieldByFormType($this->name, 'detail_table');
foreach ($param AS $key => $value) { foreach ($param as $key => $value) {
// 处理地址类型字段数据 // 处理地址类型字段数据
if (in_array($key, $positionField)) { if (in_array($key, $positionField)) {
if (!empty($value)) { if (!empty($value)) {
$businessData[] = [ $businessData[] = [
'field' => $key, 'field' => $key,
'content' => json_encode($value, JSON_NUMERIC_CHECK), 'content' => json_encode($value, JSON_NUMERIC_CHECK),
'create_time' => time() 'create_time' => time()
]; ];
$positionNames = array_column($value, 'name'); $positionNames = array_column($value, 'name');
@ -347,8 +372,8 @@ class Business extends Common
if (in_array($key, $locationField)) { if (in_array($key, $locationField)) {
if (!empty($value)) { if (!empty($value)) {
$businessData[] = [ $businessData[] = [
'field' => $key, 'field' => $key,
'content' => json_encode($value, JSON_NUMERIC_CHECK), 'content' => json_encode($value, JSON_NUMERIC_CHECK),
'create_time' => time() 'create_time' => time()
]; ];
$param[$key] = $value['address']; $param[$key] = $value['address'];
@ -360,8 +385,8 @@ class Business extends Common
if (in_array($key, $dateIntervalField)) { if (in_array($key, $dateIntervalField)) {
if (!empty($value)) { if (!empty($value)) {
$businessData[] = [ $businessData[] = [
'field' => $key, 'field' => $key,
'content' => json_encode($value, JSON_NUMERIC_CHECK), 'content' => json_encode($value, JSON_NUMERIC_CHECK),
'create_time' => time() 'create_time' => time()
]; ];
$param[$key] = implode('_', $value); $param[$key] = implode('_', $value);
@ -373,8 +398,8 @@ class Business extends Common
if (in_array($key, $detailTableField)) { if (in_array($key, $detailTableField)) {
if (!empty($value)) { if (!empty($value)) {
$businessData[] = [ $businessData[] = [
'field' => $key, 'field' => $key,
'content' => json_encode($value, JSON_NUMERIC_CHECK), 'content' => json_encode($value, JSON_NUMERIC_CHECK),
'create_time' => time() 'create_time' => time()
]; ];
$param[$key] = $key; $param[$key] = $key;
@ -383,7 +408,6 @@ class Business extends Common
} }
} }
} }
# 设置今日需联系商机 # 设置今日需联系商机
if (!empty($param['next_time']) && $param['next_time'] >= strtotime(date('Y-m-d 00:00:00'))) $param['is_dealt'] = 0; if (!empty($param['next_time']) && $param['next_time'] >= strtotime(date('Y-m-d 00:00:00'))) $param['is_dealt'] = 0;
@ -391,7 +415,7 @@ class Business extends Common
$param['discount_rate'] = $param['discount_rate'] ?: '0.00'; $param['discount_rate'] = $param['discount_rate'] ?: '0.00';
if ($this->data($param)->allowField(true)->save()) { if ($this->data($param)->allowField(true)->save()) {
updateActionLog($param['create_user_id'], 'crm_business', $this->business_id, '', '', '创建了商机'); updateActionLog($param['create_user_id'], 'crm_business', $this->business_id, '', '', '创建了商机');
RecordActionLog($param['create_user_id'],'crm_business','save',$param['name'],'','','新增了商机'.$param['name']); RecordActionLog($param['create_user_id'], 'crm_business', 'save', $param['name'], '', '', '新增了商机' . $param['name']);
$business_id = $this->business_id; $business_id = $this->business_id;
$data['business_id'] = $business_id; $data['business_id'] = $business_id;
if ($param['product']) { if ($param['product']) {
@ -427,6 +451,31 @@ class Business extends Common
}); });
db('crm_business_data')->insertAll($businessData); 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; return $data;
} else { } else {
$this->error = '添加失败'; $this->error = '添加失败';
@ -480,31 +529,31 @@ class Business extends Common
// 处理日期date类型 // 处理日期date类型
$dateField = $fieldModel->getFieldByFormType('crm_business', 'date'); $dateField = $fieldModel->getFieldByFormType('crm_business', 'date');
if (!empty($dateField)) { if (!empty($dateField)) {
foreach ($param AS $key => $value) { foreach ($param as $key => $value) {
if (in_array($key, $dateField) && empty($value)) $param[$key] = null; if (in_array($key, $dateField) && empty($value)) $param[$key] = null;
} }
} }
// 处理手写签名类型 // 处理手写签名类型
$handwritingField = $fieldModel->getFieldByFormType('crm_business', 'handwriting_sign'); $handwritingField = $fieldModel->getFieldByFormType('crm_business', 'handwriting_sign');
if (!empty($handwritingField)) { if (!empty($handwritingField)) {
foreach ($param AS $key => $value) { foreach ($param as $key => $value) {
if (in_array($key, $handwritingField)) { if (in_array($key, $handwritingField)) {
$param[$key] = !empty($value['file_id']) ? $value['file_id'] : ''; $param[$key] = !empty($value['file_id']) ? $value['file_id'] : '';
} }
} }
} }
// 处理地址、定位、日期区间、明细表格类型字段 // 处理地址、定位、日期区间、明细表格类型字段
$positionField = $fieldModel->getFieldByFormType($this->name, 'position'); $positionField = $fieldModel->getFieldByFormType($this->name, 'position');
$locationField = $fieldModel->getFieldByFormType($this->name, 'location'); $locationField = $fieldModel->getFieldByFormType($this->name, 'location');
$dateIntervalField = $fieldModel->getFieldByFormType($this->name, 'date_interval'); $dateIntervalField = $fieldModel->getFieldByFormType($this->name, 'date_interval');
$detailTableField = $fieldModel->getFieldByFormType($this->name, 'detail_table'); $detailTableField = $fieldModel->getFieldByFormType($this->name, 'detail_table');
foreach ($param AS $key => $value) { foreach ($param as $key => $value) {
// 处理地址类型字段数据 // 处理地址类型字段数据
if (in_array($key, $positionField)) { if (in_array($key, $positionField)) {
if (!empty($value)) { if (!empty($value)) {
$businessData[] = [ $businessData[] = [
'field' => $key, 'field' => $key,
'content' => json_encode($value, JSON_NUMERIC_CHECK), 'content' => json_encode($value, JSON_NUMERIC_CHECK),
'create_time' => time() 'create_time' => time()
]; ];
$positionNames = array_column($value, 'name'); $positionNames = array_column($value, 'name');
@ -517,8 +566,8 @@ class Business extends Common
if (in_array($key, $locationField)) { if (in_array($key, $locationField)) {
if (!empty($value)) { if (!empty($value)) {
$businessData[] = [ $businessData[] = [
'field' => $key, 'field' => $key,
'content' => json_encode($value, JSON_NUMERIC_CHECK), 'content' => json_encode($value, JSON_NUMERIC_CHECK),
'create_time' => time() 'create_time' => time()
]; ];
$param[$key] = $value['address']; $param[$key] = $value['address'];
@ -530,8 +579,8 @@ class Business extends Common
if (in_array($key, $dateIntervalField)) { if (in_array($key, $dateIntervalField)) {
if (!empty($value)) { if (!empty($value)) {
$businessData[] = [ $businessData[] = [
'field' => $key, 'field' => $key,
'content' => json_encode($value, JSON_NUMERIC_CHECK), 'content' => json_encode($value, JSON_NUMERIC_CHECK),
'create_time' => time() 'create_time' => time()
]; ];
$param[$key] = implode('_', $value); $param[$key] = implode('_', $value);
@ -543,8 +592,8 @@ class Business extends Common
if (in_array($key, $detailTableField)) { if (in_array($key, $detailTableField)) {
if (!empty($value)) { if (!empty($value)) {
$businessData[] = [ $businessData[] = [
'field' => $key, 'field' => $key,
'content' => json_encode($value, JSON_NUMERIC_CHECK), 'content' => json_encode($value, JSON_NUMERIC_CHECK),
'create_time' => time() 'create_time' => time()
]; ];
$param[$key] = $key; $param[$key] = $key;
@ -572,7 +621,7 @@ class Business extends Common
$resProduct = $productModel->createObject('crm_business', $param, $business_id); $resProduct = $productModel->createObject('crm_business', $param, $business_id);
//修改记录 //修改记录
updateActionLog($param['user_id'], 'crm_business', $business_id, $dataInfo, $param); updateActionLog($param['user_id'], 'crm_business', $business_id, $dataInfo, $param);
RecordActionLog($param['user_id'], 'crm_business', 'update',$dataInfo['name'], $dataInfo, $param); RecordActionLog($param['user_id'], 'crm_business', 'update', $dataInfo['name'], $dataInfo, $param);
// 添加商机扩展数据 // 添加商机扩展数据
db('crm_business_data')->where('business_id', $business_id)->delete(); db('crm_business_data')->where('business_id', $business_id)->delete();
array_walk($businessData, function (&$val) use ($business_id) { array_walk($businessData, function (&$val) use ($business_id) {
@ -598,38 +647,38 @@ class Business extends Common
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function getDataById($id = '', $userId = 0,$model='') public function getDataById($id = '', $userId = 0, $model = '')
{ {
$dataInfo = db('crm_business')->where('business_id', $id)->find(); $dataInfo = db('crm_business')->where('business_id', $id)->find();
if (!$dataInfo) { if (!$dataInfo) {
$this->error = '暂无此数据'; $this->error = '暂无此数据';
return false; return false;
} }
if(empty($model) && $model!='update'){ if (empty($model) && $model != 'update') {
$grantData = getFieldGrantData($userId); $grantData = getFieldGrantData($userId);
foreach ($grantData['crm_business'] as $key => $value) { foreach ($grantData['crm_business'] as $key => $value) {
foreach ($value as $ke => $va) { foreach ($value as $ke => $va) {
if($va['maskType']!=0){ if ($va['maskType'] != 0) {
$fieldGrant[$ke]['maskType'] = $va['maskType']; $fieldGrant[$ke]['maskType'] = $va['maskType'];
$fieldGrant[$ke]['form_type'] = $va['form_type']; $fieldGrant[$ke]['form_type'] = $va['form_type'];
$fieldGrant[$ke]['field'] = $va['field']; $fieldGrant[$ke]['field'] = $va['field'];
} }
} }
} }
foreach ($fieldGrant AS $key => $val){ foreach ($fieldGrant as $key => $val) {
//掩码相关类型字段 //掩码相关类型字段
if ($val['maskType']!=0 && $val['form_type'] == 'mobile') { if ($val['maskType'] != 0 && $val['form_type'] == 'mobile') {
$pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i"; $pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
$rs = preg_replace($pattern, "$1****$2", $dataInfo[$val['field']]); $rs = preg_replace($pattern, "$1****$2", $dataInfo[$val['field']]);
$dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)$rs : null; $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)$rs : null;
} elseif ($val['maskType']!=0 && $val['form_type'] == 'email') { } elseif ($val['maskType'] != 0 && $val['form_type'] == 'email') {
$email_array = explode("@", $dataInfo[$val['field']]); $email_array = explode("@", $dataInfo[$val['field']]);
$prevfix = (strlen($email_array[0]) < 4) ? "" : substr($dataInfo[$val['field']], 0, 2); // $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($dataInfo[$val['field']], 0, 2); //
$str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $dataInfo[$val['field']], -1, $count); $str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $dataInfo[$val['field']], -1, $count);
$rs = $prevfix . $str; $rs = $prevfix . $str;
$dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ?$rs: null; $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? $rs : null;
} elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) { } elseif ($val['maskType'] != 0 && in_array($val['form_type'], ['position', 'floatnumber'])) {
$dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)substr_replace($dataInfo[$val['field']], '*****',0,strlen($dataInfo[$val['field']])) : null; $dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)substr_replace($dataInfo[$val['field']], '*****', 0, strlen($dataInfo[$val['field']])) : null;
} }
} }
} }
@ -654,8 +703,8 @@ class Business extends Common
foreach ($datetimeField as $key => $val) { foreach ($datetimeField as $key => $val) {
$dataInfo[$val] = !empty($dataInfo[$val]) ? date('Y-m-d H:i:s', $dataInfo[$val]) : null; $dataInfo[$val] = !empty($dataInfo[$val]) ? date('Y-m-d H:i:s', $dataInfo[$val]) : null;
} }
if($dataInfo['is_end']!=1){ if ($dataInfo['is_end'] != 1) {
$dataInfo['statusRemark']=db('crm_business_log')->where(['business_id'=>$id,'is_end'=>$dataInfo['is_end']])->value('remark'); $dataInfo['statusRemark'] = db('crm_business_log')->where(['business_id' => $id, 'is_end' => $dataInfo['is_end']])->value('remark');
} }
$dataInfo['next_time'] = !empty($dataInfo['next_time']) ? date('Y-m-d H:i:s', $dataInfo['next_time']) : null; $dataInfo['next_time'] = !empty($dataInfo['next_time']) ? date('Y-m-d H:i:s', $dataInfo['next_time']) : null;
$dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null; $dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null;
@ -665,7 +714,7 @@ class Business extends Common
if (!empty($userId)) { if (!empty($userId)) {
$grantData = getFieldGrantData($userId); $grantData = getFieldGrantData($userId);
$userLevel = isSuperAdministrators($userId); $userLevel = isSuperAdministrators($userId);
foreach ($dataInfo AS $key => $value) { foreach ($dataInfo as $key => $value) {
if (!$userLevel && !empty($grantData['crm_business'])) { if (!$userLevel && !empty($grantData['crm_business'])) {
$status = getFieldGrantStatus($key, $grantData['crm_business']); $status = getFieldGrantStatus($key, $grantData['crm_business']);
@ -712,7 +761,7 @@ class Business extends Common
$map['create_time'] = $where['create_time']; $map['create_time'] = $where['create_time'];
$map['owner_user_id'] = ['in', $userIds]; $map['owner_user_id'] = ['in', $userIds];
$map['type_id'] = $type_id; $map['type_id'] = $type_id;
$sql_a = CrmBusinessModel::field([ $sql_a = CrmBusinessModel::field([
'SUM(CASE WHEN is_end = 1 THEN money ELSE 0 END) AS sum_ying', 'SUM(CASE WHEN is_end = 1 THEN money ELSE 0 END) AS sum_ying',
'SUM(CASE WHEN is_end = 2 THEN money ELSE 0 END) AS sum_shu', 'SUM(CASE WHEN is_end = 2 THEN money ELSE 0 END) AS sum_shu',
@ -737,7 +786,7 @@ class Business extends Common
->select(); ->select();
$res = queryCache($sql, 200); $res = queryCache($sql, 200);
$res = array_column($res, null, 'status_id'); $res = array_column($res, null, 'status_id');
$sum_money = 0; $sum_money = 0;
$count = 0; # 商机数总和 $count = 0; # 商机数总和
$moneyCount = 0; # 金额总和 $moneyCount = 0; # 金额总和
@ -745,22 +794,22 @@ class Business extends Common
$v['count'] = $res[$v['status_id']]['count'] ?: 0; $v['count'] = $res[$v['status_id']]['count'] ?: 0;
$v['money'] = $res[$v['status_id']]['sum'] ?: 0; $v['money'] = $res[$v['status_id']]['sum'] ?: 0;
$v['status_name'] = $v['name']; $v['status_name'] = $v['name'];
$statusList[$k] = $v; $statusList[$k] = $v;
$sum_money += $v['money']; $sum_money += $v['money'];
$moneyCount += $v['money']; $moneyCount += $v['money'];
$count += $v['count']; $count += $v['count'];
} }
$data['list'] = $statusList; $data['list'] = $statusList;
$data['sum_ying'] = $res_a[0]['sum_ying'] ?: 0; $data['sum_ying'] = $res_a[0]['sum_ying'] ?: 0;
$data['sum_shu'] = $res_a[0]['sum_shu'] ?: 0; $data['sum_shu'] = $res_a[0]['sum_shu'] ?: 0;
$data['count_ying']=$res_a[0]['count_ying']?:0; $data['count_ying'] = $res_a[0]['count_ying'] ?: 0;
$data['count_shu']=$res_a[0]['count_shu']?:0; $data['count_shu'] = $res_a[0]['count_shu'] ?: 0;
$data['sum_money'] = $sum_money ?: 0; $data['sum_money'] = $sum_money ?: 0;
$data['total'] = ['name' => '合计', 'money_count' => $moneyCount, 'count' => $count]; $data['total'] = ['name' => '合计', 'money_count' => $moneyCount, 'count' => $count];
return $data ?: []; return $data ?: [];
} }
@ -899,12 +948,12 @@ class Business extends Common
public function getSystemInfo($id) public function getSystemInfo($id)
{ {
# 商机 # 商机
$business = Db::name('crm_business')->field(['create_user_id' ,'owner_user_id', 'create_time', 'update_time', 'last_time'])->where('business_id', $id)->find(); $business = Db::name('crm_business')->field(['create_user_id', 'owner_user_id', 'create_time', 'update_time', 'last_time'])->where('business_id', $id)->find();
# 创建人 # 创建人
$realname = Db::name('admin_user')->where('id', $business['create_user_id'])->value('realname'); $realname = Db::name('admin_user')->where('id', $business['create_user_id'])->value('realname');
# zjf 20210726 # zjf 20210726
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$ownerUserInfo = $userModel->getUserById($business['owner_user_id']); $ownerUserInfo = $userModel->getUserById($business['owner_user_id']);
# 负责人部门 # 负责人部门
$ownerStructureName = $ownerUserInfo['structure_name']; $ownerStructureName = $ownerUserInfo['structure_name'];

@ -206,6 +206,11 @@ class Contacts extends Common
$list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : []; $list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
$list[$k]['customer_id_info']['customer_id'] = $v['customer_id'] ?: ''; $list[$k]['customer_id_info']['customer_id'] = $v['customer_id'] ?: '';
$list[$k]['customer_id_info']['name'] = $v['customer_name'] ?: ''; $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) { foreach ($userField as $key => $val) {
$usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : []; $usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : [];
$list[$k][$val] = implode($usernameField, ','); $list[$k][$val] = implode($usernameField, ',');

File diff suppressed because it is too large Load Diff

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

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

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

@ -56,6 +56,8 @@ return [
'crm/customer/poolAuthority' => ['crm/customer/poolAuthority', ['method' => 'POST']], 'crm/customer/poolAuthority' => ['crm/customer/poolAuthority', ['method' => 'POST']],
// 【客户】级别列表 // 【客户】级别列表
'crm/customer/level' => ['crm/customer/level', ['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']], 'crm/customerPool/index' => ['crm/customerPool/index', ['method' => 'POST']],
@ -71,6 +73,8 @@ return [
'crm/customerPool/authority' => ['crm/customerPool/authority', ['method' => 'POST']], 'crm/customerPool/authority' => ['crm/customerPool/authority', ['method' => 'POST']],
// 【客户】领取公海客户 // 【客户】领取公海客户
'crm/customerPool/receive' => ['crm/customerPool/receive', ['method' => 'POST']], 'crm/customerPool/receive' => ['crm/customerPool/receive', ['method' => 'POST']],
// 【客户】领取公海客户审批
'crm/customerPool/checkCustomerReveive' => ['crm/customerPool/checkCustomerReveive', ['method' => 'POST']],
// 【客户】分配公海客户 // 【客户】分配公海客户
'crm/customerPool/distribute' => ['crm/customerPool/distribute', ['method' => 'POST']], 'crm/customerPool/distribute' => ['crm/customerPool/distribute', ['method' => 'POST']],
// 【客户】删除公海客户 // 【客户】删除公海客户
@ -87,6 +91,8 @@ return [
'crm/customerPool/setFieldWidth' => ['crm/customerPool/setFieldWidth', ['method' => 'POST']], 'crm/customerPool/setFieldWidth' => ['crm/customerPool/setFieldWidth', ['method' => 'POST']],
// 【客户】设置公海字段配置 // 【客户】设置公海字段配置
'crm/customerPool/setFieldConfig' => ['crm/customerPool/setFieldConfig', ['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']], 'crm/visit/index' => ['crm/visit/index', ['method' => 'POST']],
@ -189,6 +195,8 @@ return [
'crm/business/count' => ['crm/business/count', ['method' => 'POST']], 'crm/business/count' => ['crm/business/count', ['method' => 'POST']],
// 【商机】菜单数量 // 【商机】菜单数量
'crm/business/setPrimary' => ['crm/business/setPrimary', ['method' => 'POST']], 'crm/business/setPrimary' => ['crm/business/setPrimary', ['method' => 'POST']],
// 【商机】审批
'crm/business/check' => ['crm/business/check', ['method' => 'POST']],
// 【合同】列表 // 【合同】列表
'crm/contract/index' => ['crm/contract/index', ['method' => 'POST']], 'crm/contract/index' => ['crm/contract/index', ['method' => 'POST']],
@ -301,8 +309,8 @@ return [
'crm/invoice/resetInvoiceStatus' => ['crm/invoice/resetInvoiceStatus', ['method' => 'POST']], 'crm/invoice/resetInvoiceStatus' => ['crm/invoice/resetInvoiceStatus', ['method' => 'POST']],
// 【发票】导出 // 【发票】导出
'crm/invoice/excelExport' => ['crm/invoice/excelExport', ['method' => 'POST']], 'crm/invoice/excelExport' => ['crm/invoice/excelExport', ['method' => 'POST']],
// 【发票-开户行】列表 // 【发票-开户行】列表
'crm/invoiceInfo/index' => ['crm/invoiceInfo/index', ['method' => 'POST']], 'crm/invoiceInfo/index' => ['crm/invoiceInfo/index', ['method' => 'POST']],
// 【发票-开户行】详情 // 【发票-开户行】详情
@ -386,7 +394,7 @@ return [
'crm/index/autoNumberStatus' => ['crm/index/autoNumberStatus', ['method' => 'POST']], 'crm/index/autoNumberStatus' => ['crm/index/autoNumberStatus', ['method' => 'POST']],
// 【商机阶段列表】 // 【商机阶段列表】
'crm/index/businessList' => ['crm/index/businessList', ['method' => 'POST']], 'crm/index/businessList' => ['crm/index/businessList', ['method' => 'POST']],
// 【获取仪表盘布局】 // 【获取仪表盘布局】
'crm/index/dashboard' => ['crm/index/dashboard', ['method' => 'POST']], 'crm/index/dashboard' => ['crm/index/dashboard', ['method' => 'POST']],
// 【修改仪表盘布局】 // 【修改仪表盘布局】
@ -394,20 +402,23 @@ return [
// 【待办事项】今日需联系 // 【待办事项】今日需联系
'crm/message/todayLeads' => ['crm/message/todayLeads', ['method' => 'POST']], 'crm/message/todayLeads' => ['crm/message/todayLeads', ['method' => 'POST']],
'crm/message/todayCustomer' => ['crm/message/todayCustomer', ['method' => 'POST']], 'crm/message/todayCustomer' => ['crm/message/todayCustomer', ['method' => 'POST']],
'crm/message/todayBusiness' => ['crm/message/todayBusiness', ['method' => 'POST']], 'crm/message/todayBusiness' => ['crm/message/todayBusiness', ['method' => 'POST']],
'crm/message/num' => ['crm/message/num', ['method' => 'POST']], 'crm/message/num' => ['crm/message/num', ['method' => 'POST']],
'crm/message/followLeads' => ['crm/message/followLeads', ['method' => 'POST']], 'crm/message/followLeads' => ['crm/message/followLeads', ['method' => 'POST']],
'crm/message/followCustomer' => ['crm/message/followCustomer', ['method' => 'POST']], 'crm/message/followCustomer' => ['crm/message/followCustomer', ['method' => 'POST']],
'crm/message/checkContract' => ['crm/message/checkContract', ['method' => 'POST']], 'crm/message/checkContract' => ['crm/message/checkContract', ['method' => 'POST']],
'crm/message/checkReceivables' => ['crm/message/checkReceivables', ['method' => 'POST']], 'crm/message/checkReceivables' => ['crm/message/checkReceivables', ['method' => 'POST']],
'crm/message/remindReceivablesPlan' => ['crm/message/remindReceivablesPlan', ['method' => 'POST']], 'crm/message/remindReceivablesPlan' => ['crm/message/remindReceivablesPlan', ['method' => 'POST']],
'crm/message/endContract' => ['crm/message/endContract', ['method' => 'POST']], 'crm/message/endContract' => ['crm/message/endContract', ['method' => 'POST']],
'crm/message/remindCustomer' => ['crm/message/remindCustomer', ['method' => 'POST']], 'crm/message/remindCustomer' => ['crm/message/remindCustomer', ['method' => 'POST']],
'crm/message/checkInvoice' => ['crm/message/checkInvoice', ['method' => 'POST']], 'crm/message/checkInvoice' => ['crm/message/checkInvoice', ['method' => 'POST']],
'crm/message/visitContract' => ['crm/message/visitContract', ['method' => 'POST']], 'crm/message/checkBusiness' => ['crm/message/checkBusiness', ['method' => 'POST']],
'crm/message/allDeal' => ['crm/message/allDeal', ['method' => 'POST']], 'crm/message/checkCustomerCheck' => ['crm/message/checkCustomerCheck', ['method' => 'POST']],
'crm/message/newBusiness' => ['crm/message/newBusiness', ['method' => 'POST']],
'crm/message/visitContract' => ['crm/message/visitContract', ['method' => 'POST']],
'crm/message/allDeal' => ['crm/message/allDeal', ['method' => 'POST']],
// 【客户】标记跟进 // 【客户】标记跟进
'crm/customer/setFollow' => ['crm/customer/setFollow', ['method' => 'POST']], 'crm/customer/setFollow' => ['crm/customer/setFollow', ['method' => 'POST']],
@ -481,14 +492,14 @@ return [
'crm/preview/previewPdf' => ['crm/preview/previewPdf', ['method' => 'POST']], 'crm/preview/previewPdf' => ['crm/preview/previewPdf', ['method' => 'POST']],
//【打印】下载打印文件 //【打印】下载打印文件
'crm/printing/down' => ['crm/printing/down', ['method' => 'POST']], 'crm/printing/down' => ['crm/printing/down', ['method' => 'POST']],
//跟进记录导入模板 //跟进记录导入模板
'crm/activity/excelDownload' => ['crm/activity/excelDownload', ['method' => 'POST']], 'crm/activity/excelDownload' => ['crm/activity/excelDownload', ['method' => 'POST']],
//跟进记录导入 //跟进记录导入
'crm/activity/excelImport' => ['crm/activity/excelImport', ['method' => 'POST']], 'crm/activity/excelImport' => ['crm/activity/excelImport', ['method' => 'POST']],
//跟进记录导出 //跟进记录导出
'crm/activity/excelExport' => ['crm/activity/excelExport', ['method' => 'POST']], 'crm/activity/excelExport' => ['crm/activity/excelExport', ['method' => 'POST']],
//市场活动列表 //市场活动列表
'crm/market/index' => ['crm/market/index', ['method' => 'POST']], 'crm/market/index' => ['crm/market/index', ['method' => 'POST']],
//市场活动添加 //市场活动添加
@ -517,7 +528,7 @@ return [
'crm/market/marketGetField' => ['crm/market/marketGetField', ['method' => 'POST']], 'crm/market/marketGetField' => ['crm/market/marketGetField', ['method' => 'POST']],
//【通用】快捷编辑 //【通用】快捷编辑
'crm/common/quickEdit' => ['crm/common/quickEdit', ['method' => 'POST']], 'crm/common/quickEdit' => ['crm/common/quickEdit', ['method' => 'POST']],
//手机导航列表 //手机导航列表
'crm/setting/appMenuConfig' => ['crm/setting/appMenuConfig', ['method' => 'POST']], 'crm/setting/appMenuConfig' => ['crm/setting/appMenuConfig', ['method' => 'POST']],
//办公数量 //办公数量
@ -525,6 +536,7 @@ return [
// 企业微信回调 // 企业微信回调
'crm/callback/index' => ['crm/callback/index', ['method' => 'POST|GET']], 'crm/callback/index' => ['crm/callback/index', ['method' => 'POST|GET']],
'crm/callback/work' => ['crm/callback/work', ['method' => 'POST|GET']],
// MISS路由 // MISS路由
'__miss__' => 'admin/base/miss', '__miss__' => 'admin/base/miss',

Loading…
Cancel
Save