338 lines
15 KiB
PHP
338 lines
15 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
require_once APPPATH . 'controllers/api/BaseController.php';
|
|
|
|
/**
|
|
* Notes:私域直播_客户列表
|
|
* Created on: 2023/2/27 17:15
|
|
* Created by: dengbw
|
|
*/
|
|
class groupsCustomer extends BaseController
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('market/Market_sylive_customer_model', 'mdSyliveCustomer');
|
|
$this->load->model('market/Market_sylive_groups_model', 'mdSyliveGroups');
|
|
$this->load->model('market/Market_sylive_groups_user_model', 'mdSyliveGroupsUser');
|
|
$this->load->model('market/Market_sylive_user_model', 'mdSyliveUser');
|
|
$this->load->model('market/Market_sylive_activity_model', 'mdSyliveActivity');
|
|
}
|
|
|
|
/**
|
|
* Notes:订单管理列表
|
|
* Created on: 2022/12/08 14:48
|
|
* Created by: dengbw
|
|
*/
|
|
public function index_get()
|
|
{
|
|
$date = $this->dataSelect($this->inputs);
|
|
$this->return_response_list($date);
|
|
}
|
|
|
|
/**
|
|
* Notes:导出订单数据
|
|
* Created on: 2022/12/08 15:26
|
|
* Created by: dengbw
|
|
*/
|
|
public function export_get()
|
|
{
|
|
$this->inputs['page'] = 1;
|
|
$this->inputs['limit'] = 20000;
|
|
$date = $this->dataSelect($this->inputs);
|
|
$this->return_response_list($date);
|
|
}
|
|
|
|
/**
|
|
* Notes:导入审核数据
|
|
* Created on: 2023/2/22 17:24
|
|
* Created by: dengbw
|
|
* @throws PHPExcel_Exception
|
|
* @throws PHPExcel_Reader_Exception
|
|
*/
|
|
public function import_post()
|
|
{
|
|
require_once COMMPATH . '/third_party/PHPExcel/IOFactory.php';
|
|
$res = $this->upload();
|
|
if (!$res['code']) {
|
|
return $this->return_json($res['message']);
|
|
}
|
|
$file = $res['path'];
|
|
if ($res['file_ext'] == '.xls') {
|
|
$reader = \PHPExcel_IOFactory::createReader('Excel5'); // 读取 excel 文档
|
|
} elseif ($res['file_ext'] == '.xlsx') {
|
|
$reader = \PHPExcel_IOFactory::createReader('Excel2007'); // 读取 excel 文档
|
|
} else {
|
|
return $this->return_json('文件无法识别');
|
|
}
|
|
$PHPExcel = $reader->load($file); // 文档名称
|
|
$objWorksheet = $PHPExcel->getActiveSheet();
|
|
$rowCnt = $objWorksheet->getHighestRow(); //获取总行数
|
|
if ($rowCnt > 800) {
|
|
@unlink($file);
|
|
$this->return_json('数据大于800请拆分多个表格导入');
|
|
}
|
|
$activityId = $_POST['activityId'];
|
|
$done = 0;
|
|
for ($_row = 2; $_row <= $rowCnt; $_row++) { //读取内容
|
|
$name = $objWorksheet->getCell('A' . $_row)->getValue();
|
|
$mobile = $objWorksheet->getCell('B' . $_row)->getValue();
|
|
$bizName = $objWorksheet->getCell('C' . $_row)->getValue();
|
|
//$cfName = $objWorksheet->getCell('D' . $_row)->getValue();
|
|
$cfMobile = $objWorksheet->getCell('E' . $_row)->getValue();
|
|
$level = $objWorksheet->getCell('F' . $_row)->getValue();
|
|
if ($mobile) {
|
|
$re = $this->mdSyliveCustomer->get(['activityId' => $activityId, 'mobile' => $mobile, 'status<>' => -1]);
|
|
if (!$re) {
|
|
!$name && $name = '';
|
|
!$level && $level = '';
|
|
$addData = ['activityId' => $activityId, 'name' => $name, 'mobile' => $mobile, 'level' => $level
|
|
, 'createTime' => date('Y-m-d H:i:s')];
|
|
if ($cfMobile) {
|
|
$re_user = $this->mdSyliveUser->get(['mobile' => $cfMobile, 'organizationId>' => 0, 'status<>' => -1]);
|
|
if ($re_user['userId']) {
|
|
$addData['cfUserId'] = $re_user['userId'];
|
|
$re_groUser = $this->mdSyliveGroupsUser->get(['activityId' => $activityId, 'userId' => $re_user['userId'], 'status<>' => -1]);
|
|
if ($re_groUser['bizId']) {
|
|
$addData['status'] = 1;
|
|
$addData['bizId'] = $re_groUser['bizId'];
|
|
$addData['levelId1'] = $re_groUser['levelId1'];
|
|
$addData['levelId2'] = $re_groUser['levelId2'];
|
|
$addData['levelId3'] = $re_groUser['levelId3'];
|
|
}
|
|
}
|
|
}
|
|
if (!$addData['bizId'] && $bizName) {
|
|
$re_gro = $this->mdSyliveGroups->get(['activityId' => $activityId, 'groupsName' => $bizName, 'ifBiz' => 1, 'status<>' => -1]);
|
|
if ($re_gro['groupsId']) {
|
|
$addData['bizId'] = $re_gro['groupsId'];
|
|
$levelAry = $this->getLevelAry($re_gro['parentId']);
|
|
$levelAry['levelId1'] && $addData['levelId1'] = $levelAry['levelId1'];
|
|
$levelAry['levelId2'] && $addData['levelId2'] = $levelAry['levelId2'];
|
|
$levelAry['levelId3'] && $addData['levelId3'] = $levelAry['levelId3'];
|
|
}
|
|
}
|
|
$re_user = $this->mdSyliveUser->get(['mobile' => $mobile, 'status<>' => -1]);
|
|
if ($re_user['userId']) {
|
|
$addData['userId'] = $re_user['userId'];
|
|
}
|
|
$customerId = $this->mdSyliveCustomer->add($addData);
|
|
$customerId && $done++;
|
|
}
|
|
}
|
|
}
|
|
@unlink($file);
|
|
$this->return_response('', "成功新增{$done}个客户");
|
|
}
|
|
|
|
/**
|
|
* Notes:获取分组等级ID
|
|
* Created on: 2023/3/01 14:30
|
|
* Created by: dengbw
|
|
* @param $groupsId
|
|
* @param array $data
|
|
* @return array
|
|
*/
|
|
private function getLevelAry($groupsId, $data = [])
|
|
{
|
|
$re = $this->mdSyliveGroups->get(['groupsId' => $groupsId], 'groupsId,parentId,groupsLevel');
|
|
if (!$re) {
|
|
return $data;
|
|
} else {
|
|
if ($re['groupsLevel']) {//分类id
|
|
$levelId = "levelId" . $re['groupsLevel'];
|
|
$data[$levelId] = $re['groupsId'];
|
|
}
|
|
if ($re['parentId']) {
|
|
return $this->getLevelAry($re['parentId'], $data);
|
|
} else {
|
|
return $data;
|
|
}
|
|
}
|
|
}
|
|
|
|
private function dataSelect($params)
|
|
{
|
|
$activityId = intval($params['activityId']);
|
|
$page = $params['page'];
|
|
$limit = $params['limit'];
|
|
$name = $params['name'];
|
|
$mobile = $params['mobile'];
|
|
$bizId = $params['bizId'];
|
|
$status = $params['status'];
|
|
$visitTagId = $params['visitTagId'];
|
|
$sort = $params['sort'];
|
|
$order = $params['order'];
|
|
$createTimeStart = $this->input_param('createTimeStart');
|
|
$createTimeEnd = $this->input_param('createTimeEnd');
|
|
!$page && $page = 1;
|
|
!$limit && $limit = 10;
|
|
$levels = [];
|
|
$re_gro = $this->mdSyliveGroups->get(['activityId' => $activityId, 'parentId' => 0, 'status>=' => 0]);
|
|
if ($re_gro['statisticsType']) {
|
|
$this->load->model('market/Market_sys_dictionary_data_model', 'mdSysDictionaryData');
|
|
$res_dit = $this->mdSysDictionaryData->select(['status>=' => 0, 'dictId' => $re_gro['statisticsType']], 'sortNumber asc,dictDataId desc'
|
|
, 0, 0, 'dictDataCode,dictDataName');
|
|
foreach ($res_dit as $k => $v) {
|
|
$groupsLevel = intval($v['dictDataCode']);
|
|
$re_gro = $this->mdSyliveGroups->get(['activityId' => $activityId, 'groupsLevel' => $groupsLevel, 'status>=' => 0]);
|
|
if ($re_gro) {
|
|
$levels[] = ['label' => $v['dictDataName'], 'prop' => "levelName{$groupsLevel}"];
|
|
}
|
|
}
|
|
}
|
|
$sort_order = 'customerId desc';
|
|
if ($sort && $order) {
|
|
$sort_order = $sort . ' ' . $order;
|
|
}
|
|
$list = [];
|
|
if (strlen($status)) {
|
|
$where["status"] = $status;
|
|
} else {
|
|
$where["status>=0"] = null;
|
|
}
|
|
$activityId && $where['activityId'] = $activityId;
|
|
$name && $where['name LIKE "%' . trim($name) . '%"'] = null;
|
|
$mobile && $where['mobile LIKE "%' . trim($mobile) . '%"'] = null;
|
|
$visitTagId && $where['visitTagId'] = $visitTagId;
|
|
$createTimeStart && $where['createTime>='] = $createTimeStart;
|
|
$createTimeEnd && $where['createTime<='] = $createTimeEnd;
|
|
if ($bizId) {
|
|
$res_org = $this->mdSyliveGroups->get(["groupsId" => $bizId]);
|
|
if ($res_org) {
|
|
if ($res_org['groupsLevel']) {
|
|
$levelId = 'levelId' . $res_org['groupsLevel'];
|
|
$where[$levelId] = $bizId;
|
|
} else if ($res_org['parentId']) {//门店
|
|
$where['bizId'] = $bizId;
|
|
}
|
|
}
|
|
}
|
|
$count = $this->mdSyliveCustomer->count($where);
|
|
if ($limit >= 10000 && $count > 10000) {
|
|
$this->return_json('导出失败,每次导出不能超出10000条数据');
|
|
}
|
|
if ($count) {
|
|
$re = $this->mdSyliveActivity->get(['activityId' => $activityId], 'jsondata');
|
|
$jsonData = $re['jsondata'] ? json_decode($re['jsondata'], true) : [];
|
|
$visitTagAry = $this->mdSyliveCustomer->visitTagAry();
|
|
$statusAry = $this->mdSyliveCustomer->statusAry();
|
|
$res = $this->mdSyliveCustomer->select($where, $sort_order, $page, $limit);
|
|
foreach ($res as $v) {
|
|
$consultant = $this->consultantGet(['activityId' => $v['activityId']
|
|
, 'levelId1' => $v['levelId1'], 'levelId2' => $v['levelId2'], 'levelId3' => $v['levelId3']
|
|
, 'bizId' => $v['bizId'], 'cfUserId' => $v['cfUserId']]);
|
|
$status = intval($v['status']);
|
|
$statusName = $statusAry[$status];
|
|
$visitTagName = '';
|
|
$visitTagId = $v['visitTagId'];
|
|
if ($visitTagId) {
|
|
$visitTagName = $visitTagAry[$visitTagId];
|
|
if ($jsonData['visitTag'][$visitTagId]) {
|
|
$visitTagName = $visitTagName . '(' . $jsonData['visitTag'][$visitTagId] . ')';
|
|
}
|
|
}
|
|
$list1 = [
|
|
'customerId' => $v['customerId'], 'name' => $v['name'], 'mobile' => $v['mobile']
|
|
, 'statusName' => $statusName, 'visitTagName' => $visitTagName, 'consultant' => $consultant['consultant']
|
|
];
|
|
if ($limit >= 10000) {
|
|
unset($list1['customerId']);
|
|
}
|
|
$list2 = [];
|
|
foreach ($levels as $k2 => $v2) {
|
|
$list2[$v2['prop']] = $consultant[$v2['prop']] ? $consultant[$v2['prop']] : '';
|
|
}
|
|
$item = count($list2) ? array_merge($list1, $list2) : $list1;
|
|
$item['stores'] = $consultant['stores'];
|
|
$list[] = $item;
|
|
}
|
|
}
|
|
if ($limit >= 10000) {
|
|
$columns1 = ['姓名', '手机号', '状态', '回访标签', '顾问'];
|
|
$columns2 = [];
|
|
foreach ($levels as $k => $v) {
|
|
$columns2[] = $v['label'];
|
|
}
|
|
$columns3 = count($columns2) ? array_merge($columns1, $columns2) : $columns1;
|
|
$columns = array_merge($columns3, ['门店']);
|
|
return ['list' => $list, 'columns' => $columns];
|
|
} else {
|
|
$columns = '';
|
|
if ($page == 1) {
|
|
$columns1 = [
|
|
['prop' => 'customerId', 'label' => 'ID', 'align' => 'center', 'showOverflowTooltip' => true, 'minWidth' => 45, 'fixed' => 'left'],
|
|
['prop' => 'name', 'label' => '姓名', 'showOverflowTooltip' => true, 'minWidth' => 60],
|
|
['prop' => 'mobile', 'label' => '手机号', 'showOverflowTooltip' => true, 'minWidth' => 60],
|
|
['prop' => 'statusName', 'label' => '状态', 'showOverflowTooltip' => true, 'minWidth' => 60, 'align' => 'center'],
|
|
['prop' => 'visitTagName', 'label' => '回访标签', 'showOverflowTooltip' => true, 'minWidth' => 100, 'align' => 'center'],
|
|
['prop' => 'consultant', 'label' => '顾问', 'showOverflowTooltip' => true, 'minWidth' => 60]
|
|
];
|
|
$columns2 = [];
|
|
foreach ($levels as $k => $v) {
|
|
$columns2[] = ['prop' => $v['prop'], 'label' => $v['label'], 'showOverflowTooltip' => true, 'minWidth' => 80];
|
|
}
|
|
$columns = count($columns2) ? array_merge($columns1, $columns2) : $columns1;
|
|
$columns[] = ['prop' => 'stores', 'label' => '门店', 'showOverflowTooltip' => true, 'minWidth' => 80];
|
|
}
|
|
return ['list' => $list, 'count' => $count, 'columns' => $columns];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Notes:获取顾问信息
|
|
* Created on: 2022/12/08 11:29
|
|
* Created by: dengbw
|
|
* @param $params
|
|
* @return string
|
|
*/
|
|
private function consultantGet($params)
|
|
{
|
|
$stores = $consultant = $levelName1 = $levelName2 = $levelName3 = '';
|
|
$levelId1 = intval($params['levelId1']);
|
|
$levelId2 = intval($params['levelId2']);
|
|
$levelId3 = intval($params['levelId3']);
|
|
$bizId = intval($params['bizId']);
|
|
$cfUserId = intval($params['cfUserId']);
|
|
if ($bizId) {
|
|
$res_org = $this->mdSyliveGroups->get(["groupsId" => $bizId]);
|
|
$res_org['groupsName'] && $stores = $res_org['groupsName'];
|
|
}
|
|
if ($levelId1) {
|
|
$res_org = $this->mdSyliveGroups->get(["groupsId" => $levelId1]);
|
|
$res_org['groupsName'] && $levelName1 = $res_org['groupsName'];
|
|
}
|
|
if ($levelId2) {
|
|
$res_org = $this->mdSyliveGroups->get(["groupsId" => $levelId2]);
|
|
$res_org['groupsName'] && $levelName2 = $res_org['groupsName'];
|
|
}
|
|
if ($levelId3) {
|
|
$res_org = $this->mdSyliveGroups->get(["groupsId" => $levelId3]);
|
|
$res_org['groupsName'] && $levelName3 = $res_org['groupsName'];
|
|
}
|
|
if($cfUserId){
|
|
$re_user = $this->mdSyliveUser->get(['userId' => $cfUserId]);
|
|
$re_user['uname'] && $consultant = $re_user['uname'];
|
|
}
|
|
return ['stores' => $stores, 'consultant' => $consultant, 'levelName1' => $levelName1,
|
|
'levelName2' => $levelName2, 'levelName3' => $levelName3];
|
|
}
|
|
|
|
private function upload()
|
|
{
|
|
$config['upload_path'] = $_SERVER['DOCUMENT_ROOT'] . '/temp/';
|
|
$config['allowed_types'] = '*';
|
|
$config['max_size'] = 5120;
|
|
$config['file_name'] = 'customer_' . time() . rand(1, 99999);
|
|
$this->load->library('upload', $config);
|
|
if (!$this->upload->do_upload('file')) {
|
|
return ['code' => SYS_CODE_FAIL, 'message' => $this->upload->display_errors('', '')];
|
|
} else {
|
|
$data = $this->upload->data();
|
|
return ['code' => SYS_CODE_SUCCESS, 'path' => $data['full_path'], 'file_ext' => $data['file_ext']];
|
|
}
|
|
}
|
|
|
|
}
|