Files
liche/market/controllers/api/sylive/Activity.php
T
2022-11-18 23:09:32 +08:00

657 lines
30 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once APPPATH . 'controllers/api/BaseController.php';
/**
* Notes:私域直播_活动管理
* Created on: 2022/9/19 17:15
* Created by: dengbw
*/
class Activity extends BaseController
{
public function __construct()
{
parent::__construct();
$this->load->model('market/Market_sylive_activity_model', 'mdSyliveActivity');
$this->load->model('market/Market_sylive_activity_biz_model', 'mdSyliveActivityBiz');
$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_team_model', 'mdSyliveActivityTeam');
}
/**
* Notes:活动管理列表
* Created on: 2022/9/20 14:48
* Created by: dengbw
*/
public function page_get()
{
$page = $this->input_param('page');
$limit = $this->input_param('limit');
$title = $this->input_param('title');
$sort = $this->input_param('sort');
$order = $this->input_param('order');
!$page && $page = 1;
!$limit && $limit = 10;
$sort_order = 'activityId desc';
if ($sort && $order) {
$sort_order = $sort . ' ' . $order;
}
$list = [];
$where['status>='] = 0;
$title && $where['title LIKE "%' . trim($title) . '%"'] = null;
if ($_SESSION['brandName']) {//品牌机构
$re_org = $this->mdSyliveOrganization->get(['organizationName' => $_SESSION['brandName'], 'parentId' => 0, 'status' => 0]);
if ($re_org['organizationId']) {
$organizationIds = ",{$re_org['organizationId']},";
$where['organizationIds LIKE "%' . $organizationIds . '%"'] = null;
} else {
$where['organizationIds'] = '-1';
}
}
$count = $this->mdSyliveActivity->count($where);
if ($count) {
$this->load->library('MyEncryption');
$res = $this->mdSyliveActivity->select($where, $sort_order, $page, $limit);
foreach ($res as $v) {
$dateRange = [$v['timeStart'], $v['timeEnd']];
$status = intval($v['status']);
$activityId = intval($v['activityId']);
$bgImg = $channelImg = $banner = $sharePhoto = $shareImg = $shareTitle = $bizIds = $teamIds = $pay = [];
$item = ['activityId' => $activityId, 'itemImg' => [], 'title' => '', 'introduction' => '', 'price' => '', 'stock' => '', 'dateRange' => ''];
$coupon = ['activityId' => $activityId, 'img' => [], 'title' => '', 'rules' => '', 'price' => '', 'dateRange' => ''];
$pay = ['way' => 1, 'price' => '', 'img' => []];
$v['shareTitle'] && $shareTitle = json_decode($v['shareTitle'], true);
$jsondata = $v['jsondata'] ? json_decode($v['jsondata'], true) : [];
if ($jsondata['item']) {
$getItem = $jsondata['item'];
$item['stock'] = $v['stock'];
$item['title'] = $getItem['title'];
$item['introduction'] = $getItem['introduction'];
$item['price'] = $getItem['price'];
$item['dateRange'] = $getItem['timeStart'] ? [$getItem['timeStart'], $getItem['timeEnd']] : [];
$item['dateUseRange'] = $getItem['useTimeStart'] ? [$getItem['useTimeStart'], $getItem['useTimeEnd']] : [];
if ($getItem['itemImg']) {
$itemImg = [];
foreach ($getItem['itemImg'] as $k2 => $v2) {
$itemImg[] = ['uid' => $k2, 'fileUrl' => $v2, 'url' => build_qiniu_image_url($v2), 'status' => 'done'];
}
$item['itemImg'] = $itemImg;
}
}
if ($jsondata['coupon']) {
$getCoupon = $jsondata['coupon'];
$coupon['title'] = $getCoupon['title'];
$coupon['rules'] = $getCoupon['rules'];
$coupon['price'] = $getCoupon['price'];
$coupon['dateUseRange'] = $getCoupon['useTimeStart'] ? [$getCoupon['useTimeStart'], $getCoupon['useTimeEnd']] : [];
if ($getCoupon['img']) {
$itemImg = [];
foreach ($getCoupon['img'] as $k2 => $v2) {
$itemImg[] = ['uid' => $k2, 'fileUrl' => $v2, 'url' => build_qiniu_image_url($v2), 'status' => 'done'];
}
$coupon['img'] = $itemImg;
}
}
if (intval($jsondata['pay']['way']) > 1) {
$pay = $jsondata['pay'];
if ($pay['img']) {
$img[] = ['uid' => 1, 'fileUrl' => $pay['img'], 'url' => build_qiniu_image_url($pay['img']), 'status' => 'done'];
$pay['img'] = $img;
} else {
$pay['img'] = [];
}
}
if ($jsondata['banner']) {
$banner = [['uid' => 1, 'fileUrl' => $jsondata['banner'], 'url' => build_qiniu_image_url($jsondata['banner']), 'status' => 'done']];
}
if ($v['bgImg']) {
$bgImg = [['uid' => 1, 'fileUrl' => $v['bgImg'], 'url' => build_qiniu_image_url($v['bgImg']), 'status' => 'done']];
}
if ($v['channelImg']) {
$channelImg = [['uid' => 1, 'fileUrl' => $v['channelImg'], 'url' => build_qiniu_image_url($v['channelImg']), 'status' => 'done']];
}
if ($v['sharePhoto']) {
$sharePhoto = [['uid' => 1, 'fileUrl' => $v['sharePhoto'], 'url' => build_qiniu_image_url($v['sharePhoto']), 'status' => 'done']];
}
if ($v['shareImg']) {
$getShareImg = json_decode($v['shareImg'], true);
foreach ($getShareImg as $k2 => $v2) {
$shareImg[] = ['uid' => $k2, 'fileUrl' => $v2, 'url' => build_qiniu_image_url($v2), 'status' => 'done'];
}
}
$res_biz = $this->mdSyliveActivityBiz->select(['activityId' => $activityId, 'status' => 0], 'id desc', 0, 0, 'bizId');
if ($res_biz) {
foreach ($res_biz as $k2 => $v2) {
$bizIds[] = intval($v2['bizId']);
}
}
$res_team = $this->mdSyliveActivityTeam->select(['activityId' => $activityId, 'status' => 0], 'id desc', 0, 0, 'teamId2');
if ($res_team) {
foreach ($res_team as $k2 => $v2) {
$teamIds[] = intval($v2['teamId2']);
}
}
$skey = $this->myencryption->base64url_encode("a_id=" . $activityId);
$url = http_host_com('home') . "/h5/market/sylive?skey=" . $skey;//活动连接
$list[] = [
'activityId' => $activityId, 'title' => $v['title'], 'channelId' => $v['channelId'], 'bizIds' => $bizIds, 'teamIds' => $teamIds, 'pay' => $pay,
'introduction' => $v['introduction'], 'shareTitle' => $shareTitle, 'dateRange' => $dateRange, 'coupon' => $coupon, 'drawCode' => $v['drawCode'],
'bgImg' => $bgImg, 'channelImg' => $channelImg, 'banner' => $banner, 'sharePhoto' => $sharePhoto, 'shareImg' => $shareImg, 'item' => $item, 'url' => $url,
's_time' => $v['timeStart'], 'e_time' => $v['timeEnd'], 'status' => $status, 'createTime' => $v['createTime']];
}
}
$date = ['list' => $list, 'count' => $count];
$this->return_response_list($date);
}
/**
* Notes:添加活动
* Created on: 2022/9/21 16:46
* Created by: dengbw
*/
public function index_post()
{
$title = $this->input_param('title');
$channelId = $this->input_param('channelId');
$dateRange = $this->input_param('dateRange');
$introduction = $this->input_param('introduction');
$shareTitle = $this->input_param('shareTitle');
$shareImg = $this->input_param('shareImg');
$bgImg = $this->input_param('bgImg');
$channelImg = $this->input_param('channelImg');
$sharePhoto = $this->input_param('sharePhoto');
$bizIds = $this->input_param('bizIds');
$teamIds = $this->input_param('teamIds');
$pay = $this->input_param('pay');
$drawCode = $this->input_param('drawCode');
$banner = $this->input_param('banner');
if (!$title) {
$this->return_json('请输入活动标题');
}
if (!$bgImg[0]['fileUrl']) {
$this->return_json('请选择背景图');
}
if (!$channelId) {
$this->return_json('请输入直播频道');
}
if (!$dateRange) {
$this->return_json('请选择直播时间');
}
if ($drawCode) {
$re = $this->mdSyliveActivity->get(['drawCode' => $drawCode, 'status' => 0], 'drawCode');
if ($re['drawCode']) {
$this->return_json('抽奖码已存在');
}
}
// if (!$introduction) {
// $this->return_json('请输入活动简介');
// }
$bgImg = $bgImg[0]['fileUrl'];
$sharePhoto = $sharePhoto ? $sharePhoto[0]['fileUrl'] : '';
$channelImg = $channelImg ? $channelImg[0]['fileUrl'] : '';
$banner = $banner ? $banner[0]['fileUrl'] : '';
$shareTitle = $shareTitle ? json_encode($shareTitle, JSON_UNESCAPED_UNICODE) : '';
$setShareImg = '';
if ($shareImg) {
foreach ($shareImg as $v) {
$setShareImg[] = $v['fileUrl'];
}
$setShareImg = json_encode($setShareImg, JSON_UNESCAPED_UNICODE);
}
if ($pay['way'] > 1) {
$pay['img'] = $pay['img'][0]['fileUrl'] ? $pay['img'][0]['fileUrl'] : '';
} else {
$pay = ['way' => 1, 'price' => '', 'img' => []];
}
$jsondata['pay'] = $pay;
$jsondata['banner'] = $banner;
$jsondata = json_encode($jsondata, JSON_UNESCAPED_UNICODE);
$addDate = ['title' => $title, 'bgImg' => $bgImg, 'channelImg' => $channelImg, 'channelId' => $channelId, 'jsondata' => $jsondata
, 'introduction' => $introduction, 'shareTitle' => $shareTitle, 'sharePhoto' => $sharePhoto, 'shareImg' => $setShareImg, 'drawCode' => $drawCode
, 'timeStart' => $dateRange[0], 'timeEnd' => $dateRange[1], 'status' => 1, 'createTime' => date('Y-m-d H:i:s')];
$activityId = $this->mdSyliveActivity->add($addDate);
if (!$activityId) {
$this->return_json('添加活动失败');
}
$organizationIds = $add_biz = $add_team = [];
if ($bizIds) {
$bizIds = implode(',', $bizIds);
$res_org = $this->mdSyliveOrganization->select(["organizationId in({$bizIds})" => null, 'organizationType' => 3]
, 'organizationId desc', 0, 0, 'organizationId,parentId');
if ($res_org) {
$this->mdSyliveActivityBiz->update(['status' => -1], ["bizId not in({$bizIds})" => null, 'activityId' => $activityId, 'status' => 0]);
foreach ($res_org as $v) {
$add_biz[] = ['activityId' => $activityId, 'areaId' => $v['parentId']
, 'bizId' => $v['organizationId'], 'createTime' => date('Y-m-d H:i:s')];
if ($v['parentId']) {
$re_org = $this->mdSyliveOrganization->get(["organizationId" => $v['parentId']]);
if ($re_org['parentId'] && !in_array($re_org['parentId'], $organizationIds)) {
$organizationIds[] = $re_org['parentId'];//所属机构
}
}
}
//增加活动商家
$add_biz && $this->mdSyliveActivityBiz->add_batch($add_biz);
}
}
if ($teamIds) {
$teamIds = implode(',', $teamIds);
$res_org = $this->mdSyliveTeam->select(["teamId in({$teamIds})" => null, 'teamType' => 2], 'teamId desc', 0, 0, 'teamId,parentId');
if ($res_org) {
$this->mdSyliveActivityTeam->update(['status' => -1], ["teamId2 not in({$teamIds})" => null, 'activityId' => $activityId, 'status' => 0]);
foreach ($res_org as $v) {
$add_team[] = ['activityId' => $activityId, 'teamId1' => $v['parentId']
, 'teamId2' => $v['teamId'], 'createTime' => date('Y-m-d H:i:s')];
if ($v['parentId']) {
$re_team = $this->mdSyliveTeam->get(["teamId" => $v['parentId']]);
if ($re_team['organizationId'] && !in_array($re_team['organizationId'], $organizationIds)) {
$organizationIds[] = $re_team['organizationId'];
}
}
}
//增加活动商家
$add_team && $this->mdSyliveActivityTeam->add_batch($add_team);
}
}
if ($organizationIds) {//所属机构
$organizationIds = ',' . implode(',', $organizationIds) . ',';
$this->mdSyliveActivity->update(['organizationIds' => $organizationIds], ['activityId' => $activityId]);
}
$this->return_response();
}
/**
* Notes:活动详情
* Created on: 2022/9/29 10:37
* Created by: dengbw
* @param null $activityId
*/
public function index_get($activityId = null)
{
if (!$activityId) {
$this->return_json('参数错误');
}
$re = $this->mdSyliveActivity->get(['activityId' => $activityId], 'activityId,title');
if (!$re) {
$this->return_json('活动不存在');
}
$this->return_response($re);
}
/**
* Notes:修改活动
* Created on: 2022/9/21 14:48
* Created by: dengbw
*/
public function index_put()
{
$activityId = intval($this->input_param('activityId'));
$title = $this->input_param('title');
$channelId = $this->input_param('channelId');
$dateRange = $this->input_param('dateRange');
$introduction = $this->input_param('introduction');
$shareTitle = $this->input_param('shareTitle');
$shareImg = $this->input_param('shareImg');
$bgImg = $this->input_param('bgImg');
$channelImg = $this->input_param('channelImg');
$sharePhoto = $this->input_param('sharePhoto');
$bizIds = $this->input_param('bizIds');
$teamIds = $this->input_param('teamIds');
$pay = $this->input_param('pay');
$drawCode = $this->input_param('drawCode');
$banner = $this->input_param('banner');
if (!$activityId) {
$this->return_json('参数错误');
}
if (!$title) {
$this->return_json('请输入活动标题');
}
if (!$bgImg[0]['fileUrl']) {
$this->return_json('请选择背景图');
}
if (!$channelId) {
$this->return_json('请输入直播频道');
}
if (!$dateRange) {
$this->return_json('请选择直播时间');
}
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
if (!$re) {
$this->return_json('活动不存在');
}
if ($drawCode) {
if ($drawCode != $re['drawCode']) {
$re = $this->mdSyliveActivity->get(['drawCode' => $drawCode, 'status' => 0], 'drawCode');
if ($re['drawCode']) {
$this->return_json('抽奖码已存在');
}
}
}
$organizationIds = $add_biz = $add_team = [];
if ($bizIds) {
$bizIds = implode(',', $bizIds);
$res_org = $this->mdSyliveOrganization->select(["organizationId in({$bizIds})" => null, 'organizationType' => 3]
, 'organizationId desc', 0, 0, 'organizationId,parentId');
if ($res_org) {
$this->mdSyliveActivityBiz->update(['status' => -1], ["bizId not in({$bizIds})" => null, 'activityId' => $activityId, 'status' => 0]);
foreach ($res_org as $v) {
$re_org = $this->mdSyliveActivityBiz->get(['activityId' => $activityId, 'bizId' => $v['organizationId']]);
if (!$re_org) {
$add_biz[] = ['activityId' => $activityId, 'areaId' => $v['parentId']
, 'bizId' => $v['organizationId'], 'createTime' => date('Y-m-d H:i:s')];
} else if ($re_org['status'] == -1) {
$this->mdSyliveActivityBiz->update(['status' => 0], ['id' => $re_org['id']]);
}
if ($v['parentId']) {
$re_org = $this->mdSyliveOrganization->get(["organizationId" => $v['parentId']]);
if ($re_org['parentId'] && !in_array($re_org['parentId'], $organizationIds)) {
$organizationIds[] = $re_org['parentId'];//所属机构
}
}
}
//增加活动商家
$add_biz && $this->mdSyliveActivityBiz->add_batch($add_biz);
}
} else {
$this->mdSyliveActivityBiz->update(['status' => -1], ['activityId' => $activityId, 'status' => 0]);
}
if ($teamIds) {
$teamIds = implode(',', $teamIds);
$res_org = $this->mdSyliveTeam->select(["teamId in({$teamIds})" => null, 'teamType' => 2], 'teamId desc', 0, 0, 'teamId,parentId');
if ($res_org) {
$this->mdSyliveActivityTeam->update(['status' => -1], ["teamId2 not in({$teamIds})" => null, 'activityId' => $activityId, 'status' => 0]);
foreach ($res_org as $v) {
$re_org = $this->mdSyliveActivityTeam->get(['activityId' => $activityId, 'teamId2' => $v['teamId']]);
if (!$re_org) {
$add_team[] = ['activityId' => $activityId, 'teamId1' => $v['parentId']
, 'teamId2' => $v['teamId'], 'createTime' => date('Y-m-d H:i:s')];
} else if ($re_org['status'] == -1) {
$this->mdSyliveActivityTeam->update(['status' => 0], ['id' => $re_org['id']]);
}
if ($v['parentId']) {
$re_team = $this->mdSyliveTeam->get(["teamId" => $v['parentId']]);
if ($re_team['organizationId'] && !in_array($re_team['organizationId'], $organizationIds)) {
$organizationIds[] = $re_team['organizationId'];
}
}
}
//增加活动商家
$add_team && $this->mdSyliveActivityTeam->add_batch($add_team);
}
} else {
$this->mdSyliveActivityTeam->update(['status' => -1], ['activityId' => $activityId, 'status' => 0]);
}
$bgImg = $bgImg[0]['fileUrl'];
$sharePhoto = $sharePhoto ? $sharePhoto[0]['fileUrl'] : '';
$channelImg = $channelImg ? $channelImg[0]['fileUrl'] : '';
$banner = $banner ? $banner[0]['fileUrl'] : '';
$shareTitle = $shareTitle ? json_encode($shareTitle, JSON_UNESCAPED_UNICODE) : '';
$setShareImg = '';
if ($shareImg) {
foreach ($shareImg as $v) {
$setShareImg[] = $v['fileUrl'];
}
$setShareImg = json_encode($setShareImg, JSON_UNESCAPED_UNICODE);
}
$jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : [];
if ($pay['way'] > 1) {
$pay['img'] = $pay['img'][0]['fileUrl'] ? $pay['img'][0]['fileUrl'] : '';
} else {
$pay = ['way' => 1, 'price' => '', 'img' => []];
}
$jsondata['pay'] = $pay;
$jsondata['banner'] = $banner;
$jsondata = json_encode($jsondata, JSON_UNESCAPED_UNICODE);
$organizationIds = $organizationIds ? ',' . implode(',', $organizationIds) . ',' : '';
$upDate = ['title' => $title, 'bgImg' => $bgImg, 'channelImg' => $channelImg, 'channelId' => $channelId, 'introduction' => $introduction,
'shareTitle' => $shareTitle, 'sharePhoto' => $sharePhoto, 'shareImg' => $setShareImg, 'jsondata' => $jsondata, 'drawCode' => $drawCode,
'timeStart' => $dateRange[0], 'timeEnd' => $dateRange[1], 'organizationIds' => $organizationIds];
$this->mdSyliveActivity->update($upDate, ['activityId' => $activityId]);
$this->return_response();
}
/**
* Notes:修改商品
* Created on: 2022/9/28 15:09
* Created by: dengbw
*/
public function item_put()
{
$activityId = intval($this->input_param('activityId'));
$title = $this->input_param('title');
$price = $this->input_param('price');
$stock = intval($this->input_param('stock'));
$itemImg = $this->input_param('itemImg');
$dateRange = $this->input_param('dateRange');
$dateUseRange = $this->input_param('dateUseRange');
$introduction = $this->input_param('introduction');
if (!$activityId) {
$this->return_json('参数错误');
}
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
if (!$re) {
$this->return_json('活动不存在');
}
$jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : [];
$timeStart = $dateRange[0] ? $dateRange[0] : '';
$timeEnd = $dateRange[1] ? $dateRange[1] : '';
$useTimeStart = $dateUseRange[0] ? $dateUseRange[0] : '';
$useTimeEnd = $dateUseRange[1] ? $dateUseRange[1] : '';
$item = ['title' => $title, 'price' => $price, 'timeStart' => $timeStart, 'timeEnd' => $timeEnd
, 'useTimeStart' => $useTimeStart, 'useTimeEnd' => $useTimeEnd, 'introduction' => $introduction];
if ($itemImg) {
$setItemImg = [];
foreach ($itemImg as $v) {
$setItemImg[] = $v['fileUrl'];
}
$item['itemImg'] = $setItemImg;
}
$jsondata['item'] = $item;
$upDate = ['stock' => $stock, 'jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE)];
$this->mdSyliveActivity->update($upDate, ['activityId' => $activityId]);
$this->return_response();
}
/**
* Notes:修改券
* Created on: 2022/10/21 15:09
* Created by: dengbw
*/
public function coupon_put()
{
$activityId = intval($this->input_param('activityId'));
$title = $this->input_param('title');
$price = $this->input_param('price');
$img = $this->input_param('img');
$dateUseRange = $this->input_param('dateUseRange');
$rules = $this->input_param('rules');
if (!$activityId) {
$this->return_json('参数错误');
}
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
if (!$re) {
$this->return_json('活动不存在');
}
$jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : [];
$useTimeStart = $dateUseRange[0] ? $dateUseRange[0] : '';
$useTimeEnd = $dateUseRange[1] ? $dateUseRange[1] : '';
$coupon = ['title' => $title, 'price' => $price, 'rules' => $rules,
'useTimeStart' => $useTimeStart, 'useTimeEnd' => $useTimeEnd];
if ($img) {
$setImg = [];
foreach ($img as $v) {
$setImg[] = $v['fileUrl'];
}
$coupon['img'] = $setImg;
}
$jsondata['coupon'] = $coupon;
$upDate = ['jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE)];
$this->mdSyliveActivity->update($upDate, ['activityId' => $activityId]);
$this->return_response();
}
/**
* Notes:删除活动
* Created on: 2022/9/21 16:10
* Created by: dengbw
* @param null $activityId
*/
public function index_delete($activityId = null)
{
if (!$activityId) {
$this->return_json('参数错误');
}
$this->mdSyliveActivity->update(['status' => -1], ['activityId' => $activityId]);
$this->return_response();
}
/**
* Notes:批量删除用户
* Created on: 2022/9/8 17:11
* Created by: dengbw
*/
public function batch_delete()
{
$ids = $this->inputs;
if (!$ids) {
$this->return_json('参数错误');
}
$str_ids = implode(',', $ids);
if ($str_ids) {
$this->mdSyliveActivity->update(['status' => -1], ["activityId in($str_ids)" => null]);
}
$this->return_response();
}
/**
* Notes:修改状态
* Created on: 2022/9/8 16:10
* Created by: dengbw
*/
public function status_put()
{
$activityId = $this->input_param('activityId');
$status = $this->input_param('status');
if (!$activityId) {
$this->return_json('参数错误');
}
$this->mdSyliveActivity->update(['status' => $status], ['activityId' => $activityId]);
$this->return_response();
}
/**
* Notes:活动订单列表
* Created on: 2022/9/29 9:53
* Created by: dengbw
*/
public function order_get()
{
$date = $this->orderList($this->inputs);
$this->return_response_list($date);
}
/**
* Notes:导出活动订单数据
* Created on: 2022/10/10 15:26
* Created by: dengbw
*/
public function order_export_get()
{
$this->inputs['page'] = 1;
$this->inputs['limit'] = 10000;
$date = $this->orderList($this->inputs);
$this->return_response_list($date);
}
private function orderList($params)
{
$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');
$activityId = intval($params['activityId']);
$page = $params['page'];
$limit = $params['limit'];
$uname = $params['uname'];
$mobile = $params['mobile'];
$status = $params['status'];
$cfrom = $params['cfrom'];
$sort = $params['sort'];
$order = $params['order'];
!$page && $page = 1;
!$limit && $limit = 10;
$sort_order = 'id desc';
if ($sort && $order) {
if ($sort == 'statusName') {
$sort_order = 'status ' . $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['itemId'] = $activityId;
$uname && $where['uname LIKE "%' . trim($uname) . '%"'] = null;
$mobile && $where['mobile LIKE "%' . trim($mobile) . '%"'] = null;
strlen($cfrom) && $where['cfrom'] = $cfrom;
if ($limit == 10000) {
$count = 1;
} 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['itemId'], 'cfrom' => $v['cfrom'], 'userId' => $v['userId']]);
$list[] = [
'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'] : ''
, '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) {
return $list;
} else {
return ['list' => $list, 'count' => $count];
}
}
/**
* Notes:获取顾问信息
* Created on: 2022/10/8 11:29
* Created by: dengbw
* @param $params
* @return string
*/
private function consultantGet($params)
{
$area = $stores = $consultant = '';
$re = $this->mdSyliveActivityKpidata->get(['activityId' => $params['activityId'], 'userId' => $params['userId'], 'type' => $params['cfrom'], 'kpi' => 'order']);
if ($re['cfUserId']) {
if ($params['cfrom'] == 1) {
$res_teama = $this->mdSyliveTeam->get(["teamId" => $re['areaId']]);
$res_teamb = $this->mdSyliveTeam->get(["teamId" => $re['bizId']]);
$res_teama['teamName'] && $area = $res_teama['teamName'];
$res_teamb['teamName'] && $stores = $res_teamb['teamName'];
} else {
$res_orga = $this->mdSyliveOrganization->get(["organizationId" => $re['areaId']]);
$res_orgb = $this->mdSyliveOrganization->get(["organizationId" => $re['bizId']]);
$res_orga['organizationName'] && $area = $res_orga['organizationName'];
$res_orgb['organizationName'] && $stores = $res_orgb['organizationName'];
}
$re_user = $this->mdSyliveUser->get(['userId' => $re['cfUserId']]);
$re_user['uname'] && $consultant = $re_user['uname'];
}
return ['area' => $area, 'stores' => $stores, 'consultant' => $consultant];
}
}