Tvindex.php 26 KB

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