diff --git a/home/controllers/h5/market/sylive2/Act.php b/home/controllers/h5/market/sylive2/Act.php index 895490c5..07d3c00e 100644 --- a/home/controllers/h5/market/sylive2/Act.php +++ b/home/controllers/h5/market/sylive2/Act.php @@ -593,7 +593,7 @@ class Act extends Wx { } } $redis->delete($key); - if($this->a_id==11){ + if($a_id==11){ //通知第三方 require_once COMMPATH . 'third_party/Syt.php'; $syt = new Syt(); @@ -603,8 +603,8 @@ class Act extends Wx { //获取意向网点编码 if($p_user){ $mediaCaName = $p_user['uname']; - $bizUser = $this->user_model->get(['userId'=>$p_user['userId']]); - $biz = $this->market_sylive_organization_model->get(['organizationId'=>$bizUser['bizId']]); + $group_user = $this->groups_user_model->get(['activityId' => $a_id, 'userId' => $this->uid, 'status' => 0]); + $biz = $this->market_sylive_organization_model->get(['organizationId'=>$group_user['bizId']]); $dlrCode = $biz['comments']; } $syt->Tj($dlrCode,"活动客户",$mobile,$mediaCaName,$leadNo); diff --git a/home/controllers/h5/market/sylive2/Stic.php b/home/controllers/h5/market/sylive2/Stic.php index 41281866..b7a3be32 100644 --- a/home/controllers/h5/market/sylive2/Stic.php +++ b/home/controllers/h5/market/sylive2/Stic.php @@ -1,15 +1,17 @@ load->model('market/market_sylive_activity_kpidata_model','mdSytActivityKpiData'); + $this->load->model('market/market_sylive_activity_kpidata_model', 'mdSytActivityKpiData'); $this->load->model('market/market_sylive_items_model'); $this->load->model('market/market_sylive_order_model'); $this->load->model('live/Live_polyv_session_model', 'mdPolyvSession'); @@ -21,40 +23,41 @@ class Stic extends Admin{ !$this->a_id && $this->a_id = $_SESSION[self::SESSION_KEY]['a_id']; $skey = $this->myencryption->base64url_encode("a_id=" . $this->a_id); $this->data['act_url'] = "/h5/market/sylive2/act?skey={$skey}"; - $this->group_user = $this->groups_user_model->get(['activityId'=>$this->a_id,'userId'=>$this->uid,'status'=>0]); + $this->group_user = $this->groups_user_model->get(['activityId' => $this->a_id, 'userId' => $this->uid, 'status' => 0]); $this->data['is_biz'] = $this->group_user['bizId'] ? 1 : 0; - if($this->group_user['bizId'] && $this->group_user['type']){ //店长 + if ($this->group_user['bizId'] && $this->group_user['type']) { //店长 $this->data['is_shop_manager'] = $this->is_shop_manager = 1; - }else{ + } else { $this->data['is_shop_manager'] = 0; } } - public function index(){ + public function index() + { $groupsId = $this->input->get('groupsId'); - $row = $this->market_sylive_activity_model->get(['activityId'=>$this->a_id]); - if(!$row){ - throw new Hd_exception('参数错误',400); + $row = $this->market_sylive_activity_model->get(['activityId' => $this->a_id]); + if (!$row) { + throw new Hd_exception('参数错误', 400); } - $user = $this->user_model->get(['userId'=>$this->uid],'nickname,headimg'); - $jsondata = json_decode($row['jsondata'],true); + $user = $this->user_model->get(['userId' => $this->uid], 'nickname,headimg'); + $jsondata = json_decode($row['jsondata'], true); $info['banner'] = $jsondata['banner'] ? build_qiniu_image_url($jsondata['banner']) : Sylive_entity::DF_BANNER; - $info['nickname'] = $user['nickname']; - $info['headimg'] = $user['headimg']; + $info['nickname'] = $user['nickname']; + $info['headimg'] = $user['headimg']; $group_user = $this->group_user; $info['group_name'] = ''; $info['is_biz'] = $group_user['bizId'] ? 1 : 0; $info['biz_id'] = $group_user['biz_id'] ? $group_user['biz_id'] : 0; - if($groupsId){ - $group_lists = $this->sylive2_entity->get_group_lists($groupsId,$this->a_id); + if ($groupsId) { + $group_lists = $this->sylive2_entity->get_group_lists($groupsId, $this->a_id); unset($group_lists[0]); - $info['group_name'] = implode(' ',array_column($group_lists,'groupsName')); - $groups = $this->groups_model->get(['groupsId'=>$groupsId]); + $info['group_name'] = implode(' ', array_column($group_lists, 'groupsName')); + $groups = $this->groups_model->get(['groupsId' => $groupsId]); $info['biz_id'] = $groups['ifBiz'] ? $groups['groupsId'] : 0; } $info['groupsId'] = $groupsId ? $groupsId : $group_user['groupsId']; $info['tab'] = 1; - if(time()>=strtotime($row['timeStart']) && $this->a_id!=11){ + if (time() >= strtotime($row['timeStart']) && $this->a_id != 11) { $info['tab'] = 2; } $info['aId'] = $this->a_id; @@ -67,20 +70,21 @@ class Stic extends Admin{ } //预约阶段数据 - public function lists_ready(){ + public function lists_ready() + { $groupsId = $this->input->get('groupsId'); $group_user = $this->group_user; !$groupsId && $groupsId = $group_user['groupsId']; - $group_row = $this->groups_model->get(['groupsId'=>$groupsId,'activityId'=>$this->a_id]); + $group_row = $this->groups_model->get(['groupsId' => $groupsId, 'activityId' => $this->a_id]); $disk = $this->sylive2_entity->level_disk($this->a_id); - if(!$group_user['bizId'] && $disk){ + if (!$group_user['bizId'] && $disk) { foreach ($disk as $key => $val) { $where = [ 'activityId' => $this->a_id, 'groupsLevel' => $key ]; $level_total = $this->groups_model->count($where); - $h_lists[] = ['title'=> "参与{$val}",'num'=>"{$level_total}个"]; + $h_lists[] = ['title' => "参与{$val}", 'num' => "{$level_total}个"]; } } $where = [ @@ -97,11 +101,11 @@ class Stic extends Admin{ $where = [ 'activityId' => $this->a_id, ]; - $kgw_total = $this->mdSytActivityKpiData->count($where,"cfUserId"); - $h_lists[] = ['title'=>'参与门店','num'=>"{$biz_total}个"]; - $h_lists[] = ['title'=>'参与顾问','num'=>"{$gw_total}个"]; - $h_lists[] = ['title'=>'开工顾问','num'=>"{$kgw_total}个"]; - $h_lists[] = ['title'=>'开工率','num'=>$gw_total ? round($kgw_total/$gw_total*100,2)."%" : 0]; + $kgw_total = $this->mdSytActivityKpiData->count($where, "cfUserId"); + $h_lists[] = ['title' => '参与门店', 'num' => "{$biz_total}个"]; + $h_lists[] = ['title' => '参与顾问', 'num' => "{$gw_total}个"]; + $h_lists[] = ['title' => '开工顾问', 'num' => "{$kgw_total}个"]; + $h_lists[] = ['title' => '开工率', 'num' => $gw_total ? round($kgw_total / $gw_total * 100, 2) . "%" : 0]; //我的 $where = [ 'activityId' => $this->a_id, @@ -110,26 +114,30 @@ class Stic extends Admin{ ]; $owner_browse_count = $this->mdSytActivityKpiData->count($where); //浏览数据 $mine = [ - ['title'=>'访问用户','num'=>"{$owner_browse_count}人",'url'=>'/h5/market/sylive2/stic/users?type=owner&kpi=browse'], + ['title' => '访问用户', 'num' => "{$owner_browse_count}人", 'url' => '/h5/market/sylive2/stic/users?type=owner&kpi=browse'], ]; - if($this->a_id==11){ + if ($this->a_id == 11) { $where['kpi'] = 'beforeOrder'; $owner_subscribe_count = $this->mdSytActivityKpiData->count($where); //订阅数据 - $mine[] = ['title'=>'留资用户','num'=>"{$owner_subscribe_count}人",'url'=>'/h5/market/sylive2/stic/users?type=owner&kpi=beforeOrder']; - $mine[] = ['title'=>'留资率','num'=>$owner_browse_count ? round($owner_subscribe_count/$owner_browse_count*100,2)."%" : 0]; - }else{ + $mine[] = ['title' => '留资用户', 'num' => "{$owner_subscribe_count}人", 'url' => '/h5/market/sylive2/stic/users?type=owner&kpi=beforeOrder']; + $mine[] = ['title' => '留资率', 'num' => $owner_browse_count ? round($owner_subscribe_count / $owner_browse_count * 100, 2) . "%" : 0]; + } else { $where['kpi'] = 'subscribe'; $owner_subscribe_count = $this->mdSytActivityKpiData->count($where); //订阅数据 - $mine[] = ['title'=>'预约用户','num'=>"{$owner_subscribe_count}人",'url'=>'/h5/market/sylive2/stic/users?type=owner&kpi=subscribe']; - $mine[] = ['title'=>'预约率','num'=>$owner_browse_count ? round($owner_subscribe_count/$owner_browse_count*100,2)."%" : 0]; + $mine[] = ['title' => '预约用户', 'num' => "{$owner_subscribe_count}人", 'url' => '/h5/market/sylive2/stic/users?type=owner&kpi=subscribe']; + $mine[] = ['title' => '预约率', 'num' => $owner_browse_count ? round($owner_subscribe_count / $owner_browse_count * 100, 2) . "%" : 0]; + } + if ($this->a_id == 11) { + $where['kpi'] = 'order'; + } else { + $where['kpi'] = 'beforeOrder'; } - $where['kpi'] = 'beforeOrder'; $order_count = $this->mdSytActivityKpiData->count($where); //下单数据 - $mine[] = ['title'=>'下单数','num'=>"{$order_count}单"]; + $mine[] = ['title' => '下单数', 'num' => "{$order_count}单"]; $sub_lists = [ - ['title'=>'我的','lists'=>$mine], + ['title' => '我的', 'lists' => $mine], ]; - if($group_user['bizId']){ + if ($group_user['bizId']) { $where = [ 'activityId' => $this->a_id, 'kpi' => 'browse', @@ -138,65 +146,82 @@ class Stic extends Admin{ $biz_browse_count = $this->mdSytActivityKpiData->count($where); //浏览数据 $where['kpi'] = 'subscribe'; $biz_subscribe_count = $this->mdSytActivityKpiData->count($where); //订阅数据 - $where['kpi'] = 'beforeOrder'; + if ($this->a_id == 11) { + $where['kpi'] = 'order'; + } else { + $where['kpi'] = 'beforeOrder'; + } $order_count = $this->mdSytActivityKpiData->count($where); //下单数据 $biz = [ - ['title'=>'访问用户','num'=>"{$biz_browse_count}人",'url' => "/h5/market/sylive2/stic/users?type=biz&type_id={$group_user['bizId']}&kpi=browse"], + ['title' => '访问用户', 'num' => "{$biz_browse_count}人", 'url' => "/h5/market/sylive2/stic/users?type=biz&type_id={$group_user['bizId']}&kpi=browse"], ]; - if($this->a_id==11){ - $biz[] = ['title'=>'留资用户','num'=>"{$order_count}人",'url' => "/h5/market/sylive2/stic/users?type=biz&type_id={$group_user['bizId']}&kpi=subscribe"]; - $biz[] = ['title'=>'留资率','num'=>$order_count ? round($order_count/$biz_browse_count*100,2)."%" : 0]; - }else{ - $biz[] = ['title'=>'预约用户','num'=>"{$biz_subscribe_count}人",'url' => "/h5/market/sylive2/stic/users?type=biz&type_id={$group_user['bizId']}&kpi=subscribe"]; - $biz[] = ['title'=>'预约率','num'=>$biz_browse_count ? round($biz_subscribe_count/$biz_browse_count*100,2)."%" : 0]; + if ($this->a_id == 11) { + $biz[] = ['title' => '留资用户', 'num' => "{$order_count}人", 'url' => "/h5/market/sylive2/stic/users?type=biz&type_id={$group_user['bizId']}&kpi=subscribe"]; + $biz[] = ['title' => '留资率', 'num' => $order_count ? round($order_count / $biz_browse_count * 100, 2) . "%" : 0]; + } else { + $biz[] = ['title' => '预约用户', 'num' => "{$biz_subscribe_count}人", 'url' => "/h5/market/sylive2/stic/users?type=biz&type_id={$group_user['bizId']}&kpi=subscribe"]; + $biz[] = ['title' => '预约率', 'num' => $biz_browse_count ? round($biz_subscribe_count / $biz_browse_count * 100, 2) . "%" : 0]; } - $biz[] = ['title'=>'下单数','num'=>"{$order_count}单"]; - $sub_lists[] = ['title'=>'本店','lists'=>$biz]; + $biz[] = ['title' => '下单数', 'num' => "{$order_count}单"]; + $sub_lists[] = ['title' => '本店', 'lists' => $biz]; } - if($group_row['groupsId']!=$group_user['bizId']){ - if(!$group_row['groupsLevel'] && !$group_row['ifBiz']){//顶级 + if ($group_row['groupsId'] != $group_user['bizId']) { + if (!$group_row['groupsLevel'] && !$group_row['ifBiz']) {//顶级 $browse_count = $this->mdSytActivityKpiData->count(['activityId' => $this->a_id, 'kpi' => 'browse']); - $subscribe_count = $this->mdSytActivityKpiData->count(['activityId' => $this->a_id, 'kpi' => 'subscribe']); - $order_count = $this->mdSytActivityKpiData->count(['activityId' => $this->a_id, 'kpi' => 'beforeOrder']); - }else{ + if ($this->a_id == 11) { + $subscribe_count = $this->mdSytActivityKpiData->count(['activityId' => $this->a_id, 'kpi' => 'beforeOrder']); + $order_count = $this->mdSytActivityKpiData->count(['activityId' => $this->a_id, 'kpi' => 'order']); + } else { + $subscribe_count = $this->mdSytActivityKpiData->count(['activityId' => $this->a_id, 'kpi' => 'subscribe']); + $order_count = $this->mdSytActivityKpiData->count(['activityId' => $this->a_id, 'kpi' => 'beforeOrder']); + } + } else { $browse_count = $group_row['browse'];//浏览数据 - $subscribe_count = $group_row['subscribe'];//订阅数据 - $order_count = $group_user['beforeOrderTotal'];//下单数 + if ($this->a_id == 11) { + $subscribe_count = $group_row['beforeOrderTotal'];//订阅数据 + $order_count = $group_user['orderTotal']; + } else { + $subscribe_count = $group_row['subscribe'];//订阅数据 + $order_count = $group_user['beforeOrderTotal'];//下单数 + } + } $b_url = $sub_url = ''; - if($group_row['ifBiz']){ + if ($group_row['ifBiz']) { $b_url = "/h5/market/sylive2/stic/users?type=biz&type_id={$group_row['groupsId']}&kpi=browse"; - $sub_url = "/h5/market/sylive2/stic/users?type=biz&type_id={$group_row['groupsId']}&kpi=subscribe"; + $yy_kpi = $this->a_id == 11 ? "beforeOrder" : "subscribe"; + $sub_url = "/h5/market/sylive2/stic/users?type=biz&type_id={$group_row['groupsId']}&kpi={$yy_kpi}"; } $biz = [ - ['title'=>'访问用户','num'=>"{$browse_count}人",'url'=>$b_url], + ['title' => '访问用户', 'num' => "{$browse_count}人", 'url' => $b_url], ]; - if($this->a_id==11){ - $biz[] = ['title'=>'留资用户','num'=>"{$order_count}人",'url'=>$sub_url]; - $biz[] = ['title'=>'留资率','num'=>$order_count ? round($order_count/$browse_count*100,2)."%" : 0]; - }else{ - $biz[] = ['title'=>'预约用户','num'=>"{$subscribe_count}人",'url'=>$sub_url]; - $biz[] = ['title'=>'预约率','num'=>$browse_count ? round($subscribe_count/$browse_count*100,2)."%" : 0]; + if ($this->a_id == 11) { + $biz[] = ['title' => '留资用户', 'num' => "{$subscribe_count}人", 'url' => $sub_url]; + $biz[] = ['title' => '留资率', 'num' => $subscribe_count ? round($subscribe_count / $browse_count * 100, 2) . "%" : 0]; + } else { + $biz[] = ['title' => '预约用户', 'num' => "{$subscribe_count}人", 'url' => $sub_url]; + $biz[] = ['title' => '预约率', 'num' => $browse_count ? round($subscribe_count / $browse_count * 100, 2) . "%" : 0]; } - $biz[] = ['title'=>'下单数','num'=>"{$order_count}单"]; - $title = $disk[$group_row['groupsLevel']+1]? '所有'.$disk[$group_row['groupsLevel']+1] : '所有门店'; + $biz[] = ['title' => '下单数', 'num' => "{$order_count}单"]; + $title = $disk[$group_row['groupsLevel'] + 1] ? '所有' . $disk[$group_row['groupsLevel'] + 1] : '所有门店'; $group_row['ifBiz'] && $title = $group_row['groupsName']; - $sub_lists[] = ['title'=>"{$title}",'lists'=>$biz]; + $sub_lists[] = ['title' => "{$title}", 'lists' => $biz]; } $data = [ 'h_lists' => $h_lists, 'sub_lists' => $sub_lists, ]; - $this->show_json($data,200); + $this->show_json($data, 200); } //直播统计数据 - public function lists_live(){ + public function lists_live() + { $groupsId = $this->input->get('groupsId'); $group_user = $this->group_user; !$groupsId && $groupsId = $group_user['groupsId']; - $group_row = $this->groups_model->get(['groupsId'=>$groupsId,'activityId'=>$this->a_id]); - $row = $this->market_sylive_activity_model->get(['activityId'=>$this->a_id]); + $group_row = $this->groups_model->get(['groupsId' => $groupsId, 'activityId' => $this->a_id]); + $row = $this->market_sylive_activity_model->get(['activityId' => $this->a_id]); //我的 $where = [ 'activityId' => $this->a_id, @@ -207,27 +232,27 @@ class Stic extends Admin{ $where['kpi'] = 'order'; $owner_subscribe_count = $this->mdSytActivityKpiData->count($where); //订阅数据 $mine = [ - ['title'=>'观看用户','num'=>"{$owner_browse_count}人",'url'=>'/h5/market/sylive2/stic/users?type=owner&kpi=watch'], - ['title'=>'下单数','num'=>"{$owner_subscribe_count}单",'url'=>'/h5/market/sylive2/stic/users?type=owner&kpi=order'], - ['title'=>'转化率','num'=>$owner_browse_count ? round($owner_subscribe_count/$owner_browse_count*100,2)."%" : 0], + ['title' => '观看用户', 'num' => "{$owner_browse_count}人", 'url' => '/h5/market/sylive2/stic/users?type=owner&kpi=watch'], + ['title' => '下单数', 'num' => "{$owner_subscribe_count}单", 'url' => '/h5/market/sylive2/stic/users?type=owner&kpi=order'], + ['title' => '转化率', 'num' => $owner_browse_count ? round($owner_subscribe_count / $owner_browse_count * 100, 2) . "%" : 0], ]; $sub_lists = [ - ['title'=>'我的','lists'=>$mine], + ['title' => '我的', 'lists' => $mine], ]; - $total_play = $this->mdPolyvSession->sum('totalPlayDuration',['channelId'=>$row['channelId']]); - $duration = $this->mdPolyvSession->sum('duration',['channelId'=>$row['channelId']]); - $pv = $this->mdPolyvSession->sum('livePV',['channelId'=>$row['channelId']]); - $uv = $this->mdPolyvSession->sum('liveUV',['channelId'=>$row['channelId']]); - $duration = $duration['duration'] ? intval($duration['duration']/60) : "0"; + $total_play = $this->mdPolyvSession->sum('totalPlayDuration', ['channelId' => $row['channelId']]); + $duration = $this->mdPolyvSession->sum('duration', ['channelId' => $row['channelId']]); + $pv = $this->mdPolyvSession->sum('livePV', ['channelId' => $row['channelId']]); + $uv = $this->mdPolyvSession->sum('liveUV', ['channelId' => $row['channelId']]); + $duration = $duration['duration'] ? intval($duration['duration'] / 60) : "0"; $livePV = $pv['livePV'] ? $pv['livePV'] : 0; - $avg_UV_time = $uv['liveUV'] ? intval($total_play['totalPlayDuration']/$uv['liveUV']) : 0; - $avg_UV_time = intval($avg_UV_time/60); + $avg_UV_time = $uv['liveUV'] ? intval($total_play['totalPlayDuration'] / $uv['liveUV']) : 0; + $avg_UV_time = intval($avg_UV_time / 60); $h_lists = [ ['title' => '直播时长', 'num' => "{$duration}分钟"], ['title' => '人均观看', 'num' => "{$avg_UV_time}分钟"], ['title' => '观看次数', 'num' => "{$livePV}次"], ]; - if($group_user['bizId']){ //门店和顾问 + if ($group_user['bizId']) { //门店和顾问 $biz_id = $group_user['bizId']; $where = [ 'activityId' => $this->a_id, @@ -238,86 +263,87 @@ class Stic extends Admin{ $where['kpi'] = 'order'; $biz_subscribe_count = $this->mdSytActivityKpiData->count($where); //下单数据 $biz = [ - ['title'=>'观看用户','num'=>"{$biz_browse_count}人",'url' => "/h5/market/sylive2/stic/users?type=biz&type_id={$biz_id}&kpi=watch"], - ['title'=>'下单数','num'=>"{$biz_subscribe_count}单",'url' => "/h5/market/sylive2/stic/users?type=biz&type_id={$biz_id}&kpi=order"], - ['title'=>'转化率','num'=>$biz_browse_count ? round($biz_subscribe_count/$biz_browse_count*100,2)."%" : 0], + ['title' => '观看用户', 'num' => "{$biz_browse_count}人", 'url' => "/h5/market/sylive2/stic/users?type=biz&type_id={$biz_id}&kpi=watch"], + ['title' => '下单数', 'num' => "{$biz_subscribe_count}单", 'url' => "/h5/market/sylive2/stic/users?type=biz&type_id={$biz_id}&kpi=order"], + ['title' => '转化率', 'num' => $biz_browse_count ? round($biz_subscribe_count / $biz_browse_count * 100, 2) . "%" : 0], ]; - $sub_lists[] = ['title'=>'本店','lists'=>$biz]; + $sub_lists[] = ['title' => '本店', 'lists' => $biz]; } - if($group_row['groupsId']!=$group_user['bizId']){ + if ($group_row['groupsId'] != $group_user['bizId']) { $disk = $this->sylive2_entity->level_disk($this->a_id); - if(!$group_row['groupsLevel'] && !$group_row['ifBiz']){//顶级 + if (!$group_row['groupsLevel'] && !$group_row['ifBiz']) {//顶级 $browse_count = $this->mdSytActivityKpiData->count(['activityId' => $this->a_id, 'kpi' => 'watch']); //观看数据 - $subscribe_count = $this->market_sylive_order_model->count(['activityId' => $this->a_id, 'status' => 1,'createTime>='=>$row['timeStart']]); //下单数据 - }else{ + $subscribe_count = $this->market_sylive_order_model->count(['activityId' => $this->a_id, 'status' => 1, 'createTime>=' => $row['timeStart']]); //下单数据 + } else { $browse_count = $group_row['watch'];//观看数据 $subscribe_count = $group_row['orderTotal'];//下单数据 } $b_url = $sub_url = ''; - if($group_row['ifBiz']){ + if ($group_row['ifBiz']) { $b_url = "/h5/market/sylive2/stic/users?type=biz&type_id={$group_row['groupsId']}&kpi=watch"; $sub_url = "/h5/market/sylive2/stic/users?type=biz&type_id={$group_row['groupsId']}&kpi=order"; } $biz = [ - ['title'=>'观看用户','num'=>"{$browse_count}人",'url'=>$b_url], - ['title'=>'下单数','num'=>"{$subscribe_count}单",'url'=>$sub_url], - ['title'=>'转化率','num'=>$browse_count ? round($subscribe_count/$browse_count*100,2)."%" : 0], + ['title' => '观看用户', 'num' => "{$browse_count}人", 'url' => $b_url], + ['title' => '下单数', 'num' => "{$subscribe_count}单", 'url' => $sub_url], + ['title' => '转化率', 'num' => $browse_count ? round($subscribe_count / $browse_count * 100, 2) . "%" : 0], ]; - $title = $disk[$group_row['groupsLevel']+1]? '所有'.$disk[$group_row['groupsLevel']+1] : '所有门店'; + $title = $disk[$group_row['groupsLevel'] + 1] ? '所有' . $disk[$group_row['groupsLevel'] + 1] : '所有门店'; $group_row['ifBiz'] && $title = $group_row['groupsName']; - $sub_lists[] = ['title'=>"{$title}",'lists'=>$biz]; + $sub_lists[] = ['title' => "{$title}", 'lists' => $biz]; } $data = [ 'h_lists' => $h_lists, 'sub_lists' => $sub_lists, ]; - $this->show_json($data,200); + $this->show_json($data, 200); } - public function event(){ + public function event() + { $map_kpi_name = [ - 'browse' => '浏览了活动页', 'subscribe' => '订阅了直播通知', 'order' => '直播间下单','watch' => '进入了直播间' + 'browse' => '浏览了活动页', 'subscribe' => '订阅了直播通知', 'order' => '直播间下单', 'watch' => '进入了直播间' ]; $page = $this->input->get('page'); $type = $this->input->get('type'); - !$page && $page=1; - $row = $this->market_sylive_activity_model->get(['activityId'=>$this->a_id]); + !$page && $page = 1; + $row = $this->market_sylive_activity_model->get(['activityId' => $this->a_id]); $group_user = $this->group_user; $where = [ - 'activityId'=>$this->a_id, - 'bizId'=>$group_user['bizId'], + 'activityId' => $this->a_id, + 'bizId' => $group_user['bizId'], ]; - if($type==1){ //预热 + if ($type == 1) { //预热 $where['createTime<='] = strtotime($row['timeStart']); - }else{ //开始 + } else { //开始 $where['createTime>='] = strtotime($row['timeStart']); } $total = $this->mdSytActivityKpiData->count($where); $lists = []; - if($total){ - $rows = $this->mdSytActivityKpiData->select($where,'id desc',$page,10,'userId,kpi,createTime,itemId'); + if ($total) { + $rows = $this->mdSytActivityKpiData->select($where, 'id desc', $page, 10, 'userId,kpi,createTime,itemId'); $users = []; - $uids = implode(',',array_unique(array_column($rows,'userId'))); - if($uids){ + $uids = implode(',', array_unique(array_column($rows, 'userId'))); + if ($uids) { $where = [ "userId in ($uids)" => null, ]; - $users = $this->user_model->map('userId','nickname',$where,'','','','userId,nickname'); + $users = $this->user_model->map('userId', 'nickname', $where, '', '', '', 'userId,nickname'); } $item_rows = []; - $itemIds = implode(',',array_unique(array_column($rows,'itemId'))); - if($itemIds){ + $itemIds = implode(',', array_unique(array_column($rows, 'itemId'))); + if ($itemIds) { $where = [ "itemId in ($itemIds)" => null, ]; - $item_rows = $this->market_sylive_items_model->map('itemId','',$where,'','','','itemId,title,price'); + $item_rows = $this->market_sylive_items_model->map('itemId', '', $where, '', '', '', 'itemId,title,price'); } foreach ($rows as $key => $val) { $nickname = $users[$val['userId']] ? $users[$val['userId']] : "用户{$val['userId']}"; $action = $map_kpi_name[$val['kpi']]; - if($val['kpi']=='beforeOrder' || $val['kpi']=='order'){ + if ($val['kpi'] == 'beforeOrder' || $val['kpi'] == 'order') { $item_row = $item_rows[$val['itemId']] ? $item_rows[$val['itemId']][0] : ''; - $action = $item_row['price']>0 ? '下单 ' : '领取 '; + $action = $item_row['price'] > 0 ? '下单 ' : '领取 '; $action .= $item_row['title']; } $lists[] = [ @@ -331,32 +357,33 @@ class Stic extends Admin{ 'lists' => $lists, 'total' => $total ]; - $this->show_json($data,200); + $this->show_json($data, 200); } - public function users(){ + public function users() + { $map_kpi_name = [ - 'browse' => '访问用户', 'subscribe' => '预约用户', 'order' => '下单数','watch' => '观看用户' + 'browse' => '访问用户', 'subscribe' => '预约用户', 'order' => '下单数', 'watch' => '观看用户' ]; $params = $this->input->get(); - $row = $this->market_sylive_activity_model->get(['activityId'=>$this->a_id]); - if(!$row){ - throw new Hd_exception('参数错误',400); + $row = $this->market_sylive_activity_model->get(['activityId' => $this->a_id]); + if (!$row) { + throw new Hd_exception('参数错误', 400); } $title = $map_kpi_name[$params['kpi']]; $tab = [ - ['id'=>1,'title'=>'客户列表'] + ['id' => 1, 'title' => '客户列表'] ]; - if($params['type']=='biz' && $params['type_id']){ //显示顾问数据 - $tab[] = ['id'=>2,'title'=>'顾问数据']; + if ($params['type'] == 'biz' && $params['type_id']) { //显示顾问数据 + $tab[] = ['id' => 2, 'title' => '顾问数据']; } $goods = []; - if($params['kpi']=='order'){ + if ($params['kpi'] == 'order') { $where = [ 'activityId' => $this->a_id, 'status' => 0 ]; - $goods = $this->market_sylive_items_model->select($where,'sort desc,itemId desc',0,0,'itemId,title'); + $goods = $this->market_sylive_items_model->select($where, 'sort desc,itemId desc', 0, 0, 'itemId,title'); } $this->data['title'] = $title; $this->data['tab'] = $tab; @@ -369,9 +396,10 @@ class Stic extends Admin{ $this->show_view('h5/market/sylive2/stic/users'); } - public function user_lists(){ + public function user_lists() + { $params = $this->input->get(); - if($params['tabid']==2){ //顾问数据 + if ($params['tabid'] == 2) { //顾问数据 $this->gw_lists(); } $page = $params['page'] ? intval($params['page']) : 1; @@ -380,44 +408,44 @@ class Stic extends Admin{ 'activityId' => $this->a_id, 'kpi' => $params['kpi'], ]; - if($params['type']=='biz'){ + if ($params['type'] == 'biz') { $where['bizId'] = $params['type_id']; - }else{ + } else { $where['cfUserId'] = $this->uid; } - if($params['kpi']=='order' && $params['itemId']){ + if ($params['kpi'] == 'order' && $params['itemId']) { $where["tagId in (select id from lc_market_sylive_order where itemId={$params['itemId']} and activityId={$this->a_id})"] = null; } $total = $this->mdSytActivityKpiData->count($where); $lists = []; - if($total){ - $rows = $this->mdSytActivityKpiData->select($where,'id desc',$page,20,'userId,cfUserId,createTime,jsondata'); - $uids_arr = array_column($rows,'userId'); - if($params['type']=='biz'){ - $gw_uids_arr = array_column($rows,'cfUserId'); - $uids_arr = array_merge($uids_arr,$gw_uids_arr); + if ($total) { + $rows = $this->mdSytActivityKpiData->select($where, 'id desc', $page, 20, 'userId,cfUserId,createTime,jsondata'); + $uids_arr = array_column($rows, 'userId'); + if ($params['type'] == 'biz') { + $gw_uids_arr = array_column($rows, 'cfUserId'); + $uids_arr = array_merge($uids_arr, $gw_uids_arr); } - $uids = implode(',',array_unique($uids_arr)); + $uids = implode(',', array_unique($uids_arr)); $users = []; - if($uids){ + if ($uids) { $where = [ "userId in ($uids)" => null, ]; - $users = $this->user_model->map('userId','',$where,'','','','userId,uname,nickname,headimg'); + $users = $this->user_model->map('userId', '', $where, '', '', '', 'userId,uname,nickname,headimg'); } foreach ($rows as $key => $item) { - $jsondata = json_decode($item['jsondata'],true); + $jsondata = json_decode($item['jsondata'], true); $user = $users[$item['userId']] ? $users[$item['userId']][0] : []; - $nickname = $user['nickname'] ? $user['nickname'] : '用户'.$user['userId']; + $nickname = $user['nickname'] ? $user['nickname'] : '用户' . $user['userId']; $headimg = $user['headimg'] ? $user['headimg'] : 'https://thirdwx.qlogo.cn/mmopen/vi_32/Q3auHgzwzM483tlYWFg5RWQ1Xat94ib82prnDSicm2GHuxI49swU08N2I1aHb7B1gmicyxXF8R1BsVWahU9SiaPEzA/132'; $cf_uname = ''; - if($params['type']=='biz'){ //店长 + if ($params['type'] == 'biz') { //店长 $cf_user = $users[$item['cfUserId']] ? $users[$item['cfUserId']][0] : []; $cf_uname = $cf_user['uname'] ? $cf_user['uname'] : ""; } $mobile = $name = ''; - if($params['kpi']=='order' && $jsondata['order_id']){ - $order = $this->market_sylive_order_model->get(['id'=>$jsondata['order_id']],'uname,mobile'); + if ($params['kpi'] == 'order' && $jsondata['order_id']) { + $order = $this->market_sylive_order_model->get(['id' => $jsondata['order_id']], 'uname,mobile'); $name = $order['uname'] ? $order['uname'] : ''; $mobile = $order['mobile'] ? $order['mobile'] : ''; } @@ -427,7 +455,7 @@ class Stic extends Admin{ 'mobile' => $mobile, 'headimg' => $headimg, 'cf_uname' => $cf_uname, - 'time' => friendly_date($item['createTime'],'normal',1) + 'time' => friendly_date($item['createTime'], 'normal', 1) ]; } } @@ -435,10 +463,11 @@ class Stic extends Admin{ 'total' => $total, 'lists' => $lists ]; - $this->show_json($data,200); + $this->show_json($data, 200); } - public function gw_lists(){ + public function gw_lists() + { $params = $this->input->get(); $page = $params['page'] ? $params['page'] : 1; $size = $params['size'] ? $params['size'] : 20; @@ -446,7 +475,7 @@ class Stic extends Admin{ 'activityId' => $this->a_id, 'kpi' => $params['kpi'] ]; - if($params['type']=='biz' && $params['type_id']){ + if ($params['type'] == 'biz' && $params['type_id']) { $biz_id = $params['type_id']; $where['bizId'] = $biz_id; } @@ -455,9 +484,9 @@ class Stic extends Admin{ $teamId = $this->uid; $select = 'cfUserId as tagId,count(id) as t'; $order = 't desc,id desc'; - $res = $this->sylive2_data_entity->top_kpidata($groupby,$where,$order,$page,$size,$select,$teamId); + $res = $this->sylive2_data_entity->top_kpidata($groupby, $where, $order, $page, $size, $select, $teamId); $lists = []; - if($res['lists']){ + if ($res['lists']) { foreach ($res['lists'] as $item) { $lists[] = [ 'nickname' => $item['name'], @@ -470,11 +499,12 @@ class Stic extends Admin{ 'total' => $res['total'], 'lists' => $lists ]; - $this->show_json($data,200); + $this->show_json($data, 200); } //分组列表 - public function group_lists(){ + public function group_lists() + { $params = $this->input->get(); $page = $params['page'] ? $params['page'] : 1; $size = 100; @@ -486,16 +516,16 @@ class Stic extends Admin{ 'status' => 0 ]; $total = $this->groups_model->count($where); - $rows = $this->groups_model->select($where,'sortNumber desc',$page,$size,'groupsId,ifBiz,groupsLevel,groupsName'); + $rows = $this->groups_model->select($where, 'sortNumber desc', $page, $size, 'groupsId,ifBiz,groupsLevel,groupsName'); $lists = []; - if($rows){ + if ($rows) { foreach ($rows as $item) { - $count = $this->groups_model->count(['activityId'=>$this->a_id,'status'=>0,'parentId'=>$item['groupsId']]); + $count = $this->groups_model->count(['activityId' => $this->a_id, 'status' => 0, 'parentId' => $item['groupsId']]); $note = ''; $url = "/h5/market/sylive2/stic?groupsId={$item['groupsId']}"; - if(!$item['ifBiz']){ - $note = $disk[$item['groupsLevel']+1] ? $disk[$item['groupsLevel']+1]:'门店'; - }else{ + if (!$item['ifBiz']) { + $note = $disk[$item['groupsLevel'] + 1] ? $disk[$item['groupsLevel'] + 1] : '门店'; + } else { $count = ''; } $lists[] = [ @@ -510,38 +540,39 @@ class Stic extends Admin{ 'total' => $total, 'list' => $lists ]; - $this->show_json($data,200); + $this->show_json($data, 200); } - public function ranking(){ - $row = $this->market_sylive_activity_model->get(['activityId'=>$this->a_id]); - if(!$row){ - throw new Hd_exception('参数错误',400); + public function ranking() + { + $row = $this->market_sylive_activity_model->get(['activityId' => $this->a_id]); + if (!$row) { + throw new Hd_exception('参数错误', 400); } - $jsondata = json_decode($row['jsondata'],true); + $jsondata = json_decode($row['jsondata'], true); $info['banner'] = $jsondata['banner'] ? build_qiniu_image_url($jsondata['banner']) : Sylive_entity::DF_BANNER; - $activityStart = strtotime($row['activityStart'])>0 ? strtotime($row['activityStart']) : strtotime($row['timeStart'])-7*24*60*60; - $end_time = time()< strtotime($row['timeEnd']) ? time() : strtotime($row['timeEnd']); + $activityStart = strtotime($row['activityStart']) > 0 ? strtotime($row['activityStart']) : strtotime($row['timeStart']) - 7 * 24 * 60 * 60; + $end_time = time() < strtotime($row['timeEnd']) ? time() : strtotime($row['timeEnd']); $diff_seconds = $end_time - $activityStart; - $diff_days = ceil($diff_seconds/86400); + $diff_days = ceil($diff_seconds / 86400); $day_list = ['日期']; $timeEnd = strtotime($row['timeEnd']);//直播结束往前七天 - for($i=0;$i<$diff_days;$i++){ - if(time()< strtotime($row['timeEnd'])){ - $day_list[] = date('Y-m-d',time() - $i*24*60*60); - }else{ - $day_list[] = date('Y-m-d',$timeEnd - $i*24*60*60); + for ($i = 0; $i < $diff_days; $i++) { + if (time() < strtotime($row['timeEnd'])) { + $day_list[] = date('Y-m-d', time() - $i * 24 * 60 * 60); + } else { + $day_list[] = date('Y-m-d', $timeEnd - $i * 24 * 60 * 60); } } $this->data['day_list'] = $day_list; $groups = []; $disk = $this->sylive2_entity->level_disk($this->a_id); - if($disk){ - foreach ($disk as $key=>$item) { + if ($disk) { + foreach ($disk as $key => $item) { $groups[] = [ 'value' => $key, 'type' => 'level', - 'title' => $item.'排名' + 'title' => $item . '排名' ]; } } @@ -549,15 +580,15 @@ class Stic extends Admin{ 'activityId' => $this->a_id, 'status' => 0 ]; - if($this->a_id==11){ + if ($this->a_id == 11) { $where['price>'] = 0; } - $goods = $this->market_sylive_items_model->select($where,'sort desc,itemId desc',0,0,'itemId,title'); + $goods = $this->market_sylive_items_model->select($where, 'sort desc,itemId desc', 0, 0, 'itemId,title'); $info['itemId'] = $goods[0]['itemId'] ? $goods[0]['itemId'] : 0; $info['aId'] = $this->a_id; $this->data['goods'] = $goods ? $goods : []; - $groups[] = ['value'=>'','type'=>'biz','title'=>'门店排名']; - $groups[] = ['value'=>'','type'=>'user','title'=>'顾问排名']; + $groups[] = ['value' => '', 'type' => 'biz', 'title' => '门店排名']; + $groups[] = ['value' => '', 'type' => 'user', 'title' => '顾问排名']; $this->data['groups'] = $groups; $this->data['info'] = $info; //微信分享 @@ -567,57 +598,58 @@ class Stic extends Admin{ $this->show_view('h5/market/sylive2/stic/ranking'); } - public function ajax_rank(){ - $sylive2_data_entity = new sylive2_data_entity(['show_echarts'=>true]); + public function ajax_rank() + { + $sylive2_data_entity = new sylive2_data_entity(['show_echarts' => true]); $map_kpi_biz = [ - 'browse' => 'browse', 'subscribe' => 'subscribe', 'order' => 'orderTotal','watch' => 'watch','beforeOrder' => 'beforeOrderTotal' + 'browse' => 'browse', 'subscribe' => 'subscribe', 'order' => 'orderTotal', 'watch' => 'watch', 'beforeOrder' => 'beforeOrderTotal' ]; $params = $this->input->get(); $title = ''; $title_arr = [ - 'browse' => $title.'浏览排行', - 'subscribe' => $title.'预约排行', - 'watch' => $title.'观看排行', - 'order' => $title.'订单排行' + 'browse' => $title . '浏览排行', + 'subscribe' => $title . '预约排行', + 'watch' => $title . '观看排行', + 'order' => $title . '订单排行' ]; - if($this->a_id==11){ - $title_arr['beforeOrder'] = $title.'留资排行'; + if ($this->a_id == 11) { + $title_arr['beforeOrder'] = $title . '留资排行'; } - $group_user = $this->groups_user_model->get(['activityId'=>$this->a_id,'userId'=>$this->uid]); + $group_user = $this->groups_user_model->get(['activityId' => $this->a_id, 'userId' => $this->uid]); $page = $params['page'] ? intval($params['page']) : 1; $size = 20; // if(strtotime($params['day']) || $params['itemId']){//根据日期排行 - $kpi = $params['kpi']; - $tagId = 0; - $where = [ - 'activityId' => $this->a_id, - 'status' => 0, - ]; - if($kpi=='order'){ - $where["(kpi='order' or kpi='beforeOrder')"] = null; - }else{ - $where['kpi'] = $kpi; - } - if($params['type']=='level'){ - $group_by = "levelId{$params['value']}"; - $select = "{$group_by} as tagId,count(id) as t"; - $where["$group_by>"] = 0; - }elseif($params['type']=='biz'){ - $group_by = 'bizId'; - $select = "bizId as tagId,count(id) as t"; - $where["$group_by>"] = 0; - $tagId = $group_user['bizId']; - }else{ - $group_by = 'cfUserId'; - $select = "cfUserId as tagId,count(id) as t"; - $where["$group_by>"] = 0; - $tagId = $group_user['userId']; - } - if($params['day']){ - strtotime($params['day']) && $where['day'] = date('Y-m-d',strtotime($params['day'])); - } - $params['itemId'] && $where["itemId"] = $params['itemId']; - $data = $sylive2_data_entity->top_kpidata($group_by,$where,'t desc,id desc',$page,$size,$select,$tagId); + $kpi = $params['kpi']; + $tagId = 0; + $where = [ + 'activityId' => $this->a_id, + 'status' => 0, + ]; + if ($kpi == 'order') { + $where["(kpi='order' or kpi='beforeOrder')"] = null; + } else { + $where['kpi'] = $kpi; + } + if ($params['type'] == 'level') { + $group_by = "levelId{$params['value']}"; + $select = "{$group_by} as tagId,count(id) as t"; + $where["$group_by>"] = 0; + } elseif ($params['type'] == 'biz') { + $group_by = 'bizId'; + $select = "bizId as tagId,count(id) as t"; + $where["$group_by>"] = 0; + $tagId = $group_user['bizId']; + } else { + $group_by = 'cfUserId'; + $select = "cfUserId as tagId,count(id) as t"; + $where["$group_by>"] = 0; + $tagId = $group_user['userId']; + } + if ($params['day']) { + strtotime($params['day']) && $where['day'] = date('Y-m-d', strtotime($params['day'])); + } + $params['itemId'] && $where["itemId"] = $params['itemId']; + $data = $sylive2_data_entity->top_kpidata($group_by, $where, 't desc,id desc', $page, $size, $select, $tagId); // }else{ // $kpi = $map_kpi_biz[$params['kpi']]; // $where = [ @@ -640,53 +672,54 @@ class Stic extends Admin{ // $data = $sylive2_data_entity->top_groups_user($group_by,$where,'t desc,groupsUserId desc',$page,$size,$select,$params['kpi'],$group_user['bizId']); // } $data['title'] = $title_arr[$params['kpi']]; - $data['url'] = "/h5/market/sylive2/stic/rank?kpi={$params['kpi']}&day={$params['day']}&index={$params['index']}&show_day=1&itemId={$params['itemId']}"; - $this->show_json($data,200); + $data['url'] = "/h5/market/sylive2/stic/rank?kpi={$params['kpi']}&day={$params['day']}&index={$params['index']}&show_day=1&itemId={$params['itemId']}"; + $this->show_json($data, 200); } - public function rank(){ + public function rank() + { $params = $this->input->get(); !$params['day'] && $params['day'] = '日期'; - $row = $this->market_sylive_activity_model->get(['activityId'=>$this->a_id]); - if(!$row){ - throw new Hd_exception('参数错误',400); + $row = $this->market_sylive_activity_model->get(['activityId' => $this->a_id]); + if (!$row) { + throw new Hd_exception('参数错误', 400); } - $activityStart = strtotime($row['activityStart'])>0 ? strtotime($row['activityStart']) : strtotime($row['timeStart'])-7*24*60*60; - $end_time = time()< strtotime($row['timeEnd']) ? time() : strtotime($row['timeEnd']); + $activityStart = strtotime($row['activityStart']) > 0 ? strtotime($row['activityStart']) : strtotime($row['timeStart']) - 7 * 24 * 60 * 60; + $end_time = time() < strtotime($row['timeEnd']) ? time() : strtotime($row['timeEnd']); $diff_seconds = $end_time - $activityStart; - $diff_days = ceil($diff_seconds/86400); + $diff_days = ceil($diff_seconds / 86400); $day_list = ['日期']; $timeEnd = strtotime($row['timeEnd']);//直播结束往前七天 - for($i=0;$i<$diff_days;$i++){ - if(time()< strtotime($row['timeEnd'])){ - $day_list[] = date('Y-m-d',time() - $i*24*60*60); - }else{ - $day_list[] = date('Y-m-d',$timeEnd - $i*24*60*60); + for ($i = 0; $i < $diff_days; $i++) { + if (time() < strtotime($row['timeEnd'])) { + $day_list[] = date('Y-m-d', time() - $i * 24 * 60 * 60); + } else { + $day_list[] = date('Y-m-d', $timeEnd - $i * 24 * 60 * 60); } } $disk = $this->sylive2_entity->level_disk($this->a_id); - if($disk){ - foreach ($disk as $key=>$item) { + if ($disk) { + foreach ($disk as $key => $item) { $groups[] = [ 'value' => $key, 'type' => 'level', - 'title' => $item.'排名' + 'title' => $item . '排名' ]; } } $goods = []; - if($params['kpi']=='order'){ + if ($params['kpi'] == 'order') { $where = [ 'activityId' => $this->a_id, 'status' => 0 ]; - if($this->a_id==11){ + if ($this->a_id == 11) { $where['price>'] = 0; } - $goods = $this->market_sylive_items_model->select($where,'sort desc,itemId desc',0,0,'itemId,title'); + $goods = $this->market_sylive_items_model->select($where, 'sort desc,itemId desc', 0, 0, 'itemId,title'); } - $groups[] = ['value'=>'','type'=>'biz','title'=>'门店排名']; - $groups[] = ['value'=>'','type'=>'user','title'=>'顾问排名']; + $groups[] = ['value' => '', 'type' => 'biz', 'title' => '门店排名']; + $groups[] = ['value' => '', 'type' => 'user', 'title' => '顾问排名']; $this->data['groups'] = $groups; $this->data['day_list'] = $day_list; $this->data['params'] = $params; @@ -698,19 +731,20 @@ class Stic extends Admin{ $this->show_view('h5/market/sylive2/stic/rank'); } - public function ajax_line(){ + public function ajax_line() + { $type = $this->input->get('type'); $biz_id = $this->input->get('biz_id'); - $row = $this->market_sylive_activity_model->get(['activityId'=>$this->a_id],'activityStart,timeStart,timeEnd'); + $row = $this->market_sylive_activity_model->get(['activityId' => $this->a_id], 'activityStart,timeStart,timeEnd'); $xAxisData = []; $title = ''; - if($type==2){ - if(time()>=strtotime($row['timeStart'])){ //直播开始后显示 + if ($type == 2) { + if (time() >= strtotime($row['timeStart'])) { //直播开始后显示 // $activityStart = strtotime($row['timeStart']); $end_time = strtotime($row['timeEnd']); - $activityStart = $end_time-5*60*60; //直播结束前5个小时 + $activityStart = $end_time - 5 * 60 * 60; //直播结束前5个小时 $diff_seconds = $end_time - $activityStart; - $diff_hour = ceil($diff_seconds/3600); + $diff_hour = ceil($diff_seconds / 3600); $where = [ 'activityId' => $this->a_id, 'bizId' => $biz_id, @@ -718,24 +752,24 @@ class Stic extends Admin{ 'createTime>=' => $activityStart, 'createTime<=' => $end_time, ]; - $watch_kpi_rows = $this->mdSytActivityKpiData->select_groupby('ctime',$where,'',0,0,'from_unixtime(createTime,"%H") as ctime,count(id) as total'); + $watch_kpi_rows = $this->mdSytActivityKpiData->select_groupby('ctime', $where, '', 0, 0, 'from_unixtime(createTime,"%H") as ctime,count(id) as total'); $where['kpi'] = 'order'; - $order_kpi_rows = $this->mdSytActivityKpiData->select_groupby('ctime',$where,'',0,0,'from_unixtime(createTime,"%H") as ctime,count(id) as total'); + $order_kpi_rows = $this->mdSytActivityKpiData->select_groupby('ctime', $where, '', 0, 0, 'from_unixtime(createTime,"%H") as ctime,count(id) as total'); $temp_o_data = $temp_w_data = []; - if($watch_kpi_rows){ + if ($watch_kpi_rows) { foreach ($watch_kpi_rows as $item) { $temp_w_data[intval($item['ctime'])] = $item['total']; } } - if($order_kpi_rows){ + if ($order_kpi_rows) { foreach ($order_kpi_rows as $item) { $temp_o_data[intval($item['ctime'])] = $item['total']; } } $watch_data = $order_data = []; - for($i=0;$i<$diff_hour;$i++){ - $xAxisData[] = date('H:00',$activityStart + ($i+1)*60*60); - $time = intval(date('H',$activityStart + $i*60*60)); + for ($i = 0; $i < $diff_hour; $i++) { + $xAxisData[] = date('H:00', $activityStart + ($i + 1) * 60 * 60); + $time = intval(date('H', $activityStart + $i * 60 * 60)); $watch_data[] = $temp_w_data[$time] ? $temp_w_data[$time] : 0;; $order_data[] = $temp_o_data[$time] ? $temp_o_data[$time] : 0;; } @@ -754,11 +788,11 @@ class Stic extends Admin{ ], ]; } - }else{ - $activityStart = strtotime($row['activityStart'])>0 ? strtotime($row['activityStart']) : strtotime($row['timeStart'])-7*24*60*60; - $end_time = time()< strtotime($row['timeEnd']) ? time() : strtotime($row['timeEnd']); + } else { + $activityStart = strtotime($row['activityStart']) > 0 ? strtotime($row['activityStart']) : strtotime($row['timeStart']) - 7 * 24 * 60 * 60; + $end_time = time() < strtotime($row['timeEnd']) ? time() : strtotime($row['timeEnd']); $diff_seconds = $end_time - $activityStart; - $diff_days = ceil($diff_seconds/86400); + $diff_days = ceil($diff_seconds / 86400); $where = [ 'activityId' => $this->a_id, 'bizId' => $biz_id, @@ -766,29 +800,34 @@ class Stic extends Admin{ 'createTime>=' => $activityStart, 'createTime<=' => $end_time, ]; - $browse_kpi_rows = $this->mdSytActivityKpiData->select_groupby('day',$where,'',0,0,'day,count(id) as total'); - $where['kpi'] = 'subscribe'; - $subscribe_rows = $this->mdSytActivityKpiData->select_groupby('day',$where,'',0,0,'day,count(id) as total'); + $browse_kpi_rows = $this->mdSytActivityKpiData->select_groupby('day', $where, '', 0, 0, 'day,count(id) as total'); + if ($this->a_id == 11) { + $where['kpi'] = 'beforeOrder'; + } else { + $where['kpi'] = 'subscribe'; + } + $subscribe_rows = $this->mdSytActivityKpiData->select_groupby('day', $where, '', 0, 0, 'day,count(id) as total'); $temp_s_data = $temp_b_data = []; - if($browse_kpi_rows){ + if ($browse_kpi_rows) { foreach ($browse_kpi_rows as $item) { $temp_b_data[$item['day']] = $item['total']; } } - if($subscribe_rows){ + if ($subscribe_rows) { foreach ($subscribe_rows as $item) { $temp_s_data[$item['day']] = $item['total']; } } $browse_data = $subscribe_data = []; - for($i=0;$i<$diff_days;$i++){ - $xAxisData[] = date('m.d',$activityStart + $i*24*60*60); - $day = date('Y-m-d',$activityStart + $i*24*60*60); + for ($i = 0; $i < $diff_days; $i++) { + $xAxisData[] = date('m.d', $activityStart + $i * 24 * 60 * 60); + $day = date('Y-m-d', $activityStart + $i * 24 * 60 * 60); $browse_data[] = $temp_b_data[$day] ? $temp_b_data[$day] : 0; $subscribe_data[] = $temp_s_data[$day] ? $temp_s_data[$day] : 0; } $title = '预热走势图'; - $legendData = ['访问数', '预约数']; + $t_title = $this->a_id == 11 ? '留资数' : '预约数'; + $legendData = ['访问数', $t_title]; $seriesData = [ [ 'name' => '访问数', @@ -796,7 +835,7 @@ class Stic extends Admin{ 'data' => $browse_data ], [ - 'name' => '预约数', + 'name' => $t_title, 'type' => 'line', 'data' => $subscribe_data ], @@ -810,6 +849,6 @@ class Stic extends Admin{ 'xAxisData' => $xAxisData, 'seriesData' => $seriesData ]; - $this->show_json($data,200); + $this->show_json($data, 200); } } \ No newline at end of file