From 226efc26cdce0caed7b3786941893b808e0e0b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=90=8C?= <494089941@qq.com> Date: Fri, 24 Mar 2023 16:46:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=B1=BB=E5=9E=8B=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/model/Field.php | 135 ++-- application/crm/model/Customer.php | 1150 ++++++++++++++-------------- 2 files changed, 647 insertions(+), 638 deletions(-) diff --git a/application/admin/model/Field.php b/application/admin/model/Field.php index 120b90e..931f663 100644 --- a/application/admin/model/Field.php +++ b/application/admin/model/Field.php @@ -390,10 +390,10 @@ class Field extends Model if ($v['form_type'] == 'checkbox') { $list[$k]['default_value'] = $v['default_value'] ? explode(',', $v['default_value']) : array(); } - if ($v['form_type']=='date_interval') { - $list[$k]['default_value'] = !empty($v['default_value']) ? explode(',',$v['default_value']) : []; + if ($v['form_type'] == 'date_interval') { + $list[$k]['default_value'] = !empty($v['default_value']) ? explode(',', $v['default_value']) : []; } - if($v['form_type']=='position'){ + if ($v['form_type'] == 'position') { $list[$k]['default_value'] = !empty($v['default_value']) ? json_decode($v['default_value'], true) : []; } if ($v['form_type'] == 'detail_table') { @@ -485,7 +485,10 @@ class Field extends Model } //生成字段名 - if (!$data['field']) $data['field'] = $this->createField($types, $types == 'oa_examine' ? 'oa_' : 'crm_'); + if (!empty($param['field'])) { + $data['field'] = $param['field']; + } else if (!$data['field']) $data['field'] = $this->createField($types, $types == 'oa_examine' ? 'oa_' : 'crm_'); + $rule = [ 'field' => ['regex' => '/^[a-z]([a-z]|_)+[a-z]$/i'], @@ -713,8 +716,8 @@ class Field extends Model $new_default_value[] = str_replace(',', ',', $v); } $data['default_value'] = implode(',', $new_default_value); - }elseif($data['default_value'] && $data['form_type'] == 'select' && !empty($data['default_value'])){ - $data['default_value'] = $data['default_value']; + } elseif ($data['default_value'] && $data['form_type'] == 'select' && !empty($data['default_value'])) { + $data['default_value'] = $data['default_value']; } else { $data['default_value'] = ''; } @@ -760,12 +763,12 @@ class Field extends Model // 数值范围 if (!empty($data['minNumRestrict'])) { $data['min_num_restrict'] = $data['minNumRestrict']; - }else{ - $data['min_num_restrict']=''; + } else { + $data['min_num_restrict'] = ''; } - if (!empty($data['maxNumRestrict'])){ + if (!empty($data['maxNumRestrict'])) { $data['max_num_restrict'] = $data['maxNumRestrict']; - }else{ + } else { $data['max_num_restrict'] = ''; } // 清除坐标 @@ -978,7 +981,7 @@ class Field extends Model if (!$resData) { $delMessage[] = $dataInfo['name'] . ',删除失败'; } - + //删除列表字段配置数据 $userFieldList = db('admin_user_field')->where(['types' => $dataInfo['types']])->select(); foreach ($userFieldList as $key => $val) { @@ -1125,8 +1128,8 @@ class Field extends Model 'fieldName' => 'owner_user_structure_name' ]; foreach ($field_list as $k => $v) { - if($v['field']=='invoice_type'){ - $field_list[$k]['setting']=$v['setting']?explode(chr(10), $v['setting']):[]; + if ($v['field'] == 'invoice_type') { + $field_list[$k]['setting'] = $v['setting'] ? explode(chr(10), $v['setting']) : []; } # 处理字段授权 $field_list[$k]['writeStatus'] = 1; @@ -1254,7 +1257,7 @@ class Field extends Model foreach ($field_list as $k => $v) { # 处理字段授权 $field_list[$k]['writeStatus'] = 1; - if($field_list[$k]['name'] == '客户级别' && !in_array(1,$adminTypes)) $field_list[$k]['writeStatus'] = 0; + if ($field_list[$k]['name'] == '客户级别' && !in_array(1, $adminTypes)) $field_list[$k]['writeStatus'] = 0; if (!$userLevel && $param['module'] == 'crm' && !empty($grantData[$param['types']])) { $status = getFieldGrantStatus($v['field'], $grantData[$param['types']]); @@ -1271,7 +1274,7 @@ class Field extends Model } if ($param['action'] == 'read') { $field_list[$k]['maskType'] = $status['maskType']; - if($status['maskType']!=0){ + if ($status['maskType'] != 0) { $field_list[$k]['writeStatus'] = 0; } } @@ -1469,32 +1472,32 @@ class Field extends Model } elseif ($v['form_type'] == 'desc_text') { // 描述文字 $value = !empty($dataInfo[$v['field']]) ? $dataInfo[$v['field']] : $v['default_value']; - } elseif ($v['form_type']=='location') { + } elseif ($v['form_type'] == 'location') { // 地址、定位、日期区间、明细表格 $primaryKey = getPrimaryKeyName($param['types']); $positionJson = !empty($dataInfo[$primaryKey]) ? db($param['types'] . '_data')->where([$primaryKey => $dataInfo[$primaryKey], 'field' => $v['field']])->value($param['types'] == 'oa_examine' ? 'value' : 'content') : ''; $positionData = !empty($positionJson) ? json_decode($positionJson, true) : ''; $value = $positionData; - } elseif($v['form_type']=='detail_table'){ + } elseif ($v['form_type'] == 'detail_table') { // $fieldGrant = db('admin_field_mask')->where('types', 'contract')->select(); $primaryKey = getPrimaryKeyName($param['types']); $positionJson = !empty($dataInfo[$primaryKey]) ? db($param['types'] . '_data')->where([$primaryKey => $dataInfo[$primaryKey], 'field' => $v['field']])->value($param['types'] == 'oa_examine' ? 'value' : 'content') : ''; $positionData = !empty($positionJson) ? json_decode($positionJson, true) : ''; - foreach ($positionData as $kk => $val){ - foreach ($val as $key => $values){ - if($values['form_type']=='user'){ - $positionData[$kk][$key]['value']= !empty($values['value'])?$userModel->getListByStr($values['value']) :[]; + foreach ($positionData as $kk => $val) { + foreach ($val as $key => $values) { + if ($values['form_type'] == 'user') { + $positionData[$kk][$key]['value'] = !empty($values['value']) ? $userModel->getListByStr($values['value']) : []; } - if($values['form_type']=='structure'){ - $positionData[$kk][$key]['value']= !empty($values['value'])? $structureModel->getListByStr($values['value']) : []; + if ($values['form_type'] == 'structure') { + $positionData[$kk][$key]['value'] = !empty($values['value']) ? $structureModel->getListByStr($values['value']) : []; } - if($values['form_type']=='datetime' && is_numeric($values['value'])){ - $positionData[$kk][$key]['value']= date('Y-m-d, H:i:s',$values['value']); + if ($values['form_type'] == 'datetime' && is_numeric($values['value'])) { + $positionData[$kk][$key]['value'] = date('Y-m-d, H:i:s', $values['value']); } - if($values['form_type']=='boolean_value'){ - $positionData[$kk][$key]['value']= (string)$values['value']; + if ($values['form_type'] == 'boolean_value') { + $positionData[$kk][$key]['value'] = (string)$values['value']; } - if($values['form_type']=='file'){ + if ($values['form_type'] == 'file') { $fileIds = stringToArray($values['value']); $whereFile = []; $whereFile['module'] = 'other'; @@ -1514,36 +1517,36 @@ class Field extends Model // $positionData[$kk][$key]['value'] = !empty($dataInfo[$val['fiele_id']]) ? (string)substr_replace($values['value'], '*',0,strlen($values['value'])) : null; // } // } - $positionData[$kk][$key]['optionsData']=!empty($field_list[$k]['options']) ? json_decode($field_list[$k]['options'], true) : ''; + $positionData[$kk][$key]['optionsData'] = !empty($field_list[$k]['options']) ? json_decode($field_list[$k]['options'], true) : ''; } } $value = $positionData; if ($v['form_type'] == 'detail_table') { $content = db('admin_field_extend')->where(['types' => $types, 'field' => $v['field']])->value('content'); - $content=json_decode($content, true); - foreach ($content as &$vv){ - $vv['optionsData']=!empty($field_list[$k]['options']) ? json_decode($field_list[$k]['options'], true) : ''; + $content = json_decode($content, true); + foreach ($content as &$vv) { + $vv['optionsData'] = !empty($field_list[$k]['options']) ? json_decode($field_list[$k]['options'], true) : ''; } $field_list[$k]['fieldExtendList'] = $content; } - } elseif($v['form_type']=='position'){ + } elseif ($v['form_type'] == 'position') { // 地址 $default_value = !empty($v['default_value']) ? json_decode($v['default_value'], true) : []; - if(!empty($dataInfo[$v['field']])){ - $position= explode(',',$dataInfo[$v['field']]); - for ($i=0; $i $v) { if (!$userLevel && !empty($grantData[$types])) { $status = getFieldGrantStatus($v['field'], $grantData[$types]); - $dataList[(int)$k]['maskType']=$status['maskType']; + $dataList[(int)$k]['maskType'] = $status['maskType']; # 查看权限 if ($status['read'] == 0) unset($dataList[(int)$k]); } @@ -1861,7 +1864,7 @@ class Field extends Model } $fieldArr = $this ->where($where) - ->field(['field', 'name', 'form_type', 'is_hidden','setting']) + ->field(['field', 'name', 'form_type', 'is_hidden', 'setting']) ->order('order_id', 'asc') ->select(); @@ -1876,7 +1879,7 @@ class Field extends Model } if (isset($this->orther_field_list[$newTypes])) { foreach ($this->orther_field_list[$newTypes] as $val) { - if($val['field'] != 'product_picture'){ + if ($val['field'] != 'product_picture') { $res[] = $val; } } @@ -1918,8 +1921,8 @@ class Field extends Model if ($types == 'jxc_product') { $res[] = [ - 'field' => 'product_picture', - 'name' => '产品图片', + 'field' => 'product_picture', + 'name' => '产品图片', 'form_type' => 'pic', 'is_hidden' => 0 ]; @@ -2231,7 +2234,7 @@ class Field extends Model if ($types == 'jxc_product') { $where['is_del'] = 0; } - + $res = $dataModel->where($where)->find(); if ($res) { @@ -2342,35 +2345,35 @@ class Field extends Model $val = db('jxc_purchase')->where(['purchase_id' => $val])->value('order_number'); break; case 'order_cause' : - if($dataInfo['receipt_type'] == '销售退货入库'){ + if ($dataInfo['receipt_type'] == '销售退货入库') { $val = db('jxc_salereturn')->where(['salereturn_id' => $val])->value('order_number'); - }elseif ($dataInfo['receipt_type'] == '采购入库') { + } elseif ($dataInfo['receipt_type'] == '采购入库') { $val = db('jxc_purchase')->where(['purchase_id' => $val])->value('order_number'); - }elseif ($dataInfo['outbound_type'] == '销售出库') { + } elseif ($dataInfo['outbound_type'] == '销售出库') { $val = db('jxc_sale')->where(['sale_id' => $val])->value('order_number'); - }elseif ($dataInfo['outbound_type'] == '采购退货出库') { + } elseif ($dataInfo['outbound_type'] == '采购退货出库') { $val = db('jxc_retreat')->where(['retreat_id' => $val])->value('order_number'); } - break; + break; case 'category_cause' : $val = db('jxc_product_category')->where(['category_id' => $val])->value('category_name'); - break; + break; case 'product_cause' : $val = db('jxc_product')->where(['product_id' => $val])->value('product_name'); - break; + break; case 'collection_object' : - if($dataInfo['collection_type'] == '采购退货'){ + if ($dataInfo['collection_type'] == '采购退货') { // $val = db('jxc_supplier')->where(['supplier_id' => $val])->value('supplier_name'); - }elseif ($dataInfo['collection_type'] == '销售出库') { + } elseif ($dataInfo['collection_type'] == '销售出库') { $val = db('jxc_sale')->where(['sale_id' => $val])->value('order_number'); - }elseif ($dataInfo['payment_type'] == '采购') { + } elseif ($dataInfo['payment_type'] == '采购') { $val = db('crm_customer')->where(['customer_id' => $val])->value('name'); - }elseif ($dataInfo['payment_type'] == '销售退货') { + } elseif ($dataInfo['payment_type'] == '销售退货') { $val = db('jxc_salereturn')->where(['salereturn_id' => $val])->value('order_number'); } - + break; - + } return $val; } @@ -2416,13 +2419,13 @@ class Field extends Model } if (!$data) return $data; $list = db('admin_field')->where(['types' => $types, 'relevant' => ['neq', '']])->field('field,relevant')->select(); - foreach ($list as &$val){ - $val=!empty($val)?$val:''; - } + foreach ($list as &$val) { + $val = !empty($val) ? $val : ''; + } $newData = []; //crm_hfsomz foreach ($list as $k => $v) { - $customer_field=db('admin_field')->where(['types' => 'crm_customer', 'field_id' => $v['relevant']])->field('field')->find(); + $customer_field = db('admin_field')->where(['types' => 'crm_customer', 'field_id' => $v['relevant']])->field('field')->find(); $newData[$customer_field['field']] = $data[$v['field']]; } return $newData ?: []; @@ -2670,7 +2673,7 @@ class Field extends Model */ public function getFieldTypesArray($types, $form_type) { - $fieldArr = db('admin_field')->where(['types' => $types, 'form_type' => ['in', $form_type]])->field(['field','name', 'form_type'])->select(); + $fieldArr = db('admin_field')->where(['types' => $types, 'form_type' => ['in', $form_type]])->field(['field', 'name', 'form_type'])->select(); $fieldList = []; $userField = []; // 人员类型 $structureField = []; // 部门类型 diff --git a/application/crm/model/Customer.php b/application/crm/model/Customer.php index 72e652b..ce3c7a1 100644 --- a/application/crm/model/Customer.php +++ b/application/crm/model/Customer.php @@ -17,59 +17,59 @@ class Customer extends Common { use FieldVerificationTrait; - /** + /** * 为了数据库的整洁,同时又不影响Model和Controller的名称 * 我们约定每个模块的数据表都加上相同的前缀,比如CRM模块用crm作为数据表前缀 */ - protected $name = 'crm_customer'; + protected $name = 'crm_customer'; protected $createTime = 'create_time'; protected $updateTime = 'update_time'; - protected $autoWriteTimestamp = true; + protected $autoWriteTimestamp = true; - protected $type = [ - // 'next_time' => 'timestamp', - ]; + protected $type = [ + // 'next_time' => 'timestamp', + ]; - public static $address = [ - '北京', '上海', '天津', '广东', '浙江', '海南', '福建', '湖南', - '湖北', '重庆', '辽宁', '吉林', '黑龙江', '河北', '河南', '山东', - '陕西', '甘肃', '青海', '新疆', '山西', '四川', '贵州', '安徽', - '江西', '江苏', '云南', '内蒙古', '广西', '西藏', '宁夏' - ]; + public static $address = [ + '北京', '上海', '天津', '广东', '浙江', '海南', '福建', '湖南', + '湖北', '重庆', '辽宁', '吉林', '黑龙江', '河北', '河南', '山东', + '陕西', '甘肃', '青海', '新疆', '山西', '四川', '贵州', '安徽', + '江西', '江苏', '云南', '内蒙古', '广西', '西藏', '宁夏' + ]; - /** + /** * [getDataList 客户list] - * @author Michael_xu * @param [string] $map [查询条件] * @param [number] $page [当前页数] * @param [number] $limit [每页数量] * @return [array] [description] - */ - public function getDataList($request) + * @author Michael_xu + */ + public function getDataList($request) { - $userModel = new \app\admin\model\User(); - $fieldModel = new \app\admin\model\Field(); - $search = $request['search']; - $user_id = $request['user_id']; - $scene_id = (int)$request['scene_id']; - $is_excel = $request['is_excel']; //导出 - $order_field = $request['order_field']; - $order_type = $request['order_type']; - $is_remind = $request['is_remind']; - $getCount = $request['getCount']; - $otherMap = $request['otherMap']; + $userModel = new \app\admin\model\User(); + $fieldModel = new \app\admin\model\Field(); + $search = $request['search']; + $user_id = $request['user_id']; + $scene_id = (int)$request['scene_id']; + $is_excel = $request['is_excel']; //导出 + $order_field = $request['order_field']; + $order_type = $request['order_type']; + $is_remind = $request['is_remind']; + $getCount = $request['getCount']; + $otherMap = $request['otherMap']; $overdue = $request['overdue']; // 待办事项下需联系客户(逾期) - # 需要过滤的参数 - $unsetRequest = ['scene_id','search','user_id','is_excel','action','order_field','order_type','is_remind','getCount','type','otherMap','poolId','overdue']; - foreach ($unsetRequest as $v) { - unset($request[$v]); - } - - # 格式化参数 - $request = $this->fmtRequest( $request ); - $requestMap = $request['map'] ? : []; - $sceneModel = new \app\admin\model\Scene(); - # 客户默认条件 + # 需要过滤的参数 + $unsetRequest = ['scene_id', 'search', 'user_id', 'is_excel', 'action', 'order_field', 'order_type', 'is_remind', 'getCount', 'type', 'otherMap', 'poolId', 'overdue']; + foreach ($unsetRequest as $v) { + unset($request[$v]); + } + + # 格式化参数 + $request = $this->fmtRequest($request); + $requestMap = $request['map'] ?: []; + $sceneModel = new \app\admin\model\Scene(); + # 客户默认条件 $customerMap = $this->getWhereByCustomer(); # getCount是代办事项传来的参数,代办事项不需要使用场景 @@ -77,87 +77,93 @@ class Customer extends Common if (empty($getCount)) { if ($scene_id) { //自定义场景 - $sceneMap = $sceneModel->getDataById($scene_id, $user_id, 'customer') ? : []; + $sceneMap = $sceneModel->getDataById($scene_id, $user_id, 'customer') ?: []; } else { //默认场景 - $sceneMap = $sceneModel->getDefaultData('crm_customer', $user_id) ? : []; + $sceneMap = $sceneModel->getDefaultData('crm_customer', $user_id) ?: []; } } # 普通筛选 - $searchMap = []; - if ($search || $search == '0') { - $searchMap = function($query) use ($search){ - $query->where('customer.name',array('like','%'.$search.'%')) - ->whereOr('customer.mobile',array('like','%'.$search.'%')) - ->whereOr('customer.telephone',array('like','%'.$search.'%')); - }; - } - - # 优先级:普通筛选 > 高级筛选 > 场景 + $searchMap = []; + if ($search || $search == '0') { + $searchMap = function ($query) use ($search) { + $query->where('customer.name', array('like', '%' . $search . '%')) + ->whereOr('customer.mobile', array('like', '%' . $search . '%')) + ->whereOr('customer.telephone', array('like', '%' . $search . '%')); + }; + } + + # 优先级:普通筛选 > 高级筛选 > 场景 $map = []; $partMap = []; - $teamMap=$requestMap['team_id']; + $teamMap = $requestMap['team_id']; //团队成员 高级筛选 - if($teamMap){ - $partMap= advancedQueryFormatForTeam($teamMap,'customer',''); + if ($teamMap) { + $partMap = advancedQueryFormatForTeam($teamMap, 'customer', ''); unset($requestMap['team_id']); $map = $requestMap ? array_merge($sceneMap, $requestMap) : $sceneMap; - }else{ + } else { $map = $requestMap ? array_merge($sceneMap, $requestMap) : $sceneMap; - + } - - # 高级筛选 - $map = advancedQuery($map, 'crm', 'customer', 'index'); - + + # 高级筛选 + $map = advancedQuery($map, 'crm', 'customer', 'index'); + # 工作台仪表盘 $requestData = $this->requestData(); $dashboardWhere = []; if ($requestData['a'] == 'indexlist' && $requestData['c'] == 'index') { $dashboardWhere = function ($query) use ($requestMap) { - $query->where('customer.create_time', array('between', [$requestMap['create_time']['start'],$requestMap['create_time']['end']])) - ->whereOr('customer.obtain_time', array('between', [$requestMap['create_time']['start'],$requestMap['create_time']['end']])); + $query->where('customer.create_time', array('between', [$requestMap['create_time']['start'], $requestMap['create_time']['end']])) + ->whereOr('customer.obtain_time', array('between', [$requestMap['create_time']['start'], $requestMap['create_time']['end']])); }; unset($map['customer.create_time']); } # 权限 $authMap = []; - $a = 'index'; - if ($is_excel) $a = 'excelExport'; - $auth_user_ids = $userModel->getUserByPer('crm', 'customer', $a); - //过滤权限 - if (isset($map['customer.owner_user_id']) ) { - if (!is_array($map['customer.owner_user_id'][1])) { - $map['customer.owner_user_id'][1] = [$map['customer.owner_user_id'][1]]; - } - if (in_array($map['customer.owner_user_id'][0], ['neq', 'notin'])) { - $auth_user_ids = array_diff($auth_user_ids, $map['customer.owner_user_id'][1]) ? : []; //取差集 - } else { - $auth_user_ids = array_intersect($map['customer.owner_user_id'][1], $auth_user_ids) ? : []; //取交集 - } - unset($map['customer.owner_user_id']); - $auth_user_ids = array_merge(array_unique(array_filter($auth_user_ids))) ? : ['-1']; - //负责人、相关团队 - $authMap['customer.owner_user_id'] = array('in',$auth_user_ids); + $a = 'index'; + if ($is_excel) $a = 'excelExport'; + $auth_user_ids = $userModel->getUserByPer('crm', 'customer', $a); + //过滤权限 + if (isset($map['customer.owner_user_id'])) { + if (!is_array($map['customer.owner_user_id'][1])) { + $map['customer.owner_user_id'][1] = [$map['customer.owner_user_id'][1]]; + } + if (in_array($map['customer.owner_user_id'][0], ['neq', 'notin'])) { + $auth_user_ids = array_diff($auth_user_ids, $map['customer.owner_user_id'][1]) ?: []; //取差集 } else { - $authMapData = []; - $authMapData['auth_user_ids'] = $auth_user_ids; - $authMapData['user_id'] = $user_id; - $authMap = function($query) use ($authMapData){ - $query->where(['customer.owner_user_id' => array('in',$authMapData['auth_user_ids'])]) - ->whereOr(function ($query) use ($authMapData) { - $query->where('FIND_IN_SET("'.$authMapData['user_id'].'", customer.ro_user_id)')->where(['customer.owner_user_id' => array('neq','')]); - }) - ->whereOr(function ($query) use ($authMapData) { - $query->where('FIND_IN_SET("'.$authMapData['user_id'].'", customer.rw_user_id)')->where(['customer.owner_user_id' => array('neq','')]); - }); - }; + $auth_user_ids = array_intersect($map['customer.owner_user_id'][1], $auth_user_ids) ?: []; //取交集 } + unset($map['customer.owner_user_id']); + $auth_user_ids = array_merge(array_unique(array_filter($auth_user_ids))) ?: ['-1']; + //负责人、相关团队 + $authMap['customer.owner_user_id'] = array('in', $auth_user_ids); + } else { + $authMapData = []; + $authMapData['auth_user_ids'] = $auth_user_ids; + $authMapData['user_id'] = $user_id; + $authMap = function ($query) use ($authMapData) { + $query->where(['customer.owner_user_id' => array('in', $authMapData['auth_user_ids'])]) + ->whereOr(function ($query) use ($authMapData) { + $query->where('FIND_IN_SET("' . $authMapData['user_id'] . '", customer.ro_user_id)')->where(['customer.owner_user_id' => array('neq', '')]); + }) + ->whereOr(function ($query) use ($authMapData) { + $query->where('FIND_IN_SET("' . $authMapData['user_id'] . '", customer.rw_user_id)')->where(['customer.owner_user_id' => array('neq', '')]); + }); + }; + } + // 过滤角色 + $groupIds = db('admin_access')->where("user_id", array("eq", $user_id))->column("group_id"); + if (!in_array(1,$groupIds)){ + $groupNameArray = db('admin_group')->where("pid", array("eq", 2))->where("id", array("in", $groupIds))->column("title"); + if ($groupNameArray) - + $map['customer.crm_role'] = array('in', $groupNameArray); + } # 代办事项 - 待进入公海 $remindWhere = []; if ($is_remind) { @@ -175,105 +181,105 @@ class Customer extends Common // 待办事项下需联系客户(逾期) $overdueWhere = ''; if (!empty($overdue)) { - $overdueWhere = "(FROM_UNIXTIME(`customer`.`last_time`,'%Y-%m-%d') < FROM_UNIXTIME(`customer`.`next_time`,'%Y-%m-%d') OR (ISNULL(`customer`.`last_time`) AND `customer`.`next_time` < ".time()."))"; + $overdueWhere = "(FROM_UNIXTIME(`customer`.`last_time`,'%Y-%m-%d') < FROM_UNIXTIME(`customer`.`next_time`,'%Y-%m-%d') OR (ISNULL(`customer`.`last_time`) AND `customer`.`next_time` < " . time() . "))"; } - $dataCount = db('crm_customer')->alias('customer') - ->where($map) - ->where($dashboardWhere) - ->where($searchMap) - ->where($customerMap) - ->where($authMap) - ->where($partMap) - ->where($otherMap) - ->where($remindWhere) - ->where($overdueWhere) - ->count(); + $dataCount = db('crm_customer')->alias('customer') + ->where($map) + ->where($dashboardWhere) + ->where($searchMap) + ->where($customerMap) + ->where($authMap) + ->where($partMap) + ->where($otherMap) + ->where($remindWhere) + ->where($overdueWhere) + ->count(); if ($getCount == 1) { - $data['dataCount'] = $dataCount ? : 0; - return $data; + $data['dataCount'] = $dataCount ?: 0; + return $data; } - $indexField = $fieldModel->getIndexField('crm_customer', $user_id, 1) ? : array('name'); // 列表展示字段 - $userField = $fieldModel->getFieldByFormType('crm_customer', 'user'); // 人员类型 - $structureField = $fieldModel->getFieldByFormType('crm_customer', 'structure'); // 部门类型 + $indexField = $fieldModel->getIndexField('crm_customer', $user_id, 1) ?: array('name'); // 列表展示字段 + $userField = $fieldModel->getFieldByFormType('crm_customer', 'user'); // 人员类型 + $structureField = $fieldModel->getFieldByFormType('crm_customer', 'structure'); // 部门类型 # 处理人员和部门类型的排序报错问题(前端传来的是包含_name的别名字段) $temporaryField = str_replace('_name', '', $order_field); if (in_array($temporaryField, $userField) || in_array($temporaryField, $structureField)) { $order_field = $temporaryField; } - # 排序 - if ($order_type && $order_field && $order_field != 'owner_user_structure_name') { - $order = $fieldModel->getOrderByFormtype('crm_customer','customer',$order_field,$order_type); - } else { - $order = 'customer.update_time desc'; - } - - $list = db('crm_customer')->alias('customer') - ->where($map) - ->where($dashboardWhere) - ->where($searchMap) - ->where($customerMap) - ->where($authMap) - ->where($partMap) - ->where($otherMap) - ->where($remindWhere) - ->where($overdueWhere) - ->limit($request['offset'], $request['length']) - ->field($indexField) - ->orderRaw($order) - ->select(); + # 排序 + if ($order_type && $order_field && $order_field != 'owner_user_structure_name') { + $order = $fieldModel->getOrderByFormtype('crm_customer', 'customer', $order_field, $order_type); + } else { + $order = 'customer.update_time desc'; + } + + $list = db('crm_customer')->alias('customer') + ->where($map) + ->where($dashboardWhere) + ->where($searchMap) + ->where($customerMap) + ->where($authMap) + ->where($partMap) + ->where($otherMap) + ->where($remindWhere) + ->where($overdueWhere) + ->limit($request['offset'], $request['length']) + ->field($indexField) + ->orderRaw($order) + ->select(); $readAuthIds = $userModel->getUserByPer('crm', 'customer', 'read'); $updateAuthIds = $userModel->getUserByPer('crm', 'customer', 'update'); - $deleteAuthIds = $userModel->getUserByPer('crm', 'customer', 'delete'); + $deleteAuthIds = $userModel->getUserByPer('crm', 'customer', 'delete'); if (!empty($list)) { - $customer_id_list = array_column($list, 'customer_id'); - $business_count = db('crm_business') - ->field([ - 'COUNT(*)' => 'count', - 'customer_id' - ]) - ->where([ - 'customer_id' => ['IN', $customer_id_list] - ]) - ->group('customer_id') - ->select(); - - $business_count = array_column($business_count, null, 'customer_id'); - $field_list = $fieldModel->getIndexFieldConfig('crm_customer', $user_id); - $field_list = array_column($field_list, 'field'); + $customer_id_list = array_column($list, 'customer_id'); + $business_count = db('crm_business') + ->field([ + 'COUNT(*)' => 'count', + 'customer_id' + ]) + ->where([ + 'customer_id' => ['IN', $customer_id_list] + ]) + ->group('customer_id') + ->select(); + + $business_count = array_column($business_count, null, 'customer_id'); + $field_list = $fieldModel->getIndexFieldConfig('crm_customer', $user_id); + $field_list = array_column($field_list, 'field'); # 获取进入公海天数 $poolDays = $this->getPoolDay($customer_id_list); # 处理数据 - $list=getFieldData($list,'crm_customer',$user_id); + $list = getFieldData($list, 'crm_customer', $user_id); # 整理数据 - 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'] : ''; - - - # 商机数 - $list[$k]['business_count'] = $business_count[$v['customer_id']]['count'] ?: 0; - # 权限 - $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; + 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'] : ''; + + + # 商机数 + $list[$k]['business_count'] = $business_count[$v['customer_id']]['count'] ?: 0; + # 权限 + $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; # 关注 $starWhere = ['user_id' => $user_id, 'target_id' => $v['customer_id'], 'type' => 'crm_customer']; @@ -283,7 +289,7 @@ class Customer extends Common # 日期 $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]['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; # 进入公海天数 $list[$k]['pool_day'] = isset($poolDays[$v['customer_id']]) ? $poolDays[$v['customer_id']] : ''; @@ -291,79 +297,79 @@ class Customer extends Common # 系统字段 负责人部门 zjf 20210726 $list[$k]['owner_user_structure_name'] = $list[$k]['owner_user_id_info']['structure_name']; - } + } } $data = []; - $data['list'] = $list ? : []; - $data['dataCount'] = $dataCount ? : 0; + $data['list'] = $list ?: []; + $data['dataCount'] = $dataCount ?: 0; return $data; } - /** - * 创建客户主表信息 - * @author Michael_xu - * @param - * @return - */ - public function createData($param) - { + /** + * 创建客户主表信息 + * @param + * @return + * @author Michael_xu + */ + public function createData($param) + { unset($param['excel']); - // 客户扩展表数据 - $customerData = []; + // 客户扩展表数据 + $customerData = []; - $userId = $param['user_id']; + $userId = $param['user_id']; - $fieldModel = new \app\admin\model\Field(); - $customerConfigModel = new \app\crm\model\CustomerConfig(); + $fieldModel = new \app\admin\model\Field(); + $customerConfigModel = new \app\crm\model\CustomerConfig(); - // 添加上限检测 - if (!$customerConfigModel->checkData($param['create_user_id'],1)) { - $this->error = $customerConfigModel->getError(); - return false; - } + // 添加上限检测 + if (!$customerConfigModel->checkData($param['create_user_id'], 1)) { + $this->error = $customerConfigModel->getError(); + return false; + } - // 获取客户时间 + // 获取客户时间 $param['obtain_time'] = time(); - // 地址 - $param['address'] = $param['address'] ? implode(chr(10),$param['address']) : ''; - $param['deal_time'] = time(); //领取、分配时间 - $param['deal_status'] = '未成交'; - - // 线索转客户 - if ($param['leads_id']) { - $leadsData = $param; - $leadsData['create_user_id'] = $param['create_user_id']; - $leadsData['owner_user_id'] = $param['owner_user_id']; - $leadsData['ro_user_id'] = ''; - $leadsData['rw_user_id'] = ''; - $leadsData['detail_address'] = $param['detail_address'] ? : ''; - - $param = $leadsData; - } + // 地址 + $param['address'] = $param['address'] ? implode(chr(10), $param['address']) : ''; + $param['deal_time'] = time(); //领取、分配时间 + $param['deal_status'] = '未成交'; + + // 线索转客户 + if ($param['leads_id']) { + $leadsData = $param; + $leadsData['create_user_id'] = $param['create_user_id']; + $leadsData['owner_user_id'] = $param['owner_user_id']; + $leadsData['ro_user_id'] = ''; + $leadsData['rw_user_id'] = ''; + $leadsData['detail_address'] = $param['detail_address'] ?: ''; + + $param = $leadsData; + } - // 数据验证 + // 数据验证 $validateResult = $this->fieldDataValidate($param, 'crm_customer', $userId); - if (!empty($validateResult)) { - $this->error = $validateResult; - return false; + if (!empty($validateResult)) { + $this->error = $validateResult; + return false; } // 删除无效数据 - unset($param['user_id']); + unset($param['user_id']); unset($param['customer_id']); - // 处理部门、员工、附件、多选类型字段 - $arrFieldAtt = $fieldModel->getArrayField('crm_customer'); - foreach ($arrFieldAtt as $k=>$v) { - $param[$v] = arrayToString($param[$v]); - } + // 处理部门、员工、附件、多选类型字段 + $arrFieldAtt = $fieldModel->getArrayField('crm_customer'); + foreach ($arrFieldAtt as $k => $v) { + $param[$v] = arrayToString($param[$v]); + } // 处理日期(date)类型 $dateField = $fieldModel->getFieldByFormType('crm_customer', 'date'); if (!empty($dateField)) { - foreach ($param AS $key => $value) { + foreach ($param as $key => $value) { if (in_array($key, $dateField) && empty($value)) $param[$key] = null; } } @@ -371,7 +377,7 @@ class Customer extends Common // 处理手写签名类型 $handwritingField = $fieldModel->getFieldByFormType('crm_customer', 'handwriting_sign'); if (!empty($handwritingField)) { - foreach ($param AS $key => $value) { + foreach ($param as $key => $value) { if (in_array($key, $handwritingField)) { $param[$key] = !empty($value['file_id']) ? $value['file_id'] : ''; } @@ -379,25 +385,25 @@ class Customer extends Common } // 处理地址、定位、日期区间、明细表格类型字段 - $positionField = $fieldModel->getFieldByFormType('crm_customer', 'position'); - $locationField = $fieldModel->getFieldByFormType('crm_customer', 'location'); + $positionField = $fieldModel->getFieldByFormType('crm_customer', 'position'); + $locationField = $fieldModel->getFieldByFormType('crm_customer', 'location'); $dateIntervalField = $fieldModel->getFieldByFormType('crm_customer', 'date_interval'); - $detailTableField = $fieldModel->getFieldByFormType('crm_customer', 'detail_table'); - $dateField = $fieldModel->getFieldByFormType('crm_customer', 'date'); - foreach ($param AS $key => $value) { + $detailTableField = $fieldModel->getFieldByFormType('crm_customer', 'detail_table'); + $dateField = $fieldModel->getFieldByFormType('crm_customer', 'date'); + foreach ($param as $key => $value) { // 处理地址类型字段数据 if (in_array($key, $positionField)) { if (!empty($value) && is_array($value)) { $customerData[] = [ - 'field' => $key, - 'content' => json_encode($value, JSON_NUMERIC_CHECK), + 'field' => $key, + 'content' => json_encode($value, JSON_NUMERIC_CHECK), 'create_time' => time() ]; $positionNames = array_column($value, 'name'); $param[$key] = implode(',', $positionNames); - } elseif(!empty($value) && !is_array($value)){ + } elseif (!empty($value) && !is_array($value)) { $param[$key] = $value; - }else{ + } else { $param[$key] = ''; } } @@ -405,20 +411,20 @@ class Customer extends Common if (in_array($key, $locationField)) { if (!empty($value) && isset($value['address'])) { $customerData[] = [ - 'field' => $key, - 'content' => json_encode($value, JSON_NUMERIC_CHECK), + 'field' => $key, + 'content' => json_encode($value, JSON_NUMERIC_CHECK), 'create_time' => time() ]; $param[$key] = $value['address']; - } elseif(!empty($value) && !isset($value['address'])){ - $vv['address']=$value; + } elseif (!empty($value) && !isset($value['address'])) { + $vv['address'] = $value; $customerData[] = [ - 'field' => $key, - 'content' => json_encode($vv, JSON_NUMERIC_CHECK), + 'field' => $key, + 'content' => json_encode($vv, JSON_NUMERIC_CHECK), 'create_time' => time() ]; $param[$key] = $value; - } else{ + } else { $param[$key] = ''; } } @@ -426,14 +432,14 @@ class Customer extends Common if (in_array($key, $dateIntervalField)) { if (!empty($value) && is_array($value)) { $customerData[] = [ - 'field' => $key, - 'content' => json_encode($value, JSON_NUMERIC_CHECK), + 'field' => $key, + 'content' => json_encode($value, JSON_NUMERIC_CHECK), 'create_time' => time() ]; - $param[$key] = trim(implode('_', $value),'"'); - } elseif(!empty($value) && !is_array($value)){ + $param[$key] = trim(implode('_', $value), '"'); + } elseif (!empty($value) && !is_array($value)) { $param[$key] = $value; - }else{ + } else { $param[$key] = ''; } } @@ -441,8 +447,8 @@ class Customer extends Common if (in_array($key, $detailTableField)) { if (!empty($value)) { $customerData[] = [ - 'field' => $key, - 'content' => json_encode($value, JSON_NUMERIC_CHECK), + 'field' => $key, + 'content' => json_encode($value, JSON_NUMERIC_CHECK), 'create_time' => time() ]; $param[$key] = $key; @@ -450,16 +456,16 @@ class Customer extends Common $param[$key] = ''; } } - $param[$key]=!empty($value)?trim($value,','):''; + $param[$key] = !empty($value) ? trim($value, ',') : ''; if (in_array($key, $dateField)) { - if (!empty($value) ) { + if (!empty($value)) { $customerData[] = [ - 'field' => $key, - 'content' => json_encode($value, JSON_NUMERIC_CHECK), + 'field' => $key, + 'content' => json_encode($value, JSON_NUMERIC_CHECK), 'create_time' => time() ]; $param[$key] = $value; - } else{ + } else { $param[$key] = null; } } @@ -473,23 +479,23 @@ class Customer extends Common $data['customer_id'] = $this->customer_id; $data['name'] = $param['name']; - if(!empty($pool_id)){ - db('crm_customer_pool_relation') ->insertGetId(['pool_id'=>$pool_id,'customer_id'=>$this->customer_id]); + if (!empty($pool_id)) { + db('crm_customer_pool_relation')->insertGetId(['pool_id' => $pool_id, 'customer_id' => $this->customer_id]); } - // 修改记录 + // 修改记录 if (empty($param['leads_id'])) { updateActionLog($param['create_user_id'], 'crm_customer', $data['customer_id'], '', '', '创建了客户'); - RecordActionLog($param['create_user_id'],'crm_customer','save',$param['name'],'','','新增了客户'.$param['name']); + RecordActionLog($param['create_user_id'], 'crm_customer', 'save', $param['name'], '', '', '新增了客户' . $param['name']); } // 添加活动记录 Db::name('crm_activity')->insert([ - 'type' => 2, - 'activity_type' => 2, + 'type' => 2, + 'activity_type' => 2, 'activity_type_id' => $data['customer_id'], - 'content' => $data['name'], - 'create_user_id' => $param['create_user_id'], - 'update_time' => time(), - 'create_time' => time() + 'content' => $data['name'], + 'create_user_id' => $param['create_user_id'], + 'update_time' => time(), + 'create_time' => time() ]); // 添加客户扩展数据 array_walk($customerData, function (&$val) use ($data) { @@ -497,30 +503,30 @@ class Customer extends Common }); db('crm_customer_data')->insertAll($customerData); - return $data; - } else { - $this->error = '添加失败'; - return false; - } - } - - //根据IDs获取数组 - public function getDataByStr($idstr) - { - $idArr = stringToArray($idstr); - if (!$idArr) { - return []; - } - $list = db('crm_customer')->where(['customer_id' => ['in',$idArr]])->select(); - return $list; - } - - /** - * 编辑客户主表信息 - * @author Michael_xu - * @param - * @return - */ + return $data; + } else { + $this->error = '添加失败'; + return false; + } + } + + //根据IDs获取数组 + public function getDataByStr($idstr) + { + $idArr = stringToArray($idstr); + if (!$idArr) { + return []; + } + $list = db('crm_customer')->where(['customer_id' => ['in', $idArr]])->select(); + return $list; + } + + /** + * 编辑客户主表信息 + * @param + * @return + * @author Michael_xu + */ public function updateDataById($param, $customer_id = '') { // 客户扩展表数据 @@ -543,17 +549,17 @@ class Customer extends Common $rwPre = $userModel->rwPre($user_id, $dataInfo['ro_user_id'], $dataInfo['rw_user_id'], 'update'); // 判断是否客户池数据 - if(empty($param['pool_id'])){ + if (empty($param['pool_id'])) { $wherePool = $this->getWhereByPool(); $resPool = db('crm_customer')->alias('customer')->where(['customer_id' => $id])->where($wherePool)->find(); - if ($resPool || (!in_array($dataInfo['owner_user_id'],$auth_user_ids) && !$rwPre)) { + if ($resPool || (!in_array($dataInfo['owner_user_id'], $auth_user_ids) && !$rwPre)) { $this->error = '无权操作'; return false; } } // 过滤不能修改的字段 - $unUpdateField = ['create_user_id','is_deleted','delete_time','user_id']; + $unUpdateField = ['create_user_id', 'is_deleted', 'delete_time', 'user_id']; foreach ($unUpdateField as $v) { unset($param[$v]); } @@ -568,21 +574,21 @@ class Customer extends Common } // 地址 - $param['address'] = $param['address'] ? implode(chr(10),$param['address']) : ''; + $param['address'] = $param['address'] ? implode(chr(10), $param['address']) : ''; if ($param['deal_status'] == '已成交' && $dataInfo->data['deal_status'] == '未成交') { $param['deal_time'] = time(); } - + // 处理部门、员工、附件、多选类型字段 $arrFieldAtt = $fieldModel->getArrayField('crm_customer'); - foreach ($arrFieldAtt as $k=>$v) { + foreach ($arrFieldAtt as $k => $v) { if (isset($param[$v])) $param[$v] = arrayToString($param[$v]); } // 处理日期(date)类型 $dateField = $fieldModel->getFieldByFormType('crm_customer', 'date'); if (!empty($dateField)) { - foreach ($param AS $key => $value) { + foreach ($param as $key => $value) { if (in_array($key, $dateField) && empty($value)) $param[$key] = null; } } @@ -590,7 +596,7 @@ class Customer extends Common // 处理手写签名类型 $handwritingField = $fieldModel->getFieldByFormType('crm_customer', 'handwriting_sign'); if (!empty($handwritingField)) { - foreach ($param AS $key => $value) { + foreach ($param as $key => $value) { if (in_array($key, $handwritingField)) { $param[$key] = !empty($value['file_id']) ? $value['file_id'] : ''; } @@ -598,17 +604,17 @@ class Customer extends Common } // 处理地址、定位、日期区间、明细表格类型字段 - $positionField = $fieldModel->getFieldByFormType('crm_customer', 'position'); - $locationField = $fieldModel->getFieldByFormType('crm_customer', 'location'); + $positionField = $fieldModel->getFieldByFormType('crm_customer', 'position'); + $locationField = $fieldModel->getFieldByFormType('crm_customer', 'location'); $dateIntervalField = $fieldModel->getFieldByFormType('crm_customer', 'date_interval'); - $detailTableField = $fieldModel->getFieldByFormType('crm_customer', 'detail_table'); - foreach ($param AS $key => $value) { + $detailTableField = $fieldModel->getFieldByFormType('crm_customer', 'detail_table'); + foreach ($param as $key => $value) { // 处理地址类型字段数据 if (in_array($key, $positionField)) { if (!empty($value)) { $customerData[] = [ - 'field' => $key, - 'content' => json_encode($value, JSON_NUMERIC_CHECK), + 'field' => $key, + 'content' => json_encode($value, JSON_NUMERIC_CHECK), 'create_time' => time() ]; $positionNames = array_column($value, 'name'); @@ -621,8 +627,8 @@ class Customer extends Common if (in_array($key, $locationField)) { if (!empty($value)) { $customerData[] = [ - 'field' => $key, - 'content' => json_encode($value, JSON_NUMERIC_CHECK), + 'field' => $key, + 'content' => json_encode($value, JSON_NUMERIC_CHECK), 'create_time' => time() ]; $param[$key] = $value['address']; @@ -635,12 +641,12 @@ class Customer extends Common if (!empty($value)) { $customerData[] = [ - 'field' => $key, - 'content' => json_encode($value, JSON_NUMERIC_CHECK), + 'field' => $key, + 'content' => json_encode($value, JSON_NUMERIC_CHECK), 'create_time' => time() ]; - $param[$key] =implode('_', $value); + $param[$key] = implode('_', $value); } else { $param[$key] = ''; } @@ -649,8 +655,8 @@ class Customer extends Common if (in_array($key, $detailTableField)) { if (!empty($value)) { $customerData[] = [ - 'field' => $key, - 'content' => json_encode($value, JSON_NUMERIC_CHECK), + 'field' => $key, + 'content' => json_encode($value, JSON_NUMERIC_CHECK), 'create_time' => time() ]; $param[$key] = $key; @@ -667,11 +673,11 @@ class Customer extends Common $data['customer_id'] = $customer_id; // 修改公海 if (!empty($param['pool_id'])) { - db('crm_customer_pool_relation')->where('customer_id', $customer_id) ->update(['pool_id' => $param['pool_id']]); + db('crm_customer_pool_relation')->where('customer_id', $customer_id)->update(['pool_id' => $param['pool_id']]); } // 修改记录 updateActionLog($user_id, 'crm_customer', $customer_id, $dataInfo->data, $param); - RecordActionLog($user_id, 'crm_customer', 'update',$dataInfo['name'], $dataInfo->data, $param); + RecordActionLog($user_id, 'crm_customer', 'update', $dataInfo['name'], $dataInfo->data, $param); // 添加客户扩展数据 db('crm_customer_data')->where('customer_id', $customer_id)->delete(); array_walk($customerData, function (&$val) use ($customer_id) { @@ -696,56 +702,56 @@ class Customer extends Common * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ - public function getDataById($id = '', $userId = 0,$model='') - { - $dataInfo = db('crm_customer')->where(['customer_id' => $id])->find(); - if (!$dataInfo) { - $this->error = '数据不存在或已删除'; - return false; - } - if(empty($model) && $model!='update'){ + public function getDataById($id = '', $userId = 0, $model = '') + { + $dataInfo = db('crm_customer')->where(['customer_id' => $id])->find(); + if (!$dataInfo) { + $this->error = '数据不存在或已删除'; + 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){ + 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){ + foreach ($fieldGrant as $key => $val) { //掩码相关类型字段 - if ($val['maskType']!=0 && $val['form_type'] == 'mobile') { + if ($val['maskType'] != 0 && $val['form_type'] == 'mobile') { $pattern = "/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i"; $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') { + } 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[$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'] = !empty($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : []; - $dataInfo['before_owner_user_id_info'] = !empty($dataInfo['before_owner_user_id']) ? $userModel->getUserById($dataInfo['before_owner_user_id']) : []; + $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'] = !empty($dataInfo['owner_user_id']) ? $userModel->getUserById($dataInfo['owner_user_id']) : []; + $dataInfo['before_owner_user_id_info'] = !empty($dataInfo['before_owner_user_id']) ? $userModel->getUserById($dataInfo['before_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['before_owner_user_name'] = !empty($dataInfo['before_owner_user_id_info']['realname']) ? $dataInfo['before_owner_user_id_info']['realname'] : ''; - # 公海信息 + # 公海信息 $poolData = $this->getPoolDay([$id]); - $dataInfo['pool_day'] = !empty($poolData[$id]) ? $poolData[$id] : ''; - $dataInfo['is_pool'] = !empty($dataInfo['owner_user_id']) ? 0 : 1; - # 关注 - $starId = empty($userId) ? 0 : Db::name('crm_star')->where(['user_id' => $userId, 'target_id' => $id, 'type' => 'crm_customer'])->value('star_id'); - $dataInfo['star'] = !empty($starId) ? 1 : 0; - # 首要联系人 + $dataInfo['pool_day'] = !empty($poolData[$id]) ? $poolData[$id] : ''; + $dataInfo['is_pool'] = !empty($dataInfo['owner_user_id']) ? 0 : 1; + # 关注 + $starId = empty($userId) ? 0 : Db::name('crm_star')->where(['user_id' => $userId, 'target_id' => $id, 'type' => 'crm_customer'])->value('star_id'); + $dataInfo['star'] = !empty($starId) ? 1 : 0; + # 首要联系人 $primaryId = Db::name('crm_contacts')->where(['customer_id' => $id, 'primary' => 1])->value('contacts_id'); $dataInfo['contacts_id'] = !empty($primaryId) && $this->getContactsAuth($primaryId) ? $primaryId : 0; # 处理时间格式 @@ -754,15 +760,15 @@ class Customer extends Common 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; - $dataInfo['last_time'] = !empty($dataInfo['last_time']) ? date('Y-m-d H:i:s', $dataInfo['last_time']) : 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; + $dataInfo['last_time'] = !empty($dataInfo['last_time']) ? date('Y-m-d H:i:s', $dataInfo['last_time']) : null; $dataInfo['into_pool_time'] = !empty($dataInfo['into_pool_time']) ? date('Y-m-d H:i:s', $dataInfo['into_pool_time']) : null; // 字段授权 if (!empty($userId)) { $grantData = getFieldGrantData($userId); $userLevel = isSuperAdministrators($userId); - foreach ($dataInfo AS $key => $value) { + foreach ($dataInfo as $key => $value) { if (!$userLevel && !empty($grantData['crm_customer'])) { $status = getFieldGrantStatus($key, $grantData['crm_customer']); @@ -778,61 +784,61 @@ class Customer extends Common $dataInfo['contacts_mobile'] = $contactsMobile; $dataInfo['contacts_address'] = $contactsInfo['detail_address']; return $dataInfo; - } + } - /** + /** * [客户统计] - * @author Michael_xu * @param - * @return - */ - public function getStatistics($request) + * @return + * @author Michael_xu + */ + public function getStatistics($request) { - $userModel = new \app\admin\model\User(); + $userModel = new \app\admin\model\User(); $adminModel = new \app\admin\model\Admin(); - $request['start_time']=strtotime($request['start_time']); - $request['end_time']=strtotime($request['end_time']); + $request['start_time'] = strtotime($request['start_time']); + $request['end_time'] = strtotime($request['end_time']); $perUserIds = $userModel->getUserByPer('bi', 'customer', 'read'); //权限范围内userIds - $whereArr = $adminModel->getWhere($request, '', $perUserIds); //统计条件 - $userIds = $whereArr['userIds']; - $request = $this->fmtRequest( $request ); - $map = $request['map'] ? : []; - unset($map['search']); - $where = []; - //时间段 - $start_time = $map['start_time']; - $end_time = $map['end_time'] ? $map['end_time'] : time(); + $whereArr = $adminModel->getWhere($request, '', $perUserIds); //统计条件 + $userIds = $whereArr['userIds']; + $request = $this->fmtRequest($request); + $map = $request['map'] ?: []; + unset($map['search']); + $where = []; + //时间段 + $start_time = $map['start_time']; + $end_time = $map['end_time'] ? $map['end_time'] : time(); if ($start_time && $end_time) { - $start_date = date('Y-m-d',$start_time); - $end_date = date('Y-m-d',$end_time); + $start_date = date('Y-m-d', $start_time); + $end_date = date('Y-m-d', $end_time); $where_time = " BETWEEN {$start_time} AND {$end_time} "; $where_date = " BETWEEN '{$start_date}' AND '{$end_date}' "; } else { $where_time = " > 0 "; $where_date = " != '' "; } - //员工IDS - $map_user_ids = []; - if (!empty($map['user_id'])) { - $map_user_ids = array($map['user_id']); - } elseif (!empty($map['structure_id'])) { - $map_user_ids = $userModel->getSubUserByStr($map['structure_id'], 2); - } - - $prefix = config('database.prefix'); - $count = count($userIds); + //员工IDS + $map_user_ids = []; + if (!empty($map['user_id'])) { + $map_user_ids = array($map['user_id']); + } elseif (!empty($map['structure_id'])) { + $map_user_ids = $userModel->getSubUserByStr($map['structure_id'], 2); + } + + $prefix = config('database.prefix'); + $count = count($userIds); $configModel = new \app\crm\model\ConfigData(); $configInfo = $configModel->getData(); - $follow_day = $configInfo['follow_day'] ? : 0; - $deal_day = $configInfo['deal_day'] ? : 0; + $follow_day = $configInfo['follow_day'] ?: 0; + $deal_day = $configInfo['deal_day'] ?: 0; //默认公海条件(没有负责人或已经到期) - $data['follow_time'] = time()-$follow_day*86400; - $data['deal_time'] = time()-$deal_day*86400; + $data['follow_time'] = time() - $follow_day * 86400; + $data['deal_time'] = time() - $deal_day * 86400; $data['deal_status'] = '未成交'; - $sql = ''; - - foreach ($userIds as $key => $user_id) { - $sql .= " + $sql = ''; + + foreach ($userIds as $key => $user_id) { + $sql .= " SELECT (SELECT realname FROM {$prefix}admin_user WHERE id = {$user_id}) as realname, COUNT(cu.customer_id) AS customer_num, @@ -858,65 +864,65 @@ class Customer extends Common WHERE (cu.create_time {$where_time} OR obtain_time {$where_time}) AND cu.owner_user_id = {$user_id} - AND (( ( deal_time > ".$data['deal_time']." ) OR (update_time > ".$data['follow_time']." AND deal_time > ".$data['deal_time']."))OR deal_status = '已成交' OR is_lock = 1 ) + AND (( ( deal_time > " . $data['deal_time'] . " ) OR (update_time > " . $data['follow_time'] . " AND deal_time > " . $data['deal_time'] . "))OR deal_status = '已成交' OR is_lock = 1 ) "; - if ($count > 1 && $key != $count - 1) { - $sql .= " UNION ALL "; - } - } - - if ($sql == '') { - return []; - } - - $customerCount = 0; # 客户总数 - $dealCustomerCount = 0; # 成交客户总数 - $contractMoneyCount = 0; # 合同总金额 + if ($count > 1 && $key != $count - 1) { + $sql .= " UNION ALL "; + } + } + + if ($sql == '') { + return []; + } + + $customerCount = 0; # 客户总数 + $dealCustomerCount = 0; # 成交客户总数 + $contractMoneyCount = 0; # 合同总金额 $receivablesMoneyCount = 0; # 回款总金额 - - $list = queryCache($sql); - foreach ($list as &$val) { - $val['deal_customer_num'] = Floor($val['deal_customer_num']); - $val['contract_money'] = Floor($val['contract_money']); - $val['receivables_money'] = Floor($val['receivables_money']); - $val['deal_customer_rate'] = $val['customer_num'] ? round(($val['deal_customer_num'] / $val['customer_num']) * 100, 2) : 0; - $val['un_receivables_money'] = $val['contract_money'] - $val['receivables_money'] >= 0 ? $val['contract_money'] - $val['receivables_money'] : '0.00'; - $val['deal_receivables_rate'] = $val['contract_money'] ? round(($val['receivables_money'] / $val['contract_money']) * 100, 2) : 0; - - $customerCount += $val['customer_num']; - $dealCustomerCount += $val['deal_customer_num']; - $contractMoneyCount += $val['contract_money']; + + $list = queryCache($sql); + foreach ($list as &$val) { + $val['deal_customer_num'] = Floor($val['deal_customer_num']); + $val['contract_money'] = Floor($val['contract_money']); + $val['receivables_money'] = Floor($val['receivables_money']); + $val['deal_customer_rate'] = $val['customer_num'] ? round(($val['deal_customer_num'] / $val['customer_num']) * 100, 2) : 0; + $val['un_receivables_money'] = $val['contract_money'] - $val['receivables_money'] >= 0 ? $val['contract_money'] - $val['receivables_money'] : '0.00'; + $val['deal_receivables_rate'] = $val['contract_money'] ? round(($val['receivables_money'] / $val['contract_money']) * 100, 2) : 0; + + $customerCount += $val['customer_num']; + $dealCustomerCount += $val['deal_customer_num']; + $contractMoneyCount += $val['contract_money']; $receivablesMoneyCount += $val['receivables_money']; - } - - return ['list' => $list, 'total' => [ - 'realname' => '总计', - 'customer_num' => $customerCount, - 'deal_customer_num' => $dealCustomerCount, - 'contract_money' => $contractMoneyCount, - 'receivables_money' => $receivablesMoneyCount + } + + return ['list' => $list, 'total' => [ + 'realname' => '总计', + 'customer_num' => $customerCount, + 'deal_customer_num' => $dealCustomerCount, + 'contract_money' => $contractMoneyCount, + 'receivables_money' => $receivablesMoneyCount ]]; - } + } - /** + /** * [客户数量] + * @param + * @return * @author Michael_xu - * @param - * @return - */ - public function getDataCount($map) - { - $dataCount = $this->where($map)->fetchSql(false)->count(); - $count = $dataCount ? : 0; - return $count; - } + */ + public function getDataCount($map) + { + $dataCount = $this->where($map)->fetchSql(false)->count(); + $count = $dataCount ?: 0; + return $count; + } /** * 客户默认条件 * - * @author fanqi - * @since 2021-05-12 * @return array + * @since 2021-05-12 + * @author fanqi */ public function getWhereByCustomer() { @@ -926,49 +932,49 @@ class Customer extends Common /** * 客户公海条件 * - * @author fanqi - * @since 2021-05-12 * @return array + * @since 2021-05-12 + * @author fanqi */ public function getWhereByPool() { - return ['customer.owner_user_id' => ['eq', 0]]; + return ['customer.owner_user_id' => ['eq', 0]]; } - /** + /** * 客户权限判断(是否客户公海) - * @author Michael_xu * @param type 1 是公海返回false,默认是公海返回true * @return - */ + * @author Michael_xu + */ public function checkData($customer_id, $type = '') { - //权限范围 - $userModel = new \app\admin\model\User(); - $authIds = $userModel->getUserByPer(); //权限范围的user_id - //是否客户公海 - $map = $this->getWhereByPool(); - $where['customer_id'] = $customer_id; - $customerInfo = db('crm_customer')->alias('customer')->where($where)->where($map)->find(); - if ($customerInfo && !$type) { - return true; - } else { - $customerInfo = db('crm_customer')->where(['customer_id' => $customer_id])->find(); - if (in_array($customerInfo['owner_user_id'], $authIds)) { - return true; - } - } - $this->error = '没有权限'; - return false; + //权限范围 + $userModel = new \app\admin\model\User(); + $authIds = $userModel->getUserByPer(); //权限范围的user_id + //是否客户公海 + $map = $this->getWhereByPool(); + $where['customer_id'] = $customer_id; + $customerInfo = db('crm_customer')->alias('customer')->where($where)->where($map)->find(); + if ($customerInfo && !$type) { + return true; + } else { + $customerInfo = db('crm_customer')->where(['customer_id' => $customer_id])->find(); + if (in_array($customerInfo['owner_user_id'], $authIds)) { + return true; + } + } + $this->error = '没有权限'; + return false; } /** * 客户到期天数 * * @param array $customerIds 客户ID - * @author fanqi - * @since 2021-04-19 * @return array + * @since 2021-04-19 + * @author fanqi */ public function getPoolDay($customerIds = [], $userIds = []) { @@ -979,7 +985,7 @@ class Customer extends Common $poolRules = db('crm_customer_pool_rule')->alias('rule')->field(['rule.*', 'pool.remain_day'])->join('__CRM_CUSTOMER_POOL__ pool', 'rule.pool_id = pool.pool_id', 'LEFT')->where($where)->select(); if (!empty($poolRules)) { - foreach ($poolRules AS $key => $value) { + foreach ($poolRules as $key => $value) { if ($value['type'] == 1) $result[] = $this->getFollowUpQueryResult($value['level_conf'], $value['level'], $value['deal_handle'], $value['business_handle'], $value['remain_day'], $customerIds, $userIds); if ($value['type'] == 2) $result[] = $this->getBusinessQueryResult($value['level_conf'], $value['level'], $value['deal_handle'], $value['remain_day'], $customerIds, $userIds); if ($value['type'] == 3) $result[] = $this->getDealQueryResult($value['level_conf'], $value['level'], $value['business_handle'], $value['remain_day'], $customerIds, $userIds); @@ -993,9 +999,9 @@ class Customer extends Common * 获取每个客户最快进入公海天数 * * @param $data - * @author fanqi - * @since 2021-04-19 * @return array + * @since 2021-04-19 + * @author fanqi */ private function getMinIntoPoolDay($data) { @@ -1003,16 +1009,16 @@ class Customer extends Common $temporary = []; # 整理数据 - foreach ($data AS $k1 => $v1) { + foreach ($data as $k1 => $v1) { if (empty($v1)) continue; - foreach ($v1 AS $k2 => $v2) { + foreach ($v1 as $k2 => $v2) { $temporary[$k2][] = $v2; } } # 每个客户最快进入公海天数 - foreach ($temporary AS $k1 => $v1) { + foreach ($temporary as $k1 => $v1) { $result[$k1] = min($v1); } @@ -1023,15 +1029,15 @@ class Customer extends Common * 获取公海规则最小数字(最快进入公海天数) * * @param $data - * @author fanqi - * @since 2021-04-19 * @return int + * @since 2021-04-19 + * @author fanqi */ private function getMinDay($data) { $number = 1; - foreach ($data AS $k1 => $v1) { + foreach ($data as $k1 => $v1) { if (empty($number) || $v1['limit_day'] < $number) $number = $v1['limit_day']; } @@ -1048,9 +1054,9 @@ class Customer extends Common * @param int $remainDay 提前几天提醒 * @param array $customerIds 客户ID * @param array $userIds 员工ID + * @return array * @author fanqi * @since 2021-04-01 - * @return array */ private function getFollowUpQueryResult($type, $levels, $dealStatus, $businessStatus, $remainDay, $customerIds = [], $userIds = []) { @@ -1068,14 +1074,14 @@ class Customer extends Common if (empty($authUserIds)) return $result; # 默认条件 - $where = "`customer`.`owner_user_id` IN (".implode(',', $authUserIds).")"; + $where = "`customer`.`owner_user_id` IN (" . implode(',', $authUserIds) . ")"; # 所有用户,不区分级别 if ($type == 1) { - foreach ($levels AS $k1 => $v1) { + foreach ($levels as $k1 => $v1) { if (!empty($v1['limit_day'])) { $time = strtotime(date('Y-m-d 00:00:00', time() - 86400 * $v1['limit_day'])); - $where .= " AND ((`customer`.`last_time` > ".$time." AND `customer`.`last_time` > `customer`.`obtain_time`) OR (`customer`.`obtain_time` > ".$time." AND `customer`.`obtain_time` > `customer`.`last_time`) OR (`customer`.`obtain_time` > ".$time." AND ISNULL(`customer`.`last_time`)))"; + $where .= " AND ((`customer`.`last_time` > " . $time . " AND `customer`.`last_time` > `customer`.`obtain_time`) OR (`customer`.`obtain_time` > " . $time . " AND `customer`.`obtain_time` > `customer`.`last_time`) OR (`customer`.`obtain_time` > " . $time . " AND ISNULL(`customer`.`last_time`)))"; $limitDay['all'] = $v1['limit_day']; } @@ -1084,13 +1090,13 @@ class Customer extends Common # 根据用户级别设置条件 if ($type == 2) { - foreach ($levels AS $k1 => $v1) { + foreach ($levels as $k1 => $v1) { if (!empty($v1['level']) && !empty($v1['limit_day'])) { $time = strtotime(date('Y-m-d 00:00:00', time() - 86400 * $v1['limit_day'])); if ($k1 == 0) { - $where .= " AND ( ((`customer`.`level` = '".$v1['level']."' AND `customer`.`last_time` > " . $time . " AND `customer`.`last_time` > `customer`.`obtain_time`) OR (`customer`.`level` = '".$v1['level']."' AND `customer`.`obtain_time` > ".$time." AND `customer`.`obtain_time` > `customer`.`last_time`) OR (`customer`.`level` = '".$v1['level']."' AND `customer`.`obtain_time` > " . $time . " AND ISNULL(`customer`.`last_time`)))"; + $where .= " AND ( ((`customer`.`level` = '" . $v1['level'] . "' AND `customer`.`last_time` > " . $time . " AND `customer`.`last_time` > `customer`.`obtain_time`) OR (`customer`.`level` = '" . $v1['level'] . "' AND `customer`.`obtain_time` > " . $time . " AND `customer`.`obtain_time` > `customer`.`last_time`) OR (`customer`.`level` = '" . $v1['level'] . "' AND `customer`.`obtain_time` > " . $time . " AND ISNULL(`customer`.`last_time`)))"; } else { - $where .= " OR ((`customer`.`level` = '".$v1['level']."' AND `customer`.`last_time` > " . $time . " AND `customer`.`last_time` > `customer`.`obtain_time`) OR (`customer`.`level` = '".$v1['level']."' AND `customer`.`obtain_time` > ".$time." AND `customer`.`obtain_time` > `customer`.`last_time`) OR (`customer`.`level` = '".$v1['level']."' AND `customer`.`obtain_time` > " . $time . " AND ISNULL(`customer`.`last_time`)))"; + $where .= " OR ((`customer`.`level` = '" . $v1['level'] . "' AND `customer`.`last_time` > " . $time . " AND `customer`.`last_time` > `customer`.`obtain_time`) OR (`customer`.`level` = '" . $v1['level'] . "' AND `customer`.`obtain_time` > " . $time . " AND `customer`.`obtain_time` > `customer`.`last_time`) OR (`customer`.`level` = '" . $v1['level'] . "' AND `customer`.`obtain_time` > " . $time . " AND ISNULL(`customer`.`last_time`)))"; } $limitDay[$v1['level']] = $v1['limit_day']; @@ -1101,7 +1107,7 @@ class Customer extends Common $minLimit = $this->getMinDay($levels); $minTime = strtotime(date('Y-m-d 00:00:00', time() - 86400 * $minLimit)); - $where .= " OR ((!`customer`.`level` AND `customer`.`last_time` > ".$minTime." AND `customer`.`last_time` > `customer`.`obtain_time`) OR (!`customer`.`level` AND `customer`.`obtain_time` > ".$time." AND `customer`.`obtain_time` > `customer`.`last_time`) OR (!`customer`.`level` AND `customer`.`obtain_time` > ".$minTime." AND ISNULL(`customer`.`last_time`))) )"; + $where .= " OR ((!`customer`.`level` AND `customer`.`last_time` > " . $minTime . " AND `customer`.`last_time` > `customer`.`obtain_time`) OR (!`customer`.`level` AND `customer`.`obtain_time` > " . $time . " AND `customer`.`obtain_time` > `customer`.`last_time`) OR (!`customer`.`level` AND `customer`.`obtain_time` > " . $minTime . " AND ISNULL(`customer`.`last_time`))) )"; } # 选择不进入公海的客户(已成交客户) @@ -1111,10 +1117,10 @@ class Customer extends Common if (!empty($businessStatus)) $where .= " AND ISNULL(`business`.`customer_id`)"; # 查询指定客户 - if (!empty($customerIds)) $where .= " AND `customer`.`customer_id` IN (".implode(',', $customerIds).")"; + if (!empty($customerIds)) $where .= " AND `customer`.`customer_id` IN (" . implode(',', $customerIds) . ")"; # 查询指定员工 - if (!empty($userIds)) $where .= " AND `customer`.`owner_user_id` IN (".implode(',', $userIds).")"; + if (!empty($userIds)) $where .= " AND `customer`.`owner_user_id` IN (" . implode(',', $userIds) . ")"; # 锁定的客户不提醒 $where .= " AND `customer`.`is_lock` = 0"; @@ -1126,7 +1132,7 @@ class Customer extends Common ->where($where)->select(); # 计算到期天数 - foreach ($data AS $k1 => $v1) { + foreach ($data as $k1 => $v1) { if ($type == 1) { $customerTime = !empty($v1['last_time']) && $v1['last_time'] > $v1['obtain_time'] ? $v1['last_time'] : $v1['obtain_time']; $date = date('Y-m-d 00:00:00', ($customerTime + $limitDay['all'] * 86400) - $remainDay * 86400); @@ -1160,9 +1166,9 @@ class Customer extends Common * @param int $remainDay 提前几天提醒 * @param array $customerIds 客户ID * @param array $userIds 员工ID - * @author fanqi - * @since 2021-04-01 * @return array|false|string + * @since 2021-04-01 + * @author fanqi */ private function getBusinessQueryResult($type, $levels, $dealStatus, $remainDay, $customerIds = [], $userIds = []) { @@ -1180,14 +1186,14 @@ class Customer extends Common if (empty($authUserIds)) return $result; # 默认条件 - $where = "`customer`.`owner_user_id` IN (".implode(',', $authUserIds).")"; + $where = "`customer`.`owner_user_id` IN (" . implode(',', $authUserIds) . ")"; # 所有用户,不区分级别 if ($type == 1) { - foreach ($levels AS $k1 => $v1) { + foreach ($levels as $k1 => $v1) { if (!empty($v1['limit_day'])) { $time = strtotime(date('Y-m-d 00:00:00', time() - 86400 * $v1['limit_day'])); - $where .= " AND ( (ISNULL(`business`.`customer_id`) AND `customer`.`obtain_time` > ".$time.") OR (`customer`.`obtain_time` > ".$time." AND `customer`.`obtain_time` > `business`.`create_time`) OR (`business`.`create_time` > ".$time." AND `business`.`create_time` > `customer`.`obtain_time`) )"; + $where .= " AND ( (ISNULL(`business`.`customer_id`) AND `customer`.`obtain_time` > " . $time . ") OR (`customer`.`obtain_time` > " . $time . " AND `customer`.`obtain_time` > `business`.`create_time`) OR (`business`.`create_time` > " . $time . " AND `business`.`create_time` > `customer`.`obtain_time`) )"; $limitDay['all'] = $v1['limit_day']; } @@ -1196,13 +1202,13 @@ class Customer extends Common # 根据用户级别设置条件 if ($type == 2) { - foreach ($levels AS $k1 => $v1) { + foreach ($levels as $k1 => $v1) { if (!empty($v1['level']) && !empty($v1['limit_day'])) { $time = strtotime(date('Y-m-d 00:00:00', time() - 86400 * $v1['limit_day'])); if ($k1 == 0) { - $where .= " AND ( ((ISNULL(`business`.`customer_id`) AND `customer`.`obtain_time` > ".$time." AND `customer`.`level` = '".$v1['level']."') OR (`customer`.`obtain_time` > ".$time." AND `customer`.`obtain_time` > `business`.`create_time` AND `customer`.`level` = '".$v1['level']."') OR (`business`.`create_time` > $time AND `business`.`create_time` > `customer`.`obtain_time` AND `customer`.`level` = '".$v1['level']."'))"; + $where .= " AND ( ((ISNULL(`business`.`customer_id`) AND `customer`.`obtain_time` > " . $time . " AND `customer`.`level` = '" . $v1['level'] . "') OR (`customer`.`obtain_time` > " . $time . " AND `customer`.`obtain_time` > `business`.`create_time` AND `customer`.`level` = '" . $v1['level'] . "') OR (`business`.`create_time` > $time AND `business`.`create_time` > `customer`.`obtain_time` AND `customer`.`level` = '" . $v1['level'] . "'))"; } else { - $where .= " OR ((ISNULL(`business`.`customer_id`) AND `customer`.`obtain_time` > ".$time." AND `customer`.`level` = '".$v1['level']."') OR (`customer`.`obtain_time` > ".$time." AND `customer`.`obtain_time` > `business`.`create_time` AND `customer`.`level` = '".$v1['level']."') OR (`business`.`create_time` > $time AND `business`.`create_time` > `customer`.`obtain_time` AND `customer`.`level` = '".$v1['level']."'))"; + $where .= " OR ((ISNULL(`business`.`customer_id`) AND `customer`.`obtain_time` > " . $time . " AND `customer`.`level` = '" . $v1['level'] . "') OR (`customer`.`obtain_time` > " . $time . " AND `customer`.`obtain_time` > `business`.`create_time` AND `customer`.`level` = '" . $v1['level'] . "') OR (`business`.`create_time` > $time AND `business`.`create_time` > `customer`.`obtain_time` AND `customer`.`level` = '" . $v1['level'] . "'))"; } } @@ -1213,17 +1219,17 @@ class Customer extends Common $minLimit = $this->getMinDay($levels); $minTime = strtotime(date('Y-m-d 00:00:00', time() - 86400 * $minLimit)); - $where .= " OR ((ISNULL(`business`.`customer_id`) AND `customer`.`obtain_time` > ".$minTime." AND !`customer`.`level`) OR (`customer`.`obtain_time` > ".$minTime." AND `customer`.`obtain_time` > `business`.`create_time` AND !`customer`.`level`) OR (`business`.`create_time` > ".$minTime." AND `business`.`create_time` > `customer`.`obtain_time` AND !`customer`.`level`)) )"; + $where .= " OR ((ISNULL(`business`.`customer_id`) AND `customer`.`obtain_time` > " . $minTime . " AND !`customer`.`level`) OR (`customer`.`obtain_time` > " . $minTime . " AND `customer`.`obtain_time` > `business`.`create_time` AND !`customer`.`level`) OR (`business`.`create_time` > " . $minTime . " AND `business`.`create_time` > `customer`.`obtain_time` AND !`customer`.`level`)) )"; } # 选择不进入公海的客户(已成交客户) if (!empty($dealStatus)) $where .= " AND (`customer`.`deal_status` <> '已成交' OR ISNULL(`customer`.`deal_status`))"; # 查询指定客户 - if (!empty($customerIds)) $where .= " AND `customer`.`customer_id` IN (".implode(',', $customerIds).")"; + if (!empty($customerIds)) $where .= " AND `customer`.`customer_id` IN (" . implode(',', $customerIds) . ")"; # 查询指定员工 - if (!empty($userIds)) $where .= " AND `customer`.`owner_user_id` IN (".implode(',', $userIds).")"; + if (!empty($userIds)) $where .= " AND `customer`.`owner_user_id` IN (" . implode(',', $userIds) . ")"; # 锁定的客户不提醒 $where .= " AND `customer`.`is_lock` = 0"; @@ -1235,7 +1241,7 @@ class Customer extends Common ->where($where)->select(); # 计算到期天数 - foreach ($data AS $k1 => $v1) { + foreach ($data as $k1 => $v1) { if ($type == 1) { $customerTime = !empty($v1['business_time']) && $v1['business_time'] > $v1['customer_time'] ? $v1['business_time'] : $v1['customer_time']; $date = date('Y-m-d 00:00:00', ($customerTime + $limitDay['all'] * 86400) - $remainDay * 86400); @@ -1269,9 +1275,9 @@ class Customer extends Common * @param int $remainDay 提前几天提醒 * @param array $customerIds 客户ID * @param array $userIds 员工ID - * @author fanqi - * @since 2021-04-01 * @return array|false|string + * @since 2021-04-01 + * @author fanqi */ private function getDealQueryResult($type, $levels, $businessStatus, $remainDay, $customerIds = [], $userIds = []) { @@ -1289,14 +1295,14 @@ class Customer extends Common if (empty($authUserIds)) return $result; # 默认条件 - $where = "`customer`.`owner_user_id` IN (".implode(',', $authUserIds).")"; + $where = "`customer`.`owner_user_id` IN (" . implode(',', $authUserIds) . ")"; # 所有用户,不区分级别 if ($type == 1) { - foreach ($levels AS $k1 => $v1) { + foreach ($levels as $k1 => $v1) { if (!empty($v1['limit_day'])) { $time = strtotime(date('Y-m-d 00:00:00', time() - 86400 * $v1['limit_day'])); - $where .= " AND ( (ISNULL(`contract`.`customer_id`) AND `customer`.`obtain_time` > ".$time.") OR (`customer`.`obtain_time` > ".$time." AND `customer`.`obtain_time` > `contract`.`create_time`) OR (`contract`.`create_time` > ".$time." AND `contract`.`create_time` > `customer`.`obtain_time`) )"; + $where .= " AND ( (ISNULL(`contract`.`customer_id`) AND `customer`.`obtain_time` > " . $time . ") OR (`customer`.`obtain_time` > " . $time . " AND `customer`.`obtain_time` > `contract`.`create_time`) OR (`contract`.`create_time` > " . $time . " AND `contract`.`create_time` > `customer`.`obtain_time`) )"; $limitDay['all'] = $v1['limit_day']; } @@ -1305,13 +1311,13 @@ class Customer extends Common # 根据用户级别设置条件 if ($type == 2) { - foreach ($levels AS $k1 => $v1) { + foreach ($levels as $k1 => $v1) { if (!empty($v1['level']) && !empty($v1['limit_day'])) { $time = strtotime(date('Y-m-d 00:00:00', time() - 86400 * $v1['limit_day'])); if ($k1 == 0) { - $where .= " AND ( ((ISNULL(`contract`.`customer_id`) AND `customer`.`level` = '".$v1['level']."' AND `customer`.`obtain_time` > ".$time.") OR (`customer`.`level` = '".$v1['level']."' AND `customer`.`obtain_time` > ".$time." AND `customer`.`obtain_time` > `contract`.`create_time`) OR (`contract`.`create_time` > ".$time." AND `contract`.`create_time` > `customer`.`obtain_time` AND `customer`.`level` = '".$v1['level']."'))"; + $where .= " AND ( ((ISNULL(`contract`.`customer_id`) AND `customer`.`level` = '" . $v1['level'] . "' AND `customer`.`obtain_time` > " . $time . ") OR (`customer`.`level` = '" . $v1['level'] . "' AND `customer`.`obtain_time` > " . $time . " AND `customer`.`obtain_time` > `contract`.`create_time`) OR (`contract`.`create_time` > " . $time . " AND `contract`.`create_time` > `customer`.`obtain_time` AND `customer`.`level` = '" . $v1['level'] . "'))"; } else { - $where .= " OR ((ISNULL(`contract`.`customer_id`) AND `customer`.`level` = '".$v1['level']."' AND `customer`.`obtain_time` > ".$time.") OR (`customer`.`level` = '".$v1['level']."' AND `customer`.`obtain_time` > ".$time." AND `customer`.`obtain_time` > `contract`.`create_time`) OR (`contract`.`create_time` > ".$time." AND `contract`.`create_time` > `customer`.`obtain_time` AND `customer`.`level` = '".$v1['level']."'))"; + $where .= " OR ((ISNULL(`contract`.`customer_id`) AND `customer`.`level` = '" . $v1['level'] . "' AND `customer`.`obtain_time` > " . $time . ") OR (`customer`.`level` = '" . $v1['level'] . "' AND `customer`.`obtain_time` > " . $time . " AND `customer`.`obtain_time` > `contract`.`create_time`) OR (`contract`.`create_time` > " . $time . " AND `contract`.`create_time` > `customer`.`obtain_time` AND `customer`.`level` = '" . $v1['level'] . "'))"; } } @@ -1322,17 +1328,17 @@ class Customer extends Common $minLimit = $this->getMinDay($levels); $minTime = strtotime(date('Y-m-d 00:00:00', time() - 86400 * $minLimit)); - $where .= " OR ((ISNULL(`contract`.`customer_id`) AND !`customer`.`level` AND `customer`.`obtain_time` > ".$minTime.") OR (!`customer`.`level` AND `customer`.`obtain_time` > ".$minTime." AND `customer`.`obtain_time` > `contract`.`create_time`) OR (`contract`.`create_time` > ".$minTime." AND `contract`.`create_time` > `customer`.`obtain_time` AND !`customer`.`level`)) )"; + $where .= " OR ((ISNULL(`contract`.`customer_id`) AND !`customer`.`level` AND `customer`.`obtain_time` > " . $minTime . ") OR (!`customer`.`level` AND `customer`.`obtain_time` > " . $minTime . " AND `customer`.`obtain_time` > `contract`.`create_time`) OR (`contract`.`create_time` > " . $minTime . " AND `contract`.`create_time` > `customer`.`obtain_time` AND !`customer`.`level`)) )"; } # 选择不进入公海的客户(有商机客户) if (!empty($businessStatus)) $where .= " AND ISNULL(`business`.`customer_id`)"; # 查询指定客户 - if (!empty($customerIds)) $where .= " AND `customer`.`customer_id` IN (".implode(',', $customerIds).")"; + if (!empty($customerIds)) $where .= " AND `customer`.`customer_id` IN (" . implode(',', $customerIds) . ")"; # 查询指定员工 - if (!empty($userIds)) $where .= " AND `customer`.`owner_user_id` IN (".implode(',', $userIds).")"; + if (!empty($userIds)) $where .= " AND `customer`.`owner_user_id` IN (" . implode(',', $userIds) . ")"; # 锁定的客户不提醒 $where .= " AND `customer`.`is_lock` = 0"; @@ -1345,9 +1351,9 @@ class Customer extends Common ->where($where)->select(); # 计算到期天数 - foreach ($data AS $k1 => $v1) { + foreach ($data as $k1 => $v1) { if ($type == 1) { - $customerTime = !empty($v1['contract_time']) && $v1['contract_time'] > $v1['customer_time'] ? $v1['contract_time'] : $v1['customer_time']; + $customerTime = !empty($v1['contract_time']) && $v1['contract_time'] > $v1['customer_time'] ? $v1['contract_time'] : $v1['customer_time']; $date = date('Y-m-d 00:00:00', ($customerTime + $limitDay['all'] * 86400) - $remainDay * 86400); $dateRange = strtotime($date); if (time() > $dateRange) { @@ -1370,19 +1376,19 @@ class Customer extends Common return $result; } - /** + /** * [今日进入客户池条件] + * @param + * @return * @author Michael_xu - * @param - * @return - */ + */ public function getWhereByToday() { - $configModel = new \app\crm\model\ConfigData(); + $configModel = new \app\crm\model\ConfigData(); $configInfo = $configModel->getData(); - $config = $configInfo['config'] ? : 0; - $follow_day = $configInfo['follow_day'] ? : 0; - $deal_day = $configInfo['deal_day'] ? : 0; + $config = $configInfo['config'] ?: 0; + $follow_day = $configInfo['follow_day'] ?: 0; + $deal_day = $configInfo['deal_day'] ?: 0; $whereData = []; //启用 @@ -1390,46 +1396,46 @@ class Customer extends Common //默认公海条件(没有负责人或已经到期) //通过提前提醒时间,计算查询时间段 if (($follow_day > 0) && ($deal_day > 0)) { - $follow_between = array(strtotime(date('Y-m-d',time()-$follow_day*86400)),time()-$follow_day*86400); - $deal_between = array(strtotime(date('Y-m-d',time()-$deal_day*86400)),time()-$deal_day*86400); + $follow_between = array(strtotime(date('Y-m-d', time() - $follow_day * 86400)), time() - $follow_day * 86400); + $deal_between = array(strtotime(date('Y-m-d', time() - $deal_day * 86400)), time() - $deal_day * 86400); - $data['update_time'] = time()-$follow_day*86400; - $data['deal_time'] = time()-$deal_day*86400; + $data['update_time'] = time() - $follow_day * 86400; + $data['deal_time'] = time() - $deal_day * 86400; $data['update_between'] = $follow_between; $data['deal_between'] = $deal_between; - if ($follow_day < $deal_day) { - $whereData = function($query) use ($data){ - $query->where(['customer.owner_user_id'=>0]) - ->whereOr(function ($query) use ($data) { - $query->where(function ($query) use ($data) { - $query->where(['customer.update_time' => array('between',$data['update_between'])]) - ->whereOr(['customer.deal_time' => array('between',$data['deal_between'])]); - }) - ->where(['customer.is_lock' => 0]) - ->where(['customer.deal_status' => ['neq','已成交']]); - }); - }; - } else { - $whereData = function($query) use ($data){ - $query->where(['customer.owner_user_id'=>0]) - ->whereOr(function ($query) use ($data) { - $query->where(function ($query) use ($data) { - $query->where(['customer.deal_time' => array('between',$data['deal_between'])]); - }) - ->where(['customer.is_lock' => 0]) - ->where(['customer.deal_status' => ['neq','已成交']]); - }); - }; - } + if ($follow_day < $deal_day) { + $whereData = function ($query) use ($data) { + $query->where(['customer.owner_user_id' => 0]) + ->whereOr(function ($query) use ($data) { + $query->where(function ($query) use ($data) { + $query->where(['customer.update_time' => array('between', $data['update_between'])]) + ->whereOr(['customer.deal_time' => array('between', $data['deal_between'])]); + }) + ->where(['customer.is_lock' => 0]) + ->where(['customer.deal_status' => ['neq', '已成交']]); + }); + }; + } else { + $whereData = function ($query) use ($data) { + $query->where(['customer.owner_user_id' => 0]) + ->whereOr(function ($query) use ($data) { + $query->where(function ($query) use ($data) { + $query->where(['customer.deal_time' => array('between', $data['deal_between'])]); + }) + ->where(['customer.is_lock' => 0]) + ->where(['customer.deal_status' => ['neq', '已成交']]); + }); + }; + } } else { $whereData['customer.customer_id'] = 0; } } else { - $whereData['customer.owner_user_id'] = 0; - $whereData['customer.update_time'] = array('between',array(strtotime(date('Y-m-d',time())),time())); + $whereData['customer.owner_user_id'] = 0; + $whereData['customer.update_time'] = array('between', array(strtotime(date('Y-m-d', time())), time())); } - return $whereData ? : ''; + return $whereData ?: ''; } /** @@ -1438,9 +1444,9 @@ class Customer extends Common * @param int $userId 用户ID * @param int $isDeal 成交客户是否占用拥有客户数条件:1 占用 0 不占用 * @param int $types 类型:1 拥有客户数,2 锁定客户数 - * @author fanqi - * @since 2021-04-15 * @return int + * @since 2021-04-15 + * @author fanqi */ public function getCountByHave($userId, $isDeal = 0, $types = 1) { @@ -1537,16 +1543,16 @@ class Customer extends Common // return $count ? : 0; // } - /** + /** * [客户成交新增数量] + * @param + * @return * @author Michael_xu - * @param - * @return - */ - public function getAddDealSql($map) - { - $prefix = config('database.prefix'); - $sql = "SELECT + */ + public function getAddDealSql($map) + { + $prefix = config('database.prefix'); + $sql = "SELECT '{$map['type']}' AS type, '{$map['start_time']}' AS start_time, '{$map['end_time']}' AS end_time, @@ -1572,19 +1578,19 @@ class Customer extends Common create_time BETWEEN {$map['start_time']} AND {$map['end_time']} AND deal_status = '{$map['deal_status']}' AND owner_user_id IN ({$map['create_user_id']})"; - return $sql; - } + return $sql; + } - /** + /** * [客户统计sql] + * @param + * @return * @author Michael_xu - * @param - * @return - */ - public function getAddressCountBySql($map) - { - $prefix = config('database.prefix'); - $sql = "SELECT + */ + public function getAddressCountBySql($map) + { + $prefix = config('database.prefix'); + $sql = "SELECT '{$map['address']}' AS address, IFNULL( ( @@ -1608,9 +1614,9 @@ class Customer extends Common address LIKE '%{$map['address']}%' AND deal_status = '{$map['deal_status']}' AND owner_user_id IN ({$map['owner_user_id']})"; - $list = $this->query($sql) ? : []; - return $list; - } + $list = $this->query($sql) ?: []; + return $list; + } /** * 获取附近的客户 @@ -1696,16 +1702,16 @@ class Customer extends Common * @param int $decimal 精度:保留小数位数 * @return float */ - private function getLngLatDistance($longitude1, $latitude1, $longitude2, $latitude2, $unit=2, $decimal=2) + private function getLngLatDistance($longitude1, $latitude1, $longitude2, $latitude2, $unit = 2, $decimal = 2) { $EARTH_RADIUS = 6370.996; // 地球半径系数 - $PI = 3.1415926; + $PI = 3.1415926; $radLat1 = $latitude1 * $PI / 180.0; $radLat2 = $latitude2 * $PI / 180.0; $radLng1 = $longitude1 * $PI / 180.0; - $radLng2 = $longitude2 * $PI /180.0; + $radLng2 = $longitude2 * $PI / 180.0; $a = $radLat1 - $radLat2; $b = $radLng1 - $radLng2; @@ -1713,7 +1719,7 @@ class Customer extends Common $distance = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2))); $distance = $distance * $EARTH_RADIUS * 1000; - if( $unit==2 ) $distance = $distance / 1000; + if ($unit == 2) $distance = $distance / 1000; return round($distance, $decimal); } @@ -1736,7 +1742,7 @@ class Customer extends Common # 计算纬度区间 $latRange = 180 / $pi * $distance / 6372.797; # 计算进度区间 - $lngRang = $latRange / cos($myLat * $pi / 180); + $lngRang = $latRange / cos($myLat * $pi / 180); $maxLng = $myLng + $lngRang; # 最大经度 $minLng = $myLng - $lngRang; # 最小经度 @@ -1764,7 +1770,7 @@ class Customer extends Common $createUserName = Db::name('admin_user')->where('id', $customer['create_user_id'])->value('realname'); # zjf 20210726 - $userModel = new \app\admin\model\User(); + $userModel = new \app\admin\model\User(); $ownerUserInfo = $userModel->getUserById($customer['owner_user_id']); # 负责人部门 $ownerStructureName = $ownerUserInfo['structure_name']; @@ -1811,7 +1817,7 @@ class Customer extends Common public function getCustomerSaleStatistics($param, $user_id) { $userModel = new \app\admin\model\User(); - $type = $param['type']; + $type = $param['type']; unset($param['type']); # 日期条件 @@ -1821,7 +1827,7 @@ class Customer extends Common $timeData['end_time'] = $timeArr[1]; } else { if (!empty($timeData['start_time'])) $timeData['start_time'] = strtotime($timeData['start_time'] . ' 00:00:00'); - if (!empty($timeData['end_time'])) $timeData['end_time'] = strtotime($timeData['end_time'] . ' 23:59:59'); + if (!empty($timeData['end_time'])) $timeData['end_time'] = strtotime($timeData['end_time'] . ' 23:59:59'); } if ($param['user_id']) { @@ -1834,21 +1840,21 @@ class Customer extends Common unset($param['user_id']); # 格式化参数 - $request = $this->fmtRequest( $param ); + $request = $this->fmtRequest($param); $perUserIds = $userModel->getUserByPer('jxc', 'bi', 'jxcProductPurchaseStatistics'); //权限范围内userIds $userIds = $map_user_ids ? array_intersect($map_user_ids, $perUserIds) : $perUserIds; //数组交集 $dataCount = db('crm_customer')->alias('a') - ->where(['owner_user_id'=>['in', $userIds]]) - ->count(); + ->where(['owner_user_id' => ['in', $userIds]]) + ->count(); $list = db('crm_customer')->alias('a') - ->where(['owner_user_id' => ['in', $userIds]]) - ->limit($request['offset'], $request['length']) - ->field('customer_id, name') - ->orderRaw('customer_id desc') - ->select(); + ->where(['owner_user_id' => ['in', $userIds]]) + ->limit($request['offset'], $request['length']) + ->field('customer_id, name') + ->orderRaw('customer_id desc') + ->select(); $userIds = implode(',', $userIds); $prefix = config('database.prefix'); @@ -1877,7 +1883,7 @@ class Customer extends Common AND b.owner_user_id IN ({$userIds}) AND b.check_status IN (7, 2) AND b.create_time BETWEEN {$timeData['start_time']} AND {$timeData['end_time']}"; - + $data = queryCache($sql); $sql1 = "SELECT @@ -1909,8 +1915,8 @@ class Customer extends Common $arr['items'][] = $item; } $data = []; - $data['list'] = $arr ? : []; - $data['dataCount'] = $dataCount ? : 0; + $data['list'] = $arr ?: []; + $data['dataCount'] = $dataCount ?: 0; return $data; } } \ No newline at end of file