1092 lines
61 KiB
PHP
1092 lines
61 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']) {//品牌机构
|
|
$str_organizationIds = '-1';
|
|
$re_org = $this->mdSyliveOrganization->get(['organizationName' => $_SESSION['brandName'], 'parentId' => 0, 'status' => 0]);
|
|
if ($re_org['organizationId']) {//查找大区
|
|
$res_all = $this->mdSyliveOrganization->select(['parentId' => $re_org['organizationId'], 'organizationType' => 2, 'status' => 0]
|
|
, 'sortNumber asc,organizationId desc', 0, 0, 'organizationId');
|
|
$res_all && $str_organizationIds = implode(',', array_column($res_all, 'organizationId'));
|
|
}
|
|
$where["activityId in(select distinct(activityId) as activityId from lc_market_sylive_activity_biz WHERE areaId in({$str_organizationIds}) AND status=0)"] = 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 = $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 ($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;//活动连接
|
|
$urlItem = http_host_com('home') . "/h5/market/sylive/act/item?skey=" . $skey;//商品连接
|
|
$list[] = [
|
|
'activityId' => $activityId, 'title' => $v['title'], 'channelId' => $v['channelId'], 'bizIds' => $bizIds, 'teamIds' => $teamIds, 'pay' => $pay,
|
|
'introduction' => $v['introduction'], 'shareTitle' => $shareTitle, 'dateRange' => $dateRange, 'urlItem' => $urlItem, 'coupon' => $coupon,
|
|
'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');
|
|
$teamIds = $this->input_param('teamIds');
|
|
$pay = $this->input_param('pay');
|
|
if (!$title) {
|
|
$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);
|
|
}
|
|
if ($pay['way'] > 1) {
|
|
$pay['img'] = $pay['img'][0]['fileUrl'] ? $pay['img'][0]['fileUrl'] : '';
|
|
} else {
|
|
$pay = ['way' => 1, 'price' => '', 'img' => []];
|
|
}
|
|
$jsondata['pay'] = $pay;
|
|
$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
|
|
, '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('添加活动失败');
|
|
}
|
|
if ($bizIds) {
|
|
$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);
|
|
}
|
|
}
|
|
if ($teamIds) {
|
|
$teamIds = implode(',', $teamIds);
|
|
$res_org = $this->mdSyliveTeam->select(["teamId in({$teamIds})" => null, 'teamType' => 3], 'teamId desc', 0, 0, 'teamId,parentId');
|
|
$add_biz = [];
|
|
if ($res_org) {
|
|
$this->mdSyliveActivityTeam->update(['status' => -1], ["teamId2 not in({$teamIds})" => null, 'activityId' => $activityId, 'status' => 0]);
|
|
foreach ($res_org as $v) {
|
|
$teamId1 = $v['parentId'];
|
|
$teamId2 = $v['teamId'];
|
|
if ($v['parentId']) {
|
|
$re_team = $this->mdSyliveTeam->get(["teamId" => $v['parentId']]);
|
|
if ($re_team && $re_team['parentId']) {
|
|
$teamId1 = $re_team['parentId'];
|
|
$teamId2 = $re_team['teamId'];
|
|
}
|
|
}
|
|
$add_biz[] = ['activityId' => $activityId, 'teamId1' => $teamId1
|
|
, 'teamId2' => $teamId2, 'createTime' => date('Y-m-d H:i:s')];
|
|
}
|
|
//增加活动商家
|
|
$add_biz && $this->mdSyliveActivityTeam->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');
|
|
$teamIds = $this->input_param('teamIds');
|
|
$pay = $this->input_param('pay');
|
|
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('请选择直播时间');
|
|
}
|
|
// if (!$introduction) {
|
|
// $this->return_json('请输入活动简介');
|
|
// }
|
|
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
|
|
if (!$re) {
|
|
$this->return_json('活动不存在');
|
|
}
|
|
if ($bizIds) {
|
|
$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);
|
|
}
|
|
} 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' => 3], 'teamId desc', 0, 0, 'teamId,parentId');
|
|
$add_biz = [];
|
|
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) {
|
|
$teamId1 = $v['parentId'];
|
|
$teamId2 = $v['teamId'];
|
|
if ($v['parentId']) {
|
|
$re_team = $this->mdSyliveTeam->get(["teamId" => $v['parentId']]);
|
|
if ($re_team && $re_team['parentId']) {
|
|
$teamId1 = $re_team['parentId'];
|
|
$teamId2 = $re_team['teamId'];
|
|
}
|
|
}
|
|
$add_biz[] = ['activityId' => $activityId, 'teamId1' => $teamId1
|
|
, 'teamId2' => $teamId2, 'createTime' => date('Y-m-d H:i:s')];
|
|
} else if ($re_org['status'] == -1) {
|
|
$this->mdSyliveActivityTeam->update(['status' => 0], ['id' => $re_org['id']]);
|
|
}
|
|
}
|
|
//增加活动商家
|
|
$add_biz && $this->mdSyliveActivityTeam->add_batch($add_biz);
|
|
}
|
|
} else {
|
|
$this->mdSyliveActivityTeam->update(['status' => -1], ['activityId' => $activityId, 'status' => 0]);
|
|
}
|
|
$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);
|
|
}
|
|
$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 = json_encode($jsondata, JSON_UNESCAPED_UNICODE);
|
|
$upDate = ['title' => $title, 'bgImg' => $bgImg, 'channelImg' => $channelImg, 'channelId' => $channelId, 'introduction' => $introduction,
|
|
'shareTitle' => $shareTitle, 'sharePhoto' => $sharePhoto, 'shareImg' => $setShareImg, 'jsondata' => $jsondata,
|
|
'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');
|
|
$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/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 = $allOrganizationIds = [];
|
|
$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, 'type' => 0, 'a_id' => $activityId], 'distinct(cf_uid)');
|
|
$browse = $this->mdSyliveActivityKpidata->count(['biz_id' => $bizId, 'type' => 0, 'a_id' => $activityId, 'kpi' => 'browse']);
|
|
$subscribe = $this->mdSyliveActivityKpidata->count(['biz_id' => $bizId, 'type' => 0, 'a_id' => $activityId, 'kpi' => 'subscribe']);
|
|
$watch = $this->mdSyliveActivityKpidata->count(['biz_id' => $bizId, 'type' => 0, 'a_id' => $activityId, 'kpi' => 'watch']);
|
|
$order = $this->mdSyliveActivityKpidata->count(['biz_id' => $bizId, 'type' => 0, '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.type' => 0, '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']) {
|
|
$playDuration = ceil($re_sum['playDuration'] / 60);
|
|
$watchDuration = round($playDuration / $livePV);
|
|
}
|
|
}
|
|
}
|
|
//统计顾问
|
|
$allConsultant = 0;
|
|
if ($areaId) {
|
|
if (!in_array($areaId, $allOrganizationIds)) {
|
|
$allOrganizationIds[] = $areaId;
|
|
}
|
|
}
|
|
if ($bizId) {
|
|
$allOrganizationIds[] = $bizId;
|
|
$areaAry[$areaId]['biz'][] = $bizId;
|
|
$consultants = [];
|
|
$consultants[] = $bizId;
|
|
$res_org = $this->mdSyliveOrganization->select(['parentId' => $bizId, 'status>=' => 0], 'organizationId desc', 0, 0, 'organizationId');
|
|
foreach ($res_org as $k2 => $v2) {
|
|
$allOrganizationIds[] = $v2['organizationId'];
|
|
$areaAry[$areaId]['sales'][] = $v2['organizationId'];
|
|
$consultants[] = $v2['organizationId'];
|
|
}
|
|
$str_organizationIds = implode(',', array_unique($consultants));
|
|
$allConsultant = $this->mdSyliveUser->count(["organizationId in({$str_organizationIds})" => null, 'status>=' => 0, 'organizationId>' => 0]);
|
|
}
|
|
$consultant > $allConsultant && $allConsultant = $consultant;
|
|
$bizData[] = ['areaId' => $areaId, 'bizId' => $bizId,
|
|
'bizName' => $re_biz['organizationName'], 'consultant' => $consultant . '/' . $allConsultant, 'browse' => $browse, 'subscribe' => $subscribe
|
|
, 'watch' => $watch, 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration];
|
|
}
|
|
}
|
|
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, 'type' => 0, 'a_id' => $activityId], 'distinct(cf_uid)');
|
|
$browse = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'type' => 0, 'a_id' => $activityId, 'kpi' => 'browse']);
|
|
$subscribe = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'type' => 0, 'a_id' => $activityId, 'kpi' => 'subscribe']);
|
|
$watch = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'type' => 0, 'a_id' => $activityId, 'kpi' => 'watch']);
|
|
$order = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'type' => 0, '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.type' => 0, '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']) {
|
|
$playDuration = ceil($re_sum['playDuration'] / 60);
|
|
$watchDuration = round($playDuration / $livePV);
|
|
}
|
|
}
|
|
}
|
|
$allConsultant = 0;
|
|
if ($v['biz']) {
|
|
$organizationIds = $v['sales'] ? array_merge($v['biz'], $v['sales']) : $v['biz'];
|
|
$str_organizationIds = implode(',', array_unique($organizationIds));
|
|
$allConsultant = $this->mdSyliveUser->count(["organizationId in({$str_organizationIds})" => null, 'status>=' => 0, 'organizationId>' => 0]);
|
|
}
|
|
$consultant > $allConsultant && $allConsultant = $consultant;
|
|
$areaData[] = ['areaName' => $re_area['organizationName'], 'biz' => count($v['biz']), 'consultant' => $consultant . '/' . $allConsultant
|
|
, '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,biz_id');
|
|
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'];
|
|
$re_org = $this->mdSyliveOrganization->get(['organizationId' => $v['biz_id']]);
|
|
$re_org && $consultantName .= "({$re_org['organizationName']})";
|
|
$browse = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'cf_uid' => $userId, 'kpi' => 'browse']);
|
|
$subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'cf_uid' => $userId, 'kpi' => 'subscribe']);
|
|
$watch = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'cf_uid' => $userId, 'kpi' => 'watch']);
|
|
$order = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, '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.type' => 0, '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']) {
|
|
$playDuration = ceil($re_sum['playDuration'] / 60);
|
|
$watchDuration = round($playDuration / $livePV);
|
|
}
|
|
}
|
|
}
|
|
$consultantData[] = ['consultantName' => $consultantName, 'browse' => $browse, 'subscribe' => $subscribe, 'watch' => $watch
|
|
, 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration];
|
|
}
|
|
}
|
|
$browse = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'kpi' => 'browse']);
|
|
$subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'kpi' => 'subscribe']);
|
|
$watch = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'kpi' => 'watch']);
|
|
$order = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'kpi' => 'order']);
|
|
$duration = $livePV = $watchDuration = $watchDuration = $pvDuration = 0;
|
|
if ($channelId) {
|
|
$re_duration = $this->mdPolyvSession->sum('duration', ['channelId' => $channelId]);
|
|
if ($re_duration['duration']) {
|
|
$re_liveUV = $this->mdPolyvSession->sum('liveUV', ['channelId' => $channelId]);
|
|
$re_livePV = $this->mdPolyvSession->sum('livePV', ['channelId' => $channelId]);
|
|
$duration = ceil($re_duration['duration'] / 60);
|
|
$livePV = $re_livePV['livePV'];
|
|
$watchDuration = round($duration / $livePV);
|
|
$pvDuration = round($livePV / $re_liveUV['liveUV'], 1);
|
|
}
|
|
}
|
|
$allConsultant = 0;
|
|
$consultant = count($res_user);
|
|
if ($allOrganizationIds) {
|
|
$str_organizationIds = implode(',', array_unique($allOrganizationIds));
|
|
$allConsultant = $this->mdSyliveUser->count(["organizationId in({$str_organizationIds})" => null, 'status>=' => 0, 'organizationId>' => 0]);
|
|
}
|
|
$consultant > $allConsultant && $allConsultant = $consultant;
|
|
$activityData1 = [['name' => '参与区域数', 'value' => count($areaData)], ['name' => '参与门店数', 'value' => count($bizData)]
|
|
, ['name' => '参与/全部顾问数', 'value' => $consultant . '/' . $allConsultant]];
|
|
$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' => ''], ['name' => '人均观看(次)', 'value' => $pvDuration, '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 / $watch_per * 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 = "uid in(select uid from lc_market_sylive_activity_kpidata where a_id = {$activityId} AND type = 0 AND kpi = 'subscribe')";
|
|
$watch_subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'kpi' => 'watch', $id_in => null]);
|
|
$order_subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'kpi' => 'order', $id_in => null]);
|
|
$subscribe_per = number_format_com($subscribe / $browse * 100, 1, '');
|
|
$watch_subscribe_per = number_format_com($watch_subscribe / $subscribe * 100, 1, '');
|
|
$order_subscribe_per = number_format_com($order_subscribe / $watch_subscribe * 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/24 10:02
|
|
* Created by: dengbw
|
|
* @param null $activityId
|
|
*/
|
|
public function statistics_team_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 = $teamData = $consultantData = $funnel = $allTeamIds = [];
|
|
$browse = $subscribe = $watch = $order = 0;
|
|
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
|
|
if ($re) {
|
|
$title = $re['title'];
|
|
$channelId = $re['channelId'];
|
|
$res_biz = $this->mdSyliveActivityTeam->select(['activityId' => $activityId, 'status' => 0], 'browse desc');
|
|
foreach ($res_biz as $k => $v) {
|
|
$area_id = intval($v['teamId1']);
|
|
$biz_id = intval($v['teamId2']);
|
|
$re_team = $this->mdSyliveTeam->get(['teamId' => $biz_id]);
|
|
if ($re_team) {
|
|
$consultant = $this->mdSyliveActivityKpidata->count(['biz_id' => $biz_id, 'type' => 1, 'a_id' => $activityId], 'distinct(cf_uid)');
|
|
$browse = $this->mdSyliveActivityKpidata->count(['biz_id' => $biz_id, 'type' => 1, 'a_id' => $activityId, 'kpi' => 'browse']);
|
|
$subscribe = $this->mdSyliveActivityKpidata->count(['biz_id' => $biz_id, 'type' => 1, 'a_id' => $activityId, 'kpi' => 'subscribe']);
|
|
$watch = $this->mdSyliveActivityKpidata->count(['biz_id' => $biz_id, 'type' => 1, 'a_id' => $activityId, 'kpi' => 'watch']);
|
|
$order = $this->mdSyliveActivityKpidata->count(['biz_id' => $biz_id, 'type' => 1, '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' => $biz_id, 'a.type' => 1, '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']) {
|
|
$playDuration = ceil($re_sum['playDuration'] / 60);
|
|
$watchDuration = round($playDuration / $livePV);
|
|
}
|
|
}
|
|
}
|
|
//统计顾问
|
|
$allConsultant = 0;
|
|
if ($area_id) {
|
|
if (!in_array($area_id, $allTeamIds)) {
|
|
$allTeamIds[] = $area_id;
|
|
}
|
|
}
|
|
if ($biz_id) {
|
|
$allTeamIds[] = $biz_id;
|
|
$consultants = [];
|
|
$consultants[] = $biz_id;
|
|
$res_org = $this->mdSyliveTeam->select(['parentId' => $biz_id, 'status>=' => 0], 'teamId desc', 0, 0, 'teamId');
|
|
foreach ($res_org as $k2 => $v2) {
|
|
$allTeamIds[] = $v2['teamId'];
|
|
$consultants[] = $v2['teamId'];
|
|
}
|
|
$str_teamId = implode(',', array_unique($consultants));
|
|
$allConsultant = $this->mdSyliveUser->count(["teamId in({$str_teamId})" => null, 'status>=' => 0, 'teamId>' => 0]);
|
|
}
|
|
$consultant > $allConsultant && $allConsultant = $consultant;
|
|
$teamData[] = ['area_id' => $area_id, 'biz_id' => $biz_id,
|
|
'teamName' => $re_team['teamName'], 'consultant' => $consultant . '/' . $allConsultant, 'browse' => $browse, 'subscribe' => $subscribe
|
|
, 'watch' => $watch, 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration];
|
|
}
|
|
}
|
|
$res_user = $this->mdSyliveActivityKpidata->select(['a_id' => $activityId, 'type' => 1], 'id desc', 0, 0, 'distinct(cf_uid) as userId,biz_id');
|
|
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'];
|
|
$re_team = $this->mdSyliveTeam->get(['teamId' => $v['biz_id']]);
|
|
$re_team && $consultantName .= "({$re_team['teamName']})";
|
|
$browse = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'cf_uid' => $userId, 'kpi' => 'browse']);
|
|
$subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'cf_uid' => $userId, 'kpi' => 'subscribe']);
|
|
$watch = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'cf_uid' => $userId, 'kpi' => 'watch']);
|
|
$order = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, '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.type' => 1, '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']) {
|
|
$playDuration = ceil($re_sum['playDuration'] / 60);
|
|
$watchDuration = round($playDuration / $livePV);
|
|
}
|
|
}
|
|
}
|
|
$consultantData[] = ['consultantName' => $consultantName, 'browse' => $browse, 'subscribe' => $subscribe, 'watch' => $watch
|
|
, 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration];
|
|
}
|
|
}
|
|
$browse = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'kpi' => 'browse']);
|
|
$subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'kpi' => 'subscribe']);
|
|
$watch = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'kpi' => 'watch']);
|
|
$order = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'kpi' => 'order']);
|
|
$duration = $livePV = $watchDuration = $watchDuration = $pvDuration = 0;
|
|
if ($channelId) {
|
|
$re_duration = $this->mdPolyvSession->sum('duration', ['channelId' => $channelId]);
|
|
if ($re_duration['duration']) {
|
|
$re_liveUV = $this->mdPolyvSession->sum('liveUV', ['channelId' => $channelId]);
|
|
$re_livePV = $this->mdPolyvSession->sum('livePV', ['channelId' => $channelId]);
|
|
$duration = ceil($re_duration['duration'] / 60);
|
|
$livePV = $re_livePV['livePV'];
|
|
$watchDuration = round($duration / $livePV);
|
|
$pvDuration = round($livePV / $re_liveUV['liveUV'], 1);
|
|
}
|
|
}
|
|
$allConsultant = 0;
|
|
$consultant = count($res_user);
|
|
if ($allTeamIds) {
|
|
$str_allTeamIds = implode(',', array_unique($allTeamIds));
|
|
$allConsultant = $this->mdSyliveUser->count(["teamId in({$str_allTeamIds})", 'status>=' => 0, 'teamId>' => 0]);
|
|
}
|
|
$consultant > $allConsultant && $allConsultant = $consultant;
|
|
$activityData1 = [['name' => '参与团队数', 'value' => count($teamData)]
|
|
, ['name' => '参与/全部团员数', 'value' => $consultant . '/' . $allConsultant]];
|
|
$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' => ''], ['name' => '人均观看(次)', 'value' => $pvDuration, 'url' => '']];
|
|
}
|
|
$watch_per = number_format_com($watch / $browse * 100, 1, '');
|
|
$order_per = number_format_com($order / $watch_per * 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 = "uid in(select uid from lc_market_sylive_activity_kpidata where a_id = {$activityId} AND type=1 AND kpi = 'subscribe')";
|
|
$watch_subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'kpi' => 'watch', $id_in => null]);
|
|
$order_subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'kpi' => 'order', $id_in => null]);
|
|
$subscribe_per = number_format_com($subscribe / $browse * 100, 1, '');
|
|
$watch_subscribe_per = number_format_com($watch_subscribe / $subscribe * 100, 1, '');
|
|
$order_subscribe_per = number_format_com($order_subscribe / $watch_subscribe * 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,
|
|
'teamData' => $teamData, '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'];
|
|
$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['item_id'] = $activityId;
|
|
$uname && $where['uname'] = $uname;
|
|
$mobile && $where['mobile'] = $mobile;
|
|
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(['a_id' => $v['item_id'], 'cfrom' => $v['cfrom'], 'uid' => $v['uid']]);
|
|
$list[] = [
|
|
'id' => $v['id'], 'sid' => $v['sid'], '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']), '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(['a_id' => $params['a_id'], 'uid' => $params['uid'], 'type' => $params['cfrom'], 'kpi' => 'order']);
|
|
if ($re['cf_uid']) {
|
|
if ($params['cfrom'] == 1) {
|
|
$res_teama = $this->mdSyliveTeam->get(["teamId" => $re['area_id']]);
|
|
$res_teamb = $this->mdSyliveTeam->get(["teamId" => $re['biz_id']]);
|
|
$res_teama['teamName'] && $area = $res_teama['teamName'];
|
|
$res_teamb['teamName'] && $stores = $res_teamb['teamName'];
|
|
} else {
|
|
$res_orga = $this->mdSyliveOrganization->get(["organizationId" => $re['area_id']]);
|
|
$res_orgb = $this->mdSyliveOrganization->get(["organizationId" => $re['biz_id']]);
|
|
$res_orga['organizationName'] && $area = $res_orga['organizationName'];
|
|
$res_orgb['organizationName'] && $stores = $res_orgb['organizationName'];
|
|
}
|
|
$re_user = $this->mdSyliveUser->get(['userId' => $re['cf_uid']]);
|
|
$re_user['uname'] && $consultant = $re_user['uname'];
|
|
}
|
|
return ['area' => $area, 'stores' => $stores, 'consultant' => $consultant];
|
|
}
|
|
|
|
} |