177 lines
8.5 KiB
PHP
177 lines
8.5 KiB
PHP
<?php
|
|
/**
|
|
* 私域直播
|
|
*/
|
|
class Sylive2_data_entity{
|
|
|
|
const DF_IMG = 'https://qs.liche.cn/web/images/project/H5-ShiYu/goodslogo.jpg'; //东风图标
|
|
|
|
private $ci;
|
|
private $show_echarts = false;
|
|
private $map_kpi_biz = [
|
|
'browse' => 'browse', 'subscribe' => 'subscribe', 'order' => 'orderTotal','watch' => 'watch','beforeOrder' => 'beforeOrderTotal'
|
|
];
|
|
|
|
public function __construct($params = []){
|
|
$this->ci = &get_instance();
|
|
$this->ci->load->model('market/market_sylive_user_model', 'user_model');
|
|
$this->ci->load->model('market/market_sylive_activity_user_model', 'act_user_model');
|
|
$this->ci->load->model('market/market_sylive_activity_model');
|
|
$this->ci->load->model('market/market_sylive_activity_biz_model','mdSytActivityBiz');
|
|
$this->ci->load->model('market/market_sylive_activity_team_model','mdSytActivityTeam');
|
|
$this->ci->load->model('market/market_sylive_activity_kpidata_model','mdSytActivityKpiData');
|
|
$this->ci->load->model('market/market_sylive_organization_model');
|
|
$this->ci->load->model('market/market_sylive_activity_orders_model','mdSytActivityOrders');
|
|
$this->ci->load->model('market/market_sylive_viewlog_model');
|
|
$this->load->model('market/market_sylive_groups_model', 'groups_model');
|
|
$this->load->model('market/market_sylive_groups_user_model', 'groups_user_model');
|
|
$params['show_echarts'] && $this->show_echarts = true;
|
|
}
|
|
|
|
/**
|
|
* @return void
|
|
*/
|
|
public function top_kpidata($groupby,$where,$order,$page=1,$page_size=20,$select='',$tagId=0){
|
|
$total = $this->ci->mdSytActivityKpiData->count($where,$groupby);
|
|
$pieChart = $lists = [];
|
|
if($total){
|
|
$rows = $this->ci->mdSytActivityKpiData->select_groupby($groupby, $where, $order, $page, $page_size, $select);
|
|
$other_total = 0;
|
|
$this->show_echarts && $other_total = $this->ci->mdSytActivityKpiData->count($where);
|
|
$biz_rows = $target_rows = [];
|
|
if($groupby=='bizId'){
|
|
$biz_ids = implode(',',array_column($rows,'tagId'));
|
|
$biz_ids && $target_rows = $this->ci->groups_model->map('groupsId','',["groupsId in ($biz_ids)"=>null],'','','','groupsId,groupsName');
|
|
}elseif($groupby=='levelId1'||$groupby=='levelId2'||$groupby=='levelId3'){
|
|
$biz_ids = implode(',',array_column($rows,'tagId'));
|
|
$biz_ids && $target_rows = $this->ci->groups_model->map('groupsId','',["groupsId in ($biz_ids)"=>null],'','','','groupsId,groupsName');
|
|
}else{ //顾问
|
|
$user_ids = implode(',',array_column($rows,'tagId'));
|
|
$user_ids && $target_rows = $this->ci->user_model->map('userId','',["userId in ($user_ids)"=>null],'','','','userId,uname as name,headimg');
|
|
$biz_ids = implode(',',array_column($rows,'bizId'));
|
|
$biz_ids && $biz_rows = $this->ci->groups_model->map('groupsId','',["groupsId in ($biz_ids)"=>null],'','','','groupsId,groupsName');
|
|
}
|
|
$num_tip = $where['kpi'] == 'order' ? '单' : '人';
|
|
$start = $page>1 ? ($page-1)*$page_size : 0;
|
|
$i = 0;
|
|
foreach ($rows as $key=>$val) {
|
|
$headimg = '';
|
|
if($groupby=='bizId'){
|
|
$biz = $target_rows[$val['tagId']][0];
|
|
$name = $biz['groupsName'];
|
|
$tip = $tagId==$val['bizId'] ? '本店' : '';
|
|
}elseif($groupby=='levelId1'||$groupby=='levelId2'||$groupby=='levelId3'){
|
|
$biz = $target_rows[$val['tagId']][0];
|
|
$name = $biz['groupsName'];
|
|
}else{
|
|
$org = $target_rows[$val['tagId']] ? $target_rows[$val['tagId']][0] : [];
|
|
$biz = $biz_rows[$val['bizId']] ? $biz_rows[$val['bizId']][0] : [];
|
|
$tip = $tagId==$val['cfUserId'] ? '本人' : '';
|
|
$name = $org['name'];
|
|
$biz && $name="{$biz['groupsName']} {$name}";
|
|
$headimg = $org['headimg'];
|
|
}
|
|
$lists[] = [
|
|
'ranking' => $start+$key+1,
|
|
'name' => $name,
|
|
'num' => $val['t'].$num_tip,
|
|
'headimg' => $headimg,
|
|
'tip' => $tip,
|
|
];
|
|
if($this->show_echarts && $val['t']>0 && $i<5){
|
|
$pieChart[] = ['value'=>$val['t'],'name'=>$name];
|
|
$other_total -= $val['t'];
|
|
}
|
|
$i++;
|
|
}
|
|
if($this->show_echarts && $other_total>0){
|
|
$pieChart[] = ['value'=>$other_total,'name'=>'其它'];
|
|
}
|
|
}
|
|
$data = [
|
|
'total' => $total,
|
|
'lists' => $lists,
|
|
'pieChart' => $pieChart
|
|
];
|
|
return $data;
|
|
}
|
|
/**
|
|
* @return void
|
|
*/
|
|
public function top_groups_user($groupby,$where,$order,$page=1,$page_size=20,$select='',$kpi,$tagId=0){
|
|
$pieChart = [];
|
|
$total = $this->ci->groups_user_model->count($where,$groupby);
|
|
$lists = [];
|
|
if($total){
|
|
$rows = $this->ci->groups_user_model->select_groupby($groupby, $where, $order, $page, $page_size, $select);
|
|
$other_total = 0;
|
|
if($this->show_echarts){
|
|
$sum_key = $this->map_kpi_biz[$kpi];
|
|
$sum_key && $other_sum = $this->ci->groups_user_model->sum($sum_key,$where);
|
|
$other_sum[$sum_key] && $other_total = $other_sum[$sum_key];
|
|
}
|
|
$biz_rows = $target_rows = [];
|
|
if($groupby=='bizId'){
|
|
$biz_ids = implode(',',array_column($rows,'tagId'));
|
|
$biz_ids && $target_rows = $this->ci->groups_model->map('groupsId','',["groupsId in ($biz_ids)"=>null],'','','','groupsId,groupsName');
|
|
}elseif($groupby=='levelId1'||$groupby=='levelId2'||$groupby=='levelId3'){
|
|
$biz_ids = implode(',',array_column($rows,'tagId'));
|
|
$biz_ids && $target_rows = $this->ci->groups_model->map('groupsId','',["groupsId in ($biz_ids)"=>null],'','','','groupsId,groupsName');
|
|
}else{
|
|
$taget_ids = implode(',',array_column($rows,'tagId'));
|
|
$taget_ids && $target_rows = $this->ci->user_model->map('userId','',["userId in ($taget_ids)"=>null],'','','','userId,uname as name,headimg');
|
|
$biz_ids = implode(',',array_column($rows,'bizId'));
|
|
$biz_ids && $biz_rows = $this->ci->groups_model->map('groupsId','',["groupsId in ($biz_ids)"=>null],'','','','groupsId,groupsName');
|
|
}
|
|
$start = $page>1 ? ($page-1)*$page_size : 0;
|
|
$num_tip = $kpi == 'order' ? '单' : '人';
|
|
$i = 0;
|
|
foreach ($rows as $key=>$val) {
|
|
$tip = $headimg = $name = '';
|
|
if($groupby=='bizId'){
|
|
$biz = $target_rows[$val['tagId']][0];
|
|
$name = $biz['groupsName'];
|
|
$tip = $tagId==$val['bizId'] ? '本店' : '';
|
|
}elseif($groupby=='levelId1'||$groupby=='levelId2'||$groupby=='levelId3'){
|
|
$biz = $target_rows[$val['tagId']][0];
|
|
$name = $biz['groupsName'];
|
|
}else{
|
|
$target = $target_rows[$val['tagId']][0];
|
|
$name = $target['name'];
|
|
$biz = $biz_rows[$val['bizId']] ? $biz_rows[$val['bizId']][0] : [];
|
|
$biz && $name="{$biz['groupsName']} {$name}";
|
|
}
|
|
$lists[] = [
|
|
'ranking' => $start+$key+1,
|
|
'name' => $name,
|
|
'num' => $val['t'].$num_tip,
|
|
'headimg' => $headimg,
|
|
'tip' => $tip,
|
|
];
|
|
if($this->show_echarts && $val['t']>0 && $i<5){
|
|
$pieChart[] = ['value'=>$val['t'],'name'=>$name];
|
|
$other_total -= $val['t'];
|
|
}
|
|
$i++;
|
|
}
|
|
if($this->show_echarts && $other_total>0){
|
|
$pieChart[] = ['value'=>$other_total,'name'=>'其它'];
|
|
}
|
|
}
|
|
$data = [
|
|
'total' => $total,
|
|
'lists' => $lists,
|
|
'pieChart' => $pieChart
|
|
];
|
|
return $data;
|
|
}
|
|
public function __get($name)
|
|
{
|
|
if ('_model' === substr($name, -6)) {
|
|
return $this->ci->$name;
|
|
} elseif ('load' == $name) {
|
|
return $this->ci->load;
|
|
}
|
|
return null;
|
|
}
|
|
} |