Vod.php 19 KB

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