Tvindex.php 26 KB

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