Tvindex.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. class Tvindex extends Api
  6. {
  7. protected $noNeedLogin = ['indexdata','video_list','videoinfo','zhuanti','tudingc','search','history'];
  8. protected $noNeedRight = '*';
  9. //首页
  10. public function indexdata(){
  11. //左上角 logo,名称,4个按钮
  12. $data['index_logo'] = localpath_to_netpath(config('site.index_logo'));
  13. $data['index_appname'] = config('site.index_appname');
  14. $data['index_tuiding_switch'] = config('site.index_tuiding_switch');
  15. $data['index_search_switch'] = config('site.index_search_switch');
  16. $data['index_history_switch'] = config('site.index_history_switch');
  17. $data['index_dinggou_switch'] = config('site.index_dinggou_switch');
  18. //右上角 三行
  19. $data['index_right_1'] = config('site.index_right_1');
  20. $data['index_right_2'] = config('site.index_right_2');
  21. $data['index_right_3'] = config('site.index_right_3');
  22. //固定五个
  23. $data['index_top_video_image'] = localpath_to_netpath(config('site.index_top_video_image'));
  24. $data['index_top_video'] = localpath_to_netpath(config('site.index_top_video'));
  25. $page_wenzhen = Db::name('page_wenzhen')->field('id,name,image,url')->where('status',1)->order('weigh asc')->select();
  26. $data['page_wenzhen'] = list_domain_image($page_wenzhen,['image']);
  27. //大分类+剧集
  28. $video_type = Db::name('video_type')->field('id,name,showtype')->where('status',1)->where('type','neq',3)->order('weigh asc, id desc')->select();
  29. $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();
  30. $video = list_domain_image($video, ['image']);
  31. //分布:1=左一右四,2=两行八个,3=一行四个,4=一行三个
  32. $more = [
  33. 'id' => 0,
  34. 'video_type_id' => 0,
  35. 'title' => '查看更多',
  36. 'image' => 'https://jiankang-1304634122.cos.ap-nanjing.myqcloud.com/uploads/20240529/37bd30cf2b80186b51f3bbfedb10a7d5.png',
  37. 'is_pay'=> 0,
  38. ];
  39. foreach($video_type as $key => $type){
  40. $type['child'] = [];
  41. //循环放入child
  42. $child = [];
  43. foreach($video as $k => $v){
  44. if($type['id'] == $v['video_type_id']){
  45. $child[] = $v;
  46. }
  47. }
  48. //查看更多
  49. if($type['showtype'] == 1){
  50. if(count($child) > 5){
  51. $child = array_chunk($child,4)[0];
  52. $child[] = $more;
  53. }
  54. }
  55. if($type['showtype'] == 2){
  56. if(count($child) > 8){
  57. $child = array_chunk($child,7)[0];
  58. $child[] = $more;
  59. }
  60. }
  61. if($type['showtype'] == 3){
  62. if(count($child) > 4){
  63. $child = array_chunk($child,3)[0];
  64. $child[] = $more;
  65. }
  66. }
  67. if($type['showtype'] == 4){
  68. if(count($child) > 3){
  69. $child = array_chunk($child,2)[0];
  70. $child[] = $more;
  71. }
  72. }
  73. $type['child'] = $child;
  74. $video_type[$key] = $type;
  75. }
  76. $data['video_type'] = $video_type;
  77. //精彩专题
  78. $data['buttom_name'] = '精彩专题';
  79. $buttom_list = Db::name('video_type')->field('id,name,image')->where('status',1)->where('type',3)->order('weigh asc,id desc')->limit(3)->select();
  80. $data['buttom_list'] = list_domain_image($buttom_list,['image']);
  81. $this->success('首页',$data);
  82. }
  83. //更多页
  84. //视频列表
  85. public function video_list() {
  86. $type_id = input('type_id', 0, 'intval'); //分类id
  87. if (!$type_id) {
  88. $this->error('您的网络开小差了~');
  89. }
  90. $video_type = Db::name('video_type')->where('id',$type_id)->value('name');
  91. $list = Db::name('video')->field('id, title, image, is_pay')->where(['video_type_id' => $type_id, 'status' => 1, 'inject_status' => 2])
  92. ->order('weigh asc, id desc')->select();
  93. $list = list_domain_image($list, ['image']);
  94. $result = [
  95. 'typename' => $video_type,
  96. 'videolist' => $list,
  97. ];
  98. $this->success('视频更多', $result);
  99. }
  100. //视频详情
  101. public function videoinfo() {
  102. $id = input('id', 0, 'intval'); //视频id
  103. if (!$id) {
  104. $this->error('您的网络开小差了');
  105. }
  106. $info = Db::name('video')->field('id,video_type_id, title, image, desc, is_pay, status, inject_status, seriesid, programid, movieid')
  107. ->where(['id' => $id])->find();
  108. if (!$info) {
  109. $this->error('数据不存在');
  110. }
  111. if ($info['status'] != 1) {
  112. $this->error('视频丢失');
  113. }
  114. if ($info['inject_status'] != 2) {
  115. $this->error('视频丢失');
  116. }
  117. $info['image'] = one_domain_image($info['image']);
  118. $info['is_collection'] = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $id])->count('id');
  119. $info['is_good'] = Db::name('video_good')->where(['user_id' => $this->auth->id, 'video_id' => $id])->count('id');
  120. //剧集列表
  121. $juji = [];
  122. $video_list = Db::name('video')->field('id, title, image, is_pay')->where(['video_type_id' => $info['video_type_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 + 10),
  130. 'list'=>$ten,
  131. ];
  132. }
  133. }
  134. //猜你喜欢
  135. $guess_list = Db::name('video')->field('id, title, image, is_pay')->where(['status' => 1, 'inject_status' => 2])
  136. ->orderRaw('rand()')->limit(4)->select();
  137. $guess_list = list_domain_image($guess_list, ['image']);
  138. //记录浏览历史
  139. if($this->auth->isLogin()){
  140. $view_map = [
  141. 'user_id' => $this->auth->id,
  142. 'video_id' => $id,
  143. ];
  144. $check_view = Db::name('video_view')->where($view_map)->find();
  145. if($check_view){
  146. Db::name('video_view')->where($view_map)->update(['updatetime'=>time()]);
  147. }else{
  148. $view_map['createtime'] = time();
  149. $view_map['updatetime'] = time();
  150. Db::name('video_view')->insertGetId($view_map);
  151. }
  152. }
  153. //
  154. $result = [
  155. 'video_info' => $info,
  156. 'juji_list' => $juji,
  157. 'guess_list' => $guess_list,
  158. ];
  159. $this->success('详情', $result);
  160. }
  161. //专题页
  162. public function zhuanti(){
  163. $type_id = input('type_id', 0, 'intval'); //分类id
  164. if (!$type_id) {
  165. $this->error('您的网络开小差了~');
  166. }
  167. $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();
  168. $list = list_domain_image($list, ['image']);
  169. $this->success('视频', $list);
  170. }
  171. //退订服务
  172. public function tudingc()
  173. {
  174. $data = config('site.text_tuiding');
  175. $this->success('', $data);
  176. }
  177. //搜索页
  178. public function search(){
  179. $keyword = input('keyword','');
  180. //热门推荐4个
  181. if(empty($keyword)){
  182. $list = Db::name('video')->field('id, title, image, is_pay')->where(['status' => 1, 'inject_status' => 2])
  183. ->orderRaw('rand()')->limit(12)->select();
  184. $list = list_domain_image($list, ['image']);
  185. }else{
  186. $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();
  187. $list = list_domain_image($list, ['image']);
  188. }
  189. $this->success('视频', $list);
  190. }
  191. //浏览历史
  192. public function history(){
  193. if($this->auth->isLogin()){
  194. $video_view = Db::name('video_view')->where('user_id',$this->auth->id)->order('updatetime desc')->group('video_id')->column('video_id,updatetime');
  195. if(!empty($video_view)){
  196. $video_ids = implode(',',array_keys($video_view));
  197. $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();
  198. $list = list_domain_image($list, ['image']);
  199. foreach($list as $key => $val){
  200. $list[$key]['history_time'] = $video_view[$val['id']];
  201. }
  202. }else{
  203. $list = [];
  204. }
  205. }else{
  206. $list = [];
  207. }
  208. $this->success('视频', $list);
  209. }
  210. //视频收藏/取消收藏
  211. public function video_collection() {
  212. $id = input('id', 0, 'intval');
  213. if (!$id) {
  214. $this->error('您的网络开小差了');
  215. }
  216. $info = Db::name('video')->where(['id' => $id])->find();
  217. if (!$info) {
  218. $this->error('数据不存在');
  219. }
  220. $info['image'] = one_domain_image($info['image']);
  221. //查询是否收藏
  222. $count = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $id])->count('id');
  223. //开启事务
  224. if ($count) {
  225. $result = Db::name('video_collection')->where(['user_id' => $this->auth->id, 'video_id' => $id])->delete();
  226. Db::name('video')->where('id',$id)->setDec('collect_number',1); //收藏数减少
  227. } else {
  228. $result = Db::name('video_collection')->insertGetId(['user_id' => $this->auth->id, 'video_id' => $id, 'createtime' => time()]);
  229. Db::name('video')->where('id',$id)->setInc('collect_number',1); //收藏数增加
  230. }
  231. if (!$result) {
  232. Db::rollback();
  233. $this->error('操作失败');
  234. }
  235. $url = 'http://meta-history.unso.gitv.tv/OTT/jscmcc/addThirdPartyCollectionRecord';
  236. $content = [
  237. 'cpPrvdName' => '健康e家',
  238. 'cpPrvCode' => '41000144',
  239. 'cpPrvType' => '1006',
  240. 'content' => $info['title'],
  241. 'ChnCode' => '1000020',
  242. 'contentId' => (string)$info['movieid'],
  243. 'extraContentID' => '',
  244. 'isEffective' => $info['status'],
  245. 'isPaid' => $info['is_pay'],
  246. 'collectionFlag' => $count ? 0 : 1,
  247. 'account' => $this->encrypt($this->auth->mobile, '!@#$%^&*FJGFJT78'),
  248. 'cpPermission' => 'GITV',
  249. 'intent' => [
  250. 'action' => 'com.huxiu.heh.tv.ui.splash.SplashActivity',
  251. 'package' => 'com.huxiu.heh.tv',
  252. 'component' => [
  253. 'pkg' => 'com.huxiu.heh.tv',
  254. 'cls' => 'com.huxiu.heh.tv.ui.splash.SplashActivity'
  255. ],
  256. 'extras' => [
  257. /*'cmd' => '',
  258. 'from' => '',
  259. 'media_id' => ''*/
  260. 'type_id' => $info['video_type_id'],
  261. 'id' => $info['id']
  262. ]
  263. ],
  264. 'imageURL' => $info['image']
  265. ];
  266. $content = json_encode($content, 320);
  267. $rt = httpRequest($url, 'POST', $content);
  268. file_put_contents('shoucang.txt',$id.'_'.$rt.PHP_EOL, FILE_APPEND);
  269. if (!$rt) {
  270. Db::rollback();
  271. $this->error('操作失败');
  272. }
  273. $rt = json_decode($rt, true);
  274. if (empty($rs) || $rt['code'] != 0) {
  275. Db::rollback();
  276. $this->error('操作失败');
  277. }
  278. //大数据上报
  279. $data = [
  280. 'favid' => (string)(config('data_cp_id') . date('Ymd') . getMillisecond() . mt_rand(10000000, 99999999)),
  281. 'UserID' => $this->auth->mobile,
  282. 'time' => date('Y-m-d H:i:s'),
  283. 'type' => $count ? 0 : 1,
  284. 'cpid' => config('data_cp_id'),
  285. 'albumid' => $id,
  286. 'albumname' => $info['title']
  287. ];
  288. $data = join(json_decode('"\u0001"', true), $data);
  289. $filename = date('Ymd').'_'.config('data_cp_id').'_userfavdata_1.dat';
  290. $check_filename = date('Ymd').'_'.config('data_cp_id').'_userfavdata_1.chk';
  291. error_log(print_r($data, 1) . PHP_EOL, 3, './dashuju/' . $filename);
  292. error_log('', 3, './dashuju/' . $check_filename);
  293. $finish_filename = date('Ymd') . '_' . config('data_cp_id') . '_userfavdata.finish';
  294. error_log('', 3, './dashuju/' . $finish_filename);
  295. Db::commit();
  296. $this->success('操作成功');
  297. }
  298. //点赞视频、取消点赞
  299. public function video_good() {
  300. $id = input('id', 0, 'intval');
  301. if (!$id) {
  302. $this->error('您的网络开小差了');
  303. }
  304. $info = Db::name('video')->where(['id' => $id])->find();
  305. if (!$info) {
  306. $this->error('数据不存在');
  307. }
  308. //查询是否收藏
  309. $check = Db::name('video_good')->where(['user_id' => $this->auth->id, 'video_id' => $id])->find();
  310. //开启事务
  311. if ($check) {
  312. $result = Db::name('video_good')->where(['user_id' => $this->auth->id, 'video_id' => $id])->delete();
  313. Db::name('video')->where('id',$id)->setDec('good_number',1); //点赞数减少
  314. } else {
  315. $result = Db::name('video_good')->insertGetId(['user_id' => $this->auth->id, 'video_id' => $id, 'createtime' => time()]);
  316. Db::name('video')->where('id',$id)->setInc('good_number',1); //点赞数增加
  317. }
  318. $this->success('操作成功');
  319. }
  320. /** * * @param string $string 需要加密的字符串 * @param string $key 密钥 * @return string */
  321. private function encrypt($string, $key) {
  322. // $key = substr(openssl_digest(openssl_digest($key, 'sha1', true), 'sha1', true), 0, 16);
  323. $data = openssl_encrypt($string, 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
  324. $data = bin2hex($data);
  325. return $data;
  326. }
  327. /** * @param string $string 需要解密的字符串 * @param string $key 密钥 * @return string */
  328. private function decrypt($string, $key) {
  329. // $key = substr(openssl_digest(openssl_digest($key, 'sha1', true), 'sha1', true), 0, 16);
  330. $decrypted = openssl_decrypt(hex2bin($string), 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
  331. return $decrypted;
  332. }
  333. }