From 41f2fe4db6de7632a9d9edb5f26c6ec7a10675fa Mon Sep 17 00:00:00 2001 From: lccsw <805383944@qq.com> Date: Mon, 5 Dec 2022 17:41:23 +0800 Subject: [PATCH] add-sylive-2 --- .../libraries/market/Sylive2_data_entity.php | 125 ++++ common/libraries/market/Sylive2_entity.php | 167 ++++++ home/controllers/h5/market/sylive2/Act.php | 439 ++++++++++++++ home/controllers/h5/market/sylive2/Biz.php | 77 +++ home/controllers/h5/market/sylive2/Common.php | 281 +++++++++ home/controllers/h5/market/sylive2/Login.php | 159 ++++++ home/controllers/h5/market/sylive2/Stic.php | 537 ++++++++++++++++++ .../controllers/h5/market/sylive2/Ucenter.php | 210 +++++++ .../controllers/h5/market/sylive2/Welcome.php | 53 ++ home/views/h5/market/sylive2/act/index.php | 249 ++++++++ home/views/h5/market/sylive2/act/item.php | 223 ++++++++ home/views/h5/market/sylive2/act/share.php | 153 +++++ home/views/h5/market/sylive2/act/test.php | 75 +++ home/views/h5/market/sylive2/biz/index.php | 96 ++++ home/views/h5/market/sylive2/footer.php | 1 + home/views/h5/market/sylive2/header.php | 18 + .../h5/market/sylive2/hidden_wx_share.php | 18 + home/views/h5/market/sylive2/index.php | 45 ++ .../h5/market/sylive2/item/agreement.php | 20 + home/views/h5/market/sylive2/item/detail.php | 520 +++++++++++++++++ home/views/h5/market/sylive2/login.php | 160 ++++++ home/views/h5/market/sylive2/nav.php | 4 + home/views/h5/market/sylive2/nav_my.php | 4 + home/views/h5/market/sylive2/share_script.php | 60 ++ home/views/h5/market/sylive2/stic/index.php | 365 ++++++++++++ home/views/h5/market/sylive2/stic/rank.php | 109 ++++ home/views/h5/market/sylive2/stic/ranking.php | 392 +++++++++++++ home/views/h5/market/sylive2/stic/users.php | 169 ++++++ .../h5/market/sylive2/ucenter/detail.php | 234 ++++++++ .../views/h5/market/sylive2/ucenter/index.php | 73 +++ .../h5/market/sylive2/ucenter/orders.php | 78 +++ home/views/h5/market/sylive2/ucenter/win.php | 104 ++++ home/views/h5/market/sylive2/user/index.php | 320 +++++++++++ home/views/h5/market/sylive2/user/team.php | 319 +++++++++++ www/home/css/h5/market/sylive/h5.css | 2 +- 35 files changed, 5858 insertions(+), 1 deletion(-) create mode 100644 common/libraries/market/Sylive2_data_entity.php create mode 100644 common/libraries/market/Sylive2_entity.php create mode 100644 home/controllers/h5/market/sylive2/Act.php create mode 100644 home/controllers/h5/market/sylive2/Biz.php create mode 100644 home/controllers/h5/market/sylive2/Common.php create mode 100644 home/controllers/h5/market/sylive2/Login.php create mode 100644 home/controllers/h5/market/sylive2/Stic.php create mode 100644 home/controllers/h5/market/sylive2/Ucenter.php create mode 100644 home/controllers/h5/market/sylive2/Welcome.php create mode 100644 home/views/h5/market/sylive2/act/index.php create mode 100644 home/views/h5/market/sylive2/act/item.php create mode 100644 home/views/h5/market/sylive2/act/share.php create mode 100644 home/views/h5/market/sylive2/act/test.php create mode 100644 home/views/h5/market/sylive2/biz/index.php create mode 100644 home/views/h5/market/sylive2/footer.php create mode 100644 home/views/h5/market/sylive2/header.php create mode 100644 home/views/h5/market/sylive2/hidden_wx_share.php create mode 100644 home/views/h5/market/sylive2/index.php create mode 100644 home/views/h5/market/sylive2/item/agreement.php create mode 100644 home/views/h5/market/sylive2/item/detail.php create mode 100644 home/views/h5/market/sylive2/login.php create mode 100644 home/views/h5/market/sylive2/nav.php create mode 100644 home/views/h5/market/sylive2/nav_my.php create mode 100644 home/views/h5/market/sylive2/share_script.php create mode 100644 home/views/h5/market/sylive2/stic/index.php create mode 100644 home/views/h5/market/sylive2/stic/rank.php create mode 100644 home/views/h5/market/sylive2/stic/ranking.php create mode 100644 home/views/h5/market/sylive2/stic/users.php create mode 100644 home/views/h5/market/sylive2/ucenter/detail.php create mode 100644 home/views/h5/market/sylive2/ucenter/index.php create mode 100644 home/views/h5/market/sylive2/ucenter/orders.php create mode 100644 home/views/h5/market/sylive2/ucenter/win.php create mode 100644 home/views/h5/market/sylive2/user/index.php create mode 100644 home/views/h5/market/sylive2/user/team.php diff --git a/common/libraries/market/Sylive2_data_entity.php b/common/libraries/market/Sylive2_data_entity.php new file mode 100644 index 00000000..9e98efbb --- /dev/null +++ b/common/libraries/market/Sylive2_data_entity.php @@ -0,0 +1,125 @@ + 'browse', 'subscribe' => 'subscribe', 'order' => 'orderTotal','watch' => 'watch' + ]; + + public function __construct(){ + $this->ci = &get_instance(); + $this->ci->load->model('market/market_sylive_user_model', 'user_model'); + $this->ci->load->model('market/market_sylive_activity_user_model', 'act_user_model'); + $this->ci->load->model('market/market_sylive_activity_model'); + $this->ci->load->model('market/market_sylive_activity_biz_model','mdSytActivityBiz'); + $this->ci->load->model('market/market_sylive_activity_team_model','mdSytActivityTeam'); + $this->ci->load->model('market/market_sylive_activity_kpidata_model','mdSytActivityKpiData'); + $this->ci->load->model('market/market_sylive_organization_model'); + $this->ci->load->model('market/market_sylive_activity_orders_model','mdSytActivityOrders'); + $this->ci->load->model('market/market_sylive_viewlog_model'); + $this->load->model('market/market_sylive_groups_model', 'groups_model'); + $this->load->model('market/market_sylive_groups_user_model', 'groups_user_model'); + } + + /** + * @return void + */ + public function top_kpidata($groupby,$where,$order,$page=1,$page_size=20,$select='',$tagId=0){ + $total = $this->ci->mdSytActivityKpiData->count($where,$groupby); + $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'); + } + } + 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'); + } + $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] : []; + $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, + 'num' => $val['t'].$num_tip, + 'headimg' => $headimg, + 'tip' => $tip, + ]; + } + } + $data = [ + 'total' => $total, + 'lists' => $lists + ]; + return $data; + } + /** + * @return void + */ + public function top_groups_user($groupby,$where,$order,$page=1,$page_size=20,$select='',$kpi,$tagId=0){ + $total = $this->ci->groups_user_model->count($where,$groupby); + $lists = []; + if($total){ + $rows = $this->ci->groups_user_model->select_groupby($groupby, $where, $order, $page, $page_size, $select); + $biz_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'); + } + + $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]; + $name = $biz['groupsName']; + $tip = $tagId==$val['bizId'] ? '本店' : ''; + } + $lists[] = [ + 'ranking' => $start+$key+1, + 'name' => $name, + 'num' => $val['t'].$num_tip, + 'headimg' => $headimg, + 'tip' => $tip, + ]; + } + } + $data = [ + 'total' => $total, + 'lists' => $lists + ]; + return $data; + } + public function __get($name) + { + if ('_model' === substr($name, -6)) { + return $this->ci->$name; + } elseif ('load' == $name) { + return $this->ci->load; + } + return null; + } +} \ No newline at end of file diff --git a/common/libraries/market/Sylive2_entity.php b/common/libraries/market/Sylive2_entity.php new file mode 100644 index 00000000..b506dc17 --- /dev/null +++ b/common/libraries/market/Sylive2_entity.php @@ -0,0 +1,167 @@ + 'browse', 'subscribe' => 'subscribe', 'order' => 'orderTotal','watch' => 'watch' + ]; + + public function __construct(){ + $this->ci = &get_instance(); + $this->ci->load->model('market/market_sylive_user_model', 'user_model'); + $this->ci->load->model('market/market_sylive_activity_user_model', 'act_user_model'); + $this->ci->load->model('market/market_sylive_groups_model', 'groups_model'); + $this->ci->load->model('market/market_sylive_groups_user_model', 'groups_user_model'); + $this->ci->load->model('market/market_sys_dictionary_data_model'); + } + + /** + * 获取等级数据 + * @param $groupsId + * @param $data + * @return int + */ + public function get_group_lists($groupsId,$a_id,$data=[]){ + $row = $this->ci->groups_model->get(['groupsId'=>$groupsId,'activityId'=>$a_id],'groupsId,parentId,groupsName'); + if(!$row){ + return $data; + }else{ + array_unshift($data,$row); + if($row['parentId']){ + return $this->get_group_lists($row['parentId'],$a_id,$data); + }else{ + return $data; + } + } + } + + /** + * 添加kpi记录 + * @param $params + * @return array + */ + public function kpi_log($params) + { + if ($params['a_id'] && $params['uid'] && $params['cf_uid']) { + $user = $this->user_model->get(['userId'=>$params['cf_uid']]); + $act_user = $this->act_user_model->get(['activityId'=>$params['a_id'],'userId'=>$params['cf_uid']]); + if(!$user || !$act_user){ + return array('code' => 0, 'msg' => '顾问不存在'); + } + if(!in_array($params['kpi'],['order'])){ //订单可添加多条kpi + $re_kpi = $this->ci->mdSytActivityKpiData->get(array("activityId" => $params['a_id'], 'userId' => $params['uid'], 'kpi' => $params['kpi'])); + if ($re_kpi) {//已添加过活动kpi(访活动只记录一次用户kpi记录) + return array('code' => 0, 'msg' => '已添加过' . $params['kpi'] . '记录'); + } + } + //增加记录 + $addData = [ + 'activityId' => $params['a_id'], + 'userId' => $user['userId'], + 'cfUserId' => $act_user['userId'], + 'kpi' => $params['kpi'], + 'createTime' => time(), + 'day' => date('Y-m-d') + ]; + $act_user['bizId'] && $addData['bizId'] = $act_user['bizId']; + $act_user['levelId1'] && $addData['levelId1'] = $act_user['levelId1']; + $act_user['levelId2'] && $addData['levelId2'] = $act_user['levelId2']; + $act_user['levelId3'] && $addData['levelId3'] = $act_user['levelId3']; + $params['tagId'] && $addData['tagId'] = $params['tagId']; + $params['itemId'] && $addData['itemId'] = $params['itemId']; + $jsondata = $params['jsondata'] ? $params['jsondata'] : []; + $jsondata && $addData['jsondata'] = json_encode($jsondata, JSON_UNESCAPED_UNICODE); + $id = $this->ci->mdSytActivityKpiData->add($addData); + if (!$id) { + return array('code' => 0, 'msg' => '添加记录失败'); + } + $this->kpi_count($params['a_id'],$params['kpi'],$params['cf_uid']); + return array('code' => 1, 'msg' => '添加记录成功'); + } else { + return array('code' => 0, 'msg' => '参数错误'); + } + } + + /** + * 更新统计数据 + * @param $a_id + * @param $kpi + * @param $cf_uid + * @return array + */ + public function kpi_count($a_id,$kpi,$cf_uid){ + if($this->map_kpi_biz[$kpi] && $cf_uid && $a_id){ + $up_key = $this->map_kpi_biz[$kpi]; + $total = $this->ci->mdSytActivityKpiData->count(['activityId'=>$a_id,'cfUserId'=>$cf_uid,'kpi'=>$kpi]); + $update = [ + $up_key => $total + ]; + //更新活动用户表统计数据 + $this->ci->act_user_model->update($update,['activityId'=>$a_id,'userId'=>$cf_uid]); + //更新分组用户统计 + $this->ci->groups_user_model->update($update,['activityId'=>$a_id,'userId'=>$cf_uid]); + //更新分组统计 + $group_user = $this->groups_user_model->get(['activityId'=>$a_id,'userId'=>$cf_uid]); + if($group_user['levelId1']){ + $total = $this->ci->mdSytActivityKpiData->count(['activityId'=>$a_id,'levelId1'=>$group_user['levelId1'],'kpi'=>$kpi]); + $update = [ + $up_key => $total + ]; + $this->ci->groups_model->update($update,['activityId'=>$a_id,'groupsId'=>$group_user['levelId1']]); + } + if($group_user['levelId2']){ + $total = $this->ci->mdSytActivityKpiData->count(['activityId'=>$a_id,'levelId2'=>$group_user['levelId2'],'kpi'=>$kpi]); + $update = [ + $up_key => $total + ]; + $this->ci->groups_model->update($update,['activityId'=>$a_id,'groupsId'=>$group_user['levelId2']]); + } + if($group_user['levelId3']){ + $total = $this->ci->mdSytActivityKpiData->count(['activityId'=>$a_id,'levelId3'=>$group_user['levelId3'],'kpi'=>$kpi]); + $update = [ + $up_key => $total + ]; + $this->ci->groups_model->update($update,['activityId'=>$a_id,'groupsId'=>$group_user['levelId3']]); + } + //更新门店 + if($group_user['bizId']){ + $total = $this->ci->mdSytActivityKpiData->count(['activityId'=>$a_id,'bizId'=>$group_user['bizId'],'kpi'=>$kpi]); + $update = [ + $up_key => $total + ]; + $this->ci->groups_model->update($update,['activityId'=>$a_id,'groupsId'=>$group_user['bizId']]); + } + return ['code'=>1,'msg'=>'更新成功']; + }else{ + return ['code'=>0,'msg'=>'参数错误']; + } + } + + /** + * 获取等级字典 + * @param $a_id + * @return array + */ + public function level_disk($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->map('dictDataCode','dictDataName',$where,'','','','dictDataName,dictDataCode'); + } + return $disk; + } + + public function __get($name) + { + if ('_model' === substr($name, -6)) { + return $this->ci->$name; + } elseif ('load' == $name) { + return $this->ci->load; + } + return null; + } +} diff --git a/home/controllers/h5/market/sylive2/Act.php b/home/controllers/h5/market/sylive2/Act.php new file mode 100644 index 00000000..27d5abf2 --- /dev/null +++ b/home/controllers/h5/market/sylive2/Act.php @@ -0,0 +1,439 @@ +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_subscribemsg_model','mdSytSubscribemsg'); + $this->load->model('market/market_sylive_activity_kpidata_model','mdSytActivityKpiData'); + $this->load->model('market/market_sylive_order_model'); + $this->load->library('market/sylive_entity'); + $this->load->library('market/sylive2_entity'); + $this->load->library('qiniu'); + $this->skey = $this->input->get('skey'); + $param = $this->myencryption->base64url_decode($this->skey); + $this->a_id = intval($param['a_id']);//活动id + } + + public function index(){ + $alert_code = $this->input->get('alert_code'); + if (!$this->a_id) { + 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],'unionid,nickname,headimg'); + $timeStart = strtotime($row['timeStart']); + $info['s_time'] = time() < $timeStart ? $timeStart-time() : 0; + $info['bg'] = $row['bgImg'] ? build_qiniu_image_url($row['bgImg']) : ''; + $info['content'] = $row['introduction']; + $act_user = $this->act_user_model->get(['userId'=>$this->uid,'activityId'=>$this->a_id]); + //一次性订阅 + $re_s = $this->mdSytSubscribemsg->get(array('activityId' => $this->a_id, 'userId' => $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/sylive2/act/userinfo?skey={$this->skey}&type=sub"; + }else{ + $this->load->config('wechat'); + $config = $this->config->item('hdy'); + $sub_redirect_url = urlencode(http_host_com('home') . '/h5/market/sylive2/act/subscribemsg?skey=' . $this->skey + . '&s_time=' . $row['timeStart']); + $subscribemsg = "https://mp.weixin.qq.com/mp/subscribemsg?action=get_confirm&appid={$config['appid']}&scene=0&template_id={$this->template_id}&redirect_url={$sub_redirect_url}&reserved=test#wechat_redirect"; + } + } + //浏览 + $params = array('a_id' => $this->a_id, 'uid' => $this->uid,'cf_uid' => $act_user['channelId'], 'kpi' => 'browse'); + $this->sylive2_entity->kpi_log($params); + $live_status = 0; //直播未开始 + if(time()>strtotime($row['timeStart']) && time()<=strtotime($row['timeEnd'])){ //直播期间人数 + $row['liveStatus']!=1 && $this->market_sylive_activity_model->update(['liveStatus'=>1],['activityId'=>$this->a_id]); //更新直播间状态 + $live_status = 1; //直播中 + } + if(time()>strtotime($row['timeEnd'])){ //直播结束 + $row['liveStatus']!=2 && $this->market_sylive_activity_model->update(['liveStatus'=>2],['activityId'=>$this->a_id]); //更新直播间状态 + $live_status = 2; //直播结束 + } + $share_skey = "a_id=" . $this->a_id . "&cf_uid=" . $this->uid; + $info['live_status'] = $live_status; + $info['skey'] = $this->myencryption->base64url_encode($share_skey); + $info['a_id'] = $this->a_id; + $info['subscribemsg'] = $subscribemsg; + $info['statisticsurl'] = $info['shareurl'] = $info['code'] = ''; + if($act_user['groupsId']){ + $info['shareurl'] = '/h5/market/sylive2/act/share?skey='.$info['skey']; + $info['statisticsurl'] = "/h5/market/sylive2/stic?a_id={$this->a_id}"; + $info['rankingurl'] = "/h5/market/sylive2/stic/ranking?a_id={$this->a_id}"; + } + + $info['channelImg'] = build_qiniu_image_url($row['channelImg']); + $userid = $user['unionid'] ? $user['unionid'] : $this->uid; + $ts = time()*1000; + $sign = md5($this->secretkey.$userid.$this->secretkey.$ts); + if(!$user['nickname'] && !$user['headimg']){ + $info['live_url'] = http_host_com('home').'/h5/market/sylive2/act/userinfo?skey='.$this->skey; + }else{ + $info['live_url'] = "https://live.haodian.cn/watch/{$row['channelId']}?userid={$userid}&ts={$ts}&sign={$sign}"; + } + $info['my_url'] = http_host_com('home')."/h5/market/sylive2/act/userinfo?skey={$this->skey}&type=my"; + //微信分享 + $wx_info = $this->share_info($row); + $info['show_code'] = $is_show_code ? 1 : 0; + $info['alert_code'] = $alert_code ? 1 : 0; + $this->data['info'] = $info; + $this->data['sign_package'] = $wx_info['sign_package']; + $this->data['share'] = $wx_info['share']; + $this->data['_title'] = $row['title']; + $this->data['skey'] = $info['skey']; + $this->show_view('h5/market/sylive2/act/index'); + } + + //获取最新订阅用户 + public function subscribemsg_lists(){ + $map_kpi_name = [ + 'browse' => '进入了直播间', 'subscribe' => '预约了直播通知' + ]; + $a_id = $this->input->get('a_id'); + $live_status = $this->input->get('live_status'); + $field = 'userId,createTime,kpi'; + $lists = []; + $where = [ + 'activityId' => $a_id, + 'kpi' => 'subscribe' + ]; + if($live_status){ + $where['kpi'] = 'browse'; + } + $rows = $this->mdSytActivityKpiData->select($where,'id desc',1,30,$field); + if($rows){ + $users = []; + $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'); + } + foreach ($rows as $item) { + $nickname = $users[$item['userId']] ? $users[$item['userId']] : "用户{$item['userId']}"; + $lists[] = [ + 'name' => $nickname, + 'tip' => $map_kpi_name[$item['kpi']], + ]; + } + } + $data['lists'] = $lists; + $this->show_json($data,200); + } + + /** + * Notes:获取授权发送一次性订阅接口 + * Created on: 2020/11/26 17:11 + * Created by: dengbw + */ + public function subscribemsg() + { + $skey = $this->input->get('skey'); + $s_time = $this->input->get('s_time');//直播时间 + $param = $this->myencryption->base64url_decode($skey); + $a_id = intval($param['a_id']);//活动id + $action = $this->input->get('action'); + $show_code = 0; + if ($s_time && $action == "confirm") { + $add_data['activityId'] = $a_id; + $add_data['openId'] = $this->input->get('openid'); + $add_data['scene'] = $this->input->get('scene'); + $re_s = $this->mdSytSubscribemsg->get($add_data); + if (!$re_s) { + $add_data['userId'] = $this->uid; + $add_data['templateId'] = $this->input->get('template_id'); + $add_data['url'] = http_host_com('home') . "/h5/market/sylive2/act?skey=" . $this->myencryption->base64url_encode("a_id=" . $a_id);; + $add_data['timeStart'] = $s_time; + $add_data['createTime'] = time(); + $add_data['status'] = 0; + $id = $this->mdSytSubscribemsg->add($add_data); + if ($id) { + $act_user = $this->act_user_model->get(['userId'=>$this->uid,'activityId'=>$a_id]); + //订阅用户加统计 + $params = array('a_id' => $a_id, 'uid' => $this->uid,'cf_uid' => $act_user['channelId'], 'kpi' => 'subscribe'); + $this->sylive2_entity->kpi_log($params); + $p_user = []; + $act_user['channelId'] && $p_user = $this->user_model->get(['userId'=>$act_user['channelId']]); + $p_user['teamId'] && $show_code = 1; + } + } + } + $url = http_host_com('home') . "/h5/market/sylive2/act?skey={$skey}&alert_code={$show_code}"; + redirect($url); + } + + public function share(){ + $row = $this->market_sylive_activity_model->get(['activityId'=>$this->a_id]); + if(!$row){ + throw new Hd_exception('参数错误',400); + } + $shareImg = json_decode($row['shareImg'],true); + $shareTitle = $row['shareTitle'] ? json_decode($row['shareTitle'],true) : []; + $lists = []; + if($shareImg){ + $share_skey = "a_id=" . $this->a_id . "&cf_uid=" . $this->uid; + $share_url = http_host_com('home') . "/h5/market/sylive2/act?skey=" . $this->myencryption->base64url_encode($share_skey); + $errorCorrectionLevel = 'L'; //容错级别 + $matrixPointSize = 5; //生成图片大小 + //生成二维码图片 + $file_name = md5($share_url).'.png'; + $file_path = "temp/{$file_name}"; + if (!file_exists(FCPATH.'temp/')) { + $oldumask = umask(0); + mkdir(FCPATH.'temp/', 0777, true); + umask($oldumask); + } + QRcode::png($share_url, FCPATH.$file_path, $errorCorrectionLevel, $matrixPointSize, 1); + $res = $this->qiniu->save($file_name, file_get_contents(FCPATH.$file_path)); + if($res['url']){ + @unlink(FCPATH.$file_path); + $qr_code = build_qiniu_image_url($res['url']); + }else{ + $qr_code = '/h5/market/sylive2/myqrcode/get?url=' . $share_url; + } + foreach ($shareImg as $item) { + $img_url = build_qiniu_image_url($item); + $img_info = file_get_contents($img_url.'?imageInfo'); + if($img_info){ + $img_info = json_decode($img_info,true); + } + $lists[] = [ + "img" => $img_url, + "code" => $qr_code, + 'width' => $img_info['width'] ? $img_info['width'] : 750, + 'height' => $img_info['height'] ? $img_info['height'] : 1130, + ]; + } + } + $user = $this->user_model->get(['userId'=>$this->uid],'uname,nickname'); + $act_row = $this->act_user_model->get(['id'=>$this->act_uid],'groupsId'); + if($act_row['groupsId']){ + $group_lists = $this->sylive2_entity->get_group_lists($act_row['groupsId'],$this->a_id); + $this->data['posterTip'] = "{$group_lists[0]['groupsName']}{$user['uname']}诚挚邀请您参与"; + }else{ + $this->data['posterTip'] = "{$user['nickname']}诚挚邀请您参与"; + } + $this->data['lists'] = $lists; + $this->data['shareTitle'] = $shareTitle; + //微信分享 + $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/sylive2/act/share'); + } + + public function item(){ + $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){ + throw new Hd_exception('参数错误',400); + } + $jsondata = json_decode($row['jsondata'],true); + $item = $jsondata['item'] ? $jsondata['item'] : []; + $is_pay = $this->market_sylive_order_model->count(['itemId'=>$a_id,'status'=>1,'userId'=>$this->uid,'type'=>0]); + if($is_pay){ + $url = http_host_com('home').'/h5/market/sylive2/ucenter/mygift?skey='.$skey; + redirect($url);exit; + } + $e_time = time() < strtotime($row['timeEnd']) ? strtotime($row['timeEnd']) - time() : 0; + $banner = $this->item_banner; + $validity = ''; + if($item['useTimeStart'] || $item['useTimeEnd']){ + $useTimeStart = date('Y-m-d',strtotime($item['useTimeStart'])); + $useTimeEnd = date('Y-m-d',strtotime($item['useTimeEnd'])); + $validity = "有效期 {$useTimeStart} - {$useTimeEnd}"; + } + $info = [ + 'title' => $item['title'] ? $item['title'] : '', + 'e_time' => $e_time, + 'price' => $item['price'] ? $item['price'] : '', + 'content' => $item['introduction'] ? $item['introduction'] : '', + 'banner' => $banner, + 'stock' => $row['stock'], + 'skey' => $skey, + 'validity' => $validity, + 'introTitle' => '权益说明', + ]; + $this->data['info'] = $info; + $this->data['_title'] = $row['title']; + //微信分享 + $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/sylive2/act/item'); + } + + //支付 + public function post_pay(){ + $redis = load_cache('redis'); + $redis_obj = $redis->redis(); + $skey = $this->input->post('skey'); + $name = $this->input->post('name'); + $mobile = $this->input->post('telPhone'); + $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->show_json('',400,'参数错误'); + } + $mb_key = 'SYLIVE_ITEM_AID_'.$a_id; + if(!mobile_valid($mobile)){ + $this->show_json('',400,'请输入正确手机号'); + } + $jsondata = json_decode($row['jsondata'],true); + $item = $jsondata['item'] ? $jsondata['item'] : []; + //判断是否已支付 + $o_row = $this->market_sylive_order_model->get(['itemId'=>$a_id,'status'=>1,'userId'=>$this->uid,'type'=>0]); + if($o_row){ + $this->show_json('',400,'已支付,请勿重复支付'); + } + $pay_price = $item['price']; + if($pay_price<=0){ + $this->show_json('',400,'无需支付'); + } + if($row['stock']<=0){ + $this->show_json('',400,'已售罄'); + } + $unpay = $this->market_sylive_order_model->get(['itemId'=>$a_id,'status'=>0,'userId'=>$this->uid,'expireTime>'=>time(),'type'=>0]); + if(!$unpay){ + $mb_count = $redis_obj->sCard($mb_key); //获取集合中用户数量 + if($mb_count && $mb_count>$row['stock']+10){ + $mb = $redis_obj->sMembers($mb_key); + $this->show_json('',400,'已售罄:'.json_encode($mb,JSON_UNESCAPED_UNICODE)); + } + try { + $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']]); + $this->market_sylive_order_model->db->trans_begin(); + //限购一件 + $u_row = $this->market_sylive_order_model->get(['itemId'=>$a_id,'status>='=>0,'userId'=>$this->uid]); + if($u_row){ + throw new Exception('限购一件'); + } + $this->load->helper('order'); + $unpay = [ + 'sid' => create_order_no('350200','market'), + 'userId' => $this->uid, + 'itemId' => $a_id, + 'itemTitle' => $item['title'], + 'totalPrice' => $pay_price, + 'expireTime' => time()+5*60,//订单过期时间 + 'createTime' => date('Y-m-d H:i:s') + ]; + $name && $unpay['uname'] = $name; + $mobile && $unpay['mobile'] = $mobile; + $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(); + throw new Exception('创建订单失败'); + } + $this->market_sylive_activity_model->update(['stock = stock-1' =>null],['activityId'=>$a_id,'stock>'=>0]); + $res = $this->market_sylive_activity_model->db->affected_rows(); + if(!$res){ + throw new Exception('已售罄'); + } + $this->market_sylive_order_model->db->trans_commit(); + $redis_obj->sRem($mb_key,$this->uid); //删除集合 + }catch (Exception $e){ + $redis_obj->sRem($mb_key,$this->uid); //删除集合 + $this->market_sylive_order_model->db->trans_rollback(); + $this->show_json('',400,$e->getMessage()); + } + } + $user = $this->user_model->get(['userId'=>$this->uid]); + $notify_url = http_host_com('home').'/h5/market/sylive2/notify'; + $other_data = []; + $pay_config = $this->market_sylive_activity_model->pay_config($row['mchId']); + $pay_config && $other_data['pay_config'] = $pay_config; + $result = $this->unorder($unpay['sid'],$unpay['totalPrice'],$user['openid'],$unpay['itemTitle'],$notify_url,$unpay['expireTime'],$other_data); + if(!$result['code']){ + $this->show_json('',400,$result['msg']); + } + $this->show_json($result['data'],200,'操作成功'); + } + + //获取微信用户信息 + public function userinfo(){ + $ret = $this->set_auth('',1); + if($ret){ + $update = [ + "sex" => $ret['sex'] ? 1 : 0, + ]; + $ret['nickname'] && $update['nickname'] = strval($ret['nickname']); + $ret['headimgurl'] && $update['headimg'] = strval($ret['headimgurl']); + $ret['unionid'] && $update['unionid'] = $ret['unionid']; + $this->user_model->update($update,['userId'=>$this->uid]); + } + $skey = $this->input->get('skey'); + $type = $this->input->get('type'); + if (!$skey) { + throw new Hd_exception("参数错误", 400); + } + $param = $this->myencryption->base64url_decode($skey); + $a_id = intval($param['a_id']);//活动id + if (!$a_id) { + throw new Hd_exception("参数错误", 400); + } + $row = $this->market_sylive_activity_model->get(['activityId'=>$a_id]); + if(!$row){ + throw new Hd_exception('参数错误',400); + } + if($type=='sub'){ //订阅跳转 + $this->load->config('wechat'); + $config = $this->config->item('hdy'); + $sub_redirect_url = urlencode(http_host_com('home') . '/h5/market/sylive2/act/subscribemsg?skey=' . $skey + . '&s_time=' . $row['timeStart']); + $subscribemsg = "https://mp.weixin.qq.com/mp/subscribemsg?action=get_confirm&appid={$config['appid']}&scene=0&template_id={$this->template_id}&redirect_url={$sub_redirect_url}&reserved=test#wechat_redirect"; + redirect($subscribemsg); + }elseif($type=='my'){ //跳转我的 + $my_url = http_host_com('home')."/h5/market/sylive2/ucenter?skey={$skey}"; + redirect($my_url); + }else{ + $user = $this->user_model->get(['userId'=>$this->uid],'unionid,nickname,headimg'); + $userid = $user['unionid'] ? $user['unionid'] : $this->uid; + $ts = time()*1000; + $sign = md5($this->secretkey.$userid.$this->secretkey.$ts); + $live_url = "https://live.haodian.cn/watch/{$row['channelId']}?userid={$userid}&ts={$ts}&sign={$sign}"; + redirect($live_url); + } + } + //进入直播间统计 + public function golive(){ + $params = $this->input->get(); + $a_id = $params['a_id']; + $row = $this->market_sylive_activity_model->get(['activityId'=>$a_id]); + if($row && time()>strtotime($row['timeStart']) && time()<=strtotime($row['timeEnd'])){ + $act_user = $this->act_user_model->get(['userId'=>$this->uid,'activityId'=>$a_id]); + $this->sylive2_entity->kpi_log(['a_id' => $a_id, 'uid' => $this->uid,'cf_uid' => $act_user['channelId'], 'kpi' => 'watch']); + $this->show_json([],200,'操作成功'); + }else{ + $this->show_json([],400,'参数错误'); + } + } +} diff --git a/home/controllers/h5/market/sylive2/Biz.php b/home/controllers/h5/market/sylive2/Biz.php new file mode 100644 index 00000000..3264055d --- /dev/null +++ b/home/controllers/h5/market/sylive2/Biz.php @@ -0,0 +1,77 @@ +data['multi_org'] = $_SESSION[self::SESSION_KEY]['multi_org'] ? 1 : 0; + $this->show_view('h5/market/sylive2/biz/index'); + } + + public function act_list(){ + $page = $this->input->get('page'); + $size = $this->input->get('size'); + !$page && $page = 1; + !$size && $size = 20; + $where = [ + 'userId' => $this->uid, + 'status' => 0, + ]; + $total = $this->groups_user_model->count($where); + $rows = $this->groups_user_model->select($where,'activityId desc',$page,$size); + $lists = []; + if($rows){ + $act_ids = implode(',',array_unique(array_column($rows,'activityId'))); + $act_rows = []; + if($act_ids){ + $where = [ + "activityId in ({$act_ids})" => null, + ]; + } + $act_ids && $act_rows = $this->market_sylive_activity_model->map('activityId','',$where,'','','','activityId,title,timeStart,timeEnd,jsondata'); + foreach ($rows as $item) { + $act = $act_rows[$item['activityId']] ? $act_rows[$item['activityId']][0] : []; + if($act){ + $jsondata = json_decode($act['jsondata'],true); + $banner = $jsondata['banner'] ? build_qiniu_image_url($jsondata['banner']) : ''; + $lists[] = [ + 'title' => $act['title'], + 'img' => $banner, + 'time' => date('Y-m-d H:i',strtotime($act['timeStart'])).'-'.date('Y-m-d H:i',strtotime($act['timeEnd'])), + 'url' => "/h5/market/sylive2/biz/userinfo?a_id={$item['activityId']}" + ]; + } + } + } + $data = [ + 'list' => $lists, + 'total' => $total + ]; + $this->show_json($data,200); + } + + //获取微信用户信息 + public function userinfo(){ + if(!$_SESSION[self::SESSION_KEY]['all_info']){ + $ret = $this->set_auth('',1); + if($ret){ + $update = [ + "sex" => $ret['sex'] ? 1 : 0, + ]; + $ret['nickname'] && $update['nickname'] = strval($ret['nickname']); + $ret['headimgurl'] && $update['headimg'] = strval($ret['headimgurl']); + $ret['unionid'] && $update['unionid'] = $ret['unionid']; + $this->user_model->update($update,['userId'=>$this->uid]); + } + $_SESSION[self::SESSION_KEY]['all_info'] =1; + } + $a_id = $this->input->get('a_id'); + $my_url = http_host_com('home')."/h5/market/sylive2/stic?a_id={$a_id}"; + redirect($my_url); + } +} \ No newline at end of file diff --git a/home/controllers/h5/market/sylive2/Common.php b/home/controllers/h5/market/sylive2/Common.php new file mode 100644 index 00000000..11a503e9 --- /dev/null +++ b/home/controllers/h5/market/sylive2/Common.php @@ -0,0 +1,281 @@ +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_groups_model', 'groups_model'); + $this->load->model('market/market_sylive_groups_user_model', 'groups_user_model'); + $this->load->model('market/market_sylive_activity_model'); + + $this->load->library('hd_exception'); + $this->load->library('MyEncryption'); + session_start(); + if ($_SESSION[self::SESSION_KEY]) { + $this->session = $_SESSION[self::SESSION_KEY]; + $this->uid = $this->session['userId']; + $this->act_uid = $this->session['act_uid']; + } + } + + /** + * @param $view + */ + protected function show_view($view){ + $this->load->view('h5/market/sylive2/header',$this->data); + $this->load->view($view); + $this->load->view('h5/market/sylive2/footer'); + } + + /** + * @param $data + * @param int $code + * @param string $msg + * @param string $url + */ + protected function show_json($data, $code = 200, $msg = 'success', $url = '') + { + if(!isset($data['code'])){ + $data = array('data' => $data, 'code' => $code, 'msg' => $msg, 'url' => $url); + } + + exit(json_encode($data)); + } + + /** + * @param $url 回调url地址 + * @param $auth 是否信息授权 + * @return void + * @throws Hd_exception + */ + protected function set_auth($url='',$auth=0){ + $this->load->helper('url'); + $this->load->config('wechat'); + $config = $this->config->item('hdy'); + $code = $this->input->get('code'); + !$url && $url = http_host_com('home').$_SERVER['REQUEST_URI']; + $auth && $url = $_SERVER['QUERY_STRING'] ? $url."&auth={$auth}" : $url."?auth={$auth}"; + if ($code) {//授权码获取微信信息 + $auth_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$config['appid']}&secret={$config['appSecret']}&code={$code}&grant_type=authorization_code"; + $res = file_get_contents($auth_url); + $ret = json_decode($res, true); + $access_token = $ret['access_token']; + $openid = $ret['openid']; + $unionid = $ret['unionid']; + if($this->input->get('auth') && $access_token){ + $u_info_url = "https://api.weixin.qq.com/sns/userinfo?access_token={$access_token}&openid={$openid}&lang=zh_CN"; + $u_ret = file_get_contents($u_info_url); + $ret = json_decode($u_ret,true); + } + if(!$openid){ + debug_log("[error]# " . $res, __FUNCTION__, $this->log_dir); + throw new Hd_exception('获取用户信息失败', 400); + } + return $ret; + } elseif ($auth) {//信息授权获取用户微信昵称/头像 + $redirect_uri = urlencode($url); + $auth_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$config['appid']}&redirect_uri={$redirect_uri}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect&forcePopup=true"; + redirect($auth_url); + } else{//静默授权获取用户openid + $redirect_uri = urlencode($url); + $auth_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$config['appid']}&redirect_uri={$redirect_uri}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"; + redirect($auth_url); + } + } + //微信分享信息 + protected function share_info($act_row=[]){ + $a_id = $act_row['activityId']; + $share_skey = "a_id=" . $a_id . "&cf_uid=" . $this->uid; + $this->load->library('Jssdk'); + $jssdk = new Jssdk('liche'); + $sign_package = $jssdk->getSignPackage(); + $share = []; + if($act_row){ + //微信分享 + $share_url = http_host_com('home') . "/h5/market/sylive2/act?skey=" . $this->myencryption->base64url_encode($share_skey); + $shareTitle = $act_row['shareTitle'] ? json_decode($act_row['shareTitle'],true) : []; + $share = array( + 'title' => $act_row['title'], + "img" => $act_row['sharePhoto'] ? build_qiniu_image_url($act_row['sharePhoto']) : '', + "desc" => $shareTitle[array_rand($shareTitle)], + "url" => $share_url + ); + } + return ['sign_package' => $sign_package ,'share' => $share]; + } + + /** + * 微信下单 + * @param $trade_no + * @param $price + * @param $openid + * @param $body + * @param $notify_url + * @param $expire_time + * @param $attach + * @param $wx_type + * @param $other_data + * @return array|false + * @throws WxPayException + */ + protected function unorder($trade_no,$price,$openid,$body,$notify_url,$expire_time,$other_data=[]){ + if(!$body){return false;} + require_once APPPATH."../api/third_party/WXpay/WxPay.Api.php"; + if($other_data['pay_config'] && file_exists($other_data['pay_config'])){ + require_once $other_data['pay_config']; + }else{ + require_once APPPATH."../api/third_party/WXconfig/hdy_WxPay.Config.php"; + } + $config = new WxPayConfig(); + $wxpay = new WxPayUnifiedOrder(); + $wxpay->SetVersion('1.0'); + $wxpay->SetBody($body); //简单描述 + $other_data['attach'] && $wxpay->SetAttach($other_data['attach']); //附加信息 + $wxpay->SetNotify_url($notify_url); + $wxpay->SetOut_trade_no($trade_no); //订单号 + $wxpay->SetTotal_fee($price * 100); //支付价格 + $wxpay->SetTime_start(date("YmdHis")); //交易起始时间 + $wxpay->SetTime_expire(date('YmdHis',$expire_time)); //交易结束时间 + $wxpay->SetTrade_type("JSAPI"); //设置交易类型 + $wxpay->SetOpenid($openid); //openid + $return = WxPayApi::unifiedOrder($config, $wxpay); //统一支付 + if($return['result_code'] == 'SUCCESS') { + $wxpay_api = new WxPayJsApiPay(); + $jsApiParameters = WxPayApi::GetJsApiParameters($return, $config, $wxpay_api); + $jsApiParameters = json_decode($jsApiParameters, true); + return ['code'=>1,'data'=>$jsApiParameters,'msg'=>'下单成功']; + }else{ + $msg = $return['return_msg'] ? $return['return_msg'].$return['err_code_des'] : $return['return_msg']; + return ['code'=>0,'data'=>[],'msg'=>$msg]; + } + } +} + +class Admin extends Common{ + const WX_SESSION = "market_wx_info"; + public function __construct(){ + parent::__construct(); + } + + public function _remap($method){ + try{ + $this->session = $_SESSION[self::SESSION_KEY]; + $this->mobile = $this->session['mobile']; + if(!in_array($method,$this->white_login_method) && !$_SESSION[self::SESSION_KEY]['mobile'] && !$this->uid){ + $ret = $this->set_auth(); + $openid = $ret['openid']; + $row_wechat = $this->user_model->get(['openid' => $openid,'status'=>0,'organizationId>'=>0]); + if(!$row_wechat){ + $_SESSION[self::WX_SESSION] = $ret; + header('Location:/h5/market/sylive2/login');exit; + } + $_SESSION[self::SESSION_KEY]['mobile'] = $row_wechat['mobile']; + $org_url = http_host_com('home')."/h5/market/sylive2"; + redirect($org_url); + } + return $this->$method(); + } catch(Hd_exception $e){//处理异常 + $msg = $e->getMessage(); + $data = array('heading' => 'Warning', 'message' => $msg); + return $this->load->view('errors/html/error_404',$data); + } + } + +} + +class Wx extends Common{ + public function __construct(){ + parent::__construct(); + } + + public function _remap($method){ + try{ + if(!$this->act_uid){ + $this->session = $this->uid = ''; + } + if(!in_array($method,$this->white_login_method) && !$this->uid){ + $ret = $this->set_auth(); + $openid = $ret['openid']; + $skey = $this->input->get('skey'); + $param = $this->myencryption->base64url_decode($skey); + //找管理员角色 + $where = [ + 'activityId' => $param['a_id'], + 'status' => 0, + "userId in (select `userId` from lc_market_sylive_user where openid='{$openid}')" => null + ]; + $row_wechat = $this->groups_user_model->get($where); + if(!$row_wechat){ + $row_wechat = $this->user_model->get(['status'=>0,'openid'=>$openid]);//普通用户角色 + } + if(!$row_wechat){ //创建用户 + $add = array( + "openid" => $openid, + "sex" => $ret['sex'] ? 1 : 0, + "createTime" => date('Y-m-d H:i:s') + ); + $ret['nickname'] && $add['nickname'] = strval($ret['nickname']); + $ret['headimgurl'] && $add['headimg'] = strval($ret['headimgurl']); + $ret['unionid'] && $add['unionid'] = $ret['unionid']; + $this->uid = $this->user_model->add($add); + if (!$this->uid) { + debug_log("[error]# " . $this->mdWeixinUsers->db->last_query(), __FUNCTION__, $this->log_dir); + } + }else{ + $this->uid = $row_wechat['userId']; + } + $act_user = $this->act_user_model->get(['activityId'=>$param['a_id'],'userId'=>$this->uid]); + if(!$act_user && $param['a_id']){ + $act_data = [ + 'activityId' => $param['a_id'], + 'userId' => $this->uid, + "createTime" => date('Y-m-d H:i:s') + ]; + $row_wechat['bizId'] && $act_data['bizId'] = $row_wechat['bizId']; + $row_wechat['groupsId'] && $act_data['groupsId'] = $row_wechat['groupsId']; + $row_wechat['levelId1'] && $act_data['levelId1'] = $row_wechat['levelId1']; + $row_wechat['levelId2'] && $act_data['levelId2'] = $row_wechat['levelId2']; + $row_wechat['levelId3'] && $act_data['levelId3'] = $row_wechat['levelId3']; + if($param['cf_uid']){ + $p_act_user = $this->act_user_model->get(['userId'=>$param['cf_uid']],'userId,channelId'); + if($p_act_user['channelId']){ + $act_data['channelId'] = $p_act_user['channelId']; + }else{ + $p_act_user['groupsId'] && $act_data['channelId'] = $p_act_user['userId']; + } + $act_data['pid'] = $p_act_user['userId']; + } + $row_wechat['groupsId'] && $act_data['channelId'] = $this->uid;//管理员自己归属到自己 + $act_user['id'] = $this->act_user_model->add($act_data); + } + $_SESSION[self::SESSION_KEY]['userId'] = $this->uid; + $_SESSION[self::SESSION_KEY]['act_uid'] = $act_user['id']; + echo ("");exit; + } + return $this->$method(); + } catch(Hd_exception $e){//处理异常 + $msg = $e->getMessage(); + $data = array('heading' => 'Warning', 'message' => $msg); + return $this->load->view('errors/html/error_404',$data); + } + } +} diff --git a/home/controllers/h5/market/sylive2/Login.php b/home/controllers/h5/market/sylive2/Login.php new file mode 100644 index 00000000..f837eb0a --- /dev/null +++ b/home/controllers/h5/market/sylive2/Login.php @@ -0,0 +1,159 @@ +load->model('market/market_sylive_user_model', 'user_model'); + $this->load->library('hd_exception'); + } + + public function index(){ + if($this->input->is_ajax_request()){ + $redis = &load_cache('redis'); + $code = $this->input->post('code'); + $mobile = $this->input->post('mobile'); + $key = "sylive_login_code_".$mobile; + if(!$code || $code!=$redis->get($key)){ + $this->show_json('',400,'请输入正确的验证码'); + } + $user=$this->user_model->get(['mobile' => $mobile,'status'=>0,'organizationId>'=>0]); + if(!$user){ + $this->show_json('',400,'用户不存在'); + } + $_SESSION[self::SESSION_KEY] = ['mobile' => $user['mobile']]; + $redis->delete($key); + $this->show_json('',200,'登录成功'); + }else{ + $wx_info = $_SESSION[self::WX_SESSION]; + if($wx_info['nickname'] || $wx_info['headimgurl']){ + $data['auth_userinfo'] = true; + } + //微信分享 + $this->load->library('Jssdk'); + $jssdk = new Jssdk('liche'); + $sign_package = $jssdk->getSignPackage(); + $data['sign_package'] = $sign_package; + $this->load->view('h5/market/sylive2/login',$data); + } + } + //绑定微信openid + private function bind_openid($mobile){ + $wx_info = $_SESSION[self::WX_SESSION]; + if(!$wx_info['openid']){ + return ['code' => 0,'msg' => '不存在公众号信息,无需绑定']; + } + if(!$mobile){ + return ['code' => 0,'msg' => '参数错误']; + } + $is_bind = $this->user_model->count(["openid!=''"=>null,'status'=>0,'mobile'=>$mobile,'organizationId>'=>0]); //已被绑定 + if($is_bind){ + $row = $this->user_model->get(['mobile'=>$mobile,"openid!=''"=>null,'status'=>0]); + if($row['openid']!=$wx_info['openid']){ + return ['code' => 0,'msg' => '该公众号已存在绑定账号']; + } + } + $update = [ + 'openid' => $wx_info['openid'] + ]; + $wx_info['nickname'] && $update['nickname'] = strval($wx_info['nickname']); + $wx_info['headimgurl'] && $update['headimg'] = strval($wx_info['headimgurl']); + $wx_info['unionid'] && $update['unionid'] = $wx_info['unionid']; + $this->user_model->update($update,['mobile'=>$mobile,'status'=>0,'organizationId>'=>0]); + return ['code' => 1,'msg' => '绑定成功']; + } + //获取验证码 + public function get_code(){ + $mobile = $this->input->post('mobile'); + if(!mobile_valid($mobile)){ + $this->show_json('',400,'请输入正确的手机号码'); + } + $user=$this->user_model->get(array('mobile' => $mobile, 'status' => 0,'organizationId>=' => 0)); + + if(!$user){ + $this->show_json('',400,'用户不存在'); + } + $redis = &load_cache('redis'); + $key = "sylive_login_code_".$mobile; + $code = $redis->get($key); + if(!$code){ + $this->load->helper('string'); + $code = random_string('numeric', 4); + $redis->save($key, $code, 60*5); + } + $content = "【好店云】您的验证码为: {$code},五分钟之内有效,请勿泄露于他人,!"; + b2m_send_sms($mobile,$content); + $this->show_json('',200, '验证码已发送'); + } + + private function show_json($data, $code = 200, $msg = 'success', $url = ''){ + if(!isset($data['code'])){ + $data = array('data' => $data, 'code' => $code, 'msg' => $msg, 'url' => $url); + } + + exit(json_encode($data)); + } + + //获取微信用户信息 + public function userinfo(){ + $ret = $this->set_auth('',1); + if($ret){ + $_SESSION[self::WX_SESSION] = $ret; + $mobile = $_SESSION[self::SESSION_KEY]['mobile']; + $this->bind_openid($mobile); + $url = http_host_com('home').'/h5/market/sylive2'; + redirect($url); + } + } + public function logout(){ + $_SESSION[self::SESSION_KEY] = ''; + $this->show_json('',200, '退出成功'); + } + + /** + * @param $url 回调url地址 + * @param $auth 是否信息授权 + * @return void + * @throws Hd_exception + */ + protected function set_auth($url='',$auth=0){ + $this->load->helper('url'); + $this->load->config('wechat'); + $config = $this->config->item('hdy'); + $code = $this->input->get('code'); + !$url && $url = http_host_com('home').$_SERVER['REQUEST_URI']; + $auth && $url = $_SERVER['QUERY_STRING'] ? $url."&auth={$auth}" : $url."?auth={$auth}"; + if ($code) {//授权码获取微信信息 + $auth_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$config['appid']}&secret={$config['appSecret']}&code={$code}&grant_type=authorization_code"; + $res = file_get_contents($auth_url); + $ret = json_decode($res, true); + $access_token = $ret['access_token']; + $openid = $ret['openid']; + $unionid = $ret['unionid']; + if($this->input->get('auth') && $access_token){ + $u_info_url = "https://api.weixin.qq.com/sns/userinfo?access_token={$access_token}&openid={$openid}&lang=zh_CN"; + $u_ret = file_get_contents($u_info_url); + $ret = json_decode($u_ret,true); + } + if(!$openid){ + debug_log("[error]# " . $res, __FUNCTION__, $this->log_dir); + throw new Hd_exception('获取用户信息失败', 400); + } + return $ret; + } elseif ($auth) {//信息授权获取用户微信昵称/头像 + $redirect_uri = urlencode($url); + $auth_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$config['appid']}&redirect_uri={$redirect_uri}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect&forcePopup=true"; + redirect($auth_url); + } elseif (!$this->session) {//静默授权获取用户openid + $redirect_uri = urlencode($url); + $auth_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$config['appid']}&redirect_uri={$redirect_uri}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"; + redirect($auth_url); + } + } +} diff --git a/home/controllers/h5/market/sylive2/Stic.php b/home/controllers/h5/market/sylive2/Stic.php new file mode 100644 index 00000000..39236960 --- /dev/null +++ b/home/controllers/h5/market/sylive2/Stic.php @@ -0,0 +1,537 @@ +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'); + $this->load->library('market/sylive_entity'); + $this->load->library('market/sylive2_entity'); + $this->load->library('market/sylive2_data_entity'); + $this->a_id = $this->input->get('a_id'); + $this->a_id && $_SESSION[self::SESSION_KEY]['a_id'] = $this->a_id; + !$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}"; + } + + 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); + } + $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']; + $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')); + $info['groupsId'] = $groupsId ? $groupsId : $group_user['groupsId']; + $info['is_biz'] = $group_user['bizId'] ? 1 : 0; + $info['tab'] = time()>=strtotime($row['timeStart']) ? 2 : 1; + $this->data['info'] = $info; + //微信分享 + $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/sylive2/stic/index'); + } + //预约阶段数据 + public function lists_ready(){ + $groupsId = $this->input->get('groupsId'); + $group_user = $this->groups_user_model->get(['activityId'=>$this->a_id,'userId'=>$this->uid]); + !$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++){ + $where = [ + 'activityId' => $this->a_id, + 'groupsLevel' => $i + ]; + $level_total = $this->groups_model->count($where); + $title = $disk[$i] ? $disk[$i] : "{$i}级"; + $h_lists[] = ['title'=> '参与'.$title,'num'=>"{$level_total}个"]; + } + } + $where = [ + 'activityId' => $this->a_id, + 'status' => 0, + 'ifBiz>' => 0 + ]; + $biz_total = $this->groups_model->count($where); + $where = [ + 'activityId' => $this->a_id, + 'status' => 0, + 'bizId>' => 0 + ]; + $gw_total = $this->groups_user_model->count($where); + $where["userId in (select cfUserId from lc_market_sylive_activity_kpidata where activityId={$this->a_id})"] = null; + $kgw_total = $this->groups_user_model->count($where); + $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, + 'kpi' => 'browse', + 'cfUserId' => $this->uid, + ]; + $owner_browse_count = $this->mdSytActivityKpiData->count($where); //浏览数据 + $where['kpi'] = 'subscribe'; + $owner_subscribe_count = $this->mdSytActivityKpiData->count($where); //订阅数据 + $mine = [ + ['title'=>'访问用户','num'=>"{$owner_browse_count}人",'url'=>'/h5/market/sylive2/stic/users?type=owner&kpi=browse'], + ['title'=>'预约用户','num'=>"{$owner_subscribe_count}人",'url'=>'/h5/market/sylive2/stic/users?type=owner&kpi=subscribe'], + ['title'=>'预约率','num'=>$owner_browse_count ? round($owner_subscribe_count/$owner_browse_count*100,2)."%" : 0], + ]; + $sub_lists = [ + ['title'=>'我的','lists'=>$mine], + ]; + if($group_user['bizId']){ + $where = [ + 'activityId' => $this->a_id, + 'kpi' => 'browse', + 'bizId' => $group_user['bizId'], + ]; + $biz_browse_count = $this->mdSytActivityKpiData->count($where); //浏览数据 + $where['kpi'] = 'subscribe'; + $biz_subscribe_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_subscribe_count}人",'url' => "/h5/market/sylive2/stic/users?type=biz&type_id={$group_user['bizId']}&kpi=subscribe"], + ['title'=>'预约率','num'=>$biz_browse_count ? round($biz_subscribe_count/$biz_browse_count*100,2)."%" : 0], + ]; + $sub_lists[] = ['title'=>'本店','lists'=>$biz]; + } + if(!$group_row['ifBiz']){ //当前等级 + if(!$group_row['groupsLevel']){//顶级 + $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'];//浏览数据 + $subscribe_count = $sub_sum['subscribe'];//订阅数据 + }else{ + $browse_count = $group_row['browse'];//浏览数据 + $subscribe_count = $group_row['subscribe'];//订阅数据 + } + $biz = [ + ['title'=>'访问用户','num'=>"{$browse_count}人"], + ['title'=>'预约用户','num'=>"{$subscribe_count}人"], + ['title'=>'预约率','num'=>$browse_count ? round($subscribe_count/$browse_count*100,2)."%" : 0], + ]; + $sub_lists[] = ['title'=>"所有大区",'lists'=>$biz]; + } + $data = [ + 'h_lists' => $h_lists, + 'sub_lists' => $sub_lists, + ]; + $this->show_json($data,200); + } + + //直播统计数据 + public function lists_live(){ + $groupsId = $this->input->get('groupsId'); + $group_user = $this->groups_user_model->get(['activityId'=>$this->a_id,'userId'=>$this->uid]); + !$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]); + //我的 + $where = [ + 'activityId' => $this->a_id, + 'kpi' => 'watch', + 'cfUserId' => $this->uid, + ]; + $owner_browse_count = $this->mdSytActivityKpiData->count($where); //浏览数据 + $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], + ]; + $sub_lists = [ + ['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"; + $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); + $h_lists = [ + ['title' => '直播时长', 'num' => "{$duration}分钟"], + ['title' => '人均观看', 'num' => "{$avg_UV_time}分钟"], + ['title' => '观看次数', 'num' => "{$livePV}次"], + ]; + if($group_user['bizId']){ //门店和顾问 + $biz_id = $group_user['bizId']; + $where = [ + 'activityId' => $this->a_id, + 'kpi' => 'watch', + 'bizId' => $biz_id, + ]; + $biz_browse_count = $this->mdSytActivityKpiData->count($where); //观看数据 + $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], + ]; + $sub_lists[] = ['title'=>'本店','lists'=>$biz]; + } + if(!$group_row['ifBiz']){ //当前等级 + if(!$group_row['groupsLevel']){//顶级 + $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'];//观看数据 + $subscribe_count = $sub_sum['orderTotal'];//下单数据 + }else{ + $browse_count = $group_row['watch'];//观看数据 + $subscribe_count = $group_row['orderTotal'];//下单数据 + } + $biz = [ + ['title'=>'观看用户','num'=>"{$browse_count}人"], + ['title'=>'下单数','num'=>"{$subscribe_count}人"], + ['title'=>'转化率','num'=>$browse_count ? round($subscribe_count/$browse_count*100,2)."%" : 0], + ]; + $sub_lists[] = ['title'=>"所有大区",'lists'=>$biz]; + } + $data = [ + 'h_lists' => $h_lists, + 'sub_lists' => $sub_lists, + ]; + $this->show_json($data,200); + } + + public function event(){ + $map_kpi_name = [ + '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]); + $group_user = $this->groups_user_model->get(['activityId'=>$this->a_id,'userId'=>$this->uid]); + $where = [ + 'activityId'=>$this->a_id, + 'bizId'=>$group_user['bizId'], + ]; + if($type==1){ //预热 + $where['createTime<='] = strtotime($row['timeStart']); + }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'); + $users = []; + $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'); + } + foreach ($rows as $key => $val) { + $nickname = $users[$val['userId']] ? $users[$val['userId']] : "用户{$val['userId']}"; + $lists[] = [ + 'nickname' => $nickname, + 'action' => $map_kpi_name[$val['kpi']], + 'time' => friendly_date($val['createTime']), + ]; + } + } + $data = [ + 'lists' => $lists, + 'total' => $total + ]; + $this->show_json($data,200); + } + + public function users(){ + $map_kpi_name = [ + '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); + } + $title = $map_kpi_name[$params['kpi']]; + $tab = [ + ['id'=>1,'title'=>'客户列表'] + ]; + if($params['type']=='biz' && $params['type_id']){ //显示顾问数据 + $tab[] = ['id'=>2,'title'=>'顾问数据']; + } + $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'); + } + $this->data['title'] = $title; + $this->data['tab'] = $tab; + $this->data['params'] = $params; + $this->data['goods'] = $goods; + //微信分享 + $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/sylive2/stic/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' => 0, + 'activityId' => $this->a_id, + 'kpi' => $params['kpi'], + ]; + if($params['type']=='biz'){ + $where['bizId'] = $params['type_id']; + }else{ + $where['cfUserId'] = $this->uid; + } + 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); + } + $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) { + $jsondata = json_decode($item['jsondata'],true); + $user = $users[$item['userId']] ? $users[$item['userId']][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($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'); + $name = $order['uname'] ? $order['uname'] : ''; + $mobile = $order['mobile'] ? $order['mobile'] : ''; + } + $lists[] = [ + 'nickname' => $nickname, + 'name' => $name, + 'mobile' => $mobile, + 'headimg' => $headimg, + 'cf_uname' => $cf_uname, + 'time' => friendly_date($item['createTime'],'normal',1) + ]; + } + } + $data = [ + 'total' => $total, + 'lists' => $lists + ]; + $this->show_json($data,200); + } + + public function gw_lists(){ + $params = $this->input->get(); + $page = $params['page'] ? $params['page'] : 1; + $size = $params['size'] ? $params['size'] : 20; + $where = [ + 'activityId' => $this->a_id, + 'kpi' => $params['kpi'] + ]; + if($params['type']=='biz' && $params['type_id']){ + $biz_id = $params['type_id']; + $where['bizId'] = $biz_id; + } + $params['itemId'] && $where['itemId'] = $params['itemId']; + $groupby = 'cfUserId'; + $teamId = $this->uid; + $select = 'bizId as teamId2,cfUserId,count(id) as t'; + $order = 't desc,id desc'; + $res = $this->sylive2_data_entity->top_kpidata($groupby,$where,$order,$page,$size,$select,$teamId); + $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); + } + + //分组列表 + public function group_lists(){ + $params = $this->input->get(); + $page = $params['page'] ? $params['page'] : 1; + $size = 20; + + $disk = $this->sylive2_entity->level_disk($this->a_id); + $where = [ + 'activityId' => $this->a_id, + 'parentId' => $params['groupsId'], + 'status' => 0 + ]; + $total = $this->groups_model->count($where); + $rows = $this->groups_model->select($where,'sortNumber desc',$page,$size); + $lists = []; + if($rows){ + foreach ($rows as $item) { + $count = $this->groups_model->count(['activityId'=>$this->a_id,'status'=>0,'parentId'=>$item['groupsId']]); + $lists[] = [ + 'title' => $item['groupsName'], + 'note' => $disk[$item['groupsLevel']+1] ? $disk[$item['groupsLevel']+1]:'下一级组员', + 'num' => $count, + 'url' => $item['groupsLevel']<3 ? "/h5/market/sylive2/stic?groupsId={$item['groupsId']}" : '', + ]; + } + } + $data = [ + 'total' => $total, + 'list' => $lists + ]; + $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); + } + $jsondata = json_decode($row['jsondata'],true); + $info['banner'] = $jsondata['banner'] ? build_qiniu_image_url($jsondata['banner']) : Sylive_entity::DF_BANNER; + $this->data['info'] = $info; + $day_list = ['全部']; + $timeEnd = strtotime($row['timeEnd']);//直播结束往前七天 + for($i=0;$i<8;$i++){ + $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'] + ]; + } + } + $this->data['groups'] = $groups; + //微信分享 + $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/sylive2/stic/ranking'); + } + + public function ajax_rank(){ + $map_kpi_biz = [ + 'browse' => 'browse', 'subscribe' => 'subscribe', 'order' => 'orderTotal','watch' => 'watch' + ]; + $params = $this->input->get(); +// $title = $params['gtype']=='gw' ? '顾问' : '门店'; + $title = ''; + $title_arr = [ + 'browse' => $title.'浏览排行', + 'subscribe' => $title.'预约排行', + 'watch' => $title.'观看排行', + 'order' => $title.'订单排行' + ]; + $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'])){//根据日期排行 + $kpi = $params['kpi']; + $select = "bizId,count(id) as t"; + $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']); + }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']); + } + $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"; + $this->show_json($data,200); + } + + 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); + } + $day_list = ['全部']; + $timeEnd = strtotime($row['timeEnd']);//直播结束往前七天 + for($i=0;$i<8;$i++){ + $day_list[] = date('Y-m-d',$timeEnd - $i*24*60*60); + } + $this->data['day_list'] = $day_list; + $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/sylive2/stic/rank'); + } +} \ No newline at end of file diff --git a/home/controllers/h5/market/sylive2/Ucenter.php b/home/controllers/h5/market/sylive2/Ucenter.php new file mode 100644 index 00000000..f6fd7783 --- /dev/null +++ b/home/controllers/h5/market/sylive2/Ucenter.php @@ -0,0 +1,210 @@ +load->model('market/market_sylive_items_model'); + $this->load->model('market/market_sylive_order_model'); + $this->load->model('market/market_sylive_activity_model'); + $this->load->library('market/sylive_entity'); + $this->skey = $this->input->get('skey'); + $param = $this->myencryption->base64url_decode($this->skey); + $this->a_id = intval($param['a_id']);//活动id + $this->data['skey'] = $this->skey; + } + + public function index(){ + $params = $this->input->get(); + $row = $this->market_sylive_activity_model->get(['activityId'=>$this->a_id]); + if(!$row){ + throw new Hd_exception('参数错误',400); + } + $jsondata = json_decode($row['jsondata'],true); + $lists = []; + + $lists[] = ['title'=>'我的权益','url'=>"/h5/market/sylive2/ucenter/orders?skey={$params['skey']}"]; + $lists[] = ['title'=>'我的抽奖','url'=>"/h5/market/sylive2/ucenter/win?skey={$params['skey']}"]; + $jsondata['serviceLink'] && $lists[] = ['title'=>'联系客服','url'=>$jsondata['serviceLink']]; + + $user = $this->user_model->get(['userId'=>$this->uid],'unionid,nickname,headimg'); + $info = [ + 'title' => $user['nickname'], + 'logo' => $user['headimg'], + 'list' => $lists + ]; + $this->data['info'] = $info; + $this->data['params'] = $params; + $this->show_view('h5/market/sylive2/ucenter/index'); + } + + //我的抽奖 + public function win(){ + $this->show_view('h5/market/sylive2/ucenter/win'); + } + + public function ajax_win(){ + $params = $this->input->get(); + $page = $params['page'] ? $params['page'] : 1; + $size = $params['size'] ? $params['size'] : 20; + $where = [ + 'activityId' => $this->a_id, + 'userId' => $this->uid, + 'win' => 1 + ]; + $total = $this->market_sylive_order_model->count($where);; + $lists = []; + if($total){ + $rows = $this->market_sylive_order_model->select($where,'id desc',$page,$size,'id,sid,winType'); + foreach ($rows as $key => $val) { + $winType = $this->market_sylive_order_model->winTypeAry($this->a_id,$val['winType']); + $lists[] = [ + 'id' => $val['id'], + 'img' => $winType['img'], + 'title' => $winType['tag'], + 'goods' => $winType['title'] + ]; + } + } + $data = [ + 'total' => $total, + 'lists' => $lists + ]; + $this->show_json($data,200); + } + //我的订单 + public function orders(){ + $this->show_view('h5/market/sylive2/ucenter/orders'); + } + + //订单详情 + public function detail(){ + $oid = $this->input->get('id'); + $order = $this->market_sylive_order_model->get(['id'=>$oid,'userId' => $this->uid]); + if(!$order){ + throw new Hd_exception('参数错误',400); + } + $item = $this->market_sylive_items_model->get(['itemId'=>$order['itemId']]); + $validity = ''; + if($item['useStart'] || $item['useEnd']){ + $useTimeStart = date('Y-m-d',strtotime($item['useStart'])); + $useTimeEnd = date('Y-m-d',strtotime($item['useEnd'])); + $validity = "有效期 {$useTimeStart} - {$useTimeEnd}"; + } + $order_jsondata = json_decode($order['jsondata'],true); + $order = [ + 'id' => $order['id'], + 'uname' => $order['uname'] ? $order['uname'] : '', + 'utel' => $order['mobile'] ? $order['mobile'] : '', + 'slogan' => '尊享您的直播好礼', + 'valid_time' => $validity, + 'sid' => $order['sid'], + 'c_time' => date('Y-m-d H:i:s'), + 'region' => $order_jsondata['address']['region'] ? $order_jsondata['address']['region'] : '', + 'detail' => $order_jsondata['address']['detail'] ? $order_jsondata['address']['detail'] : '' + ]; + $if_pid = 0; + $ac_user = $this->act_user_model->get(['userId'=>$this->uid,'activityId'=>$this->a_id],'channelId'); + $ac_user['channelId'] && $pid_user = $this->user_model->get(['userId'=>$ac_user['channelId']],'uname,organizationId,mobile,headimg'); + $logo = $gw_tel = $gw_slogan = $gw_title = ''; + if($ac_user['channelId'] && $pid_user['organizationId']>0){ + $group_id = $this->sylive_entity->get_level($pid_user['organizationId']); + if($group_id==3){ //顾问 + $if_pid = 1; + $where = [ + "organizationId in (select parentId from lc_market_sylive_organization where organizationId={$pid_user['organizationId']})" => null + ]; + $org = $this->market_sylive_organization_model->get($where); + }elseif($group_id==2){ //店长 + $if_pid = 1; + $where = [ + "organizationId" => $pid_user['organizationId'] + ]; + $org = $this->market_sylive_organization_model->get($where); + } + $gw_title = $pid_user['uname']; + $gw_slogan = $org['organizationName']; + $gw_tel = $pid_user['mobile']; + $logo = $pid_user['headimg']; + } + $info = [ + 'bg' => "https://qs.haodian.cn/web/images/project/H5-ShiYu/mine-bg.jpg", + 'logo' => $logo, + 'if_pid' => $if_pid, + 'title' => $gw_title, + 'slogan' => $gw_slogan, + 'cust_tel' => $gw_tel, + 'introTitle' => '权益说明', + 'content' => $item['descrip'] ? $item['descrip'] : '', + 'order' => $order, + 'skey' => $this->data['skey'], + 'ifAddress' => $item['ifAddress'] + ]; + $this->data['info'] = $info; + $this->show_view('h5/market/sylive2/ucenter/detail'); + } + + public function ajax_order(){ + $params = $this->input->get(); + $page = $params['page'] ? $params['page'] : 1; + $size = $params['size'] ? $params['size'] : 20; + $where = [ + 'activityId' => $this->a_id, + 'userId' => $this->uid, + 'type' => 0, + 'status' => 1 + ]; + $total = $this->market_sylive_order_model->count($where); + $lists = []; + if($total){ + $rows = $this->market_sylive_order_model->select($where,'id desc',$page,$size); + $item_ids = implode(',',array_unique(array_column($rows,'itemId'))); + $item_rows = []; + if($item_ids){ + $item_rows = $this->market_sylive_items_model->map('itemId','',["itemId in ({$item_ids})"],'',0,0,'itemId,imgs'); + } + foreach ($rows as $val) { + $item = $item_rows[$val['itemId']] ? $item_rows[$val['itemId']][0] : []; + $imgs = json_decode($item['imgs'],true); + $img = $imgs['banner'][0] ? build_qiniu_image_url($imgs['banner'][0]) : ''; + $lists[] = [ + 'sid' => $val['sid'], + 'img' => $img, + 'title' => $val['itemTitle'], + 'time' => date('Y.m.d H:i:s',strtotime($val['createTime'])), + 'price' => $val['totalPrice'], + 'url' => "/h5/market/sylive2/ucenter/detail?skey={$this->skey}&id={$val['id']}" + ]; + } + } + $data = [ + 'total' => $total, + 'lists' => $lists + ]; + $this->show_json($data,200); + } + + //修改地址 + public function edit_address(){ + $params = $this->input->post(); + if(!$params['region']||!$params['address']){ + $this->show_json([],400,'参数错误'); + } + $order = $this->market_sylive_order_model->get(['userId'=>$this->uid,'status'=>1,'id'=>$params['id']]); + if(!$order){ + $this->show_json([],400,'订单不存在'); + } + $jsondata = json_decode($order['jsondata'],true); + $jsondata['address']['region'] = $params['region']; + $jsondata['address']['detail'] = $params['address']; + $update = [ + 'jsondata' => json_encode($jsondata,JSON_UNESCAPED_UNICODE) + ]; + $this->market_sylive_order_model->update($update,['id'=>$order['id']]); + $this->show_json([],200,'保存成功'); + } +} diff --git a/home/controllers/h5/market/sylive2/Welcome.php b/home/controllers/h5/market/sylive2/Welcome.php new file mode 100644 index 00000000..614f14dc --- /dev/null +++ b/home/controllers/h5/market/sylive2/Welcome.php @@ -0,0 +1,53 @@ +load->model('market/market_sylive_organization_model'); + $this->load->library('market/sylive_entity'); + } + + public function index(){ + $where = [ + 'mobile' => $this->mobile, + 'organizationId>' => 0, + 'status' => 0 + ]; + $gu_rows = $this->user_model->select($where,'userId desc','','','userId,mobile,organizationId'); + if(count($gu_rows)>1){ //多个机构 + $org_lists = []; + foreach ($gu_rows as $key => $val) { + $levl_rows = $this->sylive_entity->get_level_lists($val['organizationId']); + $levl_top = $levl_rows[0]; + $temp = [ + 'logo' => $levl_top['logo'] ? build_qiniu_image_url($levl_top['logo']) : '', + 'url' => "/h5/market/sylive2/welcome/org?org_id={$levl_top['organizationId']}&userId={$val['userId']}" + ]; + + $org_lists[$temp['organizationId']] = $temp; + } + $_SESSION[self::SESSION_KEY]['multi_org'] = 1; + $this->data['org_lists'] = $org_lists; + //微信分享 + $wx_info = $this->share_info(); + $this->data['sign_package'] = $wx_info['sign_package']; + $this->show_view('h5/market/sylive2/index'); + }else{ //只存在一个机构 + $levl_rows = $this->sylive_entity->get_level_lists($gu_rows[0]['organizationId']); + $levl_top = $levl_rows[0]; + $org_url = http_host_com('home')."/h5/market/sylive2/welcome/org?org_id={$levl_top['organizationId']}&userId={$gu_rows[0]['userId']}"; + redirect($org_url); + } + } + //登录机构 + public function org(){ + $this->session['org_id'] = $this->input->get('org_id'); + $this->session['userId'] = $this->input->get('userId'); + $_SESSION[self::SESSION_KEY] = $this->session; + $org_url = http_host_com('home')."/h5/market/sylive2/biz"; + redirect($org_url); + } +} diff --git a/home/views/h5/market/sylive2/act/index.php b/home/views/h5/market/sylive2/act/index.php new file mode 100644 index 00000000..7bba1c18 --- /dev/null +++ b/home/views/h5/market/sylive2/act/index.php @@ -0,0 +1,249 @@ +
+ +