Vod.php 23 KB

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