458 lines
18 KiB
PHP
458 lines
18 KiB
PHP
<?php
|
|
/**
|
|
* 私域直播
|
|
*/
|
|
class Sylive_data_entity{
|
|
|
|
const DF_IMG = 'https://qs.haodian.cn/web/images/project/H5-ShiYu/goodslogo.jpg'; //东风图标
|
|
|
|
private $ci;
|
|
private $map_kpi_biz = [
|
|
'browse' => 'browse', 'subscribe' => 'subscribe', 'order' => 'orderTotal','watch' => 'watch'
|
|
];
|
|
|
|
public function __construct(){
|
|
$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('live/Live_polyv_viewlog_model', 'mdPolyvViewlog');
|
|
$this->ci->load->model('market/market_sylive_team_model');
|
|
$this->ci->load->model('market/market_sylive_viewlog_model');
|
|
}
|
|
|
|
/**
|
|
* 根据kpi排名
|
|
* @param $params ['activityId','kpi','createTime']
|
|
* @param $gtype 分组类型(biz 店铺 gw 顾问)
|
|
* @param $page
|
|
* @param $size
|
|
* @param $biz_id
|
|
* @return array
|
|
*/
|
|
public function top_biz_kpidata($params,$gtype='biz', $page=1, $size=10, $biz_id=0){
|
|
$t1 = $gtype=='gw' ? 'lc_market_sylive_activity_user' : 'lc_market_sylive_activity_biz';
|
|
$t2 = 'lc_market_sylive_activity_kpidata';
|
|
$where = [
|
|
"{$t1}.activityId" => $params['activityId'],
|
|
];
|
|
$j_where = [
|
|
"{$t2}.activityId={$t1}.activityId",
|
|
"{$t2}.kpi='{$params['kpi']}'",
|
|
"{$t2}.type=0",
|
|
];
|
|
if($gtype=='gw'){//顾问
|
|
$where["{$t1}.organizationId>"] = 0;
|
|
$j_where[] = "{$t2}.cfUserId={$t1}.userId";
|
|
$fileds = "{$t1}.userId,{$t1}.bizId as organizationId,count({$t2}.id) as t";
|
|
$group_by = "{$t1}.userId";
|
|
}else{ //门店
|
|
$where["{$t1}.status"] = 0;
|
|
$j_where[] = "{$t2}.bizId={$t1}.bizId";
|
|
$fileds = "{$t1}.bizId as organizationId,count({$t2}.id) as t";
|
|
$group_by = "{$t1}.bizId";
|
|
}
|
|
if($params['createTime']){
|
|
$j_where[] = "{$t2}.day='".date('Y-m-d',strtotime($params['createTime']))."'";
|
|
}
|
|
$j_where = implode(' and ',$j_where);
|
|
if($page) {
|
|
$offset = ($page - 1) * $size;
|
|
$limit = $size;
|
|
} else {
|
|
$offset = null;
|
|
$limit = null;
|
|
}
|
|
$total = $this->ci->db->select($fileds)->from("$t1")
|
|
->join("$t2", $j_where, 'left')
|
|
->where($where)->group_by($group_by)->order_by("t desc,{$t1}.id desc")->count_all_results();
|
|
if($total){
|
|
$rows = $this->ci->db->select($fileds)->from("$t1")
|
|
->join("$t2", $j_where, 'left')
|
|
->where($where)->group_by($group_by)->order_by("t desc,{$t1}.id desc")->limit($limit, $offset)
|
|
->get()->result_array();
|
|
if($gtype=='gw'){
|
|
$userIds = implode(',',array_column($rows,'userId'));
|
|
$user_rows = [];
|
|
if($userIds){
|
|
$user_rows = $this->ci->user_model->map('userId','',["userId in ($userIds)"=>null],'','','','userId,uname');
|
|
}
|
|
}
|
|
$biz_ids = implode(',',array_column($rows,'organizationId'));
|
|
$org_rows = [];
|
|
if($biz_ids){
|
|
$org_rows = $this->ci->market_sylive_organization_model->map('organizationId','',["organizationId in ($biz_ids)"=>null],'','','','organizationId,organizationName');
|
|
}
|
|
$num_tip = $params['kpi'] == 'order' ? '单' : '人';
|
|
$start = $page>1 ? ($page-1)*$size : 0;
|
|
foreach ($rows as $key=>$val) {
|
|
$name = $tip = '';
|
|
if($gtype=='gw'){
|
|
$user = $user_rows[$val['userId']] ? $user_rows[$val['userId']][0] : [];
|
|
$org = $org_rows[$val['organizationId']] ? $org_rows[$val['organizationId']][0] : [];
|
|
$name = $user['uname'];
|
|
$org['organizationName'] && $name.="({$org['organizationName']})";
|
|
if($biz_id>0 && $biz_id==$val['userId']){
|
|
$tip = '本人';
|
|
}
|
|
}else{
|
|
$org = $org_rows[$val['organizationId']] ? $org_rows[$val['organizationId']][0] : [];
|
|
$name = $org['organizationName'];
|
|
if($biz_id>0 && $biz_id==$val['organizationId']){
|
|
$tip = '本店';
|
|
}
|
|
}
|
|
$lists[] = [
|
|
'ranking' => $start+$key+1,
|
|
'name' => $name,
|
|
'num' => $val['t'].$num_tip,
|
|
'tip' => $tip,
|
|
];
|
|
}
|
|
}
|
|
$data = [
|
|
'total' => $total,
|
|
'lists' => $lists
|
|
];
|
|
return $data;
|
|
}
|
|
|
|
//门店排行数据
|
|
public function top_lists($aid,$type='browse',$page=1,$size=10,$biz_id=0){
|
|
$lists = [];
|
|
$where = [
|
|
'activityId' => $aid,
|
|
'status' => 0
|
|
];
|
|
$total = $this->ci->mdSytActivityBiz->count($where);
|
|
$field = $this->map_kpi_biz[$type];
|
|
if($total && $field){
|
|
$rows = $this->ci->mdSytActivityBiz->select($where,"{$field} desc,id desc",$page,$size);
|
|
$biz_ids = implode(',',array_column($rows,'bizId'));
|
|
$org_rows = [];
|
|
if($biz_ids){
|
|
$org_rows = $this->ci->market_sylive_organization_model->map('organizationId','organizationName',["organizationId in ($biz_ids)"],'','','','organizationId,organizationName');
|
|
}
|
|
$start = $page>1 ? ($page-1)*$size : 0;
|
|
$num_tip = $type == 'order' ? '单' : '人';
|
|
foreach ($rows as $key=>$val) {
|
|
$lists[] = [
|
|
'ranking' => $start+$key+1,
|
|
'name' => $org_rows[$val['bizId']] ? $org_rows[$val['bizId']] : '',
|
|
'num' => $val[$this->map_kpi_biz[$type]].$num_tip,
|
|
'tip' => $biz_id==$val['bizId'] ? '本店' : '',
|
|
];
|
|
}
|
|
}
|
|
$data = [
|
|
'total' => $total,
|
|
'lists' => $lists
|
|
];
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* 大区数据排行
|
|
* @param $params
|
|
* @param $page
|
|
* @param $size
|
|
* @param $area_id
|
|
* @return array
|
|
*/
|
|
public function top_area_lists($a_id,$type='', $page=1, $size=20){
|
|
$lists = [];
|
|
$filed = $this->map_kpi_biz[$type];
|
|
if(!$filed){
|
|
return ['lists' => $lists,'total' => 0];
|
|
}
|
|
$where = [
|
|
'activityId' => $a_id,
|
|
'status' => 0,
|
|
'areaId>' => 0,
|
|
];
|
|
$select = "areaId,sum({$filed}) as t";
|
|
$rows = $this->ci->mdSytActivityBiz->select_groupby("areaId",$where,"t desc",$page,$size,$select);
|
|
if($rows){
|
|
$area_ids = implode(',',array_column($rows,'areaId'));
|
|
$org_rows = [];
|
|
if($area_ids){
|
|
$org_rows = $this->ci->market_sylive_organization_model->map('organizationId','organizationName',["organizationId in ($area_ids)"=>null],'','','','organizationId,organizationName');
|
|
}
|
|
$start = $page>1 ? ($page-1)*$size : 0;
|
|
$num_tip = $type == 'order' ? '单' : '人';
|
|
foreach ($rows as $key=>$val) {
|
|
$lists[] = [
|
|
'ranking' => $start+$key+1,
|
|
'name' => $org_rows[$val['areaId']] ? $org_rows[$val['areaId']] : '',
|
|
'num' => $val['t'].$num_tip,
|
|
'tip' => '',
|
|
];
|
|
}
|
|
}
|
|
$data = [
|
|
'total' => 0,
|
|
'lists' => $lists
|
|
];
|
|
return $data;
|
|
}
|
|
/**
|
|
* 根据kpi排名
|
|
* @param $params ['activityId','kpi','createTime']
|
|
* @param $page
|
|
* @param $size
|
|
* @return array
|
|
*/
|
|
public function top_area_kpidata($params, $page=1, $size=20){
|
|
$lists = [];
|
|
$where = [
|
|
'activityId' => $params['activityId'],
|
|
'status' => 0,
|
|
'areaId>' => 0,
|
|
];
|
|
$select = "distinct(areaId)";
|
|
$rows = $this->ci->mdSytActivityBiz->select($where,"",$page,$size,$select);
|
|
if($rows){
|
|
$area_ids = implode(',',array_column($rows,'areaId'));
|
|
$org_rows = $this->ci->market_sylive_organization_model->map('organizationId','',["organizationId in ($area_ids)"=>null],'','','','organizationId,organizationName');
|
|
$start = $page>1 ? ($page-1)*$size : 0;
|
|
$num_tip = $params['kpi'] == 'order' ? '单' : '人';
|
|
foreach ($rows as $key=>$val) {
|
|
$where = [
|
|
'areaId' => $val['areaId'],
|
|
'activityId' => $params['activityId'],
|
|
'status' => 0
|
|
];
|
|
if($params['createTime']){
|
|
$where['day='] = date('Y-m-d',strtotime($params['createTime']));
|
|
}
|
|
$where['kpi'] = $params['kpi'];
|
|
$total = $this->ci->mdSytActivityKpiData->count($where);
|
|
$org = $org_rows[$val['areaId']] ? $org_rows[$val['areaId']][0] : [];
|
|
$lists[] = [
|
|
'ranking' => $start+$key+1,
|
|
'name' => $org ? $org['organizationName'] : '',
|
|
'total' => $total,
|
|
'num' => $total.$num_tip,
|
|
'tip' => '',
|
|
];
|
|
}
|
|
$edit = array_column($lists,'total');
|
|
array_multisort($edit,SORT_DESC,$lists);
|
|
}
|
|
$data = [
|
|
'total' => 0,
|
|
'lists' => $lists
|
|
];
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* 顾问排行
|
|
* @param $a_id
|
|
* @param $type
|
|
* @param $page
|
|
* @param $size
|
|
* @return array
|
|
*/
|
|
public function top_gw_lists($a_id,$type='',$other_where=[], $page=1, $size=20,$userId=0){
|
|
$lists = [];
|
|
$filed = $this->map_kpi_biz[$type];
|
|
if(!$filed){
|
|
return ['lists' => $lists,'total' => 0];
|
|
}
|
|
$where = [
|
|
'activityId' => $a_id,
|
|
'organizationId>' => 0
|
|
];
|
|
$other_where && $where = array_merge($where,$other_where);
|
|
$select = "bizId,userId,{$filed} as t";
|
|
$total = $this->ci->act_user_model->count($where);
|
|
if($total){
|
|
$rows = $this->ci->act_user_model->select($where,"t desc,id desc",$page,$size,$select);
|
|
$user_ids = implode(',',array_column($rows,'userId'));
|
|
$user_rows = [];
|
|
if($user_ids){
|
|
$user_rows = $this->ci->user_model->map('userId','',["userId in ($user_ids)"=>null],'','','','userId,uname,nickname,headimg');
|
|
}
|
|
$biz_ids = implode(',',array_column($rows,'bizId'));
|
|
$biz_rows = [];
|
|
if($biz_ids){
|
|
$biz_rows = $this->ci->market_sylive_organization_model->map('organizationId','',["organizationId in ($biz_ids)"=>null],'','','','organizationId,organizationName');
|
|
}
|
|
$start = $page>1 ? ($page-1)*$size : 0;
|
|
$num_tip = $type == 'order' ? '单' : '人';
|
|
foreach ($rows as $key=>$val) {
|
|
$user = $user_rows[$val['userId']] ? $user_rows[$val['userId']][0] : [];
|
|
$biz = $biz_rows[$val['bizId']] ? $biz_rows[$val['bizId']][0] : [];
|
|
$biz_name = $biz['organizationName'] ? "({$biz['organizationName']})" : '';
|
|
$lists[] = [
|
|
'ranking' => $start+$key+1,
|
|
'name' => $user['uname'].$biz_name,
|
|
'num' => $val['t'].$num_tip,
|
|
'tip' => $userId==$val['userId'] ? '本人' : '',
|
|
'headimg' => $user['headimg']
|
|
];
|
|
}
|
|
}
|
|
$data = [
|
|
'total' => $total,
|
|
'lists' => $lists
|
|
];
|
|
return $data;
|
|
}
|
|
|
|
//团队排行数据
|
|
public function top_team_lists($aid,$type='browse',$other_where=[],$page=1,$size=10,$teamId=0){
|
|
$lists = [];
|
|
$where = [
|
|
'activityId' => $aid,
|
|
'status' => 0
|
|
];
|
|
$other_where && $where = array_merge($where,$other_where);
|
|
$total = $this->ci->mdSytActivityTeam->count($where);
|
|
$field = $this->map_kpi_biz[$type];
|
|
if($total && $field){
|
|
$rows = $this->ci->mdSytActivityTeam->select($where,"{$field} desc,id desc",$page,$size);
|
|
$team_ids = implode(',',array_column($rows,'teamId2'));
|
|
$org_rows = [];
|
|
if($team_ids){
|
|
$org_rows = $this->ci->market_sylive_team_model->map('teamId','teamName',["teamId in ($team_ids)"=>null],'','','','teamId,teamName');
|
|
}
|
|
$num_tip = $type == 'order' ? '单' : '人';
|
|
$start = $page>1 ? ($page-1)*$size : 0;
|
|
foreach ($rows as $key=>$val) {
|
|
$lists[] = [
|
|
'ranking' => $start+$key+1,
|
|
'name' => $org_rows[$val['teamId2']] ? $org_rows[$val['teamId2']] : '',
|
|
'num' => $val[$this->map_kpi_biz[$type]].$num_tip,
|
|
'tip' => $teamId==$val['teamId2'] ? '我的团队' : '',
|
|
];
|
|
}
|
|
}
|
|
$data = [
|
|
'total' => $total,
|
|
'lists' => $lists
|
|
];
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* 团员排行
|
|
* @param $a_id
|
|
* @param $type
|
|
* @param $page
|
|
* @param $size
|
|
* @return array
|
|
*/
|
|
public function top_team_user_lists($a_id,$type='',$other_where=[], $page=1, $size=20,$userId=0){
|
|
$lists = [];
|
|
$filed = $this->map_kpi_biz[$type];
|
|
if(!$filed){
|
|
return ['lists' => $lists,'total' => 0];
|
|
}
|
|
$where = [
|
|
'activityId' => $a_id,
|
|
'teamId>' => 0
|
|
];
|
|
$other_where && $where = array_merge($where,$other_where);
|
|
$select = "userId,{$filed} as t";
|
|
$total = $this->ci->act_user_model->count($where);
|
|
if($total){
|
|
$rows = $this->ci->act_user_model->select($where,"t desc",$page,$size,$select);
|
|
$user_ids = implode(',',array_column($rows,'userId'));
|
|
$user_rows = [];
|
|
if($user_ids){
|
|
$user_rows = $this->ci->user_model->map('userId','',["userId in ($user_ids)"=>null],'','','','userId,uname,nickname,headimg');
|
|
}
|
|
$num_tip = $type == 'order' ? '单' : '人';
|
|
$start = $page>1 ? ($page-1)*$size : 0;
|
|
foreach ($rows as $key=>$val) {
|
|
$user = $user_rows[$val['userId']] ? $user_rows[$val['userId']][0] : [];
|
|
$name =$user['uname'] ? $user['uname'] : $user['nickname'];
|
|
$lists[] = [
|
|
'ranking' => $start+$key+1,
|
|
'uid' => $val['userId'],
|
|
'name' => name_asterisk($name),
|
|
'headimg' => self::DF_IMG,
|
|
'total' => $val['t'],
|
|
'num' => $val['t'].$num_tip,
|
|
'tip' => $userId==$val['userId'] ? '本人' : '',
|
|
];
|
|
}
|
|
}
|
|
$data = [
|
|
'total' => $total,
|
|
'lists' => $lists
|
|
];
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* @return void
|
|
*/
|
|
public function top_kpidata($groupby,$where,$order,$page=1,$page_size=20,$select='',$teamId=0){
|
|
$total = $this->ci->mdSytActivityKpiData->count($where,$groupby);
|
|
$lists = [];
|
|
if($total){
|
|
$rows = $this->ci->mdSytActivityKpiData->select_groupby($groupby, $where, $order, $page, $page_size, $select);
|
|
$org_rows = [];
|
|
if($groupby=='cfUserId'){//顾问
|
|
$user_ids = implode(',',array_column($rows,'cfUserId'));
|
|
if($user_ids){
|
|
$org_rows = $this->ci->user_model->map('userId','',["userId in ($user_ids)"=>null],'','','','userId,uname as name,headimg');
|
|
}
|
|
$biz_ids = implode(',',array_column($rows,'teamId2'));
|
|
$biz_rows = [];
|
|
if($biz_ids){
|
|
$biz_rows = $this->ci->market_sylive_organization_model->map('organizationId','',["organizationId in ($biz_ids)"=>null],'','','','organizationId,organizationName');
|
|
}
|
|
}else{
|
|
$team_ids = implode(',',array_column($rows,'teamId2'));
|
|
if($team_ids){
|
|
$org_rows = $this->ci->market_sylive_team_model->map('teamId','',["teamId in ($team_ids)"=>null],'','','','teamId,teamName as name');
|
|
}
|
|
}
|
|
$num_tip = $where['kpi'] == 'order' ? '单' : '人';
|
|
$start = $page>1 ? ($page-1)*$page_size : 0;
|
|
foreach ($rows as $key=>$val) {
|
|
$headimg = $biz_name = '';
|
|
if($groupby=='cfUserId'){
|
|
$org = $org_rows[$val['cfUserId']] ? $org_rows[$val['cfUserId']][0] : [];
|
|
$tip = $teamId==$val['cfUserId'] ? '本人' : '';
|
|
$biz = $biz_rows[$val['teamId2']] ? $biz_rows[$val['teamId2']][0] : [];
|
|
$biz_name = $biz['organizationName'] ? "({$biz['organizationName']})" : '';
|
|
$headimg = $org['headimg'];
|
|
}else{
|
|
$org = $org_rows[$val['teamId2']] ? $org_rows[$val['teamId2']][0] : [];
|
|
$tip = $teamId==$val['teamId2'] ? '我的团队' : '';
|
|
}
|
|
$lists[] = [
|
|
'ranking' => $start+$key+1,
|
|
'name' => $org['name'].$biz_name,
|
|
'num' => $val['t'].$num_tip,
|
|
'headimg' => $headimg,
|
|
'tip' => $tip,
|
|
];
|
|
}
|
|
}
|
|
$data = [
|
|
'total' => $total,
|
|
'lists' => $lists
|
|
];
|
|
return $data;
|
|
}
|
|
public function __get($name)
|
|
{
|
|
if ('_model' === substr($name, -6)) {
|
|
return $this->ci->$name;
|
|
} elseif ('load' == $name) {
|
|
return $this->ci->load;
|
|
}
|
|
return null;
|
|
}
|
|
} |