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 获取列表]
@ -92,6 +92,18 @@ class ActionRecord extends Common
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;

@ -43,9 +43,22 @@ class Field extends Model
'crm_receivables_plan', 'crm_receivables_plan',
'crm_invoice', 'crm_invoice',
'crm_visit', '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',
]; //支持自定义字段的表,不包含表前缀 ]; //支持自定义字段的表,不包含表前缀
private $formtype_arr = [ private $formtype_arr = [
'text', 'text',
'pic',
'textarea', 'textarea',
'mobile', 'mobile',
'email', 'email',
@ -209,8 +222,129 @@ class Field extends Model
'width' => '', 'width' => '',
'is_hidden' => 0, 'is_hidden' => 0,
] ]
] ],
'jxc_supplier' => [
[
'field' => 'detail_address',
'name' => '地址',
'form_type' => 'map_address',
'width' => '',
'is_hidden' => 0,
]
],
'jxc_purchase' => [
[
'field' => 'check_status',
'name' => '审核状态',
'form_type' => 'text',
'width' => '',
'is_hidden' => 0,
]
],
'jxc_retreat' => [
[
'field' => 'check_status',
'name' => '审核状态',
'form_type' => 'text',
'width' => '',
'is_hidden' => 0,
]
],
'jxc_product' => [
[
'field' => 'product_code',
'name' => '产品编码',
'form_type' => 'text',
'width' => '',
'is_hidden' => 0,
],
[
'field' => 'product_picture',
'name' => '产品图片',
'form_type' => 'text',
'width' => '',
'is_hidden' => 0,
],
[
'field' => 'sp_data_value',
'name' => '产品规格',
'form_type' => 'text',
'width' => '',
'is_hidden' => 0,
]
],
'jxc_sale' => [
[
'field' => 'check_status',
'name' => '审核状态',
'form_type' => 'text',
'width' => '',
'is_hidden' => 0,
]
],
'jxc_salereturn' => [
[
'field' => 'check_status',
'name' => '审核状态',
'form_type' => 'text',
'width' => '',
'is_hidden' => 0,
]
],
'jxc_receipt' => [
[
'field' => 'state',
'name' => '状态',
'form_type' => 'text',
'width' => '',
'is_hidden' => 0,
]
],
'jxc_outbound' => [
[
'field' => 'state',
'name' => '状态',
'form_type' => 'text',
'width' => '',
'is_hidden' => 0,
]
],
'jxc_allocation' => [
[
'field' => 'check_status',
'name' => '审核状态',
'form_type' => 'text',
'width' => '',
'is_hidden' => 0,
]
],
'jxc_inventory' => [
[
'field' => 'check_status',
'name' => '审核状态',
'form_type' => 'text',
'width' => '',
'is_hidden' => 0,
]
],
'jxc_collection' => [
[
'field' => 'check_status',
'name' => '审核状态',
'form_type' => 'text',
'width' => '',
'is_hidden' => 0,
]
],
'jxc_payment' => [
[
'field' => 'check_status',
'name' => '审核状态',
'form_type' => 'text',
'width' => '',
'is_hidden' => 0,
]
],
]; ];
protected function initialize() protected function initialize()
@ -238,18 +372,28 @@ class Field extends Model
if ($param['types'] == 'crm_customer') { if ($param['types'] == 'crm_customer') {
$map['field'] = array('not in', ['deal_status']); $map['field'] = array('not in', ['deal_status']);
} }
if ($types == 'crm_receivables_plan') {
$setting = Db::name('AdminField')->where('types', 'crm_receivables')->value('setting');
}
$list = Db::name('AdminField')->where($map)->order('form_position', 'asc')->select(); $list = Db::name('AdminField')->where($map)->order('form_position', 'asc')->select();
$detailTableList = db('admin_field_extend')->field(['field', 'content'])->where('types', $types)->select(); $detailTableList = db('admin_field_extend')->field(['field', 'content'])->where('types', $types)->select();
$detailTableData = []; $detailTableData = [];
foreach ($detailTableList as $key => $value) { foreach ($detailTableList as $key => $value) {
$detailTableData[$value['field']] = !empty($value['content']) ? json_decode($value['content']) : []; $detailTableData[$value['field']] = !empty($value['content']) ? json_decode($value['content'], true) : [];
} }
foreach ($list as $k => $v) { foreach ($list as $k => $v) {
$list[$k]['setting'] = $v['setting'] ? explode(chr(10), $v['setting']) : []; $list[$k]['setting'] = $v['setting'] ? explode(chr(10), $v['setting']) : [];
if ($types == 'crm_receivables_plan') {
$list[$k]['stting'] = $setting ? explode(chr(10), $v['setting']) : [];
}
if ($v['form_type'] == 'checkbox') { if ($v['form_type'] == 'checkbox') {
$list[$k]['default_value'] = $v['default_value'] ? explode(',', $v['default_value']) : array(); $list[$k]['default_value'] = $v['default_value'] ? explode(',', $v['default_value']) : array();
} }
if (in_array($v['form_type'], ['position', 'date_interval'])) { if ($v['form_type']=='date_interval') {
$list[$k]['default_value'] = !empty($v['default_value']) ? explode(',',$v['default_value']) : [];
}
if($v['form_type']=='position'){
$list[$k]['default_value'] = !empty($v['default_value']) ? json_decode($v['default_value'], true) : []; $list[$k]['default_value'] = !empty($v['default_value']) ? json_decode($v['default_value'], true) : [];
} }
if ($v['form_type'] == 'detail_table') { if ($v['form_type'] == 'detail_table') {
@ -260,6 +404,9 @@ class Field extends Model
$list[$k]['xaxis'] = (int)$coordinate[0]; $list[$k]['xaxis'] = (int)$coordinate[0];
$list[$k]['yaxis'] = (int)$coordinate[1]; $list[$k]['yaxis'] = (int)$coordinate[1];
} }
if (!empty($v['relevant'])) {
$list[$k]['relevant'] = !empty($v['relevant']) ? (int)$v['relevant'] : [];
}
if (!empty($v['options'])) { if (!empty($v['options'])) {
$list[$k]['optionsData'] = json_decode($v['options'], true); $list[$k]['optionsData'] = json_decode($v['options'], true);
} else { } else {
@ -268,6 +415,8 @@ class Field extends Model
// 处理数值范围字段 // 处理数值范围字段
$list[$k]['minNumRestrict'] = $v['min_num_restrict']; $list[$k]['minNumRestrict'] = $v['min_num_restrict'];
$list[$k]['maxNumRestrict'] = $v['max_num_restrict']; $list[$k]['maxNumRestrict'] = $v['max_num_restrict'];
unset($list[$k]['min_num_restrict']);
unset($list[$k]['max_num_restrict']);
} }
return getFieldGroupOrderData((array)$list); return getFieldGroupOrderData((array)$list);
@ -291,7 +440,6 @@ class Field extends Model
$this->error = '参数错误'; $this->error = '参数错误';
return false; return false;
} }
# 公海数据 # 公海数据
$poolList = []; $poolList = [];
$poolData = []; $poolData = [];
@ -312,6 +460,10 @@ class Field extends Model
// 设置$formAssistId值 // 设置$formAssistId值
$formAssistId += 1; $formAssistId += 1;
$data['formAssistId'] = $formAssistId; $data['formAssistId'] = $formAssistId;
// 数值范围
if (!empty($data['minNumRestrict'])) $data['min_num_restrict'] = $data['minNumRestrict'];
if (!empty($data['maxNumRestrict'])) $data['max_num_restrict'] = $data['maxNumRestrict'];
// 清除坐标 // 清除坐标
unset($data['xaxis']); unset($data['xaxis']);
unset($data['yaxis']); unset($data['yaxis']);
@ -327,9 +479,11 @@ class Field extends Model
$error_message[] = $data['name'] . '参数错误'; $error_message[] = $data['name'] . '参数错误';
} }
$data['types_id'] = $data['types_id'] ?: 0; $data['types_id'] = $data['types_id'] ?: 0;
if (!in_array($data['form_type'], $this->formtype_arr)) { if (!in_array($data['form_type'], $this->formtype_arr)) {
$error_message[] = $data['name'] . ',字段类型错误'; $error_message[] = $data['name'] . ',字段类型错误';
} }
//生成字段名 //生成字段名
if (!$data['field']) $data['field'] = $this->createField($types, $types == 'oa_examine' ? 'oa_' : 'crm_'); if (!$data['field']) $data['field'] = $this->createField($types, $types == 'oa_examine' ? 'oa_' : 'crm_');
@ -371,9 +525,9 @@ class Field extends Model
} }
# 处理日期区间、地址类型的默认数据 # 处理日期区间、地址类型的默认数据
if (in_array($data['form_type'], ['position', 'date_interval']) && !empty($data['default_value'])) { // if (in_array($data['form_type'], ['position', 'date_interval']) && !empty($data['default_value'])) {
$data['default_value'] = json_encode($data['default_value'], JSON_NUMERIC_CHECK); // $data['default_value'] = json_encode($data['default_value']);
} // }
# 处理明细表格中的字段数据 # 处理明细表格中的字段数据
if ($data['form_type'] == 'detail_table' && !empty($data['fieldExtendList']) && $this->setDetailTableData($types, $data['field'], $data['fieldExtendList']) === false) { if ($data['form_type'] == 'detail_table' && !empty($data['fieldExtendList']) && $this->setDetailTableData($types, $data['field'], $data['fieldExtendList']) === false) {
@ -389,11 +543,6 @@ class Field extends Model
if (empty($data['name']) && $data['form_type'] == 'desc_text') { if (empty($data['name']) && $data['form_type'] == 'desc_text') {
$data['name'] = '描述文字'; $data['name'] = '描述文字';
} }
// 数值范围
if (!empty($data['minNumRestrict'])) $data['min_num_restrict'] = $data['minNumRestrict'];
if (!empty($data['maxNumRestrict'])) $data['max_num_restrict'] = $data['maxNumRestrict'];
unset($data['field_id']); unset($data['field_id']);
if ($i > 1) { if ($i > 1) {
@ -547,7 +696,7 @@ class Field extends Model
* @return [array] * @return [array]
* @author Michael_xu * @author Michael_xu
*/ */
public function settingValue($data) public function settingValue($data, $controller = '')
{ {
//将英文逗号转换为中文逗号 //将英文逗号转换为中文逗号
$new_setting = []; $new_setting = [];
@ -559,11 +708,15 @@ class Field extends Model
$data['setting'] = implode(chr(10), $new_setting); $data['setting'] = implode(chr(10), $new_setting);
//默认值 //默认值
$new_default_value = []; $new_default_value = [];
if ($data['default_value'] && $data['form_type'] == 'checkbox') { if ($data['default_value'] && $data['form_type'] == 'checkbox' && !empty($data['default_value'])) {
foreach ($data['default_value'] as $k => $v) { foreach ($data['default_value'] as $k => $v) {
$new_default_value[] = str_replace(',', '', $v); $new_default_value[] = str_replace(',', '', $v);
} }
$data['default_value'] = implode(',', $new_default_value); $data['default_value'] = implode(',', $new_default_value);
}elseif($data['default_value'] && $data['form_type'] == 'select' && !empty($data['default_value'])){
$data['default_value'] = $data['default_value'];
} else {
$data['default_value'] = '';
} }
return $data; return $data;
} }
@ -597,7 +750,6 @@ class Field extends Model
// 获取最大formAssistId // 获取最大formAssistId
$formAssistId = db('admin_field')->where('types', $types)->order('formAssistId', 'desc')->value('formAssistId'); $formAssistId = db('admin_field')->where('types', $types)->order('formAssistId', 'desc')->value('formAssistId');
$formAssistId = !empty($formAssistId) ? $formAssistId : 1000; $formAssistId = !empty($formAssistId) ? $formAssistId : 1000;
$i = 0; $i = 0;
foreach ($param as $data) { foreach ($param as $data) {
// 设置formAssistId // 设置formAssistId
@ -605,6 +757,17 @@ class Field extends Model
$formAssistId += 1; $formAssistId += 1;
$data['formAssistId'] = $formAssistId; $data['formAssistId'] = $formAssistId;
} }
// 数值范围
if (!empty($data['minNumRestrict'])) {
$data['min_num_restrict'] = $data['minNumRestrict'];
}else{
$data['min_num_restrict']='';
}
if (!empty($data['maxNumRestrict'])){
$data['max_num_restrict'] = $data['maxNumRestrict'];
}else{
$data['max_num_restrict'] = '';
}
// 清除坐标 // 清除坐标
unset($data['xaxis']); unset($data['xaxis']);
unset($data['yaxis']); unset($data['yaxis']);
@ -628,7 +791,7 @@ class Field extends Model
//单选、下拉、多选类型(使用回车符隔开) //单选、下拉、多选类型(使用回车符隔开)
if (in_array($data['form_type'], ['radio', 'select', 'checkbox']) && $data['setting']) { if (in_array($data['form_type'], ['radio', 'select', 'checkbox']) && $data['setting']) {
//将英文逗号转换为中文逗号 //将英文逗号转换为中文逗号
$data = $this->settingValue($data); $data = $this->settingValue($data, 'update');
} }
// 验证 // 验证
$validate = validate($this->name); $validate = validate($this->name);
@ -644,9 +807,11 @@ class Field extends Model
// } // }
# 处理日期区间、地址类型的默认数据 # 处理日期区间、地址类型的默认数据
if (in_array($data['form_type'], ['position', 'date_interval']) && !empty($data['default_value'])) { // if (in_array($data['form_type'], ['position']) && !empty($data['default_value'])) {
$data['default_value'] = json_encode($data['default_value'], JSON_NUMERIC_CHECK); // dump($data['default_value']);
} // p(json_encode($data['default_value']));
// $data['default_value'] = json_encode($data['default_value']);
// }
# 处理明细表格中的字段数据 # 处理明细表格中的字段数据
if ($data['form_type'] == 'detail_table' && !empty($data['fieldExtendList']) && $this->setDetailTableData($data['types'], $data['field'], $data['fieldExtendList']) === false) { if ($data['form_type'] == 'detail_table' && !empty($data['fieldExtendList']) && $this->setDetailTableData($data['types'], $data['field'], $data['fieldExtendList']) === false) {
@ -659,11 +824,6 @@ class Field extends Model
// $data['options'] = json_encode($data['options'], JSON_NUMERIC_CHECK); // $data['options'] = json_encode($data['options'], JSON_NUMERIC_CHECK);
// } // }
// 数值范围
if (!empty($data['minNumRestrict'])) $data['min_num_restrict'] = $data['minNumRestrict'];
if (!empty($data['maxNumRestrict'])) $data['max_num_restrict'] = $data['maxNumRestrict'];
if (isset($data['minNumRestrict'])) unset($data['minNumRestrict']);
if (isset($data['maxNumRestrict'])) unset($data['maxNumRestrict']);
// $resField = $this->allowField(true)->save($data, ['field_id' => $field_id]); // $resField = $this->allowField(true)->save($data, ['field_id' => $field_id]);
unset($data['showSetting']); unset($data['showSetting']);
@ -817,6 +977,7 @@ class Field extends Model
if (!$resData) { if (!$resData) {
$delMessage[] = $dataInfo['name'] . ',删除失败'; $delMessage[] = $dataInfo['name'] . ',删除失败';
} }
//删除列表字段配置数据 //删除列表字段配置数据
$userFieldList = db('admin_user_field')->where(['types' => $dataInfo['types']])->select(); $userFieldList = db('admin_user_field')->where(['types' => $dataInfo['types']])->select();
foreach ($userFieldList as $key => $val) { foreach ($userFieldList as $key => $val) {
@ -829,7 +990,9 @@ class Field extends Model
$dataUserField = []; $dataUserField = [];
$dataUserField['value'] = $datas; $dataUserField['value'] = $datas;
$dataUserField['hide_value'] = []; $dataUserField['hide_value'] = [];
$resUserField = model('UserField')->updateConfig($dataInfo['types'], $dataUserField, $val['id']); $userFieldModel = new \app\admin\model\UserField();
$resUserField = $userFieldModel->updateConfig($dataInfo['types'], $dataUserField, $val['id']);
// $resUserField = model('UserField')->updateConfig($dataInfo['types'], $dataUserField, $val['id']);
} }
} }
//删除场景字段数据 //删除场景字段数据
@ -944,7 +1107,7 @@ class Field extends Model
$types = 'crm_customer_pool'; $types = 'crm_customer_pool';
} }
if ($param['action'] == 'excel') { if ($param['action'] == 'excel') {
$map['form_type'] = array('not in', ['file', 'form','user','structure', 'checkbox' ,'deal_status','position','location','handwriting_sign','date_interval','detail_table','desc_text','boolean_value']);//删除了过滤structure user字段类型数据 添加deal_status $map['form_type'] = array('not in', ['file', 'form', 'user', 'structure', 'checkbox', 'deal_status', 'position', 'location', 'handwriting_sign', 'date_interval', 'detail_table', 'desc_text', 'boolean_value']);//删除了过滤structure user字段类型数据 添加deal_status
} elseif ($param['action'] == 'index') { } elseif ($param['action'] == 'index') {
$map['form_type'] = array('not in', ['file', 'form']); $map['form_type'] = array('not in', ['file', 'form']);
} }
@ -952,18 +1115,25 @@ class Field extends Model
$order = 'order_id asc, field_id asc'; $order = 'order_id asc, field_id asc';
if ($param['action'] == 'index' || $param['action'] == 'pool') { if ($param['action'] == 'index' || $param['action'] == 'pool') {
$field_list = $this->getIndexFieldConfig($types, $param['user_id']); $field_list = $this->getIndexFieldConfig($types, $param['user_id']);
$field_list[] = [
'field' => 'owner_user_structure_name',
'name' => '所属部门',
'form_type' => 'structure',
'writeStatus' => 0,
'is_hidden' => 1,
'fieldName' => 'owner_user_structure_name'
];
foreach ($field_list as $k => $v) { foreach ($field_list as $k => $v) {
# 处理字段授权 # 处理字段授权
$field_list[$k]['writeStatus'] = 1; $field_list[$k]['writeStatus'] = 1;
if (!$userLevel && $param['module'] == 'crm' && !empty($grantData[$param['types']])) { if (!$userLevel && $param['module'] == 'crm' && !empty($grantData[$param['types']])) {
$status = getFieldGrantStatus($v['field'], $grantData[$param['types']]); $status = getFieldGrantStatus($v['field'], $grantData[$param['types']]);
# 查看权限 # 查看权限
if ($status['read'] == 0) { if ($status['read'] == 0) {
unset($field_list[(int)$k]); unset($field_list[(int)$k]);
continue; continue;
} }
$field_list[$k]['maskType'] = $status['maskType'];
# 编辑权限 # 编辑权限
$field_list[$k]['writeStatus'] = $status['write']; $field_list[$k]['writeStatus'] = $status['write'];
} }
@ -999,23 +1169,22 @@ class Field extends Model
]; ];
} }
} else { } else {
$fields = 'field_id,field,types,name,form_type,default_value,is_unique,is_null,input_tips,setting,is_hidden,form_position,precisions,options,style_percent,formAssistId'; $fields = 'field_id,field,types,name,max_num_restrict as maxNumRestrict,min_num_restrict as minNumRestrict,form_type,default_value,is_unique,is_null,input_tips,setting,is_hidden,form_position,precisions,options,style_percent,formAssistId,remark';
$field_list = db('admin_field')->field($fields)->where($map)->where('is_hidden', 0)->order($order)->select(); $field_list = db('admin_field')->field($fields)->where($map)->where('is_hidden', 0)->order($order)->select();
// 获取X坐标值 // 获取X坐标值
$x = $this->getFormPositionXValue($types, $types_id); $x = $this->getFormPositionXValue($types, $types_id);
# 详情页面增加负责人字段 # 详情页面增加负责人字段
if ($param['action'] == 'read' && !in_array($param['types'], ['crm_visit', 'crm_product', 'oa_examine', 'crm_invoice'])) { // if ($param['action'] == 'read' && !in_array($param['types'], ['crm_visit', 'crm_product', 'oa_examine', 'crm_invoice'])) {
$field_list[] = [ // $field_list[] = [
'field' => 'owner_user_id', // 'field' => 'owner_user_id',
'name' => '负责人', // 'name' => '负责人',
'form_type' => 'user', // 'form_type' => 'user',
'writeStatus' => 0, // 'writeStatus' => 0,
'fieldName' => 'owner_user_name', // 'fieldName' => 'owner_user_name',
'value' => $dataInfo['owner_user_name'], // 'value' => $dataInfo['owner_user_name'],
]; // ];
} // }
//客户 //客户
if (in_array($param['types'], ['crm_customer'])) { if (in_array($param['types'], ['crm_customer'])) {
@ -1072,9 +1241,9 @@ class Field extends Model
]; ];
} }
# 产品基本信息增加负责人信息 # 产品基本信息增加负责人信息
if ($param['action'] == 'read' && $param['types'] == 'crm_product') { // if ($param['action'] == 'read' && $param['types'] == 'crm_product') {
$new_field_list[] = db('admin_field')->where(['types_id' => 0, 'field' => 'owner_user_id'])->find(); // $new_field_list[] = db('admin_field')->where(['types_id' => 0, 'field' => 'owner_user_id'])->find();
} // }
if ($new_field_list) $field_list = array_merge(collection($field_list)->toArray(), $new_field_list); if ($new_field_list) $field_list = array_merge(collection($field_list)->toArray(), $new_field_list);
foreach ($field_list as $k => $v) { foreach ($field_list as $k => $v) {
# 处理字段授权 # 处理字段授权
@ -1084,12 +1253,20 @@ class Field extends Model
# 查看权限 # 查看权限
if (empty($status['read'])) { if (empty($status['read'])) {
unset($field_list[(int)$k]); unset($field_list[(int)$k]);
continue; continue;
} }
# 编辑权限 # 编辑权限
if ($param['action'] != 'save') $field_list[$k]['writeStatus'] = $status['write']; if ($param['action'] != 'save') $field_list[$k]['writeStatus'] = $status['write'];
}
if ($param['action'] == 'read') {
$field_list[$k]['maskType'] = $status['maskType'];
if($status['maskType']!=0){
$field_list[$k]['writeStatus'] = 0;
}
} }
# (联系人,商机,合同,回款,回访)关联其他模块的字段在详情页面不允许修改;创建人、负责人不允许修改 # (联系人,商机,合同,回款,回访)关联其他模块的字段在详情页面不允许修改;创建人、负责人不允许修改
@ -1154,7 +1331,7 @@ class Field extends Model
]; ];
} elseif ($v['form_type'] == 'user') { } elseif ($v['form_type'] == 'user') {
$value = $userModel->getListByStr($dataInfo[$v['field']]) ?: []; $value = $userModel->getListByStr($dataInfo[$v['field']]) ?: [];
if (empty($value)) $default_value = $userModel->getListByStr($param['user_id']) ?: []; // if (empty($value)) $default_value = $userModel->getListByStr($param['user_id']) ?: [];
} elseif ($v['form_type'] == 'single_user') { } elseif ($v['form_type'] == 'single_user') {
# 单用户 # 单用户
$userInfo = $userModel->getListByStr($dataInfo[$v['field']]); $userInfo = $userModel->getListByStr($dataInfo[$v['field']]);
@ -1285,20 +1462,96 @@ class Field extends Model
} elseif ($v['form_type'] == 'desc_text') { } elseif ($v['form_type'] == 'desc_text') {
// 描述文字 // 描述文字
$value = !empty($dataInfo[$v['field']]) ? $dataInfo[$v['field']] : $v['default_value']; $value = !empty($dataInfo[$v['field']]) ? $dataInfo[$v['field']] : $v['default_value'];
} elseif (in_array($v['form_type'], ['position', 'location', 'date_interval', 'detail_table'])) { } elseif ($v['form_type']=='location') {
// 地址、定位、日期区间、明细表格 // 地址、定位、日期区间、明细表格
$primaryKey = getPrimaryKeyName($param['types']); $primaryKey = getPrimaryKeyName($param['types']);
$positionJson = !empty($dataInfo[$primaryKey]) ? db($param['types'] . '_data')->where([$primaryKey => $dataInfo[$primaryKey], 'field' => $v['field']])->value($param['types'] == 'oa_examine' ? 'value' : 'content') : ''; $positionJson = !empty($dataInfo[$primaryKey]) ? db($param['types'] . '_data')->where([$primaryKey => $dataInfo[$primaryKey], 'field' => $v['field']])->value($param['types'] == 'oa_examine' ? 'value' : 'content') : '';
$positionData = !empty($positionJson) ? json_decode($positionJson, true) : ''; $positionData = !empty($positionJson) ? json_decode($positionJson, true) : '';
$value = $positionData; $value = $positionData;
} elseif($v['form_type']=='detail_table'){
// $fieldGrant = db('admin_field_mask')->where('types', 'contract')->select();
$primaryKey = getPrimaryKeyName($param['types']);
$positionJson = !empty($dataInfo[$primaryKey]) ? db($param['types'] . '_data')->where([$primaryKey => $dataInfo[$primaryKey], 'field' => $v['field']])->value($param['types'] == 'oa_examine' ? 'value' : 'content') : '';
$positionData = !empty($positionJson) ? json_decode($positionJson, true) : '';
foreach ($positionData as $kk => $val){
foreach ($val as $key => $values){
if($values['form_type']=='user'){
$positionData[$kk][$key]['value']= !empty($values['value'])?$userModel->getListByStr($values['value']) :[];
}
if($values['form_type']=='structure'){
$positionData[$kk][$key]['value']= !empty($values['value'])? $structureModel->getListByStr($values['value']) : [];
}
if($values['form_type']=='datetime' && is_numeric($values['value'])){
$positionData[$kk][$key]['value']= date('Y-m-d, H:i:s',$values['value']);
}
if($values['form_type']=='boolean_value'){
$positionData[$kk][$key]['value']= (string)$values['value'];
}
if($values['form_type']=='file'){
$fileIds = stringToArray($values['value']);
$whereFile = [];
$whereFile['module'] = 'other';
$whereFile['module_id'] = 1;
$whereFile['file_id'] = ['in', $fileIds];
$fileList = $fileModel->getDataList($whereFile, 'all');
$positionData[$kk][$key]['value'] = $fileList['list'] ?: [];
}
// foreach ($fieldGrant as $val) {
// if (in_array($val['statue_type'], [1, 3]) && $val['form_type'] == ['mobile']) {
// $positionData[$kk][$key]['value'] = !empty($values['value']) ? (string)substr_replace($values['value'], '*', 2, 4) : null;
// } elseif (in_array($val['statue_type'], [1, 3]) && $val['form_type'] == ['email']) {
// $email_array = explode("@", $values['value']);
// $str = substr_replace($email_array[0], '*', 1);
// $positionData[$kk][$key]['value'] = !empty($values['value']) ? (string)$str . $email_array[1] : null;
// } elseif (in_array($val['statue_type'], [1, 3]) && in_array($val['form_type'],['position','floatnumber'])) {
// $positionData[$kk][$key]['value'] = !empty($dataInfo[$val['fiele_id']]) ? (string)substr_replace($values['value'], '*',0,strlen($values['value'])) : null;
// }
// }
$positionData[$kk][$key]['optionsData']=!empty($field_list[$k]['options']) ? json_decode($field_list[$k]['options'], true) : '';
}
}
$value = $positionData;
if ($v['form_type'] == 'detail_table') { if ($v['form_type'] == 'detail_table') {
$content = db('admin_field_extend')->where(['types' => $types, 'field' => $v['field']])->value('content'); $content = db('admin_field_extend')->where(['types' => $types, 'field' => $v['field']])->value('content');
$field_list[$k]['fieldExtendList'] = json_decode($content, true); $content=json_decode($content, true);
foreach ($content as &$vv){
$vv['optionsData']=!empty($field_list[$k]['options']) ? json_decode($field_list[$k]['options'], true) : '';
}
$field_list[$k]['fieldExtendList'] = $content;
} }
} elseif($v['form_type']=='position'){
// 地址
$default_value = !empty($v['default_value']) ? json_decode($v['default_value'], true) : [];
if(!empty($dataInfo[$v['field']])){
$position= explode(',',$dataInfo[$v['field']]);
for ($i=0; $i<count($position); $i++) {
$b[]['name'] =trim(json_encode($position[$i],JSON_UNESCAPED_UNICODE),'"');
}
$value =$b;
}
} elseif($v['form_type']=='date_interval'){
if (!empty($dataInfo[$v['field']])) {
$position= explode('_',$dataInfo[$v['field']]);
$value =$position;
}
$default_value = !empty($v['default_value'])?explode(',',$v['default_value']):[];
} else { } else {
$value = isset($dataInfo[$v['field']]) ? $dataInfo[$v['field']] : ''; $value = isset($dataInfo[$v['field']]) ? $dataInfo[$v['field']] : '';
} }
// $fieldGrant = db('admin_field_mask')->where('types', 'contract')->select();
// foreach ($fieldGrant as $val) {
// if (in_array($val['statue_type'], [1, 3]) && $val['form_type'] == ['mobile']) {
// $value = !empty($dataInfo[$val['fiele_id']]) ? (string)substr_replace($dataInfo[$val['fiele_id']], '*', 2, 4) : null;
// } elseif (in_array($val['statue_type'], [1, 3]) && $val['form_type'] == ['email']) {
// $email_array = explode("@", $dataInfo[$val['fiele_id']]);
// $str = substr_replace($email_array[0], '*', 1);
// $value = !empty($dataInfo[$val['fiele_id']]) ? (string)$str . $email_array[1] : null;
// } elseif (in_array($val['statue_type'], [1, 3]) && in_array($val['form_type'],['position','floatnumber'])) {
// $value = !empty($dataInfo[$val['fiele_id']]) ? (string)substr_replace($dataInfo[$val['fiele_id']], '*',0,strlen($dataInfo[$val['fiele_id']])) : null;
// }
// }
$field_list[$k]['setting'] = $setting; $field_list[$k]['setting'] = $setting;
$field_list[$k]['default_value'] = $default_value; $field_list[$k]['default_value'] = $default_value;
$field_list[$k]['value'] = $value; $field_list[$k]['value'] = $value;
@ -1347,7 +1600,7 @@ class Field extends Model
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$user_id = $param['user_id']; $user_id = $param['user_id'];
$map['types'] = ['in', ['', $types]]; $map['types'] = ['in', ['', $types]];
$map['form_type'] = ['not in', ['file', 'form', 'business_status', 'detail_table', 'desc_text', 'handwriting_sign', 'date_interval']]; $map['form_type'] = ['not in', ['file', 'pic', 'structure', 'form', 'business_status', 'detail_table', 'desc_text', 'handwriting_sign', 'date_interval']];
$map['is_hidden'] = 0; $map['is_hidden'] = 0;
$field_list = db('admin_field') $field_list = db('admin_field')
->where($map) ->where($map)
@ -1415,6 +1668,12 @@ class Field extends Model
$field_list[$k]['form_type'] = 'module'; $field_list[$k]['form_type'] = 'module';
$field_list[$k]['field'] = 'contacts_name'; $field_list[$k]['field'] = 'contacts_name';
} }
if ($v['field'] == 'warehouse_id' && in_array($param['types'], ['jxc_receipt', 'jxc_outbound'])) {
$field_list[$k]['form_type'] = 'text';
}
if ($v['form_type'] == 'warehouse_cause') {
$field_list[$k]['form_type'] = 'text';
}
if ($v['form_type'] == 'category') { if ($v['form_type'] == 'category') {
@ -1514,15 +1773,14 @@ class Field extends Model
* @param excel 导出使用 * @param excel 导出使用
* @author Michael_xu * @author Michael_xu
*/ */
public function getIndexFieldConfig($types, $user_id, $types_id = '',$excel='') public function getIndexFieldConfig($types, $user_id, $types_id = '', $excel = '')
{ {
$userFieldModel = new \app\admin\model\UserField(); $userFieldModel = new \app\admin\model\UserField();
$userFieldData = $userFieldModel->getConfig($types, $user_id); $userFieldData = $userFieldModel->getConfig($types, $user_id);
$userFieldData = $userFieldData ? json_decode($userFieldData, true) : []; $userFieldData = $userFieldData ? json_decode($userFieldData, true) : [];
$grantData = getFieldGrantData($user_id); $grantData = getFieldGrantData($user_id);
$userLevel = isSuperAdministrators($user_id); $userLevel = isSuperAdministrators($user_id);
$fieldList = $this->getFieldList($types, $types_id, $excel);
$fieldList = $this->getFieldList($types, $types_id,$excel);
$where = []; $where = [];
if ($userFieldData) { if ($userFieldData) {
$fieldArr = []; $fieldArr = [];
@ -1551,12 +1809,11 @@ class Field extends Model
foreach ($dataList as $k => $v) { foreach ($dataList as $k => $v) {
if (!$userLevel && !empty($grantData[$types])) { if (!$userLevel && !empty($grantData[$types])) {
$status = getFieldGrantStatus($v['field'], $grantData[$types]); $status = getFieldGrantStatus($v['field'], $grantData[$types]);
$dataList[(int)$k]['maskType']=$status['maskType'];
# 查看权限 # 查看权限
if ($status['read'] == 0) unset($dataList[(int)$k]); if ($status['read'] == 0) unset($dataList[(int)$k]);
} }
} }
return array_values($dataList) ?: []; return array_values($dataList) ?: [];
} }
@ -1575,16 +1832,19 @@ class Field extends Model
$newTypes = 'crm_customer'; $newTypes = 'crm_customer';
$unField = ['owner_user_id']; $unField = ['owner_user_id'];
} }
if($excel=='excel'){ if ($excel == 'excel') {
$where=[ if ($types == 'jxc_product') {
$unField = ['product_picture'];
}
$where = [
'types' => ['IN', ['', $newTypes]], 'types' => ['IN', ['', $newTypes]],
'form_type' => ['not in', ['file', 'form', 'deal_status','position','location','handwriting_sign','date_interval','detail_table','desc_text','boolean_value']], 'form_type' => ['not in', ['file', 'form', 'pic', 'deal_status', 'handwriting_sign', 'detail_table', 'desc_text']],
'field' => ['not in', $unField], 'field' => ['not in', $unField],
'types_id' => ['eq', $types_id], 'types_id' => ['eq', $types_id],
'is_hidden' => 0 'is_hidden' => 0
]; ];
}else{ } else {
$where=[ $where = [
'types' => ['IN', ['', $newTypes]], 'types' => ['IN', ['', $newTypes]],
'form_type' => ['not in', ['file', 'form', 'desc_text', 'detail_table']], 'form_type' => ['not in', ['file', 'form', 'desc_text', 'detail_table']],
'field' => ['not in', $unField], 'field' => ['not in', $unField],
@ -1609,25 +1869,45 @@ class Field extends Model
} }
if (isset($this->orther_field_list[$newTypes])) { if (isset($this->orther_field_list[$newTypes])) {
foreach ($this->orther_field_list[$newTypes] as $val) { foreach ($this->orther_field_list[$newTypes] as $val) {
$res[] = $val; if($val['field'] != 'product_picture'){
$res[] = $val;
}
} }
} }
if ($types == 'crm_customer') { if ($types == 'crm_customer') {
$res[] = [ $res[] = [
'field' => 'pool_day', 'field' => 'pool_day',
'name' => '距进入公海天数', 'name' => '距进入公海天数',
'form_type' => 'text', 'form_type' => 'text',
'is_hidden' => 0 'is_hidden' => 0
]; ];
$res[] = [ $res[] = [
'field' => 'is_lock', 'field' => 'is_lock',
'name' => '锁定状态', 'name' => '锁定状态',
'form_type' => 'text', 'form_type' => 'text',
'is_hidden' => 0 'is_hidden' => 0
]; ];
} elseif ($types == 'crm_receivables_plan') {
$res[] = [
'field' => 'real_money',
'name' => '实际回款金额',
'form_type' => 'floatnumber',
'is_hidden' => 0
];
$res[] = [
'field' => 'real_data',
'name' => '实际回款日期',
'form_type' => 'date',
'is_hidden' => 0
];
$res[] = [
'field' => 'un_money',
'name' => '未回金额',
'form_type' => 'floatnumber',
'is_hidden' => 0
];
} }
return array_column($res, null, 'field'); return array_column($res, null, 'field');
} }
@ -1724,6 +2004,15 @@ class Field extends Model
} }
$sysField = ['invoice.invoice_id', 'invoice.owner_user_id', 'invoice.invoice_status', 'invoice.invoice_number', 'invoice.invoice_type', 'invoice.check_status', 'invoice.customer_id', 'invoice.contract_id', 'invoice.create_user_id', 'invoice.flow_id', 'invoice.real_invoice_date', 'invoice.logistics_number']; $sysField = ['invoice.invoice_id', 'invoice.owner_user_id', 'invoice.invoice_status', 'invoice.invoice_number', 'invoice.invoice_type', 'invoice.check_status', 'invoice.customer_id', 'invoice.contract_id', 'invoice.create_user_id', 'invoice.flow_id', 'invoice.real_invoice_date', 'invoice.logistics_number'];
break; break;
case 'crm_receivables_plan' :
$newList = [];
foreach ($dataList as $k => $v) {
$newList[] = 'receivables_plan.' . $v;
}
$sysField = ['receivables_plan.plan_id', 'receivables_plan.num', 'receivables_plan.receivables_id', 'receivables_plan.status', 'receivables_plan.contract_id', 'receivables_plan.customer_id', 'receivables_plan.money', 'receivables_plan.return_date', 'receivables_plan.return_type', 'receivables_plan.remind', 'receivables_plan.remind_date', 'receivables_plan.remark',
'receivables_plan.create_user_id', 'receivables_plan.owner_user_id', 'receivables_plan.create_time', 'receivables_plan.update_time', 'receivables_plan.file', 'receivables_plan.is_dealt', 'receivables_plan.un_money', 'receivables_plan.real_data', 'receivables_plan.real_money'
];
break;
} }
$listArr = $sysField ? array_unique(array_merge($newList, $sysField)) : $dataList; $listArr = $sysField ? array_unique(array_merge($newList, $sysField)) : $dataList;
} else { } else {
@ -1877,6 +2166,42 @@ class Field extends Model
case 'oa_examine' : case 'oa_examine' :
$dataModel = db('oa_examine'); $dataModel = db('oa_examine');
break; break;
case 'jxc_supplier' :
$dataModel = new \app\jxc\model\Supplier();//db('jxc_supplier');
break;
case 'jxc_product' :
$dataModel = db('jxc_product');
break;
case 'jxc_purchase' :
$dataModel = db('jxc_purchase');
break;
case 'jxc_retreat' :
$dataModel = db('jxc_retreat');
break;
case 'jxc_sale' :
$dataModel = db('jxc_sale');
break;
case 'jxc_salereturn' :
$dataModel = db('jxc_salereturn');
break;
case 'jxc_receipt' :
$dataModel = db('jxc_receipt');
break;
case 'jxc_outbound' :
$dataModel = db('jxc_outbound');
break;
case 'jxc_payment' :
$dataModel = db('jxc_payment');
break;
case 'jxc_collection' :
$dataModel = db('jxc_collection');
break;
case 'jxc_inventory' :
$dataModel = db('jxc_inventory');
break;
case 'jxc_allocation' :
$dataModel = db('jxc_allocation');
break;
} }
$where = []; $where = [];
@ -1887,7 +2212,13 @@ class Field extends Model
if ($types == 'crm_product') { if ($types == 'crm_product') {
$where['delete_user_id'] = 0; $where['delete_user_id'] = 0;
} }
if ($res = $dataModel->where($where)->find()) { if ($types == 'jxc_product') {
$where['is_del'] = 0;
}
$res = $dataModel->where($where)->find();
if ($res) {
$this->error = '该数据已存在,请修改后提交!'; $this->error = '该数据已存在,请修改后提交!';
return false; return false;
} }
@ -1932,7 +2263,7 @@ class Field extends Model
* 根据form_type处理数据 * 根据form_type处理数据
* @author lee * @author lee
*/ */
public function getValueByFormtype($val, $form_type) public function getValueByFormtype($val, $form_type, $dataInfo)
{ {
$userModel = new \app\admin\model\User(); $userModel = new \app\admin\model\User();
$structureModel = new \app\admin\model\Structure(); $structureModel = new \app\admin\model\Structure();
@ -1941,14 +2272,22 @@ class Field extends Model
// $val = $val > 0 ? date('Y-m-d H:i:s', $val) : ''; // $val = $val > 0 ? date('Y-m-d H:i:s', $val) : '';
// break; // break;
case 'user' : case 'user' :
$val = count($userModel->getUserNameByArr($val)) > 1 ? ArrayToString($userModel->getUserNameByArr($val)) : implode(',', $userModel->getUserNameByArr(stringToArray($val))); if (is_numeric($val)) {
$val = count($userModel->getUserNameByArr($val)) > 1 ? ArrayToString($userModel->getUserNameByArr($val)) : implode(',', $userModel->getUserNameByArr(stringToArray($val)));
} else {
$val = $val;
}
break; break;
case 'userStr' : case 'userStr' :
$val = explode(',', $val); $val = explode(',', $val);
$val = count($userModel->getUserNameByArr($val)) > 1 ? ArrayToString($userModel->getUserNameByArr($val)) : implode(',', $userModel->getUserNameByArr($val)); $val = count($userModel->getUserNameByArr($val)) > 1 ? ArrayToString($userModel->getUserNameByArr($val)) : implode(',', $userModel->getUserNameByArr($val));
break; break;
case 'structure' : case 'structure' :
$val = implode(',', $structureModel->getStructureNameByArr(stringToArray($val))); if (is_numeric($val)) {
$val = implode(',', $structureModel->getStructureNameByArr(stringToArray($val)));
} else {
$val = $val;
}
break; break;
case 'customer' : case 'customer' :
$val = db('crm_customer')->where(['customer_id' => $val])->value('name'); $val = db('crm_customer')->where(['customer_id' => $val])->value('name');
@ -1968,6 +2307,54 @@ class Field extends Model
case 'business_status' : case 'business_status' :
$val = db('crm_business_status')->where(['status_id' => $val])->value('name'); $val = db('crm_business_status')->where(['status_id' => $val])->value('name');
break; break;
case 'location' :
$val = $val['address'];
break;
case 'position' :
$val = trim(arrayToString(array_column($val, 'name')), ',');
break;
case 'warehouse_cause' :
$val = db('jxc_warehouse')->where(['warehouse_id' => $val])->value('warehouse_name');
break;
case 'sale_cause' :
$val = db('jxc_sale')->where(['sale_id' => $val])->value('order_number');
break;
case 'supplier_cause' :
$val = db('jxc_supplier')->where(['supplier_id' => $val])->value('supplier_name');
break;
case 'purchase_cause' :
$val = db('jxc_purchase')->where(['purchase_id' => $val])->value('order_number');
break;
case 'order_cause' :
if($dataInfo['receipt_type'] == '销售退货入库'){
$val = db('jxc_salereturn')->where(['salereturn_id' => $val])->value('order_number');
}elseif ($dataInfo['receipt_type'] == '采购入库') {
$val = db('jxc_purchase')->where(['purchase_id' => $val])->value('order_number');
}elseif ($dataInfo['outbound_type'] == '销售出库') {
$val = db('jxc_sale')->where(['sale_id' => $val])->value('order_number');
}elseif ($dataInfo['outbound_type'] == '采购退货出库') {
$val = db('jxc_retreat')->where(['retreat_id' => $val])->value('order_number');
}
break;
case 'category_cause' :
$val = db('jxc_product_category')->where(['category_id' => $val])->value('category_name');
break;
case 'product_cause' :
$val = db('jxc_product')->where(['product_id' => $val])->value('product_name');
break;
case 'collection_object' :
if($dataInfo['collection_type'] == '采购退货'){
// $val = db('jxc_supplier')->where(['supplier_id' => $val])->value('supplier_name');
}elseif ($dataInfo['collection_type'] == '销售出库') {
$val = db('jxc_sale')->where(['sale_id' => $val])->value('order_number');
}elseif ($dataInfo['payment_type'] == '采购') {
$val = db('crm_customer')->where(['customer_id' => $val])->value('name');
}elseif ($dataInfo['payment_type'] == '销售退货') {
$val = db('jxc_salereturn')->where(['salereturn_id' => $val])->value('order_number');
}
break;
} }
return $val; return $val;
} }
@ -2012,11 +2399,15 @@ class Field extends Model
return false; return false;
} }
if (!$data) return $data; if (!$data) return $data;
$list = $this->where(['types' => $types, 'relevant' => ['neq', '']])->field('field,relevant')->select(); $list = db('admin_field')->where(['types' => $types, 'relevant' => ['neq', '']])->field('field,relevant')->select();
if (!$list) return $data; foreach ($list as &$val){
$newData = $data; $val=!empty($val)?$val:'';
}
$newData = [];
//crm_hfsomz
foreach ($list as $k => $v) { foreach ($list as $k => $v) {
$newData[$v['relevant']] = $data[$v['field']]; $customer_field=db('admin_field')->where(['types' => 'crm_customer', 'field_id' => $v['relevant']])->field('field')->find();
$newData[$customer_field['field']] = $data[$v['field']];
} }
return $newData ?: []; return $newData ?: [];
} }
@ -2033,6 +2424,7 @@ class Field extends Model
public function getOrderByFormtype($types, $prefix, $field, $order_type) public function getOrderByFormtype($types, $prefix, $field, $order_type)
{ {
$form_type = $this->where(['types' => $types, 'field' => $field])->value('form_type'); $form_type = $this->where(['types' => $types, 'field' => $field])->value('form_type');
// die('123');
// if (!$form_type) { // if (!$form_type) {
// $this->error = '参数错误'; // $this->error = '参数错误';
// return false; // return false;
@ -2244,11 +2636,11 @@ class Field extends Model
} }
if (!empty($id)) { if (!empty($id)) {
return db('admin_field_extend')->where('id', $id)->update(['content' => json_encode($data, JSON_NUMERIC_CHECK)]); return db('admin_field_extend')->where('id', $id)->update(['content' => json_encode($data)]);
} }
if (empty($id)) { if (empty($id)) {
return db('admin_field_extend')->insert(['types' => $types, 'field' => $field, 'content' => json_encode($data, JSON_NUMERIC_CHECK), 'create_time' => time()]); return db('admin_field_extend')->insert(['types' => $types, 'field' => $field, 'content' => json_encode($data), 'create_time' => time()]);
} }
return false; return false;

