Tvindex.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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','image_childcate','image_list','videoinfo_simple','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. //子分类数量
  42. $video_count = Db::name('video')->field('childcate_id,count(id)')->group('childcate_id')->where('childcate_id','neq','0')->where('status',1)->where('inject_status',2)->column('childcate_id,count(id)');
  43. foreach($video_childcate as $key => $val){
  44. $video_childcate[$key]['video_number'] = isset($video_count[$val['id']]) ? $video_count[$val['id']] : 0;
  45. }
  46. //分布:1=左一右四,2=两行八个,3=一行四个,4=一行三个
  47. foreach($video_cate as $key => $cate){
  48. $cate['child'] = [];
  49. //循环放入child
  50. $child = [];
  51. foreach($video_childcate as $k => $v){
  52. if($cate['id'] == $v['cate_id']){
  53. $child[] = $v;
  54. }
  55. }
  56. $cate['child'] = $child;
  57. $video_cate[$key] = $cate;
  58. }
  59. $data['video_cate'] = $video_cate;
  60. //图片大分类+子类
  61. $image_cate = Db::name('image_cate')->field('id,name,image')->where('status',1)->order('weigh asc, id desc')->select();
  62. $image_cate = list_domain_image($image_cate, ['image']);
  63. $data['image_cate'] = $image_cate;
  64. $this->success('首页',$data);
  65. }
  66. //更多页,应该是没用了
  67. //视频列表
  68. /*public function video_list() {
  69. $type_id = input('type_id', 0, 'intval'); //分类id
  70. if (!$type_id) {
  71. $this->error('您的网络开小差了~');
  72. }
  73. $video_type = Db::name('video_type')->where('id',$type_id)->value('name');
  74. $list = Db::name('video')->field('id, title, image, is_pay')->where(['video_type_id' => $type_id, 'status' => 1, 'inject_status' => 2])
  75. ->order('weigh asc, id desc')->select();
  76. $list = list_domain_image($list, ['image']);
  77. $result = [
  78. 'typename' => $video_type,
  79. 'videolist' => $list,
  80. ];
  81. $this->success('视频更多', $result);
  82. }*/
  83. //视频详情
  84. public function videoinfo() {
  85. $id = input('id', 0, 'intval'); //视频id
  86. $childcate_id = input('child_id',0,'intval'); //子分类id
  87. if (!$id && !$childcate_id) {
  88. $this->error('您的网络开小差了');
  89. }
  90. if($id){
  91. $info = Db::name('video')->field('id,video_type_id,childcate_id, title, image, desc, is_pay, status, inject_status, seriesid, programid, movieid')
  92. ->where(['id' => $id])->find();
  93. }else{
  94. $info = Db::name('video')->field('id,video_type_id,childcate_id, title, image, desc, is_pay, status, inject_status, seriesid, programid, movieid')
  95. ->where(['childcate_id' => $childcate_id])->where(['status'=>1,'inject_status'=>2])->order('weigh asc,id desc')->find();
  96. }
  97. if (!$info && !empty($childcate_id)) {
  98. $this->success(1,'{}');
  99. }
  100. if (!$info) {
  101. $this->error('不存在的视频');
  102. }
  103. if ($info['status'] != 1) {
  104. $this->error('视频丢失');
  105. }
  106. if ($info['inject_status'] != 2) {
  107. $this->error('视频丢失');
  108. }
  109. $info['image'] = one_domain_image($info['image']);
  110. $info['is_collection'] = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $info['id']])->count('id');
  111. $info['is_good'] = Db::name('video_good')->where(['user_id' => $this->auth->id, 'video_id' => $info['id']])->count('id');
  112. //剧集列表
  113. $juji = [];
  114. $video_list = Db::name('video')->field('id, title, image, is_pay')->where(['childcate_id' => $info['childcate_id'], 'status' => 1, 'inject_status' => 2])
  115. ->order('weigh asc, id desc')->select();
  116. if(!empty($video_list)){
  117. $video_list = list_domain_image($video_list, ['image']);
  118. $video_list = array_chunk($video_list,10);
  119. foreach($video_list as $page => $ten){
  120. $juji[] = [
  121. 'name'=> ($page*10 + 1) .'-'. ($page*10 + count($ten)),
  122. 'list'=>$ten,
  123. ];
  124. }
  125. }
  126. //猜你喜欢
  127. $juji_ids = array_column($juji,'id');
  128. $guess_list = Db::name('video')->field('id, title, image, is_pay')->where(['status' => 1, 'inject_status' => 2])->where('id','NOTIN',$juji_ids)
  129. ->orderRaw('rand()')->limit(6)->select();
  130. $guess_list = list_domain_image($guess_list, ['image']);
  131. //记录浏览历史,给浏览历史列表用的,即时的
  132. if($this->auth->isLogin()){
  133. $view_map = [
  134. 'user_id' => $this->auth->id,
  135. 'video_id' => $info['id'],
  136. ];
  137. $check_view = Db::name('video_view')->where($view_map)->find();
  138. if($check_view){
  139. Db::name('video_view')->where($view_map)->update(['updatetime'=>time()]);
  140. }else{
  141. $view_map['createtime'] = time();
  142. $view_map['updatetime'] = time();
  143. Db::name('video_view')->insertGetId($view_map);
  144. }
  145. }
  146. //记录pv,uv
  147. $this->video_pvuv($info['id']);
  148. //
  149. $result = [
  150. 'video_info' => $info,
  151. 'juji_list' => $juji,
  152. 'guess_list' => $guess_list,
  153. ];
  154. $this->success('详情', $result);
  155. }
  156. public function videoinfo_simple() {
  157. $id = input('id', 0, 'intval'); //视频id
  158. if (!$id) {
  159. $this->error('您的网络开小差了');
  160. }
  161. $info = Db::name('video')->field('id,video_type_id,childcate_id, title, image, desc, is_pay, status, inject_status, seriesid, programid, movieid')
  162. ->where(['id' => $id])->find();
  163. if (!$info) {
  164. $this->error('数据不存在');
  165. }
  166. if ($info['status'] != 1) {
  167. $this->error('视频丢失');
  168. }
  169. if ($info['inject_status'] != 2) {
  170. $this->error('视频丢失');
  171. }
  172. $info['image'] = one_domain_image($info['image']);
  173. $info['is_collection'] = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $info['id']])->count('id');
  174. $info['is_good'] = Db::name('video_good')->where(['user_id' => $this->auth->id, 'video_id' => $info['id']])->count('id');
  175. //记录浏览历史,给浏览历史列表用的,即时的
  176. if($this->auth->isLogin()){
  177. $view_map = [
  178. 'user_id' => $this->auth->id,
  179. 'video_id' => $info['id'],
  180. ];
  181. $check_view = Db::name('video_view')->where($view_map)->find();
  182. if($check_view){
  183. Db::name('video_view')->where($view_map)->update(['updatetime'=>time()]);
  184. }else{
  185. $view_map['createtime'] = time();
  186. $view_map['updatetime'] = time();
  187. Db::name('video_view')->insertGetId($view_map);
  188. }
  189. }
  190. //记录pv,uv
  191. $this->video_pvuv($info['id']);
  192. //
  193. $result = [
  194. 'video_info' => $info,
  195. ];
  196. $this->success('详情', $result);
  197. }
  198. //专题页
  199. public function zhuanti(){
  200. $childcate_id = input('child_id', 0, 'intval'); //子分类id
  201. if (!$childcate_id) {
  202. $this->error('您的网络开小差了~');
  203. }
  204. $video_childcate = Db::name('video_childcate')->field('id,name,bg_image')->where('id',$childcate_id)->find();
  205. $video_childcate = info_domain_image($video_childcate,['bg_image']);
  206. $list = Db::name('video')->field('id, title, image, is_pay, status, inject_status, seriesid, programid, movieid')->where(['childcate_id' => $childcate_id, 'status' => 1, 'inject_status' => 2])->order('weigh asc, id desc')->limit(5)->select();
  207. $list = list_domain_image($list, ['image']);
  208. $result = [
  209. 'info' => $video_childcate,
  210. 'list' => $list,
  211. ];
  212. $this->success('视频', $result);
  213. }
  214. //退订服务
  215. public function tudingc()
  216. {
  217. $data = config('site.text_tuiding');
  218. $this->success('', $data);
  219. }
  220. //搜索页
  221. public function search(){
  222. $keyword = input('keyword','');
  223. //热门推荐4个
  224. if(empty($keyword)){
  225. $list = Db::name('video')->field('id, title, image, is_pay')->where(['status' => 1, 'inject_status' => 2])
  226. ->orderRaw('rand()')->limit(12)->select();
  227. $list = list_domain_image($list, ['image']);
  228. }else{
  229. $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();
  230. $list = list_domain_image($list, ['image']);
  231. }
  232. $this->success('视频', $list);
  233. }
  234. //浏览历史
  235. public function history(){
  236. if($this->auth->isLogin()){
  237. $video_view = Db::name('video_view')->where('user_id',$this->auth->id)->order('updatetime desc')->group('video_id')->column('video_id,updatetime');
  238. if(!empty($video_view)){
  239. $video_ids = implode(',',array_keys($video_view));
  240. $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();
  241. $list = list_domain_image($list, ['image']);
  242. foreach($list as $key => $val){
  243. $list[$key]['history_time'] = $video_view[$val['id']];
  244. }
  245. }else{
  246. $list = [];
  247. }
  248. }else{
  249. $list = [];
  250. }
  251. $this->success('视频', $list);
  252. }
  253. //视频收藏/取消收藏
  254. public function video_collection() {
  255. $id = input('id', 0, 'intval');
  256. if (!$id) {
  257. $this->error('您的网络开小差了');
  258. }
  259. $info = Db::name('video')->where(['id' => $id])->find();
  260. if (!$info) {
  261. $this->error('数据不存在');
  262. }
  263. //var_dump($info);exit;
  264. $info['image'] = one_domain_image($info['image']);
  265. //查询是否收藏
  266. $count = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $id])->count('id');
  267. //开启事务
  268. if ($count) {
  269. $result = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $id])->delete();
  270. Db::name('video')->where('id',$id)->setDec('collect_number',1); //收藏数减少
  271. } else {
  272. $result = Db::name('video_collection')->insertGetId(['user_id' => $this->auth->id, 'video_id' => $id, 'createtime' => time()]);
  273. Db::name('video')->where('id',$id)->setInc('collect_number',1); //收藏数增加
  274. }
  275. if (!$result) {
  276. /*Db::rollback();
  277. $this->error('操作失败');*/
  278. $this->success('操作成功');
  279. }
  280. $url = 'http://meta-history.unso.gitv.tv/OTT/jscmcc/addThirdPartyCollectionRecord';
  281. $content = [
  282. 'cpPrvdName' => '健康e家',
  283. 'cpPrvCode' => '41000144',
  284. 'cpPrvType' => '1006',
  285. 'content' => $info['title'],
  286. 'ChnCode' => '1000020',
  287. 'contentId' => (string)$info['movieid'],
  288. 'extraContentID' => '',
  289. 'isEffective' => $info['status'],
  290. 'isPaid' => $info['is_pay'],
  291. 'collectionFlag' => $count ? 0 : 1,
  292. 'account' => $this->encrypt($this->auth->mobile, '!@#$%^&*FJGFJT78'),
  293. 'cpPermission' => 'GITV',
  294. 'intent' => [
  295. 'action' => 'com.huxiu.heh.tv.ui.splash.SplashActivity',
  296. 'package' => 'com.huxiu.heh.tv',
  297. 'component' => [
  298. 'pkg' => 'com.huxiu.heh.tv',
  299. 'cls' => 'com.huxiu.heh.tv.ui.splash.SplashActivity'
  300. ],
  301. 'extras' => [
  302. /*'cmd' => '',
  303. 'from' => '',
  304. 'media_id' => ''*/
  305. 'type_id' => $info['video_type_id'],
  306. 'id' => $info['id']
  307. ]
  308. ],
  309. 'imageURL' => $info['image']
  310. ];
  311. $content = json_encode($content, 320);
  312. $rt = httpRequest($url, 'POST', $content);
  313. file_put_contents('shoucang.txt',$id.'_'.$rt.PHP_EOL, FILE_APPEND);
  314. if (!$rt) {
  315. /*Db::rollback();
  316. $this->error('操作失败');*/
  317. $this->success('操作成功');
  318. }
  319. $rt = json_decode($rt, true);
  320. if (empty($rs) || $rt['code'] != 0) {
  321. /*Db::rollback();
  322. $this->error('操作失败');*/
  323. $this->success('操作成功');
  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. //图片页
  566. public function image_childcate(){
  567. $cate_id = input('cate_id',0);
  568. $childcate = Db::name('image_childcate')->field('id,cate_id,name')->where('cate_id',$cate_id)->where('status',1)->order('weigh asc,id desc')->select();
  569. $image_list = [];
  570. if(!empty($childcate)){
  571. $childcate_id = $childcate[0]['id'];
  572. $image_list = Db::name('image')->field('id,title,image')->where('childcate_id',$childcate_id)->where('status',1)->order('weigh asc,id desc')->select();
  573. $image_list = list_domain_image($image_list,['image']);
  574. }
  575. $result = [
  576. 'childcate' => $childcate,
  577. 'image_list' => $image_list,
  578. ];
  579. $this->success(1,$result);
  580. }
  581. //图片列表
  582. public function image_list(){
  583. $childcate_id = input('child_id',0);
  584. $image_list = Db::name('image')->field('id,title,image')->where('childcate_id',$childcate_id)->where('status',1)->order('weigh asc,id desc')->select();
  585. $image_list = list_domain_image($image_list,['image']);
  586. $this->success(1,$image_list);
  587. }
  588. /** * * @param string $string 需要加密的字符串 * @param string $key 密钥 * @return string */
  589. private function encrypt($string, $key) {
  590. // $key = substr(openssl_digest(openssl_digest($key, 'sha1', true), 'sha1', true), 0, 16);
  591. $data = openssl_encrypt($string, 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
  592. $data = bin2hex($data);
  593. return $data;
  594. }
  595. /** * @param string $string 需要解密的字符串 * @param string $key 密钥 * @return string */
  596. private function decrypt($string, $key) {
  597. // $key = substr(openssl_digest(openssl_digest($key, 'sha1', true), 'sha1', true), 0, 16);
  598. $decrypted = openssl_decrypt(hex2bin($string), 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
  599. return $decrypted;
  600. }
  601. //共有方法,
  602. private function video_pvuv($video_id = 0){
  603. if(empty($video_id)) {return true;}
  604. //开启redis
  605. $redis = new Redis();
  606. $config = config('redis');
  607. $redis->connect($config['redis_host'], $config['redis_port']);
  608. if ($config['redis_pwd']) {
  609. $redis->auth($config['redis_pwd']);
  610. }
  611. if($config['redis_selectdb'] > 0){
  612. $redis->select($config['redis_selectdb']);
  613. }
  614. //今天
  615. $today = date('Y-m-d');
  616. //今日pv+1
  617. $today_pv_key = $today.'_video_pv_'.$video_id;
  618. $redis->incr($today_pv_key,1);
  619. //今日uv+1
  620. if($this->auth->isLogin() && $this->auth->id){
  621. $today_uv_key = $today.'_video_uv_'.$video_id;
  622. $uid = $this->auth->id;
  623. $redis->sAdd($today_uv_key,$uid);
  624. }
  625. //今日视频id列表
  626. $today_video_key = $today.'_video_list';
  627. $redis->sAdd($today_video_key,$video_id);
  628. }
  629. /*public function test(){
  630. $this->video_pvuv(input('video_id',0));
  631. }*/
  632. }