123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- use Redis;
- class Tvindex extends Api
- {
- protected $noNeedLogin = ['indexdata','video_list','videoinfo','image_childcate','image_list','videoinfo_simple','zhuanti','tudingc','search','history','app_error'];
- protected $noNeedRight = '*';
- //首页
- public function indexdata(){
- //背景图
- $data['index_bg_image'] = localpath_to_netpath(config('site.index_bg_image'));
- //左上角 logo,名称,4个按钮,账号
- $data['index_logo'] = localpath_to_netpath(config('site.index_logo'));
- $data['index_appname'] = config('site.index_appname');
- $data['index_tuiding_switch'] = config('site.index_tuiding_switch');
- $data['index_search_switch'] = config('site.index_search_switch');
- $data['index_history_switch'] = config('site.index_history_switch');
- $data['index_shoucang_switch'] = config('site.index_shoucang_switch');
- $data['index_dinggou_switch'] = config('site.index_dinggou_switch');
- $data['index_account_switch'] = config('site.index_account_switch');
- //右上角 三行
- $data['index_right_1'] = config('site.index_right_1');
- $data['index_right_2'] = config('site.index_right_2');
- $data['index_right_3'] = config('site.index_right_3');
- $data['index_right_4'] = config('site.index_right_4');
- //主视频
- $index_top_video_id = config('site.index_top_video_id');
- $index_top_video = Db::name('video')->field('id,image,programid,movieid')->where('id',$index_top_video_id)->where('inject_status',2)->find();
- if(!empty($index_top_video)){
- $index_top_video['image'] = localpath_to_netpath($index_top_video['image']);
- }
- $data['index_top_video'] = $index_top_video;
- //问诊四个
- $page_wenzhen = Db::name('page_wenzhen')->field('id,name,image,url')->where('status',1)->order('weigh asc')->select();
- $data['page_wenzhen'] = list_domain_image($page_wenzhen,['image']);
- //大分类+剧集
- $video_cate = Db::name('video_cate')->field('id,name,showtype,is_zhuanti')->where('status',1)->order('weigh asc, id desc')->select();
- $video_childcate = Db::name('video_childcate')->field('id, cate_id, name, image, bg_image')->where('status',1)->order('weigh asc, id desc')->select();
- $video_childcate = list_domain_image($video_childcate, ['image','bg_image']);
- //子分类数量
- $video_count = Db::name('video')->field('childcate_id,count(id)')->group('childcate_id')->where('childcate_id','neq','0')->where('status',1)->where('inject_status',2)->column('childcate_id,count(id)');
- foreach($video_childcate as $key => $val){
- $video_childcate[$key]['video_number'] = isset($video_count[$val['id']]) ? $video_count[$val['id']] : 0;
- }
- //分布:1=左一右四,2=两行八个,3=一行四个,4=一行三个
- foreach($video_cate as $key => $cate){
- $cate['child'] = [];
- //循环放入child
- $child = [];
- foreach($video_childcate as $k => $v){
- if($cate['id'] == $v['cate_id']){
- $child[] = $v;
- }
- }
- $cate['child'] = $child;
- $video_cate[$key] = $cate;
- }
- $data['video_cate'] = $video_cate;
- //图片大分类+子类
- $image_cate = Db::name('image_cate')->field('id,name,image')->where('status',1)->order('weigh asc, id desc')->select();
- $image_cate = list_domain_image($image_cate, ['image']);
- $data['image_cate'] = $image_cate;
- $this->success('首页',$data);
- }
- //更多页,应该是没用了
- //视频列表
- /*public function video_list() {
- $type_id = input('type_id', 0, 'intval'); //分类id
- if (!$type_id) {
- $this->error('您的网络开小差了~');
- }
- $video_type = Db::name('video_type')->where('id',$type_id)->value('name');
- $list = Db::name('video')->field('id, title, image, is_pay')->where(['video_type_id' => $type_id, 'status' => 1, 'inject_status' => 2])
- ->order('weigh asc, id desc')->select();
- $list = list_domain_image($list, ['image']);
- $result = [
- 'typename' => $video_type,
- 'videolist' => $list,
- ];
- $this->success('视频更多', $result);
- }*/
- //视频详情
- public function videoinfo() {
- $id = input('id', 0, 'intval'); //视频id
- $childcate_id = input('child_id',0,'intval'); //子分类id
- if (!$id && !$childcate_id) {
- $this->error('您的网络开小差了');
- }
- if($id){
- $info = Db::name('video')->field('id,video_type_id,cate_id,childcate_id, title, image, desc, is_pay, status, inject_status, seriesid, programid, movieid')
- ->where(['id' => $id])->find();
- }else{
- $info = Db::name('video')->field('id,video_type_id,cate_id,childcate_id, title, image, desc, is_pay, status, inject_status, seriesid, programid, movieid')
- ->where(['childcate_id' => $childcate_id])->where(['status'=>1,'inject_status'=>2])->order('weigh asc,id desc')->find();
- }
- if (!$info && !empty($childcate_id)) {
- $this->success(1,'{}');
- }
- if (!$info) {
- $this->error('不存在的视频');
- }
- if ($info['status'] != 1) {
- $this->error('视频丢失');
- }
- if ($info['inject_status'] != 2) {
- $this->error('视频丢失');
- }
- $info['image'] = one_domain_image($info['image']);
- $info['is_collection'] = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $info['id']])->count('id');
- $info['is_good'] = Db::name('video_good')->where(['user_id' => $this->auth->id, 'video_id' => $info['id']])->count('id');
- //大分类背景图
- $info['bg_image'] = '';
- $videobg_image = Db::name('video_cate')->where('id',$info['cate_id'])->value('videobg_image');
- unset($info['cate_id']);
- if(!empty($videobg_image)){
- $info['bg_image'] = localpath_to_netpath($videobg_image);
- }
- //剧集列表
- $juji = [];
- $video_list = Db::name('video')->field('id, title, image, is_pay')->where(['childcate_id' => $info['childcate_id'], 'status' => 1, 'inject_status' => 2])
- ->order('weigh asc, id desc')->select();
- if(!empty($video_list)){
- $video_list = list_domain_image($video_list, ['image']);
- $video_list = array_chunk($video_list,10);
- foreach($video_list as $page => $ten){
- $juji[] = [
- 'name'=> ($page*10 + 1) .'-'. ($page*10 + count($ten)),
- 'list'=>$ten,
- ];
- }
- }
- //猜你喜欢
- $juji_ids = array_column($juji,'id');
- $guess_list = Db::name('video')->field('id, title, image, is_pay')->where(['status' => 1, 'inject_status' => 2])->where('id','NOTIN',$juji_ids)
- ->orderRaw('rand()')->limit(6)->select();
- $guess_list = list_domain_image($guess_list, ['image']);
- //记录浏览历史,给浏览历史列表用的,即时的
- if($this->auth->isLogin()){
- $view_map = [
- 'user_id' => $this->auth->id,
- 'video_id' => $info['id'],
- ];
- $check_view = Db::name('video_view')->where($view_map)->find();
- if($check_view){
- Db::name('video_view')->where($view_map)->update(['updatetime'=>time()]);
- }else{
- $view_map['createtime'] = time();
- $view_map['updatetime'] = time();
- Db::name('video_view')->insertGetId($view_map);
- }
- }
- //记录pv,uv
- $this->video_pvuv($info['id']);
- //
- $result = [
- 'video_info' => $info,
- 'juji_list' => $juji,
- 'guess_list' => $guess_list,
- ];
- $this->success('详情', $result);
- }
- public function videoinfo_simple() {
- $id = input('id', 0, 'intval'); //视频id
- if (!$id) {
- $this->error('您的网络开小差了');
- }
- $info = Db::name('video')->field('id,video_type_id,childcate_id, title, image, desc, is_pay, status, inject_status, seriesid, programid, movieid')
- ->where(['id' => $id])->find();
- if (!$info) {
- $this->error('数据不存在');
- }
- if ($info['status'] != 1) {
- $this->error('视频丢失');
- }
- if ($info['inject_status'] != 2) {
- $this->error('视频丢失');
- }
- $info['image'] = one_domain_image($info['image']);
- $info['is_collection'] = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $info['id']])->count('id');
- $info['is_good'] = Db::name('video_good')->where(['user_id' => $this->auth->id, 'video_id' => $info['id']])->count('id');
- //记录浏览历史,给浏览历史列表用的,即时的
- if($this->auth->isLogin()){
- $view_map = [
- 'user_id' => $this->auth->id,
- 'video_id' => $info['id'],
- ];
- $check_view = Db::name('video_view')->where($view_map)->find();
- if($check_view){
- Db::name('video_view')->where($view_map)->update(['updatetime'=>time()]);
- }else{
- $view_map['createtime'] = time();
- $view_map['updatetime'] = time();
- Db::name('video_view')->insertGetId($view_map);
- }
- }
- //记录pv,uv
- $this->video_pvuv($info['id']);
- //
- $result = [
- 'video_info' => $info,
- ];
- $this->success('详情', $result);
- }
- //专题页
- public function zhuanti(){
- $childcate_id = input('child_id', 0, 'intval'); //子分类id
- if (!$childcate_id) {
- $this->error('您的网络开小差了~');
- }
- $video_childcate = Db::name('video_childcate')->field('id,name,bg_image')->where('id',$childcate_id)->find();
- $video_childcate = info_domain_image($video_childcate,['bg_image']);
- $list = Db::name('video')->field('id, title, image, is_pay, status, inject_status, seriesid, programid, movieid')->where(['childcate_id' => $childcate_id, 'status' => 1, 'inject_status' => 2])->order('weigh asc, id desc')->limit(5)->select();
- $list = list_domain_image($list, ['image']);
- $result = [
- 'info' => $video_childcate,
- 'list' => $list,
- ];
- $this->success('视频', $result);
- }
- //退订服务
- public function tudingc()
- {
- $data = config('site.text_tuiding');
- $this->success('', $data);
- }
- //搜索页
- public function search(){
- $keyword = input('keyword','');
- //热门推荐4个
- if(empty($keyword)){
- $list = Db::name('video')->field('id, title, image, is_pay')->where(['status' => 1, 'inject_status' => 2])
- ->orderRaw('rand()')->limit(12)->select();
- $list = list_domain_image($list, ['image']);
- }else{
- $list = Db::name('video')->field('id, title, image, is_pay')->where(['status' => 1, 'inject_status' => 2])->where('search_title','LIKE','%'.$keyword.'%')->order('is_pay asc,weigh asc,id desc')->select();
- $list = list_domain_image($list, ['image']);
- }
- $this->success('视频', $list);
- }
- //浏览历史
- public function history(){
- if($this->auth->isLogin()){
- $video_view = Db::name('video_view')->where('user_id',$this->auth->id)->order('updatetime desc')->group('video_id')->column('video_id,updatetime');
- if(!empty($video_view)){
- $video_ids = implode(',',array_keys($video_view));
- $list = Db::name('video')->field('id, title, image, is_pay')->where(['status' => 1, 'inject_status' => 2])->where('id','IN',$video_ids)->orderRaw('field(id,'.$video_ids.')')->page($this->page,$this->pagenum)->select();
- $list = list_domain_image($list, ['image']);
- foreach($list as $key => $val){
- $list[$key]['history_time'] = $video_view[$val['id']];
- }
- }else{
- $list = [];
- }
- }else{
- $list = [];
- }
- $this->success('视频', $list);
- }
- //视频收藏列表
- public function shoucang_list(){
- if($this->auth->isLogin()){
- $video_view = Db::name('video_collection')->where('user_id',$this->auth->id)->order('createtime desc')->group('video_id')->column('video_id,createtime');
- if(!empty($video_view)){
- $video_ids = implode(',',array_keys($video_view));
- $list = Db::name('video')->field('id, title, image, is_pay')->where(['status' => 1, 'inject_status' => 2])->where('id','IN',$video_ids)->orderRaw('field(id,'.$video_ids.')')->page($this->page,$this->pagenum)->select();
- $list = list_domain_image($list, ['image']);
- foreach($list as $key => $val){
- $list[$key]['shoucang_time'] = $video_view[$val['id']];
- }
- }else{
- $list = [];
- }
- }else{
- $list = [];
- }
- $this->success('视频', $list);
- }
- //视频收藏/取消收藏
- public function video_collection() {
- $id = input('id', 0, 'intval');
- if (!$id) {
- $this->error('您的网络开小差了');
- }
- $info = Db::name('video')->where(['id' => $id])->find();
- if (!$info) {
- $this->error('数据不存在');
- }
- //var_dump($info);exit;
- $info['image'] = one_domain_image($info['image']);
- //查询是否收藏
- $count = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $id])->count('id');
- //开启事务
- if ($count) {
- $result = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $id])->delete();
- Db::name('video')->where('id',$id)->setDec('collect_number',1); //收藏数减少
- } else {
- $result = Db::name('video_collection')->insertGetId(['user_id' => $this->auth->id, 'video_id' => $id, 'createtime' => time()]);
- Db::name('video')->where('id',$id)->setInc('collect_number',1); //收藏数增加
- }
- if (!$result) {
- /*Db::rollback();
- $this->error('操作失败');*/
- $this->success('操作成功');
- }
- $url = 'http://meta-history.unso.gitv.tv/OTT/jscmcc/addThirdPartyCollectionRecord';
- $content = [
- 'cpPrvdName' => '健康e家',
- 'cpPrvCode' => '41000144',
- 'cpPrvType' => '1006',
- 'content' => $info['title'],
- 'ChnCode' => '1000020',
- 'contentId' => (string)$info['movieid'],
- 'extraContentID' => '',
- 'isEffective' => $info['status'],
- 'isPaid' => $info['is_pay'],
- 'collectionFlag' => $count ? 0 : 1,
- 'account' => $this->encrypt($this->auth->mobile, '!@#$%^&*FJGFJT78'),
- 'cpPermission' => 'GITV',
- 'intent' => [
- 'action' => 'com.huxiu.heh.tv.ui.splash.SplashActivity',
- 'package' => 'com.huxiu.heh.tv',
- 'component' => [
- 'pkg' => 'com.huxiu.heh.tv',
- 'cls' => 'com.huxiu.heh.tv.ui.splash.SplashActivity'
- ],
- 'extras' => [
- /*'cmd' => '',
- 'from' => '',
- 'media_id' => ''*/
- 'type_id' => $info['video_type_id'],
- 'id' => $info['id']
- ]
- ],
- 'imageURL' => $info['image']
- ];
- $content = json_encode($content, 320);
- $rt = httpRequest($url, 'POST', $content);
- file_put_contents('shoucang.txt',$id.'_'.$rt.PHP_EOL, FILE_APPEND);
- if (!$rt) {
- /*Db::rollback();
- $this->error('操作失败');*/
- $this->success('操作成功');
- }
- $rt = json_decode($rt, true);
- if (empty($rs) || $rt['code'] != 0) {
- /*Db::rollback();
- $this->error('操作失败');*/
- $this->success('操作成功');
- }
- //大数据上报
- $data = [
- 'favid' => (string)(config('data_cp_id') . date('Ymd') . getMillisecond() . mt_rand(10000000, 99999999)),
- 'UserID' => $this->auth->mobile,
- 'time' => date('Y-m-d H:i:s'),
- 'type' => $count ? 0 : 1,
- 'cpid' => config('data_cp_id'),
- 'albumid' => $id,
- 'albumname' => $info['title']
- ];
- $data = join(json_decode('"\u0001"', true), $data);
- $filename = date('Ymd').'_'.config('data_cp_id').'_userfavdata_1.dat';
- $check_filename = date('Ymd').'_'.config('data_cp_id').'_userfavdata_1.chk';
- error_log(print_r($data, 1) . PHP_EOL, 3, './dashuju/' . $filename);
- error_log('', 3, './dashuju/' . $check_filename);
- $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_userfavdata.finish';
- error_log('', 3, './dashuju/' . $finish_filename);
- Db::commit();
- $this->success('操作成功');
- }
- //点赞视频、取消点赞
- public function video_good() {
- $id = input('id', 0, 'intval');
- if (!$id) {
- $this->error('您的网络开小差了');
- }
- $info = Db::name('video')->where(['id' => $id])->find();
- if (!$info) {
- $this->error('数据不存在');
- }
- //查询是否收藏
- $check = Db::name('video_good')->where(['user_id' => $this->auth->id, 'video_id' => $id])->find();
- //开启事务
- if ($check) {
- $result = Db::name('video_good')->where(['user_id' => $this->auth->id, 'video_id' => $id])->delete();
- Db::name('video')->where('id',$id)->setDec('good_number',1); //点赞数减少
- } else {
- $result = Db::name('video_good')->insertGetId(['user_id' => $this->auth->id, 'video_id' => $id, 'createtime' => time()]);
- Db::name('video')->where('id',$id)->setInc('good_number',1); //点赞数增加
- }
- $this->success('操作成功');
- }
- //用户观看行为(支付)
- public function payuserplay() {
- $id = input('id', 0, 'intval'); //视频id
- $sn = input('sn', '', 'trim'); //SN号
- $start_time = input('start_time', '', 'trim'); //yyyymmddhhmmss (24小时制),节目开始播放时间
- $end_time = input('end_time', '', 'trim'); //yyyymmddhhmmss (24小时制),节目结束播放时间,如果播放未结束,但是此时需要同步数据,填当前时间
- $csource = input('csource', 1, ''); //1:从搜索结果访问2:从用户收藏/书签访问3:从EPG访问4:从推荐页面访问5、其他
- //文档的说法:各业务系统只提供付费观看数据。
- if($this->auth->is_vip != 1){
- $this->success('');
- }
- if (!$id) {
- $this->error('您的网络开小差了');
- }
- $info = Db::name('video')->where(['id' => $id])->find();
- if (!$info) {
- $this->error('数据不存在');
- }
- //文档的说法:各业务系统只提供付费观看数据。
- if($info['is_pay'] != 1){
- $this->success('');
- }
- //播放日志
- $play_data = [
- 'user_id' => $this->auth->id,
- 'video_id' => $id,
- 'sn' => $sn,
- 'start_time' => $start_time,
- 'end_time' => $end_time,
- 'csource' => $csource,
- 'createtime' => time(),
- 'updatetime' => time(),
- ];
- Db::name('video_play_payuserplay')->insertGetId($play_data);
- $content = [
- 'UserID' => $this->auth->mobile, //UserID
- 'city' => '14', //用户地市 ,14南京
- 'start_time' => $start_time, //开始时间
- 'end_time' => $end_time, //结束时间
- 'service_type' => 1, //业务类型1:点播, 2:回看, 3:直播, 4:其他
- 'albumid' => $id, //节目/内容ID
- 'albumname' => $info['title'], //节目/内容名称
- 'csource' => $csource, //内容访问来源
- 'SN' => $sn, //设备ID
- 'ip' => request()->ip(), //终端IP
- 'fee_type' => $info['is_pay'] == 1 ? 1 : '', //该内容对应计费类型
- 'flow' => '', //用户使用的流量,非必填
- 'product' => (string)config('product_code'), //产品ID
- 'product_name' => '', //产品名称,非必填
- 'info_source' => (string)config('cp_id'), //信息来源
- ];
- $content = join('|', $content);
- $filename = date('YmdH').'_'.config('cp_id').'_ottuserviewdata_1.dat';
- $check_filename = date('YmdH').'_'.config('cp_id').'_ottuserviewdata_1.chk';
- error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
- error_log('', 3, './dashuju/' . $check_filename);
- $this->success('');
- }
- //视频播放记录
- public function playrecord() {
- $id = input('id', 0, 'intval');
- $total_time = input('total_time', 0, 'intval'); //总时长
- $start_time = input('start_time', 0, 'intval'); //开始看时间:相对时间
- $end_time = input('end_time', 0, 'intval'); //结束看时间:相对时间
- $log_type = input('log_type', 'watching', 'trim'); //begin:开始播放;watching:正在播放;end:结束播放
- if (!$id) {
- $this->error('您的网络开小差了');
- }
- $info = Db::name('video')->where(['id' => $id])->find();
- if (!$info) {
- $this->error('数据不存在');
- }
- if ($info['inject_status'] != 2) {
- $this->error('视频丢失');
- }
- //播放日志
- $play_data = [
- 'user_id' => $this->auth->id,
- 'video_id' => $id,
- 'total_time' => $total_time,
- 'start_time' => $start_time,
- 'end_time' => $end_time,
- 'log_type' => $log_type,
- 'createtime' => time(),
- 'updatetime' => time(),
- ];
- Db::name('video_play_playrecord')->insertGetId($play_data);
- $info['image'] = one_domain_image($info['image']);
- $url = 'http://meta-history.unso.gitv.tv/OTT/jscmcc/addThirdPartyHistoryRecord';
- $content = [
- 'cpPrvdName' => '健康e家',
- 'cpPrvCode' => '41000144',
- 'cpPrvType' => '1006',
- 'contentName' => $info['title'],
- 'ChnName' => '健康',
- 'ChnCode' => '1000020',
- 'contentId' => (string)$info['movieid'],
- 'extraContentID' => '',
- 'isEffective' => $info['status'],
- 'isPaid' => $info['is_pay'],
- 'contentTotalTime' => $total_time,
- 'startWatchTime' => $start_time,
- 'endWatchTime' => $end_time,
- 'playTime' => $end_time - $start_time,
- 'logType' => $log_type,
- 'account' => $this->encrypt($this->auth->mobile, '!@#$%^&*FJGFJT78'),
- 'cpPermission' => 'GITV',
- 'intent' => [
- 'action' => 'com.huxiu.heh.tv.ui.splash.SplashActivity',
- 'package' => 'com.huxiu.heh.tv',
- 'component' => [
- 'pkg' => 'com.huxiu.heh.tv',
- 'cls' => 'com.huxiu.heh.tv.ui.splash.SplashActivity'
- ],
- 'extras' => [
- /*'cmd' => '',
- 'from' => '',
- 'media_id' => ''*/
- 'type_id' => $info['video_type_id'],
- 'id' => $info['id']
- ]
- ],
- 'imageURL' => $info['image']
- ];
- $content = json_encode($content, 320);
- $rt = httpRequest($url, 'POST', $content);
- file_put_contents('bofang.txt',$id.'_'.$rt.PHP_EOL, FILE_APPEND);
- if (!$rt) {
- //$this->error('同步失败');
- }
- $rt = json_decode($rt, true);
- if (isset($rt['code']) && $rt['code'] != 0) {
- //$this->error('同步失败');
- }
- $this->success('同步成功');
- }
- //用户观看行为(大数据)
- public function userplay() {
- $id = input('id', 0, 'intval'); //视频id
- $sn = input('sn', '', 'trim'); //SN号
- $start_time = input('start_time', '', 'trim'); //YYYY-MM-DD HH:MM:SS(24小时制)节目开始播放时间
- $end_time = input('end_time', '', 'trim'); //YYYY-MM-DD HH:MM:SS(24小时制)节目结束播放时间
- $csource = input('csource', 0, ''); //1:从搜索结果访问2:从用户收藏/书签访问3:从EPG访问4:从推荐页面访问5:从猜你喜欢个性化推荐页面访问(带上推荐接口的trace_id)99:其他
- $trace_id = input('trace_id', '', 'trim');
- $istry = input('istry', 0, 'intval'); //0非试看 1试看
- $start_posi = input('start_posi', 0, 'intval'); //播放起始点相对于影片起始点的时长,单位秒,例如从影片第 600 秒开始观看
- if (!$id) {
- $this->error('您的网络开小差了');
- }
- $info = Db::name('video')->where(['id' => $id])->find();
- if (!$info) {
- $this->error('数据不存在');
- }
- //播放日志
- $play_data = [
- 'user_id' => $this->auth->id,
- 'video_id' => $id,
- 'sn' => $sn,
- 'start_time' => $start_time,
- 'end_time' => $end_time,
- 'csource' => $csource,
- 'trace_id' => $trace_id,
- 'istry' => $istry,
- 'start_posi' => $start_posi,
- 'createtime' => time(),
- 'updatetime' => time(),
- ];
- Db::name('video_play_userplay')->insertGetId($play_data);
- $content = [
- 'playid' => (string)(config('data_cp_id') . date('Ymd') . getMillisecond() . mt_rand(10000000, 99999999)),
- 'UserID' => $this->auth->mobile,
- 'SN' => $sn,
- 'start_time' => $start_time,
- 'end_time' => $end_time,
- 'service_type' => 1,
- 'cpid' => config('data_cp_id'),
- 'albumid' => $id,
- 'albumname' => $info['title'],
- 'videoid' => $id,
- 'videoname' => $info['title'],
- 'csource' => $csource,
- 'trace_id' => $trace_id,
- 'fee_type' => $info['is_pay'] == 1 ? 1 : 4,
- 'istry' => $istry,
- 'iscon' => 0,
- 'start_posi' => $start_posi
- ];
- $content = join(json_decode('"\u0001"', true), $content);
- $filename = date('Ymd').'_'.config('data_cp_id').'_userplaydata_1.dat';
- $check_filename = date('Ymd').'_'.config('data_cp_id').'_userplaydata_1.chk';
- error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
- error_log('', 3, './dashuju/' . $check_filename);
- $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_userplaydata.finish';
- error_log('', 3, './dashuju/' . $finish_filename);
- $this->success('');
- }
- //获取特殊机型
- public function special_models() {
- $special_models = config('site.special_models');
- $special_models = explode(',', $special_models);
- $this->success('获取特殊机型', $special_models);
- }
- //前端报错记录
- public function app_error() {
- $this->success('');
- }
- //图片页
- public function image_childcate(){
- $cate_id = input('cate_id',0);
- $childcate = Db::name('image_childcate')->field('id,cate_id,name')->where('cate_id',$cate_id)->where('status',1)->order('weigh asc,id desc')->select();
- $image_list = [];
- if(!empty($childcate)){
- $childcate_id = $childcate[0]['id'];
- $image_list = Db::name('image')->field('id,title,image')->where('childcate_id',$childcate_id)->where('status',1)->order('weigh asc,id desc')->select();
- $image_list = list_domain_image($image_list,['image']);
- }
- $result = [
- 'childcate' => $childcate,
- 'image_list' => $image_list,
- ];
- $this->success(1,$result);
- }
- //图片列表
- public function image_list(){
- $childcate_id = input('child_id',0);
- $image_list = Db::name('image')->field('id,title,image')->where('childcate_id',$childcate_id)->where('status',1)->order('weigh asc,id desc')->select();
- $image_list = list_domain_image($image_list,['image']);
- $this->success(1,$image_list);
- }
- /** * * @param string $string 需要加密的字符串 * @param string $key 密钥 * @return string */
- private function encrypt($string, $key) {
- // $key = substr(openssl_digest(openssl_digest($key, 'sha1', true), 'sha1', true), 0, 16);
- $data = openssl_encrypt($string, 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
- $data = bin2hex($data);
- return $data;
- }
- /** * @param string $string 需要解密的字符串 * @param string $key 密钥 * @return string */
- private function decrypt($string, $key) {
- // $key = substr(openssl_digest(openssl_digest($key, 'sha1', true), 'sha1', true), 0, 16);
- $decrypted = openssl_decrypt(hex2bin($string), 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
- return $decrypted;
- }
- //共有方法,
- private function video_pvuv($video_id = 0){
- if(empty($video_id)) {return true;}
- //开启redis
- $redis = new Redis();
- $config = config('redis');
- $redis->connect($config['redis_host'], $config['redis_port']);
- if ($config['redis_pwd']) {
- $redis->auth($config['redis_pwd']);
- }
- if($config['redis_selectdb'] > 0){
- $redis->select($config['redis_selectdb']);
- }
- //今天
- $today = date('Y-m-d');
- //今日pv+1
- $today_pv_key = $today.'_video_pv_'.$video_id;
- $redis->incr($today_pv_key,1);
- //今日uv+1
- if($this->auth->isLogin() && $this->auth->id){
- $today_uv_key = $today.'_video_uv_'.$video_id;
- $uid = $this->auth->id;
- $redis->sAdd($today_uv_key,$uid);
- }
- //今日视频id列表
- $today_video_key = $today.'_video_list';
- $redis->sAdd($today_video_key,$video_id);
- }
- /*public function test(){
- $this->video_pvuv(input('video_id',0));
- }*/
- }
|