@ -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) {
@ -827,6 +866,7 @@ class User extends Common
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();
} }
} }

@ -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,10 +352,10 @@ 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'])) {
@ -376,18 +377,32 @@ function advancedQuery($param, $m = '', $c = '', $a = '')
$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);
} }
@ -400,11 +415,16 @@ function advancedQuery($param, $m = '', $c = '', $a = '')
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']];
@ -519,7 +539,11 @@ function advancedQueryFormatForPersonnel($data, $condition)
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);
@ -559,7 +583,11 @@ function advancedQueryFormatForCommon($data, $condition, $formType, $key)
if (in_array($formType, ['checkbox']) && $condition == 'isNot') $condition = 'notContains'; if (in_array($formType, ['checkbox']) && $condition == 'isNot') $condition = 'notContains';
// 处理查询参数 // 处理查询参数
if (in_array($condition, ['contains', 'notContains', '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'])) {
@ -579,19 +607,19 @@ function advancedQueryFormatForCommon($data, $condition, $formType, $key)
$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 = [];
@ -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;
} }
@ -649,6 +678,24 @@ function advancedQueryDataTransform($data, $condition)
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,8 +708,9 @@ 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]);
} }
// 上一年度 // 上一年度
@ -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))) : '';
@ -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 '';
@ -2693,8 +2745,7 @@ 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;
@ -2708,17 +2759,20 @@ if (!function_exists('getFieldGrantStatus')) {
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;
} }
} }
@ -3007,36 +3061,36 @@ 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];
@ -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) {
@ -3104,10 +3170,10 @@ function advancedQueryFormatForTeam($requestMap,$db,$db_id)
$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,7 +112,35 @@ 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;
@ -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,7 +119,7 @@ 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]);
} }
@ -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) {
@ -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) {
@ -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' => '转移成功']);
@ -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'] : ''
@ -607,10 +609,10 @@ class Customer extends ApiCommon
} }
//修改记录 //修改记录
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) {
@ -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' => '领取成功']);
@ -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 . '》,分配给您';
@ -764,16 +766,16 @@ 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');
@ -783,7 +785,7 @@ class Customer extends ApiCommon
$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;
@ -811,20 +813,20 @@ 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);
} }
@ -848,7 +850,7 @@ 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()]);
} }
@ -880,6 +882,7 @@ class Customer extends ApiCommon
*/ */
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'];
@ -901,49 +904,6 @@ 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) {
@ -1124,12 +1084,12 @@ 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
]; ];
@ -1194,9 +1154,9 @@ class Customer extends ApiCommon
/** /**
* 客户级别列表 * 客户级别列表
* *
* @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(

@ -162,4 +162,41 @@ class ReceivablesPlan extends ApiCommon
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;

@ -31,19 +31,12 @@ 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'];
@ -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'];
@ -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,8 +919,8 @@ 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 ?: [];
} }

@ -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,11 +236,37 @@ 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;
} }
/** /**
@ -235,7 +275,8 @@ class InvoiceLogic
* @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,7 +291,8 @@ 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();
@ -263,7 +305,32 @@ class InvoiceLogic
$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'];
@ -324,7 +391,8 @@ class InvoiceLogic
* @param $param * @param $param
* @return Invoice * @return Invoice
*/ */
public function update($param) public
function update($param)
{ {
return Invoice::update($param); return Invoice::update($param);
} }
@ -335,7 +403,8 @@ class InvoiceLogic
* @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,7 +419,8 @@ 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) {
@ -368,7 +438,8 @@ 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]);
} }
@ -379,7 +450,8 @@ class InvoiceLogic
* @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,7 +465,8 @@ 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'];
@ -406,7 +479,8 @@ class InvoiceLogic
* @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',
@ -442,7 +517,8 @@ class InvoiceLogic
* @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,6 +553,34 @@ 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) {

@ -25,7 +25,7 @@ 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]
@ -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)) {
@ -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,6 +290,10 @@ 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;
@ -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;
} }
@ -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']) : [];
@ -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']);
unset($request['order_type']);
unset($request['is_excel']);
$request = $this->fmtRequest( $request ); $request = $this->fmtRequest($request);
$map = $request['map'] ? : []; $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'])) {
@ -103,41 +122,171 @@ class ReceivablesPlan extends Common
} }
} }
$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
@ -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;
@ -424,73 +586,89 @@ 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