425 lines
20 KiB
PHP
425 lines
20 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
require_once APPPATH . 'controllers/api/BaseController.php';
|
|
|
|
/**
|
|
* Notes:私域直播_分组订单管理
|
|
* Created on: 2022/12/08 17:15
|
|
* Created by: dengbw
|
|
*/
|
|
class groupsOrder extends BaseController
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('market/Market_sylive_order_model', 'mdSyliveOrder');
|
|
$this->load->model('market/Market_sylive_user_model', 'mdSyliveUser');
|
|
$this->load->model('market/Market_sylive_activity_kpidata_model', 'mdSyliveActivityKpidata');
|
|
$this->load->model('market/Market_sylive_groups_model', 'mdSyliveGroups');
|
|
$this->load->model('market/Market_sylive_user_model', 'mdSyliveUser');
|
|
}
|
|
|
|
/**
|
|
* Notes:订单管理列表
|
|
* Created on: 2022/12/08 14:48
|
|
* Created by: dengbw
|
|
*/
|
|
public function index_get()
|
|
{
|
|
$date = $this->orderList($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->orderList($this->inputs);
|
|
$this->return_response_list($date);
|
|
}
|
|
|
|
private function orderList($params)
|
|
{
|
|
$activityId = intval($params['activityId']);
|
|
$page = $params['page'];
|
|
$limit = $params['limit'];
|
|
$uname = $params['uname'];
|
|
$mobile = $params['mobile'];
|
|
$status = $params['status'];
|
|
$type = $params['type'];
|
|
$sort = $params['sort'];
|
|
$order = $params['order'];
|
|
$bizId = $params['bizId'];
|
|
$itemId = $params['itemId'];
|
|
$insiders = intval($params['insiders']);//内部人员
|
|
$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 = 'id desc';
|
|
if ($sort && $order) {
|
|
if ($sort == 'statusName') {
|
|
$sort_order = 'status ' . $order;
|
|
} else if ($sort == 'typeName') {
|
|
$sort_order = 'type ' . $order;
|
|
} else if ($sort == 'cfromName') {
|
|
$sort_order = 'cfrom ' . $order;
|
|
} else {
|
|
$sort_order = $sort . ' ' . $order;
|
|
}
|
|
}
|
|
$list = [];
|
|
if (!strlen($status)) {
|
|
$status = 1;
|
|
}
|
|
$where['status'] = $status;
|
|
$activityId && $where['activityId'] = $activityId;
|
|
$itemId && $where['itemId'] = $itemId;
|
|
$uname && $where['uname LIKE "%' . trim($uname) . '%"'] = null;
|
|
$mobile && $where['mobile LIKE "%' . trim($mobile) . '%"'] = null;
|
|
strlen($type) && $where['type'] = $type;
|
|
$createTimeStart && $where['createTime>='] = $createTimeStart;
|
|
$createTimeEnd && $where['createTime<='] = $createTimeEnd;
|
|
if ($insiders == 1) {
|
|
$where["userId in(select userId from lc_market_sylive_user where organizationId>0)"] = null;
|
|
} else if ($insiders == 2) {
|
|
$where["userId not in(select userId from lc_market_sylive_user where organizationId>0)"] = null;
|
|
}
|
|
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->mdSyliveOrder->count($where);
|
|
if ($limit >= 10000 && $count > 10000) {
|
|
$this->return_json('导出失败,每次导出不能超出10000条数据');
|
|
}
|
|
if ($count) {
|
|
$res = $this->mdSyliveOrder->select($where, $sort_order, $page, $limit);
|
|
$userIds = implode(',', array_column($res, 'userId'));
|
|
$map_user = $this->mdSyliveUser->map('userId', 'organizationId', ["userId in({$userIds})" => null]);
|
|
foreach ($res as $v) {
|
|
$consultant = $this->consultantGet(['activityId' => $v['activityId'], 'userId' => $v['userId']
|
|
, 'levelId1' => $v['levelId1'], 'levelId2' => $v['levelId2'], 'levelId3' => $v['levelId3']
|
|
, 'bizId' => $v['bizId'], 'cfUserId' => $v['cfUserId']]);
|
|
$insiders = $map_user[$v['userId']] ? '是' : '否';//内部人员
|
|
$list1 = [
|
|
'id' => $v['id'], 'sid' => $v['sid'], 'uname' => $v['uname'], 'mobile' => $v['mobile'], 'itemTitle' => $v['itemTitle']
|
|
, 'totalPrice' => $v['totalPrice'], 'payTime' => $v['payTime'] != '0000-00-00 00:00:00' ? $v['payTime'] : ''
|
|
, 'createTime' => $v['createTime'], 'typeName' => $this->mdSyliveOrder->typeAry($v['type'])
|
|
, 'statusName' => $this->mdSyliveOrder->statusAry($v['status']), 'insiders' => $insiders, 'consultant' => $consultant['consultant']
|
|
];
|
|
if ($limit >= 10000) {
|
|
unset($list1['id']);
|
|
$list1['consultantMobile'] = $consultant['consultantMobile'];
|
|
} else {
|
|
unset($list1['sid']);
|
|
}
|
|
$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'];
|
|
if ($limit >= 10000) {
|
|
$address = $biz = '';
|
|
$jsondata = $v['jsondata'] ? json_decode($v['jsondata'], true) : [];
|
|
if ($jsondata['address']) {
|
|
$address = $jsondata['address']['region'] . $jsondata['address']['detail'];
|
|
}
|
|
if ($jsondata['biz']) {
|
|
$biz = $jsondata['biz'];
|
|
}
|
|
$item['biz'] = $biz;
|
|
$item['address'] = $address;
|
|
}
|
|
$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' => 'id', 'label' => 'ID', 'align' => 'center', 'showOverflowTooltip' => true, 'minWidth' => 45, 'fixed' => 'left'],
|
|
['prop' => 'uname', 'label' => '姓名', 'showOverflowTooltip' => true, 'minWidth' => 60],
|
|
['prop' => 'mobile', 'label' => '手机号', 'showOverflowTooltip' => true, 'minWidth' => 80],
|
|
['prop' => 'itemTitle', 'label' => '商品标题', 'showOverflowTooltip' => true, 'minWidth' => 130],
|
|
['prop' => 'totalPrice', 'label' => '订单价格', 'showOverflowTooltip' => true, 'minWidth' => 70, 'sortable' => 'custom'],
|
|
['prop' => 'payTime', 'label' => '付款时间', 'showOverflowTooltip' => true, 'minWidth' => 100, 'sortable' => 'custom'],
|
|
['prop' => 'createTime', 'label' => '创建时间', 'showOverflowTooltip' => true, 'minWidth' => 100, 'sortable' => 'custom'],
|
|
['prop' => 'typeName', 'label' => '订单类型', 'showOverflowTooltip' => true, 'minWidth' => 60],
|
|
['prop' => 'statusName', 'label' => '状态', 'showOverflowTooltip' => true, 'minWidth' => 60],
|
|
['prop' => 'insiders', 'label' => '内部人员', 'showOverflowTooltip' => true, 'minWidth' => 60],
|
|
['prop' => 'consultant', 'label' => '顾问', 'showOverflowTooltip' => true, 'minWidth' => 55]
|
|
];
|
|
$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 = $consultantMobile = $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) {
|
|
$re = $this->mdSyliveActivityKpidata->get(['activityId' => $params['activityId'], 'userId' => $params['userId'], 'kpi' => 'order']);
|
|
if ($re) {
|
|
$levelId1 = $re['levelId1'];
|
|
$levelId2 = $re['levelId2'];
|
|
$levelId3 = $re['levelId3'];
|
|
$bizId = $re['bizId'];
|
|
$cfUserId = $re['cfUserId'];
|
|
}
|
|
}
|
|
$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'];
|
|
}
|
|
$re_user = $this->mdSyliveUser->get(['userId' => $cfUserId]);
|
|
if ($re_user['uname']) {
|
|
$consultant = $re_user['uname'];
|
|
$consultantMobile = $re_user['mobile'];
|
|
}
|
|
return ['stores' => $stores, 'consultant' => $consultant, 'consultantMobile' => $consultantMobile, 'levelName1' => $levelName1,
|
|
'levelName2' => $levelName2, 'levelName3' => $levelName3];
|
|
}
|
|
|
|
/**
|
|
* Notes:导入订单
|
|
* Created on: 2023/4/26 17:24
|
|
* Created by: dengbw
|
|
* @throws PHPExcel_Exception
|
|
* @throws PHPExcel_Reader_Exception
|
|
*/
|
|
public function import_post()
|
|
{
|
|
$activityId = intval($_POST['activityId']);
|
|
if (!$activityId) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
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请拆分多个表格导入');
|
|
}
|
|
$this->load->model('market/Market_sylive_items_model', 'mdSyliveItems');
|
|
$this->load->model('market/Market_sylive_groups_user_model', 'mdSyliveGroupsUser');
|
|
$this->load->library('market/sylive2_entity');
|
|
$done = 0;
|
|
for ($_row = 2; $_row <= $rowCnt; $_row++) { //读取内容
|
|
$itemId = $itemPrice = $totalPrice = $cfUserId = $bizId = $levelId1 = $levelId2 = $levelId3 = $userId = $cfUserId = 0;
|
|
$sid = $objWorksheet->getCell('A' . $_row)->getValue();
|
|
$mobile = $objWorksheet->getCell('C' . $_row)->getValue();
|
|
$itemTitle = $objWorksheet->getCell('D' . $_row)->getValue();
|
|
if ($mobile) {
|
|
$where = ['mobile' => $mobile, "activityId" => $activityId];
|
|
if ($itemTitle) {
|
|
$re_order = $this->mdSyliveItems->get(['title' => $itemTitle, "activityId" => $activityId]);
|
|
if ($re_order) {
|
|
$where["itemId"] = $re_order['itemId'];
|
|
$itemId = $re_order['itemId'];
|
|
$itemPrice = $re_order['price'];
|
|
}
|
|
}
|
|
$re_order = $this->mdSyliveOrder->get($where);
|
|
if (!$re_order) {
|
|
$uname = $objWorksheet->getCell('B' . $_row)->getValue();
|
|
$totalPrice = $objWorksheet->getCell('E' . $_row)->getValue();
|
|
$createTime = $objWorksheet->getCell('F' . $_row)->getValue();
|
|
$bizName = $objWorksheet->getCell('G' . $_row)->getValue();
|
|
$cfMobile = $objWorksheet->getCell('I' . $_row)->getValue();
|
|
if ($cfMobile) {
|
|
$re_user = $this->mdSyliveUser->get(['mobile' => $cfMobile, 'organizationId>' => 0, 'status<>' => -1]);
|
|
if ($re_user['userId']) {
|
|
$cfUserId = $re_user['userId'];
|
|
$re_groUser = $this->mdSyliveGroupsUser->get(['activityId' => $activityId, 'userId' => $cfUserId, 'status<>' => -1]);
|
|
if ($re_groUser['bizId']) {
|
|
$bizId = $re_groUser['bizId'];
|
|
$levelId1 = $re_groUser['levelId1'];
|
|
$levelId2 = $re_groUser['levelId2'];
|
|
$levelId3 = $re_groUser['levelId3'];
|
|
}
|
|
}
|
|
}
|
|
if (!$bizId && $bizName) {
|
|
$re_gro = $this->mdSyliveGroups->get(['activityId' => $activityId, 'groupsName' => $bizName, 'ifBiz' => 1, 'status<>' => -1]);
|
|
if ($re_gro['groupsId']) {
|
|
$bizId = $re_gro['groupsId'];
|
|
$levelAry = $this->getLevelAry($re_gro['parentId']);
|
|
$levelAry['levelId1'] && $levelId1 = $levelAry['levelId1'];
|
|
$levelAry['levelId2'] && $levelId2 = $levelAry['levelId2'];
|
|
$levelAry['levelId3'] && $levelId3 = $levelAry['levelId3'];
|
|
}
|
|
}
|
|
//$re_user2 = $this->mdSyliveUser->get(['mobile' => $mobile, 'status<>' => -1]);
|
|
//手机号和订单金额为0的订单
|
|
$re_order = $this->mdSyliveOrder->get(['mobile' => $mobile, 'totalPrice' => 0]);
|
|
if ($re_order['userId']) {
|
|
$userId = $re_order['userId'];
|
|
}
|
|
!$sid && $sid = create_order_no('350200', 'market');
|
|
!$createTime && $createTime = "0000-00-00 00:00:00";
|
|
$addData = [
|
|
'itemId' => $itemId,
|
|
'itemTitle' => $itemTitle,
|
|
'itemPrice' => $itemPrice,
|
|
'createTime' => $createTime,
|
|
'payTime' => $createTime,
|
|
'totalPrice' => $totalPrice,
|
|
'uname' => $uname,
|
|
'mobile' => $mobile,
|
|
'status' => 1,
|
|
'activityId' => $activityId,
|
|
'sid' => $sid,
|
|
'bizId' => $bizId,
|
|
'levelId1' => $levelId1,
|
|
'levelId2' => $levelId2,
|
|
'levelId3' => $levelId3,
|
|
'userId' => $userId,
|
|
'cfUserId' => $cfUserId,
|
|
];
|
|
$id = $this->mdSyliveOrder->add($addData);
|
|
if ($id) {
|
|
//私域通增加记录
|
|
if ($cfUserId) {
|
|
$params = [
|
|
'a_id' => $activityId,
|
|
'uid' => $userId,
|
|
'cf_uid' => $cfUserId,
|
|
'kpi' => 'order',
|
|
'tagId' => $id,
|
|
'jsondata' => ['order_id' => $id, 'sid' => $sid],
|
|
'itemId' => $itemId,
|
|
'c_time' => strtotime($createTime)
|
|
];
|
|
$this->sylive2_entity->kpi_log($params);
|
|
}
|
|
$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 upload()
|
|
{
|
|
$config['upload_path'] = $_SERVER['DOCUMENT_ROOT'] . '/temp/';
|
|
$config['allowed_types'] = '*';
|
|
$config['max_size'] = 5120;
|
|
$config['file_name'] = 'exchange_' . 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']];
|
|
}
|
|
}
|
|
|
|
} |