Tvindex.php 31 KB

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