diff --git a/common/libraries/market/Sylive2_data_entity.php b/common/libraries/market/Sylive2_data_entity.php index 9e98efbb..822e3328 100644 --- a/common/libraries/market/Sylive2_data_entity.php +++ b/common/libraries/market/Sylive2_data_entity.php @@ -34,32 +34,34 @@ class Sylive2_data_entity{ $lists = []; if($total){ $rows = $this->ci->mdSytActivityKpiData->select_groupby($groupby, $where, $order, $page, $page_size, $select); - $biz_rows = $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'); - } - } + $target_rows = []; if($groupby=='bizId'){ - $biz_ids = implode(',',array_column($rows,'bizId')); - $biz_ids && $biz_rows = $this->ci->groups_model->map('groupsId','',["groupsId in ($biz_ids)"=>null],'','','','groupsId,groupsName'); + $biz_ids = implode(',',array_column($rows,'tagId')); + $biz_ids && $target_rows = $this->ci->groups_model->map('groupsId','',["groupsId in ($biz_ids)"=>null],'','','','groupsId,groupsName'); + }elseif($groupby=='levelId1'||$groupby=='levelId2'||$groupby=='levelId3'){ + $biz_ids = implode(',',array_column($rows,'tagId')); + $biz_ids && $target_rows = $this->ci->groups_model->map('groupsId','',["groupsId in ($biz_ids)"=>null],'','','','groupsId,groupsName'); + }else{ //顾问 + $user_ids = implode(',',array_column($rows,'tagId')); + $user_ids && $target_rows = $this->ci->user_model->map('userId','',["userId in ($user_ids)"=>null],'','','','userId,uname as name,headimg'); } $num_tip = $where['kpi'] == 'order' ? '单' : '人'; $start = $page>1 ? ($page-1)*$page_size : 0; foreach ($rows as $key=>$val) { - $name = $tip = $headimg = $biz_name = ''; - if($groupby=='cfUserId'){ - $org = $org_rows[$val['cfUserId']] ? $org_rows[$val['cfUserId']][0] : []; + $headimg = ''; + if($groupby=='bizId'){ + $biz = $target_rows[$val['tagId']][0]; + $name = $biz['groupsName']; + $tip = $tagId==$val['bizId'] ? '本店' : ''; + }elseif($groupby=='levelId1'||$groupby=='levelId2'||$groupby=='levelId3'){ + $biz = $target_rows[$val['tagId']][0]; + $name = $biz['groupsName']; + }else{ + $org = $target_rows[$val['tagId']] ? $target_rows[$val['tagId']][0] : []; $tip = $tagId==$val['cfUserId'] ? '本人' : ''; $name = $org['name']; $headimg = $org['headimg']; } - if($groupby=='bizId'){ - $biz = $biz_rows[$val['bizId']][0]; - $name = $biz['groupsName']; - $tip = $tagId==$val['bizId'] ? '本店' : ''; - } $lists[] = [ 'ranking' => $start+$key+1, 'name' => $name, @@ -83,20 +85,31 @@ class Sylive2_data_entity{ $lists = []; if($total){ $rows = $this->ci->groups_user_model->select_groupby($groupby, $where, $order, $page, $page_size, $select); - $biz_rows = []; + $target_rows = []; if($groupby=='bizId'){ - $biz_ids = implode(',',array_column($rows,'bizId')); - $biz_ids && $biz_rows = $this->ci->groups_model->map('groupsId','',["groupsId in ($biz_ids)"=>null],'','','','groupsId,groupsName'); + $biz_ids = implode(',',array_column($rows,'tagId')); + $biz_ids && $target_rows = $this->ci->groups_model->map('groupsId','',["groupsId in ($biz_ids)"=>null],'','','','groupsId,groupsName'); + }elseif($groupby=='levelId1'||$groupby=='levelId2'||$groupby=='levelId3'){ + $biz_ids = implode(',',array_column($rows,'tagId')); + $biz_ids && $target_rows = $this->ci->groups_model->map('groupsId','',["groupsId in ($biz_ids)"=>null],'','','','groupsId,groupsName'); + }else{ + $biz_ids = implode(',',array_column($rows,'tagId')); + $biz_ids && $target_rows = $this->ci->user_model->map('userId','',["userId in ($biz_ids)"=>null],'','','','userId,uname as name,headimg'); } - $start = $page>1 ? ($page-1)*$page_size : 0; $num_tip = $kpi == 'order' ? '单' : '人'; foreach ($rows as $key=>$val) { $tip = $headimg = $name = ''; if($groupby=='bizId'){ - $biz = $biz_rows[$val['bizId']][0]; + $biz = $target_rows[$val['tagId']][0]; $name = $biz['groupsName']; $tip = $tagId==$val['bizId'] ? '本店' : ''; + }elseif($groupby=='levelId1'||$groupby=='levelId2'||$groupby=='levelId3'){ + $biz = $target_rows[$val['tagId']][0]; + $name = $biz['groupsName']; + }else{ + $biz = $target_rows[$val['tagId']][0]; + $name = $biz['name']; } $lists[] = [ 'ranking' => $start+$key+1, diff --git a/common/libraries/market/Sylive2_entity.php b/common/libraries/market/Sylive2_entity.php index b506dc17..74fa3f88 100644 --- a/common/libraries/market/Sylive2_entity.php +++ b/common/libraries/market/Sylive2_entity.php @@ -145,16 +145,32 @@ class Sylive2_entity{ * @param $a_id * @return array */ - public function level_disk($a_id){ + public function level_disk($a_id,$groupsLevel=0){ $top_group = $this->ci->groups_model->get(['activityId'=>$a_id,'parentId'=>0],'statisticsType'); $disk = []; if($top_group['statisticsType']){ $where = ['dictId'=>$top_group['statisticsType']]; + $groupsLevel && $where["dictDataCode>"] = $groupsLevel; $disk = $this->ci->market_sys_dictionary_data_model->map('dictDataCode','dictDataName',$where,'','','','dictDataName,dictDataCode'); } return $disk; } + /** + * 获取等级字典 + * @param $a_id + * @return array + */ + public function level_disk_lists($a_id){ + $top_group = $this->ci->groups_model->get(['activityId'=>$a_id,'parentId'=>0],'statisticsType'); + $disk = []; + if($top_group['statisticsType']){ + $where = ['dictId'=>$top_group['statisticsType']]; + $disk = $this->ci->market_sys_dictionary_data_model->select($where,'','','','dictDataName,dictDataCode'); + } + return $disk; + } + public function __get($name) { if ('_model' === substr($name, -6)) { diff --git a/home/controllers/h5/market/sylive2/Biz.php b/home/controllers/h5/market/sylive2/Biz.php index bd6bfa56..e5977933 100644 --- a/home/controllers/h5/market/sylive2/Biz.php +++ b/home/controllers/h5/market/sylive2/Biz.php @@ -11,7 +11,7 @@ class Biz extends Admin{ public function index(){ $user = $this->user_model->get(['userId'=>$this->session['userId']]); $this->data['multi_org'] = $_SESSION[self::SESSION_KEY]['multi_org'] ? 1 : 0; - $this->data['isBiz'] = $user['bizId'] ? 1 : 0; + $this->data['isBiz'] = $user['bizId'] == $user['organizationId'] ? 1 : 0; $this->show_view('h5/market/sylive2/biz/index'); } diff --git a/home/controllers/h5/market/sylive2/Item.php b/home/controllers/h5/market/sylive2/Item.php index 0e78ff9b..8dcd4f3b 100644 --- a/home/controllers/h5/market/sylive2/Item.php +++ b/home/controllers/h5/market/sylive2/Item.php @@ -38,7 +38,7 @@ class Item extends Wx{ $s_time = time() < strtotime($row['timeStart']) ? strtotime($row['timeStart']) - time() : 0; $is_pay = $this->market_sylive_order_model->count(['itemId'=>$itemId,'activityId'=>$a_id,'status'=>1,'userId'=>$this->uid,'type'=>0]); if($is_pay){ - $url = http_host_com('home').'/h5/market/sylive2/ucenter?skey='.$skey; + $url = http_host_com('home').'/h5/market/sylive2/ucenter/orders?skey='.$skey; redirect($url);exit; } @@ -232,13 +232,18 @@ class Item extends Wx{ //获取验证码 public function get_code(){ $mobile = $this->input->post('mobile'); + $a_id = $this->input->post('a_id'); if(!mobile_valid($mobile)){ $this->show_json('',400,'请输入正确的手机号码'); } - //验证是否黑名单用户 -// if(!$this->ck_mobile($mobile)){ -// $this->show_json('',400,'本次活动仅限受邀客户参加'); -// } + $act = $this->market_sylive_activity_model->get(['activityId'=>$a_id]); + $jsondata = json_decode($act['jsondata'],true); + if($jsondata['blacklist']){ + //验证是否黑名单用户 + if(!$this->ck_mobile($mobile)){ + $this->show_json('',400,'本次活动仅限受邀客户参加'); + } + } $redis = &load_cache('redis'); $key = "sylive_item_code_{$this->uid}_{$mobile}"; $code = $redis->get($key); @@ -301,7 +306,7 @@ class Item extends Wx{ $mobile_list[] = trim($item); } } - $redis->save($ckey,$mobile_list,2*24*60*60); + $redis->save($ckey,$mobile_list,7*24*60*60); } if(in_array($mobile,$mobile_list)){ return false; diff --git a/home/controllers/h5/market/sylive2/Stic.php b/home/controllers/h5/market/sylive2/Stic.php index 39236960..6e4a78cb 100644 --- a/home/controllers/h5/market/sylive2/Stic.php +++ b/home/controllers/h5/market/sylive2/Stic.php @@ -33,9 +33,13 @@ class Stic extends Admin{ $info['banner'] = $jsondata['banner'] ? build_qiniu_image_url($jsondata['banner']) : Sylive_entity::DF_BANNER; $info['nickname'] = $user['nickname']; $info['headimg'] = $user['headimg']; - $group_user = $this->groups_user_model->get(['activityId'=>$this->a_id,'userId'=>$this->uid]); - $group_lists = $this->sylive2_entity->get_group_lists($group_user['groupsId'],$this->a_id); - $info['group_name'] = implode(' ',array_column($group_lists,'groupsName')); + $group_user = $this->groups_user_model->get(['activityId'=>$this->a_id,'userId'=>$this->uid,'status'=>0]); + $info['group_name'] = ''; + 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')); + } $info['groupsId'] = $groupsId ? $groupsId : $group_user['groupsId']; $info['is_biz'] = $group_user['bizId'] ? 1 : 0; $info['tab'] = time()>=strtotime($row['timeStart']) ? 2 : 1; @@ -49,20 +53,18 @@ class Stic extends Admin{ //预约阶段数据 public function lists_ready(){ $groupsId = $this->input->get('groupsId'); - $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,'status'=>0]); !$groupsId && $groupsId = $group_user['groupsId']; $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']){ - $i = $group_row['groupsLevel']+1; - for($i;$i<4;$i++){ + if(!$group_user['bizId'] && $disk){ + foreach ($disk as $key => $val) { $where = [ 'activityId' => $this->a_id, - 'groupsLevel' => $i + 'groupsLevel' => $key ]; $level_total = $this->groups_model->count($where); - $title = $disk[$i] ? $disk[$i] : "{$i}级"; - $h_lists[] = ['title'=> '参与'.$title,'num'=>"{$level_total}个"]; + $h_lists[] = ['title'=> "参与{$val}",'num'=>"{$level_total}个"]; } } $where = [ @@ -116,8 +118,8 @@ class Stic extends Admin{ ]; $sub_lists[] = ['title'=>'本店','lists'=>$biz]; } - if(!$group_row['ifBiz']){ //当前等级 - if(!$group_row['groupsLevel']){//顶级 + if($group_row['groupsId']!=$group_user['bizId']){ + if(!$group_row['groupsLevel'] && !$group_row['ifBiz']){//顶级 $b_sum = $this->groups_model->sum('browse',['groupsLevel'=>1,'activityId'=>$this->a_id]); $sub_sum = $this->groups_model->sum('subscribe',['groupsLevel'=>1,'activityId'=>$this->a_id]); $browse_count = $b_sum['browse'];//浏览数据 @@ -131,7 +133,9 @@ class Stic extends Admin{ ['title'=>'预约用户','num'=>"{$subscribe_count}人"], ['title'=>'预约率','num'=>$browse_count ? round($subscribe_count/$browse_count*100,2)."%" : 0], ]; - $sub_lists[] = ['title'=>"所有大区",'lists'=>$biz]; + $title = $disk[$group_row['groupsLevel']+1]? '所有'.$disk[$group_row['groupsLevel']+1] : '所有门店'; + $group_row['ifBiz'] && $title = $group_row['groupsName']; + $sub_lists[] = ['title'=>"{$title}",'lists'=>$biz]; } $data = [ 'h_lists' => $h_lists, @@ -143,7 +147,7 @@ class Stic extends Admin{ //直播统计数据 public function lists_live(){ $groupsId = $this->input->get('groupsId'); - $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,'status'=>0]); !$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]); @@ -194,8 +198,9 @@ class Stic extends Admin{ ]; $sub_lists[] = ['title'=>'本店','lists'=>$biz]; } - if(!$group_row['ifBiz']){ //当前等级 - if(!$group_row['groupsLevel']){//顶级 + if($group_row['groupsId']!=$group_user['bizId']){ + $disk = $this->sylive2_entity->level_disk($this->a_id); + if(!$group_row['groupsLevel'] && !$group_row['ifBiz']){//顶级 $b_sum = $this->groups_model->sum('watch',['groupsLevel'=>1,'activityId'=>$this->a_id]); $sub_sum = $this->groups_model->sum('orderTotal',['groupsLevel'=>1,'activityId'=>$this->a_id]); $browse_count = $b_sum['watch'];//观看数据 @@ -209,7 +214,9 @@ class Stic extends Admin{ ['title'=>'下单数','num'=>"{$subscribe_count}人"], ['title'=>'转化率','num'=>$browse_count ? round($subscribe_count/$browse_count*100,2)."%" : 0], ]; - $sub_lists[] = ['title'=>"所有大区",'lists'=>$biz]; + $title = $disk[$group_row['groupsLevel']+1]? '所有'.$disk[$group_row['groupsLevel']+1] : '所有门店'; + $group_row['ifBiz'] && $title = $group_row['groupsName']; + $sub_lists[] = ['title'=>"{$title}",'lists'=>$biz]; } $data = [ 'h_lists' => $h_lists, @@ -226,7 +233,7 @@ class Stic extends Admin{ $type = $this->input->get('type'); !$page && $page=1; $row = $this->market_sylive_activity_model->get(['activityId'=>$this->a_id]); - $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,'status'=>0]); $where = [ 'activityId'=>$this->a_id, 'bizId'=>$group_user['bizId'], @@ -421,11 +428,18 @@ class Stic extends Admin{ if($rows){ foreach ($rows as $item) { $count = $this->groups_model->count(['activityId'=>$this->a_id,'status'=>0,'parentId'=>$item['groupsId']]); + $url = $note = ''; + $url = "/h5/market/sylive2/stic?groupsId={$item['groupsId']}"; + if(!$item['ifBiz']){ + $note = $disk[$item['groupsLevel']+1] ? $disk[$item['groupsLevel']+1]:'门店'; + }else{ + $count = ''; + } $lists[] = [ 'title' => $item['groupsName'], - 'note' => $disk[$item['groupsLevel']+1] ? $disk[$item['groupsLevel']+1]:'下一级组员', + 'note' => $note, 'num' => $count, - 'url' => $item['groupsLevel']<3 ? "/h5/market/sylive2/stic?groupsId={$item['groupsId']}" : '', + 'url' => $url, ]; } } @@ -450,18 +464,22 @@ class Stic extends Admin{ $day_list[] = date('Y-m-d',$timeEnd - $i*24*60*60); } $this->data['day_list'] = $day_list; - $groups = [ - ['value'=>0,'title'=>'选择分组'], - ]; - $group_rows = $this->groups_model->select(['activityId'=>$this->a_id,'groupsLevel'=>1,'status'=>0],'','','','groupsId,groupsName'); - if($group_rows){ - foreach ($group_rows as $item) { - $groups[] = [ - 'value' => $item['groupsId'], - 'title' => $item['groupsName'] - ]; + $groups = []; + $group_user = $this->groups_user_model->get(['activityId'=>$this->a_id,'userId'=>$this->uid]); + if(!$group_user['bizId']){ + $disk = $this->sylive2_entity->level_disk($this->a_id); + if($disk){ + foreach ($disk as $key=>$item) { + $groups[] = [ + 'value' => $key, + 'type' => 'level', + 'title' => $item.'排名' + ]; + } } } + $groups[] = ['value'=>'','type'=>'biz','title'=>'门店排名']; + $groups[] = ['value'=>'','type'=>'user','title'=>'顾问排名']; $this->data['groups'] = $groups; //微信分享 $wx_info = $this->share_info($row); @@ -475,7 +493,6 @@ class Stic extends Admin{ 'browse' => 'browse', 'subscribe' => 'subscribe', 'order' => 'orderTotal','watch' => 'watch' ]; $params = $this->input->get(); -// $title = $params['gtype']=='gw' ? '顾问' : '门店'; $title = ''; $title_arr = [ 'browse' => $title.'浏览排行', @@ -486,31 +503,55 @@ class Stic extends Admin{ $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'])){//根据日期排行 + if(strtotime($params['day']) || $params['itemId']){//根据日期排行 $kpi = $params['kpi']; - $select = "bizId,count(id) as t"; + $tagId = 0; $where = [ 'activityId' => $this->a_id, - 'bizId>' => 0, 'status' => 0, - 'day' => date('Y-m-d',strtotime($params['day'])), 'kpi' => $kpi ]; - $params['groupIds'] && $where['levelId1'] = $params['groupIds']; - $data = $this->sylive2_data_entity->top_kpidata('bizId',$where,'t desc,id desc',$page,$size,$select,$group_user['bizId']); + 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']; + } + strtotime($params['day']) && $where['day'] = date('Y-m-d',strtotime($params['day'])); + $params['itemId'] && $where["itemId"] = $params['itemId']; + $data = $this->sylive2_data_entity->top_kpidata($group_by,$where,'t desc,id desc',$page,$size,$select,$tagId); }else{ $kpi = $map_kpi_biz[$params['kpi']]; - $select = "bizId,sum({$kpi}) as t"; $where = [ 'activityId' => $this->a_id, - 'bizId>' => 0, 'status' => 0 ]; - $params['groupIds'] && $where['levelId1'] = $params['groupIds']; - $data = $this->sylive2_data_entity->top_groups_user('bizId',$where,'t desc,groupsUserId desc',$page,$size,$select,$params['kpi'],$group_user['bizId']); + if($params['type']=='level'){ + $group_by = "levelId{$params['value']}"; + $select = "{$group_by} as tagId,sum({$kpi}) as t"; + $where["$group_by>"] = 0; + }elseif($params['type']=='biz'){ + $group_by = 'bizId'; + $select = "bizId as tagId,sum({$kpi}) as t"; + $where["$group_by>"] = 0; + }else{ + $group_by = 'userId'; + $select = "userId as tagId,sum({$kpi}) as t"; + $where["$group_by>"] = 0; + } + $data = $this->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?type={$params['kpi']}&day={$params['day']}>ype={$params['gtype']}&show_day=1"; + $data['url'] = "/h5/market/sylive2/stic/rank?kpi={$params['kpi']}&day={$params['day']}&index={$params['index']}&show_day=1"; $this->show_json($data,200); } @@ -526,8 +567,33 @@ class Stic extends Admin{ for($i=0;$i<8;$i++){ $day_list[] = date('Y-m-d',$timeEnd - $i*24*60*60); } + $group_user = $this->groups_user_model->get(['activityId'=>$this->a_id,'userId'=>$this->uid]); + if(!$group_user['bizId']){ + $disk = $this->sylive2_entity->level_disk($this->a_id); + if($disk){ + foreach ($disk as $key=>$item) { + $groups[] = [ + 'value' => $key, + 'type' => 'level', + 'title' => $item.'排名' + ]; + } + } + } + $goods = []; + 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'); + } + $groups[] = ['value'=>'','type'=>'biz','title'=>'门店排名']; + $groups[] = ['value'=>'','type'=>'user','title'=>'顾问排名']; + $this->data['groups'] = $groups; $this->data['day_list'] = $day_list; $this->data['params'] = $params; + $this->data['goods'] = $goods; //微信分享 $wx_info = $this->share_info($row); $this->data['sign_package'] = $wx_info['sign_package']; diff --git a/home/views/h5/market/sylive2/act/share.php b/home/views/h5/market/sylive2/act/share.php index b38963c3..3e08d095 100644 --- a/home/views/h5/market/sylive2/act/share.php +++ b/home/views/h5/market/sylive2/act/share.php @@ -2,9 +2,9 @@