From f3ae9b45f944689cee1dd780821d57aa83565bb4 Mon Sep 17 00:00:00 2001 From: lccsw <805383944@qq.com> Date: Thu, 3 Nov 2022 19:42:40 +0800 Subject: [PATCH] edit-sylive-rank --- api/controllers/plan/Syt.php | 73 +++++++++- .../libraries/market/Sylive_data_entity.php | 129 ++++++++++++++++++ common/libraries/market/Sylive_entity.php | 33 ----- home/controllers/h5/market/sylive/Common.php | 19 +++ home/controllers/h5/market/sylive/Login.php | 24 ++++ home/controllers/h5/market/sylive/Stic.php | 49 ++++--- home/views/h5/market/sylive/stic/area.php | 56 +++++++- home/views/h5/market/sylive/stic/rank.php | 2 +- 8 files changed, 328 insertions(+), 57 deletions(-) create mode 100644 common/libraries/market/Sylive_data_entity.php diff --git a/api/controllers/plan/Syt.php b/api/controllers/plan/Syt.php index 63efa81d..82fde506 100644 --- a/api/controllers/plan/Syt.php +++ b/api/controllers/plan/Syt.php @@ -335,5 +335,76 @@ class Syt extends CI_Controller } } } - + //更新活动用户表信息 + public function tmp(){ + $this->load->library('market/sylive_entity'); + $this->load->model('market/market_sylive_user_model', 'user_model'); + $this->load->model('market/market_sylive_activity_user_model', 'act_user_model'); + $this->load->model('market/market_sylive_activity_kpidata_model','mdSytActivityKpiData'); + $page = $this->input->get('page'); + $size = $this->input->get('size'); + !$page && $page = 1; + !$size && $size = 20; + $where = [ + 'organizationId>' => 0, + 'userId>' => 0 + ]; + $total = $this->act_user_model->count($where); + $filed = 'id,userId,activityId'; + $rows = $this->act_user_model->select($where,'id asc',$page,$size,$filed); + if(!$rows){ + echo "执行完毕"; + } + $user_ids = implode(',',array_column($rows,'userId')); + $where = ["userId in ({$user_ids})"=>null]; + $users = $this->user_model->map('userId','',$where); + foreach ($rows as $item) { + $user = $users[$item['userId']] ? $users[$item['userId']][0] : []; + if($user){ + $update = [ + 'organizationId' => $user['organizationId'], + 'teamId' => $user['teamId'], + ]; + if($update['organizationId']){ + $level_lists = $this->sylive_entity->get_level_lists($update['organizationId']); + if($level_lists){ + $area_id = $level_lists[1]['organizationId'];//获取大区id + $biz_id = $level_lists[2]['organizationId'];//获取店铺id + } + $type = 0; + } + if($update['teamId']){ + $team_lists = $this->sylive_entity->get_team_lists($update['teamId']); + if($team_lists) { + $area_id = $team_lists[0]['teamId']; //大团长id + $biz_id = $team_lists[1]['teamId']; //团长id + } + $type = 1; + } + if($update['teamId']||$update['organizationId']){ + $where = [ + 'type' => $type, + 'activityId' => $item['activityId'], + 'cfUserId' => $item['userId'] + ]; + $where['kpi'] = 'browse'; + $browse = $this->mdSytActivityKpiData->count($where); + $where['kpi'] = 'subscribe'; + $subscribe = $this->mdSytActivityKpiData->count($where); + $where['kpi'] = 'order'; + $orderTotal = $this->mdSytActivityKpiData->count($where); + $where['kpi'] = 'watch'; + $watch = $this->mdSytActivityKpiData->count($where); + } + $area_id && $update['areaId'] = $area_id; + $biz_id && $update['bizId'] = $biz_id; + $browse && $update['browse'] = $browse; + $subscribe && $update['subscribe'] = $browse; + $orderTotal && $update['orderTotal'] = $browse; + $watch && $update['watch'] = $browse; + $this->act_user_model->update($update,['userId'=>$item['userId']]); + echo "更新成功:".json_encode($update,JSON_UNESCAPED_UNICODE)."
"; + } + } + } } \ No newline at end of file diff --git a/common/libraries/market/Sylive_data_entity.php b/common/libraries/market/Sylive_data_entity.php new file mode 100644 index 00000000..499ed4bb --- /dev/null +++ b/common/libraries/market/Sylive_data_entity.php @@ -0,0 +1,129 @@ + '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 $where + * @return void + */ + 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; + } + + public function __get($name) + { + if ('_model' === substr($name, -6)) { + return $this->ci->$name; + } elseif ('load' == $name) { + return $this->ci->load; + } + return null; + } +} \ No newline at end of file diff --git a/common/libraries/market/Sylive_entity.php b/common/libraries/market/Sylive_entity.php index d09a44ad..cee33303 100644 --- a/common/libraries/market/Sylive_entity.php +++ b/common/libraries/market/Sylive_entity.php @@ -234,39 +234,6 @@ class Sylive_entity{ } } - //排行数据 - 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; - } - //门店用户排行数据 public function top_biz_user($aid,$biz_id,$uid,$type='browse',$page=1,$size=50){ if(!$biz_id){ diff --git a/home/controllers/h5/market/sylive/Common.php b/home/controllers/h5/market/sylive/Common.php index ea06d96d..e299f248 100644 --- a/home/controllers/h5/market/sylive/Common.php +++ b/home/controllers/h5/market/sylive/Common.php @@ -238,11 +238,30 @@ class Wx extends Common{ $param = $this->myencryption->base64url_decode($skey); $act_user = $this->act_user_model->get(['activityId'=>$param['a_id'],'userId'=>$this->uid]); if(!$act_user && $param['a_id']){ + $this->load->library('market/sylive_entity'); $act_data = [ 'activityId' => $param['a_id'], 'userId' => $this->uid, "createTime" => date('Y-m-d H:i:s') ]; + if($row_wechat['organizationId']){ + $act_data['organizationId'] = $row_wechat['organizationId']; + $level_lists = $this->sylive_entity->get_level_lists($row_wechat['organizationId']); + if($level_lists){ + $area_id = $level_lists[1]['organizationId'];//获取大区id + $biz_id = $level_lists[2]['organizationId'];//获取店铺id + } + } + if($row_wechat['teamId']){ + $act_data['teamId'] = $row_wechat['teamId']; + $team_lists = $this->sylive_entity->get_team_lists($row_wechat['teamId']); + if($team_lists) { + $area_id = $team_lists[0]['teamId']; //大团长id + $biz_id = $team_lists[1]['teamId']; //团长id + } + } + $area_id && $act_data['areaId'] = $area_id; + $biz_id && $act_data['bizId'] = $biz_id; if($param['cf_uid']){ $p_user = $this->user_model->get(['userId'=>$param['cf_uid']],'userId,organizationId,teamId'); $p_act_user = $this->act_user_model->get(['userId'=>$param['cf_uid']],'userId,channelId'); diff --git a/home/controllers/h5/market/sylive/Login.php b/home/controllers/h5/market/sylive/Login.php index 9eae3e31..27b55f42 100644 --- a/home/controllers/h5/market/sylive/Login.php +++ b/home/controllers/h5/market/sylive/Login.php @@ -10,6 +10,8 @@ class Login extends CI_Controller{ parent::__construct(); session_start(); $this->load->model('market/market_sylive_user_model', 'user_model'); + $this->load->model('market/market_sylive_activity_user_model', 'act_user_model'); + $this->load->library('market/sylive_entity'); $this->load->library('hd_exception'); } @@ -63,6 +65,28 @@ class Login extends CI_Controller{ $this->user_model->update($update,['userId'=>$user['userId']]); //删除普通账户 $this->user_model->update(['status'=>-1],['openid'=>$wx_info['openid'],'status>='=>0,'organizationId'=>0,'teamId'=>0]); + //更新activity用户表数据 + $update = [ + 'organizationId' => $user['organizationId'], + 'teamId' => $user['teamId'] + ]; + if($update['organizationId']){ + $level_lists = $this->sylive_entity->get_level_lists($update['organizationId']); + if($level_lists){ + $area_id = $level_lists[1]['organizationId'];//获取大区id + $biz_id = $level_lists[2]['organizationId'];//获取店铺id + } + } + if($update['teamId']){ + $team_lists = $this->sylive_entity->get_team_lists($update['teamId']); + if($team_lists) { + $area_id = $team_lists[0]['teamId']; //大团长id + $biz_id = $team_lists[1]['teamId']; //团长id + } + } + $area_id && $update['areaId'] = $area_id; + $biz_id && $update['bizId'] = $biz_id; + $this->act_user_model->update($update,['openid'=>$wx_info['openid'],'status'=>0]); return ['code' => 1,'msg' => '绑定成功']; } //获取验证码 diff --git a/home/controllers/h5/market/sylive/Stic.php b/home/controllers/h5/market/sylive/Stic.php index 404b7698..15210d42 100644 --- a/home/controllers/h5/market/sylive/Stic.php +++ b/home/controllers/h5/market/sylive/Stic.php @@ -14,6 +14,7 @@ class Stic extends Admin{ $this->load->model('market/market_sylive_order_model'); $this->load->model('live/Live_polyv_session_model', 'mdPolyvSession'); $this->load->library('market/sylive_entity'); + $this->load->library('market/sylive_data_entity'); $this->group_id = $this->sylive_entity->get_level($this->session['org_id']); $this->data['skey'] = $this->input->get('skey'); } @@ -63,6 +64,11 @@ class Stic extends Admin{ $b_row = $this->market_sylive_organization_model->get(['organizationId'=>$info['biz_id']],'organizationName'); $h_title .= $b_row['organizationName']; } + $day_list = ['全部']; + for($i=0;$i<9;$i++){ + $day_list[] = date('Y-m-d',strtotime("-{$i} day")); + } + $this->data['day_list'] = $day_list; $this->data['h_title'] = $h_title; $this->data['info'] = $info; $this->show_view('h5/market/sylive/stic/area'); @@ -165,13 +171,13 @@ class Stic extends Admin{ ]; } $biz_id = $this->sylive_entity->get_biz_id($this->session['org_id'],$this->group_id); - $browse_lists = $this->sylive_entity->top_lists($a_id,'browse',1,10,$biz_id); + $browse_lists = $this->sylive_data_entity->top_lists($a_id,'browse',1,10,$biz_id); $browse = [ 'title' => '门店浏览排行', 'url' => '/h5/market/sylive/stic/rank?type=browse&skey='.$skey, 'list' => $browse_lists['lists'] ]; - $book_lists = $this->sylive_entity->top_lists($a_id,'subscribe',1,10,$biz_id); + $book_lists = $this->sylive_data_entity->top_lists($a_id,'subscribe',1,10,$biz_id); $book = [ 'title' => '门店预约排行', 'url' => '/h5/market/sylive/stic/rank?type=subscribe&skey='.$skey, @@ -312,13 +318,13 @@ class Stic extends Admin{ ['title' => '观看次数', 'num' => "{$livePV}次"], ]; $biz_id = $this->sylive_entity->get_biz_id($this->session['org_id'],$this->group_id); - $watch_lists = $this->sylive_entity->top_lists($a_id,'watch',1,10,$biz_id); + $watch_lists = $this->sylive_data_entity->top_lists($a_id,'watch',1,10,$biz_id); $view = [ 'title' => '门店观看排行', 'url' => '/h5/market/sylive/stic/rank?type=watch&skey='.$skey, 'list' => $watch_lists['lists'] ]; - $order_lists = $this->sylive_entity->top_lists($a_id,'order',1,10,$biz_id); + $order_lists = $this->sylive_data_entity->top_lists($a_id,'order',1,10,$biz_id); $order = [ 'title' => '门店订单排行', 'url' => '/h5/market/sylive/stic/rank?type=order&skey='.$skey, @@ -339,9 +345,7 @@ class Stic extends Admin{ ]; $this->show_json($data,200); } - - //排名列表 - public function rank(){ + public function ajax_rank(){ $title_arr = [ 'browse' => '门店浏览排行', 'subscribe' => '门店预约排行', @@ -349,16 +353,29 @@ class Stic extends Admin{ 'order' => '门店订单排行' ]; $params = $this->input->get(); - if($this->input->is_ajax_request()){ - $page = $params['page'] ? intval($params['page']) : 1; - $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'; - $data = $this->sylive_entity->top_lists($a_id,$type,$page,20,$biz_id); - $data['title'] = $title_arr[$type]; - $this->show_json($data,200); + $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); + }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']}"; + $this->show_json($data,200); + } + //排名列表 + public function rank(){ + $params = $this->input->get(); $param = $this->myencryption->base64url_decode($this->data['skey']); $a_id = intval($param['a_id']);//活动id $row = $this->market_sylive_activity_model->get(['activityId'=>$a_id]); diff --git a/home/views/h5/market/sylive/stic/area.php b/home/views/h5/market/sylive/stic/area.php index 59c691c4..8be8a314 100644 --- a/home/views/h5/market/sylive/stic/area.php +++ b/home/views/h5/market/sylive/stic/area.php @@ -76,7 +76,10 @@
- 查看更多 + +
@@ -90,6 +93,7 @@
{{item.num}}
+
查看更多
暂时无数据
@@ -97,7 +101,10 @@
- 查看更多 + +
@@ -111,6 +118,7 @@
{{item.num}}
+
查看更多
暂时无数据
@@ -178,7 +186,7 @@
- 查看更多 +
@@ -192,6 +200,7 @@
{{item.num}}
+
查看更多
暂时无数据
@@ -199,7 +208,7 @@
- 查看更多 +
@@ -213,6 +222,7 @@
{{item.num}}
+
查看更多
暂时无数据
@@ -220,7 +230,7 @@
- 查看更多 +
@@ -234,6 +244,7 @@
{{item.num}}
+
查看更多
暂时无数据
@@ -242,7 +253,7 @@
- 查看更多 +
@@ -256,6 +267,7 @@
{{item.num}}
+
查看更多
暂时无数据
@@ -279,6 +291,7 @@ tabid:'',//1预热阶段 /2直播阶段 info:'', loading: false, + day_list : , begin:{ mine:[], biz:[], @@ -324,6 +337,7 @@ list:[], } }, + ph_type:'', }, created(){ @@ -427,6 +441,36 @@ } }, + //选择浏览时间 + changebeginbook(e,type){ + // console.log(e.target.value) + // console.log(type) + this.ph_type = type; + if(this.beginbookDate != e.target.value){ + this.beginbookDate = e.target.value + let that=this; + var params = { + 'skey':'', + 'biz_id':'', + 'area_id':'', + 'day' : this.beginbookDate, + 'type':type, + 'size':10 + } + //请求接口 + $.get('/h5/market/sylive/stic/ajax_rank',params,function (result){ + if(result.data){ + if(that.ph_type){ + that.begin.book.list = result.data.lists + that.begin.book.url = result.data.url + }else{ + that.begin.browse.list = result.data.lists + that.begin.browse.url = result.data.url + } + } + },'json'); + } + }, }, }) diff --git a/home/views/h5/market/sylive/stic/rank.php b/home/views/h5/market/sylive/stic/rank.php index 745b1683..c3976ac5 100644 --- a/home/views/h5/market/sylive/stic/rank.php +++ b/home/views/h5/market/sylive/stic/rank.php @@ -63,7 +63,7 @@ if (!that.isNoData && !that.isDataEnd && !that.loading) { that.loading = true; //请求接口 - $.get('/h5/market/sylive/stic/rank',{'skey':'','type':'','page':that.page},function (res){ + $.get('/h5/market/sylive/stic/ajax_rank',{'skey':'','type':'','day':'','page':that.page},function (res){ that.loading = false; that.page = that.page + 1;