From af09a0b2e9d6c4ccbf225052321b579b8804775c Mon Sep 17 00:00:00 2001 From: lccsw <805383944@qq.com> Date: Thu, 29 Sep 2022 16:57:13 +0800 Subject: [PATCH] edit-market-sylive --- api/controllers/plan/Plan.php | 3 + api/controllers/plan/Syt.php | 72 ++++++++++++++------- home/controllers/h5/market/sylive/Act.php | 34 +++++++--- home/controllers/h5/market/sylive/Stic.php | 16 +++-- home/views/h5/market/sylive/act/index.php | 17 +++-- home/views/h5/market/sylive/act/ucenter.php | 3 +- home/views/h5/market/sylive/header.php | 2 +- home/views/h5/market/sylive/login.php | 2 +- home/views/h5/market/sylive/stic/area.php | 1 + www/home/css/h5/market/sylive/h5.css | 2 +- 10 files changed, 107 insertions(+), 45 deletions(-) diff --git a/api/controllers/plan/Plan.php b/api/controllers/plan/Plan.php index 558034a9..b14d1c8b 100644 --- a/api/controllers/plan/Plan.php +++ b/api/controllers/plan/Plan.php @@ -50,6 +50,9 @@ class Plan extends CI_Controller $plan[] = array('url' => base_url(array('plan', 'biz', 'merge')), 'interval' => 20); //合并结算 $plan[] = array('url' => base_url(array('plan', 'order', 'up_old_status')), 'interval' => 30); //更新旧订单状态 $plan[] = array('url' => base_url(array('plan', 'order', 'out_time')), 'interval' => 10); //未支付订单过期 + + $plan[] = array('url' => base_url(array('plan', 'syt', 'subscribemsg')), 'interval' => 60); //私域通模板消息 + $plan[] = array('url' => base_url(array('plan', 'syt', 'syn_polyv')), 'interval' => 1); //私域通直播间数据同步 $this->plan = $plan; } diff --git a/api/controllers/plan/Syt.php b/api/controllers/plan/Syt.php index 00aa8bb4..a0a78023 100644 --- a/api/controllers/plan/Syt.php +++ b/api/controllers/plan/Syt.php @@ -10,6 +10,7 @@ require_once(COMMPATH . "/third_party/WeChat/WechatServer.php"); class Syt extends CI_Controller { private $log_file = 'plan_syt.log'; + private $log_dir = 'market/sylive'; private $options; public function __construct() { @@ -21,6 +22,9 @@ class Syt extends CI_Controller 'encodingaeskey' => '', 'debug' => false ]; + $this->load->model('market/market_sylive_activity_model'); + $this->load->model('live/Live_polyv_session_model', 'mdPolyvSession'); + $this->load->library('PolyvApi'); } /** @@ -76,29 +80,51 @@ class Syt extends CI_Controller debug_log("[info] " . __FUNCTION__ . "# date:{$date}; total:{$total}; do:{$do};", $this->log_file); } - public function test(){ - require_once(COMMPATH . "/third_party/WeChat/WechatServer.php"); - $options = [ - 'token' => '', - 'appid' => 'wxe66f905683582780', - 'appsecret' => '9546cd4de877be13ce203f3e6140633f', - 'encodingaeskey' => '', - 'debug' => false + public function syn_polyv(){ + $where = [ + 'status' => 0, + "channelId <> ''" => null, + "timeStart<" => date('Y-m-d H:i:s'), + "timeStart>" => date('Y-m-d H:i:s',strtotime("-1 day")) ]; - $wechatS = new WechatServer($options); - $token = $wechatS->checkAuth(); - $content = '您预约直播已经开始啦!赶紧进入直播间观看直播领取福利吧~'; - $temp_arr = array( - 'touser' => 'ospBg6AXMlXNdgv_rzbFvBXAD4TU', - 'template_id' => '4eHuGYK69_GTjOlzkp8HK8iJNFuKboTpO7Igc1CC_fQ', - 'url' => 'https://liche-dev.xiaoyu.com/h5/market/sylive/act?skey=aWQ9MQ', - 'scene' => 0, - 'title' => '开播提醒', - 'data' => array( - 'content' => array('value' => $content) - ) - ); - $re = $wechatS->subscribeTemplateMessage($temp_arr); - } + $rows = $this->market_sylive_activity_model->select($where,'activityId desc',1,20,'activityId,channelId'); + if($rows){ + foreach ($rows as $item) { + debug_log("开始同步{$item['activityId']}活动直播",$this->log_file,$this->log_dir); + $polyv = new PolyvApi(['channel_id' => $item['channelId']]); + $pl_where = [ + 'startTime' => strtotime($item['timeStart']), + 'endTime' => strtotime($item['timeEnd']) + ]; + $results = $polyv->getSessionStats($pl_where); + if ($results['status'] == 'success') { + foreach ($results['data']['list'] as $key => $value) { + $re = $this->mdPolyvSession->get(['channelId' => $item['channelId'], 'sessionId' => $value['sessionId']]); + $data = [ + 'channelId' => $value['channelId'], 'sessionId' => $value['sessionId'], 'name' => $value['name'], + 'startTime' => $value['startTime'], 'endTime' => $value['endTime'], 'duration' => $value['duration'], + 'liveUV' => $value['liveUV'], 'livePV' => $value['livePV'], 'playbackUV' => $value['playbackUV'], + 'playbackPV' => $value['playbackPV'], 'totalPlayDuration' => $value['totalPlayDuration'], + 'session_time' => date('Y-m-d H:i:s'), + ]; + if ($re) {//同步更新数据 + $this->mdPolyvSession->update($data, ['id' => $re['id']]); + } else {//新增 + $data['c_time'] = time(); + $this->mdPolyvSession->add($data); + } + } + $msg = "同步成功:".json_encode($results,JSON_UNESCAPED_UNICODE); + echo $msg."
"; + } else { + $msg = "接口错误:".$results['message']; + echo $msg."
"; + } + debug_log($msg,$this->log_file,$this->log_dir); + } + }else{ + echo "暂无同步数据"; + } + } } \ 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 47cf414d..7aa5526e 100644 --- a/home/controllers/h5/market/sylive/Act.php +++ b/home/controllers/h5/market/sylive/Act.php @@ -74,7 +74,7 @@ class Act extends Wx { //直播参数 $live_user = ['userId' => 888888888, 'userName' => '私域直播', 'pic' => '//livestatic.videocc.net/assets/wimages/missing_face.png']; $this->load->library('PolyvApi'); - $polyv = new PolyvApi(); + $polyv = new PolyvApi(['channel_id'=>$row['channelId']]); $liveSdk = $polyv->getLiveSdk(); $liveSdk['user'] = $live_user; $info['live_status'] = $live_status; @@ -89,25 +89,36 @@ class Act extends Wx { } $info['statisticsurl'] = '/h5/market/sylive/stic?skey='.$info['skey']; $info['channelImg'] = build_qiniu_image_url($row['channelImg']); + $info['live_url'] = 'https://live.liche.cn/watch/'.$row['channelId']; $this->data['info'] = $info; $this->data['sign_package'] = $sign_package; $this->data['share'] = $share; + $this->data['_title'] = $row['title']; $this->show_view('h5/market/sylive/act/index'); } //获取最新订阅用户 public function subscribemsg_lists(){ $a_id = $this->input->get('a_id'); - $field = ''; + $field = 'uid,c_time'; $lists = []; $where = [ 'a_id' => $a_id ]; - $rows = $this->mdSytSubscribemsg->select($where,'id desc',0,30,$field); + $rows = $this->mdSytSubscribemsg->select($where,'id desc',1,30,$field); if($rows){ + $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 $item) { + $nickname = $users[$item['uid']] ? $users[$item['uid']] : "用户{$item['uid']}"; $lists[] = [ - 'name' => substr($item['openid'], 0, 3) . "****" . substr($item['openid'], 7, 4), + 'name' => $nickname, 'tip' => friendly_date($item['c_time']).'订阅了直播提醒', ]; } @@ -183,8 +194,12 @@ class Act extends Wx { ]; } } - $user = $this->user_model->get(['userId'=>$this->uid]); - $this->data['posterTip'] = '狸车集美店李菲菲诚挚邀请您参与'; + $user = $this->user_model->get(['userId'=>$this->uid],'uname'); + $where = [ + "organizationId = (select parentId from lc_market_sylive_organization where organizationId={$this->session['org_id']})" => null + ]; + $biz = $this->market_sylive_organization_model->get($where,'organizationName'); + $this->data['posterTip'] = "{$biz['organizationName']}{$user['uname']}诚挚邀请您参与"; $this->data['lists'] = $lists; $this->data['shareTitle'] = $shareTitle; $this->show_view('h5/market/sylive/act/share'); @@ -218,6 +233,7 @@ class Act extends Wx { 'is_pay' => $is_pay ]; $this->data['info'] = $info; + $this->data['_title'] = $row['title']; $this->show_view('h5/market/sylive/act/item'); } @@ -283,13 +299,15 @@ class Act extends Wx { } } $order = $this->market_sylive_order_model->get(['uid'=>$this->uid,'status'=>1,'item_id'=>$a_id]); - $pay_text = $order ? '(已支付)' : '(未支付)'; $info = [ - 'title' => $item['title'].$pay_text, + 'title' => $item['title'], 'content' => $item['introduction'], 'banner' => $banner, + 'state' => $order ? 0 : 1, + 'text' => $order ? '已抢购' : '未抢购' ]; $this->data['info'] = $info; + $this->data['_title'] = $row['title']; $this->show_view('h5/market/sylive/act/ucenter'); } diff --git a/home/controllers/h5/market/sylive/Stic.php b/home/controllers/h5/market/sylive/Stic.php index a46aa8aa..64536f83 100644 --- a/home/controllers/h5/market/sylive/Stic.php +++ b/home/controllers/h5/market/sylive/Stic.php @@ -11,6 +11,8 @@ class Stic extends Admin{ $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('live/Live_polyv_session_model', 'mdPolyvSession'); $this->load->library('market/sylive_entity'); $this->group_id = $this->sylive_entity->get_level($this->session['org_id']); $this->data['skey'] = $this->input->get('skey'); @@ -177,10 +179,14 @@ class Stic extends Admin{ ['title' => '下单用户', 'num' => "{$order_count}人"], ['title' => '转化率', 'num' => $order_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' => "0分钟"], - ['title' => '人均观看', 'num' => "0秒"], - ['title' => '观看次数', 'num' => "0次"], + ['title' => '直播时长', 'num' => "{$duration}分钟"], + ['title' => '人均观看', 'num' => "{$avg_UV_time}秒"], + ['title' => '观看次数', 'num' => "{$livePV}次"], ]; $biz_id = $this->group_id==3 ? $this->session['org_id'] : 0; $watch_lists = $this->sylive_entity->top_lists($a_id,'watch',1,10,$biz_id); @@ -234,7 +240,7 @@ class Stic extends Admin{ ]; $skey = $this->input->get('skey'); $page = $this->input->get('page'); - !$page && $page=10; + !$page && $page=1; $param = $this->myencryption->base64url_decode($skey); $a_id = intval($param['a_id']);//活动id $where = [ @@ -255,7 +261,7 @@ class Stic extends Admin{ $users = $this->user_model->map('userId','nickname',$where,'','','','userId,nickname'); } foreach ($rows as $key => $val) { - $nickname = $users[$val['uid']] ? $users['uid'] : "用户{$val['uid']}"; + $nickname = $users[$val['uid']] ? $users[$val['uid']] : "用户{$val['uid']}"; $lists[] = [ 'nickname' => $nickname, 'action' => $map_kpi_name[$val['kpi']], diff --git a/home/views/h5/market/sylive/act/index.php b/home/views/h5/market/sylive/act/index.php index 77405b97..7d068a7f 100644 --- a/home/views/h5/market/sylive/act/index.php +++ b/home/views/h5/market/sylive/act/index.php @@ -11,10 +11,19 @@ 数据
-
+
+
+
+ +
+
+
+
+