market_930
This commit is contained in:
+117
-21
@@ -12,10 +12,11 @@ class Syt extends CI_Controller
|
||||
private $log_file = 'plan_syt.log';
|
||||
private $log_dir = 'market/sylive';
|
||||
private $options;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this-> options = [
|
||||
$this->options = [
|
||||
'token' => '',
|
||||
'appid' => 'wxe66f905683582780',
|
||||
'appsecret' => '9546cd4de877be13ce203f3e6140633f',
|
||||
@@ -24,6 +25,7 @@ class Syt extends CI_Controller
|
||||
];
|
||||
$this->load->model('market/market_sylive_activity_model');
|
||||
$this->load->model('live/Live_polyv_session_model', 'mdPolyvSession');
|
||||
$this->load->model('live/Live_polyv_viewlog_model', 'mdPolyvViewlog');
|
||||
$this->load->library('PolyvApi');
|
||||
}
|
||||
|
||||
@@ -31,20 +33,19 @@ class Syt extends CI_Controller
|
||||
* Notes:发送一次性订阅
|
||||
* Created on: 2020/11/30 17:02
|
||||
* Created by: dengbw
|
||||
* https://hd-api-dev.xiaoyu.com/plan/syt/subscribemsg
|
||||
* https://api.test.haodian.cn/plan/syt/subscribemsg
|
||||
* https://api.haodian.cn/plan/syt/subscribemsg
|
||||
* https://liche-api-dev.xiaoyu.com/plan/syt/subscribemsg
|
||||
* https://api.liche.cn/plan/syt/subscribemsg
|
||||
*/
|
||||
public function subscribemsg()
|
||||
{
|
||||
$this->load->model('market/market_sylive_subscribemsg_model','mdSytSubscribemsg');
|
||||
$this->load->model('market/market_sylive_subscribemsg_model', 'mdSytSubscribemsg');
|
||||
$date = date('Y-m-d H:i:s', strtotime('+2 minute'));//提前2分钟发送
|
||||
$where['s_time<='] = $date;
|
||||
$where['status'] = 0;
|
||||
$res = $this->mdSytSubscribemsg->select($where, 'id asc', 1, 200);
|
||||
$log = array();
|
||||
if ($res) {
|
||||
$this->load->model('market/market_sylive_activity_model','mdSytActivity');
|
||||
$this->load->model('market/market_sylive_activity_model', 'mdSytActivity');
|
||||
$wechatS = new WechatServer($this->options);
|
||||
$wechatS->checkAuth();
|
||||
foreach ($res as $key => $value) {
|
||||
@@ -80,23 +81,31 @@ class Syt extends CI_Controller
|
||||
debug_log("[info] " . __FUNCTION__ . "# date:{$date}; total:{$total}; do:{$do};", $this->log_file);
|
||||
}
|
||||
|
||||
public function syn_polyv(){
|
||||
/**
|
||||
* Notes:私域通直播间数据同步
|
||||
* https://liche-api-dev.xiaoyu.com/plan/syt/syn_polyv
|
||||
* https://api.liche.cn/plan/syt/syn_polyv
|
||||
* Created on: 2022/9/30 15:05
|
||||
* Created by: dengbw
|
||||
*/
|
||||
public function syn_polyv()
|
||||
{
|
||||
$a_id = $this->input->get('a_id');
|
||||
$where = [
|
||||
'status' => 0,
|
||||
"channelId <> ''" => null,
|
||||
"timeStart<" => date('Y-m-d H:i:s'),
|
||||
"timeStart>" => date('Y-m-d H:i:s',strtotime("-1 day"))
|
||||
"timeStart>" => date('Y-m-d H:i:s', strtotime("-1 day"))
|
||||
];
|
||||
$a_id && $where = ['activityId'=>$a_id];
|
||||
$rows = $this->market_sylive_activity_model->select($where,'activityId desc',1,20,'activityId,channelId,timeStart,timeEnd');
|
||||
if($rows){
|
||||
$a_id && $where = ['activityId' => $a_id];
|
||||
$rows = $this->market_sylive_activity_model->select($where, 'activityId desc', 1, 20, 'activityId,channelId,timeStart,timeEnd');
|
||||
if ($rows) {
|
||||
foreach ($rows as $item) {
|
||||
debug_log("开始同步{$item['activityId']}活动直播",$this->log_file,$this->log_dir);
|
||||
debug_log("开始同步{$item['activityId']}活动直播", $this->log_file, $this->log_dir);
|
||||
$polyv = new PolyvApi(['channel_id' => $item['channelId']]);
|
||||
$pl_where = [
|
||||
'startTime' => strtotime($item['timeStart'])*1000,
|
||||
'endTime' => strtotime($item['timeEnd'])*1000
|
||||
'startTime' => strtotime($item['timeStart']) * 1000,
|
||||
'endTime' => strtotime($item['timeEnd']) * 1000
|
||||
];
|
||||
$results = $polyv->getSessionStats($pl_where);
|
||||
if ($results['status'] == 'success') {
|
||||
@@ -109,24 +118,111 @@ class Syt extends CI_Controller
|
||||
'playbackPV' => $value['playbackPV'], 'totalPlayDuration' => $value['totalPlayDuration'],
|
||||
'session_time' => date('Y-m-d H:i:s'),
|
||||
];
|
||||
$session = ['channelId' => $item['channelId'], 'sessionId' => $value['sessionId']];
|
||||
if ($re) {//同步更新数据
|
||||
$session['id'] = $re['id'];
|
||||
$session['viewlog_time'] = $re['viewlog_time'];
|
||||
$this->mdPolyvSession->update($data, ['id' => $re['id']]);
|
||||
} else {//新增
|
||||
$data['c_time'] = time();
|
||||
$this->mdPolyvSession->add($data);
|
||||
$session['id'] = $this->mdPolyvSession->add($data);
|
||||
$session['startTime'] = $value['startTime'];
|
||||
}
|
||||
$this->api_viewlog($session);
|
||||
}
|
||||
$msg = "同步成功:".json_encode($results,JSON_UNESCAPED_UNICODE);
|
||||
echo $msg."<br>";
|
||||
$msg = "同步成功:" . json_encode($results, JSON_UNESCAPED_UNICODE);
|
||||
echo $msg . "<br>";
|
||||
} else {
|
||||
$msg = "接口错误:".$results['message'];
|
||||
echo $msg."<br>";
|
||||
$msg = "接口错误:" . $results['message'];
|
||||
echo $msg . "<br>";
|
||||
|
||||
}
|
||||
debug_log($msg,$this->log_file,$this->log_dir);
|
||||
debug_log($msg, $this->log_file, $this->log_dir);
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
echo "暂无同步数据";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:同步保利威分页查询频道直播观看详情数据
|
||||
* Created on: 2022/9/30 14:56
|
||||
* Created by: dengbw
|
||||
* @param $session
|
||||
*/
|
||||
private function api_viewlog($session)
|
||||
{
|
||||
if ($session['viewlog_time'] && $session['viewlog_time'] != '0000-00-00 00:00:00') {
|
||||
$startTime = strtotime($session['viewlog_time']);
|
||||
} else {
|
||||
$startTime = $session['startTime'] / 1000;
|
||||
}
|
||||
$endTime = strtotime(date('Y-m-d H:i:s'));
|
||||
//不同月份时开始取本月第1天
|
||||
if (date('m', $startTime) != date('m', $endTime)) {
|
||||
$startTime = strtotime(date('Y-m', time()) . '-01 00:00:00');
|
||||
}
|
||||
$params['channelId'] = $session['channelId'];
|
||||
$params['sessionIds'] = $session['sessionId'];
|
||||
$params['startTime'] = $startTime * 1000;
|
||||
$params['endTime'] = $endTime * 1000;
|
||||
$params['page'] = 1;
|
||||
$results = $this->getViewLog($params);
|
||||
if ($results['status'] == 'success') {
|
||||
$i = 10;
|
||||
while (($i--) > 0) {
|
||||
if ($results['status'] == 'success' && !$results['lastPage']
|
||||
&& $results['pageNumber'] != $results['nextPageNumber']) {
|
||||
$params['page'] = $results['nextPageNumber'];
|
||||
$results = $this->getViewLog($params);
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
//同步观看数据时间
|
||||
$this->mdPolyvSession->update(['viewlog_time' => date('Y-m-d H:i:s', $endTime)], ['id' => $session['id']]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:增加观看日志
|
||||
* Created on: 2022/9/30 14:56
|
||||
* Created by: dengbw
|
||||
* @param $params
|
||||
* @return bool|string
|
||||
*/
|
||||
private function getViewLog($params)
|
||||
{
|
||||
$this->load->library('PolyvApi');
|
||||
$polyv = new PolyvApi(['channel_id' => $params['channelId']]);
|
||||
$results = $polyv->getViewLog($params);
|
||||
if ($results['status'] == 'success') {
|
||||
$addData = [];
|
||||
foreach ($results['data']['contents'] as $key => $value) {
|
||||
$re = $this->mdPolyvViewlog->get(['playId' => $value['playId']]);
|
||||
$data = [
|
||||
'channelId' => $value['channelId'], 'sessionId' => $value['sessionId'], 'playId' => $value['playId'],
|
||||
'userId' => $value['userId'], 'playDuration' => $value['playDuration'], 'stayDuration' => $value['stayDuration'],
|
||||
'flowSize' => $value['flowSize'], 'param1' => $value['param1'], 'param2' => $value['param2'],
|
||||
'param3' => $value['param3'], 'param4' => $value['param4'], 'param5' => $value['param5'], 'ptype' => $value['ptype'],
|
||||
'ipAddress' => $value['ipAddress'], 'country' => $value['country'], 'province' => $value['province'],
|
||||
'city' => $value['city'], 'isp' => $value['isp'], 'referer' => $value['referer'], 'userAgent' => $value['userAgent'],
|
||||
'operatingSystem' => $value['operatingSystem'], 'browser' => $value['browser'], 'isMobile' => $value['isMobile'],
|
||||
'currentDay' => $value['currentDay'], 'createdTime' => $value['createdTime'], 'lastModified' => $value['lastModified'],
|
||||
];
|
||||
if ($re) {//同步更新数据
|
||||
$this->mdPolyvViewlog->update($data, ['id' => $re['id']]);
|
||||
} else {//新增
|
||||
$data['c_time'] = time();
|
||||
$addData[] = $data;
|
||||
}
|
||||
}
|
||||
if ($addData && count($addData)) {//新增数据
|
||||
$this->mdPolyvViewlog->add_batch($addData);
|
||||
}
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -473,11 +473,11 @@ class Activity extends BaseController
|
||||
$order = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'kpi' => 'order']);
|
||||
$duration = $livePV = $watchDuration = 0;
|
||||
if ($channelId) {
|
||||
$res_live = $this->mdPolyvSession->select(['channelId' => $channelId], 'id desc', 1, 1, 'duration,livePV');
|
||||
$re_live = $res_live[0];
|
||||
if ($re_live['duration']) {
|
||||
$duration = ceil($re_live['duration'] / 60);
|
||||
$livePV = $re_live['livePV'];
|
||||
$re_duration = $this->mdPolyvSession->sum('duration', ['channelId' => $channelId]);
|
||||
$re_livePV = $this->mdPolyvSession->sum('livePV', ['channelId' => $channelId]);
|
||||
if ($re_duration['duration']) {
|
||||
$duration = ceil($re_duration['duration'] / 60);
|
||||
$livePV = $re_livePV['livePV'];
|
||||
$watchDuration = round($duration / $livePV);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user