Tvindex.php 26 KB

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