diff --git a/common/libraries/market/Sylive_data_entity.php b/common/libraries/market/Sylive_data_entity.php index 499ed4bb..da8ac889 100644 --- a/common/libraries/market/Sylive_data_entity.php +++ b/common/libraries/market/Sylive_data_entity.php @@ -25,9 +25,12 @@ class Sylive_data_entity{ } /** - * 更具kpi排名 - * @param $where - * @return void + * 根据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'; @@ -84,7 +87,7 @@ class Sylive_data_entity{ return $data; } - //排行数据 + //门店排行数据 public function top_lists($aid,$type='browse',$page=1,$size=10,$biz_id=0){ $lists = []; $where = [ @@ -117,6 +120,96 @@ class Sylive_data_entity{ 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->act_user_model->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)) { diff --git a/home/controllers/h5/market/sylive/Stic.php b/home/controllers/h5/market/sylive/Stic.php index f2ddab1b..dacecdc5 100644 --- a/home/controllers/h5/market/sylive/Stic.php +++ b/home/controllers/h5/market/sylive/Stic.php @@ -84,8 +84,7 @@ class Stic extends Admin{ if(!$row && $this->group_id>=3){ $this->show_json([],200); } - $area_name = ''; - $all = $area = $biz = $join = []; + $area_book = $area_browse = $all = $area = $biz = $join = []; if($this->group_id<2){ //所有大区 $biz_id = $this->input->get('biz_id'); $area_id = $this->input->get('area_id'); @@ -138,6 +137,19 @@ class Stic extends Admin{ ['title' => '预约率', 'num' => $a_browse_count ? round($a_subscribe_count/$a_browse_count*100,2)."%" : 0], ]; } + //战区排行 + $area_browse_lists = $this->sylive_data_entity->top_area_lists($a_id,'browse',1,50); + $area_browse = [ + 'title' => '战区浏览排行', + 'url' => '', + 'list' => $area_browse_lists['lists'] + ]; + $area_book_lists = $this->sylive_data_entity->top_area_lists($a_id,'subscribe',1,50); + $area_book = [ + 'title' => '战区预约排行', + 'url' => '', + 'list' => $area_book_lists['lists'] + ]; }else{ //门店 $biz_id = $this->session['org_id']; } @@ -184,6 +196,19 @@ class Stic extends Admin{ 'url' => '/h5/market/sylive/stic/rank?type=subscribe&skey='.$skey, 'list' => $book_lists['lists'] ]; + //顾问数据排行 + $gw_browse_lists = $this->sylive_data_entity->top_gw_lists($a_id,'browse',[],1,10,$this->uid); + $gw_browse = [ + 'title' => '顾问浏览排行', + 'url' => "/h5/market/sylive/stic/rank?type=browse&skey={$skey}&c=gw", + 'list' => $gw_browse_lists['lists'] + ]; + $gw_book_list = $this->sylive_data_entity->top_gw_lists($a_id,'subscribe',[],1,10,$this->uid); + $gw_book = [ + 'title' => '顾问预约排行', + 'url' => "/h5/market/sylive/stic/rank?type=subscribe&skey={$skey}&c=gw", + 'list' => $gw_book_list['lists'] + ]; $data = [ 'mine' => $mine, 'biz' => $biz, @@ -192,7 +217,10 @@ class Stic extends Admin{ 'join' => $join, 'browse' => $browse, 'book' => $book, - 'area_name' => $area_name, + 'area_browse' => $area_browse, + 'area_book' => $area_book, + 'gw_browse' => $gw_browse, + 'gw_book' => $gw_book ]; $this->show_json($data,200); } @@ -207,7 +235,7 @@ class Stic extends Admin{ $this->show_json([],200); } $area_name = ''; - $all = $area = $biz = $join = $view_num = $view_time = []; + $area_view = $area_order = $all = $area = $biz = $join = $view_num = $view_time = []; if($this->group_id<2){ //所有大区 $biz_id = $this->input->get('biz_id'); $area_id = $this->input->get('area_id'); @@ -260,6 +288,19 @@ class Stic extends Admin{ ['title' => '转化率', 'num' => $a_view_count ? round($a_order_count/$a_view_count*100,2)."%" : 0], ]; } + //战区排行 + $area_view_lists = $this->sylive_data_entity->top_area_lists($a_id,'watch',1,50); + $area_view = [ + 'title' => '战区观看排行', + 'url' => '', + 'list' => $area_view_lists['lists'] + ]; + $area_order_lists = $this->sylive_data_entity->top_area_lists($a_id,'order',1,50); + $area_order = [ + 'title' => '战区订单排行', + 'url' => '', + 'list' => $area_order_lists['lists'] + ]; }else{ //门店 $biz_id = $this->session['org_id']; // $view_num_lists = $this->sylive_entity->top_view_num($row['channelId'],1,10); @@ -331,6 +372,19 @@ class Stic extends Admin{ 'url' => '/h5/market/sylive/stic/rank?type=order&skey='.$skey, 'list' => $order_lists['lists'] ]; + //顾问数据排行 + $gw_view_lists = $this->sylive_data_entity->top_gw_lists($a_id,'watch',[],1,10,$this->uid); + $gw_view = [ + 'title' => '顾问观看排行', + 'url' => "/h5/market/sylive/stic/rank?type=watch&skey={$skey}&c=gw", + 'list' => $gw_view_lists['lists'] + ]; + $gw_order_list = $this->sylive_data_entity->top_gw_lists($a_id,'order',[],1,10,$this->uid); + $gw_order = [ + 'title' => '顾问订单排行', + 'url' => "/h5/market/sylive/stic/rank?type=order&skey={$skey}&c=gw", + 'list' => $gw_order_list['lists'] + ]; $data = [ 'mine' => $mine, 'biz' => $biz, @@ -343,32 +397,43 @@ class Stic extends Admin{ 'view_num' => $view_num, 'view_time' => $view_time, 'area_name' => $area_name, + 'area_view' => $area_view, + 'area_order' => $area_order, + 'gw_view' => $gw_view, + 'gw_order' => $gw_order ]; $this->show_json($data,200); } public function ajax_rank(){ + $c = $this->input->get('c'); + $title = $c=='gw' ? '顾问' : '门店'; $title_arr = [ - 'browse' => '门店浏览排行', - 'subscribe' => '门店预约排行', - 'watch' => '门店观看排行', - 'order' => '门店订单排行' + 'browse' => $title.'浏览排行', + 'subscribe' => $title.'预约排行', + 'watch' => $title.'观看排行', + 'order' => $title.'订单排行' ]; + $params = $this->input->get(); $page = $params['page'] ? intval($params['page']) : 1; $size = $params['size'] ? intval($params['size']) : 20; $info = $this->myencryption->base64url_decode($params['skey']); $a_id = intval($info['a_id']);//活动id - $biz_id = $this->sylive_entity->get_biz_id($this->session['org_id'],$this->group_id); $type = $params['type'] ? $params['type'] : 'browse'; - if(strtotime($params['day'])){ //根据日期排行 - $where = [ - 'activityId' => $a_id, - 'kpi' => $type, - 'createTime' => $params['day'], - ]; - $data = $this->sylive_data_entity->top_biz_kpidata($where,$page,$size,$biz_id); + if($c=='gw'){ + $data = $this->sylive_data_entity->top_gw_lists($a_id,$type,[],$page,$size,$this->uid); }else{ - $data = $this->sylive_data_entity->top_lists($a_id,$type,$page,$size,$biz_id); + $biz_id = $this->sylive_entity->get_biz_id($this->session['org_id'],$this->group_id); + if(strtotime($params['day'])){ //根据日期排行 + $where = [ + 'activityId' => $a_id, + 'kpi' => $type, + 'createTime' => $params['day'], + ]; + $data = $this->sylive_data_entity->top_biz_kpidata($where,$page,$size,$biz_id); + }else{ + $data = $this->sylive_data_entity->top_lists($a_id,$type,$page,$size,$biz_id); + } } $data['title'] = $title_arr[$type]; $data['url'] = "/h5/market/sylive/stic/rank?type={$type}&skey={$params['skey']}&day={$params['day']}"; @@ -439,23 +504,23 @@ class Stic extends Admin{ ]; $biz_id = $this->sylive_entity->get_biz_id($this->session['org_id'],$this->group_id); if($type==1){ - $b_rows = $this->sylive_entity->top_biz_user($a_id,$biz_id,$this->uid,'browse'); + $b_rows = $this->sylive_data_entity->top_gw_lists($a_id,'browse',['bizId'=>$biz_id],1,30,$this->uid); $data['browse'] = [ 'title' => '本店浏览排行', 'list' => $b_rows['lists'] ]; - $sub_rows = $this->sylive_entity->top_biz_user($a_id,$biz_id,$this->uid,'subscribe'); + $sub_rows = $this->sylive_data_entity->top_gw_lists($a_id,'subscribe',['bizId'=>$biz_id],1,30,$this->uid); $data['book'] = [ 'title' => '本店预约排行', 'list' => $sub_rows['lists'] ]; }else{ - $view_rows = $this->sylive_entity->top_biz_user($a_id,$biz_id,$this->uid,'watch'); + $view_rows = $this->sylive_data_entity->top_gw_lists($a_id,'watch',['bizId'=>$biz_id],1,30,$this->uid); $data['view'] = [ 'title' => '本店观看排行', 'list' => $view_rows['lists'] ]; - $order_rows = $this->sylive_entity->top_biz_user($a_id,$biz_id,$this->uid,'order'); + $order_rows = $this->sylive_data_entity->top_gw_lists($a_id,'order',['bizId'=>$biz_id],1,30,$this->uid); $data['order'] = [ 'title' => '本店订单排行', 'list' => $order_rows['lists'] @@ -574,12 +639,14 @@ class Stic extends Admin{ public function gw_lists(){ $params = $this->input->get(); + $page = $params['page'] ? $params['page'] : 1; + $size = $params['size'] ? $params['size'] : 20; if($params['type']=='biz'&&$params['type_id']){ $biz_id = $params['type_id']; - }else{ - $biz_id = $this->session['org_id']; + $o_where = ['bizId'=>$biz_id]; } - $res = $this->sylive_entity->top_biz_user($params['a_id'],$biz_id,$this->uid,$params['kpi']); + $o_where = []; + $res = $this->sylive_data_entity->top_gw_lists($params['a_id'],$params['kpi'],$o_where,$page,$size,$this->uid); $lists = []; if($res['lists']){ foreach ($res['lists'] as $item) { diff --git a/home/views/h5/market/sylive/stic/area.php b/home/views/h5/market/sylive/stic/area.php index 8be8a314..e2265aeb 100644 --- a/home/views/h5/market/sylive/stic/area.php +++ b/home/views/h5/market/sylive/stic/area.php @@ -73,6 +73,44 @@ +