717 lines
36 KiB
PHP
717 lines
36 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['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 ($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("a_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');
|
|
$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 = ['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)');
|
|
$browse = $this->mdSyliveActivityKpidata->count(['biz_id' => $bizId, 'a_id' => $activityId, 'kpi' => 'browse']);
|
|
$subscribe = $this->mdSyliveActivityKpidata->count(['biz_id' => $bizId, 'a_id' => $activityId, 'kpi' => 'subscribe']);
|
|
$watch = $this->mdSyliveActivityKpidata->count(['biz_id' => $bizId, 'a_id' => $activityId, 'kpi' => 'watch']);
|
|
$order = $this->mdSyliveActivityKpidata->count(['biz_id' => $bizId, '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.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' => $browse, 'subscribe' => $subscribe
|
|
, 'watch' => $watch, 'order' => $order, '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' => $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)]];
|
|
$url = "/sylive/activity/statistics/piechart?activityId={$activityId}&";
|
|
$activityData2 = [['name' => '浏览人数', 'value' => $browse, 'url' => ''], ['name' => '预约人数', 'value' => $subscribe, 'url' => '']
|
|
, ['name' => '观看人数', 'value' => $watch, 'url' => ''], ['name' => '订单数', 'value' => $order, 'url' => '']
|
|
, ['name' => '直播时长', 'value' => $duration, 'url' => ''], ['name' => '观看次数', 'value' => $livePV, 'url' => '']
|
|
, ['name' => '人均观看', 'value' => $watchDuration, 'url' => '']];
|
|
// $activityData2 = [['name' => '浏览人数', 'value' => $browse, 'url' => "{$url}type=browse"], ['name' => '预约人数', 'value' => $subscribe, 'url' => "{$url}type=subscribe"]
|
|
// , ['name' => '观看人数', 'value' => $watch, 'url' => "{$url}type=watch"], ['name' => '订单数', 'value' => $order, 'url' => "{$url}type=order"]
|
|
// , ['name' => '直播时长', 'value' => $duration, 'url' => ''], ['name' => '观看次数', 'value' => $livePV, 'url' => ''], ['name' => '人均观看', 'value' => $watchDuration, 'url' => '']];
|
|
}
|
|
$watch_per = number_format_com($watch / $browse * 100, 1, '');
|
|
$order_per = number_format_com($order / $browse * 100, 1, '');
|
|
$browse_expected_data = [['name' => "浏览人数(100%)", 'value' => 100], ['name' => "观看人数({$watch_per}%)", 'value' => 66.7], ['name' => "订单数({$order_per}%)", 'value' => 33.3]];
|
|
$browse_actual_data = [['name' => '浏览人数', 'value' => $browse], ['name' => '观看人数', 'value' => $watch], ['name' => '订单数', 'value' => $order]];
|
|
$funnel_browse = ['title' => '浏览转化漏斗', 'expected_data' => $browse_expected_data, 'actual_data' => $browse_actual_data];
|
|
|
|
$id_in = "id in(select id from lc_market_sylive_activity_kpidata where a_id = {$activityId} AND kpi = 'subscribe')";
|
|
$watch_subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'kpi' => 'watch', $id_in => null]);
|
|
$order_subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'kpi' => 'order', $id_in => null]);
|
|
$subscribe_per = number_format_com($subscribe / $browse * 100, 1, '');
|
|
$watch_subscribe_per = number_format_com($watch_subscribe / $browse * 100, 1, '');
|
|
$order_subscribe_per = number_format_com($order_subscribe / $browse * 100, 1, '');
|
|
$subscribe_expected_data = [['name' => "浏览人数100%", 'value' => 100], ['name' => "预约人数({$subscribe_per}%)", 'value' => 75]
|
|
, ['name' => "观看人数({$watch_subscribe_per}%)", 'value' => 50], ['name' => "订单数({$order_subscribe_per}%)", 'value' => 25]];
|
|
$subscribe_actual_data = [['name' => '浏览人数', 'value' => $browse], ['name' => '预约人数', 'value' => $subscribe]
|
|
, ['name' => '观看人数', 'value' => $watch_subscribe], ['name' => '订单数', 'value' => $order_subscribe]];
|
|
$funnel_subscribe = ['title' => '预约转化漏斗', 'expected_data' => $subscribe_expected_data, 'actual_data' => $subscribe_actual_data];
|
|
$data = ['activityId' => $activityId, 'title' => $title, 'activityData1' => $activityData1, 'activityData2' => $activityData2, 'areaData' => $areaData
|
|
, 'bizData' => $bizData, 'consultantData' => $consultantData, 'funnelBrowse' => $funnel_browse, 'funnelSubscribe' => $funnel_subscribe];
|
|
$this->return_response($data);
|
|
}
|
|
|
|
/**
|
|
* Notes:获取区域饼状数据
|
|
* Created on: 2022/10/9 17:21
|
|
* Created by: dengbw
|
|
*/
|
|
public function statistics_piechart_get()
|
|
{
|
|
$activityId = intval($this->input_param('activityId'));
|
|
$type = $this->input_param('type');
|
|
if (!$activityId || !$type) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
$this->load->model('market/Market_sylive_activity_kpidata_model', 'mdSyliveActivityKpidata');
|
|
$data = [];
|
|
$res_biz = $this->mdSyliveActivityBiz->select(['activityId' => $activityId, 'status' => 0], 'browse desc', 0, 0, 'distinct(areaId) as areaId');
|
|
foreach ($res_biz as $k => $v) {
|
|
$areaId = intval($v['areaId']);
|
|
$re_area = $this->mdSyliveOrganization->get(['organizationId' => $areaId]);
|
|
$value = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'a_id' => $activityId, 'kpi' => $type]);
|
|
$data[] = ['name' => $re_area['organizationName'], 'value' => $value
|
|
, 'url' => "/sylive/activity/statistics/barchart?activityId={$activityId}&areaId={$areaId}&type={$type}"];
|
|
}
|
|
$this->return_response($data);
|
|
}
|
|
|
|
/**
|
|
* Notes:获取门店柱状数据
|
|
* Created on: 2022/10/9 17:30
|
|
* Created by: dengbw
|
|
*/
|
|
public function statistics_barchart_get()
|
|
{
|
|
$activityId = intval($this->input_param('activityId'));
|
|
$areaId = intval($this->input_param('areaId'));
|
|
$type = $this->input_param('type');
|
|
if (!$activityId || !$areaId || !$type) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
$this->load->model('market/Market_sylive_activity_kpidata_model', 'mdSyliveActivityKpidata');
|
|
$dataTitle = $dataValue = $dataUrl = [];
|
|
$res_biz = $this->mdSyliveActivityBiz->select(['activityId' => $activityId, 'status' => 0], 'browse desc', 0, 0, 'bizId');
|
|
foreach ($res_biz as $k => $v) {
|
|
$bizId = intval($v['bizId']);
|
|
$re_biz = $this->mdSyliveOrganization->get(['organizationId' => $bizId]);
|
|
$value = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'biz_id' => $bizId, 'a_id' => $activityId, 'kpi' => $type]);
|
|
$dataTitle[] = $re_biz['organizationName'];
|
|
$dataValue[] = $value;
|
|
$dataUrl[] = "/sylive/activity/statistics/storebarchart?activityId={$activityId}&bizId={$bizId}&type={$type}";
|
|
}
|
|
$data['dataTitle'] = $dataTitle;
|
|
$data['dataValue'] = $dataValue;
|
|
$data['dataUrl'] = $dataUrl;
|
|
$this->return_response($data);
|
|
}
|
|
|
|
/**
|
|
* Notes:获取顾问柱状数据
|
|
* Created on: 2022/10/10 10:08
|
|
* Created by: dengbw
|
|
*/
|
|
public function statistics_storebarchart_get()
|
|
{
|
|
$activityId = intval($this->input_param('activityId'));
|
|
$bizId = intval($this->input_param('bizId'));
|
|
$type = $this->input_param('type');
|
|
if (!$activityId || !$bizId || !$type) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
$this->load->model('market/Market_sylive_activity_kpidata_model', 'mdSyliveActivityKpidata');
|
|
$this->load->model('market/Market_sylive_user_model', 'mdSyliveUser');
|
|
$dataTitle = $dataValue = [];
|
|
$res_user = $this->mdSyliveActivityKpidata->select(['a_id' => $activityId, 'biz_id' => $bizId], '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' => $userId]);
|
|
if ($re_user) {
|
|
$dataTitle[] = $re_user['uname'] ? $re_user['uname'] : $re_user['nickname'];
|
|
$dataValue[] = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'cf_uid' => $userId, 'kpi' => $type]);
|
|
}
|
|
}
|
|
$data['dataTitle'] = $dataTitle;
|
|
$data['dataValue'] = $dataValue;
|
|
$this->return_response($data);
|
|
}
|
|
|
|
/**
|
|
* 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'];
|
|
$item_title = $params['item_title'];
|
|
$uname = $params['uname'];
|
|
$mobile = $params['mobile'];
|
|
$status = $params['status'];
|
|
$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 {
|
|
$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;
|
|
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(['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']];
|
|
}
|
|
}
|
|
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)
|
|
{
|
|
$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;
|
|
}
|
|
|
|
} |