222 lines
8.2 KiB
PHP
222 lines
8.2 KiB
PHP
<?php
|
|
/**
|
|
* 私域直播
|
|
*/
|
|
class Sylive_data_entity{
|
|
|
|
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
|
|
* @param $page
|
|
* @param $size
|
|
* @param $biz_id
|
|
* @return array
|
|
*/
|
|
public function top_biz_kpidata($params, $page=1, $size=10, $biz_id=0){
|
|
$t1 = 'lc_market_sylive_activity_biz';
|
|
$t2 = 'lc_market_sylive_activity_kpidata';
|
|
$fileds = "{$t1}.bizId,count({$t2}.id) as t";
|
|
$where = [
|
|
"{$t1}.activityId" => $params['activityId'],
|
|
"{$t1}.status" => 0,
|
|
];
|
|
$j_where = [
|
|
"{$t2}.bizId={$t1}.bizId",
|
|
"{$t2}.activityId={$t1}.activityId",
|
|
"{$t2}.kpi='{$params['kpi']}'"
|
|
];
|
|
if($params['createTime']){
|
|
$j_where[] = "{$t2}.createTime>=".strtotime($params['createTime'].' 00:00:00');
|
|
$j_where[] = "{$t2}.createTime<=".strtotime($params['createTime'].' 23:59:59');
|
|
}
|
|
$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("{$t1}.bizId")->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("{$t1}.bizId")->order_by("t desc,{$t1}.id desc")->limit($limit, $offset)
|
|
->get()->result_array();
|
|
$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;
|
|
foreach ($rows as $key=>$val) {
|
|
$lists[] = [
|
|
'ranking' => $start+$key+1,
|
|
'name' => $org_rows[$val['bizId']] ? $org_rows[$val['bizId']] : '',
|
|
'num' => $val['t'].'人',
|
|
'tip' => $biz_id==$val['bizId'] ? '本店' : '',
|
|
];
|
|
}
|
|
}
|
|
$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;
|
|
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]].'人',
|
|
'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,
|
|
'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)"],'','','','organizationId,organizationName');
|
|
}
|
|
$start = $page>1 ? ($page-1)*$size : 0;
|
|
foreach ($rows as $key=>$val) {
|
|
$lists[] = [
|
|
'ranking' => $start+$key+1,
|
|
'name' => $org_rows[$val['areaId']] ? $org_rows[$val['areaId']] : '',
|
|
'num' => $val['t'].'人',
|
|
'tip' => '',
|
|
];
|
|
}
|
|
}
|
|
$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 = "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)"],'','','','userId,uname,nickname,headimg');
|
|
}
|
|
$start = $page>1 ? ($page-1)*$size : 0;
|
|
foreach ($rows as $key=>$val) {
|
|
$user = $user_rows[$val['userId']] ? $user_rows[$val['userId']][0] : [];
|
|
$lists[] = [
|
|
'ranking' => $start+$key+1,
|
|
'name' => $user['uname'],
|
|
'num' => $val['t'].'人',
|
|
'tip' => $userId==$val['userId'] ? '本人' : '',
|
|
'headimg' => $user['headimg']
|
|
];
|
|
}
|
|
}
|
|
$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;
|
|
}
|
|
} |