450 lines
20 KiB
PHP
450 lines
20 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
require_once APPPATH . 'controllers/api/BaseController.php';
|
|
|
|
/**
|
|
* Notes:私域直播_核销记录管理
|
|
* Created on: 2023/2/15 17:15
|
|
* Created by: dengbw
|
|
*/
|
|
class groupsExchange extends BaseController
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('market/Market_sylive_order_model', 'mdSyliveOrder');
|
|
$this->load->model('market/Market_sylive_checkdata_model', 'mdSyliveCheckdata');
|
|
$this->load->model('market/Market_sylive_user_model', 'mdSyliveUser');
|
|
$this->load->model('market/Market_sys_admin_model', 'mdSysAdmin');
|
|
$this->load->model('market/Market_sylive_groups_model', 'mdSyliveGroups');
|
|
$this->load->model('market/Market_sylive_activity_kpidata_model', 'mdSyliveActivityKpidata');
|
|
$this->load->model('market/Market_sylive_items_model', 'mdSyliveItems');
|
|
}
|
|
|
|
/**
|
|
* 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'] = 10000;
|
|
$date = $this->orderList($this->inputs);
|
|
$this->return_response_list($date);
|
|
}
|
|
|
|
/**
|
|
* Notes:操作详情
|
|
* Created on: 2023/2/21 9:45
|
|
* Created by: dengbw
|
|
*/
|
|
public function detail_get()
|
|
{
|
|
$cfId = intval($this->input_param('cfId'));
|
|
$type = intval($this->input_param('type'));
|
|
$ifCheckAry = [0 => '未审核', 1 => '通过', -1 => '驳回'];
|
|
$date = [];
|
|
$where = ['cfId' => $cfId, 'type' => $type];
|
|
$res = $this->mdSyliveCheckdata->select($where, 'id DESC', 0, 0);
|
|
if ($res) {
|
|
$address = '';
|
|
$re = $this->mdSyliveOrder->get(['id' => $cfId]);
|
|
if ($re['jsondata']) {
|
|
$jsondata = json_decode($re['jsondata'], true);
|
|
if ($jsondata['address']) {
|
|
$address = $jsondata['address']['region'] . $jsondata['address']['detail'];
|
|
}
|
|
}
|
|
$this->load->library('AliWuliu');
|
|
$cfUids = implode(',', array_column($res, 'cfUid'));
|
|
$map_users = $cfUids ? $this->mdSyliveUser->map('userId', 'uname,nickname', ["userId in({$cfUids})" => null]) : [];
|
|
$adminUids = implode(',', array_column($res, 'adminUid'));
|
|
$map_admins = $adminUids ? $this->mdSysAdmin->map('userId', 'username,nickname', ["userId in({$adminUids})" => null]) : [];
|
|
foreach ($res as $v) {
|
|
$cfName = $adminName = $adminTime = '';
|
|
$mapUser = $map_users[$v['cfUid']];
|
|
if ($mapUser) {
|
|
$cfName = $mapUser['uname'] ? $mapUser['uname'] : $mapUser['nickname'];
|
|
}
|
|
$mapAdmin = $map_admins[$v['adminUid']];
|
|
if ($mapAdmin) {
|
|
$adminName = $mapAdmin['nickname'] ? $mapAdmin['nickname'] : $mapAdmin['username'];
|
|
}
|
|
$jsondata = $v['jsondata'] ? json_decode($v['jsondata'], true) : [];
|
|
$logistics = [];
|
|
if ($jsondata) {
|
|
$jsondata['adminTime'] && $adminTime = $jsondata['adminTime'];
|
|
$courierNo = $jsondata['courierNo'];
|
|
if ($courierNo) {
|
|
if (strstr($courierNo, 'SF') || strstr($courierNo, 'FW')) {
|
|
$re_order = $this->mdSyliveOrder->get(['id' => $v['cfId']]);
|
|
if ($re_order['mobile']) {
|
|
$courierNo = $courierNo . ':' . substr($re_order['mobile'], -4);
|
|
}
|
|
}
|
|
$re_wl = $this->aliwuliu->kdi($courierNo, '', $debug = false);
|
|
if ($re_wl['code'] == 1 && $re_wl['result']) {
|
|
$result = $re_wl['result'];
|
|
$expName = $result['expName'] ? $result['expName'] : '物流单号';
|
|
$logistics[] = ['time' => $expName, 'status' => $jsondata['courierNo']];
|
|
foreach ($result['list'] as $v2) {
|
|
$logistics[] = $v2;
|
|
}
|
|
} else {
|
|
$logistics[] = ['time' => '物流单号', 'status' => $jsondata['courierNo']];
|
|
}
|
|
}
|
|
}
|
|
$cfTime = date('Y-m-d H:i:s', $v['createTime']);
|
|
$address = count($logistics) ? $address : '';
|
|
$date[] = ['adminName' => $adminName, 'adminTime' => $adminTime, 'cfName' => $cfName, 'cfTime' => $cfTime
|
|
, 'logistics' => $logistics, 'descrip' => $v['descrip'], 'address' => $address
|
|
, 'ifCheckName' => $ifCheckAry[$v['ifCheck']]];
|
|
}
|
|
}
|
|
$this->return_response_list($date);
|
|
}
|
|
|
|
/**
|
|
* Notes:审核数据
|
|
* Created on: 2023/2/21 14:43
|
|
* Created by: dengbw
|
|
*/
|
|
public function status_put()
|
|
{
|
|
$cfId = intval($this->input_param('cfId'));
|
|
$type = intval($this->input_param('type'));
|
|
$useStatus = $this->input_param('useStatus');
|
|
$descrip = $this->input_param('descrip');
|
|
if (!$cfId) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
$ret = $this->updateCheck(['cfId' => $cfId, 'type' => $type, 'useStatus' => $useStatus, 'descrip' => $descrip]);
|
|
if (!$ret) {
|
|
$this->return_json('审核失败');
|
|
}
|
|
$this->return_response();
|
|
}
|
|
|
|
/**
|
|
* 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请拆分多个表格导入');
|
|
}
|
|
$done = 0;
|
|
for ($_row = 2; $_row <= $rowCnt; $_row++) { //读取内容
|
|
$sid = $objWorksheet->getCell('A' . $_row)->getValue();
|
|
if ($sid) {
|
|
$re_order = $this->mdSyliveOrder->get(['sid' => $sid]);
|
|
$cfId = $re_order['id'];
|
|
if ($cfId) {
|
|
$useStatus = $objWorksheet->getCell('B' . $_row)->getValue();
|
|
$descrip = '';
|
|
if ($useStatus == '通过') {
|
|
$useStatus = 2;
|
|
$courierNo = $objWorksheet->getCell('C' . $_row)->getValue();
|
|
$courierNo && $descrip = $courierNo;
|
|
} else {
|
|
$useStatus = 3;
|
|
$getDescrip = $objWorksheet->getCell('D' . $_row)->getValue();
|
|
$getDescrip && $descrip = $getDescrip;
|
|
}
|
|
$getType = $objWorksheet->getCell('E' . $_row)->getValue();
|
|
$type = $getType == '抽奖' ? 1 : 0;
|
|
$ret = $this->updateCheck(['cfId' => $cfId, 'type' => $type, 'useStatus' => $useStatus, 'descrip' => $descrip]);
|
|
if ($ret) {
|
|
$done++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@unlink($file);
|
|
$this->return_response('', "成功审核{$done}条");
|
|
}
|
|
|
|
private function updateCheck($params = [])
|
|
{
|
|
$cfId = $params['cfId'];
|
|
$type = $params['type'];
|
|
$useStatus = $params['useStatus'];
|
|
$descrip = $params['descrip'];
|
|
$ifCheck = 0;
|
|
$jsonData['adminTime'] = date('Y-m-d H:i:s');
|
|
if ($useStatus == 2) {
|
|
$ifCheck = 1;
|
|
$upDate['ifCheck'] = $ifCheck;
|
|
$jsonData['courierNo'] = $descrip;
|
|
} else if ($useStatus == 3) {
|
|
$ifCheck = -1;
|
|
$upDate['descrip'] = $descrip;
|
|
}
|
|
$upDate['ifCheck'] = $ifCheck;
|
|
$upDate['jsondata'] = json_encode($jsonData, JSON_UNESCAPED_UNICODE);
|
|
$re = $this->mdSyliveCheckdata->max('id', ['cfId' => $cfId, 'type' => $type]);
|
|
if ($re['id']) {
|
|
$this->mdSyliveCheckdata->update($upDate, ['id' => $re['id']]);
|
|
}
|
|
$upDate = [];
|
|
if ($type == 1) {
|
|
$upDate['winUseStatus'] = $useStatus;
|
|
} else {
|
|
$upDate['useStatus'] = $useStatus;
|
|
}
|
|
$ret = $this->mdSyliveOrder->update($upDate, ['id' => $cfId]);
|
|
return $ret;
|
|
}
|
|
|
|
private function orderList($params)
|
|
{
|
|
$activityId = intval($params['activityId']);
|
|
$page = $params['page'];
|
|
$limit = $params['limit'];
|
|
$uname = $params['uname'];
|
|
$mobile = $params['mobile'];
|
|
$sort = $params['sort'];
|
|
$order = $params['order'];
|
|
$bizId = $params['bizId'];
|
|
$itemId = $params['itemId'];
|
|
!$page && $page = 1;
|
|
!$limit && $limit = 10;
|
|
$levels = [];
|
|
if ($page == 1) {
|
|
$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) {
|
|
$sort_order = $sort . ' ' . $order;
|
|
}
|
|
$list = [];
|
|
$useType = intval($params['useType']);
|
|
$useStatus = intval($params['useStatus']);
|
|
if ($useType == 1) {
|
|
$exchangeName = '抽奖';
|
|
if ($useStatus) {
|
|
$where['winUseStatus'] = $useStatus;
|
|
} else {
|
|
$where['winUseStatus>'] = 0;
|
|
}
|
|
} else {
|
|
$exchangeName = '订单';
|
|
if ($useStatus) {
|
|
$where['useStatus'] = $useStatus;
|
|
} else {
|
|
$where['useStatus>'] = 0;
|
|
}
|
|
}
|
|
$activityId && $where['activityId'] = $activityId;
|
|
$itemId && $where['itemId'] = $itemId;
|
|
$uname && $where['uname LIKE "%' . trim($uname) . '%"'] = null;
|
|
$mobile && $where['mobile LIKE "%' . trim($mobile) . '%"'] = 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;
|
|
}
|
|
}
|
|
}
|
|
if ($limit == 10000) {
|
|
$count = $limit;
|
|
} else {
|
|
$count = $this->mdSyliveOrder->count($where);
|
|
}
|
|
if ($count) {
|
|
$res = $this->mdSyliveOrder->select($where, $sort_order, $page, $limit);
|
|
$itemIds = implode(',', array_column($res, 'itemId'));
|
|
$map_items = $this->mdSyliveItems->map('itemId', 'ifAddress', ["itemId in({$itemIds})" => 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']]);
|
|
$useStatus = $useType == 1 ? $v['winUseStatus'] : $v['useStatus'];
|
|
$useStatusName = '未审核';
|
|
if ($useStatus == 2) {
|
|
$useStatusName = '通过';
|
|
} else if ($useStatus == 3) {
|
|
$useStatusName = '驳回';
|
|
}
|
|
$ifAddress = intval($map_items[$v['itemId']]);
|
|
$list1 = [
|
|
'id' => $v['id'], 'sid' => $v['sid'], 'uname' => $v['uname'], 'mobile' => $v['mobile'], 'itemTitle' => $v['itemTitle']
|
|
, 'totalPrice' => $v['totalPrice'], 'exchangeName' => $exchangeName
|
|
, 'useStatusName' => $useStatusName, 'consultant' => $consultant['consultant']
|
|
, 'ifAddress' => $ifAddress, 'useStatus' => intval($useStatus)
|
|
];
|
|
if ($limit == 10000) {
|
|
unset($list1['id']);
|
|
unset($list1['ifAddress']);
|
|
unset($list1['useStatus']);
|
|
} 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' => 60],
|
|
['prop' => 'exchangeName', 'label' => '核销类型', 'showOverflowTooltip' => true, 'minWidth' => 60, 'align' => 'center'],
|
|
['prop' => 'useStatus', 'label' => '状态', 'showOverflowTooltip' => true, 'minWidth' => 60, 'align' => 'center', 'slot' => 'useStatus'],
|
|
['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];
|
|
$columns[] = ['columnKey' => 'action', 'label' => '操作', 'showOverflowTooltip' => true, 'width' => 150, 'align' => 'center'
|
|
, 'resizable' => false, 'slot' => 'action'];
|
|
}
|
|
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) {
|
|
$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]);
|
|
$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'] = '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']];
|
|
}
|
|
}
|
|
|
|
} |