Files
liche/market/controllers/api/sylive/Activity.php
T
2022-10-09 16:29:13 +08:00

590 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');
}
/**
* 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;
$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 = $sharePhoto = $shareImg = $shareTitle = $bizIds = [];
$item = ['activityId' => $activityId, 'itemImg' => [], 'title' => '', 'introduction' => '', 'price' => '', 'dateRange' => ''];
$v['shareTitle'] && $shareTitle = json_decode($v['shareTitle'], true);
$jsondata = $v['jsondata'] ? json_decode($v['jsondata'], true) : [];
if ($jsondata['item']) {
$getItem = $jsondata['item'];
$item['title'] = $getItem['title'];
$item['introduction'] = $getItem['introduction'];
$item['price'] = $getItem['price'];
$item['dateRange'] = [$getItem['timeStart'], $getItem['timeEnd']];
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 ($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']);
}
}
$skey = $this->myencryption->base64url_encode("id=" . $activityId);
$url = http_host_com('home') . "/h5/market/sylive?skey=" . $skey;//活动连接
$urlItem = http_host_com('home') . "/h5/market/sylive/act/item?skey=" . $skey;//商品连接
$list[] = [
'activityId' => $activityId, 'title' => $v['title'], 'channelId' => $v['channelId'], 'bizIds' => $bizIds,
'introduction' => $v['introduction'], 'shareTitle' => $shareTitle, 'dateRange' => $dateRange, 'urlItem' => $urlItem
, 'bgImg' => $bgImg, 'channelImg' => $channelImg, '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');
if (!$title) {
$this->return_json('请输入活动标题');
}
if (!$bizIds) {
$this->return_json('请选择所属门店');
}
if (!$bgImg[0]['fileUrl']) {
$this->return_json('请选择背景图');
}
if (!$channelId) {
$this->return_json('请输入直播频道');
}
if (!$dateRange) {
$this->return_json('请选择直播时间');
}
// if (!$introduction) {
// $this->return_json('请输入活动简介');
// }
$bgImg = $bgImg[0]['fileUrl'];
$sharePhoto = $sharePhoto[0]['fileUrl'] ? $sharePhoto[0]['fileUrl'] : '';
$channelImg = $channelImg[0]['fileUrl'] ? $channelImg[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);
}
$addDate = ['title' => $title, 'bgImg' => $bgImg, 'channelImg' => $channelImg, 'channelId' => $channelId
, 'introduction' => $introduction, 'shareTitle' => $shareTitle, 'sharePhoto' => $sharePhoto, 'shareImg' => $setShareImg
, '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('添加活动失败');
}
$bizIds = implode(',', $bizIds);
$res_org = $this->mdSyliveOrganization->select(["organizationId in({$bizIds})" => null, 'organizationType' => 3]
, 'organizationId desc', 0, 0, 'organizationId,parentId');
$add_biz = [];
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')];
}
//增加活动商家
$add_biz && $this->mdSyliveActivityBiz->add_batch($add_biz);
}
$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]);
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');
if (!$activityId) {
$this->return_json('参数错误');
}
if (!$title) {
$this->return_json('请输入活动标题');
}
if (!$bizIds) {
$this->return_json('请选择所属门店');
}
if (!$bgImg[0]['fileUrl']) {
$this->return_json('请选择背景图');
}
if (!$channelId) {
$this->return_json('请输入直播频道');
}
if (!$dateRange) {
$this->return_json('请选择直播时间');
}
// if (!$introduction) {
// $this->return_json('请输入活动简介');
// }
$bizIds = implode(',', $bizIds);
$res_org = $this->mdSyliveOrganization->select(["organizationId in({$bizIds})" => null, 'organizationType' => 3]
, 'organizationId desc', 0, 0, 'organizationId,parentId');
$add_biz = [];
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']]);
}
}
//增加活动商家
$add_biz && $this->mdSyliveActivityBiz->add_batch($add_biz);
}
$bgImg = $bgImg[0]['fileUrl'];
$sharePhoto = $sharePhoto[0]['fileUrl'] ? $sharePhoto[0]['fileUrl'] : '';
$channelImg = $channelImg[0]['fileUrl'] ? $channelImg[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);
}
$upDate = ['title' => $title, 'bgImg' => $bgImg, 'channelImg' => $channelImg, 'channelId' => $channelId, 'introduction' => $introduction,
'shareTitle' => $shareTitle, 'sharePhoto' => $sharePhoto, 'shareImg' => $setShareImg, 'timeStart' => $dateRange[0], 'timeEnd' => $dateRange[1]];
$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');
$itemImg = $this->input_param('itemImg');
$dateRange = $this->input_param('dateRange');
$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) : [];
$item = ['title' => $title, 'price' => $price, 'timeStart' => $dateRange[0], 'timeEnd' => $dateRange[1], 'introduction' => $introduction];
if ($itemImg) {
$setItemImg = [];
foreach ($itemImg as $v) {
$setItemImg[] = $v['fileUrl'];
}
$item['itemImg'] = $setItemImg;
}
$jsondata['item'] = $item;
$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/27 10:02
* Created by: dengbw
* @param null $activityId
*/
public function statistics_get($activityId = null)
{
$activityId = intval($activityId);
if (!$activityId) {
$this->return_json('参数错误');
}
$this->load->model('market/Market_sylive_activity_kpidata_model', 'mdSyliveActivityKpidata');
$this->load->model('market/Market_sylive_user_model', 'mdSyliveUser');
$this->load->model('live/Live_polyv_session_model', 'mdPolyvSession');
$this->load->model('live/Live_polyv_viewlog_model', 'mdPolyvViewlog');
$title = '';
$activityData1 = $activityData2 = $areaData = $bizData = $consultantData = $areaAry = $funnel = [];
$browse = $subscribe = $watch = $order = 0;
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
if ($re) {
$title = $re['title'];
$channelId = $re['channelId'];
$res_biz = $this->mdSyliveActivityBiz->select(['activityId' => $activityId, 'status' => 0], 'browse desc');
foreach ($res_biz as $k => $v) {
$areaId = intval($v['areaId']);
$bizId = intval($v['bizId']);
$re_biz = $this->mdSyliveOrganization->get(['organizationId' => $bizId]);
if ($re_biz) {
$consultant = $this->mdSyliveActivityKpidata->count(['biz_id' => $bizId, 'a_id' => $activityId], 'distinct(cf_uid)');
$livePV = $watchDuration = 0;
if ($channelId) {
$res_watch = $this->mdSyliveActivityKpidata->db->select('b.unionid')
->from('lc_market_sylive_activity_kpidata as a')
->join('lc_market_sylive_user as b', "b.userId=a.uid", 'left')
->where(['a.biz_id' => $bizId, 'a.a_id' => $activityId, 'a.kpi' => 'watch', "unionid!=''" => null])
->limit(10000, 0)
->get()->result_array();
if ($res_watch) {
$str_unionids = implode("','", array_column($res_watch, 'unionid'));
$where_pv = ['channelId' => $channelId, 'param3' => 'live'];
$where_pv["param1 in ('" . $str_unionids . "')"] = null;
$livePV = $this->mdPolyvViewlog->count($where_pv);
$re_sum = $this->mdPolyvViewlog->sum('playDuration', $where_pv);
if ($re_sum['playDuration']) {
$watchDuration = round($re_sum['playDuration'] / $livePV);
}
}
}
$bizData[] = ['areaId' => $areaId, 'bizId' => $bizId,
'bizName' => $re_biz['organizationName'], 'consultant' => $consultant, 'browse' => $v['browse'], 'subscribe' => $v['subscribe']
, 'watch' => $v['watch'], 'order' => $v['orderTotal'], 'livePV' => $livePV, 'watchDuration' => $watchDuration];
if (!$areaAry[$areaId]) {//大区
$areaAry[$areaId] = 1;
} else {
$areaAry[$areaId] += 1;
}
}
}
foreach ($areaAry as $k => $v) {
$areaId = intval($k);
$re_area = $this->mdSyliveOrganization->get(['organizationId' => $areaId]);
if ($re_area) {
$consultant = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'a_id' => $activityId], 'distinct(cf_uid)');
$browse = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'a_id' => $activityId, 'kpi' => 'browse']);
$subscribe = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'a_id' => $activityId, 'kpi' => 'subscribe']);
$watch = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'a_id' => $activityId, 'kpi' => 'watch']);
$order = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'a_id' => $activityId, 'kpi' => 'order']);
$livePV = $watchDuration = 0;
if ($channelId) {
$res_watch = $this->mdSyliveActivityKpidata->db->select('b.unionid')
->from('lc_market_sylive_activity_kpidata as a')
->join('lc_market_sylive_user as b', "b.userId=a.uid", 'left')
->where(['a.area_id' => $areaId, 'a.a_id' => $activityId, 'a.kpi' => 'watch', "unionid!=''" => null])
->limit(10000, 0)
->get()->result_array();
if ($res_watch) {
$str_unionids = implode("','", array_column($res_watch, 'unionid'));
$where_pv = ['channelId' => $channelId, 'param3' => 'live'];
$where_pv["param1 in ('" . $str_unionids . "')"] = null;
$livePV = $this->mdPolyvViewlog->count($where_pv);
$re_sum = $this->mdPolyvViewlog->sum('playDuration', $where_pv);
if ($re_sum['playDuration']) {
$watchDuration = round($re_sum['playDuration'] / $livePV);
}
}
}
$areaData[] = ['areaName' => $re_area['organizationName'], 'biz' => $v, 'consultant' => $consultant
, 'browse' => $browse, 'subscribe' => $subscribe, 'watch' => $watch, 'order' => $order
, 'livePV' => $livePV, 'watchDuration' => $watchDuration];
}
}
$res_user = $this->mdSyliveActivityKpidata->select(['a_id' => $activityId], 'id desc', 0, 0, 'distinct(cf_uid) as userId');
foreach ($res_user as $k => $v) {
$userId = intval($v['userId']);
$re_user = $this->mdSyliveUser->get(['userId' => $v['userId']]);
if ($re_user) {
$consultantName = $re_user['uname'] ? $re_user['uname'] : $re_user['nickname'];
$browse = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'cf_uid' => $userId, 'kpi' => 'browse']);
$subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'cf_uid' => $userId, 'kpi' => 'subscribe']);
$watch = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'cf_uid' => $userId, 'kpi' => 'watch']);
$order = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'cf_uid' => $userId, 'kpi' => 'order']);
$livePV = $watchDuration = 0;
if ($channelId) {
$res_watch = $this->mdSyliveActivityKpidata->db->select('b.unionid')
->from('lc_market_sylive_activity_kpidata as a')
->join('lc_market_sylive_user as b', "b.userId=a.uid", 'left')
->where(['a.cf_uid' => $userId, 'a.a_id' => $activityId, 'a.kpi' => 'watch', "unionid!=''" => null])
->limit(10000, 0)
->get()->result_array();
if ($res_watch) {
$str_unionids = implode("','", array_column($res_watch, 'unionid'));
$where_pv = ['channelId' => $channelId, 'param3' => 'live'];
$where_pv["param1 in ('" . $str_unionids . "')"] = null;
$livePV = $this->mdPolyvViewlog->count($where_pv);
$re_sum = $this->mdPolyvViewlog->sum('playDuration', $where_pv);
if ($re_sum['playDuration']) {
$watchDuration = round($re_sum['playDuration'] / $livePV);
}
}
}
$consultantData = [['consultantName' => $consultantName, 'browse' => $browse, 'subscribe' => $subscribe, 'watch' => $watch
, 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration]];
}
}
$browse = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'kpi' => 'browse']);
$subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'kpi' => 'subscribe']);
$watch = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'kpi' => 'watch']);
$order = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'kpi' => 'order']);
$duration = $livePV = $watchDuration = 0;
if ($channelId) {
$re_duration = $this->mdPolyvSession->sum('duration', ['channelId' => $channelId]);
$re_livePV = $this->mdPolyvSession->sum('livePV', ['channelId' => $channelId]);
if ($re_duration['duration']) {
$duration = ceil($re_duration['duration'] / 60);
$livePV = $re_livePV['livePV'];
$watchDuration = round($duration / $livePV);
}
}
$activityData1 = [['name' => '参与区域数', 'value' => count($areaData)], ['name' => '参与门店数', 'value' => count($bizData)]
, ['name' => '参与顾问数', 'value' => count($res_user)]];
$activityData2 = [['name' => '浏览人数', 'value' => $browse, 'url' => '/system/user'], ['name' => '预约人数', 'value' => $subscribe, 'url' => '/system/user']
, ['name' => '观看人数', 'value' => $watch, 'url' => '/system/user'], ['name' => '订单数', 'value' => $order, 'url' => '/system/user'], ['name' => '直播时长', 'value' => $duration, 'url' => '/system/user']
, ['name' => '观看次数', 'value' => $livePV, 'url' => '/system/user'], ['name' => '人均观看', 'value' => $watchDuration, 'url' => '/system/user']];
}
$watch_per = number_format_com($watch / $browse * 100, 1, '');
$order_per = number_format_com($order / $browse * 100, 1, '');
if ($order > $subscribe) {
$expected_data = [['name' => "浏览人数(100%)", 'value' => 100], ['name' => "观看人数({$watch_per}%)", 'value' => 66.7], ['name' => "订单数({$order_per}%)", 'value' => 33.3]];
$actual_data = [['name' => '浏览人数', 'value' => $browse], ['name' => '观看人数', 'value' => $watch], ['name' => '订单数', 'value' => $order]];
} else {
$subscribe_per = number_format_com($subscribe / $browse * 100, 1, '');
$expected_data = [['name' => "浏览人数100%", 'value' => 100], ['name' => "预约人数({$subscribe_per}%)", 'value' => $subscribe > $watch ? 75 : 50]
, ['name' => "观看人数({$watch_per}%)", 'value' => $watch > $subscribe ? 75 : 50], ['name' => "订单数({$order_per}%)", 'value' => 25]];
$actual_data = [['name' => '浏览人数', 'value' => $browse], ['name' => '预约人数', 'value' => $subscribe]
, ['name' => '观看人数', 'value' => $watch], ['name' => '订单数', 'value' => $order]];
}
$funnel = ['title' => '活动漏斗', 'expected_data' => $expected_data, 'actual_data' => $actual_data];
$data = ['activityId' => $activityId, 'title' => $title, 'activityData1' => $activityData1, 'activityData2' => $activityData2, 'areaData' => $areaData
, 'bizData' => $bizData, 'consultantData' => $consultantData, 'funnel' => $funnel];
$this->return_response($data);
}
public function statistics_ar_get($activityId = null){
}
/**
* Notes:活动订单列表
* Created on: 2022/9/29 9:53
* Created by: dengbw
* @param null $activityId
*/
public function order_get()
{
$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($this->input_param('activityId'));
$page = $this->input_param('page');
$limit = $this->input_param('limit');
$item_title = $this->input_param('item_title');
$uname = $this->input_param('uname');
$mobile = $this->input_param('mobile');
$status = $this->input_param('status');
$sort = $this->input_param('sort');
$order = $this->input_param('order');
!$page && $page = 1;
!$limit && $limit = 10;
$sort_order = 'id desc';
if ($sort && $order) {
if ($sort == 'statusName') {
$sort_order = 'status ' . $order;
} else {
$sort_order = $sort . ' ' . $order;
}
}
$list = [];
if (!strlen($status)) {
$status = 1;
}
$where['status'] = $status;
$activityId && $where['item_id'] = $activityId;
$item_title && $where['item_title'] = $item_title;
$uname && $where['uname'] = $uname;
$mobile && $where['mobile'] = $mobile;
$count = $this->mdSyliveOrder->count($where);
if ($count) {
$res = $this->mdSyliveOrder->select($where, $sort_order, $page, $limit);
foreach ($res as $v) {
$consultant = $this->consultantGet(['a_id' => $v['item_id'], 'uid' => $v['uid']]);
$list[] = [
'id' => $v['id'], 'consultant' => $consultant, 'uname' => $v['uname'], 'mobile' => $v['mobile'], 'item_title' => $v['item_title']
, 'total_price' => $v['total_price'], 'pay_time' => $v['pay_time'] != '0000-00-00 00:00:00' ? $v['pay_time'] : ''
, 'statusName' => $this->mdSyliveOrder->statusAry($v['status']), 'createTime' => $v['createTime']];
}
}
$date = ['list' => $list, 'count' => $count];
$this->return_response_list($date);
}
/**
* Notes:获取顾问信息
* Created on: 2022/10/8 11:29
* Created by: dengbw
* @param $params
* @return string
*/
public function consultantGet($params)
{
$title = '';
$re = $this->mdSyliveActivityKpidata->get(['a_id' => $params['a_id'], 'uid' => $params['uid'], 'kpi' => 'order']);
if ($re['cf_uid']) {
$re_user = $this->mdSyliveUser->get(['userId' => $re['cf_uid']]);
$res_orga = $this->mdSyliveOrganization->get(["organizationId" => $re['area_id']]);
$res_orgb = $this->mdSyliveOrganization->get(["organizationId" => $re['biz_id']]);
$res_orga && $title = $res_orga['organizationName'];
$res_orgb && $title = $title ? $title . '-' . $res_orgb['organizationName'] : $res_orgb['organizationName'];
$re_user && $title = $title ? $title . '-' . $re_user['uname'] : $re_user['uname'];
}
return $title;
}
}