pull/1/head
Michael_xu 3 years ago
parent 43045d9956
commit 25706b1136

@ -274,7 +274,7 @@ class ExamineFlow extends ApiCommon
{ {
$param = $this->param; $param = $this->param;
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$data= $this->checkFlow($param,$userInfo); $data= $this->checkFlow($param,$userInfo);
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
} }
@ -287,18 +287,18 @@ class ExamineFlow extends ApiCommon
* @version 1.0 版本号 * @version 1.0 版本号
* @since 2021/3/15 0015 13:37 * @since 2021/3/15 0015 13:37
*/ */
public function checkFlow($param,$userInfo){ public function checkFlow($param,$userInfo)
{
$examineStepModel = model('ExamineStep'); $examineStepModel = model('ExamineStep');
$examineFlowModel = model('ExamineFlow'); $examineFlowModel = model('ExamineFlow');
$check_user_id = $userInfo['id']; $check_user_id = $userInfo['id'];
$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']; $typesArr = ['crm_contract', 'crm_receivables', 'crm_invoice', 'oa_examine', 'jxc_purchase', 'jxc_retreat', 'jxc_sale', 'jxc_salereturn', 'jxc_payment', 'jxc_collection', 'jxc_allocation', 'jxc_inventory'];
if (!$types || !in_array($types, $typesArr)) { if (!$types || !in_array($types, $typesArr)) {
return resultArray(['error' => '参数错误']); return resultArray(['error' => '参数错误']);
} }
if ($flow_id) { if ($flow_id) {
$examineFlowData = $examineFlowModel->getDataById($param['flow_id']); $examineFlowData = $examineFlowModel->getDataById($param['flow_id']);
if (!$examineFlowData) { if (!$examineFlowData) {

@ -145,6 +145,21 @@ class Field extends ApiCommon
$errorMessage = '数字字段类型的小数配置错误!'; $errorMessage = '数字字段类型的小数配置错误!';
break; break;
} }
# 数组数据转换为字符串保存
if ($v['form_type'] == 'date_interval') {
$v['default_value']=trim((string)implode(',',$v['default_value']),'"');
}
if( $v['form_type']=='position'){
$v['default_value']=json_encode($v['default_value']);
}
# 数组数据转换为字符串保存
// if (!empty($v['fieldExtendList'])) {
// foreach ($v['fieldExtendList'] as $key=> $value){
// if($value['form_type']=='textarea'){
// $v['fieldExtendList'][$key]['default_value']=!empty($value['default_value'])?(string)trim("'".$value['default_value']."'",'"'):'';
// }
// }
// }
if ($v['field_id']) { if ($v['field_id']) {
if (isset($v['is_deleted']) && $v['is_deleted'] == '1') { if (isset($v['is_deleted']) && $v['is_deleted'] == '1') {
@ -164,7 +179,6 @@ class Field extends ApiCommon
$saveParam[$k]['types_id'] = $types_id; $saveParam[$k]['types_id'] = $types_id;
} }
} }
# 必填的字段不可以隐藏 # 必填的字段不可以隐藏
if ($errorMessage) return resultArray(['error' => $errorMessage]); if ($errorMessage) return resultArray(['error' => $errorMessage]);
@ -174,14 +188,12 @@ class Field extends ApiCommon
foreach ($deleteIds AS $key => $value) { foreach ($deleteIds AS $key => $value) {
if (!in_array($value, $delParam)) $delParam[] = $value; if (!in_array($value, $delParam)) $delParam[] = $value;
} }
# 新增 # 新增
if (!empty($saveParam)) { if (!empty($saveParam)) {
if (!$data = $fieldModel->createData($types, $saveParam)) { if (!$data = $fieldModel->createData($types, $saveParam)) {
$errorMessage[] = $fieldModel->getError(); $errorMessage[] = $fieldModel->getError();
} }
} }
# 编辑 # 编辑
if (!empty($updateParam)) { if (!empty($updateParam)) {
if (!$data = $fieldModel->updateDataById($updateParam, $types)) { if (!$data = $fieldModel->updateDataById($updateParam, $types)) {
@ -259,10 +271,14 @@ class Field extends ApiCommon
if ($action == 'read' || $action == 'update') { if ($action == 'read' || $action == 'update') {
//获取详情数据 //获取详情数据
if (($param['action'] == 'update' || $param['action'] == 'read') && $param['action_id']) { if (($param['action'] == 'update' || $param['action'] == 'read') && $param['action_id']) {
$model='';
if($param['action'] == 'update'){
$model='update';
}
switch ($param['types']) { switch ($param['types']) {
case 'crm_customer' : case 'crm_customer' :
$customerModel = new \app\crm\model\Customer(); $customerModel = new \app\crm\model\Customer();
$dataInfo = $customerModel->getDataById(intval($param['action_id'])); $dataInfo = $customerModel->getDataById($param['action_id'],'',$model);
//判断权限 //判断权限
$auth_user_ids = $userModel->getUserByPer('crm', 'customer', $param['action']); $auth_user_ids = $userModel->getUserByPer('crm', 'customer', $param['action']);
//读写权限 //读写权限
@ -278,9 +294,10 @@ class Field extends ApiCommon
break; break;
case 'crm_leads' : case 'crm_leads' :
$leadsModel = new \app\crm\model\Leads(); $leadsModel = new \app\crm\model\Leads();
$dataInfo = $leadsModel->getDataById(intval($param['action_id'])); $dataInfo = $leadsModel->getDataById($param['action_id'],'',$model);
//判断权限 //判断权限
$auth_user_ids = $userModel->getUserByPer('crm', 'leads', $param['action']); $auth_user_ids = $userModel->getUserByPer('crm', 'leads', $param['action']);
if (!in_array($dataInfo['owner_user_id'],$auth_user_ids)) { if (!in_array($dataInfo['owner_user_id'],$auth_user_ids)) {
header('Content-Type:application/json; charset=utf-8'); header('Content-Type:application/json; charset=utf-8');
exit(json_encode(['code'=>102,'error'=>'无权操作'])); exit(json_encode(['code'=>102,'error'=>'无权操作']));
@ -288,7 +305,7 @@ class Field extends ApiCommon
break; break;
case 'crm_contacts' : case 'crm_contacts' :
$contactsModel = new \app\crm\model\Contacts(); $contactsModel = new \app\crm\model\Contacts();
$dataInfo = $contactsModel->getDataById(intval($param['action_id'])); $dataInfo = $contactsModel->getDataById($param['action_id'],'',$model);
//判断权限 //判断权限
$auth_user_ids = $userModel->getUserByPer('crm', 'contacts', $param['action']); $auth_user_ids = $userModel->getUserByPer('crm', 'contacts', $param['action']);
if (!in_array($dataInfo['owner_user_id'],$auth_user_ids)) { if (!in_array($dataInfo['owner_user_id'],$auth_user_ids)) {
@ -298,7 +315,7 @@ class Field extends ApiCommon
break; break;
case 'crm_business' : case 'crm_business' :
$businessModel = new \app\crm\model\Business(); $businessModel = new \app\crm\model\Business();
$dataInfo = $businessModel->getDataById(intval($param['action_id'])); $dataInfo = $businessModel->getDataById($param['action_id'],'',$model);
//判断权限 //判断权限
$auth_user_ids = $userModel->getUserByPer('crm', 'business', $param['action']); $auth_user_ids = $userModel->getUserByPer('crm', 'business', $param['action']);
//读写权限 //读写权限
@ -311,7 +328,7 @@ class Field extends ApiCommon
break; break;
case 'crm_contract' : case 'crm_contract' :
$contractModel = new \app\crm\model\Contract(); $contractModel = new \app\crm\model\Contract();
$dataInfo = $contractModel->getDataById(intval($param['action_id'])); $dataInfo = $contractModel->getDataById($param['action_id'],'',$model);
//判断权限 //判断权限
$auth_user_ids = $userModel->getUserByPer('crm', 'contract', $param['action']); $auth_user_ids = $userModel->getUserByPer('crm', 'contract', $param['action']);
//读写权限 //读写权限
@ -324,7 +341,7 @@ class Field extends ApiCommon
break; break;
case 'crm_product' : case 'crm_product' :
$productModel = new \app\crm\model\Product(); $productModel = new \app\crm\model\Product();
$dataInfo = $productModel->getDataById(intval($param['action_id'])); $dataInfo = $productModel->getDataById($param['action_id'],'',$model);
//判断权限 //判断权限
$auth_user_ids = $userModel->getUserByPer('crm', 'product', $param['action']); $auth_user_ids = $userModel->getUserByPer('crm', 'product', $param['action']);
@ -335,7 +352,7 @@ class Field extends ApiCommon
break; break;
case 'crm_receivables' : case 'crm_receivables' :
$receivablesModel = new \app\crm\model\Receivables(); $receivablesModel = new \app\crm\model\Receivables();
$dataInfo = $receivablesModel->getDataById(intval($param['action_id'])); $dataInfo = $receivablesModel->getDataById($param['action_id'],'',$model);
//判断权限 //判断权限
$auth_user_ids = $userModel->getUserByPer('crm', 'receivables', $param['action']); $auth_user_ids = $userModel->getUserByPer('crm', 'receivables', $param['action']);
if (!in_array($dataInfo['owner_user_id'],$auth_user_ids)) { if (!in_array($dataInfo['owner_user_id'],$auth_user_ids)) {
@ -345,7 +362,13 @@ class Field extends ApiCommon
break; break;
case 'crm_receivables_plan' : case 'crm_receivables_plan' :
$receivablesPlanModel = new \app\crm\model\ReceivablesPlan(); $receivablesPlanModel = new \app\crm\model\ReceivablesPlan();
$dataInfo = $receivablesPlanModel->getDataById(intval($param['action_id'])); $dataInfo = $receivablesPlanModel->getDataById($param['action_id'],'',$model);
//判断权限
$auth_user_ids = $userModel->getUserByPer('crm', 'receivables_plan', $param['action']);
if (!in_array($dataInfo['owner_user_id'],$auth_user_ids)) {
header('Content-Type:application/json; charset=utf-8');
exit(json_encode(['code'=>102,'error'=>'无权操作']));
}
break; break;
case 'oa_examine' : case 'oa_examine' :
$examineModel = new \app\oa\model\Examine(); $examineModel = new \app\oa\model\Examine();
@ -362,7 +385,7 @@ class Field extends ApiCommon
break; break;
case 'crm_visit' : case 'crm_visit' :
$visit = new \app\crm\model\Visit(); $visit = new \app\crm\model\Visit();
$dataInfo = $visit->getDataById(intval($param['action_id'])); $dataInfo = $visit->getDataById($param['action_id'],'',$model);
$fieldModel = new \app\admin\model\Field(); $fieldModel = new \app\admin\model\Field();
$datetimeField = $fieldModel->getFieldByFormType('crm_visit', 'datetime'); //日期时间类型 $datetimeField = $fieldModel->getFieldByFormType('crm_visit', 'datetime'); //日期时间类型
foreach ($datetimeField as $key => $val) { foreach ($datetimeField as $key => $val) {
@ -379,8 +402,8 @@ class Field extends ApiCommon
} }
break; break;
case 'crm_invoice' : case 'crm_invoice' :
$visit = new \app\crm\model\Invoice(); $Invoice = new \app\crm\model\Invoice();
$dataInfo = $visit->getDataById(intval($param['action_id'])); $dataInfo = $Invoice->getDataById($param['action_id'],'',$model);
$fieldModel = new \app\admin\model\Field(); $fieldModel = new \app\admin\model\Field();
$datetimeField = $fieldModel->getFieldByFormType('crm_invoice', 'datetime'); //日期时间类型 $datetimeField = $fieldModel->getFieldByFormType('crm_invoice', 'datetime'); //日期时间类型
foreach ($datetimeField as $key => $val) { foreach ($datetimeField as $key => $val) {
@ -400,7 +423,6 @@ class Field extends ApiCommon
$param['user_id'] = $user_id; $param['user_id'] = $user_id;
$action_id = $param['action_id'] ? : ''; $action_id = $param['action_id'] ? : '';
$data = $fieldModel->field($param, $dataInfo) ? : []; $data = $fieldModel->field($param, $dataInfo) ? : [];
# 多公海数据详情 # 多公海数据详情
if (!empty($param['pool_id']) && $param['action'] == 'read') { if (!empty($param['pool_id']) && $param['action'] == 'read') {
$data = $this->setPoolDetailData($data, $param['pool_id'], $param['action_id']); $data = $this->setPoolDetailData($data, $param['pool_id'], $param['action_id']);
@ -511,10 +533,10 @@ class Field extends ApiCommon
case 'crm_leads' : case 'crm_leads' :
$leadsModel = new Leads(); $leadsModel = new Leads();
$leadsData = $leadsModel->getSystemInfo($action_id); $leadsData = $leadsModel->getSystemInfo($action_id);
$leadsArray = ['create_user_id' => '创建人', 'create_time' => '创建时间', 'update_time' => '更新时间', 'last_time' => '最后跟进时间']; $leadsArray = ['create_user_id' => '创建人' ,'owner_user_id' => '负责人', 'owner_user_structure_name' => '所属部门', 'create_time' => '创建时间', 'update_time' => '更新时间', 'last_time' => '最后跟进时间'];
foreach ($leadsData AS $key => $value) { foreach ($leadsData AS $key => $value) {
if (empty($leadsArray[$key])) continue; if (empty($leadsArray[$key]) ) continue;
$data[] = [ $data[] = [
'field' => $key, 'field' => $key,
@ -528,8 +550,7 @@ class Field extends ApiCommon
case 'crm_customer' : case 'crm_customer' :
$customerModel = new Customer(); $customerModel = new Customer();
$customerData = $customerModel->getSystemInfo($action_id); $customerData = $customerModel->getSystemInfo($action_id);
$customerArray = ['obtain_time' => '负责人获取客户时间', 'owner_user_id' => '负责人', 'create_user_id' => '创建人', 'create_time' => '创建时间', 'update_time' => '更新时间', 'last_time' => '最后跟进时间', 'last_record' => '最后跟进记录', 'deal_status' => '成交状态']; $customerArray = ['obtain_time' => '负责人获取客户时间', 'owner_user_id' => '负责人', 'owner_user_structure_name' => '所属部门', 'create_user_id' => '创建人', 'create_time' => '创建时间', 'update_time' => '更新时间', 'last_time' => '最后跟进时间', 'last_record' => '最后跟进记录', 'deal_status' => '成交状态'];
foreach ($customerData AS $key => $value) { foreach ($customerData AS $key => $value) {
if (empty($customerArray[$key]) || (!empty($param['pool_id']) && in_array($key, ['obtain_time', 'owner_user_id']))) continue; if (empty($customerArray[$key]) || (!empty($param['pool_id']) && in_array($key, ['obtain_time', 'owner_user_id']))) continue;
@ -545,7 +566,7 @@ class Field extends ApiCommon
case 'crm_contacts' : case 'crm_contacts' :
$contactsModel = new Contacts(); $contactsModel = new Contacts();
$contactsData = $contactsModel->getSystemInfo($action_id); $contactsData = $contactsModel->getSystemInfo($action_id);
$contactsArray = ['create_user_id' => '创建人', 'create_time' => '创建时间', 'update_time' => '更新时间', 'last_time' => '最后跟进时间']; $contactsArray = ['create_user_id' => '创建人' ,'owner_user_id' => '负责人', 'owner_user_structure_name' => '所属部门', 'create_time' => '创建时间', 'update_time' => '更新时间', 'last_time' => '最后跟进时间'];
foreach ($contactsData AS $key => $value) { foreach ($contactsData AS $key => $value) {
if (empty($contactsArray[$key])) continue; if (empty($contactsArray[$key])) continue;
@ -562,7 +583,7 @@ class Field extends ApiCommon
case 'crm_business' : case 'crm_business' :
$businessModel = new Business(); $businessModel = new Business();
$businessData = $businessModel->getSystemInfo($action_id); $businessData = $businessModel->getSystemInfo($action_id);
$businessArray = ['create_user_id' => '创建人', 'create_time' => '创建时间', 'update_time' => '更新时间', 'last_time' => '最后跟进时间']; $businessArray = ['create_user_id' => '创建人' ,'owner_user_id' => '负责人', 'owner_user_structure_name' => '所属部门', 'create_time' => '创建时间', 'update_time' => '更新时间', 'last_time' => '最后跟进时间'];
foreach ($businessData AS $key => $value) { foreach ($businessData AS $key => $value) {
if (empty($businessArray[$key])) continue; if (empty($businessArray[$key])) continue;
@ -579,7 +600,7 @@ class Field extends ApiCommon
case 'crm_contract' : case 'crm_contract' :
$contractModel = new Contract(); $contractModel = new Contract();
$contractData = $contractModel->getSystemInfo($action_id); $contractData = $contractModel->getSystemInfo($action_id);
$contractArray = ['create_user_id' => '创建人', 'create_time' => '创建时间', 'update_time' => '更新时间', 'last_time' => '最后跟进时间', 'done_money' => '已收款金额', 'un_money' => '未收款金额']; $contractArray = ['create_user_id' => '创建人','owner_user_id' => '负责人', 'owner_user_structure_name' => '所属部门', 'create_time' => '创建时间', 'update_time' => '更新时间', 'last_time' => '最后跟进时间', 'done_money' => '已收款金额', 'un_money' => '未收款金额'];
foreach ($contractData AS $key => $value) { foreach ($contractData AS $key => $value) {
if (empty($contractArray[$key])) continue; if (empty($contractArray[$key])) continue;
@ -596,7 +617,7 @@ class Field extends ApiCommon
case 'crm_receivables' : case 'crm_receivables' :
$receivablesModel = new Receivables(); $receivablesModel = new Receivables();
$receivablesData = $receivablesModel->getSystemInfo($action_id); $receivablesData = $receivablesModel->getSystemInfo($action_id);
$receivablesArray = ['create_user_id' => '创建人', 'create_time' => '创建时间', 'update_time' => '更新时间']; $receivablesArray = ['create_user_id' => '创建人','owner_user_id' => '负责人', 'owner_user_structure_name' => '所属部门', 'create_time' => '创建时间', 'update_time' => '更新时间'];
foreach ($receivablesData AS $key => $value) { foreach ($receivablesData AS $key => $value) {
if (empty($receivablesArray[$key])) continue; if (empty($receivablesArray[$key])) continue;
@ -613,7 +634,7 @@ class Field extends ApiCommon
case 'crm_product' : case 'crm_product' :
$productModel = new Product(); $productModel = new Product();
$productData = $productModel->getSystemInfo($action_id); $productData = $productModel->getSystemInfo($action_id);
$productArray = ['create_user_id' => '创建人', 'create_time' => '创建时间', 'update_time' => '更新时间']; $productArray = ['create_user_id' => '创建人' ,'owner_user_id' => '负责人', 'owner_user_structure_name' => '所属部门', 'create_time' => '创建时间', 'update_time' => '更新时间'];
foreach ($productData AS $key => $value) { foreach ($productData AS $key => $value) {
if (empty($productArray[$key])) continue; if (empty($productArray[$key])) continue;
@ -630,7 +651,7 @@ class Field extends ApiCommon
case 'crm_visit' : case 'crm_visit' :
$visitLogic = new VisitLogic(); $visitLogic = new VisitLogic();
$visitData = $visitLogic->getSystemInfo($action_id); $visitData = $visitLogic->getSystemInfo($action_id);
$visitArray = ['create_user_id' => '创建人', 'create_time' => '创建时间', 'update_time' => '更新时间']; $visitArray = ['create_user_id' => '创建人' ,'owner_user_id' => '负责人', 'owner_user_structure_name' => '所属部门', 'create_time' => '创建时间', 'update_time' => '更新时间'];
foreach ($visitData AS $key => $value) { foreach ($visitData AS $key => $value) {
if (empty($visitArray[$key])) continue; if (empty($visitArray[$key])) continue;
@ -646,18 +667,23 @@ class Field extends ApiCommon
break; break;
case 'crm_invoice' : case 'crm_invoice' :
$invoiceData = db('crm_invoice')->field(['create_user_id', 'owner_user_id', 'create_time', 'update_time'])->where('invoice_id', $action_id)->find(); $invoiceData = db('crm_invoice')->field(['create_user_id', 'owner_user_id', 'create_time', 'update_time'])->where('invoice_id', $action_id)->find();
$createUserName = db('admin_user')->where('id', $invoiceData['create_user_id'])->value('realname'); $createUserName = db('admin_user')->where('id', $invoiceData['create_user_id'])->value('realname');
$ownerUserName = db('admin_user')->where('id', $invoiceData['owner_user_id'])->value('realname');
$data[] = ['field' => 'create_user_id', 'name' => '创建人', 'form_type' => 'user', 'value' => $createUserName, 'system' => 1]; $data[] = ['field' => 'create_user_id', 'name' => '创建人', 'form_type' => 'user', 'value' => $createUserName, 'system' => 1];
$data[] = ['field' => 'create_user_id', 'name' => '负责人', 'form_type' => 'user', 'value' => $ownerUserName, 'system' => 1];
$data[] = ['field' => 'create_time', 'name' => '创建时间', 'form_type' => 'datetime', 'value' => date('Y-m-d H:i:s', $invoiceData['create_time']), 'system' => 1]; $data[] = ['field' => 'create_time', 'name' => '创建时间', 'form_type' => 'datetime', 'value' => date('Y-m-d H:i:s', $invoiceData['create_time']), 'system' => 1];
$data[] = ['field' => 'update_time', 'name' => '更新时间', 'form_type' => 'datetime', 'value' => date('Y-m-d H:i:s', $invoiceData['update_time']), 'system' => 1]; $data[] = ['field' => 'update_time', 'name' => '更新时间', 'form_type' => 'datetime', 'value' => date('Y-m-d H:i:s', $invoiceData['update_time']), 'system' => 1];
# zjf 20210726
$userModel = new \app\admin\model\User();
$ownerUserInfo = $userModel->getUserById($invoiceData['owner_user_id']);
$data[] = ['field' => 'owner_user_id', 'name' => '负责人', 'form_type' => 'user', 'value' => $ownerUserInfo['realname'], 'system' => 1];
$data[] = ['field' => 'owner_user_structure_name', 'name' => '所属部门', 'form_type' => 'text', 'value' => $ownerUserInfo['structure_name'], 'system' => 1];
} }
} }
# 处理自定义字段别名、权限 # 处理自定义字段别名、权限
$data = $fieldModel->resetField($user_id, $param['types'], $param['action'], $data); $data = $fieldModel->resetField($user_id, $param['types'], $param['action'], $data);
# 处理自定义字段分组排序 # 处理自定义字段分组排序
if (in_array($param['action'], ['save', 'update', 'relative']) && $format == 2) $data = getFieldGroupOrderData($data); if (in_array($param['action'], ['save', 'update', 'relative']) && $format == 2) $data = getFieldGroupOrderData($data);

@ -63,9 +63,13 @@ class Index extends ApiCommon
if ($param['types'] == 'crm_visit' && $value['field'] == 'owner_user_id') $field_arr[$key]['name'] = '回访人'; if ($param['types'] == 'crm_visit' && $value['field'] == 'owner_user_id') $field_arr[$key]['name'] = '回访人';
} }
if(in_array($param['types'],['crm_customer','crm_customer_pool','crm_contacts','crm_business','crm_contract','crm_receivables'])){ if(in_array($param['types'],['crm_customer','crm_customer_pool','crm_contacts','crm_business','crm_contract','crm_receivables'])){
$field=[['field'=>'team_id','name'=>'相关团队','form_type'=>'user','setting'=>[]]]; $field=[['field'=>'team_id','name'=>'相关团队','form_type'=>'text','setting'=>[]]];
$field_arr=array_merge($field_arr,$field); $field_arr=array_merge($field_arr,$field);
} }
// if($param['types'] == 'jxc_product'){
// $field_arr[] = ['field'=>'product_code','name'=>'产品编码','form_type'=>'text','setting'=>[]];
// }
// $field_arr[] = ['field'=>'owner_structure','name'=>'所属部门','form_type'=>'structure','setting'=>[]];
return resultArray(['data' => $field_arr]); return resultArray(['data' => $field_arr]);
} }

@ -47,9 +47,14 @@ class FieldGrantLogic
'number', 'visit_time', 'owner_user_id', 'shape', 'customer_id', 'contacts_id', 'contract_id', 'satisfaction', 'number', 'visit_time', 'owner_user_id', 'shape', 'customer_id', 'contacts_id', 'contract_id', 'satisfaction',
'feedback', 'create_user_id', 'create_time', 'update_time' 'feedback', 'create_user_id', 'create_time', 'update_time'
], ],
'invoice' => [ 'invoice' => [
'invoice_apple_number', 'customer_id', 'contract_id', 'contract_money', 'invoice_date', 'invoice_money', 'invoice_type', 'remark' 'invoice_apple_number', 'customer_id', 'contract_id', 'contract_money', 'invoice_date', 'invoice_money', 'invoice_type', 'remark'
], ],
'receivables_plan' => [
'receivables_id','un_money','real_money','real_data', 'num', 'money', 'owner_user_id', 'return_date', 'customer_id', 'remind', 'contract_id', 'create_user_id', 'create_time', 'update_time'
]
]; ];
/** /**
@ -70,7 +75,6 @@ class FieldGrantLogic
}; };
$count = Db::name('admin_field_grant')->where($where)->count(); $count = Db::name('admin_field_grant')->where($where)->count();
# 如果该角色下没有字段授权数据则自动添加 # 如果该角色下没有字段授权数据则自动添加
if ($count == 0 && Db::name('admin_group')->where('id', $param['role_id'])->find()) { if ($count == 0 && Db::name('admin_group')->where('id', $param['role_id'])->find()) {
$this->createCrmFieldGrant($param['role_id']); $this->createCrmFieldGrant($param['role_id']);
@ -113,6 +117,9 @@ class FieldGrantLogic
$this->createVisitFieldGrant($roleId); $this->createVisitFieldGrant($roleId);
# 添加发票字段授权信息 # 添加发票字段授权信息
$this->createInvoiceFieldGrant($roleId); $this->createInvoiceFieldGrant($roleId);
# 添加回款计划字段授权信息
$this->createReceivablesPlanFieldGrant($roleId);
} }
/** /**
@ -157,12 +164,12 @@ class FieldGrantLogic
$list = Db::name('admin_field_grant')->where('module', 'crm')->where('role_id', $copyId)->select(); $list = Db::name('admin_field_grant')->where('module', 'crm')->where('role_id', $copyId)->select();
foreach ($list AS $key => $value) { foreach ($list as $key => $value) {
$data[] = [ $data[] = [
'role_id' => $roleId, 'role_id' => $roleId,
'module' => $value['module'], 'module' => $value['module'],
'column' => $value['column'], 'column' => $value['column'],
'content' => $value['content'], 'content' => $value['content'],
'create_time' => time(), 'create_time' => time(),
'update_time' => time() 'update_time' => time()
]; ];
@ -192,7 +199,7 @@ class FieldGrantLogic
# 查询自定义字段表 # 查询自定义字段表
$fieldBaseData = []; $fieldBaseData = [];
$fieldList = Db::name('admin_field')->field(['name', 'field'])->where('types', $types)->select(); $fieldList = Db::name('admin_field')->field(['name', 'field'])->where('types', $types)->select();
foreach ($fieldList AS $key => $value) { foreach ($fieldList as $key => $value) {
# 排除掉固定字段 # 排除掉固定字段
if (in_array($value['field'], $this->except[$typesArray[1]])) continue; if (in_array($value['field'], $this->except[$typesArray[1]])) continue;
@ -203,11 +210,11 @@ class FieldGrantLogic
$grantList = Db::name('admin_field_grant')->field(['grant_id', 'content'])->where('column', $typesArray[1])->select(); $grantList = Db::name('admin_field_grant')->field(['grant_id', 'content'])->where('column', $typesArray[1])->select();
# 处理授权字段的数据更新 # 处理授权字段的数据更新
foreach ($grantList AS $key => $value) { foreach ($grantList as $key => $value) {
$content = unserialize($value['content']); $content = unserialize($value['content']);
$fieldData = $fieldBaseData; $fieldData = $fieldBaseData;
foreach ($content AS $k => $v) { foreach ($content as $k => $v) {
# 只处理自定义字段 # 只处理自定义字段
if ($v['is_diy'] == 0) continue; if ($v['is_diy'] == 0) continue;
@ -216,7 +223,7 @@ class FieldGrantLogic
unset($content[(int)$k]); unset($content[(int)$k]);
} else { } else {
# 【处理更新:】如果在$fieldData找到则进行同步更新。 # 【处理更新:】如果在$fieldData找到则进行同步更新。
$content[$k]['name'] = $fieldData[$v['field']]['name']; $content[$k]['name'] = $fieldData[$v['field']]['name'];
$content[$k]['field'] = $fieldData[$v['field']]['field']; $content[$k]['field'] = $fieldData[$v['field']]['field'];
# 删除$fieldData的数据方便统计新增的自定义字段。 # 删除$fieldData的数据方便统计新增的自定义字段。
@ -227,15 +234,15 @@ class FieldGrantLogic
# 【处理新增】如果$fieldData还有数据说明是新增的则进行同步新增。 # 【处理新增】如果$fieldData还有数据说明是新增的则进行同步新增。
if (!empty($fieldData)) { if (!empty($fieldData)) {
foreach ($fieldData AS $k => $v) { foreach ($fieldData as $k => $v) {
$content[] = [ $content[] = [
'name' => $v['name'], 'name' => $v['name'],
'field' => $v['field'], 'field' => $v['field'],
'read' => 1, 'read' => 1,
'read_operation' => 1, 'read_operation' => 1,
'write' => 1, 'write' => 1,
'write_operation' => 1, 'write_operation' => 1,
'is_diy' => 1 'is_diy' => 1
]; ];
} }
} }
@ -257,46 +264,46 @@ class FieldGrantLogic
{ {
# 固定字段 # 固定字段
$content = [ $content = [
['field' => 'name', 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '线索名称'], ['field' => 'name', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '线索名称'],
['field' => 'email', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '邮箱'], ['field' => 'email', 'maskType' => 0, 'form_type'=>'email', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '邮箱'],
['field' => 'source', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '线索来源'], ['field' => 'source', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '线索来源'],
['field' => 'mobile', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '手机'], ['field' => 'mobile', 'maskType' => 0, 'read' => 1,'form_type'=>'mobile', 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '手机'],
['field' => 'telephone', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '电话'], ['field' => 'telephone', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '电话'],
['field' => 'detail_address', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '地址'], ['field' => 'detail_address', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '地址'],
['field' => 'industry', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户行业'], ['field' => 'industry', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户行业'],
['field' => 'level', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户级别'], ['field' => 'level', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户级别'],
['field' => 'next_time', 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '下次联系时间'], ['field' => 'next_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '下次联系时间'],
['field' => 'remark', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'], ['field' => 'remark', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'],
['field' => 'owner_user_id', 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'], ['field' => 'owner_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'],
['field' => 'last_record', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进记录'], ['field' => 'last_record', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进记录'],
['field' => 'create_user_id', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'], ['field' => 'create_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'],
['field' => 'create_time', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'], ['field' => 'create_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'],
['field' => 'update_time', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'], ['field' => 'update_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'],
['field' => 'last_time', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进时间'], ['field' => 'last_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进时间'],
]; ];
$leadsList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_leads')->select(); $leadsList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_leads')->select();
# 自定义字段 # 自定义字段
foreach ($leadsList AS $key => $value) { foreach ($leadsList as $key => $value) {
if (in_array($value['field'], $this->except['leads'])) continue; if (in_array($value['field'], $this->except['leads'])) continue;
$content[] = [ $content[] = [
'name' => $value['name'], 'name' => $value['name'],
'field' => $value['field'], 'field' => $value['field'],
'read' => 1, 'form_type'=>$value['form_type'],
'read_operation' => 1, 'read' => 1,
'write' => 1, 'read_operation' => 1,
'write' => 1,
'write_operation' => 1, 'write_operation' => 1,
'is_diy' => 1 'is_diy' => 1
]; ];
} }
Db::name('admin_field_grant')->insert([ Db::name('admin_field_grant')->insert([
'role_id' => $roleId, 'role_id' => $roleId,
'module' => 'crm', 'module' => 'crm',
'column' => 'leads', 'column' => 'leads',
'content' => serialize($content), 'content' => serialize($content),
'create_time' => time(), 'create_time' => time(),
'update_time' => time() 'update_time' => time()
]); ]);
@ -313,50 +320,50 @@ class FieldGrantLogic
{ {
# 固定字段 # 固定字段
$content = [ $content = [
['field' => 'name', 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户名称'], ['field' => 'name', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户名称'],
['field' => 'source', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户来源'], ['field' => 'source', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户来源'],
['field' => 'mobile', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '手机'], ['field' => 'mobile', 'maskType' => 0,'form_type'=>'mobile', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '手机'],
['field' => 'telephone', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '电话'], ['field' => 'telephone', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '电话'],
['field' => 'website', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '网址'], ['field' => 'website', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '网址'],
['field' => 'industry', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户行业'], ['field' => 'industry', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户行业'],
['field' => 'level', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户级别'], ['field' => 'level', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户级别'],
['field' => 'next_time', 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '下次联系时间'], ['field' => 'next_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '下次联系时间'],
['field' => 'remark', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'], ['field' => 'remark', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'],
['field' => 'email', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '邮箱'], ['field' => 'email', 'maskType' => 0,'form_type'=>'email', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '邮箱'],
['field' => 'owner_user_id', 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'], ['field' => 'owner_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'],
['field' => 'last_record', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进记录'], ['field' => 'last_record', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进记录'],
['field' => 'create_user_id', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'], ['field' => 'create_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'],
['field' => 'create_time', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'], ['field' => 'create_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'],
['field' => 'update_time', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'], ['field' => 'update_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'],
['field' => 'last_time', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进时间'], ['field' => 'last_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进时间'],
['field' => 'obtain_time', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人获取客户时间'], ['field' => 'obtain_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人获取客户时间'],
['field' => 'deal_status', 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '成交状态'], ['field' => 'deal_status', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '成交状态'],
['field' => 'is_lock', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '锁定状态'], ['field' => 'is_lock', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '锁定状态'],
['field' => 'pool_day', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '距进入公海天数'], ['field' => 'pool_day', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '距进入公海天数'],
]; ];
$customerList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_customer')->select(); $customerList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_customer')->select();
# 自定义字段 # 自定义字段
foreach ($customerList AS $key => $value) { foreach ($customerList as $key => $value) {
if (in_array($value['field'], $this->except['customer'])) continue; if (in_array($value['field'], $this->except['customer'])) continue;
$content[] = [ $content[] = [
'name' => $value['name'], 'name' => $value['name'],
'field' => $value['field'], 'field' => $value['field'],
'read' => 1, 'read' => 1,
'read_operation' => 1, 'read_operation' => 1,
'write' => 1, 'write' => 1,
'write_operation' => 1, 'write_operation' => 1,
'is_diy' => 1 'is_diy' => 1
]; ];
} }
Db::name('admin_field_grant')->insert([ Db::name('admin_field_grant')->insert([
'role_id' => $roleId, 'role_id' => $roleId,
'module' => 'crm', 'module' => 'crm',
'column' => 'customer', 'column' => 'customer',
'content' => serialize($content), 'content' => serialize($content),
'create_time' => time(), 'create_time' => time(),
'update_time' => time() 'update_time' => time()
]); ]);
@ -373,46 +380,46 @@ class FieldGrantLogic
{ {
# 固定字段 # 固定字段
$content = [ $content = [
['field' => 'name', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '姓名'], ['field' => 'name', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '姓名'],
['field' => 'customer_id', 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '客户名称'], ['field' => 'customer_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '客户名称'],
['field' => 'mobile', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '手机'], ['field' => 'mobile', 'maskType' => 0,'form_type'=>'mobile', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '手机'],
['field' => 'telephone', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '电话'], ['field' => 'telephone', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '电话'],
['field' => 'email', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '邮箱'], ['field' => 'email', 'maskType' => 0, 'form_type'=>'email','read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '邮箱'],
['field' => 'post', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '职务'], ['field' => 'post', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '职务'],
['field' => 'decision', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '是否关键决策人'], ['field' => 'decision', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '是否关键决策人'],
['field' => 'detail_address', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '地址'], ['field' => 'detail_address', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '地址'],
['field' => 'next_time', 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '下次联系时间'], ['field' => 'next_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '下次联系时间'],
['field' => 'remark', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'], ['field' => 'remark', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'],
['field' => 'sex', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '性别'], ['field' => 'sex', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '性别'],
['field' => 'owner_user_id', 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'], ['field' => 'owner_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'],
['field' => 'create_user_id', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'], ['field' => 'create_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'],
['field' => 'create_time', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'], ['field' => 'create_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'],
['field' => 'update_time', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'], ['field' => 'update_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'],
['field' => 'last_time', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进时间'], ['field' => 'last_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进时间'],
]; ];
$contactsList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_contacts')->select(); $contactsList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_contacts')->select();
# 自定义字段 # 自定义字段
foreach ($contactsList AS $key => $value) { foreach ($contactsList as $key => $value) {
if (in_array($value['field'], $this->except['contacts'])) continue; if (in_array($value['field'], $this->except['contacts'])) continue;
$content[] = [ $content[] = [
'name' => $value['name'], 'name' => $value['name'],
'field' => $value['field'], 'field' => $value['field'],
'read' => 1, 'read' => 1,
'read_operation' => 1, 'read_operation' => 1,
'write' => 1, 'write' => 1,
'write_operation' => 1, 'write_operation' => 1,
'is_diy' => 1 'is_diy' => 1
]; ];
} }
Db::name('admin_field_grant')->insert([ Db::name('admin_field_grant')->insert([
'role_id' => $roleId, 'role_id' => $roleId,
'module' => 'crm', 'module' => 'crm',
'column' => 'contacts', 'column' => 'contacts',
'content' => serialize($content), 'content' => serialize($content),
'create_time' => time(), 'create_time' => time(),
'update_time' => time() 'update_time' => time()
]); ]);
@ -429,42 +436,42 @@ class FieldGrantLogic
{ {
# 固定字段 # 固定字段
$content = [ $content = [
['field' => 'name', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '商机名称'], ['field' => 'name', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '商机名称'],
['field' => 'customer_id', 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '客户名称'], ['field' => 'customer_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '客户名称'],
['field' => 'money', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '商机金额'], ['field' => 'money', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '商机金额'],
['field' => 'deal_date', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '预计成交日期'], ['field' => 'deal_date', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '预计成交日期'],
['field' => 'remark', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'], ['field' => 'remark', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'],
['field' => 'status_id', 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '商机阶段'], ['field' => 'status_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '商机阶段'],
['field' => 'type_id', 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '商机状态组'], ['field' => 'type_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '商机状态组'],
['field' => 'owner_user_id', 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'], ['field' => 'owner_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'],
['field' => 'create_user_id', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'], ['field' => 'create_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'],
['field' => 'create_time', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'], ['field' => 'create_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'],
['field' => 'update_time', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'], ['field' => 'update_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'],
['field' => 'last_time', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进时间'], ['field' => 'last_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进时间'],
]; ];
$BusinessList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_business')->select(); $BusinessList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_business')->select();
# 自定义字段 # 自定义字段
foreach ($BusinessList AS $key => $value) { foreach ($BusinessList as $key => $value) {
if (in_array($value['field'], $this->except['business'])) continue; if (in_array($value['field'], $this->except['business'])) continue;
$content[] = [ $content[] = [
'name' => $value['name'], 'name' => $value['name'],
'field' => $value['field'], 'field' => $value['field'],
'read' => 1, 'read' => 1,
'read_operation' => 1, 'read_operation' => 1,
'write' => 1, 'write' => 1,
'write_operation' => 1, 'write_operation' => 1,
'is_diy' => 1 'is_diy' => 1
]; ];
} }
Db::name('admin_field_grant')->insert([ Db::name('admin_field_grant')->insert([
'role_id' => $roleId, 'role_id' => $roleId,
'module' => 'crm', 'module' => 'crm',
'column' => 'business', 'column' => 'business',
'content' => serialize($content), 'content' => serialize($content),
'create_time' => time(), 'create_time' => time(),
'update_time' => time() 'update_time' => time()
]); ]);
@ -481,50 +488,50 @@ class FieldGrantLogic
{ {
# 固定字段 # 固定字段
$content = [ $content = [
['field' => 'name', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '合同名称'], ['field' => 'name', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '合同名称'],
['field' => 'num', 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '合同编号'], ['field' => 'num', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '合同编号'],
['field' => 'customer_id', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户名称'], ['field' => 'customer_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户名称'],
['field' => 'business_id', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '商机名称'], ['field' => 'business_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '商机名称'],
['field' => 'money', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '合同金额'], ['field' => 'money', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '合同金额'],
['field' => 'order_date', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '下单时间'], ['field' => 'order_date', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '下单时间'],
['field' => 'start_time', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '合同开始时间'], ['field' => 'start_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '合同开始时间'],
['field' => 'end_time', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '合同结束时间'], ['field' => 'end_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '合同结束时间'],
['field' => 'contacts_id', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户签约人'], ['field' => 'contacts_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户签约人'],
['field' => 'order_user_id', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '公司签约人'], ['field' => 'order_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '公司签约人'],
['field' => 'remark', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'], ['field' => 'remark', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'],
['field' => 'owner_user_id', 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'], ['field' => 'owner_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'],
['field' => 'create_user_id', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'], ['field' => 'create_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'],
['field' => 'create_time', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'], ['field' => 'create_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'],
['field' => 'update_time', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'], ['field' => 'update_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'],
['field' => 'last_time', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进时间'], ['field' => 'last_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进时间'],
['field' => 'last_record', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进记录'], ['field' => 'last_record', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '最后跟进记录'],
['field' => 'done_money', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '已收款金额'], ['field' => 'done_money', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '已收款金额'],
['field' => 'un_money', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '未收款金额'], ['field' => 'un_money', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '未收款金额'],
['field' => 'check_status', 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '审核状态'], ['field' => 'check_status', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '审核状态'],
]; ];
$contractList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_contract')->select(); $contractList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_contract')->select();
# 自定义字段 # 自定义字段
foreach ($contractList AS $key => $value) { foreach ($contractList as $key => $value) {
if (in_array($value['field'], $this->except['contract'])) continue; if (in_array($value['field'], $this->except['contract'])) continue;
$content[] = [ $content[] = [
'name' => $value['name'], 'name' => $value['name'],
'field' => $value['field'], 'field' => $value['field'],
'read' => 1, 'read' => 1,
'read_operation' => 1, 'read_operation' => 1,
'write' => 1, 'write' => 1,
'write_operation' => 1, 'write_operation' => 1,
'is_diy' => 1 'is_diy' => 1
]; ];
} }
Db::name('admin_field_grant')->insert([ Db::name('admin_field_grant')->insert([
'role_id' => $roleId, 'role_id' => $roleId,
'module' => 'crm', 'module' => 'crm',
'column' => 'contract', 'column' => 'contract',
'content' => serialize($content), 'content' => serialize($content),
'create_time' => time(), 'create_time' => time(),
'update_time' => time() 'update_time' => time()
]); ]);
@ -541,44 +548,44 @@ class FieldGrantLogic
{ {
# 固定字段 # 固定字段
$content = [ $content = [
['field' => 'number', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回款编号'], ['field' => 'number', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回款编号'],
['field' => 'customer_id', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户名称'], ['field' => 'customer_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户名称'],
['field' => 'contract_id', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '合同编号'], ['field' => 'contract_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '合同编号'],
['field' => 'plan_id', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '期数'], ['field' => 'plan_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '期数'],
['field' => 'return_time', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回款日期'], ['field' => 'return_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回款日期'],
['field' => 'money', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回款金额'], ['field' => 'money', 'maskType' => 0,'form_type'=>'floatnumber', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回款金额'],
['field' => 'return_type', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回款方式'], ['field' => 'return_type', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回款方式'],
['field' => 'remark', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'], ['field' => 'remark', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'],
['field' => 'contract_money', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '合同金额'], ['field' => 'contract_money', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '合同金额'],
['field' => 'owner_user_id', 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'], ['field' => 'owner_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'],
['field' => 'create_user_id', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'], ['field' => 'create_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'],
['field' => 'create_time', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'], ['field' => 'create_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'],
['field' => 'update_time', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'], ['field' => 'update_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'],
['field' => 'check_status', 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '审核状态'], ['field' => 'check_status', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '审核状态'],
]; ];
$receivablesList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_receivables')->select(); $receivablesList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_receivables')->select();
# 自定义字段 # 自定义字段
foreach ($receivablesList AS $key => $value) { foreach ($receivablesList as $key => $value) {
if (in_array($value['field'], $this->except['receivables'])) continue; if (in_array($value['field'], $this->except['receivables'])) continue;
$content[] = [ $content[] = [
'name' => $value['name'], 'name' => $value['name'],
'field' => $value['field'], 'field' => $value['field'],
'read' => 1, 'read' => 1,
'read_operation' => 1, 'read_operation' => 1,
'write' => 1, 'write' => 1,
'write_operation' => 1, 'write_operation' => 1,
'is_diy' => 1 'is_diy' => 1
]; ];
} }
Db::name('admin_field_grant')->insert([ Db::name('admin_field_grant')->insert([
'role_id' => $roleId, 'role_id' => $roleId,
'module' => 'crm', 'module' => 'crm',
'column' => 'receivables', 'column' => 'receivables',
'content' => serialize($content), 'content' => serialize($content),
'create_time' => time(), 'create_time' => time(),
'update_time' => time() 'update_time' => time()
]); ]);
@ -595,41 +602,41 @@ class FieldGrantLogic
{ {
# 固定字段 # 固定字段
$content = [ $content = [
['field' => 'name', 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '产品名称'], ['field' => 'name', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '产品名称'],
['field' => 'category_id', 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '产品类型'], ['field' => 'category_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '产品类型'],
['field' => 'unit', 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '产品单位'], ['field' => 'unit', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '产品单位'],
['field' => 'num', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '产品编码'], ['field' => 'num', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '产品编码'],
['field' => 'price', 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '价格'], ['field' => 'price', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '价格'],
['field' => 'description', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '产品描述'], ['field' => 'description', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '产品描述'],
['field' => 'status', 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '是否上下架'], ['field' => 'status', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '是否上下架'],
['field' => 'owner_user_id', 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'], ['field' => 'owner_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'],
['field' => 'create_user_id', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'], ['field' => 'create_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'],
['field' => 'create_time', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'], ['field' => 'create_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'],
['field' => 'update_time', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'], ['field' => 'update_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'],
]; ];
$productList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_product')->select(); $productList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_product')->select();
# 自定义字段 # 自定义字段
foreach ($productList AS $key => $value) { foreach ($productList as $key => $value) {
if (in_array($value['field'], $this->except['product'])) continue; if (in_array($value['field'], $this->except['product'])) continue;
$content[] = [ $content[] = [
'name' => $value['name'], 'name' => $value['name'],
'field' => $value['field'], 'field' => $value['field'],
'read' => 1, 'read' => 1,
'read_operation' => 1, 'read_operation' => 1,
'write' => 1, 'write' => 1,
'write_operation' => 1, 'write_operation' => 1,
'is_diy' => 1 'is_diy' => 1
]; ];
} }
Db::name('admin_field_grant')->insert([ Db::name('admin_field_grant')->insert([
'role_id' => $roleId, 'role_id' => $roleId,
'module' => 'crm', 'module' => 'crm',
'column' => 'product', 'column' => 'product',
'content' => serialize($content), 'content' => serialize($content),
'create_time' => time(), 'create_time' => time(),
'update_time' => time() 'update_time' => time()
]); ]);
@ -645,49 +652,49 @@ class FieldGrantLogic
private function createVisitFieldGrant($roleId) private function createVisitFieldGrant($roleId)
{ {
$content = [ $content = [
['field' => 'number', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回访编号'], ['field' => 'number', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回访编号'],
['field' => 'visit_time', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回访时间'], ['field' => 'visit_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回访时间'],
['field' => 'owner_user_id', 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '回访人'], ['field' => 'owner_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '回访人'],
['field' => 'shape', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回访形式'], ['field' => 'shape', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '回访形式'],
['field' => 'customer_id', 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '客户名称'], ['field' => 'customer_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '客户名称'],
['field' => 'contacts_id', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '联系人'], ['field' => 'contacts_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '联系人'],
['field' => 'contract_id', 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '合同编号'], ['field' => 'contract_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '合同编号'],
['field' => 'satisfaction', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户满意度'], ['field' => 'satisfaction', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户满意度'],
['field' => 'feedback', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户反馈'], ['field' => 'feedback', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '客户反馈'],
['field' => 'create_user_id', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'], ['field' => 'create_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'],
['field' => 'create_time', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'], ['field' => 'create_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'],
['field' => 'update_time', 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'], ['field' => 'update_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'],
]; ];
$visitList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_visit')->select(); $visitList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_visit')->select();
# 处理自定义字段 # 处理自定义字段
foreach ($visitList AS $key => $value) { foreach ($visitList as $key => $value) {
if (in_array($value['field'], $this->except['visit'])) continue; if (in_array($value['field'], $this->except['visit'])) continue;
$content[] = [ $content[] = [
'name' => $value['name'], 'name' => $value['name'],
'field' => $value['field'], 'field' => $value['field'],
'read' => 1, 'read' => 1,
'read_operation' => 1, 'read_operation' => 1,
'write' => 1, 'write' => 1,
'write_operation' => 1, 'write_operation' => 1,
'is_diy' => 1 'is_diy' => 1
]; ];
} }
Db::name('admin_field_grant')->insert([ Db::name('admin_field_grant')->insert([
'role_id' => $roleId, 'role_id' => $roleId,
'module' => 'crm', 'module' => 'crm',
'column' => 'visit', 'column' => 'visit',
'content' => serialize($content), 'content' => serialize($content),
'create_time' => time(), 'create_time' => time(),
'update_time' => time() 'update_time' => time()
]); ]);
} }
/** /**
* 处理回访字段授权信息 * 处理发票字段授权信息
* *
* @param $roleId * @param $roleId
* @author fanqi * @author fanqi
@ -696,38 +703,86 @@ class FieldGrantLogic
private function createInvoiceFieldGrant($roleId) private function createInvoiceFieldGrant($roleId)
{ {
$content = [ $content = [
['field' => 'invoice_apple_number', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '发票申请编号'], ['field' => 'invoice_apple_number', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '发票申请编号'],
['field' => 'customer_id', 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '客户名称'], ['field' => 'customer_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '客户名称'],
['field' => 'contract_id', 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '合同编号'], ['field' => 'contract_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '合同编号'],
['field' => 'contract_money', 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '合同金额'], ['field' => 'contract_money', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '合同金额'],
['field' => 'invoice_money', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '开票金额'], ['field' => 'invoice_money', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '开票金额'],
['field' => 'invoice_date', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '开票日期'], ['field' => 'invoice_date', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '开票日期'],
['field' => 'invoice_type', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '开票类型'], ['field' => 'invoice_type', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '开票类型'],
['field' => 'remark', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'], ['field' => 'remark', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '备注'],
]; ];
$invoiceList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_invoice')->select(); $invoiceList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_invoice')->select();
# 处理自定义字段 # 处理自定义字段
foreach ($invoiceList AS $key => $value) { foreach ($invoiceList as $key => $value) {
if (in_array($value['field'], $this->except['invoice'])) continue; if (in_array($value['field'], $this->except['invoice'])) continue;
$content[] = [ $content[] = [
'name' => $value['name'], 'name' => $value['name'],
'field' => $value['field'], 'field' => $value['field'],
'read' => 1, 'read' => 1,
'read_operation' => 1, 'read_operation' => 1,
'write' => 1, 'write' => 1,
'write_operation' => 1, 'write_operation' => 1,
'is_diy' => 1 'is_diy' => 1
]; ];
} }
Db::name('admin_field_grant')->insert([ Db::name('admin_field_grant')->insert([
'role_id' => $roleId, 'role_id' => $roleId,
'module' => 'crm', 'module' => 'crm',
'column' => 'invoice', 'column' => 'invoice',
'content' => serialize($content), 'content' => serialize($content),
'create_time' => time(),
'update_time' => time()
]);
}
/**
* 处理回款计划字段授权信息
*
* @param int $roleId
* @author fanqi
* @date 2021-03-22
*/
private function createReceivablesPlanFieldGrant($roleId)
{
$content = [
['field' => 'num', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '期数'],
['field' => 'money', 'maskType' => 0, 'form_type'=>'floatnumber', 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '计划回款金额'],
['field' => 'owner_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '负责人'],
['field' => 'return_date', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '计划回款日期'],
['field' => 'customer_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '客户名称'],
['field' => 'remind', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 1, 'write_operation' => 1, 'is_diy' => 0, 'name' => '提前几日提醒'],
['field' => 'contract_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 0, 'write' => 1, 'write_operation' => 0, 'is_diy' => 0, 'name' => '合同编号'],
['field' => 'create_user_id', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建人'],
['field' => 'create_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '创建时间'],
['field' => 'update_time', 'maskType' => 0, 'read' => 1, 'read_operation' => 1, 'write' => 0, 'write_operation' => 0, 'is_diy' => 0, 'name' => '更新时间'],
];
$visitList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_receivables_plan')->select();
# 处理自定义字段
foreach ($visitList as $key => $value) {
if (in_array($value['field'], $this->except['receivables_plan'])) continue;
$content[] = [
'name' => $value['name'],
'field' => $value['field'],
'read' => 1,
'read_operation' => 1,
'write' => 1,
'write_operation' => 1,
'is_diy' => 1
];
}
Db::name('admin_field_grant')->insert([
'role_id' => $roleId,
'module' => 'crm',
'column' => 'receivables_plan',
'content' => serialize($content),
'create_time' => time(), 'create_time' => time(),
'update_time' => time() 'update_time' => time()
]); ]);

@ -207,12 +207,12 @@ class PrintingLogic
{ {
$result = []; $result = [];
$businessList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_business')->select(); $businessList = Db::name('admin_field')->field(['name', 'field','form_type'])->where('types', 'crm_business')->select();
# 处理自定义字段 # 处理自定义字段
foreach ($businessList AS $key => $value) { foreach ($businessList AS $key => $value) {
if ($value['field'] == 'customer_id') continue; if ($value['field'] == 'customer_id') continue;
if ($value['form_type']=='detail_table') continue;
$result[] = [ $result[] = [
'name' => $value['name'], 'name' => $value['name'],
'field' => $value['field'] 'field' => $value['field']
@ -240,13 +240,13 @@ class PrintingLogic
{ {
$result = []; $result = [];
$customerList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_customer')->select(); $customerList = Db::name('admin_field')->field(['name', 'field','form_type'])->where('types', 'crm_customer')->select();
# 处理自定义字段 # 处理自定义字段
foreach ($customerList AS $key => $value) { foreach ($customerList AS $key => $value) {
if (in_array($value['field'], ['next_time'])) continue; if (in_array($value['field'], ['next_time'])) continue;
if (in_array($type, [5, 6]) && in_array($value['field'], ['deal_status'])) continue; if (in_array($type, [5, 6]) && in_array($value['field'], ['deal_status'])) continue;
if ($value['form_type']=='detail_table') continue;
$result[] = [ $result[] = [
'name' => $value['name'], 'name' => $value['name'],
'field' => $value['field'] 'field' => $value['field']
@ -274,13 +274,13 @@ class PrintingLogic
{ {
$result = []; $result = [];
$productList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_product')->select(); $productList = Db::name('admin_field')->field(['name', 'field','form_type'])->where('types', 'crm_product')->select();
# 处理自定义字段 # 处理自定义字段
foreach ($productList AS $key => $value) { foreach ($productList AS $key => $value) {
if (in_array($value['field'], ['status'])) continue; if (in_array($value['field'], ['status'])) continue;
if (in_array($type, [5, 6]) && in_array($value['field'], ['description'])) continue; if (in_array($type, [5, 6]) && in_array($value['field'], ['description'])) continue;
if ($value['form_type']=='detail_table') continue;
$result[] = [ $result[] = [
'name' => $value['name'], 'name' => $value['name'],
'field' => $value['field'] 'field' => $value['field']
@ -310,13 +310,13 @@ class PrintingLogic
{ {
$result = []; $result = [];
$contractList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_contract')->select(); $contractList = Db::name('admin_field')->field(['name', 'field','form_type'])->where('types', 'crm_contract')->select();
# 处理自定义字段 # 处理自定义字段
foreach ($contractList AS $key => $value) { foreach ($contractList AS $key => $value) {
if (in_array($type, [6, 7]) && in_array($value['field'], ['customer_id'])) continue; if (in_array($type, [6, 7]) && in_array($value['field'], ['customer_id'])) continue;
if ($type == 7 && in_array($value['field'], ['business_id'])) continue; if ($type == 7 && in_array($value['field'], ['business_id'])) continue;
if ($value['form_type']=='detail_table') continue;
$result[] = [ $result[] = [
'name' => $value['name'], 'name' => $value['name'],
'field' => $value['field'] 'field' => $value['field']
@ -347,12 +347,12 @@ class PrintingLogic
{ {
$result = []; $result = [];
$contactsList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_contacts')->select(); $contactsList = Db::name('admin_field')->field(['name', 'field','form_type'])->where('types', 'crm_contacts')->select();
# 处理自定义字段 # 处理自定义字段
foreach ($contactsList AS $key => $value) { foreach ($contactsList AS $key => $value) {
if ($value['field'] == 'next_time') continue; if ($value['field'] == 'next_time') continue;
if ($value['form_type']=='detail_table') continue;
$result[] = [ $result[] = [
'name' => $value['name'], 'name' => $value['name'],
'field' => $value['field'] 'field' => $value['field']
@ -374,13 +374,13 @@ class PrintingLogic
{ {
$result = []; $result = [];
$receivablesList = Db::name('admin_field')->field(['name', 'field'])->where('types', 'crm_receivables')->select(); $receivablesList = Db::name('admin_field')->field(['name', 'field','form_type'])->where('types', 'crm_receivables')->select();
# 处理自定义字段 # 处理自定义字段
foreach ($receivablesList AS $key => $value) { foreach ($receivablesList AS $key => $value) {
if (in_array($value['field'], ['contract_id'])) continue; if (in_array($value['field'], ['contract_id'])) continue;
if (in_array($type, [7]) && in_array($value['field'], ['contract_id'])) continue; if (in_array($type, [7]) && in_array($value['field'], ['contract_id'])) continue;
if ($value['form_type']=='detail_table') continue;
$result[] = [ $result[] = [
'name' => $value['name'], 'name' => $value['name'],
'field' => $value['field'] 'field' => $value['field']

@ -16,7 +16,7 @@ class ActionRecord extends Common
* 我们约定每个模块的数据表都加上相同的前缀比如CRM模块用crm作为数据表前缀 * 我们约定每个模块的数据表都加上相同的前缀比如CRM模块用crm作为数据表前缀
*/ */
protected $name = 'admin_action_record'; protected $name = 'admin_action_record';
public $typesArr = ['crm_leads','crm_customer','crm_contacts','crm_product','crm_business','crm_contract','crm_receivables','crm_visit']; public $typesArr = ['crm_leads','crm_customer','crm_contacts','crm_product','crm_business','crm_contract','crm_receivables','crm_visit','jxc_product','jxc_supplier','jxc_purchase','jxc_retreat','jxc_sale','jxc_salereturn','jxc_receipt','jxc_outbound','jxc_payment','jxc_collection','jxc_inventory','jxc_allocation'];
/** /**
* [getDataList 获取列表] * [getDataList 获取列表]
@ -91,7 +91,19 @@ class ActionRecord extends Common
break; break;
case 'crm_visit' : case 'crm_visit' :
$checkRes = checkPerByAction('crm', 'visit', 'read'); $checkRes = checkPerByAction('crm', 'visit', 'read');
break; break;
case 'jxc_product': $checkRes = checkPerByAction('jxc', 'product', 'read'); break;
case 'jxc_supplier': $checkRes = checkPerByAction('jxc', 'supplier', 'read'); break;
case 'jxc_purchase': $checkRes = checkPerByAction('jxc', 'purchase', 'read'); break;
case 'jxc_retreat': $checkRes = checkPerByAction('jxc', 'retreat', 'read'); break;
case 'jxc_sale': $checkRes = checkPerByAction('jxc', 'sale', 'read'); break;
case 'jxc_salereturn': $checkRes = checkPerByAction('jxc', 'salereturn', 'read'); break;
case 'jxc_receipt': $checkRes = checkPerByAction('jxc', 'receipt', 'read'); break;
case 'jxc_outbound': $checkRes = checkPerByAction('jxc', 'outbound', 'read'); break;
case 'jxc_payment': $checkRes = checkPerByAction('jxc', 'payment', 'read'); break;
case 'jxc_collection': $checkRes = checkPerByAction('jxc', 'collection', 'read'); break;
case 'jxc_inventory': $checkRes = checkPerByAction('jxc', 'inventory', 'read'); break;
case 'jxc_allocation': $checkRes = checkPerByAction('jxc', 'allocation', 'read'); break;
} }
if ($checkRes !== false) { if ($checkRes !== false) {
return true; return true;

@ -295,9 +295,9 @@ class Common extends Model
*/ */
public function exportHandle($list, $field_list, $type = '') public function exportHandle($list, $field_list, $type = '')
{ {
foreach ($list as &$val) { foreach ($list as &$val) {
foreach ($field_list as $field) { foreach ($field_list as $field) {
// p($field);
switch ($field['form_type']) { switch ($field['form_type']) {
case 'user': case 'user':
if (isset($val[$field['field'] . 'name'])) { if (isset($val[$field['field'] . 'name'])) {
@ -320,6 +320,16 @@ class Common extends Model
case 'contacts': case 'contacts':
$val[$field['field']] = $val[$field['field'] . '_info']['name']; $val[$field['field']] = $val[$field['field'] . '_info']['name'];
break; break;
case 'boolean_value':
if( $val[$field['field']]==0){
$val[$field['field']]='否';
}else{
$val[$field['field']]='是';
}
break;
case 'date_interval' :
$val[$field['field']] = implode('_', $val[$field['field']]);
break;
default : default :
switch ($field['field']) { switch ($field['field']) {
// 商机销售阶段、商机状态组 // 商机销售阶段、商机状态组
@ -337,6 +347,13 @@ class Common extends Model
case 'plan_id' : case 'plan_id' :
$val[$field['field']] = $val[$field['field'] . '_info']; $val[$field['field']] = $val[$field['field'] . '_info'];
break; break;
case 'warehouse_isuse' :
$val[$field['field']] = $val[$field['field']] == 0 ? '已停用' : '已启用';
break;
default :
if($field['form_type'] == 'text'){
$val[$field['field']] = (string)$val[$field['field']];
}
} }
} }
} }

@ -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']; protected $typesArr = ['crm_contract', 'crm_receivables', 'crm_invoice', 'oa_examine', 'jxc_purchase', 'jxc_retreat', 'jxc_sale', 'jxc_salereturn', 'jxc_payment', 'jxc_collection', 'jxc_allocation', 'jxc_inventory'];
/** /**
* [getDataList 审批流程list] * [getDataList 审批流程list]

@ -57,13 +57,22 @@ class ExamineRecord extends Common
$result = []; $result = [];
# 获取创建者信息(业务审批) # 获取创建者信息(业务审批)
if (in_array($param['types'], ['crm_contract', 'crm_receivables', 'crm_invoice'])) { if (in_array($param['types'], ['crm_contract', 'crm_receivables', 'crm_invoice', 'jxc_purchase', 'jxc_retreat', 'jxc_sale', 'jxc_salereturn', 'jxc_payment', 'jxc_collection', 'jxc_allocation', 'jxc_inventory'])) {
$model = db($param['types']); $model = db($param['types']);
$primaryKey = null; $primaryKey = null;
if ($param['types'] == 'crm_contract') $primaryKey = 'contract_id'; if ($param['types'] == 'crm_contract') $primaryKey = 'contract_id';
if ($param['types'] == 'crm_receivables') $primaryKey = 'receivables_id'; if ($param['types'] == 'crm_receivables') $primaryKey = 'receivables_id';
if ($param['types'] == 'crm_invoice') $primaryKey = 'invoice_id'; if ($param['types'] == 'crm_invoice') $primaryKey = 'invoice_id';
if ($param['types'] == 'jxc_purchase') $primaryKey = 'purchase_id';
if ($param['types'] == 'jxc_retreat') $primaryKey = 'retreat_id';
if ($param['types'] == 'jxc_sale') $primaryKey = 'sale_id';
if ($param['types'] == 'jxc_salereturn') $primaryKey = 'salereturn_id';
if ($param['types'] == 'jxc_payment') $primaryKey = 'payment_note_id';
if ($param['types'] == 'jxc_collection') $primaryKey = 'collection_note_id';
if ($param['types'] == 'jxc_allocation') $primaryKey = 'allocation_id';
if ($param['types'] == 'jxc_inventory') $primaryKey = 'inventory_id';
$info = $model->field(['create_time', 'owner_user_id'])->where($primaryKey, $param['types_id'])->find(); $info = $model->field(['create_time', 'owner_user_id'])->where($primaryKey, $param['types_id'])->find();
$userInfo = $userModel->getUserById($info['owner_user_id']); $userInfo = $userModel->getUserById($info['owner_user_id']);

@ -180,7 +180,15 @@ class ExamineStep extends Common
case 'crm_contract' : $dataInfo = db('crm_contract')->where(['contract_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break; case 'crm_contract' : $dataInfo = db('crm_contract')->where(['contract_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'crm_receivables' : $dataInfo = db('crm_receivables')->where(['receivables_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break; case 'crm_receivables' : $dataInfo = db('crm_receivables')->where(['receivables_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'crm_invoice': $dataInfo = db('crm_invoice')->where(['invoice_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break; case 'crm_invoice': $dataInfo = db('crm_invoice')->where(['invoice_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
} case 'jxc_purchase': $dataInfo = db('jxc_purchase')->where(['purchase_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'jxc_retreat': $dataInfo = db('jxc_retreat')->where(['retreat_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'jxc_sale': $dataInfo = db('jxc_sale')->where(['sale_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'jxc_salereturn': $dataInfo = db('jxc_salereturn')->where(['salereturn_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'jxc_payment': $dataInfo = db('jxc_payment')->where(['payment_note_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'jxc_collection': $dataInfo = db('jxc_collection')->where(['collection_note_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'jxc_inventory': $dataInfo = db('jxc_inventory')->where(['inventory_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
case 'jxc_allocation': $dataInfo = db('jxc_allocation')->where(['allocation_id' => intval($types_id)])->field('create_user_id,owner_user_id,check_user_id,flow_id,order_id,check_status,update_time')->find(); break;
}
$stepInfo = []; $stepInfo = [];
if ($dataInfo['flow_id'] && !in_array($dataInfo['check_status'],['5'])) { if ($dataInfo['flow_id'] && !in_array($dataInfo['check_status'],['5'])) {
//固定审批流 //固定审批流

@ -399,15 +399,15 @@ class Excel extends Common
} }
// 排队中 // 排队中
if (!$queue->canExec()) { // if (!$queue->canExec()) {
return resultArray([ // return resultArray([
'data' => [ // 'data' => [
'page' => -2, // 'page' => -2,
'export_queue_index' => $export_queue_index, // 'export_queue_index' => $export_queue_index,
'info' => $queue->error // 'info' => $queue->error
] // ]
]); // ]);
} // }
// 没有临时文件名,代表第一次导出,生成临时文件名称,并写入表头数据 // 没有临时文件名,代表第一次导出,生成临时文件名称,并写入表头数据
if ($temp_file === null) { if ($temp_file === null) {
@ -468,7 +468,7 @@ class Excel extends Common
if (is_numeric($val[$rule['field']]) && strlen($val[$rule['field']]) > 15) { if (is_numeric($val[$rule['field']]) && strlen($val[$rule['field']]) > 15) {
$val[$rule['field']] = "\t" . $val[$rule['field']] . "\t"; $val[$rule['field']] = "\t" . $val[$rule['field']] . "\t";
} }
$rows[] = $fieldModel->getValueByFormtype($val[$rule['field']], $rule['form_type']); $rows[] = $fieldModel->getValueByFormtype($val[$rule['field']], $rule['form_type'],$val);
} }
} }
fputcsv($fp, $rows); fputcsv($fp, $rows);
@ -519,11 +519,7 @@ class Excel extends Common
$queue->dequeue(); $queue->dequeue();
return false; return false;
} }
if (!empty($param['pool_id'])) { $user_id = $param['create_user_id'];
$user_id = $param['create_user_id'];
} else {
$user_id = $param['owner_user_id'];
}
// 采用伪队列 允许三人同时导入数据 // 采用伪队列 允许三人同时导入数据
$queue = new Queue(self::IMPORT_QUEUE, 50000000); $queue = new Queue(self::IMPORT_QUEUE, 50000000);
$import_queue_index = input('import_queue_index'); $import_queue_index = input('import_queue_index');
@ -687,6 +683,7 @@ class Excel extends Common
$fieldModel = new \app\admin\model\Field(); $fieldModel = new \app\admin\model\Field();
$fieldParam['types'] = $types; $fieldParam['types'] = $types;
$fieldParam['action'] = 'excel'; $fieldParam['action'] = 'excel';
if (!empty($param['pool_id'])) { if (!empty($param['pool_id'])) {
$list = []; $list = [];
$field_list = db('crm_customer_pool_field_setting')->where(['pool_id' => $param['pool_id'], 'is_hidden' => 0, $field_list = db('crm_customer_pool_field_setting')->where(['pool_id' => $param['pool_id'], 'is_hidden' => 0,
@ -765,6 +762,7 @@ class Excel extends Common
} }
} }
} }
// 每次导入条数 // 每次导入条数
$page_size = 100; $page_size = 100;
@ -812,6 +810,7 @@ class Excel extends Common
'update_time' => time(), 'update_time' => time(),
]; ];
} }
if ($temp !== count($field_list)) { if ($temp !== count($field_list)) {
@unlink($save_path); @unlink($save_path);
$queue->dequeue(); $queue->dequeue();
@ -920,7 +919,7 @@ class Excel extends Common
$userId = db('admin_user')->where('realname', $val[2])->value('id'); $userId = db('admin_user')->where('realname', $val[2])->value('id');
$data['owner_user_id'] = $userId ?: 0; $data['owner_user_id'] = $userId ?: 0;
} }
$owner = db('crm_customer_pool')->where(['pool_id' => $param['pool_id']])->value('admin_user_ids'); $owner = db('crm_customer_pool')->where(['pool_id' => $param['pool_id']])->value('user_ids');
$auth = db('admin_access')->where('user_id', $param['create_user_id'])->column('group_id'); $auth = db('admin_access')->where('user_id', $param['create_user_id'])->column('group_id');
// 数据重复时 // 数据重复时
if ($old_data_id_list) { if ($old_data_id_list) {
@ -933,11 +932,7 @@ class Excel extends Common
$up_success_count = 0; $up_success_count = 0;
foreach ($old_data_id_list as $id) { foreach ($old_data_id_list as $id) {
if ($types == 'crm_customer' && !empty($param['pool_id'])) { if ($types == 'crm_customer' && !empty($param['pool_id'])) {
if (!in_array($param['create_user_id'], trim(stringToArray($owner), ',')) && !in_array(1, $auth) && $param['create_user_id'] != 1) { if (!in_array($param['create_user_id'], trim(stringToArray($owner), ',')) && $param['create_user_id'] != 1) {
$temp_error = '当前导入人员对该公海数据,无导入权限';
$error_data_func($val, $temp_error);
break;
} else {
if (!$dataModel->updateDataById($data, $id)) { if (!$dataModel->updateDataById($data, $id)) {
$temp_error = $dataModel->getError(); $temp_error = $dataModel->getError();
if ($temp_error == '无权操作') { if ($temp_error == '无权操作') {
@ -947,6 +942,10 @@ class Excel extends Common
$dataModel->rollback(); $dataModel->rollback();
break; break;
} }
break;
} else {
$temp_error = '当前导入人员对该公海数据,无导入权限';
$error_data_func($val, $temp_error);
} }
} else { } else {
if (!$dataModel->updateDataById($data, $id)) { if (!$dataModel->updateDataById($data, $id)) {
@ -985,15 +984,16 @@ class Excel extends Common
} }
} else { } else {
if ($types == 'crm_customer' && !empty($param['pool_id'])) { if ($types == 'crm_customer' && !empty($param['pool_id'])) {
if (!in_array($param['create_user_id'], trim(stringToArray($owner), ',')) && !in_array(1, $auth) && $param['create_user_id'] != 1) { if (!in_array($param['create_user_id'], trim(stringToArray($owner), ',')) && $param['create_user_id'] != 1) {
$temp_error = '当前导入人员对该公海数据,无导入权限';
$error_data_func($val, $temp_error);
} else {
$data = array_merge($data, $default_data); $data = array_merge($data, $default_data);
$data['excel'] = 1; $data['excel'] = 1;
if (!$resData = $dataModel->createData($data)) { if (!$resData = $dataModel->createData($data)) {
$error_data_func($val, $dataModel->getError()); $error_data_func($val, $dataModel->getError());
} }
} else {
$temp_error = '当前导入人员对该公海数据,无导入权限';
$error_data_func($val, $temp_error);
} }
} else { } else {
$data = array_merge($data, $default_data); $data = array_merge($data, $default_data);
@ -2013,7 +2013,7 @@ class Excel extends Common
} }
// 开始行 +2 跳过表头 // 开始行 +2 跳过表头
$start_row = ($page - 1) * $page_size + 2; $start_row = ($page - 1) * $page_size + 3;
// 结束行 // 结束行
$end_row = $start_row + $page_size - 1; $end_row = $start_row + $page_size - 1;
if ($end_row > $max_row) { if ($end_row > $max_row) {
@ -2032,10 +2032,14 @@ class Excel extends Common
]; ];
// 开始导入数据 // 开始导入数据
foreach ($dataList as $val) { foreach ($dataList as $val) {
$data = [];
$empty_count = 0;
$not_null_field = [];
$fk = 0;
foreach ($field_list as $field) { foreach ($field_list as $field) {
$temp_value = trim($val[$fk]); $temp_value = trim($val[$fk]);
// 特殊字段特殊处理 // 特殊字段特殊处理
$temp_value = $this->handleData($temp_value, $field); // $temp_value = $this->handleData($temp_value, $field);
$data[$field['field']] = $temp_value; $data[$field['field']] = $temp_value;
if ($temp_value == '') { if ($temp_value == '') {
if ($field['is_null']) { if ($field['is_null']) {
@ -2053,8 +2057,6 @@ class Excel extends Common
$error_data_func($val, '空行'); $error_data_func($val, '空行');
continue; continue;
} }
$data = [];
$fk = 0;
$classData = db('work_task_class')->where(['name' => $val[6], 'work_id' => $param['work_id']])->order('class_id', 'asc')->select(); $classData = db('work_task_class')->where(['name' => $val[6], 'work_id' => $param['work_id']])->order('class_id', 'asc')->select();
$max_order_id = db('work_task_class')->where(['work_id' => $param['work_id'], 'status' => 1])->max('order_id'); $max_order_id = db('work_task_class')->where(['work_id' => $param['work_id'], 'status' => 1])->max('order_id');
if ($classData[0]['class_id'] != '') { if ($classData[0]['class_id'] != '') {
@ -2071,7 +2073,6 @@ class Excel extends Common
$data['class_id'] = db('work_task_class')->insertGetId($item); $data['class_id'] = db('work_task_class')->insertGetId($item);
} }
$dataModel = new \app\work\model\Task(); $dataModel = new \app\work\model\Task();
$data = array_merge($data, $default_data); $data = array_merge($data, $default_data);
if (!$resData = $dataModel->createTask($data)) { if (!$resData = $dataModel->createTask($data)) {
$error_data_func($val, $dataModel->getError()); $error_data_func($val, $dataModel->getError());
@ -2445,7 +2446,7 @@ class Excel extends Common
$this->batchTaskImportData('', $excelData); $this->batchTaskImportData('', $excelData);
} elseif ($base == 'ActivityImport') { } elseif ($base == 'ActivityImport') {
$this->ActivityImport('', $excelData); $this->ActivityImport('', $excelData);
} else { } elseif($base == 'batchImportData') {
$this->batchImportData('', $excelData); $this->batchImportData('', $excelData);
} }
$data = 0; $data = 0;

File diff suppressed because it is too large Load Diff

@ -40,7 +40,19 @@ class File extends Common
'crm_invoice', 'crm_invoice',
'crm_activity', 'crm_activity',
'crm_visit', 'crm_visit',
'crm_receivables' 'crm_receivables',
'jxc_product',
'jxc_supplier',
'jxc_purchase',
'jxc_retreat',
'jxc_sale',
'jxc_salereturn',
'jxc_receipt',
'jxc_outbound',
'jxc_payment',
'jxc_collection',
'jxc_inventory',
'jxc_allocation'
]; ];
/** /**
@ -135,6 +147,18 @@ class File extends Common
case 'crm_activity': $r = db('crm_activity_file'); $r_name = 'activity_id'; break; case 'crm_activity': $r = db('crm_activity_file'); $r_name = 'activity_id'; break;
case 'crm_visit': $r = db('crm_visit_file'); $r_name = 'visit_id'; break; case 'crm_visit': $r = db('crm_visit_file'); $r_name = 'visit_id'; break;
case 'crm_receivables': $r = db('crm_receivables_file'); $r_name = 'receivables_id'; break; case 'crm_receivables': $r = db('crm_receivables_file'); $r_name = 'receivables_id'; break;
case 'jxc_product': $r = db('jxc_product_file'); $r_name = 'product_id'; break;
case 'jxc_supplier': $r = db('jxc_supplier_file'); $r_name = 'supplier_id'; break;
case 'jxc_purchase': $r = db('jxc_purchase_file'); $r_name = 'purchase_id'; break;
case 'jxc_retreat': $r = db('jxc_retreat_file'); $r_name = 'retreat_id'; break;
case 'jxc_sale': $r = db('jxc_sale_file'); $r_name = 'sale_id'; break;
case 'jxc_salereturn': $r = db('jxc_salereturn_file'); $r_name = 'salereturn_id'; break;
case 'jxc_receipt': $r = db('jxc_receipt_file'); $r_name = 'receipt_id'; break;
case 'jxc_outbound': $r = db('jxc_outbound_file'); $r_name = 'outbound_id'; break;
case 'jxc_payment': $r = db('jxc_payment_file'); $r_name = 'payment_note_id'; break;
case 'jxc_collection': $r = db('jxc_collection_file'); $r_name = 'collection_note_id'; break;
case 'jxc_inventory': $r = db('jxc_inventory_file'); $r_name = 'inventory_id'; break;
case 'jxc_allocation': $r = db('jxc_allocation_file'); $r_name = 'allocation_id'; break;
default : break; default : break;
} }
$rData = []; $rData = [];
@ -293,6 +317,18 @@ class File extends Common
case 'crm_activity' : $r = db('crm_activity_file'); $module = db('crm_activity'); break; case 'crm_activity' : $r = db('crm_activity_file'); $module = db('crm_activity'); break;
case 'crm_visit' : $r = db('crm_visit_file'); $module = db('crm_visit'); break; case 'crm_visit' : $r = db('crm_visit_file'); $module = db('crm_visit'); break;
case 'crm_receivables' : $r = db('crm_receivables_file'); $module = db('crm_receivables'); break; case 'crm_receivables' : $r = db('crm_receivables_file'); $module = db('crm_receivables'); break;
case 'jxc_product' : $r = db('jxc_product_file'); $module = db('jxc_product'); break;
case 'jxc_supplier' : $r = db('jxc_supplier_file'); $module = db('jxc_supplier'); break;
case 'jxc_purchase' : $r = db('jxc_purchase_file'); $module = db('jxc_purchase'); break;
case 'jxc_retreat' : $r = db('jxc_retreat_file'); $module = db('jxc_retreat'); break;
case 'jxc_sale' : $r = db('jxc_sale_file'); $module = db('jxc_sale'); break;
case 'jxc_salereturn' : $r = db('jxc_salereturn_file'); $module = db('jxc_salereturn'); break;
case 'jxc_receipt' : $r = db('jxc_receipt_file'); $module = db('jxc_receipt'); break;
case 'jxc_outbound' : $r = db('jxc_outbound_file'); $module = db('jxc_outbound'); break;
case 'jxc_payment' : $r = db('jxc_payment_file'); $module = db('jxc_payment'); break;
case 'jxc_collection' : $r = db('jxc_collection_file'); $module = db('jxc_collection'); break;
case 'jxc_inventory' : $r = db('jxc_inventory_file'); $module = db('jxc_inventory'); break;
case 'jxc_allocation' : $r = db('jxc_allocation_file'); $module = db('jxc_allocation'); break;
default : break; default : break;
} }
if ($r) { if ($r) {
@ -526,6 +562,43 @@ class File extends Common
case 'crm_receivables' : case 'crm_receivables' :
$r = db('crm_receivables_file'); $r = db('crm_receivables_file');
$r_name = 'receivables_id'; $r_name = 'receivables_id';
case 'jxc_product' :
$r = db('jxc_product_file');
$r_name = 'product_id';
case 'jxc_supplier' :
$r = db('jxc_supplier_file');
$r_name = 'supplier_id';
case 'jxc_purchase' :
$r = db('jxc_purchase_file');
$r_name = 'purchase_id';
case 'jxc_retreat' :
$r = db('jxc_retreat_file');
$r_name = 'retreat_id';
case 'jxc_sale' :
$r = db('jxc_sale_file');
$r_name = 'sale_id';
case 'jxc_salereturn':
$r = db('jxc_salereturn_file');
$r_name = 'salereturn_id';
case 'jxc_receipt' :
$r = db('jxc_receipt_file');
$r_name = 'receipt_id';
case 'jxc_outbound' :
$r = db('jxc_outbound_file');
$r_name = 'outbound_id';
case 'jxc_inventory' :
$r = db('jxc_inventory_file');
$r_name = 'inventory_id';
case 'jxc_allocation' :
$r = db('jxc_allocation_file');
$r_name = 'allocation_id';
case 'jxc_collection' :
$r = db('jxc_collection_file');
$r_name = 'collection_note_id';
case 'jxc_payment' :
$r = db('jxc_payment_file');
$r_name = 'payment_note_id';
default : break; default : break;
} }
$rWhere = []; $rWhere = [];

@ -74,7 +74,7 @@ class LoginRecord extends Common
$data['address'] = $ip_address['country']; $data['address'] = $ip_address['country'];
// 效果图有这个备注字段不知道存啥就把UA记录了一下 // 效果图有这个备注字段不知道存啥就把UA记录了一下
$data['remark'] = $_SERVER['HTTP_USER_AGENT']; // $data['remark'] = $_SERVER['HTTP_USER_AGENT'];
$this->save($data); $this->save($data);
} }

@ -169,6 +169,103 @@ class Message extends Common
* 移除队成员 * 移除队成员
*/ */
const TEAM_LEADS = 32; const TEAM_LEADS = 32;
/**
* 采购单待审批
*/
const PURCHASE_TO_DO = 33;
/**
* 采购单审批驳回
*/
const PURCHASE_REJECT = 34;
/**
* 采购单审批通过
*/
const PURCHASE_PASS = 35;
/**
* 采购退货单待审批
*/
const RETREAT_TO_DO = 36;
/**
* 采购退货单审批驳回
*/
const RETREAT_REJECT = 37;
/**
* 采购退货单审批通过
*/
const RETREAT_PASS = 38;
/**
* 销售订单待审批
*/
const SALE_TO_DO = 39;
/**
* 销售订单审批驳回
*/
const SALE_REJECT = 40;
/**
* 销售订单审批通过
*/
const SALE_PASS = 41;
/**
* 销售退货单待审批
*/
const SALERETURN_TO_DO = 42;
/**
* 销售退货单审批驳回
*/
const SALERETURN_REJECT = 43;
/**
* 销售退货单审批通过
*/
const SALERETURN_PASS = 44;
/**
* 回款单待审批
*/
const COLLECTION_TO_DO = 45;
/**
* 回款单审批驳回
*/
const COLLECTION_REJECT = 46;
/**
* 回款单审批通过
*/
const COLLECTION_PASS = 47;
/**
* 付款单待审批
*/
const PAYMENT_TO_DO = 48;
/**
* 付款单审批驳回
*/
const PAYMENT_REJECT = 49;
/**
* 付款单审批通过
*/
const PAYMENT_PASS = 50;
/**
* 调拨待审批
*/
const ALLOCATION_TO_DO = 51;
/**
* 调拨审批驳回
*/
const ALLOCATION_REJECT = 52;
/**
* 调拨审批通过
*/
const ALLOCATION_PASS = 53;
/**
* 盘点待审批
*/
const INVENTORY_TO_DO = 54;
/**
* 盘点审批驳回
*/
const INVENTORY_REJECT = 55;
/**
* 盘点审批通过
*/
const INVENTORY_PASS = 56;
/** /**
* 消息类型 * 消息类型
* *
@ -326,6 +423,32 @@ class Message extends Common
self::BUSINESS_PASS, self::BUSINESS_PASS,
self::CUSTOMER_PASS, self::CUSTOMER_PASS,
self::CONTRACT_END, self::CONTRACT_END,
],
'jxc' => [
self::PURCHASE_TO_DO,
self::PURCHASE_REJECT,
self::PURCHASE_PASS,
self::RETREAT_TO_DO,
self::RETREAT_REJECT,
self::RETREAT_PASS,
self::SALE_TO_DO,
self::SALE_REJECT,
self::SALE_PASS,
self::SALERETURN_TO_DO,
self::SALERETURN_REJECT,
self::SALERETURN_PASS,
self::COLLECTION_TO_DO,
self::COLLECTION_REJECT,
self::COLLECTION_PASS,
self::PAYMENT_TO_DO,
self::PAYMENT_REJECT,
self::PAYMENT_PASS,
self::ALLOCATION_TO_DO,
self::ALLOCATION_REJECT,
self::ALLOCATION_PASS,
self::INVENTORY_TO_DO,
self::INVENTORY_REJECT,
self::INVENTORY_PASS,
] ]
]; ];
@ -468,6 +591,54 @@ class Message extends Common
case self::BUSINESS_PASS: case self::BUSINESS_PASS:
return BusinessModel::where(['business_id' => $data['action_id']])->value('name') ?: ''; return BusinessModel::where(['business_id' => $data['action_id']])->value('name') ?: '';
// 采购单
case self::PURCHASE_TO_DO:
case self::PURCHASE_REJECT:
case self::PURCHASE_PASS:
return PurchaseModel::where(['purchase_id' => $data['action_id']])->value('order_number') ?: '';
// 采购退货单
case self::RETREAT_TO_DO:
case self::RETREAT_REJECT:
case self::RETREAT_PASS:
return RetreatModel::where(['retreat_id' => $data['action_id']])->value('order_number') ?: '';
// 销售订单
case self::SALE_TO_DO:
case self::SALE_REJECT:
case self::SALE_PASS:
return SaleModel::where(['sale_id' => $data['action_id']])->value('order_number') ?: '';
// 销售退货单订单
case self::SALERETURN_TO_DO:
case self::SALERETURN_REJECT:
case self::SALERETURN_PASS:
return SalereturnModel::where(['salereturn_id' => $data['action_id']])->value('order_number') ?: '';
// 回款单
case self::COLLECTION_TO_DO:
case self::COLLECTION_REJECT:
case self::COLLECTION_PASS:
return CollectionModel::where(['collection_note_id' => $data['action_id']])->value('collection_no') ?: '';
// 付款单
case self::PAYMENT_TO_DO:
case self::PAYMENT_REJECT:
case self::PAYMENT_PASS:
return PaymentModel::where(['payment_note_id' => $data['action_id']])->value('payment_no') ?: '';
// 调拨
case self::ALLOCATION_TO_DO:
case self::ALLOCATION_REJECT:
case self::ALLOCATION_PASS:
return PaymentModel::where(['allocation_id' => $data['action_id']])->value('allocation_code') ?: '';
// 盘点
case self::INVENTORY_TO_DO:
case self::INVENTORY_REJECT:
case self::INVENTORY_PASS:
return PaymentModel::where(['inventory_id' => $data['action_id']])->value('inventory_number') ?: '';
} }
return ''; return '';

@ -21,7 +21,7 @@ class Scene extends Common
protected $updateTime = false; protected $updateTime = false;
protected $autoWriteTimestamp = true; protected $autoWriteTimestamp = true;
private $types_arr = ['crm_leads','crm_customer','crm_customer_pool','crm_contacts','crm_product','crm_business','crm_contract','crm_receivables','crm_visit','crm_invoice']; //支持场景的分类 private $types_arr = ['crm_leads','crm_customer','crm_customer_pool','crm_contacts','crm_product','crm_business','crm_contract','crm_receivables','crm_visit','crm_invoice', 'jxc_product', 'jxc_supplier', 'jxc_purchase', 'jxc_retreat', 'jxc_sale', 'jxc_salereturn', 'jxc_receipt', 'jxc_outbound', 'jxc_payment', 'jxc_collection', 'jxc_inventory', 'jxc_allocation']; //支持场景的分类
protected $type = [ protected $type = [
'data' => 'array', 'data' => 'array',
@ -467,6 +467,7 @@ class Scene extends Common
$map['is_end'] = ['condition' => 'is', 'value' => [2], 'form_type' => 'text']; $map['is_end'] = ['condition' => 'is', 'value' => [2], 'form_type' => 'text'];
break; break;
case 'star' : case 'star' :
# 我的关注
$where = $this->getStarParam($types, $user_id); $where = $this->getStarParam($types, $user_id);
if (!empty($where)) $map = $where; if (!empty($where)) $map = $where;
break; break;
@ -482,11 +483,79 @@ class Scene extends Common
# 下架的产品 # 下架的产品
$map['status'] = ['condition' => 'is', 'value' => ['下架'], 'form_type' => 'select', 'name' => '是否上架', 'type' => 'status']; $map['status'] = ['condition' => 'is', 'value' => ['下架'], 'form_type' => 'select', 'name' => '是否上架', 'type' => 'status'];
break; break;
case 'jxc_put_on_shelves' :
# 上架的产品
$map['product_ishelf'] = ['condition' => 'is', 'value' => ['上架'], 'form_type' => 'select', 'name' => '是否上架', 'type' => 'product_ishelf'];
break;
case 'jxc_pull_off_shelves' :
# 下架的产品
$map['product_ishelf'] = ['condition' => 'is', 'value' => ['下架'], 'form_type' => 'select', 'name' => '是否上架', 'type' => 'product_ishelf'];
break;
default : default :
# 全部 # 全部
$auth_user_ids = ''; $auth_user_ids = '';
} }
if($types=='receivables_plan'){
switch ($bydata) {
case 'me' :
# 我负责的
$auth_user_ids[] = $user_id;
break;
case 'sub' :
# 下属负责的
$auth_user_ids = getSubUserId(false, 0, $user_id) ? : ['-1'];
break;
case 'all' :
# 全部
$auth_user_ids = '';
break;
case 'not' :
# 全部未回款
$map['status'] = ['neq',1];
break;
case 'not_overdue' :
# 全部逾期未回款
// $map['status'] =array(['neq',1],['neq',4],'or');
$map['status'] =['neq',1];
$map['return_date'] = ['lt',time()];
break;
case 'not_moth' :
# 本月到期未回款
$timeAry = ByDateTime('month');
$map['status'] =['neq',1];
$map['return_date'] = ['between',[$timeAry[0],$timeAry[1]]];
break;
case 'not_week' :
# 本周到期未回款
$timeAry = ByDateTime('week');
$map['status'] =['neq',1];
$map['return_date'] = ['between',[$timeAry[0],$timeAry[1]]];
break;
case 'complete' :
# 已回款
$map['status'] =['eq',1];
break;
case 'complete_moth' :
# 本月已回款
$timeAry = ByDateTime('month');
$map['status'] =['eq',1];
$map['return_date'] = ['between',[$timeAry[0],$timeAry[1]]];
break;
case 'complete_week' :
# 本周已回款
$timeAry = ByDateTime('week');
$map['status'] =['eq',1];
$map['return_date'] = ['between',[$timeAry[0],$timeAry[1]]]; break;
case 'complete_part' :
# 部分已回
$map['status'] = ['eq',2];
break;
default :
# 全部
$auth_user_ids = '';
}
}
$auth_user_ids = $auth_user_ids ? : []; $auth_user_ids = $auth_user_ids ? : [];
if ($auth_user_ids) { if ($auth_user_ids) {

@ -28,18 +28,30 @@ class Structure extends Common
{ {
$cat = new \com\Category('admin_structure', array('id', 'pid', 'name', 'title')); $cat = new \com\Category('admin_structure', array('id', 'pid', 'name', 'title'));
$data = $cat->getList('', 0, 'id'); $data = $cat->getList('', 0, 'id');
foreach ($data as $k=>$v){
$data[$k]['owner_user_name']=foreachData('admin_structure',$v['owner_user_id'])?:null;
//选择部门传入当前部门权限范围内的员工
$data[$k]['user_id']=$this->getSubUserByStructrue($v['id']);
}
// 若type为tree则返回树状结构 // 若type为tree则返回树状结构
if ($type == 'tree') { if ($type == 'tree') {
$tree = new \com\Tree(); $tree = new \com\Tree();
$data = $tree->list_to_tree($data, 'id', 'pid', 'child', 0, true, array('')); $data = $tree->list_to_tree($data, 'id', 'pid', 'child', 0, true, array(''));
} }
foreach ($data as $k=>$v){
$data[$k]['owner_user_name']=foreachData('admin_structure',$v['owner_user_id'])?:null;
}
return $data; return $data;
} }
//获取部门下权限范围内员工
public function getSubUserByStructrue($param)
{
$userModel = model('User');
$structureList = $userModel->getSubUserByStr($param, 1);
if ($param) {
$where['id'] = ['in', $structureList];
}
$list = Db::name('AdminUser')->field('id,realname')->where($where)->select();
$list = $list ?: array();
return $list;
}
/* /*
*根据字符串展示参与部门 use by work *根据字符串展示参与部门 use by work
*add by yykun *add by yykun

@ -80,6 +80,12 @@ class User extends Common
'name' => '岗位', 'name' => '岗位',
'form_type' => 'text', 'form_type' => 'text',
'is_null' => 0, 'is_null' => 0,
],
[
'field' => 'department',
'name' => '部门',
'form_type' => 'text',
'is_null' => 1,
] ]
]; ];
@ -274,7 +280,18 @@ class User extends Common
$temp[$val['field']] = $param[$val['field']]; $temp[$val['field']] = $param[$val['field']];
} }
$param = $temp; $param = $temp;
$param['structure_id'] = 0; $department=explode('/',$param['department']);
$pid=1;
foreach ($department as $k => $v){
$structure=db('admin_structure')->where('name',$v)->find();
if(empty($structure)){
$id=db('admin_structure')->insertGetId(['name'=>$v,'pid'=>$pid]);
$pid=$id;
}else{
$pid=$structure['id'];
}
}
$param['structure_id'] = $pid;
if (db('admin_user')->where('username', $param['username'])->find()) { if (db('admin_user')->where('username', $param['username'])->find()) {
$this->error = '手机号已存在'; $this->error = '手机号已存在';
return false; return false;
@ -457,6 +474,18 @@ class User extends Common
} }
$param['realname'] = $name; $param['realname'] = $name;
} }
$department=explode('/',$param['department']);
$pid=1;
foreach ($department as $k => $v){
$structure=db('admin_structure')->where('name',$v)->find();
if(empty($structure)){
$id=db('admin_structure')->insertGetId(['name'=>$v,'pid'=>$pid]);
$pid=$id;
}else{
$pid=$structure['id'];
}
}
$param['structure_id'] = $pid;
$param['userId']=!empty($param['create_user_id'])?:$param['owner_user_id']; $param['userId']=!empty($param['create_user_id'])?:$param['owner_user_id'];
unset($param['owner_user_id']); unset($param['owner_user_id']);
unset($param['create_user_id']); unset($param['create_user_id']);
@ -755,7 +784,11 @@ class User extends Common
if ($v['name'] == 'market') { if ($v['name'] == 'market') {
$rules[$k]['name'] = 'activityForm'; $rules[$k]['name'] = 'activityForm';
} }
if($v['name'] == 'warehouseProduct'){
$rules[$k]['name'] = 'warehouseProduct';
}
} }
// p($rules);die();
//菜单管理(弃用) //菜单管理(弃用)
// $menuMap['status'] = 1; // $menuMap['status'] = 1;
// $menuMap['rule_id'] = array('in',$newRuleIds); // $menuMap['rule_id'] = array('in',$newRuleIds);
@ -765,6 +798,7 @@ class User extends Common
$tree = new \com\Tree(); $tree = new \com\Tree();
//处理规则成树状 //处理规则成树状
$rulesList = $tree->list_to_tree($rules, 'id', 'pid', 'child', 0, true, array('pid')); $rulesList = $tree->list_to_tree($rules, 'id', 'pid', 'child', 0, true, array('pid'));
//权限数组 //权限数组
$authList = rulesListToArray($rulesList, $newRuleIds); $authList = rulesListToArray($rulesList, $newRuleIds);
//应用控制 //应用控制
@ -817,6 +851,11 @@ class User extends Common
if (in_array('calendar', $adminConfig)) { if (in_array('calendar', $adminConfig)) {
$authList['oa']['calendar'] = (object)[]; $authList['oa']['calendar'] = (object)[];
} }
# 进销存
if (in_array('jxc', $adminConfig)) {
$authList['jxc']['field'] = (object)[];
$authList['jxc']['params'] = (object)[];
}
# 公海权限 # 公海权限
$structureId = db('admin_user')->where('id', $u_id)->value('structure_id'); $structureId = db('admin_user')->where('id', $u_id)->value('structure_id');
$poolStatus = db('crm_customer_pool')->where('status', 1)->where(function ($requery) use ($u_id, $structureId, $adminTypes) { $poolStatus = db('crm_customer_pool')->where('status', 1)->where(function ($requery) use ($u_id, $structureId, $adminTypes) {
@ -825,8 +864,9 @@ class User extends Common
if (!in_array(1, $adminTypes)) $requery->whereOr('department_ids', 'like', '%,' . $structureId . ',%'); if (!in_array(1, $adminTypes)) $requery->whereOr('department_ids', 'like', '%,' . $structureId . ',%');
})->value('pool_id'); })->value('pool_id');
if (!empty($poolStatus)) $authList['crm']['pool'] = ['index' => true]; if (!empty($poolStatus)) $authList['crm']['pool'] = ['index' => true];
$ret['authList'] = $this->resetAuthorityFiled($authList); $ret['authList'] = $this->resetAuthorityFiled($authList);
$res['manage'] = $rules; $res['manage'] = $rules;
return $ret; return $ret;
} }
@ -988,7 +1028,11 @@ class User extends Common
$authList['email'] = (object)[]; $authList['email'] = (object)[];
$authList['hrm'] = (object)[]; $authList['hrm'] = (object)[];
$authList['jxc'] = (object)[]; // $authList['jxc'] = (object)[];
# jxc
$authList['manage']['jxc']['field'] = true;
$authList['manage']['jxc']['params'] = true;
$authList['knowledge'] = (object)[]; $authList['knowledge'] = (object)[];
return $authList; return $authList;
@ -1084,6 +1128,7 @@ class User extends Common
*/ */
public function getSubUserByStr($structure_id, $type = 1) public function getSubUserByStr($structure_id, $type = 1)
{ {
// p($structure_id);die;
$allStrIds = (array)$structure_id; $allStrIds = (array)$structure_id;
if ($type == 2) { if ($type == 2) {
$structureModel = new \app\admin\model\Structure(); $structureModel = new \app\admin\model\Structure();
@ -1433,10 +1478,12 @@ class User extends Common
foreach ($ids as $v) { foreach ($ids as $v) {
$data['id'] = $v; $data['id'] = $v;
$data['structure_id'] = $param['structure_id']; $data['structure_id'] = $param['structure_id'];
$flag = foreachData('', $data); $flag=$this->isUpdate(true)->save($data);
// $flag = foreachData('', $data);
// p(Db::name('AdminUser')->getLastSql());
} }
if ($flag) { if ($flag!==false) {
return $flag; return 1;
} else { } else {
$this->error = '修改失败,请稍后重试'; $this->error = '修改失败,请稍后重试';
return false; return false;

@ -2,6 +2,7 @@
/** /**
* 字段验证(线索、客户、联系人、商机、合同、回款、回访、产品、办公审批) * 字段验证(线索、客户、联系人、商机、合同、回款、回访、产品、办公审批)
*/ */
namespace app\admin\traits; namespace app\admin\traits;
trait FieldVerificationTrait trait FieldVerificationTrait
@ -15,9 +16,9 @@ trait FieldVerificationTrait
* @param string $types 自定义表栏目类型crm_leads、crm_customer ... * @param string $types 自定义表栏目类型crm_leads、crm_customer ...
* @param int $dataId 编辑时相应的模块数据的ID * @param int $dataId 编辑时相应的模块数据的ID
* @param int $typesId 自定义表栏目类型ID * @param int $typesId 自定义表栏目类型ID
* @author fanqi
* @since 2021-05-18
* @return string * @return string
* @since 2021-05-18
* @author fanqi
*/ */
public function fieldDataValidate($param, $types, $userId, $dataId = 0, $typesId = 0) public function fieldDataValidate($param, $types, $userId, $dataId = 0, $typesId = 0)
{ {
@ -28,18 +29,18 @@ trait FieldVerificationTrait
# 查询自定义字段表数据 # 查询自定义字段表数据
$fieldList = $this->getFieldList($types, $typesId); $fieldList = $this->getFieldList($types, $typesId);
# 验证 # 验证
foreach ($fieldList AS $key => $value) { foreach ($fieldList as $key => $value) {
# 字段授权,没有读写权限,跳过验证。 # 字段授权,没有读写权限,跳过验证。
if (!$userLevel && !empty($grantData[$types])) { if (!$userLevel && !empty($grantData[$types])) {
$status = getFieldGrantStatus($value['field'], $grantData[$types]); $status = getFieldGrantStatus($value['field'], $grantData[$types]);
if (empty($status['read']) || (empty($dataId) && empty($status['write']))) continue; if (empty($status['read']) || (empty($dataId) && empty($status['write']))) continue;
} }
# 验证非明细表格字段数据 # 验证非明细表格字段数据
if (!empty($value['is_null']) && !in_array($value['form_type'], ['detail_table', 'boolean_value']) && (isset($param[$value['field']]) && empty($param[$value['field']]))) { if ($value['form_type'] != 'detail_table' && !empty($value['is_null']) && !in_array($value['form_type'], ['detail_table', 'boolean_value']) && (isset($param[$value['field']]) && empty($param[$value['field']]))) {
$error = $value['name'] . '字段不能为空!'; $error = $value['name'] . '字段不能为空!';
break; break;
} }
@ -62,29 +63,27 @@ trait FieldVerificationTrait
break; break;
} }
# 验证明细表格不能为空 # 验证明细表格不能为空
if (!empty($value['is_null']) && $value['form_type'] == 'detail_table' && isset($param[$value['field']]) && empty($param[$value['field']])) { if (!empty($value['is_null']) && $value['form_type'] == 'detail_table' && isset($param[$value['field']]) && empty($param[$value['field']])) {
$error = $value['name'] . '数据不能为空!'; $error = $value['name'] . '数据不能为空!';
} }
# 验证明细表格可以为空,明细表格里的字段不能为空的情况。 # 验证明细表格可以为空,明细表格里的字段不能为空的情况。
if ($value['form_type'] == 'detail_table') { if ($value['form_type'] == 'detail_table') {
foreach ($param[$value['field']] AS $val) { foreach ($param[$value['field']] as $val) {
foreach ($val AS $v) { foreach ($val as $v) {
if (!empty($v['is_null']) && empty($v['is_hidden']) && isset($v['value']) && empty($v['value'])) { if ($v['form_type']!='boolean_value' && !empty($v['is_null']) && empty($v['is_hidden']) && isset($v['value']) && empty($v['value'])) {
$error = $value['name'] . '中的' . $v['name'] . '字段不能为空!'; $error = $value['name'] . '中的' . $v['name'] . '字段不能为空!';
break; break;
} }
} }
} }
} }
if (empty($value['is_unique'])) continue; if (empty($value['is_unique'])) continue;
// 人员、部门、文件、手写签名、描述文字、多选、明细表格跳过验证 // 人员、部门、文件、手写签名、描述文字、多选、明细表格跳过验证
if (in_array($value['form_type'], ['user', 'structure', 'file', 'handwriting_sign', 'desc_text', 'checkbox', 'detail_table'])) continue; if (in_array($value['form_type'], ['file', 'handwriting_sign', 'desc_text', 'checkbox', 'detail_table'])) continue;
$uniqueStatus = false; $uniqueStatus = false;
# 验证唯一性 # 验证唯一性
if ($value['form_type'] == 'date_interval' && !empty($param[$value['field']])) { if ($value['form_type'] == 'date_interval' && !empty($param[$value['field']])) {
// 日期区间 // 日期区间
@ -95,8 +94,15 @@ trait FieldVerificationTrait
} elseif ($value['form_type'] == 'location' && !empty($param[$value['field']])) { } elseif ($value['form_type'] == 'location' && !empty($param[$value['field']])) {
// 定位 // 定位
$uniqueStatus = $this->checkDataUniqueForLocation($types, $value['field'], $param[$value['field']], $dataId); $uniqueStatus = $this->checkDataUniqueForLocation($types, $value['field'], $param[$value['field']], $dataId);
} elseif ($value['form_type'] == 'user' && !empty($param[$value['field']])) {
// 人员
$uniqueStatus = $this->checkDataUniqueForUser($types, $value['field'], $param[$value['field']], $dataId);
} elseif ($value['form_type'] == 'structure' && !empty($param[$value['field']])) {
// 部门
$uniqueStatus = $this->checkDataUniqueForStructure($types, $value['field'], $param[$value['field']], $dataId);
} else { } else {
if (!empty($param[$value['field']])) $uniqueStatus = $this->checkDataUniqueForCommon($types, $value['field'], $param[$value['field']], $dataId); if (!empty($param[$value['field']])) $uniqueStatus = $this->checkDataUniqueForCommon($types, $value['field'], $param[$value['field']], $dataId);
} }
if (!empty($uniqueStatus)) { if (!empty($uniqueStatus)) {
@ -104,7 +110,6 @@ trait FieldVerificationTrait
break; break;
} }
} }
return $error; return $error;
} }
@ -117,9 +122,9 @@ trait FieldVerificationTrait
* @param string $field 字段名称 * @param string $field 字段名称
* @param string $value 字段值 * @param string $value 字段值
* @param int $dataId 更新时传来的数据ID * @param int $dataId 更新时传来的数据ID
* @author fanqi
* @since 2021-05-18
* @return float|mixed|string * @return float|mixed|string
* @since 2021-05-18
* @author fanqi
*/ */
private function checkDataUniqueForCommon($types, $field, $value, $dataId = 0) private function checkDataUniqueForCommon($types, $field, $value, $dataId = 0)
{ {
@ -142,9 +147,9 @@ trait FieldVerificationTrait
* @param string $field 字段名称 * @param string $field 字段名称
* @param array $value 字段值 * @param array $value 字段值
* @param int $dataId 更新时传来的数据ID * @param int $dataId 更新时传来的数据ID
* @author fanqi
* @since 2021-05-18
* @return float|mixed|string * @return float|mixed|string
* @since 2021-05-18
* @author fanqi
*/ */
private function checkDataUniqueForDateInterval($types, $field, $value, $dataId = 0) private function checkDataUniqueForDateInterval($types, $field, $value, $dataId = 0)
{ {
@ -167,9 +172,9 @@ trait FieldVerificationTrait
* @param string $field 字段名称 * @param string $field 字段名称
* @param array $value 字段值 * @param array $value 字段值
* @param int $dataId 更新时传来的数据ID * @param int $dataId 更新时传来的数据ID
* @author fanqi
* @since 2021-05-18
* @return float|mixed|string * @return float|mixed|string
* @since 2021-05-18
* @author fanqi
*/ */
private function checkDataUniqueForPosition($types, $field, $value, $dataId = 0) private function checkDataUniqueForPosition($types, $field, $value, $dataId = 0)
{ {
@ -192,9 +197,9 @@ trait FieldVerificationTrait
* @param string $field 字段名称 * @param string $field 字段名称
* @param array $value 字段值 * @param array $value 字段值
* @param int $dataId 更新时传来的数据ID * @param int $dataId 更新时传来的数据ID
* @author fanqi
* @since 2021-05-18
* @return float|mixed|string * @return float|mixed|string
* @since 2021-05-18
* @author fanqi
*/ */
private function checkDataUniqueForLocation($types, $field, $value, $dataId = 0) private function checkDataUniqueForLocation($types, $field, $value, $dataId = 0)
{ {
@ -210,46 +215,69 @@ trait FieldVerificationTrait
return db($types)->where($where)->value($primaryKey); return db($types)->where($where)->value($primaryKey);
} }
// /** /**
// * 验证唯一性(部门) * 验证唯一性(部门)
// * *
// * @param string $types 栏目类型 * @param string $types 栏目类型
// * @param string $field 字段名称 * @param string $field 字段名称
// * @param string $value 字段值 * @param string $value 字段值
// * @param int $dataId 更新时传来的数据ID * @param int $dataId 更新时传来的数据ID
// * @author fanqi * @return float|mixed|string
// * @since 2021-05-18 * @since 2021-05-18
// * @return float|mixed|string * @author fanqi
// */ */
// private function checkDataUniqueForStructure($types, $field, $value, $dataId = 0) private function checkDataUniqueForStructure($types, $field, $value, $dataId = 0)
// { {
// if (empty($value)) return false; if (empty($value)) return false;
//
// # 主键 # 主键
// $primaryKey = getPrimaryKeyName($types); $primaryKey = getPrimaryKeyName($types);
//
// # 查询条件 # 查询条件
// $where[$field] = ',' . $value . ','; $where[$field] = ',' . $value . ',';
// if (!empty($dataId)) $where[$primaryKey] = ['neq', $dataId]; if (!empty($dataId)) $where[$primaryKey] = ['neq', $dataId];
//
// return db($types)->where($where)->value($primaryKey); return db($types)->where($where)->value($primaryKey);
// } }
/**
* @param $types 栏目类型
* @param $field 字段名称
* @param $value 字段值
* @param int $dataId 更新时传来的数据ID
* @return false|float|mixed|string|null
* @since 2021-05-18
* @author fanqi
*/
private function checkDataUniqueForUser($types, $field, $value, $dataId = 0)
{
if (empty($value)) return false;
# 主键
$primaryKey = getPrimaryKeyName($types);
# 查询条件
$where[$field] = ',' . $value . ',';
if (!empty($dataId)) $where[$primaryKey] = ['neq', $dataId];
return db($types)->where($where)->value($primaryKey);
}
/** /**
* 自定义字段列表 * 自定义字段列表
* *
* @param string $types 自定义表栏目类型crm_leads、crm_customer ... * @param string $types 自定义表栏目类型crm_leads、crm_customer ...
* @param int $typesId 自定义表栏目类型ID * @param int $typesId 自定义表栏目类型ID
* @author fanqi
* @since 2021-05-18
* @return bool|\PDOStatement|string|\think\Collection * @return bool|\PDOStatement|string|\think\Collection
* @since 2021-05-18
* @author fanqi
*/ */
private function getFieldList($types, $typesId) private function getFieldList($types, $typesId)
{ {
# 查询条件 # 查询条件
$where = [ $where = [
'types' => $types, 'types' => $types,
'types_id' => $typesId, 'types_id' => $typesId,
'is_hidden' => 0, 'is_hidden' => 0,
'form_type' => ['neq', 'desc_text'] 'form_type' => ['neq', 'desc_text']
]; ];
@ -259,4 +287,5 @@ trait FieldVerificationTrait
return db('admin_field')->field($fields)->where($where)->select(); return db('admin_field')->field($fields)->where($where)->select();
} }
} }

@ -136,7 +136,7 @@ function where_arr($array = [], $m = '', $c = '', $a = '')
//查询自定义字段模块多选字段类型 //查询自定义字段模块多选字段类型
$check_field_arr = []; $check_field_arr = [];
//特殊字段 //特殊字段
//过滤系统参数 //过滤系统参数
$unset_arr = ['page', 'limit', 'order_type', 'order_field']; $unset_arr = ['page', 'limit', 'order_type', 'order_field'];
if (!is_array($array)) { if (!is_array($array)) {
@ -307,13 +307,13 @@ function where_arr($array = [], $m = '', $c = '', $a = '')
} }
} }
} }
# 商机阶段为赢单、输单、无效的值保存在is_end中将status_id改为is_end # 商机阶段为赢单、输单、无效的值保存在is_end中将status_id改为is_end
if (!empty($where['business.status_id']) && in_array($where['business.status_id'][1], [1, 2, 3])) { if (!empty($where['business.status_id']) && in_array($where['business.status_id'][1], [1, 2, 3])) {
$where['business.is_end'] = $where['business.status_id']; $where['business.is_end'] = $where['business.status_id'];
unset($where['business.status_id']); unset($where['business.status_id']);
} }
return $where ?: []; return $where ?: [];
} }
@ -340,6 +340,7 @@ function advancedQuery($param, $m = '', $c = '', $a = '')
'nextQuarter', 'month', 'lastMonth', 'nextMonth', 'week', 'lastWeek', 'nextWeek', 'today', 'nextQuarter', 'month', 'lastMonth', 'nextMonth', 'week', 'lastWeek', 'nextWeek', 'today',
'yesterday', 'tomorrow', 'previous7day', 'previous30day', 'future7day', 'future30day' 'yesterday', 'tomorrow', 'previous7day', 'previous30day', 'future7day', 'future30day'
]; ];
foreach ($param as $key => $value) { foreach ($param as $key => $value) {
// 过滤不能参与搜索的字段类型 // 过滤不能参与搜索的字段类型
if (!empty($value['form_type']) && in_array($value['form_type'], ['file', 'handwriting_sign', 'desc_text', 'detail_table', 'date_interval'])) continue; if (!empty($value['form_type']) && in_array($value['form_type'], ['file', 'handwriting_sign', 'desc_text', 'detail_table', 'date_interval'])) continue;
@ -351,11 +352,11 @@ function advancedQuery($param, $m = '', $c = '', $a = '')
list($c, $key) = advancedQueryParam($c, $key, $value['name']); list($c, $key) = advancedQueryParam($c, $key, $value['name']);
if ($key == 'check_status' && !is_array($value)) $result[$c . $key] = $value; if ($key == 'check_status' && !is_array($value)) $result[$c . $key] = $value;
if ($key == 'status_id' && !is_array($value)) $result[$c . $key] = $value; if ($key == 'status_id' && !is_array($value)) $result[$c . $key] = $value;
if ($key == 'customer_id' && !is_array($value)) $result['customer.' . $key] = $value; if ($key == 'customer_id' && !is_array($value)) $result['customer.' . $key] = $value;
if ($key == 'contract_id' && !is_array($value)) $result['contract.' . $key] = $value; if ($key == 'contract_id' && !is_array($value)) $result['contract.' . $key] = $value;
if ($key == 'business_id' && !is_array($value)) $result['business.' . $key] = $value; if ($key == 'business_id' && !is_array($value)) $result['business.' . $key] = $value;
// 仪表盘参数 // 仪表盘参数
if (!empty($value['value'][0]) && empty($value['condition'])) { if (!empty($value['value'][0]) && empty($value['condition'])) {
$value['condition'] = 'is'; $value['condition'] = 'is';
@ -375,43 +376,62 @@ function advancedQuery($param, $m = '', $c = '', $a = '')
$value['type'] = 'check_status'; $value['type'] = 'check_status';
$value['condition'] = 'is'; $value['condition'] = 'is';
} }
if (!empty($value['value'][0]) && in_array($value['value'][0], $betweenType)) {
$value = advancedQueryHandleDate($value);
}
// 代办事项 // 代办事项
if (isset($value) && !isset($value['condition']) && !isset($value['value']) && !isset($value['form_type'])) { if (isset($value) && !isset($value['condition']) && !isset($value['value']) && !isset($value['form_type'])) {
$result[$c . $key] = is_array($value) ? $value : ['in', $value]; $result[$c . $key] = is_array($value) ? $value : ['in', $value];
continue; continue;
} }
// 等于(时间段)类型筛选
if (!empty($value['value'][0]) && in_array($value['value'][0], $betweenType)) {
$value = advancedQueryHandleDate($value);
}
// 创建人、负责人
if (in_array($key, ['create_user_id', 'owner_user_id'])) {
if($value['condition'] == 'contains'){
$result[$c . $key] = ['in', $value['value']];
}else if ($value['condition'] == 'notContains') {
$result[$c . $key] = ['not in', $value['value']];
}else if ($value['condition'] == 'isNull') {
$result[$c . $key] = ['eq', ''];
}else if ($value['condition'] == 'isNotNull') {
$result[$c . $key] = ['neq', ''];
}
}
// 模块、审核状态、成交状态、产品分类、单行文本、多行文本、网址、手机、邮箱、下拉框、布尔值、多选、定位、创建人、负责人 // 模块、审核状态、成交状态、产品分类、单行文本、多行文本、网址、手机、邮箱、下拉框、布尔值、多选、定位、创建人、负责人
if (isset($value['form_type']) && in_array($value['form_type'], ['module', 'check_status', 'deal_status', 'category', 'text', 'textarea', 'mobile', 'email', 'select', 'boolean_value', 'checkbox', 'location', 'website']) || in_array($key, ['create_user_id', 'owner_user_id'])) { 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',])) {
$result[$c . $key] = advancedQueryFormatForCommon($value['value'], $value['condition'], $value['form_type'], $key); $result[$c . $key] = advancedQueryFormatForCommon($value['value'], $value['condition'], $value['form_type'], $key);
} }
// 日期、日期时间、数字、货币、百分数、下次联系时间 // 日期、日期时间、数字、货币、百分数、下次联系时间
if (isset($value['form_type']) && in_array($value['form_type'], ['date', 'datetime', 'number', 'floatnumber', 'percent', 'next_time'])) { if (isset($value['form_type']) && in_array($value['form_type'], ['date', 'datetime', 'number', 'floatnumber', 'percent', 'next_time'])) {
$result[$c . $key] = advancedQueryFormatForDate($value); $result[$c . $key] = advancedQueryFormatForDate($value);
} }
// 地址(固定字段)、地址(自定义字段) // 地址(固定字段)、地址(自定义字段)
if (isset($value['form_type']) && in_array($value['form_type'], ['map_address', 'position'])) { if (isset($value['form_type']) && in_array($value['form_type'], ['map_address', 'position'])) {
$result[$c . $key] = advancedQueryFormatForAddress($value['value'], $value['form_type']); $result[$c . $key] = advancedQueryFormatForAddress($value['value'], $value['form_type']);
} }
// 人员、部门 // 人员、部门
if (isset($value['form_type']) && in_array($value['form_type'], ['user', 'structure', 'single_user']) && !in_array($key, ['create_user_id', 'owner_user_id']) && $value['type'] != 'team_id') { if (isset($value['form_type']) && in_array($value['form_type'], ['user', 'structure', 'single_user']) && !in_array($key, ['create_user_id', 'owner_user_id']) && $value['type'] != 'team_id') {
$result[$c . $key] = advancedQueryFormatForPersonnel($value['value'], $value['condition']); if ($value['type'] == 'owner_structure') { # 所属部门
$userIds = db('admin_user')->whereIn('structure_id', implode(',', $value['value']))->column('id');
$result[$c . 'owner_user_id'] = ['in', $userIds];
} else {
$result[$c . $key] = advancedQueryFormatForPersonnel($value['value'], $value['condition']);
}
} }
// 商机状态组 // 商机状态组
if (isset($value['form_type']) && $value['form_type'] == 'business_type') { if (isset($value['form_type']) && $value['form_type'] == 'business_type') {
if (!empty($value['type_id'])) $result[$c . 'type_id'] = ['eq', $value['type_id']]; if (!empty($value['type_id'])) $result[$c . 'type_id'] = ['eq', $value['type_id']];
if (!empty($value['status_id']) && in_array($value['status_id'], [1, 2, 3])) $result[$c . 'is_end'] = ['eq', $value['status_id']]; if (!empty($value['status_id']) && in_array($value['status_id'], [1, 2, 3])) $result[$c . 'is_end'] = ['eq', $value['status_id']];
if (!empty($value['status_id']) && !in_array($value['status_id'], [1, 2, 3])) $result[$c . 'status_id'] = ['eq', $value['status_id']]; if (!empty($value['status_id']) && !in_array($value['status_id'], [1, 2, 3])) $result[$c . 'status_id'] = ['eq', $value['status_id']];
} }
// 回款计划 // 回款计划
if (isset($value['form_type']) && $value['form_type'] == 'receivables_plan' && !empty($value['value'])) { if (isset($value['form_type']) && $value['form_type'] == 'receivables_plan' && !empty($value['value'])) {
$result[$c . 'plan_id'] = advancedQueryFormatForPlan($value['value']); $result[$c . 'plan_id'] = advancedQueryFormatForPlan($value['value']);
@ -441,7 +461,7 @@ function advancedQueryParam($prefix, $field, $name)
'business_id' => 'business.', 'business_id' => 'business.',
'contacts_id' => 'contacts.' 'contacts_id' => 'contacts.'
]; ];
// 处理客户名称、联系人名称、商机名称、合同名称字段 // 处理客户名称、联系人名称、商机名称、合同名称字段
if (in_array($field, ['customer_name', 'contacts_name', 'business_name', 'contract_name']) && $name != '合同编号') { if (in_array($field, ['customer_name', 'contacts_name', 'business_name', 'contract_name']) && $name != '合同编号') {
$prefix = $prefixChange[$field]; $prefix = $prefixChange[$field];
@ -462,7 +482,7 @@ function advancedQueryParam($prefix, $field, $name)
$prefix = 'contacts.'; $prefix = 'contacts.';
$field = 'name'; $field = 'name';
} }
return [$prefix, $field]; return [$prefix, $field];
} }
@ -477,11 +497,11 @@ function advancedQueryParam($prefix, $field, $name)
function advancedQueryFormatForPlan($data) function advancedQueryFormatForPlan($data)
{ {
$result = []; $result = [];
$planIds = db('crm_receivables_plan')->whereIn('num', $data)->column('plan_id'); $planIds = db('crm_receivables_plan')->whereIn('num', $data)->column('plan_id');
if (!empty($planIds)) $result = ['in', $planIds]; if (!empty($planIds)) $result = ['in', $planIds];
return $result; return $result;
} }
@ -501,7 +521,7 @@ function advancedQueryFormatForAddress($data, $formType)
$data = array_filter(array_column($data[0], 'name')); $data = array_filter(array_column($data[0], 'name'));
$data = implode(',', $data); $data = implode(',', $data);
} }
return ['like', '%' . trim($data) . '%']; return ['like', '%' . trim($data) . '%'];
} }
@ -517,10 +537,14 @@ function advancedQueryFormatForPersonnel($data, $condition)
// 处理查询条件 // 处理查询条件
if ($condition == 'is') $condition = 'contains'; if ($condition == 'is') $condition = 'contains';
if ($condition == 'isNot') $condition = 'notContains'; if ($condition == 'isNot') $condition = 'notContains';
// 处理查询参数 // 处理查询参数
$data = advancedQueryDataTransform($data, $condition); if (in_array($condition, ['contains', 'notContains'])) {
array_walk($data, function ($value, $key) use (&$data) {
$data[$key] = '%,' . $value . ',%';
});
}
// 搜索条件 // 搜索条件
return advancedQueryWhere($condition, $data); return advancedQueryWhere($condition, $data);
} }
@ -538,7 +562,7 @@ function advancedQueryFormatForDate($data)
# 转换日期时间类型格式 # 转换日期时间类型格式
if (in_array($data['form_type'], ['datetime', 'next_time']) && !empty($data['value'][0])) $data['value'][0] = strtotime($data['value'][0]); if (in_array($data['form_type'], ['datetime', 'next_time']) && !empty($data['value'][0])) $data['value'][0] = strtotime($data['value'][0]);
if (in_array($data['form_type'], ['datetime', 'next_time']) && !empty($data['value'][1])) $data['value'][1] = strtotime($data['value'][1]); if (in_array($data['form_type'], ['datetime', 'next_time']) && !empty($data['value'][1])) $data['value'][1] = strtotime($data['value'][1]);
return advancedQueryWhere($data['condition'], count($data['value']) == 2 ? $data['value'] : $data['value'][0]); return advancedQueryWhere($data['condition'], count($data['value']) == 2 ? $data['value'] : $data['value'][0]);
} }
@ -557,17 +581,21 @@ function advancedQueryFormatForCommon($data, $condition, $formType, $key)
// 处理查询方式 // 处理查询方式
if (in_array($formType, ['checkbox']) && $condition == 'is') $condition = 'contains'; if (in_array($formType, ['checkbox']) && $condition == 'is') $condition = 'contains';
if (in_array($formType, ['checkbox']) && $condition == 'isNot') $condition = 'notContains'; if (in_array($formType, ['checkbox']) && $condition == 'isNot') $condition = 'notContains';
// 处理查询参数 // 处理查询参数
if (in_array($condition, ['contains', 'notContains', 'startWith', 'endWith'])) $data = advancedQueryDataTransform($data, $condition); if(in_array($condition, ['contains', 'notContains']) && in_array($key,['create_user_id','owner_user_id'])){
$data = advancedQueryDataUserform($data, $condition);
}elseif (in_array($condition, ['contains', 'notContains', 'startWith', 'endWith'])){
$data = advancedQueryDataTransform($data, $condition);
}
// 处理回访形式 // 处理回访形式
if (in_array($key, ['shape', 'satisfaction'])) { if (in_array($key, ['shape', 'satisfaction'])) {
array_walk($data, function ($value, $key) use (&$data) { array_walk($data, function ($value, $key) use (&$data) {
$data[$key] = $value . "\r"; $data[$key] = $value . "\r";
}); });
} }
// 处理审核状态 // 处理审核状态
if ($formType == 'check_status') { if ($formType == 'check_status') {
$data[0] = str_replace('待审核', 0, $data[0]); $data[0] = str_replace('待审核', 0, $data[0]);
@ -578,26 +606,26 @@ function advancedQueryFormatForCommon($data, $condition, $formType, $key)
$data[0] = str_replace('未提交', 5, $data[0]); $data[0] = str_replace('未提交', 5, $data[0]);
$data[0] = str_replace('已作废', 6, $data[0]); $data[0] = str_replace('已作废', 6, $data[0]);
} }
return advancedQueryWhere($condition, $data); return advancedQueryWhere($condition, $data,$key);
} }
/** /**
* 设置搜索条件 * 设置搜索条件
* *
* @param string $condition 查询方式 * @param string $condition 查询方式
* @param string $data 查询数据 * @param string|array $data 查询数据
* @return array * @return array
* @since 2021-05-22 * @since 2021-05-22
* @author fanqi * @author fanqi
*/ */
function advancedQueryWhere($condition, $data) function advancedQueryWhere($condition, $data, $key='')
{ {
$result = []; $result = [];
// NULL(0)不存在、IS(1)等于、IS_NOT(2)不等于、CONTAINS(3)包含、NOT_CONTAINS(4)不包含、IS_NULL(5)为空、IS_NOT_NULL(6)不为空 // NULL(0)不存在、IS(1)等于、IS_NOT(2)不等于、CONTAINS(3)包含、NOT_CONTAINS(4)不包含、IS_NULL(5)为空、IS_NOT_NULL(6)不为空
// GT(7)大于、EGT(8)大于等于、LT(9)小于、ELT(10)小于等于、ID(11)通过id、PREFIX(12) 前缀匹配、SUFFIX(13) 后缀匹配、RANGE(14) 数字区间 // GT(7)大于、EGT(8)大于等于、LT(9)小于、ELT(10)小于等于、ID(11)通过id、PREFIX(12) 前缀匹配、SUFFIX(13) 后缀匹配、RANGE(14) 数字区间
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]; // 不等于 if ($condition == 'isNot') $result = ['notin', $data]; // 不等于
@ -613,7 +641,8 @@ function advancedQueryWhere($condition, $data)
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 == 'notContains' && in_array($key,['create_user_id','owner_user_id'])) $result = ['notin', $data]; // 暂定为创建人 负责人不包含
return $result; return $result;
} }
@ -633,22 +662,40 @@ function advancedQueryDataTransform($data, $condition)
$data[$key] = '%' . $value . '%'; $data[$key] = '%' . $value . '%';
}); });
} }
if ($condition == 'startWith') { if ($condition == 'startWith') {
array_walk($data, function ($value, $key) use (&$data) { array_walk($data, function ($value, $key) use (&$data) {
$data[$key] = $value . '%'; $data[$key] = $value . '%';
}); });
} }
if ($condition == 'endWith') { if ($condition == 'endWith') {
array_walk($data, function ($value, $key) use (&$data) { array_walk($data, function ($value, $key) use (&$data) {
$data[$key] = '%' . $value; $data[$key] = '%' . $value;
}); });
} }
return $data; return $data;
} }
/**
* 处理要查询的数据 包含不包含条件 数据为数字专用
*
* @param array $data 要查询的数据
* @param string $condition 查询方式
* @return mixed
* @author: alvin guogaobo
* @version: 11.1.0
* Date: 2021/9/2 14:44
*/
function advancedQueryDataUserform($data, $condition){
if (in_array($condition, ['contains', 'notContains'])) {
array_walk($data, function ($value, $key) use (&$data) {
$data[$key] = $value;
});
}
return $data;
}
/** /**
* 等于(时间段)数据处理 * 等于(时间段)数据处理
* *
@ -661,79 +708,80 @@ function advancedQueryHandleDate($data)
{ {
// 本年度 // 本年度
if ($data['value'][0] == 'year') { if ($data['value'][0] == 'year') {
$data['value'][0] = date('Y-m-d 00:00:00'); $arrTime = DataTime::year();
$data['value'][1] = date('Y-m-d 23:59:59'); $data['value'][0] = date('Y-m-d 00:00:00', $arrTime[0]);
$data['value'][1] = date('Y-m-d 23:59:59', $arrTime[1]);
} }
// 上一年度 // 上一年度
if ($data['value'][0] == 'lastYear') { if ($data['value'][0] == 'lastYear') {
$data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-1 year')); $data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-1 year'));
$data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 year')); $data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 year'));
} }
// 下一年度 // 下一年度
if ($data['value'][0] == 'nextYear') { if ($data['value'][0] == 'nextYear') {
$data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 year')); $data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 year'));
$data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+1 year')); $data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+1 year'));
} }
// 上半年 // 上半年
if ($data['value'][0] == 'firstHalfYear') { if ($data['value'][0] == 'firstHalfYear') {
$data['value'][0] = date('Y-01-01 00:00:00'); $data['value'][0] = date('Y-01-01 00:00:00');
$data['value'][1] = date('Y-06-30 23:59:59'); $data['value'][1] = date('Y-06-30 23:59:59');
} }
// 下半年 // 下半年
if ($data['value'][0] == 'nextHalfYear') { if ($data['value'][0] == 'nextHalfYear') {
$data['value'][0] = date('Y-07-01 00:00:00'); $data['value'][0] = date('Y-07-01 00:00:00');
$data['value'][1] = date('Y-12-31 23:59:59'); $data['value'][1] = date('Y-12-31 23:59:59');
} }
// 本季度 // 本季度
if ($data['value'][0] == 'quarter') { if ($data['value'][0] == 'quarter') {
$season = ceil((date('n')) / 3); $season = ceil((date('n')) / 3);
$data['value'][0] = date('Y-m-d H:i:s', mktime(0, 0, 0, $season * 3 - 3 + 1, 1, date('Y'))); $data['value'][0] = date('Y-m-d H:i:s', mktime(0, 0, 0, $season * 3 - 3 + 1, 1, date('Y')));
$data['value'][1] = date('Y-m-d H:i:s', mktime(23, 59, 59, $season * 3, date('t', mktime(0, 0, 0, $season * 3, 1, date("Y"))), date('Y'))); $data['value'][1] = date('Y-m-d H:i:s', mktime(23, 59, 59, $season * 3, date('t', mktime(0, 0, 0, $season * 3, 1, date("Y"))), date('Y')));
} }
// 上一季度 // 上一季度
if ($data['value'][0] == 'lastQuarter') { if ($data['value'][0] == 'lastQuarter') {
$season = ceil((date('n')) / 3) - 1; $season = ceil((date('n')) / 3) - 1;
$data['value'][0] = date('Y-m-d H:i:s', mktime(0, 0, 0, $season * 3 - 3 + 1, 1, date('Y'))); $data['value'][0] = date('Y-m-d H:i:s', mktime(0, 0, 0, $season * 3 - 3 + 1, 1, date('Y')));
$data['value'][1] = date('Y-m-d H:i:s', mktime(23, 59, 59, $season * 3, date('t', mktime(0, 0, 0, $season * 3, 1, date("Y"))), date('Y'))); $data['value'][1] = date('Y-m-d H:i:s', mktime(23, 59, 59, $season * 3, date('t', mktime(0, 0, 0, $season * 3, 1, date("Y"))), date('Y')));
} }
// 下一季度 // 下一季度
if ($data['value'][0] == 'nextQuarter') { if ($data['value'][0] == 'nextQuarter') {
$season = ceil((date('n')) / 3); $season = ceil((date('n')) / 3);
$data['value'][0] = date('Y-m-d H:i:s', mktime(0, 0, 0, $season * 3 + 1, 1, date('Y'))); $data['value'][0] = date('Y-m-d H:i:s', mktime(0, 0, 0, $season * 3 + 1, 1, date('Y')));
$data['value'][1] = date('Y-m-d H:i:s', mktime(23, 59, 59, $season * 3 + 3, date('t', mktime(0, 0, 0, $season * 3, 1, date("Y"))), date('Y'))); $data['value'][1] = date('Y-m-d H:i:s', mktime(23, 59, 59, $season * 3 + 3, date('t', mktime(0, 0, 0, $season * 3, 1, date("Y"))), date('Y')));
} }
// 本月 // 本月
if ($data['value'][0] == 'month') { if ($data['value'][0] == 'month') {
$data['value'][0] = date('Y-m-01 00:00:00'); $data['value'][0] = date('Y-m-01 00:00:00');
$data['value'][1] = date('Y-m-31 23:59:59'); $data['value'][1] = date('Y-m-31 23:59:59');
} }
// 上月 // 上月
if ($data['value'][0] == 'lastMonth') { if ($data['value'][0] == 'lastMonth') {
$data['value'][0] = date('Y-m-01 00:00:00', strtotime(date('Y-m-d') . '-1 month')); $data['value'][0] = date('Y-m-01 00:00:00', strtotime(date('Y-m-d') . '-1 month'));
$data['value'][1] = date('Y-m-31 23:59:59', strtotime(date('Y-m-d') . '-1 month')); $data['value'][1] = date('Y-m-31 23:59:59', strtotime(date('Y-m-d') . '-1 month'));
} }
// 下月 // 下月
if ($data['value'][0] == 'nextMonth') { if ($data['value'][0] == 'nextMonth') {
$data['value'][0] = date('Y-m-01 00:00:00', strtotime(date('Y-m-d') . '+1 month')); $data['value'][0] = date('Y-m-01 00:00:00', strtotime(date('Y-m-d') . '+1 month'));
$data['value'][1] = date('Y-m-31 23:59:59', strtotime(date('Y-m-d') . '+1 month')); $data['value'][1] = date('Y-m-31 23:59:59', strtotime(date('Y-m-d') . '+1 month'));
} }
// 本周 // 本周
if ($data['value'][0] == 'week') { if ($data['value'][0] == 'week') {
$data['value'][0] = date('Y-m-d 00:00:00', mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('Y'))); $data['value'][0] = date('Y-m-d 00:00:00', mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('Y')));
$data['value'][1] = date('Y-m-d 23:59:59', mktime(23, 59, 59, date('m'), date('d') - date('w') + 7, date('Y'))); $data['value'][1] = date('Y-m-d 23:59:59', mktime(23, 59, 59, date('m'), date('d') - date('w') + 7, date('Y')));
} }
// 上周 // 上周
if ($data['value'][0] == 'lastWeek') { if ($data['value'][0] == 'lastWeek') {
$date = date("Y-m-d"); $date = date("Y-m-d");
@ -743,7 +791,7 @@ function advancedQueryHandleDate($data)
$data['value'][0] = date('Y-m-d', strtotime($start . " - 7 days")); $data['value'][0] = date('Y-m-d', strtotime($start . " - 7 days"));
$data['value'][1] = date('Y-m-d', strtotime($start . " - 1 days")); $data['value'][1] = date('Y-m-d', strtotime($start . " - 1 days"));
} }
// 下周 // 下周
if ($data['value'][0] == 'nextWeek') { if ($data['value'][0] == 'nextWeek') {
$date = date("Y-m-d"); $date = date("Y-m-d");
@ -753,49 +801,49 @@ function advancedQueryHandleDate($data)
$data['value'][0] = date('Y-m-d', strtotime($start . " + 7 days")); $data['value'][0] = date('Y-m-d', strtotime($start . " + 7 days"));
$data['value'][1] = date('Y-m-d', strtotime($start . " + 13 days")); $data['value'][1] = date('Y-m-d', strtotime($start . " + 13 days"));
} }
// 今天 // 今天
if ($data['value'][0] == 'today') { if ($data['value'][0] == 'today') {
$data['value'][0] = date('Y-m-d 00:00:00'); $data['value'][0] = date('Y-m-d 00:00:00');
$data['value'][1] = date('Y-m-d 23:59:59'); $data['value'][1] = date('Y-m-d 23:59:59');
} }
// 昨天 // 昨天
if ($data['value'][0] == 'yesterday') { if ($data['value'][0] == 'yesterday') {
$data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-1 day')); $data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-1 day'));
$data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 day')); $data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 day'));
} }
// 明天 // 明天
if ($data['value'][0] == 'tomorrow') { if ($data['value'][0] == 'tomorrow') {
$data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 day')); $data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 day'));
$data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+1 day')); $data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+1 day'));
} }
// 过去7天 // 过去7天
if ($data['value'][0] == 'previous7day') { if ($data['value'][0] == 'previous7day') {
$data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-7 day')); $data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-7 day'));
$data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 day')); $data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 day'));
} }
// 过去30天 // 过去30天
if ($data['value'][0] == 'previous30day') { if ($data['value'][0] == 'previous30day') {
$data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-30 day')); $data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '-30 day'));
$data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 day')); $data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '-1 day'));
} }
// 未来7天 // 未来7天
if ($data['value'][0] == 'future7day') { if ($data['value'][0] == 'future7day') {
$data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 day')); $data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 day'));
$data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+7 day')); $data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+7 day'));
} }
// 未来30天 // 未来30天
if ($data['value'][0] == 'future30day') { if ($data['value'][0] == 'future30day') {
$data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 day')); $data['value'][0] = date('Y-m-d 00:00:00', strtotime(date('Y-m-d') . '+1 day'));
$data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+30 day')); $data['value'][1] = date('Y-m-d 23:59:59', strtotime(date('Y-m-d') . '+30 day'));
} }
return $data; return $data;
} }
@ -904,12 +952,12 @@ function field($search, $condition = '', $k = '')
function field_arr($value, $condition = '') function field_arr($value, $condition = '')
{ {
if (is_array($value)) { if (is_array($value)) {
} else { } else {
$condition = $condition ?: 'eq'; $condition = $condition ?: 'eq';
$where_arr = ['value' => $value, 'condition' => $condition]; $where_arr = ['value' => $value, 'condition' => $condition];
} }
return $where_arr; return $where_arr;
} }
@ -934,12 +982,12 @@ function actionLog($id, $join_user_ids = '', $structure_ids = '', $content = '')
} }
$userInfo = $cache['userInfo']; $userInfo = $cache['userInfo'];
$category = $userInfo['id'] == 1 ? '管理员' : '员工'; $category = $userInfo['id'] == 1 ? '管理员' : '员工';
$request = request(); $request = request();
$m = strtolower($request->module()); $m = strtolower($request->module());
$c = strtolower($request->controller()); $c = strtolower($request->controller());
$a = strtolower($request->action()); $a = strtolower($request->action());
$res_action = true; $res_action = true;
foreach ($idArr as $v) { foreach ($idArr as $v) {
$data = []; $data = [];
@ -959,7 +1007,7 @@ function actionLog($id, $join_user_ids = '', $structure_ids = '', $content = '')
if (!db('admin_action_log')->insert($data)) { if (!db('admin_action_log')->insert($data)) {
$res_action = false; $res_action = false;
} }
# 数据操作日志 # 数据操作日志
db('admin_operation_log')->insert([ db('admin_operation_log')->insert([
'user_id' => $userInfo['id'], 'user_id' => $userInfo['id'],
@ -970,7 +1018,7 @@ function actionLog($id, $join_user_ids = '', $structure_ids = '', $content = '')
'create_time' => time() 'create_time' => time()
]); ]);
} }
if ($res_action) { if ($res_action) {
return true; return true;
} else { } else {
@ -1094,14 +1142,14 @@ function getSubUserId($self = true, $type = 0, $user_id = '')
$userInfo = $cache['userInfo']; $userInfo = $cache['userInfo'];
$user_id = $userInfo['id']; $user_id = $userInfo['id'];
$adminTypes = adminGroupTypes($user_id); $adminTypes = adminGroupTypes($user_id);
if (in_array(1, $adminTypes)) { if (in_array(1, $adminTypes)) {
$type = 1; $type = 1;
} }
} }
$belowIds = []; $belowIds = [];
if (empty($type)) { if (empty($type)) {
if ($user_id) { if ($user_id) {
$belowIds = getSubUser($user_id); $belowIds = getSubUser($user_id);
} }
@ -1221,7 +1269,7 @@ function sendMessage($user_id, $content, $action_id, $sysMessage = 0)
$m = strtolower($request->module()); $m = strtolower($request->module());
$c = strtolower($request->controller()); $c = strtolower($request->controller());
$a = strtolower($request->action()); $a = strtolower($request->action());
$userInfo = []; $userInfo = [];
if ($sysMessage == 0) { if ($sysMessage == 0) {
$header = $request->header(); $header = $request->header();
@ -1277,7 +1325,7 @@ function updateActionLog($user_id, $types, $action_id, $oldData = [], $newData =
if (!empty($oldData['next_time']) && $oldData['next_time'] != strtotime($oldData['next_time'])) { if (!empty($oldData['next_time']) && $oldData['next_time'] != strtotime($oldData['next_time'])) {
$oldData['next_time'] = strtotime($oldData['next_time']); $oldData['next_time'] = strtotime($oldData['next_time']);
} }
if (is_array($oldData) && is_array($newData) && $user_id) { if (is_array($oldData) && is_array($newData) && $user_id) {
$differentData = array_diff_assoc($newData, $oldData); $differentData = array_diff_assoc($newData, $oldData);
$fieldModel = new FieldModel(); $fieldModel = new FieldModel();
@ -1299,7 +1347,11 @@ function updateActionLog($user_id, $types, $action_id, $oldData = [], $newData =
$old_value = $oldData[$k] ?: '空'; $old_value = $oldData[$k] ?: '空';
if ($newFieldArr[$k]['form_type'] == 'datetime') { if ($newFieldArr[$k]['form_type'] == 'datetime') {
$new_value = $v ? date('Y-m-d', $v) : '空'; $new_value = $v ? date('Y-m-d', $v) : '空';
$old_value = !empty($oldData[$k]) ? date('Y-m-d', $oldData[$k]) : '空'; if (date('Y-m-d H:i:s', strtotime($oldData[$k])) == $oldData[$k]) {
$old_value = !empty($oldData[$k]) ? $oldData[$k] : '空';
} else {
$old_value = !empty($oldData[$k]) ? date('Y-m-d', $oldData[$k]) : '空';
}
if (empty($v) && empty($oldData[$k])) continue; if (empty($v) && empty($oldData[$k])) continue;
} elseif ($newFieldArr[$k]['form_type'] == 'user') { } elseif ($newFieldArr[$k]['form_type'] == 'user') {
$new_value = $v ? implode(',', $userModel->getUserNameByArr(stringToArray($v))) : ''; $new_value = $v ? implode(',', $userModel->getUserNameByArr(stringToArray($v))) : '';
@ -1407,7 +1459,7 @@ function checkVerify($saftCode = '5kcrm@')
$parmList['sessionId'] = $header['sessionId']; $parmList['sessionId'] = $header['sessionId'];
$authkey = $header['authKey']; $authkey = $header['authKey'];
$clientSign = $parmList['client_sign']; $clientSign = $parmList['client_sign'];
if ($clientSign) { if ($clientSign) {
unset($parmList['client_sign']); unset($parmList['client_sign']);
if (count($parmList) > 0) { if (count($parmList) > 0) {
@ -1873,7 +1925,7 @@ function getTimeByType($type = 'today', $is_last = false)
function getFullPath($path) function getFullPath($path)
{ {
if ($path) { if ($path) {
$protocol = strpos(strtolower($_SERVER['HTTP_REFERER']), 'https') === false ? 'http' : 'https'; $protocol = strpos(strtolower($_SERVER['REQUEST_SCHEME']), 'https') === false ? 'http' : 'https';
return $protocol . '://' . $_SERVER['HTTP_HOST'] . substr($_SERVER["SCRIPT_NAME"], 0, -10) . substr(str_replace(DS, '/', $path), 1); return $protocol . '://' . $_SERVER['HTTP_HOST'] . substr($_SERVER["SCRIPT_NAME"], 0, -10) . substr(str_replace(DS, '/', $path), 1);
} else { } else {
return ''; return '';
@ -2067,12 +2119,12 @@ function nextCheckData($user_id, $flow_id, $types, $types_id, $order_id, $check_
$new_order_id = $order_id; $new_order_id = $order_id;
$max_order_id = db('admin_examine_step')->where(['flow_id' => $flow_id])->max('order_id'); //审批流最大排序ID $max_order_id = db('admin_examine_step')->where(['flow_id' => $flow_id])->max('order_id'); //审批流最大排序ID
$examineStepModel = new \app\admin\model\ExamineStep(); $examineStepModel = new \app\admin\model\ExamineStep();
$stepInfo = $examineStepModel->getStepByOrder($flow_id, $new_order_id); //审批步骤 $stepInfo = $examineStepModel->getStepByOrder($flow_id, $new_order_id); //审批步骤
$next_user_ids = []; $next_user_ids = [];
$is_end = 0; //审批结束 $is_end = 0; //审批结束
//固定流程status 1负责人主管2指定用户任意一人3指定用户多人会签4上一级审批人主管 //固定流程status 1负责人主管2指定用户任意一人3指定用户多人会签4上一级审批人主管
//当前步骤审批人user_id //当前步骤审批人user_id
$step_user_ids = $examineStepModel->getUserByStep($stepInfo['step_id'], $user_id); $step_user_ids = $examineStepModel->getUserByStep($stepInfo['step_id'], $user_id);
if ($step_user_ids) { if ($step_user_ids) {
@ -2229,7 +2281,7 @@ function getWhereUserByParam(&$where, $field = 'owner_user_id', $m = '', $c = ''
{ {
$param = request()->param(); $param = request()->param();
$userModel = new UserModel(); $userModel = new UserModel();
$map_user_ids = []; $map_user_ids = [];
if ($param['user_id']) { if ($param['user_id']) {
$map_user_ids = array($param['user_id']); $map_user_ids = array($param['user_id']);
@ -2240,7 +2292,7 @@ function getWhereUserByParam(&$where, $field = 'owner_user_id', $m = '', $c = ''
$where[$field] = array('in', $map_user_ids); $where[$field] = array('in', $map_user_ids);
return; return;
} }
$perUserIds = $userModel->getUserByPer($m, $c, $a); //权限范围内userIds $perUserIds = $userModel->getUserByPer($m, $c, $a); //权限范围内userIds
$userIds = array_intersect($map_user_ids, $perUserIds); //数组交集 $userIds = array_intersect($map_user_ids, $perUserIds); //数组交集
$where[$field] = array('in', $userIds); $where[$field] = array('in', $userIds);
@ -2335,10 +2387,10 @@ function download($file, $name = '', $del = false)
'error' => '文件路径错误', 'error' => '文件路径错误',
]); ]);
} }
$fp = fopen($file, 'r'); $fp = fopen($file, 'r');
$size = filesize($file); $size = filesize($file);
//下载文件需要的头 //下载文件需要的头
header("Content-type: application/octet-stream"); header("Content-type: application/octet-stream");
header("Accept-Ranges: bytes"); header("Accept-Ranges: bytes");
@ -2347,12 +2399,12 @@ function download($file, $name = '', $del = false)
$file_name = $name != '' ? $name : pathinfo($file, PATHINFO_BASENAME); $file_name = $name != '' ? $name : pathinfo($file, PATHINFO_BASENAME);
// urlencode 处理中文乱码 // urlencode 处理中文乱码
header("Content-Disposition:attachment; filename=" . urlencode($file_name)); header("Content-Disposition:attachment; filename=" . urlencode($file_name));
// 导出数据时 csv office Excel 需要添加bom头 // 导出数据时 csv office Excel 需要添加bom头
if (pathinfo($file, PATHINFO_EXTENSION) == 'csv') { if (pathinfo($file, PATHINFO_EXTENSION) == 'csv') {
echo "\xEF\xBB\xBF"; // UTF-8 BOM echo "\xEF\xBB\xBF"; // UTF-8 BOM
} }
$fileCount = 0; $fileCount = 0;
$fileUnit = 1024; $fileUnit = 1024;
while (!feof($fp) && $size - $fileCount > 0) { while (!feof($fp) && $size - $fileCount > 0) {
@ -2361,7 +2413,7 @@ function download($file, $name = '', $del = false)
$fileCount += $fileUnit; $fileCount += $fileUnit;
} }
fclose($fp); fclose($fp);
// 删除 // 删除
if ($del) @unlink($file); if ($del) @unlink($file);
die(); die();
@ -2382,7 +2434,7 @@ function tempFileName($ext = '')
if (!file_exists($path)) { if (!file_exists($path)) {
mkdir($path, 0777, true); mkdir($path, 0777, true);
} }
$ext = trim($ext, '.'); $ext = trim($ext, '.');
do { do {
$temp_file = md5(time() . rand(1000, 9999)); $temp_file = md5(time() . rand(1000, 9999));
@ -2411,7 +2463,7 @@ function delDir($dir)
} }
} }
} }
closedir($dh); closedir($dh);
//删除当前文件夹: //删除当前文件夹:
@rmdir($dir); @rmdir($dir);
@ -2523,7 +2575,7 @@ function getTimeArray($start = null, $end = null)
break; break;
} }
} }
$between = [$start, $end]; $between = [$start, $end];
$list = []; $list = [];
$len = ($end - $start) / 86400; $len = ($end - $start) / 86400;
@ -2552,7 +2604,7 @@ function getTimeArray($start = null, $end = null)
$start = $item['end_time'] + 1; $start = $item['end_time'] + 1;
} }
} }
return [ return [
'list' => $list, // 时间段列表 'list' => $list, // 时间段列表
'time_format' => $time_format, // 时间格式 mysql 格式化时间戳 'time_format' => $time_format, // 时间格式 mysql 格式化时间戳
@ -2585,8 +2637,8 @@ function DBBackup($file = '', $path = '')
$username = config('database.username'); $username = config('database.username');
$password = config('database.password'); $password = config('database.password');
$dsn = "{$type}:host={$host};dbname={$dbname};port={$port}"; $dsn = "{$type}:host={$host};dbname={$dbname};port={$port}";
if ($file == '') { if ($file == '') {
$save_path = dirname(APP_PATH) . DS . 'data' . DS . date('Ym') . DS; $save_path = dirname(APP_PATH) . DS . 'data' . DS . date('Ym') . DS;
if (!file_exists($save_path) && !mkdir($save_path, '0777', true)) { if (!file_exists($save_path) && !mkdir($save_path, '0777', true)) {
@ -2594,11 +2646,11 @@ function DBBackup($file = '', $path = '')
} }
$file = $save_path . date('d_H_i') . '_db_backup' . '.sql'; $file = $save_path . date('d_H_i') . '_db_backup' . '.sql';
} }
if (file_exists($file)) { if (file_exists($file)) {
return '数据库备份文件已存在自动备份时间间隔需大于1分钟。'; return '数据库备份文件已存在自动备份时间间隔需大于1分钟。';
} }
try { try {
$backup = new \com\Mysqldump($dsn, $username, $password); $backup = new \com\Mysqldump($dsn, $username, $password);
$backup->start($file); $backup->start($file);
@ -2606,7 +2658,7 @@ function DBBackup($file = '', $path = '')
} catch (\Exception $e) { } catch (\Exception $e) {
return '备份失败,请手动备份。错误原因:' . $e->getMessage(); return '备份失败,请手动备份。错误原因:' . $e->getMessage();
} }
} }
/** /**
@ -2629,17 +2681,17 @@ if (!function_exists('isSuperAdministrators')) {
function isSuperAdministrators($userId) function isSuperAdministrators($userId)
{ {
$status = false; $status = false;
$apiCommon = new \app\admin\controller\ApiCommon(); $apiCommon = new \app\admin\controller\ApiCommon();
$userId = !empty($userId) ? $userId : $apiCommon->userInfo['id']; $userId = !empty($userId) ? $userId : $apiCommon->userInfo['id'];
$data = db('admin_access')->where('user_id', $userId)->column('group_id'); $data = db('admin_access')->where('user_id', $userId)->column('group_id');
if ($userId == 1 || in_array(1, $data)) { if ($userId == 1 || in_array(1, $data)) {
$status = true; $status = true;
} }
return $status; return $status;
} }
} }
@ -2653,11 +2705,11 @@ if (!function_exists('getFieldGrantData')) {
function getFieldGrantData($userId) function getFieldGrantData($userId)
{ {
$result = []; $result = [];
$apiCommon = new \app\admin\controller\ApiCommon(); $apiCommon = new \app\admin\controller\ApiCommon();
$userId = !empty($userId) ? $userId : $apiCommon->userInfo['id']; $userId = !empty($userId) ? $userId : $apiCommon->userInfo['id'];
$grantData = Db::query(" $grantData = Db::query("
SELECT SELECT
`grant`.`module`, `grant`.`column`, `grant`.`content` `grant`.`module`, `grant`.`column`, `grant`.`content`
@ -2670,14 +2722,14 @@ if (!function_exists('getFieldGrantData')) {
WHERE WHERE
`access`.`user_id` = `access`.`user_id` =
" . $userId); " . $userId);
# 存在多角色多授权的情况 # 存在多角色多授权的情况
foreach ($grantData as $key => $value) { foreach ($grantData as $key => $value) {
if (empty($value['module']) || empty($value['column'])) continue; if (empty($value['module']) || empty($value['column'])) continue;
$result[$value['module'] . '_' . $value['column']][] = !empty($value['content']) ? unserialize($value['content']) : []; $result[$value['module'] . '_' . $value['column']][] = !empty($value['content']) ? unserialize($value['content']) : [];
} }
return $result; return $result;
} }
} }
@ -2693,32 +2745,34 @@ if (!function_exists('getFieldGrantStatus')) {
function getFieldGrantStatus($field, $grantData) function getFieldGrantStatus($field, $grantData)
{ {
# 默认状态都是不能查看、不能编辑,通过配置来取最大权限。 # 默认状态都是不能查看、不能编辑,通过配置来取最大权限。
$result = ['read' => 0, 'write' => 0]; $result = ['read' => 0, 'write' => 0,'maskType'=>0];
foreach ($grantData as $key => $value) { foreach ($grantData as $key => $value) {
$fieldBool = false; $fieldBool = false;
foreach ($value as $ke => $va) { foreach ($value as $ke => $va) {
# 多个字段授权,只取最高的读权限 # 多个字段授权,只取最高的读权限
if ($va['field'] == $field && $result['read'] == 0) { if ($va['field'] == $field && $result['read'] == 0) {
$result['read'] = $va['read'] > $result['read'] ? $va['read'] : $result['read']; $result['read'] = $va['read'] > $result['read'] ? $va['read'] : $result['read'];
} }
# 多个字段授权,只取最高的写权限 # 多个字段授权,只取最高的写权限
if ($va['field'] == $field && $result['write'] == 0) { if ($va['field'] == $field && $result['write'] == 0) {
$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) {
$result['maskType'] = !empty($va['maskType'])?$va['maskType']:0;
}
if ($va['field'] == $field) $fieldBool = true; if ($va['field'] == $field) $fieldBool = true;
} }
# 对于不在权限控制之内的字段将状态都改为1。 # 对于不在权限控制之内的字段将状态都改为1。
if (!$fieldBool) { if (!$fieldBool) {
$result['read'] = 1; $result['read'] = 1;
$result['write'] = 1; $result['write'] = 1;
} }
} }
return $result; return $result;
} }
} }
@ -2767,7 +2821,7 @@ function ByDateTime($type = 'today')
$daterange_start_time = strtotime(date('Y-10-01 00:00:00')); $daterange_start_time = strtotime(date('Y-10-01 00:00:00'));
$daterange_end_time = strtotime(date("Y-12-31 23:59:59")); $daterange_end_time = strtotime(date("Y-12-31 23:59:59"));
} }
//上季度 //上季度
$month = date('m'); $month = date('m');
if ($month == 1 || $month == 2 || $month == 3) { if ($month == 1 || $month == 2 || $month == 3) {
@ -3007,41 +3061,41 @@ if (!function_exists('getFieldGroupOrderData')) {
$formPositionEmpty = []; $formPositionEmpty = [];
$formPositionExist = []; $formPositionExist = [];
$result = []; $result = [];
// 处理数据,将有位置信息和无位置信息的数据分开存放。 // 处理数据,将有位置信息和无位置信息的数据分开存放。
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
if (empty($value['form_position'])) { if (empty($value['form_position'])) {
$formPositionEmpty[] = $value; $formPositionEmpty[] = $value;
continue; continue;
} }
$formPositionArray = explode(',', $value['form_position']); $formPositionArray = explode(',', $value['form_position']);
$x = (int)$formPositionArray[0]; $x = (int)$formPositionArray[0];
$y = (int)$formPositionArray[1]; $y = (int)$formPositionArray[1];
if (!isset($value['xaxis'])) $value['xaxis'] = $x; if (!isset($value['xaxis'])) $value['xaxis'] = $x;
if (!isset($value['yaxis'])) $value['yaxis'] = $y; if (!isset($value['yaxis'])) $value['yaxis'] = $y;
if ($value['form_type'] == 'date_interval' && !is_array($value['default_value'])) {
$value['default_value'] = !empty($value['default_value']) ? explode(',', $value['default_value']) : [];
}
$formPositionExist[$x][$y] = $value; $formPositionExist[$x][$y] = $value;
} }
// 排序 // 排序
ksort($formPositionExist); ksort($formPositionExist);
// 处理有位置信息的数据 // 处理有位置信息的数据
foreach ($formPositionExist as $key => $value) { foreach ($formPositionExist as $key => $value) {
foreach ($value as $k => $v) { foreach ($value as $k => $v) {
if (!empty($formPositionExist[$key][$k])) $result[$key][$k] = $v; if (!empty($formPositionExist[$key][$k])) $result[$key][$k] = $v;
} }
$result[$key] = array_values($result[$key]); $result[$key] = array_values($result[$key]);
} }
// 将无位置信息的数据放置尾端 // 将无位置信息的数据放置尾端
foreach ($formPositionEmpty as $key => $value) { foreach ($formPositionEmpty as $key => $value) {
$result[] = [$value]; $result[] = [$value];
} }
return array_values($result); return array_values($result);
} }
} }
@ -3058,7 +3112,7 @@ if (!function_exists('getPrimaryKeyName')) {
function getPrimaryKeyName($types) function getPrimaryKeyName($types)
{ {
$primaryKey = ''; $primaryKey = '';
if ($types == 'crm_leads') $primaryKey = 'leads_id'; if ($types == 'crm_leads') $primaryKey = 'leads_id';
if ($types == 'crm_customer') $primaryKey = 'customer_id'; if ($types == 'crm_customer') $primaryKey = 'customer_id';
if ($types == 'crm_contacts') $primaryKey = 'contacts_id'; if ($types == 'crm_contacts') $primaryKey = 'contacts_id';
@ -3070,24 +3124,36 @@ if (!function_exists('getPrimaryKeyName')) {
if ($types == 'crm_product') $primaryKey = 'product_id'; if ($types == 'crm_product') $primaryKey = 'product_id';
if ($types == 'crm_invoice') $primaryKey = 'invoice_id'; if ($types == 'crm_invoice') $primaryKey = 'invoice_id';
if ($types == 'oa_examine') $primaryKey = 'examine_id'; if ($types == 'oa_examine') $primaryKey = 'examine_id';
if ($types == 'jxc_product') $primaryKey = 'product_id';
if ($types == 'jxc_supplier') $primaryKey = 'supplier_id';
if ($types == 'jxc_purchase') $primaryKey = 'purchase_id';
if ($types == 'jxc_retreat') $primaryKey = 'retreat_id';
if ($types == 'jxc_sale') $primaryKey = 'sale_id';
if ($types == 'jxc_salereturn') $primaryKey = 'salereturn_id';
if ($types == 'jxc_receipt') $primaryKey = 'receipt_id';
if ($types == 'jxc_outbound') $primaryKey = 'outbound_id';
if ($types == 'jxc_payment') $primaryKey = 'payment_note_id';
if ($types == 'jxc_collection') $primaryKey = 'collection_note_id';
if ($types == 'jxc_inventory') $primaryKey = 'inventory_id';
if ($types == 'jxc_allocation') $primaryKey = 'allocation_id';
return $primaryKey; return $primaryKey;
} }
} }
function advancedQueryFormatForTeam($requestMap,$db,$db_id) function advancedQueryFormatForTeam($requestMap, $db, $db_id)
{ {
// 处理查询条件 // 处理查询条件
foreach ($requestMap['team_id']['value'] as $v) { foreach ($requestMap['team_id']['value'] as $v) {
if ($requestMap['team_id']['condition'] == 'contains') { if ($requestMap['team_id']['condition'] == 'contains') {
$date = function ($query) use ($v) { $date = function ($query) use ($v) {
$query->where('FIND_IN_SET("'.$v.'", ro_user_id)') $query->where('FIND_IN_SET("' . $v . '", ro_user_id)')
->whereOr('FIND_IN_SET("'.$v.'", rw_user_id)'); ->whereOr('FIND_IN_SET("' . $v . '", rw_user_id)');
}; };
} elseif ($requestMap['team_id']['condition'] == 'notContains') { } elseif ($requestMap['team_id']['condition'] == 'notContains') {
$date = function ($query) use ($v) { $date = function ($query) use ($v) {
$query->where('FIND_IN_SET("'.$v.'", ro_user_id)') $query->where('FIND_IN_SET("' . $v . '", ro_user_id)')
->where('FIND_IN_SET("'.$v.'", rw_user_id)'); ->where('FIND_IN_SET("' . $v . '", rw_user_id)');
}; };
} elseif ($requestMap['team_id']['condition'] == 'isNull') { } elseif ($requestMap['team_id']['condition'] == 'isNull') {
$date = function ($query) { $date = function ($query) {
@ -3099,15 +3165,15 @@ function advancedQueryFormatForTeam($requestMap,$db,$db_id)
$query->where('ro_user_id', ['neq', '']) $query->where('ro_user_id', ['neq', ''])
->where('rw_user_id', ['not null']); ->where('rw_user_id', ['not null']);
}; };
} }
$part[] = db($db)->where($date)->column($db_id); $part[] = db($db)->where($date)->column($db_id);
} }
$result = []; $result = [];
array_walk_recursive($part, function($value) use (&$result) { array_walk_recursive($part, function ($value) use (&$result) {
array_push($result, $value); array_push($result, $value);
}); });
$result=array_unique($result); $result = array_unique($result);
$partMap['customer.customer_id'] = ['in', trim(arrayToString($result), ',')]; $partMap['customer.customer_id'] = ['in', trim(arrayToString($result), ',')];
return $partMap ?: []; return $partMap ?: [];
} }

@ -112,8 +112,36 @@ class PoolCommand extends Command
} }
}); });
} }
/**
* 自动入公海操作记录
* @param $ruleList
* @param $customerWhere
*
* @author alvin guogaobo
* @version 1.0 版本号
* @since 2021/6/3 0003 10:38
*/
// private function updateInfo($ruleList, $customerWhere)
// {
// foreach ($ruleList as $k => $v) {
// $levels = json_decode($v['level'], true);
// foreach ($levels as $k1 => $v1) {
// if (!empty($v1['limit_day'])) {
// $time = $v1['limit_day'];
// } else {
// $time = $this->getMinDay($levels);
// }
// }
// foreach ($customerWhere as $val) {
// if ($v['type'] == 1) updateActionLog(0, 'crm_customer', $val, '', '', '超过' . $time . '天无新建跟进记录自动进入公海');
// if ($v['type'] == 2) updateActionLog(0, 'crm_customer', $val, '', '', '超过' . $time . '天无新建商机自动进入公海');
// if ($v['type'] == 3) updateActionLog(0, 'crm_customer', $val, '', '', '超过' . $time . '天未成交自动进入公海');
//
// }
// }
// }
//
protected function execute(Input $input, Output $output) protected function execute(Input $input, Output $output)
{ {

@ -71,6 +71,7 @@ class Team extends Command
{ {
$this->timer = Timer::add(1, function () { $this->timer = Timer::add(1, function () {
# 只在凌晨12点至6点间执行 # 只在凌晨12点至6点间执行
if ((int)date('H') >= 0 && (int)date('H') < 6) { if ((int)date('H') >= 0 && (int)date('H') < 6) {
# 团队成员过滤规则 # 团队成员过滤规则
db('crm_team')->where('target_time',0)->delete(); db('crm_team')->where('target_time',0)->delete();
@ -125,6 +126,7 @@ class Team extends Command
} }
$upData = db($types)->where([$data_name => $v['target_id']])->update($data); $upData = db($types)->where([$data_name => $v['target_id']])->update($data);
db('crm_team')->where(['target_id' => $v['target_id'], 'types' => $v['types'], 'team_user_id' => ['in', arrayToString($team_user_id)]])->delete(); db('crm_team')->where(['target_id' => $v['target_id'], 'types' => $v['types'], 'team_user_id' => ['in', arrayToString($team_user_id)]])->delete();
// updateActionLog(0, $v['types'], $data, '', '', '自动删除到期员工');
} }
Db::commit(); Db::commit();
} catch (\Exception $e) { } catch (\Exception $e) {

@ -116,7 +116,10 @@ class Contract extends ApiCommon
$param['check_user_id'] = is_array($check_user_id) ? ','.implode(',',$check_user_id).',' : $check_user_id; $param['check_user_id'] = is_array($check_user_id) ? ','.implode(',',$check_user_id).',' : $check_user_id;
} else { } else {
# 审批流停用,将状态改为审核通过 # 审批流停用,将状态改为审核通过
$param['check_status'] = 2; // $param['check_status'] = 2;
# 审批流停用,将状态改为正常 zjf 20210727 默认值为7
$param['check_status'] = 7;
} }
} }
@ -212,7 +215,7 @@ class Contract extends ApiCommon
} }
# 已进行审批,不能编辑 # 已进行审批,不能编辑
if (!in_array($dataInfo['check_status'], ['3', '4', '5', '6'])) { if (!in_array($dataInfo['check_status'], ['3', '4', '5', '6', '7']) && $dataInfo['check_status']!=0) {
return resultArray(['error' => '当前状态为审批中或已审批通过,不可编辑']); return resultArray(['error' => '当前状态为审批中或已审批通过,不可编辑']);
} }
@ -260,10 +263,10 @@ class Contract extends ApiCommon
$examineFlowWheres['status'] = 1; $examineFlowWheres['status'] = 1;
$examineFlowWheres['is_deleted'] = 0; $examineFlowWheres['is_deleted'] = 0;
$contractExamineCount = db('admin_examine_flow')->where($examineFlowWheres)->count(); $contractExamineCount = db('admin_examine_flow')->where($examineFlowWheres)->count();
# 审核没有开启,更新作废合同的状态 # 审核没有开启,更新作废合同的状态 zjf 20210727 改状态为正常 值为7
if ($contractExamineCount == 0 && $dataInfo['check_status'] == 6 && empty($param['is_draft'])) $param['check_status'] = 2; if ($contractExamineCount == 0 && $dataInfo['check_status'] == 6 && empty($param['is_draft'])) $param['check_status'] = 7;
# 审核没有开启,更新作废合同的状态 # 审核没有开启,更新作废合同的状态 zjf 20210727 改状态为正常 值为7
if ($contractExamineCount == 0 && $dataInfo['check_status'] == 5 && empty($param['is_draft'])) $param['check_status'] = 2; if ($contractExamineCount == 0 && $dataInfo['check_status'] == 5 && empty($param['is_draft'])) $param['check_status'] = 7;
# 审核没有开启,保存为草稿 # 审核没有开启,保存为草稿
if ($contractExamineCount == 0 && !empty($param['is_draft'])) $param['check_status'] = 5; if ($contractExamineCount == 0 && !empty($param['is_draft'])) $param['check_status'] = 5;

@ -11,6 +11,8 @@ use app\admin\controller\ApiCommon;
use app\crm\logic\CustomerLogic; use app\crm\logic\CustomerLogic;
use app\crm\traits\SearchConditionTrait; use app\crm\traits\SearchConditionTrait;
use app\crm\traits\StarTrait; use app\crm\traits\StarTrait;
use phpDocumentor\Reflection\Types\False_;
use think\Cache;
use think\Hook; use think\Hook;
use think\Request; use think\Request;
use think\Db; use think\Db;
@ -18,7 +20,7 @@ use think\Db;
class Customer extends ApiCommon class Customer extends ApiCommon
{ {
use StarTrait, SearchConditionTrait; use StarTrait, SearchConditionTrait;
/** /**
* 用于判断权限 * 用于判断权限
* @permission 无限制 * @permission 无限制
@ -41,7 +43,7 @@ class Customer extends ApiCommon
$this->param = $param; $this->param = $param;
} }
} }
/** /**
* 客户列表 * 客户列表
* @return * @return
@ -56,7 +58,7 @@ class Customer extends ApiCommon
$data = $customerModel->getDataList($param); $data = $customerModel->getDataList($param);
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
} }
/** /**
* 客户公海(没有负责人或已经到期) * 客户公海(没有负责人或已经到期)
* @return * @return
@ -70,7 +72,7 @@ class Customer extends ApiCommon
$data = model('Customer')->getDataList($param); $data = model('Customer')->getDataList($param);
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
} }
/** /**
* 添加客户 * 添加客户
* @param * @param
@ -91,7 +93,7 @@ class Customer extends ApiCommon
return resultArray(['error' => $customerModel->getError()]); return resultArray(['error' => $customerModel->getError()]);
} }
} }
/** /**
* 客户详情 * 客户详情
* @param * @param
@ -101,6 +103,7 @@ class Customer extends ApiCommon
public function read() public function read()
{ {
$customerModel = model('Customer'); $customerModel = model('Customer');
$cutomerLogic = new CustomerLogic();
$param = $this->param; $param = $this->param;
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$data = $customerModel->getDataById($param['id'], $userInfo['id']); $data = $customerModel->getDataById($param['id'], $userInfo['id']);
@ -116,13 +119,13 @@ 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]);
} }
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
} }
/** /**
* 编辑客户 * 编辑客户
* @param * @param
@ -139,7 +142,7 @@ class Customer extends ApiCommon
if (!$data) { if (!$data) {
return resultArray(['error' => $customerModel->getError()]); return resultArray(['error' => $customerModel->getError()]);
} }
$param['user_id'] = $userInfo['id']; $param['user_id'] = $userInfo['id'];
if ($customerModel->updateDataById($param, $param['id'])) { if ($customerModel->updateDataById($param, $param['id'])) {
return resultArray(['data' => '编辑成功']); return resultArray(['data' => '编辑成功']);
@ -147,7 +150,7 @@ class Customer extends ApiCommon
return resultArray(['error' => $customerModel->getError()]); return resultArray(['error' => $customerModel->getError()]);
} }
} }
/** /**
* 删除客户 * 删除客户
* @param * @param
@ -157,7 +160,7 @@ class Customer extends ApiCommon
public function delete() public function delete()
{ {
$param = $this->param; $param = $this->param;
$user=new ApiCommon(); $user = new ApiCommon();
$userInfo = $user->userInfo; $userInfo = $user->userInfo;
// 是否客户池 // 是否客户池
if ($param['isSeas'] == 1) { if ($param['isSeas'] == 1) {
@ -180,7 +183,7 @@ class Customer extends ApiCommon
} }
$delIds = []; $delIds = [];
$errorMessage = []; $errorMessage = [];
//数据权限判断 //数据权限判断
$auth_user_ids = $userModel->getUserByPer('crm', 'customer', 'delete'); $auth_user_ids = $userModel->getUserByPer('crm', 'customer', 'delete');
//判断是否客户池数据(客户池数据只有管理员可以删) //判断是否客户池数据(客户池数据只有管理员可以删)
@ -204,7 +207,7 @@ class Customer extends ApiCommon
// $isDel = false; // $isDel = false;
// $errorMessage[] = '名称为'.$data['name'].'的客户删除失败,错误原因:无权操作'; // $errorMessage[] = '名称为'.$data['name'].'的客户删除失败,错误原因:无权操作';
// } // }
//有商机、合同、联系人则不能删除 //有商机、合同、联系人则不能删除
if ($isDel) { if ($isDel) {
$resBusiness = db('crm_business')->where(['customer_id' => $v])->find(); $resBusiness = db('crm_business')->where(['customer_id' => $v])->find();
if ($resBusiness) { if ($resBusiness) {
@ -230,7 +233,7 @@ class Customer extends ApiCommon
$delIds[] = $v; $delIds[] = $v;
} }
} }
$dataInfo = $customerModel->where('customer_id',['in',$delIds])->select(); $dataInfo = $customerModel->where('customer_id', ['in', $delIds])->select();
if ($delIds) { if ($delIds) {
$delRes = $customerModel->delDatas($delIds); $delRes = $customerModel->delDatas($delIds);
if (!$delRes) { if (!$delRes) {
@ -254,7 +257,7 @@ class Customer extends ApiCommon
return resultArray(['data' => '删除成功']); return resultArray(['data' => '删除成功']);
} }
} }
/** /**
* 客户转移 * 客户转移
* @param owner_user_id 变更负责人 * @param owner_user_id 变更负责人
@ -275,7 +278,7 @@ class Customer extends ApiCommon
$settingModel = model('Setting'); $settingModel = model('Setting');
$customerConfigModel = model('CustomerConfig'); $customerConfigModel = model('CustomerConfig');
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
if (!$param['owner_user_id']) { if (!$param['owner_user_id']) {
return resultArray(['error' => '变更负责人不能为空']); return resultArray(['error' => '变更负责人不能为空']);
} }
@ -285,14 +288,14 @@ class Customer extends ApiCommon
$is_remove = ($param['is_remove'] == 2) ? 2 : 1; $is_remove = ($param['is_remove'] == 2) ? 2 : 1;
$type = $param['type'] == 2 ?: 1; $type = $param['type'] == 2 ?: 1;
$types = $param['types'] ?: []; $types = $param['types'] ?: [];
$data = []; $data = [];
$data['owner_user_id'] = $param['owner_user_id']; $data['owner_user_id'] = $param['owner_user_id'];
$data['update_time'] = time(); $data['update_time'] = time();
$data['follow'] = '待跟进'; $data['follow'] = '待跟进';
# 获取客户的时间 # 获取客户的时间
$data['obtain_time'] = time(); $data['obtain_time'] = time();
$ownerUserName = $userModel->getUserNameById($param['owner_user_id']); $ownerUserName = $userModel->getUserNameById($param['owner_user_id']);
$errorMessage = []; $errorMessage = [];
foreach ($param['customer_id'] as $customer_id) { foreach ($param['customer_id'] as $customer_id) {
@ -312,7 +315,7 @@ class Customer extends ApiCommon
$errorMessage[] = $customerInfo['name'] . '转移失败,错误原因:' . $customerConfigModel->getError(); $errorMessage[] = $customerInfo['name'] . '转移失败,错误原因:' . $customerConfigModel->getError();
continue; continue;
} }
//团队成员 //团队成员
$teamData = []; $teamData = [];
$teamData['type'] = $type; //权限 1只读2读写 $teamData['type'] = $type; //权限 1只读2读写
@ -324,7 +327,7 @@ class Customer extends ApiCommon
# 处理分配标识,待办事项专用 # 处理分配标识,待办事项专用
$data['is_allocation'] = 1; $data['is_allocation'] = 1;
$resCustomer = db('crm_customer')->where(['customer_id' => $customer_id])->update($data); $resCustomer = db('crm_customer')->where(['customer_id' => $customer_id])->update($data);
if (!$resCustomer) { if (!$resCustomer) {
$errorMessage[] = $customerInfo['name'] . '转移失败,错误原因:数据出错;'; $errorMessage[] = $customerInfo['name'] . '转移失败,错误原因:数据出错;';
@ -343,7 +346,7 @@ class Customer extends ApiCommon
} }
db('crm_customer')->where('customer_id', $customer_id)->update($customerArray); db('crm_customer')->where('customer_id', $customer_id)->update($customerArray);
} }
if (in_array('crm_contacts', $types)) { if (in_array('crm_contacts', $types)) {
$contactsIds = []; $contactsIds = [];
$contactsIds = db('crm_contacts')->where(['customer_id' => $customer_id])->column('contacts_id'); $contactsIds = db('crm_contacts')->where(['customer_id' => $customer_id])->column('contacts_id');
@ -355,7 +358,7 @@ class Customer extends ApiCommon
} }
} }
} }
//商机、合同转移 //商机、合同转移
if (in_array('crm_business', $types)) { if (in_array('crm_business', $types)) {
$businessIds = []; $businessIds = [];
@ -368,7 +371,7 @@ class Customer extends ApiCommon
} }
} }
} }
if (in_array('crm_contract', $types)) { if (in_array('crm_contract', $types)) {
$contractIds = []; $contractIds = [];
$contractIds = db('crm_contract')->where(['customer_id' => $customer_id])->column('contract_id'); $contractIds = db('crm_contract')->where(['customer_id' => $customer_id])->column('contract_id');
@ -382,7 +385,7 @@ class Customer extends ApiCommon
} }
//修改记录 //修改记录
updateActionLog($userInfo['id'], 'crm_customer', $customer_id, '', '', '将客户转移给:' . $ownerUserName); updateActionLog($userInfo['id'], 'crm_customer', $customer_id, '', '', '将客户转移给:' . $ownerUserName);
RecordActionLog($userInfo['id'], 'crm_customer', 'transfer',$customerInfo['name'], '','','将客户:'.$customerInfo['name'].'转移给:' . $ownerUserName); RecordActionLog($userInfo['id'], 'crm_customer', 'transfer', $customerInfo['name'], '', '', '将客户:' . $customerInfo['name'] . '转移给:' . $ownerUserName);
} }
if (!$errorMessage) { if (!$errorMessage) {
return resultArray(['data' => '转移成功']); return resultArray(['data' => '转移成功']);
@ -390,7 +393,7 @@ class Customer extends ApiCommon
return resultArray(['error' => $errorMessage]); return resultArray(['error' => $errorMessage]);
} }
} }
/** /**
* 客户放入公海(负责人置为0) * 客户放入公海(负责人置为0)
* @param * @param
@ -407,14 +410,14 @@ class Customer extends ApiCommon
$userId = $userInfo['id']; $userId = $userInfo['id'];
$customerIds = $this->param['customer_id']; $customerIds = $this->param['customer_id'];
$poolId = $this->param['pool_id']; $poolId = $this->param['pool_id'];
$customerModel=new \app\crm\model\Customer(); $customerModel = new \app\crm\model\Customer();
# 消息数据 # 消息数据
$message = []; $message = [];
# 获取客户数据 # 获取客户数据
$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'])->whereIn('customer_id', $customerIds)->select();
foreach ($customerList AS $key => $value) { foreach ($customerList as $key => $value) {
$customerData[$value['customer_id']] = $value; $customerData[$value['customer_id']] = $value;
} }
@ -424,8 +427,7 @@ class Customer extends ApiCommon
$poolRecordData = []; $poolRecordData = [];
$fieldRecordData = []; $fieldRecordData = [];
$operationLogData = []; $operationLogData = [];
foreach ($customerIds AS $key => $value) foreach ($customerIds as $key => $value) {
{
if (empty($customerData[$value])) { if (empty($customerData[$value])) {
$message[] = '将客户放入公海失败,错误原因:数据不存在!'; $message[] = '将客户放入公海失败,错误原因:数据不存在!';
unset($customerIds[(int)$key]); unset($customerIds[(int)$key]);
@ -458,19 +460,19 @@ class Customer extends ApiCommon
]; ];
# 字段操作记录数据 # 字段操作记录数据
$fieldRecordData[] = [ $fieldRecordData[] = [
'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()
]; ];
# 数据操作日志数据 # 数据操作日志数据
$operationLogData[] = [ $operationLogData[] = [
'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' => !empty($customerData[$value]['name']) ? $customerData[$value]['name'] : '' 'target_name' => !empty($customerData[$value]['name']) ? $customerData[$value]['name'] : ''
@ -488,16 +490,16 @@ class Customer extends ApiCommon
'owner_user_id' => 0, 'owner_user_id' => 0,
'into_pool_time' => time() 'into_pool_time' => time()
]); ]);
# 删除联系人的负责人 # 删除联系人的负责人
Db::name('crm_contacts')->whereIn('customer_id', $customerIds)->update(['owner_user_id' => 0]); Db::name('crm_contacts')->whereIn('customer_id', $customerIds)->update(['owner_user_id' => 0]);
# 将客户放入公海 # 将客户放入公海
Db::name('crm_customer_pool_relation')->insertAll($poolRelationData); Db::name('crm_customer_pool_relation')->insertAll($poolRelationData);
# 公海操作记录 # 公海操作记录
Db::name('crm_customer_pool_record')->insertAll($poolRecordData); Db::name('crm_customer_pool_record')->insertAll($poolRecordData);
# 字段操作记录 # 字段操作记录
Db::name('admin_action_record')->insertAll($fieldRecordData); Db::name('admin_action_record')->insertAll($fieldRecordData);
@ -557,7 +559,7 @@ class Customer extends ApiCommon
// return resultArray(['error' => $errorMessage]); // return resultArray(['error' => $errorMessage]);
// } // }
} }
/** /**
* 客户锁定,解锁 * 客户锁定,解锁
* @param is_lock 1锁定2解锁 * @param is_lock 1锁定2解锁
@ -599,18 +601,18 @@ class Customer extends ApiCommon
//已成交客户,锁定,提示无需锁定 //已成交客户,锁定,提示无需锁定
// if ($customerInfo['deal_status'] == '已成交' && $is_lock == 1) { // if ($customerInfo['deal_status'] == '已成交' && $is_lock == 1) {
// $errorMessage[] = $customerInfo['name'].$lock_name.'失败,错误原因:已成交状态,无需锁定'; // $errorMessage[] = $customerInfo['name'].$lock_name.'失败,错误原因:已成交状态,无需锁定';
// continue; // continue;
// } // }
$resCustomer = db('crm_customer')->where(['customer_id' => $customer_id])->update($data); $resCustomer = db('crm_customer')->where(['customer_id' => $customer_id])->update($data);
if (!$resCustomer) { if (!$resCustomer) {
$errorMessage[] = $customerInfo['name'] . $lock_name . '失败,错误原因:数据出错;'; $errorMessage[] = $customerInfo['name'] . $lock_name . '失败,错误原因:数据出错;';
} }
//修改记录 //修改记录
updateActionLog($userInfo['id'], 'crm_customer', $customer_id, '', '', '将客户' . $lock_name); updateActionLog($userInfo['id'], 'crm_customer', $customer_id, '', '', '将客户' . $lock_name);
if($is_lock == 2){ if ($is_lock == 2) {
RecordActionLog($userInfo['id'], 'crm_customer', 'islock',$customerInfo['name'], '','','将客户'.$customerInfo['name'].$lock_name ); RecordActionLog($userInfo['id'], 'crm_customer', 'islock', $customerInfo['name'], '', '', '将客户' . $customerInfo['name'] . $lock_name);
}else{ } else {
RecordActionLog($userInfo['id'], 'crm_customer', 'lock',$customerInfo['name'], '','','将客户'.$customerInfo['name'].$lock_name ); RecordActionLog($userInfo['id'], 'crm_customer', 'lock', $customerInfo['name'], '', '', '将客户' . $customerInfo['name'] . $lock_name);
} }
} }
if (!$errorMessage) { if (!$errorMessage) {
@ -619,7 +621,7 @@ class Customer extends ApiCommon
return resultArray(['error' => $errorMessage]); return resultArray(['error' => $errorMessage]);
} }
} }
/** /**
* 客户领取 * 客户领取
* @param * @param
@ -632,7 +634,7 @@ class Customer extends ApiCommon
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$customerModel = model('Customer'); $customerModel = model('Customer');
$customerConfigModel = model('CustomerConfig'); $customerConfigModel = model('CustomerConfig');
$customer_ids = $param['customer_id'] ?: $userInfo['id']; $customer_ids = $param['customer_id'] ?: $userInfo['id'];
if (!$customer_ids || !is_array($customer_ids)) { if (!$customer_ids || !is_array($customer_ids)) {
return resultArray(['error' => '请选择需要领取的客户']); return resultArray(['error' => '请选择需要领取的客户']);
@ -671,7 +673,7 @@ class Customer extends ApiCommon
db('crm_contacts')->where(['customer_id' => $v])->update(['owner_user_id' => $userInfo['id']]); db('crm_contacts')->where(['customer_id' => $v])->update(['owner_user_id' => $userInfo['id']]);
//修改记录 //修改记录
updateActionLog($userInfo['id'], 'crm_customer', $v, '', '', '领取了客户'); updateActionLog($userInfo['id'], 'crm_customer', $v, '', '', '领取了客户');
RecordActionLog($userInfo['id'], 'crm_customer', 'update',$dataName, '','','领取了客户:'.$dataName); RecordActionLog($userInfo['id'], 'crm_customer', 'update', $dataName, '', '', '领取了客户:' . $dataName);
} }
if (!$errorMessage) { if (!$errorMessage) {
return resultArray(['data' => '领取成功']); return resultArray(['data' => '领取成功']);
@ -679,7 +681,7 @@ class Customer extends ApiCommon
return resultArray(['error' => $errorMessage]); return resultArray(['error' => $errorMessage]);
} }
} }
/** /**
* 客户分配 * 客户分配
* @param * @param
@ -693,7 +695,7 @@ class Customer extends ApiCommon
$customerModel = model('Customer'); $customerModel = model('Customer');
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$customerConfigModel = model('CustomerConfig'); $customerConfigModel = model('CustomerConfig');
$customer_ids = $param['customer_id']; $customer_ids = $param['customer_id'];
$owner_user_id = $param['owner_user_id']; $owner_user_id = $param['owner_user_id'];
if (!$customer_ids || !is_array($customer_ids)) { if (!$customer_ids || !is_array($customer_ids)) {
@ -703,7 +705,7 @@ class Customer extends ApiCommon
return resultArray(['error' => '请选择分配人']); return resultArray(['error' => '请选择分配人']);
} }
$ownerUserName = $userModel->getUserNameById($owner_user_id); $ownerUserName = $userModel->getUserNameById($owner_user_id);
$errorMessage = []; $errorMessage = [];
$wherePool = $customerModel->getWhereByPool(); $wherePool = $customerModel->getWhereByPool();
foreach ($customer_ids as $k => $v) { foreach ($customer_ids as $k => $v) {
@ -738,7 +740,7 @@ class Customer extends ApiCommon
db('crm_contacts')->where(['customer_id' => $v])->update(['owner_user_id' => $owner_user_id]); db('crm_contacts')->where(['customer_id' => $v])->update(['owner_user_id' => $owner_user_id]);
//修改记录 //修改记录
updateActionLog($userInfo['id'], 'crm_customer', $v, '', '', '将客户分配给:' . $ownerUserName); updateActionLog($userInfo['id'], 'crm_customer', $v, '', '', '将客户分配给:' . $ownerUserName);
RecordActionLog($userInfo['id'], 'crm_customer', 'distribute',$dataName, '','','将客户'.$dataName.'分配给:' . $ownerUserName); RecordActionLog($userInfo['id'], 'crm_customer', 'distribute', $dataName, '', '', '将客户' . $dataName . '分配给:' . $ownerUserName);
//站内信 //站内信
$send_user_id[] = $owner_user_id; $send_user_id[] = $owner_user_id;
$sendContent = $userInfo['realname'] . '将客户《' . $dataName . '》,分配给您'; $sendContent = $userInfo['realname'] . '将客户《' . $dataName . '》,分配给您';
@ -752,7 +754,7 @@ class Customer extends ApiCommon
return resultArray(['error' => $errorMessage]); return resultArray(['error' => $errorMessage]);
} }
} }
/** /**
* 客户导出 * 客户导出
* @param * @param
@ -764,26 +766,26 @@ class Customer extends ApiCommon
$param = $this->param; $param = $this->param;
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$param['user_id'] = $userInfo['id']; $param['user_id'] = $userInfo['id'];
$action_name='导出全部'; $action_name = '导出全部';
if ($param['customer_id']) { if ($param['customer_id']) {
$param['customer_id'] = ['condition' => 'in', 'value' => $param['customer_id'], 'form_type' => 'text', 'name' => '']; $param['customer_id'] = ['condition' => 'in', 'value' => $param['customer_id'], 'form_type' => 'text', 'name' => ''];
$action_name='导出选中'; $action_name = '导出选中';
} }
$param['is_excel'] = 1; $param['is_excel'] = 1;
$excelModel = new \app\admin\model\Excel(); $excelModel = new \app\admin\model\Excel();
// 导出的字段列表 // 导出的字段列表
$fieldModel = new \app\admin\model\Field(); $fieldModel = new \app\admin\model\Field();
$field_list = $fieldModel->getIndexFieldConfig('crm_customer', $userInfo['id'],'','excel'); $field_list = $fieldModel->getIndexFieldConfig('crm_customer', $userInfo['id'], '', 'excel');
// 文件名 // 文件名
$file_name = '5kcrm_customer_' . date('Ymd'); $file_name = '5kcrm_customer_' . date('Ymd');
$model = model('Customer'); $model = model('Customer');
$temp_file = $param['temp_file']; $temp_file = $param['temp_file'];
unset($param['temp_file']); unset($param['temp_file']);
$page = $param['page'] ?: 1; $page = $param['page'] ?: 1;
unset($param['page']); unset($param['page']);
unset($param['export_queue_index']); unset($param['export_queue_index']);
RecordActionLog($userInfo['id'],'crm_customer','excelexport',$action_name,'','','导出客户'); RecordActionLog($userInfo['id'], 'crm_customer', 'excelexport', $action_name, '', '', '导出客户');
return $excelModel->batchExportCsv($file_name, $temp_file, $field_list, $page, function ($page, $limit) use ($model, $param, $field_list) { return $excelModel->batchExportCsv($file_name, $temp_file, $field_list, $page, function ($page, $limit) use ($model, $param, $field_list) {
$param['page'] = $page; $param['page'] = $page;
$param['limit'] = $limit; $param['limit'] = $limit;
@ -791,9 +793,9 @@ class Customer extends ApiCommon
$data['list'] = $model->exportHandle($data['list'], $field_list, 'customer'); $data['list'] = $model->exportHandle($data['list'], $field_list, 'customer');
return $data; return $data;
}); });
} }
/** /**
* 客户导入模板下载 * 客户导入模板下载
* @param string $save_path 本地保存路径 用于错误数据导出,在 Admin\Model\Excel::batchImportData()调用 * @param string $save_path 本地保存路径 用于错误数据导出,在 Admin\Model\Excel::batchImportData()调用
@ -811,24 +813,24 @@ class Customer extends ApiCommon
$fieldParam['types'] = 'crm_customer'; $fieldParam['types'] = 'crm_customer';
$fieldParam['action'] = 'excel'; $fieldParam['action'] = 'excel';
$field_list = $fieldModel->field($fieldParam); $field_list = $fieldModel->field($fieldParam);
$field=[1=>[ $field = [1 => [
'field'=>'owner_user_id', 'field' => 'owner_user_id',
'types'=>'crm_customer', 'types' => 'crm_customer',
'name'=>'负责人', 'name' => '负责人',
'form_type'=>'user', 'form_type' => 'user',
'default_value'=>'', 'default_value' => '',
'is_null' => 1, 'is_null' => 1,
'input_tips' =>'', 'input_tips' => '',
'setting' => Array(), 'setting' => array(),
'is_hidden'=>0, 'is_hidden' => 0,
'writeStatus' => 1, 'writeStatus' => 1,
'value' => ''] 'value' => '']
]; ];
$first_array = array_splice($field_list, 2,0, $field); $first_array = array_splice($field_list, 2, 0, $field);
$excelModel->excelImportDownload($field_list, 'crm_customer', $save_path); $excelModel->excelImportDownload($field_list, 'crm_customer', $save_path);
} }
/** /**
* 客户数据导入 * 客户数据导入
* @param * @param
@ -848,10 +850,10 @@ class Customer extends ApiCommon
$file = request()->file('file'); $file = request()->file('file');
// $res = $excelModel->importExcel($file, $param, $this); // $res = $excelModel->importExcel($file, $param, $this);
$res = $excelModel->batchImportData($file, $param, $this); $res = $excelModel->batchImportData($file, $param, $this);
RecordActionLog($userInfo['id'],'crm_customer','excel','导入客户','','','导入客户'); RecordActionLog($userInfo['id'], 'crm_customer', 'excel', '导入客户', '', '', '导入客户');
return resultArray(['data' => $excelModel->getError()]); return resultArray(['data' => $excelModel->getError()]);
} }
/** /**
* 客户标记为已跟进 * 客户标记为已跟进
* @param * @param
@ -873,18 +875,19 @@ class Customer extends ApiCommon
} }
return resultArray(['data' => '跟进成功']); return resultArray(['data' => '跟进成功']);
} }
/** /**
* 置顶 / 取消置顶 * 置顶 / 取消置顶
* @return [type] [description] * @return [type] [description]
*/ */
public function top() public function top()
{ {
$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'];
$param['top_time'] = time(); $param['top_time'] = time();
$top_id = Db::name('crm_top')->where(['module' => ['eq', $param['module']], 'create_role_id' => ['eq', $userInfo['id']], 'module_id' => ['eq', $param['module_id']]])->column('top_id'); $top_id = Db::name('crm_top')->where(['module' => ['eq', $param['module']], 'create_role_id' => ['eq', $userInfo['id']], 'module_id' => ['eq', $param['module_id']]])->column('top_id');
if ($top_id) { if ($top_id) {
if ($res = Db::name('crm_top')->where('top_id', $top_id[0])->update($param)) { if ($res = Db::name('crm_top')->where('top_id', $top_id[0])->update($param)) {
@ -900,50 +903,7 @@ class Customer extends ApiCommon
} }
} }
} }
/**
* 客户公海导出
* @param
* @return
* @author Michael_xu
*/
public function poolExcelExport()
{
$param = $this->param;
$userInfo = $this->userInfo;
$param['user_id'] = $userInfo['id'];
if ($param['customer_id']) {
$param['customer_id'] = ['condition' => 'in', 'value' => $param['customer_id'], 'form_type' => 'text', 'name' => ''];
$action_name='导出选中';
}
$param['is_excel'] = 1;
$excelModel = new \app\admin\model\Excel();
// 导出的字段列表
$fieldModel = new \app\admin\model\Field();
$field_list = $fieldModel->getIndexFieldConfig('crm_customer', $userInfo['id']);
$field_list = array_filter($field_list, function ($val) {
return $val['field'] != 'owner_user_id';
});
// 文件名
$file_name = '5kcrm_customer_pool_' . date('Ymd');
$param['action'] = 'pool';
$model = model('Customer');
$temp_file = $param['temp_file'];
unset($param['temp_file']);
$page = $param['page'] ?: 1;
unset($param['page']);
unset($param['export_queue_index']);
RecordActionLog($userInfo['id'],'crm_customer','excelexport',$action_name,'','','导出客户');
return $excelModel->batchExportCsv($file_name, $temp_file, $field_list, $page, function ($page, $limit) use ($model, $param) {
$param['page'] = $page;
$param['limit'] = $limit;
$data = $model->getDataList($param);
$data['list'] = $model->exportHandle($data['list'], $field_list,'crm_customer');
return $data;
});
}
/** /**
* 客户成交状态 * 客户成交状态
* @param status 1已成交,2未成交 * @param status 1已成交,2未成交
@ -1001,10 +961,10 @@ class Customer extends ApiCommon
} }
//修改记录 //修改记录
updateActionLog($userInfo['id'], 'crm_customer', $customer_id, ['deal_status' => $dataInfo['deal_status']], ['deal_status' => $data['deal_status']]); updateActionLog($userInfo['id'], 'crm_customer', $customer_id, ['deal_status' => $dataInfo['deal_status']], ['deal_status' => $data['deal_status']]);
if($param['status']==1){ if ($param['status'] == 1) {
RecordActionLog($userInfo['id'], 'crm_customer', 'status',$dataInfo['name'], '','','修改客户:'.$dataInfo['name'].'成交状态:'.$statusArr[$param['status']]); RecordActionLog($userInfo['id'], 'crm_customer', 'status', $dataInfo['name'], '', '', '修改客户:' . $dataInfo['name'] . '成交状态:' . $statusArr[$param['status']]);
}else{ } else {
RecordActionLog($userInfo['id'], 'crm_customer', 'status',$dataInfo['name'], '','','修改客户:'.$dataInfo['name'].'成交状态:'.$statusArr[$param['status']]); RecordActionLog($userInfo['id'], 'crm_customer', 'status', $dataInfo['name'], '', '', '修改客户:' . $dataInfo['name'] . '成交状态:' . $statusArr[$param['status']]);
} }
} }
if (!$errorMessage) { if (!$errorMessage) {
@ -1013,7 +973,7 @@ class Customer extends ApiCommon
return resultArray(['error' => $errorMessage]); return resultArray(['error' => $errorMessage]);
} }
} }
/** /**
* 设置关注 * 设置关注
* *
@ -1026,16 +986,16 @@ class Customer extends ApiCommon
$userId = $this->userInfo['id']; $userId = $this->userInfo['id'];
$targetId = $this->param['target_id']; $targetId = $this->param['target_id'];
$type = $this->param['type']; $type = $this->param['type'];
if (empty($userId) || empty($targetId) || empty($type)) return resultArray(['error' => '缺少必要参数!']); if (empty($userId) || empty($targetId) || empty($type)) return resultArray(['error' => '缺少必要参数!']);
if (!$this->setStar($type, $userId, $targetId)) { if (!$this->setStar($type, $userId, $targetId)) {
return resultArray(['error' => '设置关注失败!']); return resultArray(['error' => '设置关注失败!']);
} }
return resultArray(['data' => '设置关注成功!']); return resultArray(['data' => '设置关注成功!']);
} }
/** /**
* 附近客户 * 附近客户
* *
@ -1046,14 +1006,14 @@ class Customer extends ApiCommon
if (empty($this->param['lng'])) return resultArray(['error' => '缺少经度参数!']); if (empty($this->param['lng'])) return resultArray(['error' => '缺少经度参数!']);
if (empty($this->param['lat'])) return resultArray(['error' => '缺少纬度参数!']); if (empty($this->param['lat'])) return resultArray(['error' => '缺少纬度参数!']);
if (empty($this->param['distance'])) return resultArray(['error' => '请选择距离!']); if (empty($this->param['distance'])) return resultArray(['error' => '请选择距离!']);
$customerModel = model('Customer'); $customerModel = model('Customer');
$data = $customerModel->getNearbyList($this->param); $data = $customerModel->getNearbyList($this->param);
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
} }
/** /**
* 系统信息 * 系统信息
* *
@ -1065,14 +1025,14 @@ class Customer extends ApiCommon
public function system() public function system()
{ {
if (empty($this->param['id'])) return resultArray(['error' => '参数错误!']); if (empty($this->param['id'])) return resultArray(['error' => '参数错误!']);
$customerModel = new \app\crm\model\Customer(); $customerModel = new \app\crm\model\Customer();
$data = $customerModel->getSystemInfo($this->param['id']); $data = $customerModel->getSystemInfo($this->param['id']);
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
} }
/** /**
* table标签栏数量 * table标签栏数量
* *
@ -1086,9 +1046,9 @@ class Customer extends ApiCommon
if (empty($this->param['customer_id'])) return resultArray(['error' => '参数错误!']); if (empty($this->param['customer_id'])) return resultArray(['error' => '参数错误!']);
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$customerId = $this->param['customer_id']; $customerId = $this->param['customer_id'];
# 联系人 # 联系人
$contactsAuth = $this->getContactsSearchWhere($userInfo['id']); $contactsAuth = $this->getContactsSearchWhere($userInfo['id']);
$contactsCount = Db::name('crm_contacts')->where('customer_id', $customerId)->where($contactsAuth)->count(); $contactsCount = Db::name('crm_contacts')->where('customer_id', $customerId)->where($contactsAuth)->count();
@ -1122,21 +1082,21 @@ class Customer extends ApiCommon
# 附件 # 附件
$fileCount = Db::name('crm_customer_file')->alias('customer')->join('__ADMIN_FILE__ file', 'file.file_id = customer.file_id')->where('customer_id', $customerId)->count(); $fileCount = Db::name('crm_customer_file')->alias('customer')->join('__ADMIN_FILE__ file', 'file.file_id = customer.file_id')->where('customer_id', $customerId)->count();
$data = [ $data = [
'businessCount' => $businessCount, 'businessCount' => $businessCount,
'contactCount' => $contactsCount, 'contactCount' => $contactsCount,
'contractCount' => $contractCount, 'contractCount' => $contractCount,
'fileCount' => $fileCount, 'fileCount' => $fileCount,
'invoiceCount' => $invoiceCount, 'invoiceCount' => $invoiceCount,
'memberCount' => count($teamCount), 'memberCount' => count($teamCount),
'receivablesCount' => $receivablesCount, 'receivablesCount' => $receivablesCount,
'returnVisitCount' => $visitCount 'returnVisitCount' => $visitCount
]; ];
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
} }
/** /**
* 公海权限 * 公海权限
* *
@ -1155,18 +1115,18 @@ class Customer extends ApiCommon
'index' => false, # 列表 'index' => false, # 列表
'receive' => false, # 领取 'receive' => false, # 领取
]; ];
$userId = $this->userInfo['id']; $userId = $this->userInfo['id'];
if (empty($userId)) return resultArray(['data' => $authority]); if (empty($userId)) return resultArray(['data' => $authority]);
# 员工角色数据 # 员工角色数据
$groupIds = $customerLogic->getEmployeeGroups($userId); $groupIds = $customerLogic->getEmployeeGroups($userId);
# 员工角色下的规则数据 # 员工角色下的规则数据
$ruleIds = $customerLogic->getEmployeeRules($groupIds); $ruleIds = $customerLogic->getEmployeeRules($groupIds);
# 公海规则数据 # 公海规则数据
$poolRules = $customerLogic->getPoolRules(); $poolRules = $customerLogic->getPoolRules();
# 整理员工规则数据 # 整理员工规则数据
$rules = []; $rules = [];
$ruleIds = implode(',', $ruleIds); $ruleIds = implode(',', $ruleIds);
@ -1180,23 +1140,23 @@ class Customer extends ApiCommon
if ($value['name'] == 'poolExcelExport') $exportId = $value['id']; if ($value['name'] == 'poolExcelExport') $exportId = $value['id'];
if ($value['name'] == 'poolDelete') $deleteId = $value['id']; if ($value['name'] == 'poolDelete') $deleteId = $value['id'];
} }
# 权限判断 # 权限判断
$authority['delete'] = $userId == 1 || in_array(1, $groupIds) || in_array($deleteId, $rules) ? true : false; $authority['delete'] = $userId == 1 || in_array(1, $groupIds) || in_array($deleteId, $rules) ? true : false;
$authority['distribute'] = $userId == 1 || in_array(1, $groupIds) || in_array($distributeId, $rules) ? true : false; $authority['distribute'] = $userId == 1 || in_array(1, $groupIds) || in_array($distributeId, $rules) ? true : false;
$authority['excelexport'] = $userId == 1 || in_array(1, $groupIds) || in_array($exportId, $rules) ? true : false; $authority['excelexport'] = $userId == 1 || in_array(1, $groupIds) || in_array($exportId, $rules) ? true : false;
$authority['index'] = $userId == 1 || in_array(1, $groupIds) || in_array($indexId, $rules) ? true : false; $authority['index'] = $userId == 1 || in_array(1, $groupIds) || in_array($indexId, $rules) ? true : false;
$authority['receive'] = $userId == 1 || in_array(1, $groupIds) || in_array($receiveId, $rules) ? true : false; $authority['receive'] = $userId == 1 || in_array(1, $groupIds) || in_array($receiveId, $rules) ? true : false;
return resultArray(['data' => $authority]); return resultArray(['data' => $authority]);
} }
/** /**
* 客户级别列表 * 客户级别列表
* *
* @author fanqi
* @since 2021-03-29
* @return \think\response\Json * @return \think\response\Json
* @since 2021-03-29
* @author fanqi
*/ */
public function level() public function level()
{ {

@ -371,7 +371,9 @@ class CustomerPool extends ApiCommon
} }
break; break;
case 'detail_address': case 'detail_address':
unset($pool_list[$k]); if($param['is_excel']!=1){
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();

@ -309,7 +309,7 @@ class Index extends ApiCommon
foreach ($time['list'] as $val) { foreach ($time['list'] as $val) {
$item = []; $item = [];
$item['type'] = $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'];

@ -135,7 +135,7 @@ class Invoice extends ApiCommon
$param['check_user_id'] = is_array($check_user_id) ? ',' . implode(',', $check_user_id) . ',' : $check_user_id; $param['check_user_id'] = is_array($check_user_id) ? ',' . implode(',', $check_user_id) . ',' : $check_user_id;
} else { } else {
# 审批流停用,将状态改为审核通过 # 审批流停用,将状态改为审核通过
$param['check_status'] = 2; $param['check_status'] = 7;
} }
// 数据验证 // 数据验证
@ -350,7 +350,7 @@ class Invoice extends ApiCommon
// } // }
$checkStatus = $invoiceLogic->getExamineStatus($param['invoice_id']); $checkStatus = $invoiceLogic->getExamineStatus($param['invoice_id']);
if (!in_array($checkStatus, ['3', '4', '5', '6'])) return resultArray(['error' => '当前状态为审批中或已审批通过,不可编辑']); if (!in_array($checkStatus, ['3', '4', '5', '6', '7']) && $checkStatus!=0) return resultArray(['error' => '当前状态为审批中或已审批通过,不可编辑']);
# 自动设置发票编号 # 自动设置发票编号
$numberInfo = []; $numberInfo = [];

@ -233,6 +233,7 @@ class Leads extends ApiCommon
$data['create_time'] = time(); $data['create_time'] = time();
$data['update_time'] = time(); $data['update_time'] = time();
$data['next_time'] = $leadsInfo['next_time']; $data['next_time'] = $leadsInfo['next_time'];
if (empty($data['telephone'])) $data['telephone'] = 0; if (empty($data['telephone'])) $data['telephone'] = 0;
# 获取客户的时间 # 获取客户的时间
$data['obtain_time'] = time(); $data['obtain_time'] = time();
@ -245,7 +246,9 @@ class Leads extends ApiCommon
$errorMessage[] = '线索《' . $leadsInfo['name'] . '》转化失败,错误原因:无权限;'; $errorMessage[] = '线索《' . $leadsInfo['name'] . '》转化失败,错误原因:无权限;';
continue; continue;
} }
$resCustomer = $customerModel->createData($data); $resCustomer = $customerModel->createData($data);
if (!$resCustomer) { if (!$resCustomer) {
$errorMessage[] = '线索《' . $leadsInfo['name'] . '》转化失败,错误原因:' . $customerModel->getError(); $errorMessage[] = '线索《' . $leadsInfo['name'] . '》转化失败,错误原因:' . $customerModel->getError();
continue; continue;

@ -490,11 +490,12 @@ class Message extends ApiCommon
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'] = 1; $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());
if ($types == 'list') { if ($types == 'list') {
return resultArray(['data' => $data]); return resultArray(['data' => $data]);
} }

@ -74,7 +74,7 @@ class Receivables extends ApiCommon
$excelModel = new \app\admin\model\Excel(); $excelModel = new \app\admin\model\Excel();
// 导出的字段列表 // 导出的字段列表
$fieldModel = new \app\admin\model\Field(); $fieldModel = new \app\admin\model\Field();
$field_list = $fieldModel->getIndexFieldConfig('crm_receivables', $userInfo['id']); $field_list = $fieldModel->getIndexFieldConfig('crm_receivables', $userInfo['id'],'','excel');
// 文件名 // 文件名
$file_name = '5kcrm_receivables_' . date('Ymd'); $file_name = '5kcrm_receivables_' . date('Ymd');
$model = model('Receivables'); $model = model('Receivables');
@ -148,7 +148,10 @@ class Receivables extends ApiCommon
$param['check_user_id'] = is_array($check_user_id) ? ',' . implode(',', $check_user_id) . ',' : $check_user_id; $param['check_user_id'] = is_array($check_user_id) ? ',' . implode(',', $check_user_id) . ',' : $check_user_id;
} else { } else {
# 审批流停用,将状态改为审核通过 # 审批流停用,将状态改为审核通过
$param['check_status'] = 2; // $param['check_status'] = 2;
# 审批流停用,将状态改为正常 zjf 20210727 默认值为7
$param['check_status'] = 7;
} }
$res = $receivablesModel->createData($param); $res = $receivablesModel->createData($param);
@ -224,7 +227,7 @@ class Receivables extends ApiCommon
} }
//已进行审批,不能编辑 //已进行审批,不能编辑
if (!in_array($dataInfo['check_status'], ['3', '4', '5', '6'])) { if (!in_array($dataInfo['check_status'], ['3', '4', '5', '6', '7']) && $dataInfo['check_status']!=0) {
return resultArray(['error' => '当前状态为审批中或已审批通过,不可编辑']); return resultArray(['error' => '当前状态为审批中或已审批通过,不可编辑']);
} }
@ -271,7 +274,6 @@ class Receivables extends ApiCommon
} }
} }
} }
$res = $receivablesModel->updateDataById($param, $param['id']); $res = $receivablesModel->updateDataById($param, $param['id']);
if ($res) { if ($res) {
//将审批记录至为无效 //将审批记录至为无效
@ -474,7 +476,19 @@ class Receivables extends ApiCommon
//审批记录 //审批记录
$resRecord = $examineRecordModel->createData($checkData); $resRecord = $examineRecordModel->createData($checkData);
$receivablesPlan=db('crm_receivables_plan')->where('receivables_id',$param['id'])->find();
$data=[];
$data['un_money']=$receivablesPlan['real_money']-$dataInfo['money'] <= 0 ? 0 :$receivablesPlan['un_money']-$dataInfo['money'];
$data['real_money']=$receivablesPlan['real_money']-$dataInfo['money'] <= 0 ?$dataInfo['money']:$receivablesPlan['real_money']-$dataInfo['money'];
$data['real_data']=date('Y-m-d',time());
if( $data['un_money']==0){
$data['status']=1;
}else{
$data['status']=2;
}
if(!db('crm_receivables_plan')->where('receivables_id',$param['id'])->update($data)){
return resultArray(['data' => '审批失败,未更新回款计划信息!']);
}
if ($is_end == 1 && !empty($status)) { if ($is_end == 1 && !empty($status)) {
//发送站内信 通过 //发送站内信 通过
(new Message())->send( (new Message())->send(

@ -161,5 +161,42 @@ class ReceivablesPlan extends ApiCommon
} else { } else {
return resultArray(['error'=>'参数错误']); return resultArray(['error'=>'参数错误']);
} }
} }
/**
* 回款计划导出
* @param
* @return
* @author Michael_xu
*/
public function excelExport()
{
$param = $this->param;
$userInfo = $this->userInfo;
$param['user_id'] = $userInfo['id'];
$action_name = '导出全部';
if ($param['plan_id']) {
$param['plan_id'] = ['condition' => 'in', 'value' => $param['plan_id'], 'form_type' => 'text', 'name' => ''];
$action_name='导出选中';
}
$excelModel = new \app\admin\model\Excel();
// 导出的字段列表
$fieldModel = new \app\admin\model\Field();
$field_list = $fieldModel->getIndexFieldConfig('crm_receivables_plan', $userInfo['id'],'','excel');
// 文件名
$file_name = '5kcrm_receivables_plan_' . date('Ymd');
$model = model('ReceivablesPlan');
$temp_file = $param['temp_file'];
unset($param['temp_file']);
$page = $param['page'] ?: 1;
unset($param['page']);
unset($param['export_queue_index']);
// RecordActionLog($userInfo['id'],'crm_receivables_plan','excelexport',$action_name,'','','导出回款');
return $excelModel->batchExportCsv($file_name, $temp_file, $field_list, $page, function ($page, $limit) use ($model, $param, $field_list) {
$param['page'] = $page;
$param['limit'] = $limit;
$data = $model->getDataList($param);
$data['list'] = $model->exportHandle($data['list'], $field_list, 'ReceivablesPlan');
return $data;
});
}
} }

@ -442,13 +442,15 @@ class ActivityLogic
$param['type'] = 1; $param['type'] = 1;
$param['next_time'] = !empty($param['next_time']) ? strtotime($param['next_time']) : 0; $param['next_time'] = !empty($param['next_time']) ? strtotime($param['next_time']) : 0;
$param['business_ids'] = !empty($param['business_ids']) ? arrayToString($param['business_ids']) : ''; $param['business_ids'] = !empty($param['business_ids']) ? arrayToString($param['business_ids']) : '';
$param['create_time'] = time();
$param['update_time'] = time(); $param['update_time'] = time();
if(empty($param['excel'])){ if(empty($param['excel'])){
if (!empty($param['contacts_ids'])) $param['contacts_ids'] = ',' . $param['contacts_ids'] . ','; if (!empty($param['contacts_ids'])) $param['contacts_ids'] = ',' . $param['contacts_ids'] . ',';
}else{ }else{
$param['create_time'] = $param['create_time'];
unset($param['excel']); unset($param['excel']);
} }
$activityJson = Activity::create($param); $activityJson = Activity::create($param);
if (empty($activityJson)) return false; if (empty($activityJson)) return false;

@ -22,7 +22,7 @@ class IndexLogic extends Common
'11' => 'november', '11' => 'november',
'12' => 'december', '12' => 'december',
]; ];
/** /**
* @param $param * @param $param
* @return array * @return array
@ -31,22 +31,15 @@ class IndexLogic extends Common
{ {
$adminModel = new \app\admin\model\Admin(); $adminModel = new \app\admin\model\Admin();
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$customerModel = new \app\crm\model\Customer();
$contactsModel = new \app\crm\model\Contacts();
$businessModel = new \app\crm\model\Business();
$contractModel = new \app\crm\model\Contract();
$receivablesModel = new \app\crm\model\Receivables();
$activityModel = new \app\crm\model\Activity();
$last_between_time = ByDateTime($param['type']); $last_between_time = ByDateTime($param['type']);
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, ''); //统计条件
// $lastArr = $adminModel->getWhere($param, 1, '', true); //统计条件
$userIds = $whereArr['userIds']; $userIds = $whereArr['userIds'];
$between_time = $whereArr['between_time']; $between_time = $whereArr['between_time'];
$customerNum = 0; //新增客户 $customerNum = 0; //新增客户
$customerLastNum = 0; //上期对比 $customerLastNum = 0; //上期对比
$contactsNum = 0; //新增联系人 $contactsNum = 0; //新增联系人
@ -63,13 +56,13 @@ class IndexLogic extends Common
$contractLastMoneyNum = 0; //上期对比 $contractLastMoneyNum = 0; //上期对比
$receivablesMoneyNum = 0; //新增回款金额 $receivablesMoneyNum = 0; //新增回款金额
$receivablesLastMoneyNum = 0; //上期对比 $receivablesLastMoneyNum = 0; //上期对比
$where = []; $where = [];
$where['owner_user_id']['value'] = $userIds; $where['owner_user_id']['value'] = $userIds;
$where['create_time']['start'] = $between_time[0]; $where['create_time']['start'] = $between_time[0];
$where['create_time']['end'] = $between_time[1]; $where['create_time']['end'] = $between_time[1];
$where['getCount'] = 1; $where['getCount'] = 1;
$customer_auth_user_ids = $userModel->getUserByPer('crm', 'customer', 'index'); $customer_auth_user_ids = $userModel->getUserByPer('crm', 'customer', 'index');
$contacts_auth_user_ids = $userModel->getUserByPer('crm', 'contacts', 'index'); $contacts_auth_user_ids = $userModel->getUserByPer('crm', 'contacts', 'index');
$business_auth_user_ids = $userModel->getUserByPer('crm', 'business', 'index'); $business_auth_user_ids = $userModel->getUserByPer('crm', 'business', 'index');
@ -100,7 +93,7 @@ class IndexLogic extends Common
'record_auth_user_ids' => array_intersect($userIds, $record_auth_user_ids) ? : [-1], 'record_auth_user_ids' => array_intersect($userIds, $record_auth_user_ids) ? : [-1],
]) ])
); );
$customerNum = (int)$resCount[0]['count1'] ?: 0; $customerNum = (int)$resCount[0]['count1'] ?: 0;
$contactsNum = (int)$resCount[1]['count1'] ?: 0; $contactsNum = (int)$resCount[1]['count1'] ?: 0;
$businessNum = (int)$resCount[2]['count1'] ?: 0; $businessNum = (int)$resCount[2]['count1'] ?: 0;
@ -109,7 +102,7 @@ class IndexLogic extends Common
$contractMoneyNum = $resCount[3]['count2'] ?: 0; $contractMoneyNum = $resCount[3]['count2'] ?: 0;
$receivablesMoneyNum = $resCount[4]['count1'] ?: 0; $receivablesMoneyNum = $resCount[4]['count1'] ?: 0;
$recordNum = (int)$resCount[5]['count1'] ?: 0; $recordNum = (int)$resCount[5]['count1'] ?: 0;
$customerLastNum = (int)$resLastCount[0]['count1'] ?: 0; $customerLastNum = (int)$resLastCount[0]['count1'] ?: 0;
$contactsLastNum = (int)$resLastCount[1]['count1'] ?: 0; $contactsLastNum = (int)$resLastCount[1]['count1'] ?: 0;
$businessLastNum = (int)$resLastCount[2]['count1'] ?: 0; $businessLastNum = (int)$resLastCount[2]['count1'] ?: 0;
@ -121,31 +114,31 @@ class IndexLogic extends Common
$data = []; $data = [];
$data['data']['customerNum'] = $customerNum; $data['data']['customerNum'] = $customerNum;
$data['prev']['customerNum'] = $this->getProportion($customerNum, $customerLastNum); $data['prev']['customerNum'] = $this->getProportion($customerNum, $customerLastNum);
$data['data']['contactsNum'] = $contactsNum; $data['data']['contactsNum'] = $contactsNum;
$data['prev']['contactsNum'] = $this->getProportion($contactsNum, $contactsLastNum); $data['prev']['contactsNum'] = $this->getProportion($contactsNum, $contactsLastNum);
$data['data']['businessNum'] = $businessNum; $data['data']['businessNum'] = $businessNum;
$data['prev']['businessNum'] = $this->getProportion($businessNum, $businessLastNum); $data['prev']['businessNum'] = $this->getProportion($businessNum, $businessLastNum);
$data['data']['contractNum'] = $contractNum; $data['data']['contractNum'] = $contractNum;
$data['prev']['contractNum'] = $this->getProportion($contractNum, $contractLastNum); $data['prev']['contractNum'] = $this->getProportion($contractNum, $contractLastNum);
$data['data']['recordNum'] = $recordNum; $data['data']['recordNum'] = $recordNum;
$data['prev']['recordNum'] = $this->getProportion($recordNum, $recordLastNum); $data['prev']['recordNum'] = $this->getProportion($recordNum, $recordLastNum);
$data['data']['businessMoneyNum'] = $businessMoneyNum; $data['data']['businessMoneyNum'] = $businessMoneyNum;
$data['prev']['businessMoneyNum'] = $this->getProportion($businessMoneyNum, $businessLastMoneyNum); $data['prev']['businessMoneyNum'] = $this->getProportion($businessMoneyNum, $businessLastMoneyNum);
$data['data']['contractMoneyNum'] = $contractMoneyNum; $data['data']['contractMoneyNum'] = $contractMoneyNum;
$data['prev']['contractMoneyNum'] = $this->getProportion($contractMoneyNum, $contractLastMoneyNum); $data['prev']['contractMoneyNum'] = $this->getProportion($contractMoneyNum, $contractLastMoneyNum);
$data['data']['receivablesMoneyNum'] = $receivablesMoneyNum; $data['data']['receivablesMoneyNum'] = $receivablesMoneyNum;
$data['prev']['receivablesMoneyNum'] = $this->getProportion($receivablesMoneyNum, $receivablesLastMoneyNum); $data['prev']['receivablesMoneyNum'] = $this->getProportion($receivablesMoneyNum, $receivablesLastMoneyNum);
return $data; return $data;
} }
public function getCountSql($param) public function getCountSql($param)
{ {
$countSql = "SELECT $countSql = "SELECT
@ -196,7 +189,7 @@ class IndexLogic extends Common
and create_user_id IN (" . implode(',', $param['record_auth_user_ids']) . ")"; and create_user_id IN (" . implode(',', $param['record_auth_user_ids']) . ")";
return $countSql; return $countSql;
} }
///计算涨幅 ///计算涨幅
public function getProportion($now, $last) public function getProportion($now, $last)
{ {
@ -211,8 +204,8 @@ class IndexLogic extends Common
} }
return $res; return $res;
} }
/** /**
* 遗忘数据统计 * 遗忘数据统计
* @return mixed * @return mixed
@ -233,14 +226,14 @@ class IndexLogic extends Common
$auth_customer_user_ids = $userModel->getUserByPer('crm', 'customer', 'index'); $auth_customer_user_ids = $userModel->getUserByPer('crm', 'customer', 'index');
$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) : []; //取交集
$owner_user_ids = array('in', $auth_customer_user_ids); $owner_user_ids = array('in', $auth_customer_user_ids);
$customerParam = []; $customerParam = [];
$customerParam['limit'] = $param['limit']; $customerParam['limit'] = $param['limit'];
$customerParam['page'] = $param['page']; $customerParam['page'] = $param['page'];
$customerParam['search'] = $param['search']; $customerParam['search'] = $param['search'];
$customerParam['getCount'] = 1; $customerParam['getCount'] = 1;
$customerParam['owner_user_id'] = $owner_user_ids; $customerParam['owner_user_id'] = $owner_user_ids;
$sevenDaysParam['otherMap'] = " ( IFNULL(last_time,create_time) < " . strtotime('-1 week') . ") "; $sevenDaysParam['otherMap'] = " ( IFNULL(last_time,create_time) < " . strtotime('-1 week') . ") ";
$fifteenDaysParam['otherMap'] = " ( IFNULL(last_time,create_time) < " . strtotime('-15 day') . ") "; $fifteenDaysParam['otherMap'] = " ( IFNULL(last_time,create_time) < " . strtotime('-15 day') . ") ";
$oneMonthParam['otherMap'] = " ( IFNULL(last_time,create_time) < " . strtotime('-30 day') . ") "; $oneMonthParam['otherMap'] = " ( IFNULL(last_time,create_time) < " . strtotime('-30 day') . ") ";
@ -253,10 +246,10 @@ class IndexLogic extends Common
$data['threeMonth'] = $customerModel->getDataList(array_merge($customerParam, $threeMonthParam))['dataCount'] ?: 0; $data['threeMonth'] = $customerModel->getDataList(array_merge($customerParam, $threeMonthParam))['dataCount'] ?: 0;
$data['sixMonth'] = $customerModel->getDataList(array_merge($customerParam, $sixMonthParam))['dataCount'] ?: 0; $data['sixMonth'] = $customerModel->getDataList(array_merge($customerParam, $sixMonthParam))['dataCount'] ?: 0;
$data['unContactCustomerCount'] = $customerModel->getDataList(array_merge($customerParam, $unContactParam))['dataCount'] ?: 0; $data['unContactCustomerCount'] = $customerModel->getDataList(array_merge($customerParam, $unContactParam))['dataCount'] ?: 0;
return $data; return $data;
} }
/** /**
* 遗忘数据列表 * 遗忘数据列表
* @return mixed * @return mixed
@ -279,13 +272,13 @@ class IndexLogic extends Common
$auth_customer_user_ids = $userModel->getUserByPer('crm', 'customer', 'index'); $auth_customer_user_ids = $userModel->getUserByPer('crm', 'customer', 'index');
$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) : []; //取交集
$owner_user_ids = array('in', $auth_customer_user_ids); $owner_user_ids = array('in', $auth_customer_user_ids);
$sql_unContactCustomerList = db('crm_customer') $sql_unContactCustomerList = db('crm_customer')
->where(['owner_user_id' => $owner_user_ids]) ->where(['owner_user_id' => $owner_user_ids])
->where('last_time < next_time AND next_time < now()') ->where('last_time < next_time AND next_time < now()')
->fetchSql() ->fetchSql()
->select(); ->select();
$label = $param['label']; $label = $param['label'];
$day = $param['day'] ?: ''; $day = $param['day'] ?: '';
$customerParam = []; $customerParam = [];
@ -293,7 +286,7 @@ class IndexLogic extends Common
$customerParam['page'] = $param['page']; $customerParam['page'] = $param['page'];
$customerParam['search'] = $param['search']; $customerParam['search'] = $param['search'];
$customerParam['owner_user_id'] = $owner_user_ids; $customerParam['owner_user_id'] = $owner_user_ids;
switch ($label) { switch ($label) {
case 1 : case 1 :
// ((( next_time < " . strtotime(date('Y-m-d 00:00:00')).") AND (last_time IS NOT NULL)) AND (IFNULL(last_time,next_time) >0)) // ((( next_time < " . strtotime(date('Y-m-d 00:00:00')).") AND (last_time IS NOT NULL)) AND (IFNULL(last_time,next_time) >0))
@ -317,7 +310,7 @@ class IndexLogic extends Common
} }
return $customerModel->getDataList($customerParam); return $customerModel->getDataList($customerParam);
} }
/** /**
* 排行榜 * 排行榜
* @param $param * @param $param
@ -338,7 +331,7 @@ class IndexLogic extends Common
$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'];
$auth_user_ids = $userModel->getUserByPer('bi', 'ranking', 'read'); $auth_user_ids = $userModel->getUserByPer('bi', 'ranking', 'read');
$auth_user_ids = $auth_user_ids ? array_intersect($userIds, $auth_user_ids) : []; //取交集 $auth_user_ids = $auth_user_ids ? array_intersect($userIds, $auth_user_ids) : []; //取交集
switch ($param['label']) { switch ($param['label']) {
@ -533,12 +526,12 @@ class IndexLogic extends Common
$ranking['ranking'][] = $v; $ranking['ranking'][] = $v;
$ranking['self'] = $list['self']; $ranking['self'] = $list['self'];
} }
$data = []; $data = [];
$data = $ranking ?: []; $data = $ranking ?: [];
return $data; return $data;
} }
/** /**
* 数据汇总 * 数据汇总
* @param $param * @param $param
@ -555,7 +548,7 @@ class IndexLogic extends Common
$user_id = $param['user_id'] ?: [-1]; $user_id = $param['user_id'] ?: [-1];
$userIds = $whereArr['userIds']; $userIds = $whereArr['userIds'];
$between_time = $whereArr['between_time']; $between_time = $whereArr['between_time'];
$customer_auth_user_ids = $userModel->getUserByPer('crm', 'customer', 'index'); $customer_auth_user_ids = $userModel->getUserByPer('crm', 'customer', 'index');
$contacts_auth_user_ids = $userModel->getUserByPer('crm', 'contacts', 'index'); $contacts_auth_user_ids = $userModel->getUserByPer('crm', 'contacts', 'index');
$business_auth_user_ids = $userModel->getUserByPer('crm', 'business', 'index'); $business_auth_user_ids = $userModel->getUserByPer('crm', 'business', 'index');
@ -583,7 +576,7 @@ class IndexLogic extends Common
} }
return $resDataArr; return $resDataArr;
} }
/** /**
* [数据汇总sql] * [数据汇总sql]
* @return * @return
@ -659,7 +652,7 @@ class IndexLogic extends Common
} }
return $countSql; return $countSql;
} }
/** /**
* 销售漏斗查看 * 销售漏斗查看
*/ */
@ -680,7 +673,7 @@ class IndexLogic extends Common
$param['scene_id'] = $scene_id ?: ''; $param['scene_id'] = $scene_id ?: '';
$param['create_time']['start'] = $start_time; $param['create_time']['start'] = $start_time;
$param['create_time']['end'] = $end_time; $param['create_time']['end'] = $end_time;
$param['owner_user_id']['value'] = $userIds; $param['owner_user_id']['value'] = $userIds;
unset($param['type']); unset($param['type']);
unset($param['dataType']); unset($param['dataType']);
@ -691,7 +684,7 @@ class IndexLogic extends Common
$data=$businessModel->getDataList($param); $data=$businessModel->getDataList($param);
return $data; return $data;
} }
/** /**
* 仪表盘布局列表 * 仪表盘布局列表
*/ */
@ -699,7 +692,7 @@ class IndexLogic extends Common
{ {
$data = []; $data = [];
$list = db('crm_dashboard')->where('user_id', $param['user_id'])->find(); $list = db('crm_dashboard')->where('user_id', $param['user_id'])->find();
if ($list) { if ($list) {
$data = unserialize($list['dashboard']); $data = unserialize($list['dashboard']);
return $data ?: []; return $data ?: [];
@ -713,7 +706,7 @@ class IndexLogic extends Common
$data['left'][2]['modelId'] = 7; $data['left'][2]['modelId'] = 7;
$data['left'][2]['list'] = 1; $data['left'][2]['list'] = 1;
$data['left'][2]['isHidden'] = 0; $data['left'][2]['isHidden'] = 0;
$data['right'][0]['modelId'] = 2; $data['right'][0]['modelId'] = 2;
$data['right'][0]['list'] = 2; $data['right'][0]['list'] = 2;
$data['right'][0]['isHidden'] = 0; $data['right'][0]['isHidden'] = 0;
@ -725,16 +718,16 @@ class IndexLogic extends Common
$data['right'][2]['isHidden'] = 0; $data['right'][2]['isHidden'] = 0;
return $data; return $data;
} }
} }
/** /**
* 修改自定义仪表盘 * 修改自定义仪表盘
* @param $param * @param $param
*/ */
public function updateDashboard($param) public function updateDashboard($param)
{ {
$data = db('crm_dashboard')->where('user_id', $param['user_id'])->find(); $data = db('crm_dashboard')->where('user_id', $param['user_id'])->find();
if ($data) { if ($data) {
$list = db('crm_dashboard')->where('user_id', $param['user_id'])->update(['dashboard' => serialize($param['dashboard'])]); $list = db('crm_dashboard')->where('user_id', $param['user_id'])->update(['dashboard' => serialize($param['dashboard'])]);
@ -743,9 +736,9 @@ class IndexLogic extends Common
$list = db('crm_dashboard')->insert(['user_id' => $param['user_id'], 'dashboard' => serialize($param['dashboard'])]); $list = db('crm_dashboard')->insert(['user_id' => $param['user_id'], 'dashboard' => serialize($param['dashboard'])]);
return $list; return $list;
} }
} }
/** /**
* 跟进记录列表 * 跟进记录列表
* @param $param * @param $param
@ -798,14 +791,14 @@ class IndexLogic extends Common
$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');
$type['t.create_time'] = ['between', [$start_time, $end_time]]; $type['t.create_time'] = ['between', [$start_time, $end_time]];
} }
if ($param['queryType'] == 0) { if ($param['queryType'] == 0) {
$type['t.type'] = ['in', [1, 4]]; $type['t.type'] = ['in', [1, 4]];
} else { } else {
$type['t.type'] = $param['queryType']; $type['t.type'] = $param['queryType'];
} }
if ($param['user_id'] == '') { if ($param['user_id'] == '') {
if ($param['subUser'] === "0" || $param['subUser']===0) { if ($param['subUser'] === "0" || $param['subUser']===0) {
$type['t.create_user_id'] = $param['id']; $type['t.create_user_id'] = $param['id'];
//下属创建 //下属创建
@ -853,13 +846,11 @@ class IndexLogic extends Common
if ($v['activity_type'] == 2) { if ($v['activity_type'] == 2) {
$activity_name = Db::name('crm_customer')->where('customer_id', $v['activity_type_id'])->find(); $activity_name = Db::name('crm_customer')->where('customer_id', $v['activity_type_id'])->find();
$list[$k]['activity_type_name'] = $activity_name['name']; $list[$k]['activity_type_name'] = $activity_name['name'];
$activity_business = Db::name('crm_business')->where('business_id', $v['activity_type_id'])->select(); $activity_business = Db::name('crm_business')->where('business_id',['in',$v['business_ids']])->find();
$activity_contacts = Db::name('crm_contacts')->where('contacts_id', $v['activity_type_id'])->select(); $activity_contacts = Db::name('crm_contacts')->where('contacts_id', ['in',$v['contacts_ids']])->find();
$list[$k]['business_list'] = $activity_business ?: []; $list[$k]['business_list'] = $activity_business ?: [];
$list[$k]['contacts_list'] = $activity_contacts ?: []; $list[$k]['contacts_list'] = $activity_contacts ?: [];
} }
if ($v['activity_type'] == 3) { if ($v['activity_type'] == 3) {
$activity_name = Db::name('crm_contacts')->where('contacts_id', $v['activity_type_id'])->find(); $activity_name = Db::name('crm_contacts')->where('contacts_id', $v['activity_type_id'])->find();
$list[$k]['activity_type_name'] = $activity_name['name']; $list[$k]['activity_type_name'] = $activity_name['name'];
@ -898,7 +889,7 @@ class IndexLogic extends Common
}; };
$list[$k]['fileList'] = $fileList ?: []; $list[$k]['fileList'] = $fileList ?: [];
$list[$k]['imgList'] = $imgList ?: []; $list[$k]['imgList'] = $imgList ?: [];
$dataInfo['customerList'] = $relation_list['customerList'] ?: []; $dataInfo['customerList'] = $relation_list['customerList'] ?: [];
$dataInfo['contactsList'] = $relation_list['contactsList'] ?: []; $dataInfo['contactsList'] = $relation_list['contactsList'] ?: [];
$dataInfo['businessList'] = $relation_list['businessList'] ?: []; $dataInfo['businessList'] = $relation_list['businessList'] ?: [];
@ -913,7 +904,7 @@ class IndexLogic extends Common
->alias('t') ->alias('t')
->join('__ADMIN_USER__ user', 'user.id = t.create_user_id', 'LEFT') ->join('__ADMIN_USER__ user', 'user.id = t.create_user_id', 'LEFT')
->where($where_activity) ->where($where_activity)
->field('t.content,t.next_time,t.update_time,t.create_time,t.category,t.activity_type,t.type,t.activity_id,t.activity_type_id,user.realname as create_user_name,user.thumb_img') ->field('t.business_ids,t.contacts_ids,t.content,t.next_time,t.update_time,t.create_time,t.category,t.activity_type,t.type,t.activity_id,t.activity_type_id,user.realname as create_user_name,user.thumb_img')
->page($param['page'], $param['limit']) ->page($param['page'], $param['limit'])
->order('t.create_time desc') ->order('t.create_time desc')
->select(); ->select();
@ -928,12 +919,12 @@ class IndexLogic extends Common
if ($param['activity_type'] == 2) { if ($param['activity_type'] == 2) {
$activity_name = Db::name('crm_customer')->where('customer_id', $v['activity_type_id'])->find(); $activity_name = Db::name('crm_customer')->where('customer_id', $v['activity_type_id'])->find();
$list[$k]['activity_type_name'] = $activity_name['name']; $list[$k]['activity_type_name'] = $activity_name['name'];
$activity_business = Db::name('crm_business')->where('business_id', $v['activity_type_id'])->select(); $activity_business = Db::name('crm_business')->where('business_id',['in',$v['business_ids']])->find();
$activity_contacts = Db::name('crm_contacts')->where('contacts_id', $v['activity_type_id'])->select(); $activity_contacts = Db::name('crm_contacts')->where('contacts_id', ['in',$v['contacts_ids']])->find();
$list[$k]['business_list'] = $activity_business ?: []; $list[$k]['business_list'] = $activity_business ?: [];
$list[$k]['contacts_list'] = $activity_contacts ?: []; $list[$k]['contacts_list'] = $activity_contacts ?: [];
} }
if ($param['activity_type'] == 3) { if ($param['activity_type'] == 3) {
$activity_name = Db::name('crm_contacts')->where('contacts_id', $v['activity_type_id'])->find(); $activity_name = Db::name('crm_contacts')->where('contacts_id', $v['activity_type_id'])->find();
$list[$k]['activity_type_name'] = $activity_name['name']; $list[$k]['activity_type_name'] = $activity_name['name'];
@ -980,8 +971,8 @@ class IndexLogic extends Common
$list[$k]['dataInfo'] = $dataInfo ?: []; $list[$k]['dataInfo'] = $dataInfo ?: [];
} }
} }
$data = []; $data = [];
$data['list'] = $list; $data['list'] = $list;
$data['dataCount'] = $dataCount ?: 0; $data['dataCount'] = $dataCount ?: 0;

@ -17,7 +17,7 @@ class InvoiceLogic
{ {
private $invoiceType = ['增值税专用发票', '增值税普通发票', '国税通用机打发票', '地税通用机打发票', '收据']; private $invoiceType = ['增值税专用发票', '增值税普通发票', '国税通用机打发票', '地税通用机打发票', '收据'];
private $check_status = ['待审核', '审核中', '审核通过', '审核未通过', '撤回']; private $check_status = ['待审核', '审核中', '审核通过', '审核未通过', '撤回'];
/** /**
* 列表 * 列表
* *
@ -45,7 +45,7 @@ class InvoiceLogic
$scene_id = $param['scene_id']; $scene_id = $param['scene_id'];
$isMessage = !empty($param['isMessage']); $isMessage = !empty($param['isMessage']);
$common = new Common(); $common = new Common();
unset($param['getCount']); unset($param['getCount']);
// unset($param['limit']); 导出使用 暂未发现为何去掉分页参数 // unset($param['limit']); 导出使用 暂未发现为何去掉分页参数
// unset($param['page']); // unset($param['page']);
@ -60,11 +60,11 @@ class InvoiceLogic
unset($param['isMessage']); unset($param['isMessage']);
$request = $common->fmtRequest($param); $request = $common->fmtRequest($param);
$where = []; $where = [];
# 高级搜索 # 高级搜索
$requestMap = !empty($request['map']) ? $request['map'] : []; $requestMap = !empty($request['map']) ? $request['map'] : [];
unset($requestMap['search']); unset($requestMap['search']);
# 场景 # 场景
$sceneMap = []; $sceneMap = [];
$sceneModel = new \app\admin\model\Scene(); $sceneModel = new \app\admin\model\Scene();
@ -94,13 +94,13 @@ class InvoiceLogic
# 替换掉字段前缀,不修改公共函数 # 替换掉字段前缀,不修改公共函数
foreach ($map as $key => $value) { foreach ($map as $key => $value) {
$k = str_replace('invoice.', '', $key); $k = str_replace('invoice.', '', $key);
$where[$k] = $value; $where[$k] = $value;
} }
# 待办事项查询参数 # 待办事项查询参数
$dealtWhere = []; $dealtWhere = [];
if (!empty($invoiceIdArray)) $dealtWhere['invoice.invoice_id'] = ['in', $invoiceIdArray]; if (!empty($invoiceIdArray)) $dealtWhere['invoice.invoice_id'] = ['in', $invoiceIdArray];
# 权限,不是待办事项,则加上列表权限 # 权限,不是待办事项,则加上列表权限
$auth = []; $auth = [];
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
@ -154,7 +154,7 @@ class InvoiceLogic
->limit($request['offset'], $request['length']) ->limit($request['offset'], $request['length'])
->orderRaw($order) ->orderRaw($order)
->select(); ->select();
$dataCount = db('crm_invoice') $dataCount = db('crm_invoice')
->alias('invoice') ->alias('invoice')
->join($join) ->join($join)
@ -176,21 +176,35 @@ class InvoiceLogic
$positionField = $fieldModel->getFieldByFormType('crm_invoice', 'position'); // 地址类型字段 $positionField = $fieldModel->getFieldByFormType('crm_invoice', 'position'); // 地址类型字段
$handwritingField = $fieldModel->getFieldByFormType('crm_invoice', 'handwriting_sign'); // 手写签名类型字段 $handwritingField = $fieldModel->getFieldByFormType('crm_invoice', 'handwriting_sign'); // 手写签名类型字段
$locationField = $fieldModel->getFieldByFormType('crm_invoice', 'location'); // 定位类型字段 $locationField = $fieldModel->getFieldByFormType('crm_invoice', 'location'); // 定位类型字段
$boxField = $fieldModel->getFieldByFormType('crm_customer', 'checkbox'); // 多选类型字段
$floatField = $fieldModel->getFieldByFormType('crm_invoice', 'floatnumber'); // 货币类型字段
// $fieldGrant = db('admin_field_mask')->where('types', 'invoice')->select();
# 扩展数据 # 扩展数据
$extraData = []; $extraData = [];
$invoice_id_list = !empty($list) ? array_column($list, 'invoice_id') : []; $invoice_id_list = !empty($list) ? array_column($list, 'invoice_id') : [];
$extraList = db('crm_invoice_data')->whereIn('invoice_id', $invoice_id_list)->select(); $extraList = db('crm_invoice_data')->whereIn('invoice_id', $invoice_id_list)->select();
foreach ($extraList AS $key => $value) { foreach ($extraList as $key => $value) {
$extraData[$value['invoice_id']][$value['field']] = $value['content']; $extraData[$value['invoice_id']][$value['field']] = $value['content'];
} }
$grantData = getFieldGrantData($userId);
foreach ($grantData['crm_invoice'] as $key => $value) {
foreach ($value as $ke => $va) {
if($va['maskType']!=0){
$fieldGrant[$ke]['maskType'] = $va['maskType'];
$fieldGrant[$ke]['form_type'] = $va['form_type'];
$fieldGrant[$ke]['field'] = $va['field'];
}
}
}
# 处理发票类型 # 处理发票类型
foreach ($list as $key => $value) { foreach ($list as $key => $value) {
$list[$key]['check_status_info'] = $this->check_status[$value['check_status']]; $list[$key]['check_status_info'] = $this->check_status[$value['check_status']];
$list[$key]['invoice_status'] = !empty($value['invoice_status']) ? '已开票' : '未开票'; $list[$key]['invoice_status'] = !empty($value['invoice_status']) ? '已开票' : '未开票';
$list[$key]['create_time'] = !empty($value['create_time']) ? date('Y-m-d H:i:s',$value['create_time']) : null; $list[$key]['create_time'] = !empty($value['create_time']) ? date('Y-m-d H:i:s', $value['create_time']) : null;
$list[$key]['update_time'] = !empty($value['update_time']) ? date('Y-m-d H:i:s',$value['update_time']) : null; $list[$key]['update_time'] = !empty($value['update_time']) ? date('Y-m-d H:i:s', $value['update_time']) : null;
# 系统字段 负责人部门 zjf 20210726
$ownerUserIdInfo = $userModel->getUserById($value['owner_user_id']);
$list[$key]['owner_user_structure_name'] = $ownerUserIdInfo['structure_name'];
foreach ($userField as $k => $val) { foreach ($userField as $k => $val) {
$usernameField = !empty($value[$val]) ? db('admin_user')->whereIn('id', stringToArray($value[$val]))->column('realname') : []; $usernameField = !empty($value[$val]) ? db('admin_user')->whereIn('id', stringToArray($value[$val]))->column('realname') : [];
$list[$key][$val] = implode($usernameField, ','); $list[$key][$val] = implode($usernameField, ',');
@ -214,7 +228,7 @@ class InvoiceLogic
$list[$key][$val] = !empty($extraData[$value['invoice_id']][$val]) ? json_decode($extraData[$value['invoice_id']][$val], true) : null; $list[$key][$val] = !empty($extraData[$value['invoice_id']][$val]) ? json_decode($extraData[$value['invoice_id']][$val], true) : null;
} }
// 手写签名类型字段 // 手写签名类型字段
foreach ($handwritingField AS $k => $val) { foreach ($handwritingField as $k => $val) {
$handwritingData = !empty($value[$val]) ? db('admin_file')->where('file_id', $value[$val])->value('file_path') : null; $handwritingData = !empty($value[$val]) ? db('admin_file')->where('file_id', $value[$val])->value('file_path') : null;
$list[$key][$val] = ['url' => !empty($handwritingData) ? getFullPath($handwritingData) : null]; $list[$key][$val] = ['url' => !empty($handwritingData) ? getFullPath($handwritingData) : null];
} }
@ -222,24 +236,51 @@ class InvoiceLogic
foreach ($locationField as $k => $val) { foreach ($locationField as $k => $val) {
$list[$key][$val] = !empty($extraData[$value['invoice_id']][$val]) ? json_decode($extraData[$value['invoice_id']][$val], true) : null; $list[$key][$val] = !empty($extraData[$value['invoice_id']][$val]) ? json_decode($extraData[$value['invoice_id']][$val], true) : null;
} }
// 多选框类型字段
foreach ($boxField as $k => $val) {
$list[$key][$val] = !empty($value[$val]) ? trim($value[$val], ',') : null;
}
//货币类型字段
foreach ($floatField as $k => $val) {
$list[$key][$val] = $value[$val] != '0.00' ? (string)$value[$val] : null;
}
//掩码相关类型字段
foreach ($fieldGrant AS $key => $v){
//掩码相关类型字段
if ($v['maskType']!=0 && $v['form_type'] == 'mobile') {
$pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
$rs = preg_replace($pattern, "$1****$2", $value[$v['field']]);
$list[$k][$v['field']] = !empty($value[$v['field']]) ? (string)$rs : null;
} elseif ($v['maskType']!=0 && $v['form_type'] == 'email') {
$email_array = explode("@", $value[$v['field']]);
$prevfix = (strlen($email_array[0]) < 4) ? "" : substr($value[$v['field']], 0, 2); //
$str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $value[$v['field']], -1, $count);
$rs = $prevfix . $str;
$list[$k][$v['field']] = !empty($value[$v['field']]) ?$rs: null;
} elseif ($v['maskType']!=0 && in_array($v['form_type'],['position','floatnumber'])) {
$list[$k][$v['field']] = !empty($value[$v['field']]) ? (string)substr_replace($value[$v['field']], '*****',0,strlen($value[$v['field']])) : null;
}
}
$data = [];
$data['list'] = $list ?: [];
$data['dataCount'] = $dataCount ?: 0;
return $data;
} }
$data = [];
$data['list'] = $list ?: [];
$data['dataCount'] = $dataCount ?: 0;
return $data;
} }
/** /**
* 创建 * 创建
* *
* @param $param * @param $param
* @return Invoice|int|string * @return Invoice|int|string
*/ */
public function save($param) public
function save($param)
{ {
return db('crm_invoice')->insert($param, false, true); return db('crm_invoice')->insert($param, false, true);
} }
/** /**
* 详情 * 详情
* *
@ -250,27 +291,53 @@ class InvoiceLogic
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function read($invoiceId, $isUpdate) public
function read($invoiceId, $isUpdate)
{ {
$apiCommon = new ApiCommon(); $apiCommon = new ApiCommon();
$userId = $apiCommon->userInfo['id']; $userId = $apiCommon->userInfo['id'];
$result = []; $result = [];
$dataObject = Invoice::with(['toCustomer', 'toContract'])->where('invoice_id', $invoiceId)->find(); $dataObject = Invoice::with(['toCustomer', 'toContract'])->where('invoice_id', $invoiceId)->find();
if (empty($dataObject)) return $result; if (empty($dataObject)) return $result;
$dataArray = $dataObject->toArray(); $dataArray = $dataObject->toArray();
if (!empty($isUpdate)) return $dataArray; if (!empty($isUpdate)) return $dataArray;
$grantData = getFieldGrantData($userId);
foreach ($grantData['crm_leads'] as $key => $value) {
foreach ($value as $ke => $va) {
if($va['maskType']!=0){
$fieldGrant[$ke]['maskType'] = $va['maskType'];
$fieldGrant[$ke]['form_type'] = $va['form_type'];
$fieldGrant[$ke]['field'] = $va['field'];
}
}
}
foreach ($fieldGrant AS $key => $val){
//掩码相关类型字段
if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
$pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
$rs = preg_replace($pattern, "$1****$2", $dataArray[$val['field']]);
$dataArray[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)$rs : null;
} elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
$email_array = explode("@", $dataArray[$val['field']]);
$prevfix = (strlen($email_array[0]) < 4) ? "" : substr($dataArray[$val['field']], 0, 2); //
$str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $dataArray[$val['field']], -1, $count);
$rs = $prevfix . $str;
$dataArray[$val['field']] = !empty($dataInfo[$val['field']]) ?$rs: null;
} elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
$dataArray[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)substr_replace($dataArray[$val['field']], '*****',0,strlen($dataArray[$val['field']])) : null;
}
}
# 主键ID # 主键ID
$result['invoice_id'] = $dataArray['invoice_id']; $result['invoice_id'] = $dataArray['invoice_id'];
# 是否显示撤回按钮 # 是否显示撤回按钮
$result['isShowRecall'] = 0; $result['isShowRecall'] = 0;
if ($userId == $dataArray['owner_user_id'] && $dataArray['check_status'] == 0) $result['isShowRecall'] = 1; if ($userId == $dataArray['owner_user_id'] && $dataArray['check_status'] == 0) $result['isShowRecall'] = 1;
$result['customer_name'] = $dataArray['customer_name']; # 客户名称 $result['customer_name'] = $dataArray['customer_name']; # 客户名称
$result['invoice_money'] = $dataArray['invoice_money']; # 开票金额 $result['invoice_money'] = $dataArray['invoice_money']; # 开票金额
$result['invoice_number'] = $dataArray['invoice_number']; # 发票号码 $result['invoice_number'] = $dataArray['invoice_number']; # 发票号码
@ -296,7 +363,7 @@ class InvoiceLogic
'customer_id' => $dataArray['customer_id'], 'customer_id' => $dataArray['customer_id'],
'check_status' => $check[$dataArray['check_status']] 'check_status' => $check[$dataArray['check_status']]
]; ];
# 发票信息 # 发票信息
$result['invoice'] = [ $result['invoice'] = [
'title_type' => $dataArray['title_type'], 'title_type' => $dataArray['title_type'],
@ -307,39 +374,41 @@ class InvoiceLogic
'deposit_address' => $dataArray['deposit_address'], 'deposit_address' => $dataArray['deposit_address'],
'phone' => $dataArray['phone'] 'phone' => $dataArray['phone']
]; ];
# 邮寄信息 # 邮寄信息
$result['posting'] = [ $result['posting'] = [
'contacts_name' => $dataArray['contacts_name'], 'contacts_name' => $dataArray['contacts_name'],
'contacts_mobile' => $dataArray['contacts_mobile'], 'contacts_mobile' => $dataArray['contacts_mobile'],
'contacts_address' => $dataArray['contacts_address'] 'contacts_address' => $dataArray['contacts_address']
]; ];
return $result; return $result;
} }
/** /**
* 编辑 * 编辑
* *
* @param $param * @param $param
* @return Invoice * @return Invoice
*/ */
public function update($param) public
function update($param)
{ {
return Invoice::update($param); return Invoice::update($param);
} }
/** /**
* 删除 * 删除
* *
* @param $where * @param $where
* @return int * @return int
*/ */
public function delete($where) public
function delete($where)
{ {
return Invoice::destroy($where); return Invoice::destroy($where);
} }
/** /**
* 获取审批状态 * 获取审批状态
* *
@ -350,17 +419,18 @@ class InvoiceLogic
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function getExamineStatus($invoiceId, $isDelete = false) public
function getExamineStatus($invoiceId, $isDelete = false)
{ {
# 删除 # 删除
if ($isDelete) { if ($isDelete) {
return Invoice::field(['check_status'])->whereIn('invoice_id', $invoiceId)->select(); return Invoice::field(['check_status'])->whereIn('invoice_id', $invoiceId)->select();
} }
# 编辑 # 编辑
return Invoice::where('invoice_id', $invoiceId)->value('check_status'); return Invoice::where('invoice_id', $invoiceId)->value('check_status');
} }
/** /**
* 转移(变更负责人) * 转移(变更负责人)
* *
@ -368,22 +438,24 @@ class InvoiceLogic
* @param $ownerUserId * @param $ownerUserId
* @return Invoice * @return Invoice
*/ */
public function transfer($invoiceIds, $ownerUserId) public
function transfer($invoiceIds, $ownerUserId)
{ {
return Invoice::whereIn('invoice_id', $invoiceIds)->update(['owner_user_id' => $ownerUserId]); return Invoice::whereIn('invoice_id', $invoiceIds)->update(['owner_user_id' => $ownerUserId]);
} }
/** /**
* 设置开票 * 设置开票
* *
* @param $param * @param $param
* @return Invoice * @return Invoice
*/ */
public function setInvoice($param) public
function setInvoice($param)
{ {
return Invoice::update($param); return Invoice::update($param);
} }
/** /**
* 获取发票审核信息 * 获取发票审核信息
* *
@ -393,24 +465,26 @@ class InvoiceLogic
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function getExamineInfo($invoiceId) public
function getExamineInfo($invoiceId)
{ {
$field = ['check_status', 'flow_id', 'order_id', 'check_user_id', 'flow_user_id', 'invoice_apple_number', 'owner_user_id', 'create_user_id']; $field = ['check_status', 'flow_id', 'order_id', 'check_user_id', 'flow_user_id', 'invoice_apple_number', 'owner_user_id', 'create_user_id'];
return Invoice::field($field)->where('invoice_id', $invoiceId)->find(); return Invoice::field($field)->where('invoice_id', $invoiceId)->find();
} }
/** /**
* 设置审批信息 * 设置审批信息
* *
* @param $data * @param $data
* @return Invoice * @return Invoice
*/ */
public function setExamineInfo($data) public
function setExamineInfo($data)
{ {
return Invoice::update($data); return Invoice::update($data);
} }
/** /**
* 添加撤销审核记录 * 添加撤销审核记录
* *
@ -420,7 +494,8 @@ class InvoiceLogic
* @param $content * @param $content
* @param $userId * @param $userId
*/ */
public function createExamineRecord($invoiceId, $examineInfo, $realname, $content, $userId) public
function createExamineRecord($invoiceId, $examineInfo, $realname, $content, $userId)
{ {
$data = [ $data = [
'types' => 'crm_invoice', 'types' => 'crm_invoice',
@ -432,17 +507,18 @@ class InvoiceLogic
'status' => 2, 'status' => 2,
'content' => !empty($content) ? $content : $realname . ' 撤销了审核', 'content' => !empty($content) ? $content : $realname . ' 撤销了审核',
]; ];
Db::name('admin_examine_record')->insert($data); Db::name('admin_examine_record')->insert($data);
} }
/** /**
* 检查发票编号是否重复 * 检查发票编号是否重复
* *
* @param $where * @param $where
* @return int|mixed|string|null * @return int|mixed|string|null
*/ */
public function getInvoiceId($where) public
function getInvoiceId($where)
{ {
return Db::name('crm_invoice')->where($where)->value('invoice_id'); return Db::name('crm_invoice')->where($where)->value('invoice_id');
} }

@ -100,6 +100,9 @@ class VisitLogic extends Common
$positionField = $fieldModel->getFieldByFormType('crm_visit', 'position'); // 地址类型字段 $positionField = $fieldModel->getFieldByFormType('crm_visit', 'position'); // 地址类型字段
$handwritingField = $fieldModel->getFieldByFormType('crm_visit', 'handwriting_sign'); // 手写签名类型字段 $handwritingField = $fieldModel->getFieldByFormType('crm_visit', 'handwriting_sign'); // 手写签名类型字段
$locationField = $fieldModel->getFieldByFormType('crm_visit', 'location'); // 定位类型字段 $locationField = $fieldModel->getFieldByFormType('crm_visit', 'location'); // 定位类型字段
$boxField = $fieldModel->getFieldByFormType('crm_customer', 'checkbox'); // 多选类型字段
$floatField = $fieldModel->getFieldByFormType('crm_visit', 'floatnumber'); // 货币类型字段
// $fieldGrant = db('admin_field_mask')->where('types', 'visit')->select();
# 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段) # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
$temporaryField = str_replace('_name', '', $order_field); $temporaryField = str_replace('_name', '', $order_field);
if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) { if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
@ -147,12 +150,26 @@ class VisitLogic extends Common
foreach ($extraList AS $key => $value) { foreach ($extraList AS $key => $value) {
$extraData[$value['visit_id']][$value['field']] = $value['content']; $extraData[$value['visit_id']][$value['field']] = $value['content'];
} }
$grantData = getFieldGrantData($user_id);
foreach ($grantData['crm_visit_'] as $key => $value) {
foreach ($value as $ke => $va) {
if($va['maskType']!=0){
$fieldGrant[$ke]['maskType'] = $va['maskType'];
$fieldGrant[$ke]['form_type'] = $va['form_type'];
$fieldGrant[$ke]['field'] = $va['field'];
}
}
}
foreach ($list as $k => $v) { foreach ($list as $k => $v) {
$list[$k]['contract_num'] = $v['contract_number']; $list[$k]['contract_num'] = $v['contract_number'];
$list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : []; $list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
$list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : []; $list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
$list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : ''; $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'] : ''; $list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : '';
# 系统字段 负责人部门 zjf 20210726
$list[$k]['owner_user_structure_name'] = $list[$k]['owner_user_id_info']['structure_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.'_name'] = implode($usernameField, ','); $list[$k][$val.'_name'] = implode($usernameField, ',');
@ -184,6 +201,31 @@ class VisitLogic extends Common
foreach ($locationField AS $key => $val) { foreach ($locationField AS $key => $val) {
$list[$k][$val] = !empty($extraData[$v['visit_id']][$val]) ? json_decode($extraData[$v['visit_id']][$val], true) : null; $list[$k][$val] = !empty($extraData[$v['visit_id']][$val]) ? json_decode($extraData[$v['visit_id']][$val], true) : null;
} }
// 多选框类型字段
foreach ($boxField AS $key => $val) {
$list[$k][$val] = !empty($v[$val]) ? trim($v[$val], ',') : null;
}
// 货币类型字段
foreach ($floatField AS $key => $val) {
$list[$k][$val] = $v[$val]!='0.00' ? (string)$v[$val] : null;
}
//掩码相关类型字段
foreach ($fieldGrant AS $key => $val){
//掩码相关类型字段
if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
$pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
$rs = preg_replace($pattern, "$1****$2", $v[$val['field']]);
$list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)$rs : null;
} elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
$email_array = explode("@", $v[$val['field']]);
$prevfix = (strlen($email_array[0]) < 4) ? "" : substr($v[$val['field']], 0, 2); //
$str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $v[$val['field']], -1, $count);
$rs = $prevfix . $str;
$list[$k][$val['field']] = !empty($v[$val['field']]) ?$rs: null;
} elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
$list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)substr_replace($v[$val['field']], '*****',0,strlen($v[$val['field']])) : null;
}
}
$list[$k]['contract_id_info']['contract_id'] = $v['contract_id']; $list[$k]['contract_id_info']['contract_id'] = $v['contract_id'];
$list[$k]['contract_id_info']['name'] = $v['contract_name']; $list[$k]['contract_id_info']['name'] = $v['contract_name'];
$list[$k]['customer_id_info']['customer_id'] = $v['create_user_id']; $list[$k]['customer_id_info']['customer_id'] = $v['create_user_id'];
@ -226,6 +268,32 @@ class VisitLogic extends Common
$this->error = '暂无此数据'; $this->error = '暂无此数据';
return false; return false;
} }
$grantData = getFieldGrantData($userId);
foreach ($grantData['crm_leads'] as $key => $value) {
foreach ($value as $ke => $va) {
if($va['maskType']!=0){
$fieldGrant[$ke]['maskType'] = $va['maskType'];
$fieldGrant[$ke]['form_type'] = $va['form_type'];
$fieldGrant[$ke]['field'] = $va['field'];
}
}
}
foreach ($fieldGrant AS $key => $val){
//掩码相关类型字段
if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
$pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
$rs = preg_replace($pattern, "$1****$2", $dataInfo[$val['field']]);
$dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)$rs : null;
} elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
$email_array = explode("@", $dataInfo[$val['field']]);
$prevfix = (strlen($email_array[0]) < 4) ? "" : substr($dataInfo[$val['field']], 0, 2); //
$str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $dataInfo[$val['field']], -1, $count);
$rs = $prevfix . $str;
$dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ?$rs: null;
} 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($v[$val['field']])) : null;
}
}
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : []; $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
$dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : []; $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
@ -584,13 +652,25 @@ class VisitLogic extends Common
public function getSystemInfo($id) public function getSystemInfo($id)
{ {
# 回访 # 回访
$visit = Db::name('crm_visit')->field(['create_user_id', 'create_time', 'update_time'])->where('visit_id', $id)->find(); $visit = Db::name('crm_visit')->field(['create_user_id', 'owner_user_id', 'create_time', 'update_time'])->where('visit_id', $id)->find();
# 创建人 # 创建人
$realname = Db::name('admin_user')->where('id', $visit['create_user_id'])->value('realname'); $realname = Db::name('admin_user')->where('id', $visit['create_user_id'])->value('realname');
# zjf 20210726
$userModel = new \app\admin\model\User();
$ownerUserInfo = $userModel->getUserById($visit['owner_user_id']);
# 负责人部门
$ownerStructureName = $ownerUserInfo['structure_name'];
# 负责人
$ownerUserName = $ownerUserInfo['realname'];
return [ return [
'create_user_id' => $realname, 'create_user_id' => $realname,
'owner_user_id' => $ownerUserName,
'create_time' => date('Y-m-d H:i:s', $visit['create_time']), 'create_time' => date('Y-m-d H:i:s', $visit['create_time']),
'update_time' => date('Y-m-d H:i:s', $visit['update_time']) 'update_time' => date('Y-m-d H:i:s', $visit['update_time']),
'owner_user_structure_name' => $ownerStructureName
]; ];
} }
} }

@ -161,6 +161,9 @@ class Business extends Common
$positionField = $fieldModel->getFieldByFormType('crm_business', 'position'); // 地址类型字段 $positionField = $fieldModel->getFieldByFormType('crm_business', 'position'); // 地址类型字段
$handwritingField = $fieldModel->getFieldByFormType('crm_business', 'handwriting_sign'); // 手写签名类型字段 $handwritingField = $fieldModel->getFieldByFormType('crm_business', 'handwriting_sign'); // 手写签名类型字段
$locationField = $fieldModel->getFieldByFormType('crm_business', 'location'); // 定位类型字段 $locationField = $fieldModel->getFieldByFormType('crm_business', 'location'); // 定位类型字段
$boxField = $fieldModel->getFieldByFormType('crm_business', 'checkbox'); // 多选类型字段
$floatField = $fieldModel->getFieldByFormType('crm_business', 'floatnumber'); // 货币类型字段
// $fieldGrant = db('admin_field_mask')->where('types', 'business')->select();
# 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段) # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
$temporaryField = str_replace('_name', '', $order_field); $temporaryField = str_replace('_name', '', $order_field);
if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) { if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
@ -224,6 +227,16 @@ class Business extends Common
foreach ($extraList AS $key => $value) { foreach ($extraList AS $key => $value) {
$extraData[$value['business_id']][$value['field']] = $value['content']; $extraData[$value['business_id']][$value['field']] = $value['content'];
} }
$grantData = getFieldGrantData($user_id);
foreach ($grantData['crm_business'] as $key => $value) {
foreach ($value as $ke => $va) {
if($va['maskType']!=0){
$fieldGrant[$ke]['maskType'] = $va['maskType'];
$fieldGrant[$ke]['form_type'] = $va['form_type'];
$fieldGrant[$ke]['field'] = $va['field'];
}
}
}
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'];
@ -262,6 +275,31 @@ class Business extends Common
foreach ($locationField AS $key => $val) { foreach ($locationField AS $key => $val) {
$list[$k][$val] = !empty($extraData[$v['business_id']][$val]) ? json_decode($extraData[$v['business_id']][$val], true) : null; $list[$k][$val] = !empty($extraData[$v['business_id']][$val]) ? json_decode($extraData[$v['business_id']][$val], true) : null;
} }
// 多选框类型字段
foreach ($boxField AS $key => $val) {
$list[$k][$val] = !empty($v[$val]) ? trim($v[$val], ',') : null;
}
// 货币类型字段
foreach ($floatField AS $key => $val) {
$list[$k][$val] = $v[$val]!='0.00' ? (string)$v[$val] : null;
}
//掩码相关类型字段
foreach ($fieldGrant AS $key => $val){
//掩码相关类型字段
if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
$pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
$rs = preg_replace($pattern, "$1****$2", $v[$val['field']]);
$list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)$rs : null;
} elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
$email_array = explode("@", $v[$val['field']]);
$prevfix = (strlen($email_array[0]) < 4) ? "" : substr($v[$val['field']], 0, 2); //
$str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $v[$val['field']], -1, $count);
$rs = $prevfix . $str;
$list[$k][$val['field']] = !empty($v[$val['field']]) ?$rs: null;
} elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
$list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)substr_replace($v[$val['field']], '*****',0,strlen($v[$val['field']])) : null;
}
}
$statusInfo = []; $statusInfo = [];
$status_count = 0; $status_count = 0;
if (!$v['is_end']) { if (!$v['is_end']) {
@ -301,6 +339,9 @@ class Business extends Common
$list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null; $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; $list[$k]['update_time'] = !empty($v['update_time']) ? date('Y-m-d H:i:s', $v['update_time']) : null;
$list[$k]['last_time'] = !empty($v['last_time']) ? date('Y-m-d H:i:s', $v['last_time']) : null; $list[$k]['last_time'] = !empty($v['last_time']) ? date('Y-m-d H:i:s', $v['last_time']) : null;
# 系统字段 负责人部门 zjf 20210726
$list[$k]['owner_user_structure_name'] = $list[$k]['owner_user_id_info']['structure_name'];
} }
$data = []; $data = [];
$data['list'] = $list ?: []; $data['list'] = $list ?: [];
@ -633,13 +674,41 @@ 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) 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'){
$grantData = getFieldGrantData($userId);
foreach ($grantData['crm_business'] as $key => $value) {
foreach ($value as $ke => $va) {
if($va['maskType']!=0){
$fieldGrant[$ke]['maskType'] = $va['maskType'];
$fieldGrant[$ke]['form_type'] = $va['form_type'];
$fieldGrant[$ke]['field'] = $va['field'];
}
}
}
foreach ($fieldGrant AS $key => $val){
//掩码相关类型字段
if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
$pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
$rs = preg_replace($pattern, "$1****$2", $dataInfo[$val['field']]);
$dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)$rs : null;
} elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
$email_array = explode("@", $dataInfo[$val['field']]);
$prevfix = (strlen($email_array[0]) < 4) ? "" : substr($dataInfo[$val['field']], 0, 2); //
$str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $dataInfo[$val['field']], -1, $count);
$rs = $prevfix . $str;
$dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ?$rs: null;
} 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;
}
}
}
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : []; $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
$dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : []; $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
@ -902,15 +971,24 @@ class Business extends Common
public function getSystemInfo($id) public function getSystemInfo($id)
{ {
# 商机 # 商机
$business = Db::name('crm_business')->field(['create_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
$userModel = new \app\admin\model\User();
$ownerUserInfo = $userModel->getUserById($business['owner_user_id']);
# 负责人部门
$ownerStructureName = $ownerUserInfo['structure_name'];
# 负责人
$ownerUserName = $ownerUserInfo['realname'];
return [ return [
'create_user_id' => $realname, 'create_user_id' => $realname,
'owner_user_id' => $ownerUserName,
'create_time' => date('Y-m-d H:i:s', $business['create_time']), 'create_time' => date('Y-m-d H:i:s', $business['create_time']),
'update_time' => date('Y-m-d H:i:s', $business['update_time']), 'update_time' => date('Y-m-d H:i:s', $business['update_time']),
'last_time' => !empty($business['last_time']) ? date('Y-m-d H:i:s', $business['last_time']) : '' 'last_time' => !empty($business['last_time']) ? date('Y-m-d H:i:s', $business['last_time']) : '',
'owner_user_structure_name' => $ownerStructureName
]; ];
} }

@ -136,6 +136,9 @@ class Contacts extends Common
$positionField = $fieldModel->getFieldByFormType('crm_contacts', 'position'); // 地址类型字段 $positionField = $fieldModel->getFieldByFormType('crm_contacts', 'position'); // 地址类型字段
$handwritingField = $fieldModel->getFieldByFormType('crm_contacts', 'handwriting_sign'); // 手写签名类型字段 $handwritingField = $fieldModel->getFieldByFormType('crm_contacts', 'handwriting_sign'); // 手写签名类型字段
$locationField = $fieldModel->getFieldByFormType('crm_contacts', 'location'); // 定位类型字段 $locationField = $fieldModel->getFieldByFormType('crm_contacts', 'location'); // 定位类型字段
$boxField = $fieldModel->getFieldByFormType('crm_contacts', 'checkbox'); // 多选类型字段
$floatField = $fieldModel->getFieldByFormType('crm_contacts', 'floatnumber'); // 货币类型字段
// $fieldGrant = db('admin_field_mask')->where('types', 'contacts')->select();
# 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段) # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
$temporaryField = str_replace('_name', '', $order_field); $temporaryField = str_replace('_name', '', $order_field);
if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) { if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
@ -187,6 +190,16 @@ class Contacts extends Common
foreach ($extraList as $key => $value) { foreach ($extraList as $key => $value) {
$extraData[$value['contacts_id']][$value['field']] = $value['content']; $extraData[$value['contacts_id']][$value['field']] = $value['content'];
} }
$grantData = getFieldGrantData($user_id);
foreach ($grantData['crm_contacts'] as $key => $value) {
foreach ($value as $ke => $va) {
if($va['maskType']!=0){
$fieldGrant[$ke]['maskType'] = $va['maskType'];
$fieldGrant[$ke]['form_type'] = $va['form_type'];
$fieldGrant[$ke]['field'] = $va['field'];
}
}
}
foreach ($list as $k => $v) { foreach ($list as $k => $v) {
$list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : []; $list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
$list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : []; $list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
@ -223,6 +236,31 @@ class Contacts extends Common
foreach ($locationField AS $key => $val) { foreach ($locationField AS $key => $val) {
$list[$k][$val] = !empty($extraData[$v['contacts_id']][$val]) ? json_decode($extraData[$v['contacts_id']][$val], true) : null; $list[$k][$val] = !empty($extraData[$v['contacts_id']][$val]) ? json_decode($extraData[$v['contacts_id']][$val], true) : null;
} }
// 多选框类型字段
foreach ($boxField AS $key => $val) {
$list[$k][$val] = !empty($v[$val]) ? trim($v[$val], ',') : null;
}
// 货币类型字段
foreach ($floatField AS $key => $val) {
$list[$k][$val] = $v[$val]!='0.00' ? (string)$v[$val] : null;
}
//掩码相关类型字段
foreach ($fieldGrant AS $key => $val){
//掩码相关类型字段
if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
$pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
$rs = preg_replace($pattern, "$1****$2", $v[$val['field']]);
$list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)$rs : null;
} elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
$email_array = explode("@", $v[$val['field']]);
$prevfix = (strlen($email_array[0]) < 4) ? "" : substr($v[$val['field']], 0, 2); //
$str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $v[$val['field']], -1, $count);
$rs = $prevfix . $str;
$list[$k][$val['field']] = !empty($v[$val['field']]) ?$rs: null;
} elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
$list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)substr_replace($v[$val['field']], '*****',0,strlen($v[$val['field']])) : null;
}
}
//权限 //权限
$permission = []; $permission = [];
$is_read = 0; $is_read = 0;
@ -248,6 +286,9 @@ class Contacts extends Common
$list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : ''; $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'] : ''; $list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : '';
# 系统字段 负责人部门 zjf 20210726
$list[$k]['owner_user_structure_name'] = $list[$k]['owner_user_id_info']['structure_name'];
} }
$data = []; $data = [];
$data['list'] = $list; $data['list'] = $list;
@ -586,7 +627,7 @@ class Contacts 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) public function getDataById($id = '', $userId = 0,$model='')
{ {
$map['contacts_id'] = $id; $map['contacts_id'] = $id;
$dataInfo = db('crm_contacts')->where($map)->find(); $dataInfo = db('crm_contacts')->where($map)->find();
@ -594,6 +635,35 @@ class Contacts extends Common
$this->error = '暂无此数据'; $this->error = '暂无此数据';
return false; return false;
} }
if(empty($model) && $model!='update'){
$grantData = getFieldGrantData($userId);
foreach ($grantData['crm_contacts'] as $key => $value) {
foreach ($value as $ke => $va) {
if($va['maskType']!=0){
$fieldGrant[$ke]['maskType'] = $va['maskType'];
$fieldGrant[$ke]['form_type'] = $va['form_type'];
$fieldGrant[$ke]['field'] = $va['field'];
}
}
}
foreach ($fieldGrant AS $key => $val){
//掩码相关类型字段
if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
$pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
$rs = preg_replace($pattern, "$1****$2", $dataInfo[$val['field']]);
$dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)$rs : null;
} elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
$email_array = explode("@", $dataInfo[$val['field']]);
$prevfix = (strlen($email_array[0]) < 4) ? "" : substr($dataInfo[$val['field']], 0, 2); //
$str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $dataInfo[$val['field']], -1, $count);
$rs = $prevfix . $str;
$dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ?$rs: null;
} 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;
}
}
}
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : []; $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
$dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : []; $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
@ -694,15 +764,25 @@ class Contacts extends Common
public function getSystemInfo($id) public function getSystemInfo($id)
{ {
# 联系人 # 联系人
$contacts = Db::name('crm_contacts')->field(['create_user_id', 'create_time', 'update_time', 'last_time'])->where('contacts_id', $id)->find(); $contacts = Db::name('crm_contacts')->field(['create_user_id','owner_user_id' , 'create_time', 'update_time', 'last_time'])->where('contacts_id', $id)->find();
# 创建人 # 创建人
$realname = Db::name('admin_user')->where('id', $contacts['create_user_id'])->value('realname'); $realname = Db::name('admin_user')->where('id', $contacts['create_user_id'])->value('realname');
# zjf 20210726
$userModel = new \app\admin\model\User();
$ownerUserInfo = $userModel->getUserById($contacts['owner_user_id']);
# 负责人部门
$ownerStructureName = $ownerUserInfo['structure_name'];
# 负责人
$ownerUserName = $ownerUserInfo['realname'];
return [ return [
'create_user_id' => $realname, 'create_user_id' => $realname,
'owner_user_id' => $ownerUserName,
'create_time' => date('Y-m-d H:i:s', $contacts['create_time']), 'create_time' => date('Y-m-d H:i:s', $contacts['create_time']),
'update_time' => date('Y-m-d H:i:s', $contacts['update_time']), 'update_time' => date('Y-m-d H:i:s', $contacts['update_time']),
'last_time' => !empty($contacts['last_time']) ? date('Y-m-d H:i:s', $contacts['last_time']) : '' 'last_time' => !empty($contacts['last_time']) ? date('Y-m-d H:i:s', $contacts['last_time']) : '',
'owner_user_structure_name' => $ownerStructureName
]; ];
} }
} }

@ -23,7 +23,7 @@ class Contract extends Common
protected $createTime = 'create_time'; protected $createTime = 'create_time';
protected $updateTime = 'update_time'; protected $updateTime = 'update_time';
protected $autoWriteTimestamp = true; protected $autoWriteTimestamp = true;
private $statusArr = ['0'=>'待审核','1'=>'审核中','2'=>'审核通过','3'=>'已拒绝','4'=>'已撤回','5'=>'未提交','6'=>'已作废']; private $statusArr = ['0'=>'待审核','1'=>'审核中','2'=>'审核通过','3'=>'已拒绝','4'=>'已撤回','5'=>'未提交','6'=>'已作废', '7'=>'正常'];
/** /**
* [getDataList 合同list] * [getDataList 合同list]
@ -36,6 +36,9 @@ class Contract extends Common
*/ */
public function getDataList($request) public function getDataList($request)
{ {
// if($param['check_status'] == 2){
// die('11');
// }
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$structureModel = new \app\admin\model\Structure(); $structureModel = new \app\admin\model\Structure();
$fieldModel = new \app\admin\model\Field(); $fieldModel = new \app\admin\model\Field();
@ -62,8 +65,8 @@ class Contract extends Common
unset($request['isMessage']); unset($request['isMessage']);
$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();
# getCount是代办事项传来的参数代办事项不需要使用场景 # getCount是代办事项传来的参数代办事项不需要使用场景
$sceneMap = []; $sceneMap = [];
@ -148,6 +151,9 @@ class Contract extends Common
$positionField = $fieldModel->getFieldByFormType('crm_contract', 'position'); // 地址类型字段 $positionField = $fieldModel->getFieldByFormType('crm_contract', 'position'); // 地址类型字段
$handwritingField = $fieldModel->getFieldByFormType('crm_contract', 'handwriting_sign'); // 手写签名类型字段 $handwritingField = $fieldModel->getFieldByFormType('crm_contract', 'handwriting_sign'); // 手写签名类型字段
$locationField = $fieldModel->getFieldByFormType('crm_contract', 'location'); // 定位类型字段 $locationField = $fieldModel->getFieldByFormType('crm_contract', 'location'); // 定位类型字段
$boxField = $fieldModel->getFieldByFormType('crm_contract', 'checkbox'); // 多选类型字段
$floatField = $fieldModel->getFieldByFormType('crm_contract', 'floatnumber'); // 货币类型字段
# 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段) # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
$temporaryField = str_replace('_name', '', $order_field); $temporaryField = str_replace('_name', '', $order_field);
if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) { if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
@ -188,6 +194,12 @@ class Contract extends Common
if ($vv == 'contract.customer_name') unset($indexField[(int)$kk]); if ($vv == 'contract.customer_name') unset($indexField[(int)$kk]);
if ($vv == 'contract.business_name') unset($indexField[(int)$kk]); if ($vv == 'contract.business_name') unset($indexField[(int)$kk]);
} }
# zjf 20210727 添加回款绑定合同 合同列表 状态为审核通过和正常
if($requestMap['check_status'] == 2){
$map['contract.check_status'] = ['in', [2,7]];
}
$list = db('crm_contract') $list = db('crm_contract')
->alias('contract') ->alias('contract')
->join('__CRM_CUSTOMER__ customer','contract.customer_id = customer.customer_id','LEFT') ->join('__CRM_CUSTOMER__ customer','contract.customer_id = customer.customer_id','LEFT')
@ -218,6 +230,16 @@ class Contract extends Common
foreach ($extraList AS $key => $value) { foreach ($extraList AS $key => $value) {
$extraData[$value['contract_id']][$value['field']] = $value['content']; $extraData[$value['contract_id']][$value['field']] = $value['content'];
} }
$grantData = getFieldGrantData($user_id);
foreach ($grantData['crm_contract'] as $key => $value) {
foreach ($value as $ke => $va) {
if($va['maskType']!=0){
$fieldGrant[$ke]['maskType'] = $va['maskType'];
$fieldGrant[$ke]['form_type'] = $va['form_type'];
$fieldGrant[$ke]['field'] = $va['field'];
}
}
}
foreach ($list as $k=>$v) { foreach ($list as $k=>$v) {
$list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : []; $list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
$list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : []; $list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
@ -253,6 +275,31 @@ class Contract extends Common
// 定位类型字段 // 定位类型字段
foreach ($locationField AS $key => $val) { foreach ($locationField AS $key => $val) {
$list[$k][$val] = !empty($extraData[$v['contract_id']][$val]) ? json_decode($extraData[$v['contract_id']][$val], true) : null; $list[$k][$val] = !empty($extraData[$v['contract_id']][$val]) ? json_decode($extraData[$v['contract_id']][$val], true) : null;
}
// 多选框类型字段
foreach ($boxField AS $key => $val) {
$list[$k][$val] = !empty($v[$val]) ? trim($v[$val], ',') : null;
}
// 货币类型字段
foreach ($floatField AS $key => $val) {
$list[$k][$val] = $v[$val]!='0.00' ? (string)$v[$val] : null;
}
//掩码相关类型字段
foreach ($fieldGrant AS $key => $val){
//掩码相关类型字段
if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
$pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
$rs = preg_replace($pattern, "$1****$2", $v[$val['field']]);
$list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)$rs : null;
} elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
$email_array = explode("@", $v[$val['field']]);
$prevfix = (strlen($email_array[0]) < 4) ? "" : substr($v[$val['field']], 0, 2); //
$str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $v[$val['field']], -1, $count);
$rs = $prevfix . $str;
$list[$k][$val['field']] = !empty($v[$val['field']]) ?$rs: null;
} elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
$list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)substr_replace($v[$val['field']], '*****',0,strlen($v[$val['field']])) : null;
}
} }
$list[$k]['business_id_info']['business_id'] = $v['business_id']; $list[$k]['business_id_info']['business_id'] = $v['business_id'];
$list[$k]['business_id_info']['name'] = $v['business_name']; $list[$k]['business_id_info']['name'] = $v['business_name'];
@ -260,6 +307,7 @@ class Contract extends Common
$list[$k]['customer_id_info']['name'] = $v['customer_name']; $list[$k]['customer_id_info']['name'] = $v['customer_name'];
$list[$k]['contacts_id_info']['contacts_id'] = $v['contacts_id']; $list[$k]['contacts_id_info']['contacts_id'] = $v['contacts_id'];
$list[$k]['contacts_id_info']['name'] = $v['contacts_name']; $list[$k]['contacts_id_info']['name'] = $v['contacts_name'];
$list[$k]['check_status_info'] = $this->statusArr[$v['check_status']]; $list[$k]['check_status_info'] = $this->statusArr[$v['check_status']];
$moneyInfo = []; $moneyInfo = [];
$moneyInfo = $receivablesModel->getMoneyByContractId($v['contract_id']); $moneyInfo = $receivablesModel->getMoneyByContractId($v['contract_id']);
@ -298,6 +346,9 @@ class Contract extends Common
$list[$k]['order_user_name'] = implode(',', $orderNames); $list[$k]['order_user_name'] = implode(',', $orderNames);
unset($list[$k]['order_user_id']); unset($list[$k]['order_user_id']);
$list[$k]['order_user_id_name'] = $v['order_user_id']; $list[$k]['order_user_id_name'] = $v['order_user_id'];
# 系统字段 负责人部门 zjf 20210726
$list[$k]['owner_user_structure_name'] = $list[$k]['owner_user_id_info']['structure_name'];
} }
$data = []; $data = [];
$data['list'] = $list; $data['list'] = $list;
@ -749,7 +800,7 @@ class Contract 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) public function getDataById($id = '', $userId = 0,$model='')
{ {
$receivablesModel = new \app\crm\model\Receivables(); $receivablesModel = new \app\crm\model\Receivables();
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
@ -759,6 +810,35 @@ class Contract extends Common
$this->error = '暂无此数据'; $this->error = '暂无此数据';
return false; return false;
} }
if(empty($model) && $model!='update'){
$grantData = getFieldGrantData($userId);
foreach ($grantData['crm_contract'] as $key => $value) {
foreach ($value as $ke => $va) {
if($va['maskType']!=0){
$fieldGrant[$ke]['maskType'] = $va['maskType'];
$fieldGrant[$ke]['form_type'] = $va['form_type'];
$fieldGrant[$ke]['field'] = $va['field'];
}
}
}
foreach ($fieldGrant AS $key => $val){
//掩码相关类型字段
if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
$pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
$rs = preg_replace($pattern, "$1****$2", $dataInfo[$val['field']]);
$dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)$rs : null;
} elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
$email_array = explode("@", $dataInfo[$val['field']]);
$prevfix = (strlen($email_array[0]) < 4) ? "" : substr($dataInfo[$val['field']], 0, 2); //
$str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $dataInfo[$val['field']], -1, $count);
$rs = $prevfix . $str;
$dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ?$rs: null;
} 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['create_user_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : []; $dataInfo['create_user_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
$dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : []; $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
$dataInfo['create_user_name'] = !empty($dataInfo['create_user_info']['realname']) ? $dataInfo['create_user_info']['realname'] : ''; $dataInfo['create_user_name'] = !empty($dataInfo['create_user_info']['realname']) ? $dataInfo['create_user_info']['realname'] : '';
@ -903,20 +983,32 @@ class Contract extends Common
public function getSystemInfo($id) public function getSystemInfo($id)
{ {
# 合同 # 合同
$business = Db::name('crm_contract')->where('contract_id', $id)->find(); $contract = Db::name('crm_contract')->where('contract_id', $id)->find();
# 创建人 # 创建人
$realname = Db::name('admin_user')->where('id', $business['create_user_id'])->value('realname'); $realname = Db::name('admin_user')->where('id', $contract['create_user_id'])->value('realname');
# zjf 20210726
$userModel = new \app\admin\model\User();
$ownerUserInfo = $userModel->getUserById($contract['owner_user_id']);
# 负责人部门
$ownerStructureName = $ownerUserInfo['structure_name'];
# 负责人
$ownerUserName = $ownerUserInfo['realname'];
# 回款 # 回款
$receivablesModel = new Receivables(); $receivablesModel = new Receivables();
$receivables = $receivablesModel->getMoneyByContractId($id); $receivables = $receivablesModel->getMoneyByContractId($id);
return [ return [
'create_user_id' => $realname, 'create_user_id' => $realname,
'create_time' => date('Y-m-d H:i:s', $business['create_time']), 'owner_user_id' => $ownerUserName,
'update_time' => date('Y-m-d H:i:s', $business['update_time']), 'create_time' => date('Y-m-d H:i:s', $contract['create_time']),
'last_time' => !empty($business['last_time']) ? date('Y-m-d H:i:s', $business['last_time']) : '', 'update_time' => date('Y-m-d H:i:s', $contract['update_time']),
'last_time' => !empty($contract['last_time']) ? date('Y-m-d H:i:s', $contract['last_time']) : '',
'done_money' => $receivables['doneMoney'], 'done_money' => $receivables['doneMoney'],
'un_money' => $receivables['unMoney'] 'un_money' => $receivables['unMoney'],
'owner_user_structure_name' => $ownerStructureName
]; ];
} }

@ -70,7 +70,6 @@ class Customer extends Common
$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();
# 客户默认条件 # 客户默认条件
$customerMap = $this->getWhereByCustomer(); $customerMap = $this->getWhereByCustomer();
@ -105,11 +104,12 @@ class Customer extends Common
unset($map['team_id']); unset($map['team_id']);
}else{ }else{
$map = $requestMap ? array_merge($sceneMap, $requestMap) : $sceneMap; $map = $requestMap ? array_merge($sceneMap, $requestMap) : $sceneMap;
} }
# 高级筛选 # 高级筛选
$map = advancedQuery($map, 'crm', 'customer', 'index'); $map = advancedQuery($map, 'crm', 'customer', 'index');
# 工作台仪表盘 # 工作台仪表盘
$requestData = $this->requestData(); $requestData = $this->requestData();
$dashboardWhere = []; $dashboardWhere = [];
@ -204,13 +204,16 @@ class Customer extends Common
$positionField = $fieldModel->getFieldByFormType('crm_customer', 'position'); // 地址类型字段 $positionField = $fieldModel->getFieldByFormType('crm_customer', 'position'); // 地址类型字段
$handwritingField = $fieldModel->getFieldByFormType('crm_customer', 'handwriting_sign'); // 手写签名类型字段 $handwritingField = $fieldModel->getFieldByFormType('crm_customer', 'handwriting_sign'); // 手写签名类型字段
$locationField = $fieldModel->getFieldByFormType('crm_customer', 'location'); // 定位类型字段 $locationField = $fieldModel->getFieldByFormType('crm_customer', 'location'); // 定位类型字段
$boxField = $fieldModel->getFieldByFormType('crm_customer', 'checkbox'); // 多选类型字段
$floatField = $fieldModel->getFieldByFormType('crm_customer', 'floatnumber'); // 货币类型字段
# 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段) # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
$temporaryField = str_replace('_name', '', $order_field); $temporaryField = str_replace('_name', '', $order_field);
if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) { if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
$order_field = $temporaryField; $order_field = $temporaryField;
} }
# 排序 # 排序
if ($order_type && $order_field) { if ($order_type && $order_field && $order_field != 'owner_user_structure_name') {
$order = $fieldModel->getOrderByFormtype('crm_customer','customer',$order_field,$order_type); $order = $fieldModel->getOrderByFormtype('crm_customer','customer',$order_field,$order_type);
} else { } else {
$order = 'customer.update_time desc'; $order = 'customer.update_time desc';
@ -229,7 +232,9 @@ class Customer extends Common
->limit($request['offset'], $request['length']) ->limit($request['offset'], $request['length'])
->field($indexField) ->field($indexField)
->orderRaw($order) ->orderRaw($order)
// ->fetchSql()
->select(); ->select();
// p(db('crm_customer')->getLastSql());
$readAuthIds = $userModel->getUserByPer('crm', 'customer', 'read'); $readAuthIds = $userModel->getUserByPer('crm', 'customer', 'read');
$updateAuthIds = $userModel->getUserByPer('crm', 'customer', 'update'); $updateAuthIds = $userModel->getUserByPer('crm', 'customer', 'update');
$deleteAuthIds = $userModel->getUserByPer('crm', 'customer', 'delete'); $deleteAuthIds = $userModel->getUserByPer('crm', 'customer', 'delete');
@ -245,23 +250,37 @@ class Customer extends Common
]) ])
->group('customer_id') ->group('customer_id')
->select(); ->select();
$business_count = array_column($business_count, null, 'customer_id'); $business_count = array_column($business_count, null, 'customer_id');
$field_list = $fieldModel->getIndexFieldConfig('crm_customer', $user_id); $field_list = $fieldModel->getIndexFieldConfig('crm_customer', $user_id);
$field_list = array_column($field_list, 'field'); $field_list = array_column($field_list, 'field');
# 扩展数据 # 扩展数据
$extraData = []; $extraData = [];
$extraList = db('crm_customer_data')->whereIn('customer_id', $customer_id_list)->select(); $extraList = db('crm_customer_data')->whereIn('customer_id', $customer_id_list)->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'];
} }
$grantData = getFieldGrantData($user_id);
foreach ($grantData['crm_customer'] as $key => $value) {
foreach ($value as $ke => $va) {
if($va['maskType']!=0){
$fieldGrant[$ke]['maskType'] = $va['maskType'];
$fieldGrant[$ke]['form_type'] = $va['form_type'];
$fieldGrant[$ke]['field'] = $va['field'];
}
}
}
# 获取进入公海天数 # 获取进入公海天数
$poolDays = $this->getPoolDay($customer_id_list); $poolDays = $this->getPoolDay($customer_id_list);
# 整理数据 # 整理数据
foreach ($list AS $k => $v) { foreach ($list AS $k => $v) {
$list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : []; $list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
$list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : []; $list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
$list[$k]['create_user_name'] = !empty($list[$k]['create_user_id_info']['realname']) ? $list[$k]['create_user_id_info']['realname'] : ''; $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'] : ''; $list[$k]['owner_user_name'] = !empty($list[$k]['owner_user_id_info']['realname']) ? $list[$k]['owner_user_id_info']['realname'] : '';
# 用户类型字段 # 用户类型字段
foreach ($userField AS $key => $val) { foreach ($userField AS $key => $val) {
if (in_array($val, $indexField)) { if (in_array($val, $indexField)) {
@ -300,6 +319,31 @@ class Customer extends Common
// 定位类型字段 // 定位类型字段
foreach ($locationField AS $key => $val) { foreach ($locationField AS $key => $val) {
$list[$k][$val] = !empty($extraData[$v['customer_id']][$val]) ? json_decode($extraData[$v['customer_id']][$val], true) : null; $list[$k][$val] = !empty($extraData[$v['customer_id']][$val]) ? json_decode($extraData[$v['customer_id']][$val], true) : null;
}
// 多选框类型字段
foreach ($boxField AS $key => $val) {
$list[$k][$val] = !empty($v[$val]) ? trim($v[$val], ',') : null;
}
// 货币类型字段
foreach ($floatField AS $key => $val) {
$list[$k][$val] = $v[$val]!='0.00' ? (string)$v[$val] : null;
}
//掩码相关类型字段
foreach ($fieldGrant AS $key => $val){
//掩码相关类型字段
if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
$pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
$rs = preg_replace($pattern, "$1****$2", $v[$val['field']]);
$list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)$rs : null;
} elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
$email_array = explode("@", $v[$val['field']]);
$prevfix = (strlen($email_array[0]) < 4) ? "" : substr($v[$val['field']], 0, 2); //
$str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $v[$val['field']], -1, $count);
$rs = $prevfix . $str;
$list[$k][$val['field']] = !empty($v[$val['field']]) ?$rs: null;
} elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
$list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)substr_replace($v[$val['field']], '*****',0,strlen($v[$val['field']])) : null;
}
} }
# 商机数 # 商机数
$list[$k]['business_count'] = $business_count[$v['customer_id']]['count'] ?: 0; $list[$k]['business_count'] = $business_count[$v['customer_id']]['count'] ?: 0;
@ -331,6 +375,9 @@ class Customer extends Common
# 进入公海天数 # 进入公海天数
$list[$k]['pool_day'] = isset($poolDays[$v['customer_id']]) ? $poolDays[$v['customer_id']] : ''; $list[$k]['pool_day'] = isset($poolDays[$v['customer_id']]) ? $poolDays[$v['customer_id']] : '';
$list[$k]['is_pool'] = 0; $list[$k]['is_pool'] = 0;
# 系统字段 负责人部门 zjf 20210726
$list[$k]['owner_user_structure_name'] = $list[$k]['owner_user_id_info']['structure_name'];
} }
} }
$data = []; $data = [];
@ -423,10 +470,11 @@ class Customer extends Common
$locationField = $fieldModel->getFieldByFormType('crm_customer', 'location'); $locationField = $fieldModel->getFieldByFormType('crm_customer', 'location');
$dateIntervalField = $fieldModel->getFieldByFormType('crm_customer', 'date_interval'); $dateIntervalField = $fieldModel->getFieldByFormType('crm_customer', 'date_interval');
$detailTableField = $fieldModel->getFieldByFormType('crm_customer', 'detail_table'); $detailTableField = $fieldModel->getFieldByFormType('crm_customer', 'detail_table');
$dateField = $fieldModel->getFieldByFormType('crm_customer', 'date');
foreach ($param AS $key => $value) { foreach ($param AS $key => $value) {
// 处理地址类型字段数据 // 处理地址类型字段数据
if (in_array($key, $positionField)) { if (in_array($key, $positionField)) {
if (!empty($value)) { if (!empty($value) && is_array($value)) {
$customerData[] = [ $customerData[] = [
'field' => $key, 'field' => $key,
'content' => json_encode($value, JSON_NUMERIC_CHECK), 'content' => json_encode($value, JSON_NUMERIC_CHECK),
@ -434,33 +482,45 @@ class Customer extends Common
]; ];
$positionNames = array_column($value, 'name'); $positionNames = array_column($value, 'name');
$param[$key] = implode(',', $positionNames); $param[$key] = implode(',', $positionNames);
} else { } elseif(!empty($value) && !is_array($value)){
$param[$key] = $value;
}else{
$param[$key] = ''; $param[$key] = '';
} }
} }
// 处理定位类型字段数据 // 处理定位类型字段数据
if (in_array($key, $locationField)) { if (in_array($key, $locationField)) {
if (!empty($value)) { if (!empty($value) && isset($value['address'])) {
$customerData[] = [ $customerData[] = [
'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'];
} else { } elseif(!empty($value) && !isset($value['address'])){
$vv['address']=$value;
$customerData[] = [
'field' => $key,
'content' => json_encode($vv, JSON_NUMERIC_CHECK),
'create_time' => time()
];
$param[$key] = $value;
} else{
$param[$key] = ''; $param[$key] = '';
} }
} }
// 处理日期区间类型字段数据 // 处理日期区间类型字段数据
if (in_array($key, $dateIntervalField)) { if (in_array($key, $dateIntervalField)) {
if (!empty($value)) { if (!empty($value) && is_array($value)) {
$customerData[] = [ $customerData[] = [
'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] = trim(implode('_', $value),'"');
} else { } elseif(!empty($value) && !is_array($value)){
$param[$key] = $value;
}else{
$param[$key] = ''; $param[$key] = '';
} }
} }
@ -477,12 +537,26 @@ class Customer extends Common
$param[$key] = ''; $param[$key] = '';
} }
} }
$param[$key]=!empty($value)?trim($value,','):'';
if (in_array($key, $dateField)) {
if (!empty($value) ) {
$customerData[] = [
'field' => $key,
'content' => json_encode($value, JSON_NUMERIC_CHECK),
'create_time' => time()
];
$param[$key] = $value;
} else{
$param[$key] = null;
}
}
} }
// p($customerData);
# 设置今日需联系客户 # 设置今日需联系客户
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;
$pool_id = !empty($param['pool_id']) ? $param['pool_id'] : 0; $pool_id = !empty($param['pool_id']) ? $param['pool_id'] : 0;
unset($param['pool_id']); unset($param['pool_id']);
if ($this->data($param)->allowField(true)->isUpdate(false)->save()) { if ($this->data($param)->allowField(true)->isUpdate(false)->save()) {
$data['customer_id'] = $this->customer_id; $data['customer_id'] = $this->customer_id;
$data['name'] = $param['name']; $data['name'] = $param['name'];
@ -647,12 +721,14 @@ class Customer extends Common
// 处理日期区间类型字段数据 // 处理日期区间类型字段数据
if (in_array($key, $dateIntervalField)) { if (in_array($key, $dateIntervalField)) {
if (!empty($value)) { if (!empty($value)) {
$customerData[] = [ $customerData[] = [
'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);
} else { } else {
$param[$key] = ''; $param[$key] = '';
} }
@ -671,7 +747,6 @@ class Customer 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;
@ -709,13 +784,41 @@ class Customer 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) public function getDataById($id = '', $userId = 0,$model='')
{ {
$dataInfo = db('crm_customer')->where(['customer_id' => $id])->find(); $dataInfo = db('crm_customer')->where(['customer_id' => $id])->find();
if (!$dataInfo) { if (!$dataInfo) {
$this->error = '数据不存在或已删除'; $this->error = '数据不存在或已删除';
return false; return false;
} }
if(empty($model) && $model!='update'){
$grantData = getFieldGrantData($userId);
foreach ($grantData['crm_customer'] as $key => $value) {
foreach ($value as $ke => $va) {
if($va['maskType']!=0){
$fieldGrant[$ke]['maskType'] = $va['maskType'];
$fieldGrant[$ke]['form_type'] = $va['form_type'];
$fieldGrant[$ke]['field'] = $va['field'];
}
}
}
foreach ($fieldGrant AS $key => $val){
//掩码相关类型字段
if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
$pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
$rs = preg_replace($pattern, "$1****$2", $dataInfo[$val['field']]);
$dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)$rs : null;
} elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
$email_array = explode("@", $dataInfo[$val['field']]);
$prevfix = (strlen($email_array[0]) < 4) ? "" : substr($dataInfo[$val['field']], 0, 2); //
$str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $dataInfo[$val['field']], -1, $count);
$rs = $prevfix . $str;
$dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ?$rs: null;
} 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;
}
}
}
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : []; $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
$dataInfo['owner_user_id_info'] = !empty($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : []; $dataInfo['owner_user_id_info'] = !empty($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
@ -1608,22 +1711,24 @@ class Customer extends Common
*/ */
public function getNearbyList($param) public function getNearbyList($param)
{ {
$apiCommon = new ApiCommon();
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
# 客户条件 $poolStatus = checkPerByAction('crm', 'customer', 'pool');
# 客户
$customerAuth = [];
$customerWhere = []; $customerWhere = [];
if (!empty($param['type']) && $param['type'] == 2) { if ((!empty($param['type']) && $param['type'] == 2) || !$poolStatus) {
$customerWhere = $this->getWhereByCustomer(); $customerWhere = $this->getWhereByCustomer();
} }
# 公海条件 # 公海
$poolWhere = []; $poolWhere = [];
if (!empty($param['type']) && $param['type'] == 9) { if (!empty($param['type']) && $param['type'] == 9 && $poolStatus) {
$poolWhere = ['customer.owner_user_id' => 0]; $poolWhere = ['customer.owner_user_id' => 0];
$model = '公海客户管理模块';
} }
# 附近
# 距离条件
$lngLatRange = $this->getLngLatRange($param['lng'], $param['lat'], $param['distance']); $lngLatRange = $this->getLngLatRange($param['lng'], $param['lat'], $param['distance']);
$lngLatWhere = function ($query) use ($lngLatRange) { $lngLatWhere = function ($query) use ($lngLatRange) {
$query->where(['lng' => ['egt', $lngLatRange['minLng']]]); $query->where(['lng' => ['egt', $lngLatRange['minLng']]]);
@ -1643,23 +1748,31 @@ class Customer extends Common
->where($customerWhere) ->where($customerWhere)
->where($poolWhere) ->where($poolWhere)
->where($lngLatWhere) ->where($lngLatWhere)
->field(['customer_id', 'name', 'address', 'detail_address', 'owner_user_id', 'lat', 'lng','next_time','last_time']) ->where($customerAuth)
->field(['customer_id', 'name', 'address', 'detail_address', 'owner_user_id', 'lat', 'lng', 'next_time', 'last_time'])
->order('update_time', 'desc') ->order('update_time', 'desc')
->select(); ->select();
# 组装数据 # 组装数据
foreach ($list as $key => $value) { foreach ($list as $key => $value) {
$ownerUserInfo = !empty($value['owner_user_id']) ? $userModel->getUserById($value['owner_user_id']) : []; # todo 暂时将查询写在循环中
$ownerUserInfo = !empty($value['owner_user_id']) ? $userModel->getUserById($value['owner_user_id']) : [];
$ownerUserName = !empty($ownerUserInfo['realname']) ? $ownerUserInfo['realname'] : ''; $ownerUserName = !empty($ownerUserInfo['realname']) ? $ownerUserInfo['realname'] : '';
$list[$key]['owner_user_name'] = !empty($ownerUserName) ? $ownerUserName : '暂无负责人'; $list[$key]['owner_user_name'] = !empty($ownerUserName) ? $ownerUserName : '暂无负责人';
$list[$key]['distance'] = $this->getLngLatDistance($param['lng'], $param['lat'], $value['lng'], $value['lat'], 1, 0); $list[$key]['distance'] = $this->getLngLatDistance($param['lng'], $param['lat'], $value['lng'], $value['lat'], 1, 0);
$list[$key]['last_time'] = !empty($value['last_time'])?date('y-m-d H:i:s',$value['last_time']):!empty($value['next_time'])?date('y-m-d H:i:s',$value['next_time']):null; $list[$key]['last_time'] = !empty($value['last_time']) ? date('y-m-d H:i:s', $value['last_time']) : !empty($value['next_time']) ? date('y-m-d H:i:s', $value['next_time']) : null;
$list[$key]['model']=$model; if ($value['owner_user_id'] != 0) {
$list[$key]['model'] = '客户';
} else {
$list[$key]['model'] = '公海';
}
} }
return ['list' => $list, 'count' => $count]; return ['list' => $list, 'count' => $count];
} }
/** /**
* 计算两点地理坐标之间的距离 * 计算两点地理坐标之间的距离
* *
@ -1737,9 +1850,15 @@ class Customer extends Common
$customer = Db::name('crm_customer')->field($field)->where('customer_id', $id)->find(); $customer = Db::name('crm_customer')->field($field)->where('customer_id', $id)->find();
# 创建人 # 创建人
$createUserName = Db::name('admin_user')->where('id', $customer['create_user_id'])->value('realname'); $createUserName = Db::name('admin_user')->where('id', $customer['create_user_id'])->value('realname');
# 负责人
$ownerUserName = Db::name('admin_user')->where('id', $customer['owner_user_id'])->value('realname');
# zjf 20210726
$userModel = new \app\admin\model\User();
$ownerUserInfo = $userModel->getUserById($customer['owner_user_id']);
# 负责人部门
$ownerStructureName = $ownerUserInfo['structure_name'];
# 负责人
$ownerUserName = $ownerUserInfo['realname'];
return [ return [
'obtain_time' => !empty($customer['obtain_time']) ? date('Y-m-d H:i:s', $customer['obtain_time']) : '', 'obtain_time' => !empty($customer['obtain_time']) ? date('Y-m-d H:i:s', $customer['obtain_time']) : '',
'last_record' => !empty($customer['last_record']) ? $customer['last_record'] : '', 'last_record' => !empty($customer['last_record']) ? $customer['last_record'] : '',
@ -1748,7 +1867,8 @@ class Customer extends Common
'create_time' => date('Y-m-d H:i:s', $customer['create_time']), 'create_time' => date('Y-m-d H:i:s', $customer['create_time']),
'update_time' => date('Y-m-d H:i:s', $customer['update_time']), 'update_time' => date('Y-m-d H:i:s', $customer['update_time']),
'last_time' => !empty($customer['last_time']) ? date('Y-m-d H:i:s', $customer['last_time']) : '', 'last_time' => !empty($customer['last_time']) ? date('Y-m-d H:i:s', $customer['last_time']) : '',
'deal_status' => $customer['deal_status'] 'deal_status' => $customer['deal_status'],
'owner_user_structure_name' => $ownerStructureName
]; ];
} }

@ -51,4 +51,97 @@ class Invoice extends Common
'owner_user_name' => 'realname' 'owner_user_name' => 'realname'
]); ]);
} }
/**
* @param string $id
* @param int $userId
* @param string $model
* @author: alvin guogaobo
* @version: 11.1.0
* Date: 2021/8/30 14:11
*/
public function getDataById($id = '', $userId = 0, $model='')
{
$map['invoice_id'] = $id;
$dataInfo = $this->where($map)->find();
if (!$dataInfo) {
$this->error = '暂无此数据';
return false;
}
if(empty($model) && $model!='update'){
$grantData = getFieldGrantData($userId);
foreach ($grantData['crm_invoice'] as $key => $value) {
foreach ($value as $ke => $va) {
if($va['maskType']!=0){
$fieldGrant[$ke]['maskType'] = $va['maskType'];
$fieldGrant[$ke]['form_type'] = $va['form_type'];
$fieldGrant[$ke]['field'] = $va['field'];
}
}
}
foreach ($fieldGrant AS $key => $val){
//掩码相关类型字段
if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
$pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
$rs = preg_replace($pattern, "$1****$2", $dataInfo[$val['field']]);
$dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)$rs : null;
} elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
$email_array = explode("@", $dataInfo[$val['field']]);
$prevfix = (strlen($email_array[0]) < 4) ? "" : substr($dataInfo[$val['field']], 0, 2); //
$str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $dataInfo[$val['field']], -1, $count);
$rs = $prevfix . $str;
$dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ?$rs: null;
} 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;
}
}
}
// $userModel = new \app\admin\model\User();
// $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
// $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
// $dataInfo['create_user_name'] = !empty($dataInfo['create_user_id_info']['realname']) ? $dataInfo['create_user_id_info']['realname'] : '';
// $dataInfo['owner_user_name'] = !empty($dataInfo['owner_user_id_info']['realname']) ? $dataInfo['owner_user_id_info']['realname'] : '';
// $dataInfo['customer_id_info'] = $dataInfo['customer_id'] ? db('crm_customer')->where(['customer_id' => $dataInfo['customer_id']])->field('customer_id,name')->find() : [];
// $dataInfo['contract_id_info'] = $dataInfo['contract_id'] ? db('crm_contract')->where(['contract_id' => $dataInfo['contract_id']])->field('contract_id,name,money')->find() : [];
// $dataInfo['receivables_id'] = $id;
// $userModel = new \app\admin\model\User();
// $dataInfo['create_user_info'] = $userModel->getUserById($dataInfo['create_user_id']);
// $dataInfo['plan_id'] = $id;
// # 处理时间格式
// $fieldModel = new \app\admin\model\Field();
// $datetimeField = $fieldModel->getFieldByFormType('crm_receivables', 'datetime'); //日期时间类型
// foreach ($datetimeField as $key => $val) {
// $dataInfo[$val] = !empty($dataInfo[$val]) ? date('Y-m-d H:i:s', $dataInfo[$val]) : null;
// }
// $dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null;
// $dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
// // 字段授权
// if (!empty($userId)) {
// $grantData = getFieldGrantData($userId);
// $userLevel = isSuperAdministrators($userId);
// foreach ($dataInfo as $key => $value) {
// if (!$userLevel && !empty($grantData['crm_receivables'])) {
// $status = getFieldGrantStatus($key, $grantData['crm_receivables']);
//
// # 查看权限
// if ($status['read'] == 0) unset($dataInfo[$key]);
// }
// }
// if (!$userLevel && !empty($grantData['crm_receivables'])) {
// # 客户名称
// $customerStatus = getFieldGrantStatus('customer_id', $grantData['crm_receivables']);
// if ($customerStatus['read'] == 0) {
// $dataInfo['customer_name'] = '';
// $dataInfo['customer_id_info'] = [];
// }
// # 合同金额
// $contractMoneyStatus = getFieldGrantStatus('contract_money', $grantData['crm_receivables']);
// if ($contractMoneyStatus['read'] == 0) $dataInfo['contract_id_info']['money'] = '';
// # 合同名称
// $contractMoneyStatus = getFieldGrantStatus('contract_money', $grantData['crm_receivables']);
// if ($contractMoneyStatus['read'] == 0) $dataInfo['contract_id_info']['money'] = '';
// }
// }
return $dataInfo;
}
} }

@ -112,6 +112,8 @@ class Leads extends Common
$positionField = $fieldModel->getFieldByFormType('crm_leads', 'position'); // 地址类型字段 $positionField = $fieldModel->getFieldByFormType('crm_leads', 'position'); // 地址类型字段
$handwritingField = $fieldModel->getFieldByFormType('crm_leads', 'handwriting_sign'); // 手写签名类型字段 $handwritingField = $fieldModel->getFieldByFormType('crm_leads', 'handwriting_sign'); // 手写签名类型字段
$locationField = $fieldModel->getFieldByFormType('crm_leads', 'location'); // 定位类型字段 $locationField = $fieldModel->getFieldByFormType('crm_leads', 'location'); // 定位类型字段
$boxField = $fieldModel->getFieldByFormType('crm_leads', 'checkbox'); // 多选类型字段
$floatField = $fieldModel->getFieldByFormType('crm_leads', 'floatnumber'); // 货币类型字段
# 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段) # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
$temporaryField = str_replace('_name', '', $order_field); $temporaryField = str_replace('_name', '', $order_field);
if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) { if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
@ -153,7 +155,6 @@ class Leads extends Common
->field(implode(',', $indexField)) ->field(implode(',', $indexField))
->orderRaw($order) ->orderRaw($order)
->select(); ->select();
// echo db('crm_leads')->getLastSql();exit;
# 扩展数据 # 扩展数据
$extraData = []; $extraData = [];
$leads_id_list = !empty($list) ? array_column($list, 'leads_id') : []; $leads_id_list = !empty($list) ? array_column($list, 'leads_id') : [];
@ -161,6 +162,17 @@ class Leads extends Common
foreach ($extraList AS $key => $value) { foreach ($extraList AS $key => $value) {
$extraData[$value['leads_id']][$value['field']] = $value['content']; $extraData[$value['leads_id']][$value['field']] = $value['content'];
} }
$grantData = getFieldGrantData($user_id);
foreach ($grantData['crm_leads'] as $key => $value) {
foreach ($value as $ke => $va) {
if($va['maskType']!=0){
$fieldGrant[$ke]['maskType'] = $va['maskType'];
$fieldGrant[$ke]['form_type'] = $va['form_type'];
$fieldGrant[$ke]['field'] = $va['field'];
}
}
}
foreach ($list as $k => $v) { foreach ($list as $k => $v) {
$list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : []; $list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
$list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : []; $list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
@ -197,6 +209,36 @@ class Leads extends Common
foreach ($locationField AS $key => $val) { foreach ($locationField AS $key => $val) {
$list[$k][$val] = !empty($extraData[$v['leads_id']][$val]) ? json_decode($extraData[$v['leads_id']][$val], true) : null; $list[$k][$val] = !empty($extraData[$v['leads_id']][$val]) ? json_decode($extraData[$v['leads_id']][$val], true) : null;
} }
// 多选框类型字段
foreach ($boxField AS $key => $val) {
$list[$k][$val] = !empty($v[$val]) ? trim($v[$val], ',') : null;
}
// 货币类型字段
foreach ($floatField AS $key => $val) {
$list[$k][$val] = $v[$val]!='0.00' ? (string)$v[$val] : null;
}
foreach ($fieldGrant AS $key => $val){
//掩码相关类型字段
if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
$pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
$rs = preg_replace($pattern, "$1****$2", $v[$val['field']]);
$list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)$rs : null;
} elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
$email_array = explode("@", $v[$val['field']]);
$prevfix = (strlen($email_array[0]) < 4) ? "" : substr($v[$val['field']], 0, 2); //
$str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $v[$val['field']], -1, $count);
$rs = $prevfix . $str;
$list[$k][$val['field']] = !empty($v[$val['field']]) ?$rs: null;
} elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
$list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)substr_replace($v[$val['field']], '*****',0,strlen($v[$val['field']])) : null;
}
}
// 货币类型字段
foreach ($floatField AS $key => $val) {
$list[$k][$val] = $v[$val]!='0.00' ? (string)$v[$val] : null;
}
//权限 //权限
$permission = []; $permission = [];
$is_read = 0; $is_read = 0;
@ -217,6 +259,9 @@ class Leads extends Common
$list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null; $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; $list[$k]['update_time'] = !empty($v['update_time']) ? date('Y-m-d H:i:s', $v['update_time']) : null;
$list[$k]['last_time'] = !empty($v['last_time']) ? date('Y-m-d H:i:s', $v['last_time']) : null; $list[$k]['last_time'] = !empty($v['last_time']) ? date('Y-m-d H:i:s', $v['last_time']) : null;
# 系统字段 负责人部门 zjf 20210726
$list[$k]['owner_user_structure_name'] = $list[$k]['owner_user_id_info']['structure_name'];
} }
$data = []; $data = [];
$data['list'] = $list; $data['list'] = $list;
@ -362,7 +407,7 @@ class Leads extends Common
'type' => 2, 'type' => 2,
'activity_type' => 1, 'activity_type' => 1,
'activity_type_id' => $this->leads_id, 'activity_type_id' => $this->leads_id,
'content' => $param['name'], 'content' => $param['name']?:'',
'create_user_id' => $param['create_user_id'], 'create_user_id' => $param['create_user_id'],
'update_time' => time(), 'update_time' => time(),
'create_time' => time(), 'create_time' => time(),
@ -542,7 +587,7 @@ class Leads 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) public function getDataById($id = '', $userId = 0, $model='')
{ {
$map['leads_id'] = $id; $map['leads_id'] = $id;
$dataInfo = db('crm_leads')->where($map)->find(); $dataInfo = db('crm_leads')->where($map)->find();
@ -550,6 +595,35 @@ class Leads extends Common
$this->error = '暂无此数据'; $this->error = '暂无此数据';
return false; return false;
} }
if(empty($model) && $model!='update'){
$grantData = getFieldGrantData($userId);
foreach ($grantData['crm_leads'] as $key => $value) {
foreach ($value as $ke => $va) {
if($va['maskType']!=0){
$fieldGrant[$ke]['maskType'] = $va['maskType'];
$fieldGrant[$ke]['form_type'] = $va['form_type'];
$fieldGrant[$ke]['field'] = $va['field'];
}
}
}
foreach ($fieldGrant AS $key => $val){
//掩码相关类型字段
if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
$pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
$rs = preg_replace($pattern, "$1****$2", $dataInfo[$val['field']]);
$dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)$rs : null;
} elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
$email_array = explode("@", $dataInfo[$val['field']]);
$prevfix = (strlen($email_array[0]) < 4) ? "" : substr($dataInfo[$val['field']], 0, 2); //
$str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $dataInfo[$val['field']], -1, $count);
$rs = $prevfix . $str;
$dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ?$rs: null;
} 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;
}
}
}
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : []; $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
$dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : []; $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
@ -592,19 +666,28 @@ class Leads extends Common
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public public function getSystemInfo($id)
function getSystemInfo($id)
{ {
# 线索 # 线索
$leads = Db::name('crm_leads')->field(['create_user_id', 'create_time', 'update_time', 'last_time'])->where('leads_id', $id)->find(); $leads = Db::name('crm_leads')->field(['create_user_id','owner_user_id', 'create_time', 'update_time', 'last_time'])->where('leads_id', $id)->find();
# 创建人 # 创建人
$realname = Db::name('admin_user')->where('id', $leads['create_user_id'])->value('realname'); $realname = Db::name('admin_user')->where('id', $leads['create_user_id'])->value('realname');
# zjf 20210726
$userModel = new \app\admin\model\User();
$ownerUserInfo = $userModel->getUserById($leads['owner_user_id']);
# 负责人部门
$ownerStructureName = $ownerUserInfo['structure_name'];
# 负责人
$ownerUserName = $ownerUserInfo['realname'];
return [ return [
'create_user_id' => $realname, 'create_user_id' => $realname,
'owner_user_id' => $ownerUserName,
'create_time' => date('Y-m-d H:i:s', $leads['create_time']), 'create_time' => date('Y-m-d H:i:s', $leads['create_time']),
'update_time' => date('Y-m-d H:i:s', $leads['update_time']), 'update_time' => date('Y-m-d H:i:s', $leads['update_time']),
'last_time' => !empty($leads['last_time']) ? date('Y-m-d H:i:s', $leads['last_time']) : '' 'last_time' => !empty($leads['last_time']) ? date('Y-m-d H:i:s', $leads['last_time']) : '',
'owner_user_structure_name' => $ownerStructureName
]; ];
} }
} }

@ -107,6 +107,9 @@ class Product extends Common
$positionField = $fieldModel->getFieldByFormType('crm_product', 'position'); // 地址类型字段 $positionField = $fieldModel->getFieldByFormType('crm_product', 'position'); // 地址类型字段
$handwritingField = $fieldModel->getFieldByFormType('crm_product', 'handwriting_sign'); // 手写签名类型字段 $handwritingField = $fieldModel->getFieldByFormType('crm_product', 'handwriting_sign'); // 手写签名类型字段
$locationField = $fieldModel->getFieldByFormType('crm_product', 'location'); // 定位类型字段 $locationField = $fieldModel->getFieldByFormType('crm_product', 'location'); // 定位类型字段
$boxField = $fieldModel->getFieldByFormType('crm_product', 'checkbox'); // 多选类型字段
$floatField = $fieldModel->getFieldByFormType('crm_product', 'floatnumber'); // 货币类型字段
# 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段) # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
$temporaryField = str_replace('_name', '', $order_field); $temporaryField = str_replace('_name', '', $order_field);
if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) { if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
@ -142,6 +145,16 @@ class Product extends Common
foreach ($extraList AS $key => $value) { foreach ($extraList AS $key => $value) {
$extraData[$value['product_id']][$value['field']] = $value['content']; $extraData[$value['product_id']][$value['field']] = $value['content'];
} }
$grantData = getFieldGrantData($user_id);
foreach ($grantData['crm_product'] as $key => $value) {
foreach ($value as $ke => $va) {
if($va['maskType']!=0){
$fieldGrant[$ke]['maskType'] = $va['maskType'];
$fieldGrant[$ke]['form_type'] = $va['form_type'];
$fieldGrant[$ke]['field'] = $va['field'];
}
}
}
foreach ($list as $k => $v) { foreach ($list as $k => $v) {
$list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : []; $list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
$list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : []; $list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
@ -178,11 +191,39 @@ class Product extends Common
foreach ($locationField AS $key => $val) { foreach ($locationField AS $key => $val) {
$list[$k][$val] = !empty($extraData[$v['product_id']][$val]) ? json_decode($extraData[$v['product_id']][$val], true) : null; $list[$k][$val] = !empty($extraData[$v['product_id']][$val]) ? json_decode($extraData[$v['product_id']][$val], true) : null;
} }
// 多选框类型字段
foreach ($boxField AS $key => $val) {
$list[$k][$val] = !empty($v[$val]) ? trim($v[$val], ',') : null;
}
// 货币类型字段
foreach ($floatField AS $key => $val) {
$list[$k][$val] = $v[$val]!='0.00' ? (string)$v[$val] : null;
}
//掩码相关类型字段
foreach ($fieldGrant AS $key => $val){
//掩码相关类型字段
if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
$pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
$rs = preg_replace($pattern, "$1****$2", $v[$val['field']]);
$list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)$rs : null;
} elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
$email_array = explode("@", $v[$val['field']]);
$prevfix = (strlen($email_array[0]) < 4) ? "" : substr($v[$val['field']], 0, 2); //
$str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $v[$val['field']], -1, $count);
$rs = $prevfix . $str;
$list[$k][$val['field']] = !empty($v[$val['field']]) ?$rs: null;
} elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
$list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)substr_replace($v[$val['field']], '*****',0,strlen($v[$val['field']])) : null;
}
}
//产品类型 //产品类型
$list[$k]['category_id_info'] = $v['category_name']; $list[$k]['category_id_info'] = $v['category_name'];
# 处理日期格式 # 处理日期格式
$list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null; $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; $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 = [];
$data['list'] = $list; $data['list'] = $list;
@ -503,7 +544,7 @@ class Product 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) public function getDataById($id = '', $userId = 0,$model='')
{ {
$map['product_id'] = $id; $map['product_id'] = $id;
$map['delete_user_id'] = 0; $map['delete_user_id'] = 0;
@ -512,7 +553,35 @@ class Product extends Common
$this->error = '暂无此数据'; $this->error = '暂无此数据';
return false; return false;
} }
if(empty($model) && $model!='update'){
$grantData = getFieldGrantData($userId);
foreach ($grantData['crm_product'] as $key => $value) {
foreach ($value as $ke => $va) {
if($va['maskType']!=0){
$fieldGrant[$ke]['maskType'] = $va['maskType'];
$fieldGrant[$ke]['form_type'] = $va['form_type'];
$fieldGrant[$ke]['field'] = $va['field'];
}
}
}
foreach ($fieldGrant AS $key => $val){
//掩码相关类型字段
if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
$pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
$rs = preg_replace($pattern, "$1****$2", $dataInfo[$val['field']]);
$dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)$rs : null;
} elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
$email_array = explode("@", $dataInfo[$val['field']]);
$prevfix = (strlen($email_array[0]) < 4) ? "" : substr($dataInfo[$val['field']], 0, 2); //
$str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $dataInfo[$val['field']], -1, $count);
$rs = $prevfix . $str;
$dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ?$rs: null;
} 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['cover_images'] = $this->getProductImages($dataInfo['cover_images']); $dataInfo['cover_images'] = $this->getProductImages($dataInfo['cover_images']);
# 获取详情图片 # 获取详情图片
@ -947,14 +1016,25 @@ class Product extends Common
public function getSystemInfo($id) public function getSystemInfo($id)
{ {
# 产品 # 产品
$product = Db::name('crm_product')->field(['create_user_id', 'create_time', 'update_time'])->where('product_id', $id)->find(); $product = Db::name('crm_product')->field(['create_user_id','owner_user_id', 'create_time', 'update_time'])->where('product_id', $id)->find();
# 创建人 # 创建人
$realname = Db::name('admin_user')->where('id', $product['create_user_id'])->value('realname'); $realname = Db::name('admin_user')->where('id', $product['create_user_id'])->value('realname');
# zjf 20210726
$userModel = new \app\admin\model\User();
$ownerUserInfo = $userModel->getUserById($product['owner_user_id']);
# 负责人部门
$ownerStructureName = $ownerUserInfo['structure_name'];
# 负责人
$ownerUserName = $ownerUserInfo['realname'];
return [ return [
'create_user_id' => $realname, 'create_user_id' => $realname,
'owner_user_id' => $ownerUserName,
'create_time' => date('Y-m-d H:i:s', $product['create_time']), 'create_time' => date('Y-m-d H:i:s', $product['create_time']),
'update_time' => date('Y-m-d H:i:s', $product['update_time']) 'update_time' => date('Y-m-d H:i:s', $product['update_time']),
'owner_user_structure_name' => $ownerStructureName
]; ];
} }

@ -120,8 +120,9 @@ class ProductCategory extends Common
if (db('crm_product')->where(['category_id' => $param['id']])->find()) { if (db('crm_product')->where(['category_id' => $param['id']])->find()) {
$resDel = false; $resDel = false;
} }
if ($delSon && is_numeric($id)) {
$childIds = $this->getAllChild($id); if ($delSon && is_numeric($param['id'])) {
$childIds = $this->getAllChild($param['id']);
if($childIds){ if($childIds){
if (db('crm_product')->where(['category_id' => ['in',$childIds]])->find()) { if (db('crm_product')->where(['category_id' => ['in',$childIds]])->find()) {
$resDel = false; $resDel = false;
@ -132,6 +133,7 @@ class ProductCategory extends Common
$this->error = '请先移除该类型及子类下的相关产品'; $this->error = '请先移除该类型及子类下的相关产品';
return false; return false;
} }
$data=db('crm_product_category')->where('category_id' , $param['id'])->find(); $data=db('crm_product_category')->where('category_id' , $param['id'])->find();
//提交事务 //提交事务
$this->startTrans(); $this->startTrans();
@ -145,7 +147,7 @@ class ProductCategory extends Common
} }
} }
# 系统操作日志 # 系统操作日志
SystemActionLog($param['user_id'], 'crm_product','customer', $id, 'update',$data['name'] , '', '','删除了产品分类:'.$data['name']); SystemActionLog($param['user_id'], 'crm_product','customer', $param['id'], 'update',$data['name'] , '', '','删除了产品分类:'.$data['name']);
$this->commit(); $this->commit();
return true; return true;
} catch(\Exception $e) { } catch(\Exception $e) {

@ -16,7 +16,7 @@ use think\Request;
class Receivables extends Common class Receivables extends Common
{ {
use FieldVerificationTrait; use FieldVerificationTrait;
/** /**
* 为了数据库的整洁同时又不影响Model和Controller的名称 * 为了数据库的整洁同时又不影响Model和Controller的名称
* 我们约定每个模块的数据表都加上相同的前缀比如CRM模块用crm作为数据表前缀 * 我们约定每个模块的数据表都加上相同的前缀比如CRM模块用crm作为数据表前缀
@ -25,8 +25,8 @@ class Receivables extends Common
protected $createTime = 'create_time'; protected $createTime = 'create_time';
protected $updateTime = 'update_time'; protected $updateTime = 'update_time';
protected $autoWriteTimestamp = true; protected $autoWriteTimestamp = true;
private $statusArr = ['0' => '待审核', '1' => '审核中', '2' => '审核通过', '3' => '已拒绝', '4' => '已撤回']; private $statusArr = ['0' => '待审核', '1' => '审核中', '2' => '审核通过', '3' => '已拒绝', '4' => '已撤回', '7' => '正常'];
/** /**
* [getDataList 回款list] * [getDataList 回款list]
* *
@ -60,7 +60,7 @@ class Receivables extends Common
$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();
# getCount是代办事项传来的参数代办事项不需要使用场景 # getCount是代办事项传来的参数代办事项不需要使用场景
$sceneMap = []; $sceneMap = [];
@ -97,7 +97,7 @@ class Receivables extends Common
} }
//高级筛选 //高级筛选
$map = advancedQuery($map, 'crm', 'receivables', 'index'); $map = advancedQuery($map, 'crm', 'receivables', 'index');
//权限 //权限
$authMap = []; $authMap = [];
if (!$partMap) { if (!$partMap) {
@ -140,6 +140,9 @@ class Receivables extends Common
$positionField = $fieldModel->getFieldByFormType('crm_receivables', 'position'); // 地址类型字段 $positionField = $fieldModel->getFieldByFormType('crm_receivables', 'position'); // 地址类型字段
$handwritingField = $fieldModel->getFieldByFormType('crm_receivables', 'handwriting_sign'); // 手写签名类型字段 $handwritingField = $fieldModel->getFieldByFormType('crm_receivables', 'handwriting_sign'); // 手写签名类型字段
$locationField = $fieldModel->getFieldByFormType('crm_receivables', 'location'); // 定位类型字段 $locationField = $fieldModel->getFieldByFormType('crm_receivables', 'location'); // 定位类型字段
$boxField = $fieldModel->getFieldByFormType('crm_receivables', 'checkbox'); // 多选类型字段
$floatField = $fieldModel->getFieldByFormType('crm_receivables', 'floatnumber'); // 货币类型字段
// $fieldGrant = db('admin_field_mask')->where('types', 'receivables')->select();
# 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段) # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
$temporaryField = str_replace('_name', '', $order_field); $temporaryField = str_replace('_name', '', $order_field);
if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) { if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
@ -151,11 +154,11 @@ class Receivables extends Common
} else { } else {
$order = 'receivables.update_time desc'; $order = 'receivables.update_time desc';
} }
# 待办事项查询参数 # 待办事项查询参数
$dealtWhere = []; $dealtWhere = [];
if (!empty($receivablesIdArray)) $dealtWhere['receivables.receivables_id'] = ['in', $receivablesIdArray]; if (!empty($receivablesIdArray)) $dealtWhere['receivables.receivables_id'] = ['in', $receivablesIdArray];
$readAuthIds = $userModel->getUserByPer('crm', 'receivables', 'read'); $readAuthIds = $userModel->getUserByPer('crm', 'receivables', 'read');
$updateAuthIds = $userModel->getUserByPer('crm', 'receivables', 'update'); $updateAuthIds = $userModel->getUserByPer('crm', 'receivables', 'update');
$deleteAuthIds = $userModel->getUserByPer('crm', 'receivables', 'delete'); $deleteAuthIds = $userModel->getUserByPer('crm', 'receivables', 'delete');
@ -192,6 +195,16 @@ class Receivables extends Common
foreach ($extraList as $key => $value) { foreach ($extraList as $key => $value) {
$extraData[$value['receivables_id']][$value['field']] = $value['content']; $extraData[$value['receivables_id']][$value['field']] = $value['content'];
} }
$grantData = getFieldGrantData($user_id);
foreach ($grantData['crm_receivables'] as $key => $value) {
foreach ($value as $ke => $va) {
if($va['maskType']!=0){
$fieldGrant[$ke]['maskType'] = $va['maskType'];
$fieldGrant[$ke]['form_type'] = $va['form_type'];
$fieldGrant[$ke]['field'] = $va['field'];
}
}
}
foreach ($list as $k => $v) { foreach ($list as $k => $v) {
$list[$k]['create_user_id_info'] = $v['create_user_id'] ? $userModel->getUserById($v['create_user_id']) : []; $list[$k]['create_user_id_info'] = $v['create_user_id'] ? $userModel->getUserById($v['create_user_id']) : [];
$list[$k]['owner_user_id_info'] = $v['owner_user_id'] ? $userModel->getUserById($v['owner_user_id']) : []; $list[$k]['owner_user_id_info'] = $v['owner_user_id'] ? $userModel->getUserById($v['owner_user_id']) : [];
@ -234,6 +247,30 @@ class Receivables extends Common
foreach ($locationField AS $key => $val) { foreach ($locationField AS $key => $val) {
$list[$k][$val] = !empty($extraData[$v['receivables_id']][$val]) ? json_decode($extraData[$v['receivables_id']][$val], true) : null; $list[$k][$val] = !empty($extraData[$v['receivables_id']][$val]) ? json_decode($extraData[$v['receivables_id']][$val], true) : null;
} }
// 多选框类型字段
foreach ($boxField AS $key => $val) {
$list[$k][$val] = !empty($v[$val]) ? trim($v[$val],',') : null;
}
// 货币类型字段
foreach ($floatField AS $key => $val) {
$list[$k][$val] = $v[$val]!='0.00' ? (string)$v[$val] : null;
}
foreach ($fieldGrant AS $key => $val){
//掩码相关类型字段
if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
$pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
$rs = preg_replace($pattern, "$1****$2", $v[$val['field']]);
$list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)$rs : null;
} elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
$email_array = explode("@", $v[$val['field']]);
$prevfix = (strlen($email_array[0]) < 4) ? "" : substr($v[$val['field']], 0, 2); //
$str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $v[$val['field']], -1, $count);
$rs = $prevfix . $str;
$list[$k][$val['field']] = !empty($v[$val['field']]) ?$rs: null;
} elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
$list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)substr_replace($v[$val['field']], '*****',0,strlen($v[$val['field']])) : null;
}
}
$list[$k]['check_status_info'] = $this->statusArr[$v['check_status']]; $list[$k]['check_status_info'] = $this->statusArr[$v['check_status']];
//期数 //期数
$plan_num = db('crm_receivables_plan')->where(['plan_id' => $v['plan_id']])->value('num'); $plan_num = db('crm_receivables_plan')->where(['plan_id' => $v['plan_id']])->value('num');
@ -253,15 +290,19 @@ class Receivables extends Common
# 日期 # 日期
$list[$k]['create_time'] = !empty($v['create_time']) ? date('Y-m-d H:i:s', $v['create_time']) : null; $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; $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 = [];
$data['list'] = $list; $data['list'] = $list;
$data['dataCount'] = $dataCount ?: 0; $data['dataCount'] = $dataCount ?: 0;
$data['extraData']['money'] = ['receivablesMoney' => $this->getReceivablesMoney($map, $authMap)]; $data['extraData']['money'] = ['receivablesMoney' => $this->getReceivablesMoney($map, $authMap)];
return $data; return $data;
} }
/** /**
* 获取回款总金额 * 获取回款总金额
* *
@ -275,10 +316,10 @@ class Receivables extends Common
->join('__CRM_CUSTOMER__ customer', 'receivables.customer_id = customer.customer_id', 'LEFT') ->join('__CRM_CUSTOMER__ customer', 'receivables.customer_id = customer.customer_id', 'LEFT')
->join('__CRM_CONTRACT__ contract', 'receivables.contract_id = contract.contract_id', 'LEFT') ->join('__CRM_CONTRACT__ contract', 'receivables.contract_id = contract.contract_id', 'LEFT')
->where($map)->where($authMap)->where('receivables.check_status', 2)->sum('receivables.money'); ->where($map)->where($authMap)->where('receivables.check_status', 2)->sum('receivables.money');
return !empty($money) ? sprintf("%.2f", $money) : 0.00; return !empty($money) ? sprintf("%.2f", $money) : 0.00;
} }
/** /**
* 创建回款信息 * 创建回款信息
* @param * @param
@ -289,7 +330,7 @@ class Receivables extends Common
{ {
// 回款扩展表数据 // 回款扩展表数据
$receivablesData = []; $receivablesData = [];
if (!$param['customer_id']) { if (!$param['customer_id']) {
$this->error = '请先选择客户'; $this->error = '请先选择客户';
return false; return false;
@ -300,7 +341,7 @@ class Receivables extends Common
if ($check_status == 6) { if ($check_status == 6) {
$this->error = '合同已作废'; $this->error = '合同已作废';
return false; return false;
} elseif ($check_status != 2) { } elseif ($check_status != 2 && $check_status != 7) {
$this->error = '合同未审核通过'; $this->error = '合同未审核通过';
return false; return false;
} }
@ -308,22 +349,22 @@ class Receivables extends Common
$this->error = '请先选择合同'; $this->error = '请先选择合同';
return false; return false;
} }
$fieldModel = new \app\admin\model\Field(); $fieldModel = new \app\admin\model\Field();
// 数据验证 // 数据验证
$validateResult = $this->fieldDataValidate($param, $this->name, $param['create_user_id']); $validateResult = $this->fieldDataValidate($param, $this->name, $param['create_user_id']);
if (!empty($validateResult)) { if (!empty($validateResult)) {
$this->error = $validateResult; $this->error = $validateResult;
return false; return false;
} }
# 验证回款计划是否已经被关联 # 验证回款计划是否已经被关联
if (!empty($param['plan_id']) && db('crm_receivables_plan')->where('plan_id', $param['plan_id'])->value('receivables_id')) { if (!empty($param['plan_id']) && db('crm_receivables_plan')->where('plan_id', $param['plan_id'])->value('receivables_id')) {
$this->error = '回款已经已经关联了其他回款,不能重复关联!'; $this->error = '回款已经已经关联了其他回款,不能重复关联!';
return false; return false;
} }
// 处理部门、员工、附件、多选类型字段 // 处理部门、员工、附件、多选类型字段
$arrFieldAtt = $fieldModel->getArrayField('crm_receivables'); $arrFieldAtt = $fieldModel->getArrayField('crm_receivables');
foreach ($arrFieldAtt as $k => $v) { foreach ($arrFieldAtt as $k => $v) {
@ -405,7 +446,7 @@ class Receivables extends Common
} }
} }
} }
if ($this->data($param)->allowField(true)->save()) { if ($this->data($param)->allowField(true)->save()) {
//站内信 //站内信
$send_user_id = stringToArray($param['check_user_id']); $send_user_id = stringToArray($param['check_user_id']);
@ -421,11 +462,11 @@ class Receivables extends Common
} }
$data = []; $data = [];
$data['receivables_id'] = $this->receivables_id; $data['receivables_id'] = $this->receivables_id;
//修改记录 //修改记录
updateActionLog($param['create_user_id'], 'crm_receivables', $this->receivables_id, '', '', '创建了回款'); updateActionLog($param['create_user_id'], 'crm_receivables', $this->receivables_id, '', '', '创建了回款');
RecordActionLog($param['create_user_id'], 'crm_receivables', 'save', $param['number'], '', '', '新增了回款' . $param['number']); RecordActionLog($param['create_user_id'], 'crm_receivables', 'save', $param['number'], '', '', '新增了回款' . $param['number']);
# 添加活动记录 # 添加活动记录
Db::name('crm_activity')->insert([ Db::name('crm_activity')->insert([
'type' => 2, 'type' => 2,
@ -438,7 +479,7 @@ class Receivables extends Common
'customer_ids' => ',' . $param['customer_id'] . ',', 'customer_ids' => ',' . $param['customer_id'] . ',',
'contract_ids' => ',' . $param['contract_id'] . ',' 'contract_ids' => ',' . $param['contract_id'] . ','
]); ]);
# 创建待办事项的关联数据 # 创建待办事项的关联数据
$checkUserIds = db('crm_receivables')->where('receivables_id', $data['receivables_id'])->value('check_user_id'); $checkUserIds = db('crm_receivables')->where('receivables_id', $data['receivables_id'])->value('check_user_id');
$checkUserIdArray = stringToArray($checkUserIds); $checkUserIdArray = stringToArray($checkUserIds);
@ -451,20 +492,20 @@ class Receivables extends Common
]; ];
} }
if (!empty($dealtData)) db('crm_dealt_relation')->insertAll($dealtData); if (!empty($dealtData)) db('crm_dealt_relation')->insertAll($dealtData);
// 添加回款扩展数据 // 添加回款扩展数据
array_walk($receivablesData, function (&$val) use ($data) { array_walk($receivablesData, function (&$val) use ($data) {
$val['receivables_id'] = $data['receivables_id']; $val['receivables_id'] = $data['receivables_id'];
}); });
db('crm_receivables_data')->insertAll($receivablesData); db('crm_receivables_data')->insertAll($receivablesData);
return $data; return $data;
} else { } else {
$this->error = '添加失败'; $this->error = '添加失败';
return false; return false;
} }
} }
/** /**
* 根据对象ID 获取该年各个月回款情况 * 根据对象ID 获取该年各个月回款情况
* @param [year] [哪一年] * @param [year] [哪一年]
@ -490,7 +531,7 @@ class Receivables extends Common
$data = $this->where($map)->where(['return_time' => ['between', [$start, $stop]]])->sum('money'); $data = $this->where($map)->where(['return_time' => ['between', [$start, $stop]]])->sum('money');
return $data; return $data;
} }
/** /**
* 编辑回款主表信息 * 编辑回款主表信息
* @param * @param
@ -501,7 +542,7 @@ class Receivables extends Common
{ {
// 回款扩展表数据 // 回款扩展表数据
$receivablesData = []; $receivablesData = [];
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$dataInfo = db('crm_receivables')->where(['receivables_id' => $receivables_id])->find(); $dataInfo = db('crm_receivables')->where(['receivables_id' => $receivables_id])->find();
if (!$dataInfo) { if (!$dataInfo) {
@ -514,16 +555,16 @@ class Receivables extends Common
foreach ($unUpdateField as $v) { foreach ($unUpdateField as $v) {
unset($param[$v]); unset($param[$v]);
} }
$fieldModel = new \app\admin\model\Field(); $fieldModel = new \app\admin\model\Field();
// 数据验证 // 数据验证
$validateResult = $this->fieldDataValidate($param, $this->name, $param['user_id'], $param['receivables_id']); $validateResult = $this->fieldDataValidate($param, $this->name, $param['user_id'], $param['receivables_id']);
if (!empty($validateResult)) { if (!empty($validateResult)) {
$this->error = $validateResult; $this->error = $validateResult;
return false; return false;
} }
// 处理部门、员工、附件、多选类型字段 // 处理部门、员工、附件、多选类型字段
$arrFieldAtt = $fieldModel->getArrayField('crm_receivables'); $arrFieldAtt = $fieldModel->getArrayField('crm_receivables');
foreach ($arrFieldAtt as $k => $v) { foreach ($arrFieldAtt as $k => $v) {
@ -605,7 +646,7 @@ class Receivables extends Common
} }
} }
} }
if ($this->update($param, ['receivables_id' => $receivables_id], true)) { if ($this->update($param, ['receivables_id' => $receivables_id], true)) {
//修改记录 //修改记录
updateActionLog($param['user_id'], 'crm_receivables', $receivables_id, $dataInfo, $param); updateActionLog($param['user_id'], 'crm_receivables', $receivables_id, $dataInfo, $param);
@ -622,10 +663,10 @@ class Receivables extends Common
$send_user_id $send_user_id
); );
} }
$data = []; $data = [];
$data['receivables_id'] = $receivables_id; $data['receivables_id'] = $receivables_id;
# 删除待办事项的关联数据 # 删除待办事项的关联数据
db('crm_dealt_relation')->where(['types' => ['eq', 'crm_receivables'], 'types_id' => ['eq', $data['receivables_id']]])->delete(); db('crm_dealt_relation')->where(['types' => ['eq', 'crm_receivables'], 'types_id' => ['eq', $data['receivables_id']]])->delete();
# 创建待办事项的关联数据 # 创建待办事项的关联数据
@ -640,21 +681,21 @@ class Receivables extends Common
]; ];
} }
if (!empty($dealtData)) db('crm_dealt_relation')->insertAll($dealtData); if (!empty($dealtData)) db('crm_dealt_relation')->insertAll($dealtData);
// 添加回款扩展数据 // 添加回款扩展数据
db('crm_receivables_data')->where('receivables_id', $receivables_id)->delete(); db('crm_receivables_data')->where('receivables_id', $receivables_id)->delete();
array_walk($receivablesData, function (&$val) use ($receivables_id) { array_walk($receivablesData, function (&$val) use ($receivables_id) {
$val['receivables_id'] = $receivables_id; $val['receivables_id'] = $receivables_id;
}); });
db('crm_receivables_data')->insertAll($receivablesData); db('crm_receivables_data')->insertAll($receivablesData);
return $data; return $data;
} else { } else {
$this->error = '编辑失败'; $this->error = '编辑失败';
return false; return false;
} }
} }
/** /**
* 回款数据 * 回款数据
* *
@ -664,7 +705,7 @@ class Receivables 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) public function getDataById($id = '', $userId = 0,$model='')
{ {
$map['receivables_id'] = $id; $map['receivables_id'] = $id;
$dataInfo = db('crm_receivables')->where($map)->find(); $dataInfo = db('crm_receivables')->where($map)->find();
@ -672,6 +713,35 @@ class Receivables extends Common
$this->error = '暂无此数据'; $this->error = '暂无此数据';
return false; return false;
} }
if(empty($model) && $model!='update'){
$grantData = getFieldGrantData($userId);
foreach ($grantData['crm_receivables'] as $key => $value) {
foreach ($value as $ke => $va) {
if($va['maskType']!=0){
$fieldGrant[$ke]['maskType'] = $va['maskType'];
$fieldGrant[$ke]['form_type'] = $va['form_type'];
$fieldGrant[$ke]['field'] = $va['field'];
}
}
}
foreach ($fieldGrant AS $key => $val){
//掩码相关类型字段
if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
$pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
$rs = preg_replace($pattern, "$1****$2", $dataInfo[$val['field']]);
$dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)$rs : null;
} elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
$email_array = explode("@", $dataInfo[$val['field']]);
$prevfix = (strlen($email_array[0]) < 4) ? "" : substr($dataInfo[$val['field']], 0, 2); //
$str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $dataInfo[$val['field']], -1, $count);
$rs = $prevfix . $str;
$dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ?$rs: null;
} 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;
}
}
}
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : []; $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
$dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : []; $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
@ -695,7 +765,7 @@ class Receivables extends Common
foreach ($dataInfo as $key => $value) { foreach ($dataInfo as $key => $value) {
if (!$userLevel && !empty($grantData['crm_receivables'])) { if (!$userLevel && !empty($grantData['crm_receivables'])) {
$status = getFieldGrantStatus($key, $grantData['crm_receivables']); $status = getFieldGrantStatus($key, $grantData['crm_receivables']);
# 查看权限 # 查看权限
if ($status['read'] == 0) unset($dataInfo[$key]); if ($status['read'] == 0) unset($dataInfo[$key]);
} }
@ -717,7 +787,7 @@ class Receivables extends Common
} }
return $dataInfo; return $dataInfo;
} }
/** /**
* 回款&&合同统计(列表) * 回款&&合同统计(列表)
* @param * @param
@ -733,7 +803,7 @@ class Receivables extends Common
$perUserIds = $userModel->getUserByPer('bi', 'receivables', 'read'); //权限范围内userIds $perUserIds = $userModel->getUserByPer('bi', 'receivables', 'read'); //权限范围内userIds
$whereData = $adminModel->getWhere($request, '', $perUserIds); //统计条件 $whereData = $adminModel->getWhere($request, '', $perUserIds); //统计条件
$userIds = $whereData['userIds']; $userIds = $whereData['userIds'];
if (!$request['year']) { if (!$request['year']) {
$request['year'] = date('Y'); $request['year'] = date('Y');
} }
@ -751,7 +821,7 @@ class Receivables extends Common
$start = strtotime($request['year'] . '-01-01'); $start = strtotime($request['year'] . '-01-01');
$end = strtotime($next_year . '-01-01'); $end = strtotime($next_year . '-01-01');
} }
$map['owner_user_id'] = ['in', $userIds]; $map['owner_user_id'] = ['in', $userIds];
//$map['rec.check_status'] = 3; //$map['rec.check_status'] = 3;
$map['create_time'] = array('between', array($start, $end)); $map['create_time'] = array('between', array($start, $end));
@ -760,10 +830,10 @@ class Receivables extends Common
if ($request['type'] == '1') { if ($request['type'] == '1') {
$map_type['contract.owner_user_id'] = ['in', $userIds]; $map_type['contract.owner_user_id'] = ['in', $userIds];
$map_type['contract.create_time'] = array('between', array($start, $end)); $map_type['contract.create_time'] = array('between', array($start, $end));
$userField = $fieldModel->getFieldByFormType('crm_contract', 'user'); $userField = $fieldModel->getFieldByFormType('crm_contract', 'user');
$structureField = $fieldModel->getFieldByFormType('crm_contract', 'structure'); //部门类型 $structureField = $fieldModel->getFieldByFormType('crm_contract', 'structure'); //部门类型
$list = Db::name('CrmContract')->alias('contract') $list = Db::name('CrmContract')->alias('contract')
->join('__CRM_CUSTOMER__ customer', 'contract.customer_id = customer.customer_id', 'LEFT') ->join('__CRM_CUSTOMER__ customer', 'contract.customer_id = customer.customer_id', 'LEFT')
->join('__CRM_BUSINESS__ business', 'contract.contract_id = business.business_id', 'LEFT') ->join('__CRM_BUSINESS__ business', 'contract.contract_id = business.business_id', 'LEFT')
@ -797,10 +867,10 @@ class Receivables extends Common
//$map['rec.check_status'] = 3; //$map['rec.check_status'] = 3;
$map_rec['receivables.create_time'] = array('between', array($start, $end)); $map_rec['receivables.create_time'] = array('between', array($start, $end));
$map_rec['receivables.check_status'] = 2; $map_rec['receivables.check_status'] = 2;
$userField = $fieldModel->getFieldByFormType('crm_receivables', 'user'); $userField = $fieldModel->getFieldByFormType('crm_receivables', 'user');
$structureField = $fieldModel->getFieldByFormType('crm_receivables', 'structure'); //部门类型 $structureField = $fieldModel->getFieldByFormType('crm_receivables', 'structure'); //部门类型
$list = db('crm_receivables') $list = db('crm_receivables')
->alias('receivables') ->alias('receivables')
->join('__CRM_CUSTOMER__ customer', 'receivables.customer_id = customer.customer_id', 'LEFT') ->join('__CRM_CUSTOMER__ customer', 'receivables.customer_id = customer.customer_id', 'LEFT')
@ -828,7 +898,7 @@ class Receivables extends Common
return $list; return $list;
} }
} }
/** /**
* [回款统计] 柱状图 * [回款统计] 柱状图
* @param request [查询条件] * @param request [查询条件]
@ -868,7 +938,7 @@ class Receivables extends Common
$where_receivables['check_status'] = $where_contract['check_status'] = 2; //审核通过 $where_receivables['check_status'] = $where_contract['check_status'] = 2; //审核通过
$contractMoney = db('crm_contract')->where($where_contract)->sum('money'); $contractMoney = db('crm_contract')->where($where_contract)->sum('money');
$receivablesMoney = db('crm_receivables')->where($where_receivables)->sum('money'); $receivablesMoney = db('crm_receivables')->where($where_receivables)->sum('money');
$conQuarterMoney += $charMonthArr[$i]['contractMoney'] = $contractMoney; $conQuarterMoney += $charMonthArr[$i]['contractMoney'] = $contractMoney;
$reQuarterMoney += $charMonthArr[$i]['receivablesMoney'] = $receivablesMoney; $reQuarterMoney += $charMonthArr[$i]['receivablesMoney'] = $receivablesMoney;
if (in_array($i, array('3', '4', '6', '9', '12'))) { if (in_array($i, array('3', '4', '6', '9', '12'))) {
@ -888,7 +958,7 @@ class Receivables extends Common
$data['receivablesMoneyTotal'] = $receivablesMoneyTotal ?: 0.00; $data['receivablesMoneyTotal'] = $receivablesMoneyTotal ?: 0.00;
return $data; return $data;
} }
/** /**
* [合同回款金额] * [合同回款金额]
* @param contract_id 合同ID * @param contract_id 合同ID
@ -906,7 +976,7 @@ class Receivables extends Common
$data['contractMoney'] = $contractMoney ?: '0.00'; $data['contractMoney'] = $contractMoney ?: '0.00';
return $data; return $data;
} }
/** /**
* 获取系统信息 * 获取系统信息
* *
@ -919,14 +989,23 @@ class Receivables extends Common
public function getSystemInfo($id) public function getSystemInfo($id)
{ {
# 回款 # 回款
$receivables = Db::name('crm_receivables')->field(['create_user_id', 'create_time', 'update_time'])->where('receivables_id', $id)->find(); $receivables = Db::name('crm_receivables')->field(['create_user_id' ,'owner_user_id', 'create_time', 'update_time'])->where('receivables_id', $id)->find();
# 创建人 # 创建人
$realname = Db::name('admin_user')->where('id', $receivables['create_user_id'])->value('realname'); $realname = Db::name('admin_user')->where('id', $receivables['create_user_id'])->value('realname');
# zjf 20210726
$userModel = new \app\admin\model\User();
$ownerUserInfo = $userModel->getUserById($receivables['owner_user_id']);
# 负责人部门
$ownerStructureName = $ownerUserInfo['structure_name'];
# 负责人
$ownerUserName = $ownerUserInfo['realname'];
return [ return [
'create_user_id' => $realname, 'create_user_id' => $realname,
'owner_user_id' => $ownerUserName,
'create_time' => date('Y-m-d H:i:s', $receivables['create_time']), 'create_time' => date('Y-m-d H:i:s', $receivables['create_time']),
'update_time' => date('Y-m-d H:i:s', $receivables['update_time']) 'update_time' => date('Y-m-d H:i:s', $receivables['update_time']),
'owner_user_structure_name' => $ownerStructureName
]; ];
} }
} }

@ -7,6 +7,7 @@
namespace app\crm\model; namespace app\crm\model;
use app\admin\traits\FieldVerificationTrait; use app\admin\traits\FieldVerificationTrait;
use think\composer\LibraryInstaller;
use think\Db; use think\Db;
use app\admin\model\Common; use app\admin\model\Common;
use app\crm\model\Contract as ContractModel; use app\crm\model\Contract as ContractModel;
@ -15,78 +16,96 @@ use think\Validate;
class ReceivablesPlan extends Common class ReceivablesPlan extends Common
{ {
use FieldVerificationTrait;
/** /**
* 为了数据库的整洁同时又不影响Model和Controller的名称 * 为了数据库的整洁同时又不影响Model和Controller的名称
* 我们约定每个模块的数据表都加上相同的前缀比如CRM模块用crm作为数据表前缀 * 我们约定每个模块的数据表都加上相同的前缀比如CRM模块用crm作为数据表前缀
*/ */
protected $name = 'crm_receivables_plan'; protected $name = 'crm_receivables_plan';
protected $createTime = 'create_time'; protected $createTime = 'create_time';
protected $updateTime = 'update_time'; protected $updateTime = 'update_time';
protected $autoWriteTimestamp = true; protected $autoWriteTimestamp = true;
protected $statusArr = [0 =>'待回款', 1=>'完成', 2=>'部分回款', 3=>'已作废', 4=>'已逾期', 5=>'待生效'];
/**
/**
* [getDataList 回款计划list] * [getDataList 回款计划list]
* @author Michael_xu
* @param [string] $map [查询条件] * @param [string] $map [查询条件]
* @param [number] $page [当前页数] * @param [number] $page [当前页数]
* @param [number] $limit [每页数量] * @param [number] $limit [每页数量]
* @param [string] $types 1 未使用的回款计划 * @param [string] $types 1 未使用的回款计划
* @return [array] [description] * @return [array] [description]
*/ * @author Michael_xu
public function getDataList($request) */
public function getDataList($request)
{ {
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$search = $request['search']; $fieldModel = new \app\admin\model\Field();
$user_id = $request['user_id']; $search = $request['search'];
$scene_id = (int)$request['scene_id']; $user_id = $request['user_id'];
$check_status = $request['check_status']; $scene_id = (int)$request['scene_id'];
$types = $request['types']; $check_status = $request['check_status'];
$types = $request['types'];
$getCount = $request['getCount']; $getCount = $request['getCount'];
$status = isset($request['status']) ? $request['status'] : 1; $status = isset($request['status']) ? $request['status'] : 1;
$dealt = $request['dealt']; # 待办事项 $dealt = $request['dealt']; # 待办事项
unset($request['scene_id']); $order_field = $request['order_field'];
unset($request['search']); $order_type = $request['order_type'];
unset($request['user_id']); $is_excel = $request['is_excel'];
unset($request['check_status']); unset($request['scene_id']);
unset($request['types']); unset($request['search']);
unset($request['user_id']);
unset($request['check_status']);
unset($request['types']);
unset($request['getCount']); unset($request['getCount']);
unset($request['status']); unset($request['status']);
unset($request['dealt']); unset($request['dealt']);
unset($request['order_field']);
$request = $this->fmtRequest( $request ); unset($request['order_type']);
$map = $request['map'] ? : []; unset($request['is_excel']);
$request = $this->fmtRequest($request);
$map = $request['map'] ?: [];
$sceneModel = new \app\admin\model\Scene();
$sceneMap = [];
if (empty($getCount)) {
if ($scene_id) {
//自定义场景
$sceneMap = $sceneModel->getDataById($scene_id, $user_id, 'receivables_plan') ?: [];
} else {
//默认场景
$sceneMap = $sceneModel->getDefaultData('crm_receivables_plan', $user_id) ?: [];
}
}
if (isset($map['search'])) { if (isset($map['search'])) {
//普通筛选
$map['name'] = ['like', '%'.$map['search'].'%']; //普通筛选
unset($map['search']); $map['name'] = ['like', '%' . $map['search'] . '%'];
} else { unset($map['search']);
} else {
// 高级筛选 // 高级筛选
$map = advancedQuery($map, 'crm', 'receivables_plan', 'index'); $map = advancedQuery($map, 'crm', 'receivables_plan', 'index');
} }
if ($map['receivables_plan.owner_user_id']) { if ($map['receivables_plan.owner_user_id']) {
$map['contract.owner_user_id'] = $map['receivables_plan.owner_user_id']; $map['contract.owner_user_id'] = $map['receivables_plan.owner_user_id'];
unset($map['receivables_plan.owner_user_id']); unset($map['receivables_plan.owner_user_id']);
} }
$whereData = []; $whereData = [];
if ($check_status) { if ($check_status) {
unset($map['receivables_plan.check_status']); unset($map['receivables_plan.check_status']);
if ($check_status == 2) { if ($check_status == 2) {
$map['receivables.check_status'] = $check_status; $map['receivables.check_status'] = $check_status;
} else { } else {
unset($map['receivables_plan.receivables_id']); unset($map['receivables_plan.receivables_id']);
$data = []; $data = [];
$data['check_status'] = $check_status; $data['check_status'] = $check_status;
$whereData = function($query) use ($data){ $whereData = function ($query) use ($data) {
$query->where(['receivables_plan.receivables_id'=> ['eq',0]]) $query->where(['receivables_plan.receivables_id' => ['eq', 0]])
->whereOr(['receivables.check_status' => $data['check_status']]); ->whereOr(['receivables.check_status' => $data['check_status']]);
}; };
} }
} }
// @ymob 2019-12-11 17:51:54 // @ymob 2019-12-11 17:51:54
// 修改回款时,回款计划选项列表应该包含该回款对应的回款计划 不能过滤 // 修改回款时,回款计划选项列表应该包含该回款对应的回款计划 不能过滤
// 将types改为statusstatus可用的回款计划 fanqi // 将types改为statusstatus可用的回款计划 fanqi
if (empty($dealt)) { # 不是待办事项 if (empty($dealt)) { # 不是待办事项
if ($request['map']['receivables_id']) { if ($request['map']['receivables_id']) {
if (!empty($request['map']['contract_id'])) { if (!empty($request['map']['contract_id'])) {
@ -102,48 +121,178 @@ class ReceivablesPlan extends Common
$map['receivables_plan.receivables_id'] = 0; $map['receivables_plan.receivables_id'] = 0;
} }
} }
$dataCount = db('crm_receivables_plan') $dataCount = db('crm_receivables_plan')
->alias('receivables_plan') ->alias('receivables_plan')
->join('__CRM_CONTRACT__ contract','receivables_plan.contract_id = contract.contract_id','LEFT') ->join('__CRM_CONTRACT__ contract', 'receivables_plan.contract_id = contract.contract_id', 'LEFT')
->join('__CRM_CUSTOMER__ customer','receivables_plan.customer_id = customer.customer_id','LEFT') ->join('__CRM_CUSTOMER__ customer', 'receivables_plan.customer_id = customer.customer_id', 'LEFT')
->join('__CRM_RECEIVABLES__ receivables','receivables_plan.plan_id = receivables.plan_id','LEFT') ->join('__CRM_RECEIVABLES__ receivables', 'receivables_plan.plan_id = receivables.plan_id', 'LEFT')
->where($map) ->where($map)
->where($sceneMap)
->where($whereData) ->where($whereData)
->count('receivables_plan.plan_id'); ->count('receivables_plan.plan_id');
$indexField = $fieldModel->getIndexField('crm_receivables_plan', $user_id, 1) ?: array('name'); // 列表展示字段
$userField = $fieldModel->getFieldByFormType('crm_receivables_plan', 'user'); // 人员类型
$structureField = $fieldModel->getFieldByFormType('crm_receivables_plan', 'structure'); // 部门类型
$datetimeField = $fieldModel->getFieldByFormType('crm_receivables_plan', 'datetime'); // 日期时间类型
$booleanField = $fieldModel->getFieldByFormType('crm_receivables_plan', 'boolean_value'); // 布尔值类型字段
$dateIntervalField = $fieldModel->getFieldByFormType('crm_receivables_plan', 'date_interval'); // 日期区间类型字段
$positionField = $fieldModel->getFieldByFormType('crm_receivables_plan', 'position'); // 地址类型字段
$handwritingField = $fieldModel->getFieldByFormType('crm_receivables_plan', 'handwriting_sign'); // 手写签名类型字段
if (!empty($getCount) && $getCount == 1) { if (!empty($getCount) && $getCount == 1) {
$data['dataCount'] = !empty($dataCount) ? $dataCount : 0; $data['dataCount'] = !empty($dataCount) ? $dataCount : 0;
return $data; return $data;
} }
$list = db('crm_receivables_plan') # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段)
->alias('receivables_plan') $temporaryField = str_replace('_name', '', $order_field);
->join('__CRM_CONTRACT__ contract','receivables_plan.contract_id = contract.contract_id','LEFT') if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) {
->join('__CRM_CUSTOMER__ customer','receivables_plan.customer_id = customer.customer_id','LEFT') $order_field = $temporaryField;
->join('__CRM_RECEIVABLES__ receivables','receivables_plan.plan_id = receivables.plan_id','LEFT') }
->limit($request['offset'], $request['length']) # 排序
->field('receivables_plan.*,customer.name as customer_name,contract.num as contract_name,receivables.receivables_id,receivables.check_status') if ($order_type && $order_field) {
->where($map) $order = $fieldModel->getOrderByFormtype('crm_receivables_plan', 'receivables_plan', $order_field, $order_type);
->where($whereData) } else {
->select(); $order = 'receivables_plan.num asc';
foreach ($list as $k=>$v) { }
$list[$k]['create_user_id_info'] = $userModel->getUserById($v['create_user_id']); $list = db('crm_receivables_plan')
$list[$k]['contract_id_info']['name'] = $v['contract_name'] ? : ''; ->alias('receivables_plan')
$list[$k]['contract_id_info']['contract_id'] = $v['contract_id'] ? : ''; ->join('__CRM_CONTRACT__ contract', 'receivables_plan.contract_id = contract.contract_id', 'LEFT')
$list[$k]['customer_id_info']['name'] = $v['customer_name'] ? : ''; ->join('__CRM_CUSTOMER__ customer', 'receivables_plan.customer_id = customer.customer_id', 'LEFT')
$list[$k]['customer_id_info']['customer_id'] = $v['customer_id'] ? : ''; ->join('__CRM_RECEIVABLES__ receivables', 'receivables_plan.plan_id = receivables.plan_id', 'LEFT')
->limit($request['offset'], $request['length'])
->field(array_merge($indexField, [
'customer.name' => 'customer_name',
'receivables.receivables_id' => 'receivables_id',
'receivables.check_status' => 'check_status',
'contract.num ' => 'contract_name',
'ifnull(SUM(receivables_plan.money), 0)' => 'done_money',//计划回款总金额
'(ifnull(SUM(receivables.money), 0)-SUM( real_money))' => 'un_money',//未回款总金额
'SUM(real_money) AS real_money'//实际回款总金额
]))
->where($map)
->where($sceneMap)
->where($whereData)
->group('receivables_plan.contract_id')
->orderRaw($order)
->select();
$grantData = getFieldGrantData($user_id);
foreach ($grantData['crm_visit_'] as $key => $value) {
foreach ($value as $ke => $va) {
if($va['maskType']!=0){
$fieldGrant[$ke]['maskType'] = $va['maskType'];
$fieldGrant[$ke]['form_type'] = $va['form_type'];
$fieldGrant[$ke]['field'] = $va['field'];
}
}
}
$readAuthIds = $userModel->getUserByPer('crm', 'receivables_plan', 'read');
$updateAuthIds = $userModel->getUserByPer('crm', 'receivables_plan', 'update');
$deleteAuthIds = $userModel->getUserByPer('crm', 'receivables_plan', 'delete');
$real_money=0.00;
$receivedMoney=0.00;
$unReceivedMoney=0.00;
foreach ($list as $k => $v) {
$list[$k]['create_user_id_info'] = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
$list[$k]['owner_user_id_info'] = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
$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'] : '';
foreach ($userField as $key => $val) {
if (in_array($val, $indexField)) {
$usernameField = !empty($v[$val]) ? db('admin_user')->whereIn('id', stringToArray($v[$val]))->column('realname') : [];
$list[$k][$val] = implode($usernameField, ',');
}
}
# 部门类型字段
foreach ($structureField as $key => $val) {
if (in_array($val, $indexField)) {
$structureNameField = !empty($v[$val]) ? db('admin_structure')->whereIn('id', stringToArray($v[$val]))->column('name') : [];
$list[$k][$val] = implode($structureNameField, ',');
}
}
# 日期时间类型字段
foreach ($datetimeField as $key => $val) {
$list[$k][$val] = !empty($v[$val]) ? date('Y-m-d H:i:s', $v[$val]) : null;
}
// 布尔值类型字段
foreach ($booleanField as $key => $val) {
$list[$k][$val] = !empty($v[$val]) ? (string)$v[$val] : '0';
}
// 处理日期区间类型字段的格式
foreach ($dateIntervalField as $key => $val) {
$list[$k][$val] = !empty($extraData[$v['customer_id']][$val]) ? json_decode($extraData[$v['customer_id']][$val], true) : null;
}
// 处理地址类型字段的格式
foreach ($positionField as $key => $val) {
$list[$k][$val] = !empty($extraData[$v['customer_id']][$val]) ? json_decode($extraData[$v['customer_id']][$val], true) : null;
}
// 手写签名类型字段
foreach ($handwritingField as $key => $val) {
$handwritingData = !empty($v[$val]) ? db('admin_file')->where('file_id', $v[$val])->value('file_path') : null;
$list[$k][$val] = ['url' => !empty($handwritingData) ? getFullPath($handwritingData) : null
];
}
foreach ($fieldGrant AS $key => $val){
//掩码相关类型字段
if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
$pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
$rs = preg_replace($pattern, "$1****$2", $v[$val['field']]);
$list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)$rs : null;
} elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
$email_array = explode("@", $v[$val['field']]);
$prevfix = (strlen($email_array[0]) < 4) ? "" : substr($v[$val['field']], 0, 2); //
$str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $v[$val['field']], -1, $count);
$rs = $prevfix . $str;
$list[$k][$val['field']] = !empty($v[$val['field']]) ?$rs: null;
} elseif ($val['maskType']!=0 && in_array($val['form_type'],['position','floatnumber'])) {
$list[$k][$val['field']] = !empty($v[$val['field']]) ? (string)substr_replace($v[$val['field']], '*****',0,strlen($v[$val['field']])) : null;
}
}
// 状态
if(strtotime($v['return_date'])>strtotime(date("Y-m-d",strtotime("+1 day")))){
$list[$k]['status']=4;
}
# 时间格式
$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;
# 权限
$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;
$real_money += $v['real_money']; //实际回款总金额
$receivedMoney += $v['done_money'];// 回款总金额
$unReceivedMoney += $v['un_money']; // 未回款
} }
$data = []; $data = [];
$data['list'] = $list; $data['list'] = $list;
$data['dataCount'] = $dataCount ? : 0; $data['dataCount'] = $dataCount ?: 0;
return $data ? : []; $data['extraData']['money'] = [
'real_money' => $real_money, # 实际回款总金额
'receivedMoney' => $receivedMoney, # 回款总金额
'unReceivedMoney' => $unReceivedMoney # 未回款
];
return $data ?: [];
} }
/** /**
* 创建回款计划信息 * 创建回款计划信息
* @author Michael_xu * @author Michael_xu
* @param * @param
* @return * @return
*/ */
public function createData($param) public function createData($param)
{ {
$userId = $param['user_id']; $userId = $param['user_id'];
@ -266,7 +415,20 @@ class ReceivablesPlan extends Common
} }
} }
} }
switch ($res){
case 1:
$param['status']=5;
break;
case 2:
$param['status']=0;
break;
case 3:
$param['status']=3;
break;
case 6:
$param['status']=0;
break;
}
if ($this->data($param)->allowField(true)->save()) { if ($this->data($param)->allowField(true)->save()) {
$data = []; $data = [];
$data['plan_id'] = $this->plan_id; $data['plan_id'] = $this->plan_id;
@ -422,75 +584,91 @@ class ReceivablesPlan extends Common
/** /**
* 回款计划数据 * 回款计划数据
* @param $id 回款计划ID * @param $id 回款计划ID
* @return * @return
*/ */
public function getDataById($id = '') public function getDataById($id = '', $userId = 0, $model='')
{ {
$map['plan_id'] = $id; $map['plan_id'] = $id;
$dataInfo = $this->where($map)->find(); $dataInfo = $this->where($map)->find();
if (!$dataInfo) { if (!$dataInfo) {
$this->error = '暂无此数据'; $this->error = '暂无此数据';
return false; return false;
} }
$userModel = new \app\admin\model\User(); if(empty($model) && $model!='update'){
$dataInfo['create_user_info'] = $userModel->getUserById($dataInfo['create_user_id']); $grantData = getFieldGrantData($userId);
$dataInfo['plan_id'] = $id; foreach ($grantData['crm_receivables_plan'] as $key => $value) {
return $dataInfo; foreach ($value as $ke => $va) {
} if($va['maskType']!=0){
$fieldGrant[$ke]['maskType'] = $va['maskType'];
$fieldGrant[$ke]['form_type'] = $va['form_type'];
$fieldGrant[$ke]['field'] = $va['field'];
}
}
}
foreach ($fieldGrant AS $key => $val){
//掩码相关类型字段
if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
$pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
$rs = preg_replace($pattern, "$1****$2", $dataInfo[$val['field']]);
$dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)$rs : null;
} elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
$email_array = explode("@", $dataInfo[$val['field']]);
$prevfix = (strlen($email_array[0]) < 4) ? "" : substr($dataInfo[$val['field']], 0, 2); //
$str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $dataInfo[$val['field']], -1, $count);
$rs = $prevfix . $str;
$dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ?$rs: null;
} 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;
}
}
}
// $userModel = new \app\admin\model\User();
// $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
// $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
// $dataInfo['create_user_name'] = !empty($dataInfo['create_user_id_info']['realname']) ? $dataInfo['create_user_id_info']['realname'] : '';
// $dataInfo['owner_user_name'] = !empty($dataInfo['owner_user_id_info']['realname']) ? $dataInfo['owner_user_id_info']['realname'] : '';
// $dataInfo['customer_id_info'] = $dataInfo['customer_id'] ? db('crm_customer')->where(['customer_id' => $dataInfo['customer_id']])->field('customer_id,name')->find() : [];
// $dataInfo['contract_id_info'] = $dataInfo['contract_id'] ? db('crm_contract')->where(['contract_id' => $dataInfo['contract_id']])->field('contract_id,name,money')->find() : [];
// $dataInfo['receivables_id'] = $id;
// $userModel = new \app\admin\model\User();
// $dataInfo['create_user_info'] = $userModel->getUserById($dataInfo['create_user_id']);
// $dataInfo['plan_id'] = $id;
// # 处理时间格式
// $fieldModel = new \app\admin\model\Field();
// $datetimeField = $fieldModel->getFieldByFormType('crm_receivables', 'datetime'); //日期时间类型
// foreach ($datetimeField as $key => $val) {
// $dataInfo[$val] = !empty($dataInfo[$val]) ? date('Y-m-d H:i:s', $dataInfo[$val]) : null;
// }
// $dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null;
// $dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
// // 字段授权
// if (!empty($userId)) {
// $grantData = getFieldGrantData($userId);
// $userLevel = isSuperAdministrators($userId);
// foreach ($dataInfo as $key => $value) {
// if (!$userLevel && !empty($grantData['crm_receivables'])) {
// $status = getFieldGrantStatus($key, $grantData['crm_receivables']);
//
// # 查看权限
// if ($status['read'] == 0) unset($dataInfo[$key]);
// }
// }
// if (!$userLevel && !empty($grantData['crm_receivables'])) {
// # 客户名称
// $customerStatus = getFieldGrantStatus('customer_id', $grantData['crm_receivables']);
// if ($customerStatus['read'] == 0) {
// $dataInfo['customer_name'] = '';
// $dataInfo['customer_id_info'] = [];
// }
// # 合同金额
// $contractMoneyStatus = getFieldGrantStatus('contract_money', $grantData['crm_receivables']);
// if ($contractMoneyStatus['read'] == 0) $dataInfo['contract_id_info']['money'] = '';
// # 合同名称
// $contractMoneyStatus = getFieldGrantStatus('contract_money', $grantData['crm_receivables']);
// if ($contractMoneyStatus['read'] == 0) $dataInfo['contract_id_info']['money'] = '';
// }
// }
return $dataInfo;
}
//模拟自定义字段返回
public function getField()
{
$field_arr = [
'0' => [
'field' => 'customer_id',
'name' => '客户名称',
'form_type' => 'customer',
'setting' => []
],
'1' => [
'field' => 'contract_id',
'name' => '合同名称',
'form_type' => 'contract',
'setting' => []
],
'2' => [
'field' => 'money',
'name' => '计划回款金额',
'form_type' => 'floatnumber',
'setting' => []
],
'3' => [
'field' => 'return_date',
'name' => '计划回款日期',
'form_type' => 'date',
'setting' => []
],
'4' => [
'field' => 'return_type',
'name' => '计划回款方式',
'form_type' => 'select',
'setting' => '支付宝\n微信\n转账'
],
'5' => [
'field' => 'remind',
'name' => '提前几日提醒',
'form_type' => 'number',
'setting' => []
],
'6' => [
'field' => 'remark',
'name' => '备注',
'form_type' => 'textarea',
'setting' => []
],
'7' => [
'field' => 'file',
'name' => '附件',
'form_type' => 'file',
'setting' => []
]
];
return $field_arr;
}
} }

@ -13,4 +13,94 @@ class Visit extends Common
protected $createTime = 'create_time'; protected $createTime = 'create_time';
protected $updateTime = 'update_time'; protected $updateTime = 'update_time';
protected $autoWriteTimestamp = true; protected $autoWriteTimestamp = true;
/**
* 回访计划数据
* @param $id 回款计划ID
* @return
*/
public function getDataById($id = '', $userId = 0, $model='')
{
$map['visit_id'] = $id;
$dataInfo = $this->where($map)->find();
if (!$dataInfo) {
$this->error = '暂无此数据';
return false;
}
if(empty($model) && $model!='update'){
$grantData = getFieldGrantData($userId);
foreach ($grantData['crm_visit'] as $key => $value) {
foreach ($value as $ke => $va) {
if($va['maskType']!=0){
$fieldGrant[$ke]['maskType'] = $va['maskType'];
$fieldGrant[$ke]['form_type'] = $va['form_type'];
$fieldGrant[$ke]['field'] = $va['field'];
}
}
}
foreach ($fieldGrant AS $key => $val){
//掩码相关类型字段
if ($val['maskType']!=0 && $val['form_type'] == 'mobile') {
$pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i";
$rs = preg_replace($pattern, "$1****$2", $dataInfo[$val['field']]);
$dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ? (string)$rs : null;
} elseif ($val['maskType']!=0 && $val['form_type'] == 'email') {
$email_array = explode("@", $dataInfo[$val['field']]);
$prevfix = (strlen($email_array[0]) < 4) ? "" : substr($dataInfo[$val['field']], 0, 2); //
$str = preg_replace('/([\d\w+_-]{0,100})@/', "***@", $dataInfo[$val['field']], -1, $count);
$rs = $prevfix . $str;
$dataInfo[$val['field']] = !empty($dataInfo[$val['field']]) ?$rs: null;
} 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;
}
}
}
// $userModel = new \app\admin\model\User();
// $dataInfo['create_user_id_info'] = isset($dataInfo['create_user_id']) ? $userModel->getUserById($dataInfo['create_user_id']) : [];
// $dataInfo['owner_user_id_info'] = isset($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : [];
// $dataInfo['create_user_name'] = !empty($dataInfo['create_user_id_info']['realname']) ? $dataInfo['create_user_id_info']['realname'] : '';
// $dataInfo['owner_user_name'] = !empty($dataInfo['owner_user_id_info']['realname']) ? $dataInfo['owner_user_id_info']['realname'] : '';
// $dataInfo['customer_id_info'] = $dataInfo['customer_id'] ? db('crm_customer')->where(['customer_id' => $dataInfo['customer_id']])->field('customer_id,name')->find() : [];
// $dataInfo['contract_id_info'] = $dataInfo['contract_id'] ? db('crm_contract')->where(['contract_id' => $dataInfo['contract_id']])->field('contract_id,name,money')->find() : [];
// $dataInfo['receivables_id'] = $id;
// $userModel = new \app\admin\model\User();
// $dataInfo['create_user_info'] = $userModel->getUserById($dataInfo['create_user_id']);
// $dataInfo['plan_id'] = $id;
// # 处理时间格式
// $fieldModel = new \app\admin\model\Field();
// $datetimeField = $fieldModel->getFieldByFormType('crm_receivables', 'datetime'); //日期时间类型
// foreach ($datetimeField as $key => $val) {
// $dataInfo[$val] = !empty($dataInfo[$val]) ? date('Y-m-d H:i:s', $dataInfo[$val]) : null;
// }
// $dataInfo['create_time'] = !empty($dataInfo['create_time']) ? date('Y-m-d H:i:s', $dataInfo['create_time']) : null;
// $dataInfo['update_time'] = !empty($dataInfo['update_time']) ? date('Y-m-d H:i:s', $dataInfo['update_time']) : null;
// // 字段授权
// if (!empty($userId)) {
// $grantData = getFieldGrantData($userId);
// $userLevel = isSuperAdministrators($userId);
// foreach ($dataInfo as $key => $value) {
// if (!$userLevel && !empty($grantData['crm_receivables'])) {
// $status = getFieldGrantStatus($key, $grantData['crm_receivables']);
//
// # 查看权限
// if ($status['read'] == 0) unset($dataInfo[$key]);
// }
// }
// if (!$userLevel && !empty($grantData['crm_receivables'])) {
// # 客户名称
// $customerStatus = getFieldGrantStatus('customer_id', $grantData['crm_receivables']);
// if ($customerStatus['read'] == 0) {
// $dataInfo['customer_name'] = '';
// $dataInfo['customer_id_info'] = [];
// }
// # 合同金额
// $contractMoneyStatus = getFieldGrantStatus('contract_money', $grantData['crm_receivables']);
// if ($contractMoneyStatus['read'] == 0) $dataInfo['contract_id_info']['money'] = '';
// # 合同名称
// $contractMoneyStatus = getFieldGrantStatus('contract_money', $grantData['crm_receivables']);
// if ($contractMoneyStatus['read'] == 0) $dataInfo['contract_id_info']['money'] = '';
// }
// }
return $dataInfo;
}
} }

@ -72,6 +72,7 @@ class Log extends ApiCommon
$param = $this->param; $param = $this->param;
$userInfo = $this->userInfo; $userInfo = $this->userInfo;
$param['read_user_id'] = $userInfo['id']; $param['read_user_id'] = $userInfo['id'];
$param['structure_ids'] = $param['structure_id'];
$param['structure_id'] = $userInfo['structure_id']; $param['structure_id'] = $userInfo['structure_id'];
$data = model('Log')->getDataList($param); $data = model('Log')->getDataList($param);
return resultArray(['data' => $data]); return resultArray(['data' => $data]);

@ -360,7 +360,7 @@ class Event extends Common
} }
} else { } else {
$list = db('admin_oa_schedule')->select(); $list = db('admin_oa_schedule')->select();
foreach ($list as $k=>$v){ foreach ($list as $k=> $v){
$list[$k]['is_select'] = 1; $list[$k]['is_select'] = 1;
} }
} }

@ -42,6 +42,9 @@ class Log extends Common
$recordModel = new \app\admin\model\Record(); $recordModel = new \app\admin\model\Record();
$user_id = $request['read_user_id']; $user_id = $request['read_user_id'];
$by = $request['by'] ?: ''; $by = $request['by'] ?: '';
if($request['structure_ids']){
$user_id = $userModel->getSubUserByStr($request['structure_ids'], 2);
}
$map = []; $map = [];
$search = $request['search']; $search = $request['search'];
if (isset($request['search']) && $request['search']) { if (isset($request['search']) && $request['search']) {
@ -66,8 +69,9 @@ class Log extends Common
$map['log.create_time'] = ['between', [$start_time, $end_time]]; $map['log.create_time'] = ['between', [$start_time, $end_time]];
} }
$requestData = $this->requestData(); $requestData = $this->requestData();
//获取权限范围内的员工 //获取权限范围内的员工
$auth_user_ids = getSubUserId(); $auth_user_ids = getSubUserId(true,0,$user_id);
$dataWhere['user_id'] = $user_id; $dataWhere['user_id'] = $user_id;
$dataWhere['structure_id'] = $request['structure_id']; $dataWhere['structure_id'] = $request['structure_id'];
$dataWhere['auth_user_ids'] = $auth_user_ids; $dataWhere['auth_user_ids'] = $auth_user_ids;
@ -93,16 +97,18 @@ class Log extends Common
}; };
break; break;
} }
$list = Db::name('OaLog')
$list = Db::name('oa_log')
->alias('log')
->where($map) ->where($map)
->where($logMap) ->where($logMap)
->where($searchMap) ->where($searchMap)
->alias('log')
->join('__ADMIN_USER__ user', 'user.id = log.create_user_id', 'LEFT') ->join('__ADMIN_USER__ user', 'user.id = log.create_user_id', 'LEFT')
->page($request['page'], $request['limit']) ->page($request['page'], $request['limit'])
->field('log.*,user.realname,user.thumb_img') ->field('log.*,user.realname,user.thumb_img')
->order('log.update_time desc') ->order('log.update_time desc')
->select(); ->select();
$dataCount = $this->alias('log')->where($map)->where($logMap)->where($searchMap)->count(); $dataCount = $this->alias('log')->where($map)->where($logMap)->where($searchMap)->count();
foreach ($list as $k => $v) { foreach ($list as $k => $v) {
$list[$k]['create_user_info']['realname'] = $v['realname'] ?: ''; $list[$k]['create_user_info']['realname'] = $v['realname'] ?: '';

@ -266,7 +266,8 @@ return [
'crm/receivables/count' => ['crm/receivables/count', ['method' => 'POST']], 'crm/receivables/count' => ['crm/receivables/count', ['method' => 'POST']],
//【回款】导出 //【回款】导出
'crm/receivables/excelExport' => ['crm/receivables/excelExport', ['method' => 'POST']], 'crm/receivables/excelExport' => ['crm/receivables/excelExport', ['method' => 'POST']],
// 【回款计划】导出
'crm/receivablesPlan/excelExport' => ['crm/receivablesPlan/excelExport', ['method' => 'POST']],
// 【回款计划】列表 // 【回款计划】列表
'crm/receivables_plan/index' => ['crm/receivables_plan/index', ['method' => 'POST']], 'crm/receivables_plan/index' => ['crm/receivables_plan/index', ['method' => 'POST']],
// 【回款计划】创建 // 【回款计划】创建
@ -301,6 +302,7 @@ return [
// 【发票】导出 // 【发票】导出
'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']],
// 【发票-开户行】详情 // 【发票-开户行】详情

@ -1,5 +1,5 @@
<?php <?php
return array( return array(
'VERSION'=>'11.1.0', 'VERSION'=>'11.1.1',
'RELEASE'=>'20210625', 'RELEASE'=>'20210903',
); );

@ -261,6 +261,7 @@ INSERT INTO `5kcrm_admin_field` VALUES (14, 'crm_customer', 0, 'name', '客户
INSERT INTO `5kcrm_admin_field` VALUES (15, 'crm_customer', 0, 'level', '客户级别', 'select', '', 0, 0, 0, '', 'A重点客户\nB普通客户\nC非优先客户', 3, 191, 1553788800, 1624439032, 3, '', 0, 50, '1,0', 2, '', '', '', 'A重点客户,B普通客户,C非优先客户', 0); INSERT INTO `5kcrm_admin_field` VALUES (15, 'crm_customer', 0, 'level', '客户级别', 'select', '', 0, 0, 0, '', 'A重点客户\nB普通客户\nC非优先客户', 3, 191, 1553788800, 1624439032, 3, '', 0, 50, '1,0', 2, '', '', '', 'A重点客户,B普通客户,C非优先客户', 0);
INSERT INTO `5kcrm_admin_field` VALUES (16, 'crm_customer', 0, 'industry', '客户行业', 'select', '', 0, 0, 0, '', 'IT/通信/电子/互联网\n金融业\n房地产\n商业服务\n贸易\n生产\n运输/物流\n服务业\n文化传媒\n政府', 2, 191, 1553788800, 1624439031, 3, '', 0, 50, '0,1', 2, '', '', '', 'IT/通信/电子/互联网,金融业,房地产,商业服务,贸易,生产,运输/物流,服务业,文化传媒,政府', 1025); INSERT INTO `5kcrm_admin_field` VALUES (16, 'crm_customer', 0, 'industry', '客户行业', 'select', '', 0, 0, 0, '', 'IT/通信/电子/互联网\n金融业\n房地产\n商业服务\n贸易\n生产\n运输/物流\n服务业\n文化传媒\n政府', 2, 191, 1553788800, 1624439031, 3, '', 0, 50, '0,1', 2, '', '', '', 'IT/通信/电子/互联网,金融业,房地产,商业服务,贸易,生产,运输/物流,服务业,文化传媒,政府', 1025);
INSERT INTO `5kcrm_admin_field` VALUES (17, 'crm_customer', 0, 'source', '客户来源', 'select', '', 0, 0, 0, '', '促销活动\n搜索引擎\n广告\n转介绍\n线上注册\n线上询价\n预约上门\n陌拜\n招商资源\n公司资源\n展会资源\n个人资源\n电话咨询\n邮件咨询', 4, 191, 1553788800, 1624439032, 3, '', 0, 50, '1,1', 2, '', '', '', '促销活动,搜索引擎,广告,转介绍,线上注册,线上询价,预约上门,陌拜,招商资源,公司资源,展会资源,个人资源,电话咨询,邮件咨询', 1026); INSERT INTO `5kcrm_admin_field` VALUES (17, 'crm_customer', 0, 'source', '客户来源', 'select', '', 0, 0, 0, '', '促销活动\n搜索引擎\n广告\n转介绍\n线上注册\n线上询价\n预约上门\n陌拜\n招商资源\n公司资源\n展会资源\n个人资源\n电话咨询\n邮件咨询', 4, 191, 1553788800, 1624439032, 3, '', 0, 50, '1,1', 2, '', '', '', '促销活动,搜索引擎,广告,转介绍,线上注册,线上询价,预约上门,陌拜,招商资源,公司资源,展会资源,个人资源,电话咨询,邮件咨询', 1026);
INSERT INTO `5kcrm_admin_field` VALUES (18, 'crm_customer', 0, 'deal_status', '成交状态', 'select', '未成交', 0, 0, 1, '', '未成交\n已成交', 0, 191, 1553788800, 1553788800, 0, NULL, 0, 100, '', NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO `5kcrm_admin_field` VALUES (19, 'crm_customer', 0, 'telephone', '电话', 'text', '', 0, 0, 0, '', '', 5, 191, 1553788800, 1624439032, 1, '', 0, 50, '2,0', 0, '', '', '', '', 1027); INSERT INTO `5kcrm_admin_field` VALUES (19, 'crm_customer', 0, 'telephone', '电话', 'text', '', 0, 0, 0, '', '', 5, 191, 1553788800, 1624439032, 1, '', 0, 50, '2,0', 0, '', '', '', '', 1027);
INSERT INTO `5kcrm_admin_field` VALUES (20, 'crm_customer', 0, 'website', '网址', 'text', '', 0, 0, 0, '', '', 8, 191, 1553788800, 1624439032, 1, '', 0, 50, '3,1', 0, '', '', '', '', 1028); INSERT INTO `5kcrm_admin_field` VALUES (20, 'crm_customer', 0, 'website', '网址', 'text', '', 0, 0, 0, '', '', 8, 191, 1553788800, 1624439032, 1, '', 0, 50, '3,1', 0, '', '', '', '', 1028);
INSERT INTO `5kcrm_admin_field` VALUES (21, 'crm_customer', 0, 'next_time', '下次联系时间', 'datetime', '', 0, 0, 0, '', '', 9, 63, 1553788800, 1624439032, 13, '', 0, 50, '4,0', 0, '', '', '', '', 1029); INSERT INTO `5kcrm_admin_field` VALUES (21, 'crm_customer', 0, 'next_time', '下次联系时间', 'datetime', '', 0, 0, 0, '', '', 9, 63, 1553788800, 1624439032, 13, '', 0, 50, '4,0', 0, '', '', '', '', 1029);
@ -1599,45 +1600,44 @@ CREATE TABLE `5kcrm_crm_contract_product` (
-- Table structure for 5kcrm_crm_customer -- Table structure for 5kcrm_crm_customer
-- ---------------------------- -- ----------------------------
DROP TABLE IF EXISTS `5kcrm_crm_customer`; DROP TABLE IF EXISTS `5kcrm_crm_customer`;
CREATE TABLE `5kcrm_crm_customer` ( CREATE TABLE `5kcrm_crm_customer` (
`customer_id` int(11) NOT NULL AUTO_INCREMENT, `customer_id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '客户名称', `name` varchar(255) DEFAULT NULL COMMENT '客户名称',
`is_lock` tinyint(1) NOT NULL DEFAULT 0 COMMENT '1锁定', `is_lock` tinyint(1) NOT NULL DEFAULT '0' COMMENT '1锁定',
`deal_time` int(11) NOT NULL COMMENT '领取,分配,创建时间', `deal_time` int(11) NOT NULL COMMENT '领取,分配,创建时间',
`level` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '客户级别', `level` varchar(500) DEFAULT NULL COMMENT '客户级别',
`industry` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '客户行业', `industry` varchar(500) DEFAULT NULL COMMENT '客户行业',
`source` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '客户来源', `source` varchar(500) DEFAULT NULL COMMENT '客户来源',
`telephone` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '电话', `telephone` varchar(255) DEFAULT NULL COMMENT '电话',
`mobile` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '手机', `mobile` varchar(255) DEFAULT NULL COMMENT '手机',
`website` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '网址', `website` varchar(255) DEFAULT NULL COMMENT '网址',
`remark` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '备注', `remark` text COMMENT '备注',
`create_user_id` int(11) NOT NULL COMMENT '创建人ID', `create_user_id` int(11) NOT NULL COMMENT '创建人ID',
`owner_user_id` int(11) NOT NULL COMMENT '负责人ID', `owner_user_id` int(11) NOT NULL COMMENT '负责人ID',
`ro_user_id` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '只读权限', `ro_user_id` varchar(500) NOT NULL DEFAULT '' COMMENT '只读权限',
`rw_user_id` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '读写权限', `rw_user_id` varchar(500) NOT NULL DEFAULT '' COMMENT '读写权限',
`address` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '省市区', `address` varchar(255) NOT NULL DEFAULT '' COMMENT '省市区',
`location` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '定位信息', `location` varchar(255) NOT NULL DEFAULT '' COMMENT '定位信息',
`detail_address` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '详细地址', `detail_address` varchar(255) NOT NULL DEFAULT '' COMMENT '详细地址',
`lng` double(14, 11) NULL DEFAULT NULL COMMENT '地理位置经度', `lng` double(14,11) DEFAULT NULL COMMENT '地理位置经度',
`lat` double(14, 11) NULL DEFAULT NULL COMMENT '地理位置维度', `lat` double(14,11) DEFAULT NULL COMMENT '地理位置维度',
`next_time` int(11) NULL DEFAULT NULL COMMENT '下次联系时间', `next_time` int(11) DEFAULT NULL COMMENT '下次联系时间',
`follow` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '跟进', `follow` varchar(20) DEFAULT NULL COMMENT '跟进',
`obtain_time` int(10) NOT NULL DEFAULT 0 COMMENT '负责人获取客户时间', `obtain_time` int(10) NOT NULL DEFAULT '0' COMMENT '负责人获取客户时间',
`create_time` int(11) NOT NULL COMMENT '创建时间', `create_time` int(11) NOT NULL COMMENT '创建时间',
`update_time` int(11) NOT NULL COMMENT '更新时间', `update_time` int(11) NOT NULL COMMENT '更新时间',
`is_dealt` tinyint(1) NOT NULL DEFAULT 1 COMMENT '是否已经处理待办事项1已处理0未处理', `is_dealt` tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否已经处理待办事项1已处理0未处理',
`is_allocation` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否是分配给我的客户1是0不是', `is_allocation` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否是分配给我的客户1是0不是',
`last_time` int(10) UNSIGNED NULL DEFAULT NULL COMMENT '最后跟进时间', `last_time` int(10) unsigned DEFAULT NULL COMMENT '最后跟进时间',
`last_record` varchar(512) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '最后跟进记录', `last_record` varchar(512) DEFAULT NULL COMMENT '最后跟进记录',
`email` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '邮箱', `email` varchar(255) DEFAULT NULL COMMENT '邮箱',
`before_owner_user_id` int(10) UNSIGNED NULL DEFAULT 0 COMMENT '前负责人', `before_owner_user_id` int(10) unsigned DEFAULT '0' COMMENT '前负责人',
`into_pool_time` int(10) UNSIGNED NULL DEFAULT 0 COMMENT '进入公海时间', `into_pool_time` int(10) unsigned DEFAULT '0' COMMENT '进入公海时间',
`pool_remain` tinyint(1) NOT NULL DEFAULT 0 COMMENT '代办事项待进入公海1已处理0未处理', `pool_remain` tinyint(1) NOT NULL DEFAULT '0' COMMENT '代办事项待进入公海1已处理0未处理',
`deal_status` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '未成交' COMMENT '成交状态', `deal_status` varchar(10) NOT NULL DEFAULT '未成交' COMMENT '成交状态',
PRIMARY KEY (`customer_id`) USING BTREE, PRIMARY KEY (`customer_id`) USING BTREE,
INDEX `bi_analysis`(`create_time`, `owner_user_id`) USING BTREE KEY `bi_analysis` (`create_time`,`owner_user_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '客户表' ROW_FORMAT = DYNAMIC; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='客户表';
-- ---------------------------- -- ----------------------------
-- Records of 5kcrm_crm_customer -- Records of 5kcrm_crm_customer
-- ---------------------------- -- ----------------------------

@ -0,0 +1,5 @@
ALTER TABLE `5kcrm_crm_receivables_plan` ADD COLUMN `real_money` decimal(18,2) NOT NULL DEFAULT '0.00' COMMENT '实际回款金额';
ALTER TABLE `5kcrm_crm_receivables_plan` ADD COLUMN `real_data` date DEFAULT NULL COMMENT '实际回款日期';
ALTER TABLE `5kcrm_crm_receivables_plan` ADD COLUMN `un_money` decimal(18,2) NOT NULL DEFAULT '0.00' COMMENT '未回金额';
INSERT INTO `5kcrm_admin_field` VALUES (18, 'crm_customer', 0, 'deal_status', '成交状态', 'select', '未成交', 0, 0, 1, '', '未成交\n已成交', 0, 191, 1553788800, 1553788800, 0, NULL, 0, 100, '', NULL, NULL, NULL, NULL, NULL, NULL);

@ -88,10 +88,10 @@ $('.next').click(function () {
localStorage.clear(); localStorage.clear();
window.location = 'step5.html'; window.location = 'step5.html';
} else if (result.code == '400') { } else if (result.code == '400') {
alert(result.error); // alert(result.error);
window.location.href = 'step6.html'; window.location.href = 'step6.html';
} else { } else {
alert(result.error); // alert(result.error);
window.location.href = 'step6.html'; window.location.href = 'step6.html';
} }
}, },

@ -0,0 +1,5 @@
ALTER TABLE `5kcrm_crm_receivables_plan` ADD COLUMN `real_money` decimal(18,2) NOT NULL DEFAULT '0.00' COMMENT '实际回款金额';
ALTER TABLE `5kcrm_crm_receivables_plan` ADD COLUMN `real_data` date DEFAULT NULL COMMENT '实际回款日期';
ALTER TABLE `5kcrm_crm_receivables_plan` ADD COLUMN `un_money` decimal(18,2) NOT NULL DEFAULT '0.00' COMMENT '未回金额';
INSERT INTO `5kcrm_admin_field` VALUES (18, 'crm_customer', 0, 'deal_status', '成交状态', 'select', '未成交', 0, 0, 1, '', '未成交\n已成交', 0, 191, 1553788800, 1553788800, 0, NULL, 0, 100, '', NULL, NULL, NULL, NULL, NULL, NULL);
Loading…
Cancel
Save