Tvindex.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  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(6)->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. $video_type = Db::name('video_type')->field('id,name,bg_image')->where('id',$type_id)->find();
  220. $video_type = info_domain_image($video_type,['bg_image']);
  221. $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();
  222. $list = list_domain_image($list, ['image']);
  223. $result = [
  224. 'info' => $video_type,
  225. 'list' => $list,
  226. ];
  227. $this->success('视频', $result);
  228. }
  229. //退订服务
  230. public function tudingc()
  231. {
  232. $data = config('site.text_tuiding');
  233. $this->success('', $data);
  234. }
  235. //搜索页
  236. public function search(){
  237. $keyword = input('keyword','');
  238. //热门推荐4个
  239. if(empty($keyword)){
  240. $list = Db::name('video')->field('id, title, image, is_pay')->where(['status' => 1, 'inject_status' => 2])
  241. ->orderRaw('rand()')->limit(12)->select();
  242. $list = list_domain_image($list, ['image']);
  243. }else{
  244. $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();
  245. $list = list_domain_image($list, ['image']);
  246. }
  247. $this->success('视频', $list);
  248. }
  249. //浏览历史
  250. public function history(){
  251. if($this->auth->isLogin()){
  252. $video_view = Db::name('video_view')->where('user_id',$this->auth->id)->order('updatetime desc')->group('video_id')->column('video_id,updatetime');
  253. if(!empty($video_view)){
  254. $video_ids = implode(',',array_keys($video_view));
  255. $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();
  256. $list = list_domain_image($list, ['image']);
  257. foreach($list as $key => $val){
  258. $list[$key]['history_time'] = $video_view[$val['id']];
  259. }
  260. }else{
  261. $list = [];
  262. }
  263. }else{
  264. $list = [];
  265. }
  266. $this->success('视频', $list);
  267. }
  268. //视频收藏/取消收藏
  269. public function video_collection() {
  270. $id = input('id', 0, 'intval');
  271. if (!$id) {
  272. $this->error('您的网络开小差了');
  273. }
  274. $info = Db::name('video')->where(['id' => $id])->find();
  275. if (!$info) {
  276. $this->error('数据不存在');
  277. }
  278. $info['image'] = one_domain_image($info['image']);
  279. //查询是否收藏
  280. $count = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $id])->count('id');
  281. //开启事务
  282. if ($count) {
  283. $result = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $id])->delete();
  284. Db::name('video')->where('id',$id)->setDec('collect_number',1); //收藏数减少
  285. } else {
  286. $result = Db::name('video_collection')->insertGetId(['user_id' => $this->auth->id, 'video_id' => $id, 'createtime' => time()]);
  287. Db::name('video')->where('id',$id)->setInc('collect_number',1); //收藏数增加
  288. }
  289. if (!$result) {
  290. Db::rollback();
  291. $this->error('操作失败');
  292. }
  293. $url = 'http://meta-history.unso.gitv.tv/OTT/jscmcc/addThirdPartyCollectionRecord';
  294. $content = [
  295. 'cpPrvdName' => '健康e家',
  296. 'cpPrvCode' => '41000144',
  297. 'cpPrvType' => '1006',
  298. 'content' => $info['title'],
  299. 'ChnCode' => '1000020',
  300. 'contentId' => (string)$info['movieid'],
  301. 'extraContentID' => '',
  302. 'isEffective' => $info['status'],
  303. 'isPaid' => $info['is_pay'],
  304. 'collectionFlag' => $count ? 0 : 1,
  305. 'account' => $this->encrypt($this->auth->mobile, '!@#$%^&*FJGFJT78'),
  306. 'cpPermission' => 'GITV',
  307. 'intent' => [
  308. 'action' => 'com.huxiu.heh.tv.ui.splash.SplashActivity',
  309. 'package' => 'com.huxiu.heh.tv',
  310. 'component' => [
  311. 'pkg' => 'com.huxiu.heh.tv',
  312. 'cls' => 'com.huxiu.heh.tv.ui.splash.SplashActivity'
  313. ],
  314. 'extras' => [
  315. /*'cmd' => '',
  316. 'from' => '',
  317. 'media_id' => ''*/
  318. 'type_id' => $info['video_type_id'],
  319. 'id' => $info['id']
  320. ]
  321. ],
  322. 'imageURL' => $info['image']
  323. ];
  324. $content = json_encode($content, 320);
  325. $rt = httpRequest($url, 'POST', $content);
  326. file_put_contents('shoucang.txt',$id.'_'.$rt.PHP_EOL, FILE_APPEND);
  327. if (!$rt) {
  328. Db::rollback();
  329. $this->error('操作失败');
  330. }
  331. $rt = json_decode($rt, true);
  332. if (empty($rs) || $rt['code'] != 0) {
  333. Db::rollback();
  334. $this->error('操作失败');
  335. }
  336. //大数据上报
  337. $data = [
  338. 'favid' => (string)(config('data_cp_id') . date('Ymd') . getMillisecond() . mt_rand(10000000, 99999999)),
  339. 'UserID' => $this->auth->mobile,
  340. 'time' => date('Y-m-d H:i:s'),
  341. 'type' => $count ? 0 : 1,
  342. 'cpid' => config('data_cp_id'),
  343. 'albumid' => $id,
  344. 'albumname' => $info['title']
  345. ];
  346. $data = join(json_decode('"\u0001"', true), $data);
  347. $filename = date('Ymd').'_'.config('data_cp_id').'_userfavdata_1.dat';
  348. $check_filename = date('Ymd').'_'.config('data_cp_id').'_userfavdata_1.chk';
  349. error_log(print_r($data, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  350. error_log('', 3, './dashuju/' . $check_filename);
  351. $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_userfavdata.finish';
  352. error_log('', 3, './dashuju/' . $finish_filename);
  353. Db::commit();
  354. $this->success('操作成功');
  355. }
  356. //点赞视频、取消点赞
  357. public function video_good() {
  358. $id = input('id', 0, 'intval');
  359. if (!$id) {
  360. $this->error('您的网络开小差了');
  361. }
  362. $info = Db::name('video')->where(['id' => $id])->find();
  363. if (!$info) {
  364. $this->error('数据不存在');
  365. }
  366. //查询是否收藏
  367. $check = Db::name('video_good')->where(['user_id' => $this->auth->id, 'video_id' => $id])->find();
  368. //开启事务
  369. if ($check) {
  370. $result = Db::name('video_good')->where(['user_id' => $this->auth->id, 'video_id' => $id])->delete();
  371. Db::name('video')->where('id',$id)->setDec('good_number',1); //点赞数减少
  372. } else {
  373. $result = Db::name('video_good')->insertGetId(['user_id' => $this->auth->id, 'video_id' => $id, 'createtime' => time()]);
  374. Db::name('video')->where('id',$id)->setInc('good_number',1); //点赞数增加
  375. }
  376. $this->success('操作成功');
  377. }
  378. //用户观看行为(支付)
  379. public function payuserplay() {
  380. $id = input('id', 0, 'intval'); //视频id
  381. $sn = input('sn', '', 'trim'); //SN号
  382. $start_time = input('start_time', '', 'trim'); //yyyymmddhhmmss (24小时制),节目开始播放时间
  383. $end_time = input('end_time', '', 'trim'); //yyyymmddhhmmss (24小时制),节目结束播放时间,如果播放未结束,但是此时需要同步数据,填当前时间
  384. $csource = input('csource', 0, ''); //1:从搜索结果访问2:从用户收藏/书签访问3:从EPG访问4:从推荐页面访问5、其他
  385. if (!$id) {
  386. $this->error('您的网络开小差了');
  387. }
  388. $info = Db::name('video')->where(['id' => $id])->find();
  389. if (!$info) {
  390. $this->error('数据不存在');
  391. }
  392. //播放日志
  393. $play_data = [
  394. 'user_id' => $this->auth->id,
  395. 'video_id' => $id,
  396. 'sn' => $sn,
  397. 'start_time' => $start_time,
  398. 'end_time' => $end_time,
  399. 'csource' => $csource,
  400. 'createtime' => time(),
  401. 'updatetime' => time(),
  402. ];
  403. Db::name('video_play_payuserplay')->insertGetId($play_data);
  404. $content = [
  405. 'UserID' => $this->auth->mobile,
  406. 'city' => '14',
  407. 'start_time' => $start_time,
  408. 'end_time' => $end_time,
  409. 'service_type' => 1,
  410. 'albumid' => $id,
  411. 'albumname' => $info['title'],
  412. 'csource' => $csource,
  413. 'SN' => $sn,
  414. 'ip' => request()->ip(),
  415. 'fee_type' => $info['is_pay'] == 1 ? 1 : '',
  416. 'flow' => '',
  417. 'product' => '',
  418. 'product_name' => '',
  419. 'info_source' => '02'
  420. ];
  421. $content = join('|', $content);
  422. $filename = date('YmdH').'_'.config('cp_id').'_userviewdata_1.dat';
  423. $check_filename = date('YmdH').'_'.config('cp_id').'_userviewdata_1.chk';
  424. error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  425. error_log('', 3, './dashuju/' . $check_filename);
  426. $this->success('');
  427. }
  428. //视频播放记录
  429. public function playrecord() {
  430. $id = input('id', 0, 'intval');
  431. $total_time = input('total_time', 0, 'intval'); //总时长
  432. $start_time = input('start_time', 0, 'intval'); //开始看时间:相对时间
  433. $end_time = input('end_time', 0, 'intval'); //结束看时间:相对时间
  434. $log_type = input('log_type', 'watching', 'trim'); //begin:开始播放;watching:正在播放;end:结束播放
  435. if (!$id) {
  436. $this->error('您的网络开小差了');
  437. }
  438. $info = Db::name('video')->where(['id' => $id])->find();
  439. if (!$info) {
  440. $this->error('数据不存在');
  441. }
  442. if ($info['inject_status'] != 2) {
  443. $this->error('视频丢失');
  444. }
  445. //播放日志
  446. $play_data = [
  447. 'user_id' => $this->auth->id,
  448. 'video_id' => $id,
  449. 'total_time' => $total_time,
  450. 'start_time' => $start_time,
  451. 'end_time' => $end_time,
  452. 'log_type' => $log_type,
  453. 'createtime' => time(),
  454. 'updatetime' => time(),
  455. ];
  456. Db::name('video_play_playrecord')->insertGetId($play_data);
  457. $info['image'] = one_domain_image($info['image']);
  458. $url = 'http://meta-history.unso.gitv.tv/OTT/jscmcc/addThirdPartyHistoryRecord';
  459. $content = [
  460. 'cpPrvdName' => '健康e家',
  461. 'cpPrvCode' => '41000144',
  462. 'cpPrvType' => '1006',
  463. 'contentName' => $info['title'],
  464. 'ChnName' => '健康',
  465. 'ChnCode' => '1000020',
  466. 'contentId' => (string)$info['movieid'],
  467. 'extraContentID' => '',
  468. 'isEffective' => $info['status'],
  469. 'isPaid' => $info['is_pay'],
  470. 'contentTotalTime' => $total_time,
  471. 'startWatchTime' => $start_time,
  472. 'endWatchTime' => $end_time,
  473. 'playTime' => $end_time - $start_time,
  474. 'logType' => $log_type,
  475. 'account' => $this->encrypt($this->auth->mobile, '!@#$%^&*FJGFJT78'),
  476. 'cpPermission' => 'GITV',
  477. 'intent' => [
  478. 'action' => 'com.huxiu.heh.tv.ui.splash.SplashActivity',
  479. 'package' => 'com.huxiu.heh.tv',
  480. 'component' => [
  481. 'pkg' => 'com.huxiu.heh.tv',
  482. 'cls' => 'com.huxiu.heh.tv.ui.splash.SplashActivity'
  483. ],
  484. 'extras' => [
  485. /*'cmd' => '',
  486. 'from' => '',
  487. 'media_id' => ''*/
  488. 'type_id' => $info['video_type_id'],
  489. 'id' => $info['id']
  490. ]
  491. ],
  492. 'imageURL' => $info['image']
  493. ];
  494. $content = json_encode($content, 320);
  495. $rt = httpRequest($url, 'POST', $content);
  496. file_put_contents('bofang.txt',$id.'_'.$rt.PHP_EOL, FILE_APPEND);
  497. if (!$rt) {
  498. //$this->error('同步失败');
  499. }
  500. $rt = json_decode($rt, true);
  501. if (isset($rt['code']) && $rt['code'] != 0) {
  502. //$this->error('同步失败');
  503. }
  504. $this->success('同步成功');
  505. }
  506. //用户观看行为(大数据)
  507. public function userplay() {
  508. $id = input('id', 0, 'intval'); //视频id
  509. $sn = input('sn', '', 'trim'); //SN号
  510. $start_time = input('start_time', '', 'trim'); //YYYY-MM-DD HH:MM:SS(24小时制)节目开始播放时间
  511. $end_time = input('end_time', '', 'trim'); //YYYY-MM-DD HH:MM:SS(24小时制)节目结束播放时间
  512. $csource = input('csource', 0, ''); //1:从搜索结果访问2:从用户收藏/书签访问3:从EPG访问4:从推荐页面访问5:从猜你喜欢个性化推荐页面访问(带上推荐接口的trace_id)99:其他
  513. $trace_id = input('trace_id', '', 'trim');
  514. $istry = input('istry', 0, 'intval'); //0非试看 1试看
  515. $start_posi = input('start_posi', 0, 'intval'); //播放起始点相对于影片起始点的时长,单位秒,例如从影片第 600 秒开始观看
  516. if (!$id) {
  517. $this->error('您的网络开小差了');
  518. }
  519. $info = Db::name('video')->where(['id' => $id])->find();
  520. if (!$info) {
  521. $this->error('数据不存在');
  522. }
  523. //播放日志
  524. $play_data = [
  525. 'user_id' => $this->auth->id,
  526. 'video_id' => $id,
  527. 'sn' => $sn,
  528. 'start_time' => $start_time,
  529. 'end_time' => $end_time,
  530. 'csource' => $csource,
  531. 'trace_id' => $trace_id,
  532. 'istry' => $istry,
  533. 'start_posi' => $start_posi,
  534. 'createtime' => time(),
  535. 'updatetime' => time(),
  536. ];
  537. Db::name('video_play_userplay')->insertGetId($play_data);
  538. $content = [
  539. 'playid' => (string)(config('data_cp_id') . date('Ymd') . getMillisecond() . mt_rand(10000000, 99999999)),
  540. 'UserID' => $this->auth->mobile,
  541. 'SN' => $sn,
  542. 'start_time' => $start_time,
  543. 'end_time' => $end_time,
  544. 'service_type' => 1,
  545. 'cpid' => config('data_cp_id'),
  546. 'albumid' => $id,
  547. 'albumname' => $info['title'],
  548. 'videoid' => $id,
  549. 'videoname' => $info['title'],
  550. 'csource' => $csource,
  551. 'trace_id' => $trace_id,
  552. 'fee_type' => $info['is_pay'] == 1 ? 1 : 4,
  553. 'istry' => $istry,
  554. 'iscon' => 0,
  555. 'start_posi' => $start_posi
  556. ];
  557. $content = join(json_decode('"\u0001"', true), $content);
  558. $filename = date('Ymd').'_'.config('data_cp_id').'_userplaydata_1.dat';
  559. $check_filename = date('Ymd').'_'.config('data_cp_id').'_userplaydata_1.chk';
  560. error_log(print_r($content, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  561. error_log('', 3, './dashuju/' . $check_filename);
  562. $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_userplaydata.finish';
  563. error_log('', 3, './dashuju/' . $finish_filename);
  564. $this->success('');
  565. }
  566. //获取特殊机型
  567. public function special_models() {
  568. $special_models = config('site.special_models');
  569. $special_models = explode(',', $special_models);
  570. $this->success('获取特殊机型', $special_models);
  571. }
  572. //前端报错记录
  573. public function app_error() {
  574. $this->success('');
  575. }
  576. /** * * @param string $string 需要加密的字符串 * @param string $key 密钥 * @return string */
  577. private function encrypt($string, $key) {
  578. // $key = substr(openssl_digest(openssl_digest($key, 'sha1', true), 'sha1', true), 0, 16);
  579. $data = openssl_encrypt($string, 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
  580. $data = bin2hex($data);
  581. return $data;
  582. }
  583. /** * @param string $string 需要解密的字符串 * @param string $key 密钥 * @return string */
  584. private function decrypt($string, $key) {
  585. // $key = substr(openssl_digest(openssl_digest($key, 'sha1', true), 'sha1', true), 0, 16);
  586. $decrypted = openssl_decrypt(hex2bin($string), 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
  587. return $decrypted;
  588. }
  589. //共有方法,
  590. private function video_pvuv($video_id = 0){
  591. if(empty($video_id)) {return true;}
  592. //开启redis
  593. $redis = new Redis();
  594. $config = config('redis');
  595. $redis->connect($config['redis_host'], $config['redis_port']);
  596. if ($config['redis_pwd']) {
  597. $redis->auth($config['redis_pwd']);
  598. }
  599. if($config['redis_selectdb'] > 0){
  600. $redis->select($config['redis_selectdb']);
  601. }
  602. //今天
  603. $today = date('Y-m-d');
  604. //今日pv+1
  605. $today_pv_key = $today.'_video_pv_'.$video_id;
  606. $redis->incr($today_pv_key,1);
  607. //今日uv+1
  608. if($this->auth->isLogin() && $this->auth->id){
  609. $today_uv_key = $today.'_video_uv_'.$video_id;
  610. $uid = $this->auth->id;
  611. $redis->sAdd($today_uv_key,$uid);
  612. }
  613. //今日视频id列表
  614. $today_video_key = $today.'_video_list';
  615. $redis->sAdd($today_video_key,$video_id);
  616. }
  617. /*public function test(){
  618. $this->video_pvuv(input('video_id',0));
  619. }*/
  620. }