Tvindex.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use Redis;
  6. class Tvindex extends Api
  7. {
  8. protected $noNeedLogin = ['indexdata','video_list','videoinfo','zhuanti','tudingc','search','history','app_error'];
  9. protected $noNeedRight = '*';
  10. //首页
  11. public function indexdata(){
  12. //左上角 logo,名称,4个按钮
  13. $data['index_logo'] = localpath_to_netpath(config('site.index_logo'));
  14. $data['index_appname'] = config('site.index_appname');
  15. $data['index_tuiding_switch'] = config('site.index_tuiding_switch');
  16. $data['index_search_switch'] = config('site.index_search_switch');
  17. $data['index_history_switch'] = config('site.index_history_switch');
  18. $data['index_dinggou_switch'] = config('site.index_dinggou_switch');
  19. $data['index_account_switch'] = config('site.index_account_switch');
  20. //右上角 三行
  21. $data['index_right_1'] = config('site.index_right_1');
  22. $data['index_right_2'] = config('site.index_right_2');
  23. $data['index_right_3'] = config('site.index_right_3');
  24. //主视频
  25. $index_top_video_id = config('site.index_top_video_id');
  26. $index_top_video = Db::name('video')->field('id,image,programid,movieid')->where('id',$index_top_video_id)->where('inject_status',2)->find();
  27. if(!empty($index_top_video)){
  28. $index_top_video['image'] = localpath_to_netpath($index_top_video['image']);
  29. }
  30. $data['index_top_video'] = $index_top_video;
  31. //问诊四个
  32. $page_wenzhen = Db::name('page_wenzhen')->field('id,name,image,url')->where('status',1)->order('weigh asc')->select();
  33. $data['page_wenzhen'] = list_domain_image($page_wenzhen,['image']);
  34. //大分类+剧集
  35. $video_type = Db::name('video_type')->field('id,name,showtype')->where('status',1)->where('type','neq',3)->order('weigh asc, id desc')->select();
  36. $video = Db::name('video')->field('id, video_type_id, title, image, is_pay')->where(['status' => 1, 'inject_status' => 2])->order('weigh asc, id desc')->select();
  37. $video = list_domain_image($video, ['image']);
  38. //分布:1=左一右四,2=两行八个,3=一行四个,4=一行三个
  39. $more = [
  40. 'id' => 0,
  41. 'video_type_id' => 0,
  42. 'title' => '查看更多',
  43. 'image' => 'https://jiankang-1304634122.cos.ap-nanjing.myqcloud.com/uploads/20240529/37bd30cf2b80186b51f3bbfedb10a7d5.png',
  44. 'is_pay'=> 0,
  45. ];
  46. foreach($video_type as $key => $type){
  47. $type['child'] = [];
  48. $more['video_type_id'] = $type['id'];
  49. //循环放入child
  50. $child = [];
  51. foreach($video as $k => $v){
  52. if($type['id'] == $v['video_type_id']){
  53. $child[] = $v;
  54. }
  55. }
  56. //查看更多
  57. if($type['showtype'] == 1){
  58. if(count($child) > 5){
  59. $child = array_chunk($child,4)[0];
  60. $child[] = $more;
  61. }
  62. }
  63. if($type['showtype'] == 2){
  64. if(count($child) > 8){
  65. $child = array_chunk($child,7)[0];
  66. $child[] = $more;
  67. }
  68. }
  69. if($type['showtype'] == 3){
  70. if(count($child) > 4){
  71. $child = array_chunk($child,3)[0];
  72. $child[] = $more;
  73. }
  74. }
  75. if($type['showtype'] == 4){
  76. if(count($child) > 3){
  77. $child = array_chunk($child,2)[0];
  78. $child[] = $more;
  79. }
  80. }
  81. $type['child'] = $child;
  82. $video_type[$key] = $type;
  83. }
  84. $data['video_type'] = $video_type;
  85. //精彩专题
  86. $data['buttom_name'] = '精彩专题';
  87. $buttom_list = Db::name('video_type')->field('id,name,image')->where('status',1)->where('type',3)->order('weigh asc,id desc')->limit(3)->select();
  88. $data['buttom_list'] = list_domain_image($buttom_list,['image']);
  89. $this->success('首页',$data);
  90. }
  91. //更多页
  92. //视频列表
  93. public function video_list() {
  94. $type_id = input('type_id', 0, 'intval'); //分类id
  95. if (!$type_id) {
  96. $this->error('您的网络开小差了~');
  97. }
  98. $video_type = Db::name('video_type')->where('id',$type_id)->value('name');
  99. $list = Db::name('video')->field('id, title, image, is_pay')->where(['video_type_id' => $type_id, 'status' => 1, 'inject_status' => 2])
  100. ->order('weigh asc, id desc')->select();
  101. $list = list_domain_image($list, ['image']);
  102. $result = [
  103. 'typename' => $video_type,
  104. 'videolist' => $list,
  105. ];
  106. $this->success('视频更多', $result);
  107. }
  108. //视频详情
  109. public function videoinfo() {
  110. $id = input('id', 0, 'intval'); //视频id
  111. if (!$id) {
  112. $this->error('您的网络开小差了');
  113. }
  114. $info = Db::name('video')->field('id,video_type_id, title, image, desc, is_pay, status, inject_status, seriesid, programid, movieid')
  115. ->where(['id' => $id])->find();
  116. if (!$info) {
  117. $this->error('数据不存在');
  118. }
  119. if ($info['status'] != 1) {
  120. $this->error('视频丢失');
  121. }
  122. if ($info['inject_status'] != 2) {
  123. $this->error('视频丢失');
  124. }
  125. $info['image'] = one_domain_image($info['image']);
  126. $info['is_collection'] = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $id])->count('id');
  127. $info['is_good'] = Db::name('video_good')->where(['user_id' => $this->auth->id, 'video_id' => $id])->count('id');
  128. //剧集列表
  129. $juji = [];
  130. $video_list = Db::name('video')->field('id, title, image, is_pay')->where(['video_type_id' => $info['video_type_id'], 'status' => 1, 'inject_status' => 2])
  131. ->order('weigh asc, id desc')->select();
  132. if(!empty($video_list)){
  133. $video_list = list_domain_image($video_list, ['image']);
  134. $video_list = array_chunk($video_list,10);
  135. foreach($video_list as $page => $ten){
  136. $juji[] = [
  137. 'name'=> ($page*10 + 1) .'-'. ($page*10 + 10),
  138. 'list'=>$ten,
  139. ];
  140. }
  141. }
  142. //猜你喜欢
  143. $guess_list = Db::name('video')->field('id, title, image, is_pay')->where(['status' => 1, 'inject_status' => 2])
  144. ->orderRaw('rand()')->limit(4)->select();
  145. $guess_list = list_domain_image($guess_list, ['image']);
  146. //记录浏览历史,给浏览历史列表用的,即时的
  147. if($this->auth->isLogin()){
  148. $view_map = [
  149. 'user_id' => $this->auth->id,
  150. 'video_id' => $id,
  151. ];
  152. $check_view = Db::name('video_view')->where($view_map)->find();
  153. if($check_view){
  154. Db::name('video_view')->where($view_map)->update(['updatetime'=>time()]);
  155. }else{
  156. $view_map['createtime'] = time();
  157. $view_map['updatetime'] = time();
  158. Db::name('video_view')->insertGetId($view_map);
  159. }
  160. }
  161. //记录pv,uv
  162. $this->video_pvuv($id);
  163. //
  164. $result = [
  165. 'video_info' => $info,
  166. 'juji_list' => $juji,
  167. 'guess_list' => $guess_list,
  168. ];
  169. $this->success('详情', $result);
  170. }
  171. public function videoinfo_simple() {
  172. $id = input('id', 0, 'intval'); //视频id
  173. if (!$id) {
  174. $this->error('您的网络开小差了');
  175. }
  176. $info = Db::name('video')->field('id,video_type_id, title, image, desc, is_pay, status, inject_status, seriesid, programid, movieid')
  177. ->where(['id' => $id])->find();
  178. if (!$info) {
  179. $this->error('数据不存在');
  180. }
  181. if ($info['status'] != 1) {
  182. $this->error('视频丢失');
  183. }
  184. if ($info['inject_status'] != 2) {
  185. $this->error('视频丢失');
  186. }
  187. $info['image'] = one_domain_image($info['image']);
  188. $info['is_collection'] = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $id])->count('id');
  189. $info['is_good'] = Db::name('video_good')->where(['user_id' => $this->auth->id, 'video_id' => $id])->count('id');
  190. //记录浏览历史,给浏览历史列表用的,即时的
  191. if($this->auth->isLogin()){
  192. $view_map = [
  193. 'user_id' => $this->auth->id,
  194. 'video_id' => $id,
  195. ];
  196. $check_view = Db::name('video_view')->where($view_map)->find();
  197. if($check_view){
  198. Db::name('video_view')->where($view_map)->update(['updatetime'=>time()]);
  199. }else{
  200. $view_map['createtime'] = time();
  201. $view_map['updatetime'] = time();
  202. Db::name('video_view')->insertGetId($view_map);
  203. }
  204. }
  205. //记录pv,uv
  206. $this->video_pvuv($id);
  207. //
  208. $result = [
  209. 'video_info' => $info,
  210. ];
  211. $this->success('详情', $result);
  212. }
  213. //专题页
  214. public function zhuanti(){
  215. $type_id = input('type_id', 0, 'intval'); //分类id
  216. if (!$type_id) {
  217. $this->error('您的网络开小差了~');
  218. }
  219. $list = Db::name('video')->field('id, title, image, is_pay, status, inject_status, seriesid, programid, movieid')->where(['video_type_id' => $type_id, 'status' => 1, 'inject_status' => 2])->order('weigh asc, id desc')->limit(5)->select();
  220. $list = list_domain_image($list, ['image']);
  221. $this->success('视频', $list);
  222. }
  223. //退订服务
  224. public function tudingc()
  225. {
  226. $data = config('site.text_tuiding');
  227. $this->success('', $data);
  228. }
  229. //搜索页
  230. public function search(){
  231. $keyword = input('keyword','');
  232. //热门推荐4个
  233. if(empty($keyword)){
  234. $list = Db::name('video')->field('id, title, image, is_pay')->where(['status' => 1, 'inject_status' => 2])
  235. ->orderRaw('rand()')->limit(12)->select();
  236. $list = list_domain_image($list, ['image']);
  237. }else{
  238. $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();
  239. $list = list_domain_image($list, ['image']);
  240. }
  241. $this->success('视频', $list);
  242. }
  243. //浏览历史
  244. public function history(){
  245. if($this->auth->isLogin()){
  246. $video_view = Db::name('video_view')->where('user_id',$this->auth->id)->order('updatetime desc')->group('video_id')->column('video_id,updatetime');
  247. if(!empty($video_view)){
  248. $video_ids = implode(',',array_keys($video_view));
  249. $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();
  250. $list = list_domain_image($list, ['image']);
  251. foreach($list as $key => $val){
  252. $list[$key]['history_time'] = $video_view[$val['id']];
  253. }
  254. }else{
  255. $list = [];
  256. }
  257. }else{
  258. $list = [];
  259. }
  260. $this->success('视频', $list);
  261. }
  262. //视频收藏/取消收藏
  263. public function video_collection() {
  264. $id = input('id', 0, 'intval');
  265. if (!$id) {
  266. $this->error('您的网络开小差了');
  267. }
  268. $info = Db::name('video')->where(['id' => $id])->find();
  269. if (!$info) {
  270. $this->error('数据不存在');
  271. }
  272. $info['image'] = one_domain_image($info['image']);
  273. //查询是否收藏
  274. $count = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $id])->count('id');
  275. //开启事务
  276. if ($count) {
  277. $result = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $id])->delete();
  278. Db::name('video')->where('id',$id)->setDec('collect_number',1); //收藏数减少
  279. } else {
  280. $result = Db::name('video_collection')->insertGetId(['user_id' => $this->auth->id, 'video_id' => $id, 'createtime' => time()]);
  281. Db::name('video')->where('id',$id)->setInc('collect_number',1); //收藏数增加
  282. }
  283. if (!$result) {
  284. Db::rollback();
  285. $this->error('操作失败');
  286. }
  287. $url = 'http://meta-history.unso.gitv.tv/OTT/jscmcc/addThirdPartyCollectionRecord';
  288. $content = [
  289. 'cpPrvdName' => '健康e家',
  290. 'cpPrvCode' => '41000144',
  291. 'cpPrvType' => '1006',
  292. 'content' => $info['title'],
  293. 'ChnCode' => '1000020',
  294. 'contentId' => (string)$info['movieid'],
  295. 'extraContentID' => '',
  296. 'isEffective' => $info['status'],
  297. 'isPaid' => $info['is_pay'],
  298. 'collectionFlag' => $count ? 0 : 1,
  299. 'account' => $this->encrypt($this->auth->mobile, '!@#$%^&*FJGFJT78'),
  300. 'cpPermission' => 'GITV',
  301. 'intent' => [
  302. 'action' => 'com.huxiu.heh.tv.ui.splash.SplashActivity',
  303. 'package' => 'com.huxiu.heh.tv',
  304. 'component' => [
  305. 'pkg' => 'com.huxiu.heh.tv',
  306. 'cls' => 'com.huxiu.heh.tv.ui.splash.SplashActivity'
  307. ],
  308. 'extras' => [
  309. /*'cmd' => '',
  310. 'from' => '',
  311. 'media_id' => ''*/
  312. 'type_id' => $info['video_type_id'],
  313. 'id' => $info['id']
  314. ]
  315. ],
  316. 'imageURL' => $info['image']
  317. ];
  318. $content = json_encode($content, 320);
  319. $rt = httpRequest($url, 'POST', $content);
  320. file_put_contents('shoucang.txt',$id.'_'.$rt.PHP_EOL, FILE_APPEND);
  321. if (!$rt) {
  322. Db::rollback();
  323. $this->error('操作失败');
  324. }
  325. $rt = json_decode($rt, true);
  326. if (empty($rs) || $rt['code'] != 0) {
  327. Db::rollback();
  328. $this->error('操作失败');
  329. }
  330. //大数据上报
  331. $data = [
  332. 'favid' => (string)(config('data_cp_id') . date('Ymd') . getMillisecond() . mt_rand(10000000, 99999999)),
  333. 'UserID' => $this->auth->mobile,
  334. 'time' => date('Y-m-d H:i:s'),
  335. 'type' => $count ? 0 : 1,
  336. 'cpid' => config('data_cp_id'),
  337. 'albumid' => $id,
  338. 'albumname' => $info['title']
  339. ];
  340. $data = join(json_decode('"\u0001"', true), $data);
  341. $filename = date('Ymd').'_'.config('data_cp_id').'_userfavdata_1.dat';
  342. $check_filename = date('Ymd').'_'.config('data_cp_id').'_userfavdata_1.chk';
  343. error_log(print_r($data, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  344. error_log('', 3, './dashuju/' . $check_filename);
  345. $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_userfavdata.finish';
  346. error_log('', 3, './dashuju/' . $finish_filename);
  347. Db::commit();
  348. $this->success('操作成功');
  349. }
  350. //点赞视频、取消点赞
  351. public function video_good() {
  352. $id = input('id', 0, 'intval');
  353. if (!$id) {
  354. $this->error('您的网络开小差了');
  355. }
  356. $info = Db::name('video')->where(['id' => $id])->find();
  357. if (!$info) {
  358. $this->error('数据不存在');
  359. }
  360. //查询是否收藏
  361. $check = Db::name('video_good')->where(['user_id' => $this->auth->id, 'video_id' => $id])->find();
  362. //开启事务
  363. if ($check) {
  364. $result = Db::name('video_good')->where(['user_id' => $this->auth->id, 'video_id' => $id])->delete();
  365. Db::name('video')->where('id',$id)->setDec('good_number',1); //点赞数减少
  366. } else {
  367. $result = Db::name('video_good')->insertGetId(['user_id' => $this->auth->id, 'video_id' => $id, 'createtime' => time()]);
  368. Db::name('video')->where('id',$id)->setInc('good_number',1); //点赞数增加
  369. }
  370. $this->success('操作成功');
  371. }
  372. //用户观看行为(支付)
  373. public function payuserplay() {
  374. $id = input('id', 0, 'intval'); //视频id
  375. $sn = input('sn', '', 'trim'); //SN号
  376. $start_time = input('start_time', '', 'trim'); //yyyymmddhhmmss (24小时制),节目开始播放时间
  377. $end_time = input('end_time', '', 'trim'); //yyyymmddhhmmss (24小时制),节目结束播放时间,如果播放未结束,但是此时需要同步数据,填当前时间
  378. $csource = input('csource', 0, ''); //1:从搜索结果访问2:从用户收藏/书签访问3:从EPG访问4:从推荐页面访问5、其他
  379. if (!$id) {
  380. $this->error('您的网络开小差了');
  381. }
  382. $info = Db::name('video')->where(['id' => $id])->find();
  383. if (!$info) {
  384. $this->error('数据不存在');
  385. }
  386. //播放日志
  387. $play_data = [
  388. 'user_id' => $this->auth->id,
  389. 'video_id' => $id,
  390. 'sn' => $sn,
  391. 'start_time' => $start_time,
  392. 'end_time' => $end_time,
  393. 'csource' => $csource,
  394. 'createtime' => time(),
  395. 'updatetime' => time(),
  396. ];
  397. Db::name('video_play_payuserplay')->insertGetId($play_data);
  398. $content = [
  399. 'UserID' => $this->auth->mobile,
  400. 'city' => '14',
  401. 'start_time' => $start_time,
  402. 'end_time' => $end_time,
  403. 'service_type' => 1,
  404. 'albumid' => $id,
  405. 'albumname' => $info['title'],
  406. 'csource' => $csource,
  407. 'SN' => $sn,
  408. 'ip' => request()->ip(),
  409. 'fee_type' => $info['is_pay'] == 1 ? 1 : '',
  410. 'flow' => '',
  411. 'product' => '',
  412. 'product_name' => '',
  413. 'info_source' => '02'
  414. ];
  415. $content = join('|', $content);
  416. $filename = date('YmdH').'_'.config('cp_id').'_userviewdata_1.dat';
  417. $check_filename = date('YmdH').'_'.config('cp_id').'_userviewdata_1.chk';
  418. error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  419. error_log('', 3, './dashuju/' . $check_filename);
  420. $this->success('');
  421. }
  422. //视频播放记录
  423. public function playrecord() {
  424. $id = input('id', 0, 'intval');
  425. $total_time = input('total_time', 0, 'intval'); //总时长
  426. $start_time = input('start_time', 0, 'intval'); //开始看时间:相对时间
  427. $end_time = input('end_time', 0, 'intval'); //结束看时间:相对时间
  428. $log_type = input('log_type', 'watching', 'trim'); //begin:开始播放;watching:正在播放;end:结束播放
  429. if (!$id) {
  430. $this->error('您的网络开小差了');
  431. }
  432. $info = Db::name('video')->where(['id' => $id])->find();
  433. if (!$info) {
  434. $this->error('数据不存在');
  435. }
  436. if ($info['inject_status'] != 2) {
  437. $this->error('视频丢失');
  438. }
  439. //播放日志
  440. $play_data = [
  441. 'user_id' => $this->auth->id,
  442. 'video_id' => $id,
  443. 'total_time' => $total_time,
  444. 'start_time' => $start_time,
  445. 'end_time' => $end_time,
  446. 'log_type' => $log_type,
  447. 'createtime' => time(),
  448. 'updatetime' => time(),
  449. ];
  450. Db::name('video_play_playrecord')->insertGetId($play_data);
  451. $info['image'] = one_domain_image($info['image']);
  452. $url = 'http://meta-history.unso.gitv.tv/OTT/jscmcc/addThirdPartyHistoryRecord';
  453. $content = [
  454. 'cpPrvdName' => '健康e家',
  455. 'cpPrvCode' => '41000144',
  456. 'cpPrvType' => '1006',
  457. 'contentName' => $info['title'],
  458. 'ChnName' => '健康',
  459. 'ChnCode' => '1000020',
  460. 'contentId' => (string)$info['movieid'],
  461. 'extraContentID' => '',
  462. 'isEffective' => $info['status'],
  463. 'isPaid' => $info['is_pay'],
  464. 'contentTotalTime' => $total_time,
  465. 'startWatchTime' => $start_time,
  466. 'endWatchTime' => $end_time,
  467. 'playTime' => $end_time - $start_time,
  468. 'logType' => $log_type,
  469. 'account' => $this->encrypt($this->auth->mobile, '!@#$%^&*FJGFJT78'),
  470. 'cpPermission' => 'GITV',
  471. 'intent' => [
  472. 'action' => 'com.huxiu.heh.tv.ui.splash.SplashActivity',
  473. 'package' => 'com.huxiu.heh.tv',
  474. 'component' => [
  475. 'pkg' => 'com.huxiu.heh.tv',
  476. 'cls' => 'com.huxiu.heh.tv.ui.splash.SplashActivity'
  477. ],
  478. 'extras' => [
  479. /*'cmd' => '',
  480. 'from' => '',
  481. 'media_id' => ''*/
  482. 'type_id' => $info['video_type_id'],
  483. 'id' => $info['id']
  484. ]
  485. ],
  486. 'imageURL' => $info['image']
  487. ];
  488. $content = json_encode($content, 320);
  489. $rt = httpRequest($url, 'POST', $content);
  490. file_put_contents('bofang.txt',$id.'_'.$rt.PHP_EOL, FILE_APPEND);
  491. if (!$rt) {
  492. //$this->error('同步失败');
  493. }
  494. $rt = json_decode($rt, true);
  495. if (isset($rt['code']) && $rt['code'] != 0) {
  496. //$this->error('同步失败');
  497. }
  498. $this->success('同步成功');
  499. }
  500. //用户观看行为(大数据)
  501. public function userplay() {
  502. $id = input('id', 0, 'intval'); //视频id
  503. $sn = input('sn', '', 'trim'); //SN号
  504. $start_time = input('start_time', '', 'trim'); //YYYY-MM-DD HH:MM:SS(24小时制)节目开始播放时间
  505. $end_time = input('end_time', '', 'trim'); //YYYY-MM-DD HH:MM:SS(24小时制)节目结束播放时间
  506. $csource = input('csource', 0, ''); //1:从搜索结果访问2:从用户收藏/书签访问3:从EPG访问4:从推荐页面访问5:从猜你喜欢个性化推荐页面访问(带上推荐接口的trace_id)99:其他
  507. $trace_id = input('trace_id', '', 'trim');
  508. $istry = input('istry', 0, 'intval'); //0非试看 1试看
  509. $start_posi = input('start_posi', 0, 'intval'); //播放起始点相对于影片起始点的时长,单位秒,例如从影片第 600 秒开始观看
  510. if (!$id) {
  511. $this->error('您的网络开小差了');
  512. }
  513. $info = Db::name('video')->where(['id' => $id])->find();
  514. if (!$info) {
  515. $this->error('数据不存在');
  516. }
  517. //播放日志
  518. $play_data = [
  519. 'user_id' => $this->auth->id,
  520. 'video_id' => $id,
  521. 'sn' => $sn,
  522. 'start_time' => $start_time,
  523. 'end_time' => $end_time,
  524. 'csource' => $csource,
  525. 'trace_id' => $trace_id,
  526. 'istry' => $istry,
  527. 'start_posi' => $start_posi,
  528. 'createtime' => time(),
  529. 'updatetime' => time(),
  530. ];
  531. Db::name('video_play_userplay')->insertGetId($play_data);
  532. $content = [
  533. 'playid' => (string)(config('data_cp_id') . date('Ymd') . getMillisecond() . mt_rand(10000000, 99999999)),
  534. 'UserID' => $this->auth->mobile,
  535. 'SN' => $sn,
  536. 'start_time' => $start_time,
  537. 'end_time' => $end_time,
  538. 'service_type' => 1,
  539. 'cpid' => config('data_cp_id'),
  540. 'albumid' => $id,
  541. 'albumname' => $info['title'],
  542. 'videoid' => $id,
  543. 'videoname' => $info['title'],
  544. 'csource' => $csource,
  545. 'trace_id' => $trace_id,
  546. 'fee_type' => $info['is_pay'] == 1 ? 1 : 4,
  547. 'istry' => $istry,
  548. 'iscon' => 0,
  549. 'start_posi' => $start_posi
  550. ];
  551. $content = join(json_decode('"\u0001"', true), $content);
  552. $filename = date('Ymd').'_'.config('data_cp_id').'_userplaydata_1.dat';
  553. $check_filename = date('Ymd').'_'.config('data_cp_id').'_userplaydata_1.chk';
  554. error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  555. error_log('', 3, './dashuju/' . $check_filename);
  556. $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_userplaydata.finish';
  557. error_log('', 3, './dashuju/' . $finish_filename);
  558. $this->success('');
  559. }
  560. //获取特殊机型
  561. public function special_models() {
  562. $special_models = config('site.special_models');
  563. $special_models = explode(',', $special_models);
  564. $this->success('获取特殊机型', $special_models);
  565. }
  566. //前端报错记录
  567. public function app_error() {
  568. $this->success('');
  569. }
  570. /** * * @param string $string 需要加密的字符串 * @param string $key 密钥 * @return string */
  571. private function encrypt($string, $key) {
  572. // $key = substr(openssl_digest(openssl_digest($key, 'sha1', true), 'sha1', true), 0, 16);
  573. $data = openssl_encrypt($string, 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
  574. $data = bin2hex($data);
  575. return $data;
  576. }
  577. /** * @param string $string 需要解密的字符串 * @param string $key 密钥 * @return string */
  578. private function decrypt($string, $key) {
  579. // $key = substr(openssl_digest(openssl_digest($key, 'sha1', true), 'sha1', true), 0, 16);
  580. $decrypted = openssl_decrypt(hex2bin($string), 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
  581. return $decrypted;
  582. }
  583. //共有方法,
  584. private function video_pvuv($video_id = 0){
  585. if(empty($video_id)) {return true;}
  586. //开启redis
  587. $redis = new Redis();
  588. $config = config('redis');
  589. $redis->connect($config['redis_host'], $config['redis_port']);
  590. if ($config['redis_pwd']) {
  591. $redis->auth($config['redis_pwd']);
  592. }
  593. if($config['redis_selectdb'] > 0){
  594. $redis->select($config['redis_selectdb']);
  595. }
  596. //今天
  597. $today = date('Y-m-d');
  598. //今日pv+1
  599. $today_pv_key = $today.'_video_pv_'.$video_id;
  600. $redis->incr($today_pv_key,1);
  601. //今日uv+1
  602. if($this->auth->isLogin() && $this->auth->id){
  603. $today_uv_key = $today.'_video_uv_'.$video_id;
  604. $uid = $this->auth->id;
  605. $redis->sAdd($today_uv_key,$uid);
  606. }
  607. //今日视频id列表
  608. $today_video_key = $today.'_video_list';
  609. $redis->sAdd($today_video_key,$video_id);
  610. }
  611. /*public function test(){
  612. $this->video_pvuv(input('video_id',0));
  613. }*/
  614. }