Vod.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Cache;
  4. use think\Db;
  5. class Vod extends Base
  6. {
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. }
  11. public function data()
  12. {
  13. $param = input();
  14. $param['page'] = intval($param['page']) <1 ? 1 : $param['page'];
  15. $param['limit'] = intval($param['limit']) <1 ? $this->_pagesize : $param['limit'];
  16. $where = [];
  17. if(!empty($param['type'])){
  18. $where['type_id|type_id_1'] = ['eq',$param['type']];
  19. }
  20. if(!empty($param['level'])){
  21. $where['vod_level'] = ['eq',$param['level']];
  22. }
  23. if(in_array($param['status'],['0','1'])){
  24. $where['vod_status'] = ['eq',$param['status']];
  25. }
  26. if(in_array($param['copyright'],['0','1'])){
  27. $where['vod_copyright'] = ['eq',$param['copyright']];
  28. }
  29. if(in_array($param['isend'],['0','1'])){
  30. $where['vod_isend'] = ['eq',$param['isend']];
  31. }
  32. if(!empty($param['lock'])){
  33. $where['vod_lock'] = ['eq',$param['lock']];
  34. }
  35. if(!empty($param['state'])){
  36. $where['vod_state'] = ['eq',$param['state']];
  37. }
  38. if(!empty($param['area'])){
  39. $where['vod_area'] = ['eq',$param['area']];
  40. }
  41. if(!empty($param['lang'])){
  42. $where['vod_lang'] = ['eq',$param['lang']];
  43. }
  44. if(in_array($param['plot'],['0','1'])){
  45. $where['vod_plot'] = ['eq',$param['plot']];
  46. }
  47. if(!empty($param['url'])){
  48. if($param['url']==1){
  49. $where['vod_play_url'] = '';
  50. }
  51. }
  52. if(!empty($param['points'])){
  53. $where['vod_points_play|vod_points_down'] = ['gt', 0];
  54. }
  55. if(!empty($param['pic'])){
  56. if($param['pic'] == '1'){
  57. $where['vod_pic'] = ['eq',''];
  58. }
  59. elseif($param['pic'] == '2'){
  60. $where['vod_pic'] = ['like','http%'];
  61. }
  62. elseif($param['pic'] == '3'){
  63. $where['vod_pic'] = ['like','%#err%'];
  64. }
  65. }
  66. if(!empty($param['weekday'])){
  67. $where['vod_weekday'] = ['like','%'.$param['weekday'].'%'];
  68. }
  69. if(!empty($param['wd'])){
  70. $param['wd'] = urldecode($param['wd']);
  71. $param['wd'] = mac_filter_xss($param['wd']);
  72. $where['vod_name|vod_actor|vod_sub'] = ['like','%'.$param['wd'].'%'];
  73. }
  74. if(!empty($param['player'])){
  75. if($param['player']=='no'){
  76. $where['vod_play_from'] = [['eq', ''], ['eq', 'no'], 'or'];
  77. }
  78. else {
  79. $where['vod_play_from'] = ['like', '%' . $param['player'] . '%'];
  80. }
  81. }
  82. if(!empty($param['downer'])){
  83. if($param['downer']=='no'){
  84. $where['vod_down_from'] = [['eq', ''], ['eq', 'no'], 'or'];
  85. }
  86. else {
  87. $where['vod_down_from'] = ['like', '%' . $param['downer'] . '%'];
  88. }
  89. }
  90. if(!empty($param['server'])){
  91. $where['vod_play_server|vod_down_server'] = ['like','%'.$param['server'].'%'];
  92. }
  93. $order='vod_time desc';
  94. if(in_array($param['order'],['vod_id','vod_hits','vod_hits_month','vod_hits_week','vod_hits_day'])){
  95. $order = $param['order'] .' desc';
  96. }
  97. if(!empty($param['repeat'])){
  98. if(!empty($param['cache'])){
  99. model('Vod')->createRepeatCache();
  100. return $this->success(lang('update_ok'));
  101. }
  102. if($param['page'] ==1){
  103. //使用缓存查看是否创建过缓存表
  104. $cacheResult = Cache::get('vod_repeat_table_created_time',0);
  105. //缓存时间超过7天和没有创建过缓存都会重建缓存
  106. if( $cacheResult == 0 || time() - $cacheResult > 604800){
  107. model('Vod')->createRepeatCache();
  108. }
  109. }
  110. $order='vod_name asc';
  111. $res = model('Vod')->listRepeatData($where,$order,$param['page'],$param['limit']);
  112. }
  113. else{
  114. $res = model('Vod')->listData($where,$order,$param['page'],$param['limit']);
  115. }
  116. foreach($res['list'] as $k=>&$v){
  117. $v['ismake'] = 1;
  118. if($GLOBALS['config']['view']['vod_detail'] >0 && $v['vod_time_make'] < $v['vod_time']){
  119. $v['ismake'] = 0;
  120. }
  121. }
  122. $this->assign('list',$res['list']);
  123. $this->assign('total',$res['total']);
  124. $this->assign('page',$res['page']);
  125. $this->assign('limit',$res['limit']);
  126. $param['page'] = '{page}';
  127. $param['limit'] = '{limit}';
  128. $this->assign('param',$param);
  129. //分类
  130. $type_tree = model('Type')->getCache('type_tree');
  131. $this->assign('type_tree',$type_tree);
  132. //播放器
  133. $this->assignBaseListByConfig();
  134. $this->assign('title',lang('admin/vod/title'));
  135. return $this->fetch('admin@vod/index');
  136. }
  137. public function batch()
  138. {
  139. $param = input();
  140. if (!empty($param)) {
  141. mac_echo('<style type="text/css">body{font-size:12px;color: #333333;line-height:21px;}span{font-weight:bold;color:#FF0000}</style>');
  142. if(empty($param['ck_del']) && empty($param['ck_level']) && empty($param['ck_status']) && empty($param['ck_lock']) && empty($param['ck_hits'])
  143. && empty($param['ck_points']) && empty($param['ck_copyright'])
  144. ){
  145. return $this->error(lang('param_err'));
  146. }
  147. if($param['ck_del']==2 && empty($param['player'])){
  148. return $this->error(lang('admin/vod/del_play_must_select_play'));
  149. }
  150. if($param['ck_del']==3 && empty($param['downer'])){
  151. return $this->error(lang('admin/vod/del_down_must_select_down'));
  152. }
  153. $where = [];
  154. if(!empty($param['type'])){
  155. $where['type_id'] = ['eq',$param['type']];
  156. }
  157. if(!empty($param['level'])){
  158. $where['vod_level'] = ['eq',$param['level']];
  159. }
  160. if(in_array($param['status'],['0','1'])){
  161. $where['vod_status'] = ['eq',$param['status']];
  162. }
  163. if(in_array($param['copyright'],['0','1'])){
  164. $where['vod_copyright'] = ['eq',$param['copyright']];
  165. }
  166. if(in_array($param['isend'],['0','1'])){
  167. $where['vod_isend'] = ['eq',$param['isend']];
  168. }
  169. if(!empty($param['lock'])){
  170. $where['vod_lock'] = ['eq',$param['lock']];
  171. }
  172. if(!empty($param['state'])){
  173. $where['vod_state'] = ['eq',$param['state']];
  174. }
  175. if(!empty($param['area'])){
  176. $where['vod_area'] = ['eq',$param['area']];
  177. }
  178. if(!empty($param['lang'])){
  179. $where['vod_lang'] = ['eq',$param['lang']];
  180. }
  181. if(!empty($param['url'])){
  182. if($param['url']==1){
  183. $where['vod_play_url'] = '';
  184. }
  185. }
  186. if(!empty($param['pic'])){
  187. if($param['pic'] == '1'){
  188. $where['vod_pic'] = ['eq',''];
  189. }
  190. elseif($param['pic'] == '2'){
  191. $where['vod_pic'] = ['like','http%'];
  192. }
  193. elseif($param['pic'] == '3'){
  194. $where['vod_pic'] = ['like','%#err%'];
  195. }
  196. }
  197. if(!empty($param['wd'])){
  198. $param['wd'] = htmlspecialchars(urldecode($param['wd']));
  199. $where['vod_name'] = ['like','%'.$param['wd'].'%'];
  200. }
  201. if(!empty($param['weekday'])){
  202. $where['vod_weekday'] = ['like','%'.$param['weekday'].'%'];
  203. }
  204. if(!empty($param['player'])){
  205. if($param['player']=='no'){
  206. $where['vod_play_from'] = [['eq', ''], ['eq', 'no'], 'or'];
  207. }
  208. else {
  209. $where['vod_play_from'] = ['like', '%' . $param['player'] . '%'];
  210. }
  211. }
  212. if(!empty($param['downer'])){
  213. if($param['downer']=='no'){
  214. $where['vod_down_from'] = [['eq', ''], ['eq', 'no'], 'or'];
  215. }
  216. else {
  217. $where['vod_down_from'] = ['like', '%' . $param['downer'] . '%'];
  218. }
  219. }
  220. if($param['ck_del'] == 1){
  221. $res = model('Vod')->delData($where);
  222. mac_echo(lang('multi_del_ok'));
  223. mac_jump( url('vod/batch') ,3);
  224. exit;
  225. }
  226. if(empty($param['page'])){
  227. $param['page'] = 1;
  228. }
  229. if(empty($param['limit'])){
  230. $param['limit'] = 100;
  231. }
  232. if(empty($param['total'])) {
  233. $param['total'] = model('Vod')->countData($where);
  234. $param['page_count'] = ceil($param['total'] / $param['limit']);
  235. }
  236. if($param['page'] > $param['page_count']) {
  237. mac_echo(lang('multi_opt_ok'));
  238. mac_jump( url('vod/batch') ,3);
  239. exit;
  240. }
  241. mac_echo( "<font color=red>".lang('admin/batch_tip',[$param['total'],$param['limit'],$param['page_count'],$param['page']])."</font>");
  242. $page = $param['page_count'] - $param['page'] + 1;
  243. $order='vod_id desc';
  244. $res = model('Vod')->listData($where,$order,$page,$param['limit']);
  245. foreach($res['list'] as $k=>$v){
  246. $where2 = [];
  247. $where2['vod_id'] = $v['vod_id'];
  248. $update = [];
  249. $des = $v['vod_id'].','.$v['vod_name'];
  250. if(!empty($param['ck_level']) && !empty($param['val_level'])){
  251. $update['vod_level'] = $param['val_level'];
  252. $des .= '&nbsp;'.lang('level').':'.$param['val_level'].';';
  253. }
  254. if(!empty($param['ck_status']) && isset($param['val_status'])){
  255. $update['vod_status'] = $param['val_status'];
  256. $des .= '&nbsp;'.lang('status').':'.($param['val_status'] ==1 ? '['.lang('reviewed').']':'['.lang('reviewed_not').']') .';';
  257. }
  258. if(!empty($param['ck_copyright']) && isset($param['val_copyright'])){
  259. $update['vod_copyright'] = $param['val_copyright'];
  260. $des .= '&nbsp;'.lang('copyright').':'.($param['val_copyright'] ==1 ? '['.lang('open').']':'['.lang('close').'') .';';
  261. }
  262. if(!empty($param['ck_lock']) && isset($param['val_lock'])){
  263. $update['vod_lock'] = $param['val_lock'];
  264. $des .= '&nbsp;'.lang('lock').':'.($param['val_lock']==1 ? '['.lang('lock').']':'['.lang('unlock').']').';';
  265. }
  266. if(!empty($param['ck_hits']) && $param['val_hits_min']!='' && $param['val_hits_max']!='' ){
  267. $update['vod_hits'] = rand($param['val_hits_min'],$param['val_hits_max']);
  268. $des .= '&nbsp;'.lang('hits').':'.$update['vod_hits'].';';
  269. }
  270. if(!empty($param['ck_points']) && $param['val_points_play']!='' ){
  271. $update['vod_points_play'] = $param['val_points_play'];
  272. $des .= '&nbsp;'.lang('points_play').':'.$param['val_points_play'].';';
  273. }
  274. if(!empty($param['ck_points']) && $param['val_points_down']!='' ){
  275. $update['vod_points_down'] = $param['val_points_down'];
  276. $des .= '&nbsp;'.lang('points_down').':'.$param['val_points_down'].';';
  277. }
  278. if($param['ck_del'] == 2 || $param['ck_del'] ==3){
  279. if($param['ck_del']==2) {
  280. $pre = 'vod_play';
  281. $par = 'player';
  282. $des .= '&nbsp;'.lang('play_group').':';
  283. }
  284. elseif($param['ck_del']==3){
  285. $pre = 'vod_down';
  286. $par='downer';
  287. $des .= '&nbsp;'.lang('down_group').':';
  288. }
  289. if($param[$par] == $v[$pre.'_from']){
  290. $update[$pre.'_from'] = '';
  291. $update[$pre.'_server'] = '';
  292. $update[$pre.'_note'] = '';
  293. $update[$pre.'_url'] = '';
  294. $des .= lang('del_empty').';';
  295. }
  296. else{
  297. $vod_from_arr = explode('$$$',$v[$pre.'_from']);
  298. $vod_server_arr = explode('$$$',$v[$pre.'_server']);
  299. $vod_note_arr = explode('$$$',$v[$pre.'_note']);
  300. $vod_url_arr = explode('$$$',$v[$pre.'_url']);
  301. $key = array_search($param[$par],$vod_from_arr);
  302. if($key!==false){
  303. unset($vod_from_arr[$key]);
  304. unset($vod_server_arr[$key]);
  305. unset($vod_note_arr[$key]);
  306. unset($vod_url_arr[$key]);
  307. $update[$pre.'_from'] = join('$$$',$vod_from_arr);
  308. $update[$pre.'_server'] = join('$$$',$vod_server_arr);
  309. $update[$pre.'_note'] = join('$$$',$vod_note_arr);
  310. $update[$pre.'_url'] = join('$$$',$vod_url_arr);
  311. $des .= lang('del'). ';';
  312. }
  313. else{
  314. $des .= lang('jump_over').';';
  315. }
  316. }
  317. }
  318. mac_echo($des);
  319. $res2 = model('Vod')->where($where2)->update($update);
  320. }
  321. $param['page']++;
  322. $url = url('vod/batch') .'?'. http_build_query($param);
  323. mac_jump( $url ,3);
  324. exit;
  325. }
  326. //分类
  327. $type_tree = model('Type')->getCache('type_tree');
  328. $this->assign('type_tree',$type_tree);
  329. //播放器
  330. $this->assignBaseListByConfig();
  331. $this->assign('title',lang('admin/vod/title'));
  332. return $this->fetch('admin@vod/batch');
  333. }
  334. public function info()
  335. {
  336. if (Request()->isPost()) {
  337. $param = input('post.');
  338. $res = model('Vod')->saveData($param);
  339. if($res['code']>1){
  340. return $this->error($res['msg']);
  341. }
  342. return $this->success($res['msg']);
  343. }
  344. $id = input('id');
  345. $where=[];
  346. $where['vod_id'] = $id;
  347. $res = model('Vod')->infoData($where);
  348. $info = $res['info'];
  349. $this->assign('info',$info);
  350. //分类
  351. $type_tree = model('Type')->getCache('type_tree');
  352. $this->assign('type_tree',$type_tree);
  353. //地区、语言
  354. $config = config('maccms.app');
  355. $area_list = explode(',',$config['vod_area']);
  356. $lang_list = explode(',',$config['vod_lang']);
  357. $this->assign('area_list',$area_list);
  358. $this->assign('lang_list',$lang_list);
  359. //用户组
  360. $group_list = model('Group')->getCache('group_list');
  361. $this->assign('group_list',$group_list);
  362. //播放器
  363. $this->assignBaseListByConfig();
  364. //播放组、下载租
  365. $this->assign('vod_play_list',(array)$info['vod_play_list']);
  366. $this->assign('vod_down_list',(array)$info['vod_down_list']);
  367. $this->assign('vod_plot_list',(array)$info['vod_plot_list']);
  368. $this->assign('title',lang('admin/vod/title'));
  369. return $this->fetch('admin@vod/info');
  370. }
  371. public function iplot()
  372. {
  373. if (Request()->isPost()) {
  374. $param = input('post.');
  375. $res = model('Vod')->savePlot($param);
  376. if($res['code']>1){
  377. return $this->error($res['msg']);
  378. }
  379. return $this->success($res['msg']);
  380. }
  381. $id = input('id');
  382. $where=[];
  383. $where['vod_id'] = $id;
  384. $res = model('Vod')->infoData($where);
  385. $info = $res['info'];
  386. $this->assign('info',$info);
  387. $this->assign('vod_plot_list',$info['vod_plot_list']);
  388. $this->assign('title',lang('admin/vod/plot/title'));
  389. return $this->fetch('admin@vod/iplot');
  390. }
  391. public function del()
  392. {
  393. $param = input();
  394. $ids = $param['ids'];
  395. if(!empty($ids)){
  396. $where=[];
  397. $where['vod_id'] = ['in',$ids];
  398. $res = model('Vod')->delData($where);
  399. if($res['code']>1){
  400. return $this->error($res['msg']);
  401. }
  402. Cache::rm('vod_repeat_table_created_time');
  403. return $this->success($res['msg']);
  404. }
  405. elseif(!empty($param['repeat'])){
  406. if($param['retain']=='max') {
  407. // 保留最大ID - 先用子查询找出要保留的ID
  408. $sql = 'DELETE FROM '.config('database.prefix').'vod WHERE vod_id IN (
  409. SELECT * FROM (
  410. SELECT v1.vod_id
  411. FROM '.config('database.prefix').'vod v1
  412. INNER JOIN '.config('database.prefix').'vod v2
  413. ON v1.vod_name = v2.vod_name AND v1.vod_id < v2.vod_id
  414. ) tmp
  415. )';
  416. } else {
  417. // 保留最小ID - 先用子查询找出要保留的ID
  418. $sql = 'DELETE FROM '.config('database.prefix').'vod WHERE vod_id IN (
  419. SELECT * FROM (
  420. SELECT v1.vod_id
  421. FROM '.config('database.prefix').'vod v1
  422. INNER JOIN '.config('database.prefix').'vod v2
  423. ON v1.vod_name = v2.vod_name AND v1.vod_id > v2.vod_id
  424. ) tmp
  425. )';
  426. }
  427. $res = model('Vod')->execute($sql);
  428. if($res===false){
  429. return $this->success(lang('del_err'));
  430. }
  431. Cache::rm('vod_repeat_table_created_time');
  432. return $this->success(lang('del_ok'));
  433. }
  434. return $this->error(lang('param_err'));
  435. }
  436. public function field()
  437. {
  438. $param = input();
  439. $ids = $param['ids'];
  440. $col = $param['col'];
  441. $val = $param['val'];
  442. $start = $param['start'];
  443. $end = $param['end'];
  444. if ($col == 'type_id' && $val==''){
  445. return $this->error("请选择分类提交");
  446. }
  447. if(!empty($ids) && in_array($col,['vod_status','vod_lock','vod_level','vod_hits','type_id','vod_copyright'])){
  448. $where=[];
  449. $where['vod_id'] = ['in',$ids];
  450. $update = [];
  451. if(empty($start)) {
  452. $update[$col] = $val;
  453. if($col == 'type_id'){
  454. $type_list = model('Type')->getCache();
  455. $id1 = intval($type_list[$val]['type_pid']);
  456. $update['type_id_1'] = $id1;
  457. }
  458. $res = model('Vod')->fieldData($where, $update);
  459. }
  460. else{
  461. if(empty($end)){$end = 9999;}
  462. $ids = explode(',',$ids);
  463. foreach($ids as $k=>$v){
  464. $val = rand($start,$end);
  465. $where['vod_id'] = ['eq',$v];
  466. $update[$col] = $val;
  467. $res = model('Vod')->fieldData($where, $update);
  468. }
  469. }
  470. if($res['code']>1){
  471. return $this->error($res['msg']);
  472. }
  473. return $this->success($res['msg']);
  474. }
  475. return $this->error(lang('param_err'));
  476. }
  477. public function updateToday()
  478. {
  479. $param = input();
  480. $flag = $param['flag'];
  481. $res = model('Vod')->updateToday($flag);
  482. return json($res);
  483. }
  484. private function assignBaseListByConfig() {
  485. $player_list = config('vodplayer');
  486. $downer_list = config('voddowner');
  487. $server_list = config('vodserver');
  488. $player_list = mac_multisort($player_list,'sort',SORT_DESC,'status','1');
  489. $downer_list = mac_multisort($downer_list,'sort',SORT_DESC,'status','1');
  490. $server_list = mac_multisort($server_list,'sort',SORT_DESC,'status','1');
  491. $this->assign('player_list',$player_list);
  492. $this->assign('downer_list',$downer_list);
  493. $this->assign('server_list',$server_list);
  494. }
  495. }