diff --git a/api/controllers/plan/Syt.php b/api/controllers/plan/Syt.php index 0d226c9a..ff72c262 100644 --- a/api/controllers/plan/Syt.php +++ b/api/controllers/plan/Syt.php @@ -230,8 +230,8 @@ class Syt extends CI_Controller $this->load->model('market/market_sylive_order_model'); //商家订单过期 $where = [ - 'expire_time>' => 0, - 'expire_time<' => time(), + 'expireTime>' => 0, + 'expireTime<' => time(), 'status' => 0 ]; $this->mdSytActivityOrders->update(['status'=>-1],$where); @@ -241,6 +241,75 @@ class Syt extends CI_Controller 'expire_time<' => time(), 'status' => 0 ]; - $this->market_sylive_order_model->update(['status'=>-1],$where); + $rows = $this->market_sylive_order_model->select($where,'id asc',1,20); + if($rows){ + foreach ($rows as $key => $val) { + $res = $this->market_sylive_order_model->update(['status'=>-1],['id'=>$val['id']]); + if($res){ + $up_data = [ + 'stock = stock+1' => null + ]; + $this->market_sylive_activity_model->update($up_data,['activityId'=>$val['item_id']]); + } + } + } + } + + //关联观看日志 + public function union_user(){ + $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_viewlog_model'); + $size = 30; + $t1 = 'lc_market_sylive_viewlog'; + $t2 = 'lc_live_polyv_viewlog'; + $t3 = 'lc_market_sylive_activity'; + $where = [ + "$t2.id>" => 0, + "$t2.id is null" => null + ]; + $fileds = "{$t2}.*,{$t3}.activityId"; + $rows = $this->db->select($fileds)->from("$t3") + ->join("$t2", "{$t2}.channelId={$t3}.activityId", 'left') + ->join("$t1", "{$t1}.vlog_id={$t2}.id", 'left') + ->where($where)->order_by("{$t2}.id asc")->limit($size, 0) + ->get()->result_array(); + if (!$rows) { + echo "不存在直播日志数据"; + }else{ + foreach ($rows as $key => $value) { + $ac_user = $p_user = ''; + $addData = [ + 'vlog_id' => $value['id'], + 'a_id' => $value['activityId'], + 'playId' => $value['playId'], + 'playDuration' => $value['playDuration'], + 'stayDuration' => $value['stayDuration'], + 'c_time' => time() + ]; + $user = $this->user_model->get(['unionid'=>$value['param1']]); + $user && $ac_user = $this->act_user_model->get(['activityId'=>$value['activityId'],'userId'=>$user['userId']]); + if($ac_user['channelId']){ + $p_user = $this->user_model->get(['userId'=>$ac_user['channelId']]); + } + if($p_user['teamId']){ + $addData['type'] = 1; + $team_lists = $this->sylive_entity->get_team_lists($p_user['teamId']); + $area_id = $team_lists[0]['teamId']; //大团长id + $biz_id = $team_lists[1]['teamId']; //团长id + } + if($p_user['organizationId']){ + $addData['type'] = 0; + $team_lists = $this->sylive_entity->get_level_lists($p_user['organizationId']); + $area_id = $team_lists[0]['teamId']; //大团长id + $biz_id = $team_lists[1]['teamId']; //团长id + } + $area_id && $addData['area_id'] = $area_id; + $biz_id && $addData['biz_id'] = $biz_id; + $user && $addData['userId'] = $user['userId']; + $this->market_sylive_viewlog_model->add($addData); + } + } } } \ No newline at end of file diff --git a/common/libraries/market/Sylive_entity.php b/common/libraries/market/Sylive_entity.php index 57b9246e..001698ed 100644 --- a/common/libraries/market/Sylive_entity.php +++ b/common/libraries/market/Sylive_entity.php @@ -15,10 +15,13 @@ class Sylive_entity{ $this->ci->load->model('market/market_sylive_user_model', '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'); } /** @@ -88,7 +91,6 @@ class Sylive_entity{ * @return int */ public function get_level_lists($organizationId,$data=[]){ - $this->ci->load->model('market/market_sylive_organization_model'); $row = $this->ci->market_sylive_organization_model->get(['organizationId'=>$organizationId],'organizationId,parentId,organizationName'); if(!$row){ return $data; @@ -112,10 +114,16 @@ class Sylive_entity{ public function kpi_log($params) { if(!$params['cf_uid']){ - $group_id = $this->get_level($params['uid']); - if($group_id<4){ - $params['cf_uid'] = $params['uid']; + $u_row = $this->user_model->get(['userId'=>$params['uid']]); + if($params['teamId']){ + $t_level_id = $this->get_team_level($u_row['teamId']); + $params['cf_uid'] = $t_level_id<3 ? $params['uid'] : 0; } + if($params['organizationId']){ + $group_id = $this->get_level($u_row['organizationId']); + $params['cf_uid'] = $group_id<4 ? $params['uid'] : 0; + } + } if ($params['a_id'] && $params['uid'] && $params['cf_uid']) { $user = $this->user_model->get(['userId'=>$params['cf_uid']]); @@ -129,16 +137,25 @@ class Sylive_entity{ return array('code' => 0, 'msg' => '无活动或未在活动时间内'); } } - $re_kpi = $this->ci->mdSytActivityKpiData->get(array("a_id" => $params['a_id'], 'uid' => $params['uid'], 'kpi' => $params['kpi'])); + $type = $user['organizationId'] > 0 ? 0 : 1; //0门店 1团队 + $re_kpi = $this->ci->mdSytActivityKpiData->get(array("a_id" => $params['a_id'], 'uid' => $params['uid'], 'kpi' => $params['kpi'],'type'=>$type)); if ($re_kpi) {//已添加过活动kpi(访活动只记录一次用户kpi记录) return array('code' => 0, 'msg' => '已添加过' . $params['kpi'] . '记录'); } - $level_lists = $this->get_level_lists($user['organizationId']); - if($level_lists){ - //获取大区id - $area_id = $level_lists[1]['organizationId']; - //获取店铺id - $biz_id = $level_lists[2]['organizationId']; + if($type){ + $team_lists = $this->get_team_lists($user['teamId']); + if($team_lists) { + $area_id = $team_lists[0]['teamId']; //大团长id + $biz_id = $team_lists[1]['teamId']; //团长id + } + }else{ + $level_lists = $this->get_level_lists($user['organizationId']); + if($level_lists){ + //获取大区id + $area_id = $level_lists[1]['organizationId']; + //获取店铺id + $biz_id = $level_lists[2]['organizationId']; + } } //增加记录 $addData = [ @@ -146,6 +163,7 @@ class Sylive_entity{ 'uid' => $params['uid'], 'cf_uid' => $params['cf_uid'], 'kpi' => $params['kpi'], + 'type' => $type, 'c_time' => time() ]; $area_id && $addData['area_id'] = $area_id; @@ -156,11 +174,16 @@ class Sylive_entity{ if (!$id) { return array('code' => 0, 'msg' => '添加记录失败'); } - if($this->map_kpi_biz[$params['kpi']] && $biz_id){//更新门店统计数据 + if($this->map_kpi_biz[$params['kpi']] && $biz_id && !$addData['type']){//更新门店统计数据 $up_key = $this->map_kpi_biz[$params['kpi']]; - $update[$up_key] = $this->ci->mdSytActivityKpiData->count(['a_id'=>$params['a_id'],'biz_id'=>$biz_id,'kpi'=>$params['kpi']]); + $update[$up_key] = $this->ci->mdSytActivityKpiData->count(['a_id'=>$params['a_id'],'biz_id'=>$biz_id,'kpi'=>$params['kpi'],'type'=>0]); $this->ci->mdSytActivityBiz->update($update,['activityId'=>$params['a_id'],'bizId'=>$biz_id]); } + if($this->map_kpi_biz[$params['kpi']] && $biz_id && $addData['type']) {//更新团队统计数据 + $up_key = $this->map_kpi_biz[$params['kpi']]; + $update[$up_key] = $this->ci->mdSytActivityKpiData->count(['a_id'=>$params['a_id'],'biz_id'=>$biz_id,'kpi'=>$params['kpi'],'type'=>1]); + $this->ci->mdSytActivityTeam->update($update,['activityId'=>$params['a_id'],'teamId2'=>$biz_id]); + } return array('code' => 1, 'msg' => '添加记录成功'); } else { return array('code' => 0, 'msg' => '参数错误'); @@ -177,7 +200,7 @@ class Sylive_entity{ $total = $this->ci->mdSytActivityBiz->count($where); $field = $this->map_kpi_biz[$type]; if($total && $field){ - $rows = $this->ci->mdSytActivityBiz->select($where,"{$field} desc",$page,$size); + $rows = $this->ci->mdSytActivityBiz->select($where,"{$field} desc,id desc",$page,$size); $biz_ids = implode(',',array_column($rows,'bizId')); $org_rows = []; if($biz_ids){ @@ -222,7 +245,8 @@ class Sylive_entity{ $where = [ 'a_id' => $aid, 'kpi' => $type, - 'biz_id' => $biz_id + 'biz_id' => $biz_id, + 'type' => 0, ]; $t_rows = $this->ci->mdSytActivityKpiData->select_groupby('cf_uid',$where,'total desc',$page,$size,'cf_uid,count(id) as total'); $map = []; @@ -323,6 +347,218 @@ class Sylive_entity{ return $data; } + /** + * @param $teamId 团队id + * @param $level 0大团长 1团长 2团员 3普通用户 + * @return int|mixed + */ + public function get_team_level($teamId,$level=0){ + if(!$teamId){ + return 3; + } + $row = $this->ci->market_sylive_team_model->get(['teamId'=>$teamId],'teamId,parentId'); + if(!$row){ + return 3; + } + if($row['parentId']){ + $temp = $level+1; + return $this->get_team_level($row['parentId'],$temp); + } + return $level; + } + + /** + * 获取等级数据 + * @param $teamId 团队id + * @param $data + * @return int + */ + public function get_team_lists($teamId,$data=[]){ + $row = $this->ci->market_sylive_team_model->get(['teamId'=>$teamId],'teamId,parentId,teamName'); + if(!$row){ + return $data; + }else{ + array_unshift($data,$row); + if($row['parentId']){ + return $this->get_team_lists($row['parentId'],$data); + }else{ + return $data; + } + } + } + + /** + * 判断团长活动是否有权限 + * @param $organizationId + * @param $level + * @param $a_id + * @return int + */ + public function team_act_role($organizationId,$level,$a_id){ + $where['activityId'] = $a_id; + if($level==2){ //团员 + $where["teamId2 in (select parentId from lc_market_sylive_team where teamId={$organizationId} and status=0)"] = null; + }elseif($level==1){ //团长 + $where['teamId2'] = $organizationId; + }else{ //大团长 + $where["teamId1"] = $organizationId; + } + $act = $this->ci->mdSytActivityTeam->get($where,'activityId'); + return $act ? true : false; + } + + //团队排行数据 + public function top_team_lists($aid,$type='browse',$page=1,$size=10,$teamId=0){ + $lists = []; + $where = [ + 'activityId' => $aid, + 'status' => 0 + ]; + $total = $this->ci->mdSytActivityTeam->count($where); + $field = $this->map_kpi_biz[$type]; + if($total && $field){ + $rows = $this->ci->mdSytActivityTeam->select($where,"{$field} desc,id desc",$page,$size); + $team_ids = implode(',',array_column($rows,'teamId2')); + $org_rows = []; + if($team_ids){ + $org_rows = $this->ci->market_sylive_team_model->map('teamId','teamName',["teamId in ($team_ids)"],'','','','teamId,teamName'); + } + $start = $page>1 ? ($page-1)*$size : 0; + foreach ($rows as $key=>$val) { + $lists[] = [ + 'ranking' => $start+$key+1, + 'name' => $org_rows[$val['teamId2']] ? $org_rows[$val['teamId2']] : '', + 'num' => $val[$this->map_kpi_biz[$type]].'人', + 'tip' => $teamId==$val['teamId2'] ? '我的团队' : '', + ]; + } + } + $data = [ + 'total' => $total, + 'lists' => $lists + ]; + return $data; + } + + //团队用户排行数据 + public function top_team_user($aid,$teamId,$uid,$type='browse',$page=1,$size=50){ + $where = [ + 'parentId' => $teamId + ]; + $orgs = $this->ci->market_sylive_team_model->select($where,'',0,0,'teamId'); + $org_ids = 0; + if($orgs){ + $org_arr_ids = array_column($orgs,'teamId'); + $org_arr_ids[] = $teamId; + $org_ids = implode($org_arr_ids,','); + } + $where = [ + "teamId>" => 0, + "teamId in ({$org_ids})" => null + ]; + $total = $this->ci->user_model->count($where); + $lists = []; + if($total){ + $rows = $this->ci->user_model->select($where,'userId desc',$page,$size,'userId,uname,nickname,headimg'); + $where = [ + 'a_id' => $aid, + 'kpi' => $type, + 'biz_id' => $teamId, + 'type' => 1, + ]; + $t_rows = $this->ci->mdSytActivityKpiData->select_groupby('cf_uid',$where,'total desc',$page,$size,'cf_uid,count(id) as total'); + $map = []; + if($t_rows){ + foreach($t_rows as $item) { + $map[$item['cf_uid']] = null !== $item['total'] ? $item['total'] : $item; + } + } + foreach ($rows as $item) { + $total = $map[$item['userId']] ? $map[$item['userId']] : '0'; + $lists[] = [ + 'uid' => $item['userId'], + 'name' => $item['uname'] ? $item['uname'] : $item['nickname'], + 'headimg' => $item['headimg'] ? $item['headimg'] : self::DEFAULT_HEAD, + 'total' => $total, + 'num' => "{$total}人", + 'tip' => $uid == $item['userId'] ? '本人' : '', + ]; + } + $edit = array_column($lists,'total'); + array_multisort($edit,SORT_DESC,$lists); + } + $data = [ + 'total' => $total, + 'lists' => $lists + ]; + return $data; + } + + //用户用户观看次数排行 + public function top_team_view_num($where,$page=1,$size=10){ + $total = $this->ci->market_sylive_viewlog_model->count($where); + $lists = []; + if($total){ + $rows = $this->ci->market_sylive_viewlog_model->select_groupby('userId',$where,'total desc',$page,$size,'userId,count(id) as total'); + $uids = implode(",",array_unique(array_column($rows,'userId'))); + $users = []; + if($uids){ + $where = [ + "userId in ('$uids')" => null, + ]; + $users = $this->ci->user_model->map('userId','',$where,'','','','userId,unionid,uname,nickname,headimg'); + } + foreach ($rows as $item) { + $user = $users[$item['userId']] ? $users[$item['userId']][0] : []; + $total = $item['total']; + $lists[] = [ + 'uid' => $user['userId'], + 'name' => $user['nickname'] ? $user['nickname'] : '', + 'headimg' => $user['headimg'] ? $user['headimg'] : self::DEFAULT_HEAD, + 'total' => $total, + 'num' => "{$total}次", + ]; + } + } + $data = [ + 'total' => $total, + 'lists' => $lists + ]; + return $data; + } + + //用户用户观看时长排行 + public function top_team_view_time($where,$page=1,$size=10){ + $total = $this->ci->market_sylive_viewlog_model->count($where); + $lists = []; + if($total){ + $rows = $this->ci->market_sylive_viewlog_model->select_groupby('userId',$where,'total desc',$page,$size,'userId,sum(playDuration) as total'); + $uids = implode(",",array_unique(array_column($rows,'userId'))); + $users = []; + if($uids){ + $where = [ + "userId in ('$uids')" => null, + ]; + $users = $this->ci->user_model->map('userId','',$where,'','','','userId,unionid,uname,nickname,headimg'); + } + foreach ($rows as $item) { + $user = $users[$item['userId']] ? $users[$item['userId']][0] : []; + $total = $item['total']; + $lists[] = [ + 'uid' => $user['userId'], + 'name' => $user['nickname'] ? $user['nickname'] : '', + 'headimg' => $user['headimg'] ? $user['headimg'] : self::DEFAULT_HEAD, + 'total' => $total, + 'num' => "{$total}秒", + ]; + } + } + $data = [ + 'total' => $total, + 'lists' => $lists + ]; + return $data; + } public function __get($name) { if ('_model' === substr($name, -6)) { diff --git a/common/models/market/Market_sylive_viewlog_model.php b/common/models/market/Market_sylive_viewlog_model.php new file mode 100644 index 00000000..be0396f9 --- /dev/null +++ b/common/models/market/Market_sylive_viewlog_model.php @@ -0,0 +1,13 @@ +table_name, 'default'); + } + +} \ No newline at end of file diff --git a/home/controllers/h5/market/sylive/Act.php b/home/controllers/h5/market/sylive/Act.php index 725dbbd5..68c3a137 100644 --- a/home/controllers/h5/market/sylive/Act.php +++ b/home/controllers/h5/market/sylive/Act.php @@ -5,7 +5,8 @@ require_once COMMPATH . 'third_party/phpqrcode/phpqrcode.php'; class Act extends Wx { - private $group_id; + private $group_id = 4; + private $teamLevel = 3; private $secretkey = '7a23vx9257'; private $item_banner = ['https://qs.haodian.cn/web/images/project/H5-ShiYu/goods.jpg']; private $template_id = 'DO0B9IYYub1d0oNvy9czzGbe6_1EU8PQmnLEoDOcmXA'; @@ -23,9 +24,18 @@ class Act extends Wx { $skey = $this->input->get('skey'); $param = $this->myencryption->base64url_decode($skey); $a_id = intval($param['a_id']);//活动id - $this->group_id = $this->sylive_entity->get_level($this->session['org_id']); - if($this->group_id<4 && $a_id && !$this->sylive_entity->act_role($this->session['org_id'],$this->group_id,$a_id)){ - $this->group_id = 4; + if($this->session['org_id']){ + $this->group_id = $this->sylive_entity->get_level($this->session['org_id']); + var_dump($this->group_id); + if($this->group_id<4 && $a_id && !$this->sylive_entity->act_role($this->session['org_id'],$this->group_id,$a_id)){ + $this->group_id = 4; + } + } + if($this->session['teamId']){ //团长 + $this->teamLevel = $this->sylive_entity->get_team_level($this->session['teamId']); + if($this->teamLevel<3 && $a_id && !$this->sylive_entity->team_act_role($this->session['teamId'],$this->teamLevel,$a_id)){ + $this->teamLevel = 3; + } } } @@ -51,8 +61,12 @@ class Act extends Wx { $act_user = $this->act_user_model->get(['userId'=>$this->uid,'activityId'=>$a_id]); //一次性订阅 $re_s = $this->mdSytSubscribemsg->get(array('a_id' => $a_id, 'uid' => $this->uid)); + $is_show_code = false; //是否显示二维码 if ($re_s) { $subscribemsg = '已订阅直播'; + $p_user = []; + $act_user['channelId'] && $p_user = $this->user_model->get(['userId'=>$act_user['channelId']]); + $p_user['teamId'] && $is_show_code = true; } else { if(!$user['nickname'] && !$user['headimg']){ $subscribemsg = http_host_com('home')."/h5/market/sylive/act/userinfo?skey={$skey}&type=sub"; @@ -83,6 +97,10 @@ class Act extends Wx { $info['org_id'] = $this->session['org_id']; $info['subscribemsg'] = $subscribemsg; $info['statisticsurl'] = $info['shareurl'] = $info['code'] = ''; + if($this->teamLevel<3){ + $info['shareurl'] = '/h5/market/sylive/act/share?skey='.$info['skey']; + $info['statisticsurl'] = '/h5/market/sylive/tstic?skey='.$info['skey']; + } if($this->group_id<4){ $info['shareurl'] = '/h5/market/sylive/act/share?skey='.$info['skey']; $info['statisticsurl'] = '/h5/market/sylive/stic?skey='.$info['skey']; @@ -102,6 +120,7 @@ class Act extends Wx { //微信分享 $wx_info = $this->share_info($row); $info['is_pay'] = $is_pay ? 1 : 0; + $info['show_code'] = $is_show_code ? 1 : 0; $this->data['info'] = $info; $this->data['sign_package'] = $wx_info['sign_package']; $this->data['share'] = $wx_info['share']; @@ -284,6 +303,7 @@ class Act extends Wx { 'price' => $item['price'] ? $item['price'] : '', 'content' => $item['introduction'] ? $item['introduction'] : '', 'banner' => $banner, + 'stock' => $row['stock'], 'skey' => $skey, 'validity' => $validity, 'introTitle' => '权益说明', @@ -324,6 +344,7 @@ class Act extends Wx { } $unpay = $this->market_sylive_order_model->get(['item_id'=>$a_id,'status'=>0,'uid'=>$this->uid,'expire_time>'=>time()]); if(!$unpay){ + $this->market_sylive_order_model->db->trans_begin(); $this->load->helper('order'); $unpay = [ 'sid' => create_order_no('350200','market'), @@ -336,10 +357,22 @@ class Act extends Wx { ]; $name && $unpay['uname'] = $name; $mobile && $unpay['mobile'] = $mobile; + $act_user = $this->act_user_model->get(['userId'=>$this->uid,'activityId'=>$a_id]); + $p_user = []; + $act_user['channelId'] && $p_user = $this->user_model->get(['userId'=>$act_user['channelId']]); + $p_user['teamId'] && $unpay['cfrom'] = 1; $oid = $this->market_sylive_order_model->add($unpay); if(!is_numeric($oid)){ + $this->market_sylive_order_model->db->trans_rollback(); $this->show_json('',400,'创建订单失败'); } + $this->market_sylive_activity_model->update(['stock = stock-1' =>null],['activityId'=>$a_id]); + $res = $this->market_sylive_activity_model->db->affected_rows(); + if(!$res){ + $this->market_sylive_order_model->db->trans_rollback(); + $this->show_json('',400,'已售罄'); + } + $this->market_sylive_order_model->db->trans_commit(); } $user = $this->user_model->get(['userId'=>$this->uid]); $notify_url = http_host_com('home').'/h5/market/sylive/notify'; diff --git a/home/controllers/h5/market/sylive/Biz.php b/home/controllers/h5/market/sylive/Biz.php index 64372c0c..5427c531 100644 --- a/home/controllers/h5/market/sylive/Biz.php +++ b/home/controllers/h5/market/sylive/Biz.php @@ -106,7 +106,8 @@ class Biz extends Admin { $count_live = $this->market_sylive_activity_model->count($where); $where = [ 'kpi' => 'order', - "area_id" => $area_id + "area_id" => $area_id, + 'type' => 0 ]; $count_order = $this->mdSytActivityKpiData->count($where); $count = [ @@ -134,6 +135,7 @@ class Biz extends Admin { ]; $count_live = $this->market_sylive_activity_model->count($where); $where = [ + 'type' => 0, 'kpi' => 'order', " area_id in (select organizationId from lc_market_sylive_organization where parentId={$this->session['org_id']} and status=0)" => null ]; diff --git a/home/controllers/h5/market/sylive/Common.php b/home/controllers/h5/market/sylive/Common.php index 4d874a24..ba7ed3d8 100644 --- a/home/controllers/h5/market/sylive/Common.php +++ b/home/controllers/h5/market/sylive/Common.php @@ -174,7 +174,7 @@ class Admin extends Common{ if(!in_array($method,$this->white_login_method) && !$this->uid){ $ret = $this->set_auth(); $openid = $ret['openid']; - $row_wechat = $this->user_model->get(['openid' => $openid,'organizationId>'=>0,'status>='=>0]); + $row_wechat = $this->user_model->get(['openid' => $openid,'(organizationId>0 or teamId>0)'=>null,'status>='=>0]); if(!$row_wechat){ $_SESSION[self::WX_SESSION] = $ret; header('Location:/h5/market/sylive/login');exit; @@ -183,9 +183,9 @@ class Admin extends Common{ throw new Hd_exception('该账户禁用', 400); } $this->uid = $row_wechat['userId']; - $this->session = $_SESSION[self::SESSION_KEY] = ['uid' => $this->uid,'org_id'=>$row_wechat['organizationId']]; + $this->session = $_SESSION[self::SESSION_KEY] = ['uid' => $this->uid,'org_id'=>$row_wechat['organizationId'],'teamId'=>$row_wechat['teamId']]; } - if(!$this->session['org_id']){ + if(!$this->session['org_id'] && !$this->session['teamId']){ header('Location:/h5/market/sylive/login');exit; } return $this->$method(); @@ -222,7 +222,7 @@ class Wx extends Common{ $ret['headimgurl'] && $add['headimg'] = strval($ret['headimgurl']); $ret['unionid'] && $add['unionid'] = $ret['unionid']; $this->uid = $this->user_model->add($add); - $row_wechat['organizationId'] = 0; + $row_wechat['teamId'] = $row_wechat['organizationId'] = 0; if (!$this->uid) { debug_log("[error]# " . $this->mdWeixinUsers->db->last_query(), __FUNCTION__, $this->log_dir); } @@ -239,17 +239,18 @@ class Wx extends Common{ "createTime" => date('Y-m-d H:i:s') ]; if($param['cf_uid']){ - $p_user = $this->user_model->get(['userId'=>$param['cf_uid']],'userId,organizationId'); + $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'); $p_act_user['channelId'] && $act_data['channelId'] = $p_act_user['channelId']; - if(!$p_user['channelId'] && $p_user['organizationId']>0){ + if(!$p_user['channelId'] && ($p_user['organizationId']>0||$p_user['teamId']>0)){ $act_data['channelId'] = $p_user['userId']; } $act_data['pid'] = $p_user['userId']; } $this->act_user_model->add($act_data); } - $this->session = $_SESSION[self::SESSION_KEY] = ['uid' => $this->uid,'org_id'=>$row_wechat['organizationId']]; + $_SESSION[self::SESSION_KEY] = ['uid' => $this->uid,'org_id'=>$row_wechat['organizationId'],'teamId'=>$row_wechat['teamId']]; + echo ("");exit; } return $this->$method(); } catch(Hd_exception $e){//处理异常 diff --git a/home/controllers/h5/market/sylive/Login.php b/home/controllers/h5/market/sylive/Login.php index c8f47669..9eae3e31 100644 --- a/home/controllers/h5/market/sylive/Login.php +++ b/home/controllers/h5/market/sylive/Login.php @@ -4,6 +4,7 @@ class Login extends CI_Controller{ const WX_SESSION = "market_wx_info"; protected $secret = "market_sylive_h5"; + protected $log_dir = 'market/sylive'; public function __construct(){ parent::__construct(); @@ -21,11 +22,11 @@ class Login extends CI_Controller{ if(!$code || $code!=$redis->get($key)){ $this->show_json('',400,'请输入正确的验证码'); } - $user=$this->user_model->get(array('mobile' => $mobile,'organizationId>'=>0)); + $user=$this->user_model->get(array('mobile' => $mobile,'(organizationId>0 or teamId>0)'=> null)); if($user['status']){ $this->show_json('',400,'用户已禁用'); } - $_SESSION['market_sylive_session'] = ['uid' => $user['userId'],'org_id'=>$user['organizationId']]; + $_SESSION['market_sylive_session'] = ['uid' => $user['userId'],'org_id'=>$user['organizationId'],'teamId'=>$user['teamId']]; $this->show_json('',200,'登录成功'); }else{ $wx_info = $_SESSION[self::WX_SESSION]; @@ -49,7 +50,7 @@ class Login extends CI_Controller{ if($user['openid']){ return ['code' => 0,'msg' => '该用户已绑定公众号']; } - $is_bind = $this->user_model->count(['openid'=>$wx_info['openid'],'organizationId>'=>0,'status>='=>0]); //是否绑定 + $is_bind = $this->user_model->count(['openid'=>$wx_info['openid'],'(organizationId>0 or teamId>0)'=>null,'status>='=>0]); //是否绑定 if($is_bind){ return ['code' => 0,'msg' => '该公众号已存在绑定账号']; } @@ -61,7 +62,7 @@ class Login extends CI_Controller{ $wx_info['unionid'] && $update['unionid'] = $wx_info['unionid']; $this->user_model->update($update,['userId'=>$user['userId']]); //删除普通账户 - $this->user_model->update(['status'=>-1],['openid'=>$wx_info['openid'],'organizationId'=>0,'status>='=>0]); + $this->user_model->update(['status'=>-1],['openid'=>$wx_info['openid'],'status>='=>0,'organizationId'=>0,'teamId'=>0]); return ['code' => 1,'msg' => '绑定成功']; } //获取验证码 @@ -70,7 +71,7 @@ class Login extends CI_Controller{ if(!mobile_valid($mobile)){ $this->show_json('',400,'请输入正确的手机号码'); } - $user=$this->user_model->get(array('mobile' => $mobile, 'status' => 0,'organizationId>'=>0)); + $user=$this->user_model->get(array('mobile' => $mobile, 'status' => 0,'(organizationId>0 or teamId>0)'=>null)); if(!$user){ $this->show_json('',400,'用户不存在'); } diff --git a/home/controllers/h5/market/sylive/Stic.php b/home/controllers/h5/market/sylive/Stic.php index 9c9ce2d1..064d42e0 100644 --- a/home/controllers/h5/market/sylive/Stic.php +++ b/home/controllers/h5/market/sylive/Stic.php @@ -34,15 +34,15 @@ class Stic extends Admin{ $this->data['sign_package'] = $wx_info['sign_package']; $this->data['share'] = $wx_info['share']; if($this->group_id==3){ //顾问 - $browse_count = $this->mdSytActivityKpiData->count(['a_id'=>$a_id,'kpi'=>'browse','cf_uid'=>$this->uid]); - $subscribe_count = $this->mdSytActivityKpiData->count(['a_id'=>$a_id,'kpi'=>'subscribe','cf_uid'=>$this->uid]); + $browse_count = $this->mdSytActivityKpiData->count(['a_id'=>$a_id,'kpi'=>'browse','cf_uid'=>$this->uid,'type'=>0]); + $subscribe_count = $this->mdSytActivityKpiData->count(['a_id'=>$a_id,'kpi'=>'subscribe','cf_uid'=>$this->uid,'type'=>0]); $info['begin'] = [ ['title' => '访问用户', 'num' => "{$browse_count}人",'url'=>'/h5/market/sylive/stic/users?type=owner&kpi=browse&a_id='.$a_id], ['title' => '预约用户', 'num' => "{$subscribe_count}人",'url'=>'/h5/market/sylive/stic/users?type=owner&kpi=subscribe&a_id='.$a_id], ['title' => '预约率', 'num' => $browse_count ? round($subscribe_count/$browse_count*100,2)."%" : 0], ]; - $watch_count = $this->mdSytActivityKpiData->count(['a_id'=>$a_id,'kpi'=>'watch','cf_uid'=>$this->uid]); - $order_count = $this->mdSytActivityKpiData->count(['a_id'=>$a_id,'kpi'=>'order','cf_uid'=>$this->uid]); + $watch_count = $this->mdSytActivityKpiData->count(['a_id'=>$a_id,'kpi'=>'watch','cf_uid'=>$this->uid,'type'=>0]); + $order_count = $this->mdSytActivityKpiData->count(['a_id'=>$a_id,'kpi'=>'order','cf_uid'=>$this->uid,'type'=>0]); $info['live'] = [ ['title' => '观看用户', 'num' => "{$watch_count}人",'url' => '/h5/market/sylive/stic/users?type=owner&kpi=watch&a_id='.$a_id], ['title' => '下单用户', 'num' => "{$order_count}人",'url' => '/h5/market/sylive/stic/users?type=owner&kpi=order&a_id='.$a_id], @@ -67,6 +67,7 @@ class Stic extends Admin{ $cell3 = $cell2 = []; if($this->group_id<2){ //所有大区 $where = [ + 'type' => 0, 'a_id' => $a_id, 'kpi' => 'browse', ]; @@ -99,7 +100,8 @@ class Stic extends Admin{ $where = [ 'a_id' => $a_id, 'kpi' => 'browse', - 'cf_uid' => $this->uid + 'cf_uid' => $this->uid, + 'type' => 0 ]; $owner_browse_count = $this->mdSytActivityKpiData->count($where); //浏览数据 $where['kpi'] = 'subscribe'; @@ -113,7 +115,8 @@ class Stic extends Admin{ $where = [ 'a_id' => $a_id, 'kpi' => 'browse', - 'biz_id' => $this->session['org_id'] + 'biz_id' => $this->session['org_id'], + 'type' => 0 ]; $browse_count = $this->mdSytActivityKpiData->count($where); //浏览数据 $where['kpi'] = 'subscribe'; @@ -167,6 +170,7 @@ class Stic extends Admin{ $view_num = $view_time = []; if($this->group_id<2){ //所有大区 $where = [ + 'type' => 0, 'a_id' => $a_id, 'kpi' => 'watch', ]; @@ -197,6 +201,7 @@ class Stic extends Admin{ ['title' => '参与人数', 'num' => "{$gw_count}人"], ]; $where = [ + 'type' => 0, 'a_id' => $a_id, 'kpi' => 'watch', 'cf_uid' => $this->uid @@ -211,6 +216,7 @@ class Stic extends Admin{ ]; }else{ //门店 $where = [ + 'type' => 0, 'a_id' => $a_id, 'kpi' => 'watch', 'biz_id' => $this->session['org_id'] @@ -332,7 +338,8 @@ class Stic extends Admin{ $where = [ 'a_id'=>$a_id, // 'kpi'=>'watch', - 'cf_uid'=>$this->uid + 'cf_uid'=>$this->uid, + 'type' => 0, ]; if($type==1){ //预热 $where['c_time<='] = strtotime($row['timeStart']); @@ -443,6 +450,7 @@ class Stic extends Admin{ } $page = $params['page'] ? intval($params['page']) : 1; $where = [ + 'type' => 0, 'a_id' => $params['a_id'], 'kpi' => $params['kpi'], ]; diff --git a/home/controllers/h5/market/sylive/Team.php b/home/controllers/h5/market/sylive/Team.php new file mode 100644 index 00000000..63325e67 --- /dev/null +++ b/home/controllers/h5/market/sylive/Team.php @@ -0,0 +1,152 @@ +load->model('market/market_sylive_activity_model'); + $this->load->model('market/market_sylive_team_model'); + $this->load->library('market/sylive_entity'); + $this->load->library('MyEncryption'); + $this->teamLevel = $this->sylive_entity->get_team_level($this->session['teamId']); + } + + public function index(){ + if($this->teamLevel>0){ + throw new Hd_exception('权限不足',400); + } + $row = $this->market_sylive_team_model->get(['teamId'=>$this->session['teamId']]); + $info['nickname'] = $row['teamName']; + $info['headimg'] = $this->liche_img; + $info['tab'] = [ + ['id'=>1,'title'=>'团队'], + ['id'=>2,'title'=>'活动'], + ]; + $this->data['info'] = $info; + //微信分享 + $wx_info = $this->share_info(); + $this->data['sign_package'] = $wx_info['sign_package']; + $this->show_view('h5/market/sylive/team/index'); + } + //活动列表 + public function lists(){ + if($this->teamLevel==1){ + $team_id = $this->session['teamId']; + }elseif($this->teamLevel==2) { + $biz_row = $this->market_sylive_team_model->get(['teamId'=>$this->session['teamId']]); + $team_id = $biz_row['parentId']; + }else{ + $team_id = $this->input->get('team_id'); + } + $row = $this->market_sylive_team_model->get(['teamId'=>$team_id]); + $this->data['headimg'] = $this->liche_img; + $this->data['biz_name'] = $row['teamName']; + $this->data['team_id'] = $this->input->get('team_id'); + $this->data['teamLevel'] = $this->teamLevel; + //微信分享 + $wx_info = $this->share_info(); + $this->data['sign_package'] = $wx_info['sign_package']; + $this->show_view('h5/market/sylive/team/lists'); + } + //团队列表 + public function team_list(){ + $page = $this->input->get('page'); + !$page && $page = 1; + $size = 20; + $where = [ + 'status' => 0, + 'parentId' => $this->session['teamId'], + ]; + $total = $this->market_sylive_team_model->count($where); + $lists = []; + if($total){ + $rows = $this->market_sylive_team_model->select($where,'sortNumber asc,teamId desc',$page,$size); + foreach ($rows as $val) { + $where = [ + 'status' => 0, + "activityId in (select activityId from lc_market_sylive_activity_team where teamId2={$val['teamId']})" => null + ]; + $activitynum = $this->market_sylive_activity_model->count($where); + $where = [ + 'status' => 0, + "teamId in (select teamId from lc_market_sylive_team where parentId={$val['teamId']})" => null + ]; + $storenum = $this->user_model->count($where);//团员 + $temp = [ + 'title' => $val['teamName'], + 'storenum' => $storenum, + 'activitynum' => $activitynum, + 'url' => '/h5/market/sylive/team/lists?team_id='.$val['teamId'], + 'state' => [], + ]; + $lists[] = $temp; + } + } + $data['list'] = $lists; + $data['total'] = $total; + $this->show_json($data,200); + } + + //活动列表 + public function act_list(){ + $team_id = $this->input->get('team_id'); + $page = $this->input->get('page'); + !$page && $page = 1; + $size = 20; + $where = [ + 'status' => 0 + ]; + if($this->teamLevel==2){ //团员 + $where["activityId in (select activityId from lc_market_sylive_activity_team where + teamId2 in (select parentId from lc_market_sylive_team where teamId={$this->session['teamId']} and status=0) + )"] = null; + }elseif($this->teamLevel==1 || $team_id){ //团长 + $s_t_id = $team_id ? $team_id : $this->session['teamId']; + $where["activityId in (select activityId from lc_market_sylive_activity_team where + teamId2 in (select teamId from lc_market_sylive_team where teamId={$s_t_id} and status=0) + )"] = null; + }else{ //大团长 + $where["activityId in (select activityId from lc_market_sylive_activity_team where + teamId1 in (select teamId from lc_market_sylive_team where teamId={$this->session['teamId']} and status=0) + )"] = null; + } +// $where = ['status'=>0]; + $total = $this->market_sylive_activity_model->count($where); + $lists = []; + if($total){ + $rows = $this->market_sylive_activity_model->select($where,'timeStart desc',$page,$size,'activityId,title,timeStart,timeEnd'); + foreach ($rows as $val) { + $s_time = strtotime($val['timeStart']); + $e_time = strtotime($val['timeEnd']); + $n_time = time(); + if($n_time>=$s_time&&$n_time<=$e_time){ + $state = ['title'=>'活动进行中','class'=>'bg-fe9538']; + }elseif($n_time<$s_time){ + $state = ['title'=>'活动预热中','class'=>'bg-ff5a5a']; + }else{ + $state = ['title'=>'活动已结束','class'=>'bg-fccba0']; + } + $skey = $this->myencryption->base64url_encode("a_id=" . $val['activityId']); + $url = '/h5/market/sylive/act?skey='.$skey; + $stat_url = '/h5/market/sylive/tstic?skey='.$skey; + + $temp = [ + 'title' => $val['title'], + 'time' => date('m-d H:i',$s_time).'~'.date('m-d H:i',$e_time), + 'url' => $url, + 'stat_url' => $stat_url, + 'state' => $state, + ]; + $lists[] = $temp; + } + } + $data['list'] = $lists; + $data['total'] = $total; + $this->show_json($data,200); + } +} \ No newline at end of file diff --git a/home/controllers/h5/market/sylive/Tstic.php b/home/controllers/h5/market/sylive/Tstic.php new file mode 100644 index 00000000..caf1d799 --- /dev/null +++ b/home/controllers/h5/market/sylive/Tstic.php @@ -0,0 +1,524 @@ +load->model('market/market_sylive_organization_model'); + $this->load->model('market/market_sylive_activity_model'); + $this->load->model('market/market_sylive_activity_biz_model','mdSytActivityBiz'); + $this->load->model('market/market_sylive_activity_kpidata_model','mdSytActivityKpiData'); + $this->load->model('market/market_sylive_team_model'); + + $this->load->model('live/Live_polyv_session_model', 'mdPolyvSession'); + $this->load->library('market/sylive_entity'); + $this->teamLevel = $this->sylive_entity->get_team_level($this->session['teamId']); + $this->data['skey'] = $this->input->get('skey'); + } + //顾问 + public function index(){ + if($this->teamLevel>2){ + throw new Hd_exception('权限不足',400); + } + $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]); + if(!$row){ + throw new Hd_exception('参数错误',400); + } + $info['tab'] = time()>=strtotime($row['timeStart']) ? 2 : 1; + //微信分享 + $wx_info = $this->share_info($row); + $this->data['sign_package'] = $wx_info['sign_package']; + $this->data['share'] = $wx_info['share']; + if($this->teamLevel==2){ //团员 + $browse_count = $this->mdSytActivityKpiData->count(['a_id'=>$a_id,'kpi'=>'browse','cf_uid'=>$this->uid,'type'=>1]); + $subscribe_count = $this->mdSytActivityKpiData->count(['a_id'=>$a_id,'kpi'=>'subscribe','cf_uid'=>$this->uid,'type'=>1]); + $info['begin'] = [ + ['title' => '访问用户', 'num' => "{$browse_count}人",'url'=>'/h5/market/sylive/tstic/users?type=owner&kpi=browse&a_id='.$a_id], + ['title' => '预约用户', 'num' => "{$subscribe_count}人",'url'=>'/h5/market/sylive/tstic/users?type=owner&kpi=subscribe&a_id='.$a_id], + ['title' => '预约率', 'num' => $browse_count ? round($subscribe_count/$browse_count*100,2)."%" : 0], + ]; + $watch_count = $this->mdSytActivityKpiData->count(['a_id'=>$a_id,'kpi'=>'watch','cf_uid'=>$this->uid,'type'=>1]); + $order_count = $this->mdSytActivityKpiData->count(['a_id'=>$a_id,'kpi'=>'order','cf_uid'=>$this->uid,'type'=>1]); + $info['live'] = [ + ['title' => '观看用户', 'num' => "{$watch_count}人",'url' => '/h5/market/sylive/tstic/users?type=owner&kpi=watch&a_id='.$a_id], + ['title' => '下单用户', 'num' => "{$order_count}人",'url' => '/h5/market/sylive/tstic/users?type=owner&kpi=order&a_id='.$a_id], + ['title' => '转化率', 'num' => $watch_count ? round($order_count/$watch_count*100,2)."%" : 0], + ]; + $this->data['info'] = $info; + $this->show_view('h5/market/sylive/tstic/index'); + }else{ //团长和大团长 + $this->data['info'] = $info; + $this->show_view('h5/market/sylive/tstic/area'); + } + } + + public function lists_ready(){ + $skey = $this->input->get('skey'); + $param = $this->myencryption->base64url_decode($skey); + $a_id = intval($param['a_id']);//活动id + $row = $this->market_sylive_activity_model->get(['activityId'=>$a_id]); + if(!$row && $this->teamLevel>=3){ + $this->show_json([],200); + } + $cell3 = $cell2 = []; + if(!$this->teamLevel){ //大团长 + $where = [ + 'type' => 1, + 'a_id' => $a_id, + 'kpi' => 'browse', + 'area_id' => $this->session['teamId'] + ]; + $browse_count = $this->mdSytActivityKpiData->count($where); //浏览数据 + $where['kpi'] = 'subscribe'; + $subscribe_count = $this->mdSytActivityKpiData->count($where); //预约用户 +// $sql = "select count(distinct areaId) as total from lc_market_sylive_activity_biz where `activityId`={$a_id}"; +// $area_count = $this->mdSytActivityBiz->db->query($sql)->row_array(); +// $sql = "select count(distinct bizId) as total from lc_market_sylive_activity_biz where `activityId`={$a_id}"; +// $biz_count = $this->mdSytActivityBiz->db->query($sql)->row_array(); +// $where = [ +// 'status' => 0, +// "organizationId in (select organizationId from lc_market_sylive_organization where +// parentId in (select bizId from lc_market_sylive_activity_biz where activityId={$a_id} and status=0) +// )" => null +// ]; +// $gw_count = $this->user_model->count($where); //顾问 +// $cell2 = [ +// ['title' => '参与大区', 'num' => "{$area_count['total']}个"], +// ['title' => '参与门店', 'num' => "{$biz_count['total']}家"], +// ['title' => '参与人数', 'num' => "{$gw_count}人"], +// ]; + $where = [ + 'type' => 1, + 'a_id' => $a_id, + 'kpi' => 'browse', + 'biz_id' => $this->uid + ]; + $owner_browse_count = $this->mdSytActivityKpiData->count($where); //浏览数据 + $where['kpi'] = 'subscribe'; + $owner_subscribe_count = $this->mdSytActivityKpiData->count($where); //浏览数据 + $cell3 = [ + ['title' => '访问用户', 'num' => "{$owner_browse_count}人",'url'=>'/h5/market/sylive/tstic/users?type=owner&kpi=browse&a_id='.$a_id], + ['title' => '预约用户', 'num' => "{$owner_subscribe_count}人",'url'=>'/h5/market/sylive/tstic/users?type=owner&kpi=subscribe&a_id='.$a_id], + ['title' => '预约率', 'num' => $owner_browse_count ? round($owner_subscribe_count/$owner_browse_count*100,2)."%" : 0], + ]; + }else{ //团长 + $where = [ + 'type' => 1, + 'a_id' => $a_id, + 'kpi' => 'browse', + 'biz_id' => $this->session['teamId'], + ]; + $browse_count = $this->mdSytActivityKpiData->count($where); //浏览数据 + $where['kpi'] = 'subscribe'; + $subscribe_count = $this->mdSytActivityKpiData->count($where); //浏览数据 + } + $cell1 = [ + ['title' => '访问用户', 'num' => "{$browse_count}人",'url'=>'/h5/market/sylive/tstic/users?type=all&kpi=browse&a_id='.$a_id], + ['title' => '预约用户', 'num' => "{$subscribe_count}人",'url'=>'/h5/market/sylive/tstic/users?type=all&kpi=subscribe&a_id='.$a_id], + ['title' => '预约率', 'num' => $subscribe_count ? round($subscribe_count/$browse_count*100,2)."%" : 0], + ]; + if($this->teamLevel==1){ //团长 + $teamId = $this->session['teamId']; + }else{ //大团长 + $teamId = 0; + } + $browse_lists = $this->sylive_entity->top_team_lists($a_id,'browse',1,10,$teamId); + $browse = [ + 'title' => '团队浏览排行', + 'url' => '/h5/market/sylive/tstic/rank?type=browse&skey='.$skey, + 'list' => $browse_lists['lists'] + ]; + $book_lists = $this->sylive_entity->top_team_lists($a_id,'subscribe',1,10,$teamId); + $book = [ + 'title' => '团队预约排行', + 'url' => '/h5/market/sylive/tstic/rank?type=subscribe&skey='.$skey, + 'list' => $book_lists['lists'] + ]; + $data = [ + 'cell1' => $cell1, + 'cell2' => $cell2, + 'cell3' => $cell3, + 'browse' => $browse, + 'book' => $book + ]; + $this->show_json($data,200); + } + + //直播统计数据 + public function lists_live(){ + $skey = $this->input->get('skey'); + $param = $this->myencryption->base64url_decode($skey); + $a_id = intval($param['a_id']);//活动id + $row = $this->market_sylive_activity_model->get(['activityId'=>$a_id]); + if(!$row && $this->teamLevel>=3){ + $this->show_json([],200); + } + $cell4 = $cell3 = []; + $view_num = $view_time = []; + if(!$this->teamLevel){ //大团长 + $where = [ + 'type' => 1, + 'a_id' => $a_id, + 'kpi' => 'watch', + 'area_id' => $this->session['teamId'] + ]; + $view_count = $this->mdSytActivityKpiData->count($where); //浏览数据 + $where['kpi'] = 'order'; + $order_count = $this->mdSytActivityKpiData->count($where); //预约用户 +// $sql = "select count(distinct areaId) as total from lc_market_sylive_activity_biz where `activityId`={$a_id}"; +// $area_count = $this->mdSytActivityBiz->db->query($sql)->row_array(); +// $sql = "select count(distinct bizId) as total from lc_market_sylive_activity_biz where `activityId`={$a_id}"; +// $biz_count = $this->mdSytActivityBiz->db->query($sql)->row_array(); +// $where = [ +// 'status' => 0, +// "organizationId in (select organizationId from lc_market_sylive_organization where +// parentId in (select bizId from lc_market_sylive_activity_biz where activityId={$a_id} and status=0) +// )" => null +// ]; +// $gw_count = $this->user_model->count($where); //顾问 +// $cell3 = [ +// ['title' => '参与大区', 'num' => "{$area_count['total']}个"], +// ['title' => '参与门店', 'num' => "{$biz_count['total']}家"], +// ['title' => '参与人数', 'num' => "{$gw_count}人"], +// ]; + $where = [ + 'type' => 1, + 'a_id' => $a_id, + 'kpi' => 'watch', + 'cf_uid' => $this->uid + ]; + $owner_view_count = $this->mdSytActivityKpiData->count($where); //观看数据 + $where['kpi'] = 'order'; + $owner_order_count = $this->mdSytActivityKpiData->count($where); //下单数据 + $cell4 = [ + ['title' => '观看用户', 'num' => "{$owner_view_count}人",'url'=>'/h5/market/sylive/tstic/users?type=owner&kpi=watch&a_id='.$a_id], + ['title' => '下单用户', 'num' => "{$owner_order_count}人",'url'=>'/h5/market/sylive/tstic/users?type=owner&kpi=order&a_id='.$a_id], + ['title' => '转化率', 'num' => $owner_view_count ? round($owner_order_count/$owner_view_count*100,2)."%" : 0], + ]; + }else{ //团长 + $where = [ + 'type' => 1, + 'a_id' => $a_id, + 'kpi' => 'watch', + 'biz_id' => $this->session['teamId'], + ]; + $view_count = $this->mdSytActivityKpiData->count($where); //观看数据 + $where['kpi'] = 'order'; + $order_count = $this->mdSytActivityKpiData->count($where); //下单数据 + $where = [ + 'type' => 1, + 'a_id' => $a_id, + 'biz_id' => $this->session['teamId'], + ]; + $view_num_lists = $this->sylive_entity->top_team_view_num($where,1,10); + $view_num = [ + 'title' => '客户观看次数排行', + 'url' => '', + 'list' => $view_num_lists['lists'] + ]; + $view_time_lists = $this->sylive_entity->top_team_view_time($where,1,10); + $view_time = [ + 'title' => '客户观看时长排行', + 'url' => '', + 'list' => $view_time_lists['lists'] + ]; + } + $cell1 = [ + ['title' => '观看用户', 'num' => "{$view_count}人",'url'=>'/h5/market/sylive/tstic/users?type=all&kpi=watch&a_id='.$a_id], + ['title' => '下单用户', 'num' => "{$order_count}人",'url'=>'/h5/market/sylive/tstic/users?type=all&kpi=order&a_id='.$a_id], + ['title' => '转化率', 'num' => $view_count ? round($order_count/$view_count*100,2)."%" : 0], + ]; + $poly_row = $this->mdPolyvSession->get(['channelId'=>$row['channelId']]); + $duration = $poly_row['duration'] ? intval($poly_row['duration']/60) : "0"; + $livePV = $poly_row['livePV'] ? $poly_row['livePV'] : 0; + $avg_UV_time = $poly_row['liveUV'] ? intval($poly_row['totalPlayDuration']/$poly_row['liveUV']) : 0; + $cell2 = [ + ['title' => '直播时长', 'num' => "{$duration}分钟"], + ['title' => '人均观看', 'num' => "{$avg_UV_time}秒"], + ['title' => '观看次数', 'num' => "{$livePV}次"], + ]; + if($this->teamLevel==1){ //团长 + $teamId = $this->session['teamId']; + }else{ //大团长 + $teamId = 0; + } + $watch_lists = $this->sylive_entity->top_team_lists($a_id,'watch',1,10,$teamId); + $view = [ + 'title' => '团队观看排行', + 'url' => '/h5/market/sylive/tstic/rank?type=watch&skey='.$skey, + 'list' => $watch_lists['lists'] + ]; + $order_lists = $this->sylive_entity->top_team_lists($a_id,'order',1,10,$teamId); + $order = [ + 'title' => '团队订单排行', + 'url' => '/h5/market/sylive/tstic/rank?type=order&skey='.$skey, + 'list' => $order_lists['lists'] + ]; + $data = [ + 'cell1' => $cell1, + 'cell2' => $cell2, + 'cell3' => $cell3, + 'cell4' => $cell4, + 'view' => $view, + 'order' => $order, + 'view_num' => $view_num, + 'view_time' => $view_time, + ]; + $this->show_json($data,200); + } + + //排名列表 + public function rank(){ + $title_arr = [ + 'browse' => '团队浏览排行', + 'subscribe' => '团队预约排行', + 'watch' => '团队观看排行', + '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 + if($this->teamLevel==1){ //团长 + $teamId = $this->session['teamId']; + }else{ //大团长 + $teamId = 0; + } + $type = $params['type'] ? $params['type'] : 'browse'; + $data = $this->sylive_entity->top_team_lists($a_id,$type,$page,20,$teamId); + $data['title'] = $title_arr[$type]; + $this->show_json($data,200); + } + $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]); + if(!$row){ + throw new Hd_exception('参数错误',400); + } + $this->data['params'] = $params; + //微信分享 + $wx_info = $this->share_info($row); + $this->data['sign_package'] = $wx_info['sign_package']; + $this->data['share'] = $wx_info['share']; + $this->show_view('h5/market/sylive/tstic/rank'); + } + + public function event(){ + $map_kpi_name = [ + 'browse' => '浏览了活动页', 'subscribe' => '订阅了直播通知', 'order' => '直播间下单','watch' => '进入了直播间' + ]; + $skey = $this->input->get('skey'); + $page = $this->input->get('page'); + $type = $this->input->get('type'); + !$page && $page=1; + $param = $this->myencryption->base64url_decode($skey); + $a_id = intval($param['a_id']);//活动id + $row = $this->market_sylive_activity_model->get(['activityId'=>$a_id]); + $where = [ + 'type' => 1, + 'a_id'=>$a_id, + 'cf_uid'=>$this->uid + ]; + if($type==1){ //预热 + $where['c_time<='] = strtotime($row['timeStart']); + }else{ //开始 + $where['c_time>='] = strtotime($row['timeStart']); + } + $total = $this->mdSytActivityKpiData->count($where); + $lists = []; + if($total){ + $rows = $this->mdSytActivityKpiData->select($where,'id desc',$page,10,'uid,kpi,c_time'); + $users = []; + $uids = implode(',',array_unique(array_column($rows,'uid'))); + if($uids){ + $where = [ + "userId in ($uids)" => null, + ]; + $users = $this->user_model->map('userId','nickname',$where,'','','','userId,nickname'); + } + foreach ($rows as $key => $val) { + $nickname = $users[$val['uid']] ? $users[$val['uid']] : "用户{$val['uid']}"; + $lists[] = [ + 'nickname' => $nickname, + 'action' => $map_kpi_name[$val['kpi']], + 'time' => friendly_date($val['c_time']), + ]; + } + } + $data = [ + 'lists' => $lists, + 'total' => $total + ]; + if($this->teamLevel==2){ //团员 + $t_row = $this->market_sylive_team_model->get(['teamId'=>$this->session['teamId']],'parentId'); + $teamId = $t_row['parentId']; + }elseif($this->teamLevel==1){ //团长 + $teamId = $this->session['teamId']; + }else{//大团长 + $teamId = 0; + } + if($type==1){ + $b_rows = $this->sylive_entity->top_team_user($a_id,$teamId,$this->uid,'browse'); + $data['browse'] = [ + 'title' => '团队浏览排行', + 'list' => $b_rows['lists'] + ]; + $sub_rows = $this->sylive_entity->top_team_user($a_id,$teamId,$this->uid,'subscribe'); + $data['book'] = [ + 'title' => '团队预约排行', + 'list' => $sub_rows['lists'] + ]; + }else{ + $view_rows = $this->sylive_entity->top_team_user($a_id,$teamId,$this->uid,'watch'); + $data['view'] = [ + 'title' => '团队观看排行', + 'list' => $view_rows['lists'] + ]; + $order_rows = $this->sylive_entity->top_team_user($a_id,$teamId,$this->uid,'order'); + $data['order'] = [ + 'title' => '团队订单排行', + 'list' => $order_rows['lists'] + ]; + $where = [ + 'a_id' => $a_id, + 'type' => 1, + 'biz_id' => $teamId, + ]; + $view_num_lists = $this->sylive_entity->top_team_view_num($where,1,10); + $data['view_num'] = [ + 'title' => '团队观看次数排行', + 'list' => $view_num_lists['lists'] + ]; + $view_time_lists = $this->sylive_entity->top_team_view_time($where,1,10); + $data['view_time'] = [ + 'title' => '团队观看时长排行', + 'url' => '', + 'list' => $view_time_lists['lists'] + ]; + } + $this->show_json($data,200); + } + + public function users(){ + $map_kpi_name = [ + 'browse' => '访问用户', 'subscribe' => '预约用户', 'order' => '下单用户','watch' => '观看用户' + ]; + $params = $this->input->get(); + $a_id = intval($params['a_id']);//活动id + $row = $this->market_sylive_activity_model->get(['activityId'=>$a_id]); + if(!$row){ + throw new Hd_exception('参数错误',400); + } + $title = $map_kpi_name[$params['kpi']]; + $tab = [ + ['id'=>1,'title'=>'客户列表'] + ]; + if($this->teamLevel==1){ //团长 + $tab[] = ['id'=>2,'title'=>'团员数据']; + } + $this->data['title'] = $title; + $this->data['tab'] = $tab; + $this->data['params'] = $params; + //微信分享 + $wx_info = $this->share_info($row); + $this->data['sign_package'] = $wx_info['sign_package']; + $this->data['share'] = $wx_info['share']; + $this->show_view('h5/market/sylive/tstic/users'); + } + + public function user_lists(){ + $params = $this->input->get(); + if($params['tabid']==2){ //顾问数据 + $this->gw_lists(); + } + $page = $params['page'] ? intval($params['page']) : 1; + $where = [ + 'type' => 1, + 'a_id' => $params['a_id'], + 'kpi' => $params['kpi'], + ]; + if($params['type']=='all' && $this->teamLevel<2){ //所有 + if(!$this->teamLevel){ //大团长 + $where["area_id"] = $this->session['teamId']; + }elseif($this->teamLevel==1){ //团长 + $where["biz_id"] = $this->session['teamId']; + }else{ //团员 + $where['cf_uid'] = $this->uid; + } + }else{ //只显示个人 + $where['cf_uid'] = $this->uid; + } + $total = $this->mdSytActivityKpiData->count($where); + $lists = []; + if($total){ + $rows = $this->mdSytActivityKpiData->select($where,'id desc',$page,20,'uid,cf_uid,c_time'); + $uids_arr = array_column($rows,'uid'); + if($this->teamLevel==1){ + $gw_uids_arr = array_column($rows,'cf_uid'); + $uids_arr = array_merge($uids_arr,$gw_uids_arr); + } + $uids = implode(',',array_unique($uids_arr)); + $users = []; + if($uids){ + $where = [ + "userId in ($uids)" => null, + ]; + $users = $this->user_model->map('userId','',$where,'','','','userId,uname,nickname,headimg'); + } + foreach ($rows as $key => $item) { + $user = $users[$item['uid']] ? $users[$item['uid']][0] : []; + $nickname = $user['nickname'] ? $user['nickname'] : '用户'.$user['userId']; + $headimg = $user['headimg'] ? $user['headimg'] : 'https://thirdwx.qlogo.cn/mmopen/vi_32/Q3auHgzwzM483tlYWFg5RWQ1Xat94ib82prnDSicm2GHuxI49swU08N2I1aHb7B1gmicyxXF8R1BsVWahU9SiaPEzA/132'; + $cf_uname = ''; + if($this->teamLevel==1){ //团长 + $cf_user = $users[$item['cf_uid']] ? $users[$item['cf_uid']][0] : []; + $cf_uname = $cf_user['uname'] ? "({$cf_user['uname']})" : ""; + } + $lists[] = [ + 'nickname' => $nickname, + 'headimg' => $headimg, + 'time' => $cf_uname.friendly_date($item['c_time'],'normal',1) + ]; + } + } + $data = [ + 'total' => $total, + 'lists' => $lists + ]; + $this->show_json($data,200); + } + + public function gw_lists(){ + $params = $this->input->get(); + if($this->teamLevel==2){ //团员 + $t_row = $this->market_sylive_team_model->get(['teamId'=>$this->session['teamId']],'parentId'); + $teamId = $t_row['parentId']; + }elseif($this->teamLevel==1){ //团长 + $teamId = $this->session['teamId']; + }else{//大团长 + $teamId = 0; + } + $res = $this->sylive_entity->top_team_user($params['a_id'],$teamId,$this->uid,$params['kpi']); + $lists = []; + if($res['lists']){ + foreach ($res['lists'] as $item) { + $lists[] = [ + 'nickname' => $item['name'], + 'headimg' => $item['headimg'], + 'time' => $item['num'] + ]; + } + } + $data = [ + 'total' => $res['total'], + 'lists' => $lists + ]; + $this->show_json($data,200); + } +} \ No newline at end of file diff --git a/home/controllers/h5/market/sylive/Welcome.php b/home/controllers/h5/market/sylive/Welcome.php index 9329f9bb..8ab90e67 100644 --- a/home/controllers/h5/market/sylive/Welcome.php +++ b/home/controllers/h5/market/sylive/Welcome.php @@ -10,6 +10,14 @@ class Welcome extends Admin { } public function index(){ + if($this->session['teamId']){ //团队首页 + $teamLevel = $this->sylive_entity->get_team_level($this->session['teamId']); + if($teamLevel>0){ //团长和团员 首页 + header('Location:/h5/market/sylive/team/lists');exit; + }else{ // 团队列表 + header('Location:/h5/market/sylive/team');exit; + } + } $group_id = $this->sylive_entity->get_level($this->session['org_id']); if($group_id==2 || $group_id==3){ //顾问和店长 店铺首页 header('Location:/h5/market/sylive/biz');exit; diff --git a/home/views/h5/market/sylive/act/index.php b/home/views/h5/market/sylive/act/index.php index ac2f0165..122cb1c0 100644 --- a/home/views/h5/market/sylive/act/index.php +++ b/home/views/h5/market/sylive/act/index.php @@ -44,15 +44,28 @@
-
-
- +
+
企微福利官二维码
+
+
+ 您的
50积分
奖励即将到账 +
+
添加[东风EV官方企微号]即刻领取
+
+ 更有
100%中奖
惊喜等着您 +
+
+
+ +
+
+ # + 长按识别二维码领福利
-
长按识别二维码,关注狸车服务号。即可接收直播提醒,还有更多福利不定期放送哦~
-
- +
@@ -118,16 +131,16 @@ clearInterval(this.bundleIntervalEvent); }, methods: { - showCode: function() { let that = this; if (that.info.subscribemsg == '已订阅直播') { - mDialog.msg({content: that.info.subscribemsg}); - return; - } - if (!that.mp_app_id) { - window.location.href = "" + that.info.subscribemsg; - return; + if(that.info.show_code){ + this.msgisShowCode = true + }else{ + mDialog.msg({content: that.info.subscribemsg}); + } + }else{ + window.location.href = that.info.subscribemsg; } }, closeCode: function() { diff --git a/home/views/h5/market/sylive/act/item.php b/home/views/h5/market/sylive/act/item.php index a73c5ffb..59c21921 100644 --- a/home/views/h5/market/sylive/act/item.php +++ b/home/views/h5/market/sylive/act/item.php @@ -30,10 +30,13 @@
- -
立即支付{{info.price}}
-
-
+
活动已结束
diff --git a/home/views/h5/market/sylive/biz/brands.php b/home/views/h5/market/sylive/biz/brands.php index 3b77798e..0851dcc5 100644 --- a/home/views/h5/market/sylive/biz/brands.php +++ b/home/views/h5/market/sylive/biz/brands.php @@ -140,7 +140,7 @@ //判断导航是否需要吸顶 handleScroll () { - let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop + let scrollTop = document.querySelector('#app').scrollTop let mainoffsetTop = document.querySelector('#main').offsetTop if (scrollTop > mainoffsetTop) { this.tabFixed = true diff --git a/home/views/h5/market/sylive/biz/lists.php b/home/views/h5/market/sylive/biz/lists.php index e34c42c3..407d8d22 100644 --- a/home/views/h5/market/sylive/biz/lists.php +++ b/home/views/h5/market/sylive/biz/lists.php @@ -147,7 +147,7 @@ //判断导航是否需要吸顶 handleScroll () { - let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop + let scrollTop = document.querySelector('#app').scrollTop let mainoffsetTop = document.querySelector('#main').offsetTop if (scrollTop > mainoffsetTop) { this.tabFixed = true diff --git a/home/views/h5/market/sylive/stic/area.php b/home/views/h5/market/sylive/stic/area.php index e44f94ca..36729c08 100644 --- a/home/views/h5/market/sylive/stic/area.php +++ b/home/views/h5/market/sylive/stic/area.php @@ -298,7 +298,7 @@ //判断导航是否需要吸顶 handleScroll () { - let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop + let scrollTop = document.querySelector('#app').scrollTop let mainoffsetTop = document.querySelector('#main').offsetTop if (scrollTop > mainoffsetTop) { this.tabFixed = true diff --git a/home/views/h5/market/sylive/stic/index.php b/home/views/h5/market/sylive/stic/index.php index 0b86c4b4..259b1783 100644 --- a/home/views/h5/market/sylive/stic/index.php +++ b/home/views/h5/market/sylive/stic/index.php @@ -253,7 +253,7 @@ //判断导航是否需要吸顶 handleScroll () { - let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop + let scrollTop = document.querySelector('#app').scrollTop let mainoffsetTop = document.querySelector('#main').offsetTop if (scrollTop > mainoffsetTop) { this.tabFixed = true diff --git a/home/views/h5/market/sylive/stic/users.php b/home/views/h5/market/sylive/stic/users.php index e07aaec8..c70c5d15 100644 --- a/home/views/h5/market/sylive/stic/users.php +++ b/home/views/h5/market/sylive/stic/users.php @@ -72,7 +72,7 @@ methods: { //判断导航是否需要吸顶 handleScroll () { - let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop + let scrollTop = document.querySelector('#app').scrollTop let mainoffsetTop = document.querySelector('#main').offsetTop if (scrollTop > mainoffsetTop) { this.tabFixed = true diff --git a/home/views/h5/market/sylive/team/index.php b/home/views/h5/market/sylive/team/index.php new file mode 100644 index 00000000..baa49a5f --- /dev/null +++ b/home/views/h5/market/sylive/team/index.php @@ -0,0 +1,218 @@ + +
+
+
+
+ # + {{info.nickname}} + + 退出 + +
+
+
+
{{item.num}}
+
+ {{item.title}} +
+
+
+
+
+
+
+
+ +
+
+ + + +
暂无数据
+
请稍等...
+
我们是有底线的
+
+
+
+
+ + +load->view('h5/market/sylive/hidden_wx_share')?> + \ No newline at end of file diff --git a/home/views/h5/market/sylive/team/lists.php b/home/views/h5/market/sylive/team/lists.php new file mode 100644 index 00000000..59148f4c --- /dev/null +++ b/home/views/h5/market/sylive/team/lists.php @@ -0,0 +1,139 @@ + +
+
+ +
+ # +
{{info.title}}
+ + +
暂无数据
+
请稍等...
+
我们是有底线的
+
+
+
+ + load->view('h5/market/sylive/nav')?> + +
+ + +load->view('h5/market/sylive/hidden_wx_share')?> + \ No newline at end of file diff --git a/home/views/h5/market/sylive/tstic/area.php b/home/views/h5/market/sylive/tstic/area.php new file mode 100644 index 00000000..00c00d1f --- /dev/null +++ b/home/views/h5/market/sylive/tstic/area.php @@ -0,0 +1,360 @@ + +
+
+
+
+
+
+
+ +
+
+ + +
+ + + + + +
+
+ + 查看更多 +
+
+
+
+
+ # + {{item.ranking}} + {{item.name}} + {{item.tip}} +
+
{{item.num}}
+
+
+
+
暂时无数据
+
+ +
+
+ + 查看更多 +
+
+
+
+
+ # + {{item.ranking}} + {{item.name}} + {{item.tip}} +
+
{{item.num}}
+
+
+
+
暂时无数据
+
+ +
+ + +
+
直播结束后2小时同步完整数据
+ + + + + +
+
+ + 查看更多 +
+
+
+
+
+ # + {{item.ranking}} + {{item.name}} + {{item.tip}} +
+
{{item.num}}
+
+
+
+
暂时无数据
+
+ +
+
+ + 查看更多 +
+
+
+
+
+ # + {{item.ranking}} + {{item.name}} + {{item.tip}} +
+
{{item.num}}
+
+
+
+
暂时无数据
+
+ +
+
+ + 查看更多 +
+
+
+
+
+ # + {{index+1}} + {{item.name}} + {{item.tip}} +
+
{{item.num}}
+
+
+
+
暂时无数据
+
+ + +
+ +
+ + + +
+ load->view('h5/market/sylive/nav');?> +
+ + +load->view('h5/market/sylive/share_script')?> + diff --git a/home/views/h5/market/sylive/tstic/index.php b/home/views/h5/market/sylive/tstic/index.php new file mode 100644 index 00000000..8b2d0953 --- /dev/null +++ b/home/views/h5/market/sylive/tstic/index.php @@ -0,0 +1,360 @@ + +
+
+
+
+
+
+
+ +
+
+ + +
+ + +
+
+ +
+
+
+
+ # + {{index+1}} + {{item.name}} + {{item.tip}} +
+
{{item.num}}
+
+
+
+ +
+
+ +
+
+
+
+ # + {{index+1}} + {{item.name}} + {{item.tip}} +
+
{{item.num}}
+
+
+
暂时无数据
+
+ +
+ + +
+ +
+
+ +
+
+
+
+ # + {{index+1}} + {{item.name}} + {{item.tip}} +
+
{{item.num}}
+
+
+
暂时无数据
+
+
+
+ +
+
+
+
+ # + {{index+1}} + {{item.name}} + {{item.tip}} +
+
{{item.num}}
+
+
+
暂时无数据
+
+
+
+ +
+
+
+
+ # + {{index+1}} + {{item.name}} + {{item.tip}} +
+
{{item.num}}
+
+
+
暂时无数据
+
+
+
+ +
+
+
+
+ # + {{index+1}} + {{item.name}} + {{item.tip}} +
+
{{item.num}}
+
+
+
暂时无数据
+
+
+ + +
+
+ +
+
+
+
+ {{item.nickname}} + {{item.action}} +
+
{{item.time}}
+
+
+ +
暂无数据
+
请稍等...
+
我们是有底线的
+
+
+ +
+ + + +
+ load->view('h5/market/sylive/nav');?> +
+ + +load->view('h5/market/sylive/share_script')?> + \ No newline at end of file diff --git a/home/views/h5/market/sylive/tstic/rank.php b/home/views/h5/market/sylive/tstic/rank.php new file mode 100644 index 00000000..46df688f --- /dev/null +++ b/home/views/h5/market/sylive/tstic/rank.php @@ -0,0 +1,84 @@ + +
+
+
+
+
+
+
+ # + {{item.ranking}} + {{item.name}} + {{item.tip}} +
+
{{item.num}}
+
+
+ +
暂无数据
+
请稍等...
+
我们是有底线的
+
+
+
+
+ + +load->view('h5/market/sylive/share_script')?> + \ No newline at end of file diff --git a/home/views/h5/market/sylive/tstic/users.php b/home/views/h5/market/sylive/tstic/users.php new file mode 100644 index 00000000..fcf28266 --- /dev/null +++ b/home/views/h5/market/sylive/tstic/users.php @@ -0,0 +1,130 @@ + +
+
+
+ + +
+
+ # + {{item.nickname}} +
+
{{item.time}}
+
+ +
暂无数据
+
请稍等...
+
我们是有底线的
+
+
+
+ load->view('h5/market/sylive/nav');?> +
+ + +load->view('h5/market/sylive/share_script')?> + \ No newline at end of file