184 lines
7.2 KiB
PHP
184 lines
7.2 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_organization_model', 'mdSyliveOrganization');
|
|
$this->load->model('market/Market_sylive_team_model', 'mdSyliveTeam');
|
|
$this->load->model('market/Market_sylive_activity_kpidata_model', 'mdSyliveActivityKpidata');
|
|
}
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
|
|
private function orderList($params)
|
|
{
|
|
$activityId = intval($params['activityId']);
|
|
$page = $params['page'];
|
|
$limit = $params['limit'];
|
|
$uname = $params['uname'];
|
|
$mobile = $params['mobile'];
|
|
$status = $params['status'];
|
|
$cfrom = $params['cfrom'];
|
|
$type = $params['type'];
|
|
$sort = $params['sort'];
|
|
$order = $params['order'];
|
|
$bizId = $params['bizId'];
|
|
$teamId = $params['teamId'];
|
|
$itemId = $params['itemId'];
|
|
!$page && $page = 1;
|
|
!$limit && $limit = 10;
|
|
$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($cfrom) && $where['cfrom'] = $cfrom;
|
|
strlen($type) && $where['type'] = $type;
|
|
$cfrom == 1 && $bizId = 0;
|
|
if ($bizId) {
|
|
$res_org = $this->mdSyliveOrganization->get(["organizationId" => $bizId]);
|
|
if ($res_org) {
|
|
if ($res_org['organizationType'] == 3) {//门店
|
|
$where['bizId'] = $bizId;
|
|
} else if ($res_org['organizationType'] == 2) {//大区
|
|
$where['areaId'] = $bizId;
|
|
}
|
|
}
|
|
} elseif ($teamId) {
|
|
$res_team = $this->mdSyliveTeam->get(["teamId" => $bizId]);
|
|
if ($res_team) {
|
|
if ($res_team['teamType'] == 2) {//团队
|
|
$where['bizId'] = $bizId;
|
|
} else if ($res_team['teamType'] == 1) {//总部
|
|
$where['areaId'] = $bizId;
|
|
}
|
|
}
|
|
}
|
|
if ($limit == 10000) {
|
|
$count = $limit;
|
|
} else {
|
|
$count = $this->mdSyliveOrder->count($where);
|
|
}
|
|
if ($count) {
|
|
$res = $this->mdSyliveOrder->select($where, $sort_order, $page, $limit);
|
|
foreach ($res as $v) {
|
|
$consultant = $this->consultantGet(['activityId' => $v['activityId'], 'userId' => $v['userId']
|
|
, 'areaId' => $v['areaId'], 'bizId' => $v['bizId'], 'cfrom' => $v['cfrom'], 'cfUserId' => $v['cfUserId']]);
|
|
$item = [
|
|
'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'] : ''
|
|
, 'typeName' => $this->mdSyliveOrder->typeAry($v['type'])
|
|
, 'statusName' => $this->mdSyliveOrder->statusAry($v['status']), 'cfromName' => $this->mdSyliveOrder->cfromAry($v['cfrom'])
|
|
, 'createTime' => $v['createTime'], 'area' => $consultant['area'], 'stores' => $consultant['stores'], 'consultant' => $consultant['consultant']
|
|
];
|
|
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['address'] = $address;
|
|
$item['biz'] = $biz;
|
|
}
|
|
$list[] = $item;
|
|
}
|
|
}
|
|
if ($limit == 10000) {
|
|
return $list;
|
|
} else {
|
|
return ['list' => $list, 'count' => $count];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Notes:获取顾问信息
|
|
* Created on: 2022/12/08 11:29
|
|
* Created by: dengbw
|
|
* @param $params
|
|
* @return string
|
|
*/
|
|
private function consultantGet($params)
|
|
{
|
|
$area = $stores = $consultant = '';
|
|
$areaId = intval($params['areaId']);
|
|
$bizId = intval($params['bizId']);
|
|
$cfUserId = intval($params['cfUserId']);
|
|
if (!$bizId) {
|
|
$re = $this->mdSyliveActivityKpidata->get(['activityId' => $params['activityId'], 'userId' => $params['userId']
|
|
, 'type' => $params['cfrom'], 'kpi' => 'order']);
|
|
if ($re) {
|
|
$areaId = $re['areaId'];
|
|
$bizId = $re['bizId'];
|
|
$cfUserId = $re['cfUserId'];
|
|
}
|
|
}
|
|
if ($params['cfrom'] == 1) {
|
|
$res_teama = $this->mdSyliveTeam->get(["teamId" => $areaId]);
|
|
$res_teamb = $this->mdSyliveTeam->get(["teamId" => $bizId]);
|
|
$res_teama['teamName'] && $area = $res_teama['teamName'];
|
|
$res_teamb['teamName'] && $stores = $res_teamb['teamName'];
|
|
} else {
|
|
$res_orga = $this->mdSyliveOrganization->get(["organizationId" => $areaId]);
|
|
$res_orgb = $this->mdSyliveOrganization->get(["organizationId" => $bizId]);
|
|
$res_orga['organizationName'] && $area = $res_orga['organizationName'];
|
|
$res_orgb['organizationName'] && $stores = $res_orgb['organizationName'];
|
|
}
|
|
$re_user = $this->mdSyliveUser->get(['userId' => $cfUserId]);
|
|
$re_user['uname'] && $consultant = $re_user['uname'];
|
|
return ['area' => $area, 'stores' => $stores, 'consultant' => $consultant];
|
|
}
|
|
|
|
} |