250 lines
11 KiB
PHP
250 lines
11 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 groupsWin 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_activity_draw_model', 'mdSyliveActivityDraw');
|
|
$this->load->model('market/Market_sylive_organization_model', 'mdSyliveOrganization');
|
|
$this->load->model('market/Market_sylive_team_model', 'mdSyliveTeam');
|
|
}
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
|
|
/**
|
|
* Notes:中奖类型
|
|
* Created on: 2022/12/08 15:26
|
|
* Created by: dengbw
|
|
*/
|
|
public function win_type_get()
|
|
{
|
|
$activityId = intval($this->input_param('activityId'));
|
|
$re_draw = $this->mdSyliveActivityDraw->get(['activityId' => $activityId]);
|
|
$date = [];
|
|
if ($re_draw && $re_draw['winType']) {
|
|
$json_winType = json_decode($re_draw['winType'], true);
|
|
foreach ($json_winType as $v) {
|
|
$date[] = ['id' => $v['id'], 'name' => $v['title']];
|
|
}
|
|
}
|
|
$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'];
|
|
$type = $params['type'];
|
|
$sort = $params['sort'];
|
|
$order = $params['order'];
|
|
$bizId = $params['bizId'];
|
|
$itemId = $params['itemId'];
|
|
$winType = $params['winType'];
|
|
!$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 = 'winTime desc';
|
|
if ($sort && $order) {
|
|
$sort_order = $sort . ' ' . $order;
|
|
}
|
|
$list = [];
|
|
$where['status'] = 1;
|
|
$where['win'] = 1;
|
|
$activityId && $where['activityId'] = $activityId;
|
|
$itemId && $where['itemId'] = $itemId;
|
|
$winType && $where['winType'] = $winType;
|
|
$uname && $where['uname LIKE "%' . trim($uname) . '%"'] = null;
|
|
$mobile && $where['mobile LIKE "%' . trim($mobile) . '%"'] = null;
|
|
strlen($type) && $where['type'] = $type;
|
|
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) {
|
|
$winTypeAry = [];
|
|
$re_draw = $this->mdSyliveActivityDraw->get(['activityId' => $activityId]);
|
|
if ($re_draw && $re_draw['winType']) {
|
|
$json_winType = json_decode($re_draw['winType'], true);
|
|
foreach ($json_winType as $v) {
|
|
$winTypeAry[$v['id']] = $v['title'];
|
|
}
|
|
}
|
|
$res = $this->mdSyliveOrder->select($where, $sort_order, $page, $limit);
|
|
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']]);
|
|
$winName = $winTypeAry[$v['winType']] ? $winTypeAry[$v['winType']] : '';
|
|
$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'] : ''
|
|
, 'winTime' => $v['winTime'] ? $v['winTime'] : '', 'winName' => $winName, 'consultant' => $consultant['consultant']
|
|
];
|
|
if ($limit >= 10000) {
|
|
unset($list1['id']);
|
|
} 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' => 'winTime', 'label' => '中奖时间', 'showOverflowTooltip' => true, 'minWidth' => 100, 'sortable' => 'custom'],
|
|
['prop' => 'winName', 'label' => '中奖类型', 'showOverflowTooltip' => true, 'minWidth' => 90],
|
|
['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) {
|
|
$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];
|
|
}
|
|
|
|
} |