Vod.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  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. if (!empty($param['recycle'])) {
  112. $where['vod_recycle_time'] = ['>', 0];
  113. }
  114. $order='vod_time desc';
  115. if(in_array($param['order'],['vod_id','vod_hits','vod_hits_month','vod_hits_week','vod_hits_day'])){
  116. $order = $param['order'] .' desc';
  117. }
  118. if(!empty($param['repeat'])){
  119. if(!empty($param['cache'])){
  120. model('Vod')->createRepeatCache();
  121. return $this->success(lang('update_ok'));
  122. }
  123. if($param['page'] ==1){
  124. //使用缓存查看是否创建过缓存表
  125. $cacheResult = Cache::get('vod_repeat_table_created_time',0);
  126. //缓存时间超过7天和没有创建过缓存都会重建缓存
  127. if( $cacheResult == 0 || time() - $cacheResult > 604800){
  128. model('Vod')->createRepeatCache();
  129. }
  130. }
  131. $order='vod_name asc';
  132. $res = model('Vod')->listRepeatData($where,$order,$param['page'],$param['limit']);
  133. }
  134. else{
  135. $res = model('Vod')->listData($where,$order,$param['page'],$param['limit']);
  136. }
  137. // 批量查询哪些视频有角色数据
  138. $vodIds = array_column($res['list'], 'vod_id');
  139. $vodIdsWithRole = [];
  140. $vodSeoStatusMap = [];
  141. if (!empty($vodIds)) {
  142. $roleData = Db::name('role')
  143. ->where('role_rid', 'in', $vodIds)
  144. ->where('role_rid', '>', 0)
  145. ->group('role_rid')
  146. ->column('role_rid');
  147. $vodIdsWithRole = array_flip($roleData); // 转为键值对,方便快速查找
  148. $seoRows = Db::name('seo_ai_result')
  149. ->field('seo_obj_id,seo_status')
  150. ->where('seo_mid', 1)
  151. ->where('seo_obj_id', 'in', $vodIds)
  152. ->where('seo_status', 'in', [1, 2])
  153. ->select();
  154. foreach ((array)$seoRows as $seoRow) {
  155. $vodSeoStatusMap[intval($seoRow['seo_obj_id'])] = intval($seoRow['seo_status']);
  156. }
  157. }
  158. foreach($res['list'] as $k=>&$v){
  159. $v['ismake'] = 1;
  160. if($GLOBALS['config']['view']['vod_detail'] >0 && $v['vod_time_make'] < $v['vod_time']){
  161. $v['ismake'] = 0;
  162. }
  163. // 标记是否有角色数据
  164. $v['vod_role'] = isset($vodIdsWithRole[$v['vod_id']]) ? 1 : 0;
  165. $v['seo_ai_status'] = isset($vodSeoStatusMap[$v['vod_id']]) ? intval($vodSeoStatusMap[$v['vod_id']]) : 0;
  166. }
  167. $this->assign('list',$res['list']);
  168. $this->assign('total',$res['total']);
  169. $this->assign('page',$res['page']);
  170. $this->assign('limit',$res['limit']);
  171. $param['page'] = '{page}';
  172. $param['limit'] = '{limit}';
  173. $this->assign('param',$param);
  174. $queryString = '?' . http_build_query($param);
  175. $this->assign('query_string',$queryString);
  176. //分类
  177. $type_tree = model('Type')->getCache('type_tree');
  178. $this->assign('type_tree',$type_tree);
  179. //播放器
  180. $this->assignBaseListByConfig();
  181. $this->assign('title',lang('admin/vod/title'));
  182. return $this->fetch('admin@vod/index');
  183. }
  184. public function batch()
  185. {
  186. $param = input();
  187. if (!empty($param)) {
  188. mac_echo('<style type="text/css">body{font-size:12px;color: #333333;line-height:21px;}span{font-weight:bold;color:#FF0000}</style>');
  189. if(empty($param['ck_del']) && empty($param['ck_level']) && empty($param['ck_status']) && empty($param['ck_lock']) && empty($param['ck_hits'])
  190. && empty($param['ck_points']) && empty($param['ck_copyright']) && empty($param['ck_type']) && empty($param['ck_tag']) && empty($param['ck_play'])
  191. && empty($param['ck_replace'])
  192. ){
  193. return $this->error(lang('param_err'));
  194. }
  195. if($param['ck_del']==2 && empty($param['player'])){
  196. return $this->error(lang('admin/vod/del_play_must_select_play'));
  197. }
  198. if($param['ck_del']==3 && empty($param['downer'])){
  199. return $this->error(lang('admin/vod/del_down_must_select_down'));
  200. }
  201. $where = $this->vodBatchFilterWhere($param);
  202. if($param['ck_del'] == 1){
  203. $res = model('Vod')->recycleData($where);
  204. mac_echo($res['code'] == 1 ? lang('recycle_ok') : $res['msg']);
  205. mac_jump( url('vod/batch') ,3);
  206. exit;
  207. }
  208. if($param['ck_del'] == 4){
  209. $res = model('Vod')->delData($where);
  210. mac_echo(lang('multi_del_ok'));
  211. mac_jump( url('vod/batch') ,3);
  212. exit;
  213. }
  214. if(empty($param['page'])){
  215. $param['page'] = 1;
  216. }
  217. if(empty($param['limit'])){
  218. $param['limit'] = 100;
  219. }
  220. if(empty($param['total'])) {
  221. $param['total'] = model('Vod')->countData($where);
  222. $param['page_count'] = ceil($param['total'] / $param['limit']);
  223. }
  224. if($param['page'] > $param['page_count']) {
  225. mac_echo(lang('multi_opt_ok'));
  226. mac_jump( url('vod/batch') ,3);
  227. exit;
  228. }
  229. mac_echo( "<font color=red>".lang('admin/batch_tip',[$param['total'],$param['limit'],$param['page_count'],$param['page']])."</font>");
  230. $page = $param['page_count'] - $param['page'] + 1;
  231. $order='vod_id desc';
  232. $res = model('Vod')->listData($where,$order,$page,$param['limit']);
  233. foreach($res['list'] as $k=>$v){
  234. $where2 = [];
  235. $where2['vod_id'] = $v['vod_id'];
  236. $update = [];
  237. $des = $v['vod_id'].','.$v['vod_name'];
  238. if(!empty($param['ck_level']) && !empty($param['val_level'])){
  239. $update['vod_level'] = $param['val_level'];
  240. $des .= '&nbsp;'.lang('level').':'.$param['val_level'].';';
  241. }
  242. if(!empty($param['ck_status']) && isset($param['val_status'])){
  243. $update['vod_status'] = $param['val_status'];
  244. $des .= '&nbsp;'.lang('status').':'.($param['val_status'] ==1 ? '['.lang('reviewed').']':'['.lang('reviewed_not').']') .';';
  245. }
  246. if(!empty($param['ck_copyright']) && isset($param['val_copyright'])){
  247. $update['vod_copyright'] = $param['val_copyright'];
  248. $des .= '&nbsp;'.lang('copyright').':'.($param['val_copyright'] ==1 ? '['.lang('open').']':'['.lang('close').'') .';';
  249. }
  250. if(!empty($param['ck_lock']) && isset($param['val_lock'])){
  251. $update['vod_lock'] = $param['val_lock'];
  252. $des .= '&nbsp;'.lang('lock').':'.($param['val_lock']==1 ? '['.lang('lock').']':'['.lang('unlock').']').';';
  253. }
  254. if(!empty($param['ck_hits']) && $param['val_hits_min']!='' && $param['val_hits_max']!='' ){
  255. $update['vod_hits'] = rand($param['val_hits_min'],$param['val_hits_max']);
  256. $des .= '&nbsp;'.lang('hits').':'.$update['vod_hits'].';';
  257. }
  258. if(!empty($param['ck_points']) && $param['val_points_play']!='' ){
  259. $update['vod_points_play'] = $param['val_points_play'];
  260. $des .= '&nbsp;'.lang('points_play').':'.$param['val_points_play'].';';
  261. }
  262. if(!empty($param['ck_points']) && $param['val_points_down']!='' ){
  263. $update['vod_points_down'] = $param['val_points_down'];
  264. $des .= '&nbsp;'.lang('points_down').':'.$param['val_points_down'].';';
  265. }
  266. // 新增:批量修改分类
  267. if(!empty($param['ck_type']) && !empty($param['val_type'])){
  268. $update['type_id'] = intval($param['val_type']);
  269. $type_list = model('Type')->getCache();
  270. if(isset($type_list[$update['type_id']])){
  271. $id1 = intval($type_list[$update['type_id']]['type_pid']);
  272. $update['type_id_1'] = $id1;
  273. }
  274. $des .= '&nbsp;'.lang('type').':'.$update['type_id'].';';
  275. }
  276. // 新增:批量修改标签
  277. if(!empty($param['ck_tag']) && !empty($param['val_tag'])){
  278. $update['vod_tag'] = mac_filter_xss($param['val_tag']);
  279. $des .= '&nbsp;'.lang('tag').':'.$update['vod_tag'].';';
  280. }
  281. // 新增:批量修改播放源
  282. if(!empty($param['ck_play']) && !empty($param['val_play'])){
  283. $update['vod_play_from'] = $param['val_play'];
  284. $des .= '&nbsp;'.lang('play_group').':'.$param['val_play'].';';
  285. }
  286. // 新增:批量替换功能
  287. if(!empty($param['ck_replace']) && !empty($param['replace_field']) && isset($param['replace_search'])){
  288. $field = $param['replace_field'];
  289. $replaceres = $this->batch_replace($field,$v,$param['replace_search'],$param['replace_with'],'vod');
  290. if(isset($replaceres[$field])) $update[$field] = $replaceres[$field];
  291. if(!empty($replaceres['des'])) $des .= $replaceres['des'];
  292. }
  293. if($param['ck_del'] == 2 || $param['ck_del'] ==3){
  294. if($param['ck_del']==2) {
  295. $pre = 'vod_play';
  296. $par = 'player';
  297. $des .= '&nbsp;'.lang('play_group').':';
  298. }
  299. elseif($param['ck_del']==3){
  300. $pre = 'vod_down';
  301. $par='downer';
  302. $des .= '&nbsp;'.lang('down_group').':';
  303. }
  304. if($param[$par] == $v[$pre.'_from']){
  305. $update[$pre.'_from'] = '';
  306. $update[$pre.'_server'] = '';
  307. $update[$pre.'_note'] = '';
  308. $update[$pre.'_url'] = '';
  309. $des .= lang('del_empty').';';
  310. }
  311. else{
  312. $vod_from_arr = explode('$$$',$v[$pre.'_from']);
  313. $vod_server_arr = explode('$$$',$v[$pre.'_server']);
  314. $vod_note_arr = explode('$$$',$v[$pre.'_note']);
  315. $vod_url_arr = explode('$$$',$v[$pre.'_url']);
  316. $key = array_search($param[$par],$vod_from_arr);
  317. if($key!==false){
  318. unset($vod_from_arr[$key]);
  319. unset($vod_server_arr[$key]);
  320. unset($vod_note_arr[$key]);
  321. unset($vod_url_arr[$key]);
  322. $update[$pre.'_from'] = join('$$$',$vod_from_arr);
  323. $update[$pre.'_server'] = join('$$$',$vod_server_arr);
  324. $update[$pre.'_note'] = join('$$$',$vod_note_arr);
  325. $update[$pre.'_url'] = join('$$$',$vod_url_arr);
  326. $des .= lang('del'). ';';
  327. }
  328. else{
  329. $des .= lang('jump_over').';';
  330. }
  331. }
  332. }
  333. mac_echo($des);
  334. $res2 = model('Vod')->where($where2)->update($update);
  335. }
  336. $param['page']++;
  337. $url = url('vod/batch') .'?'. http_build_query($param);
  338. mac_jump( $url ,3);
  339. exit;
  340. }
  341. //分类
  342. $type_tree = model('Type')->getCache('type_tree');
  343. $this->assign('type_tree',$type_tree);
  344. //播放器
  345. $this->assignBaseListByConfig();
  346. $this->assign('title',lang('admin/vod/title'));
  347. return $this->fetch('admin@vod/batch');
  348. }
  349. /**
  350. * 与批量操作页筛选条件一致(用于导出)
  351. */
  352. private function vodBatchFilterWhere(&$param)
  353. {
  354. $where = [];
  355. if (!empty($param['type'])) {
  356. $where['type_id'] = ['eq', $param['type']];
  357. }
  358. if (!empty($param['level'])) {
  359. $where['vod_level'] = ['eq', $param['level']];
  360. }
  361. if (in_array($param['status'] ?? '', ['0', '1'])) {
  362. $where['vod_status'] = ['eq', $param['status']];
  363. }
  364. if (in_array($param['copyright'] ?? '', ['0', '1'])) {
  365. $where['vod_copyright'] = ['eq', $param['copyright']];
  366. }
  367. if (in_array($param['isend'] ?? '', ['0', '1'])) {
  368. $where['vod_isend'] = ['eq', $param['isend']];
  369. }
  370. if (!empty($param['lock'])) {
  371. $where['vod_lock'] = ['eq', $param['lock']];
  372. }
  373. if (!empty($param['state'])) {
  374. $where['vod_state'] = ['eq', $param['state']];
  375. }
  376. if (!empty($param['area'])) {
  377. $where['vod_area'] = ['eq', $param['area']];
  378. }
  379. if (!empty($param['lang'])) {
  380. $where['vod_lang'] = ['eq', $param['lang']];
  381. }
  382. if (in_array($param['plot'] ?? '', ['0', '1'])) {
  383. $where['vod_plot'] = ['eq', $param['plot']];
  384. }
  385. if (in_array($param['role'] ?? '', ['0', '1'])) {
  386. $roleVodIds = Db::name('role')->where('role_rid', '>', 0)->group('role_rid')->column('role_rid');
  387. if ($param['role'] == '1') {
  388. if (!empty($roleVodIds)) {
  389. $where['vod_id'] = ['in', $roleVodIds];
  390. } else {
  391. $where['vod_id'] = ['eq', 0];
  392. }
  393. } else {
  394. if (!empty($roleVodIds)) {
  395. $where['vod_id'] = ['not in', $roleVodIds];
  396. }
  397. }
  398. }
  399. if (!empty($param['url'])) {
  400. if ($param['url'] == 1) {
  401. $where['vod_play_url'] = '';
  402. }
  403. }
  404. if (!empty($param['points'])) {
  405. $where['vod_points_play|vod_points_down'] = ['gt', 0];
  406. }
  407. if (!empty($param['pic'])) {
  408. if ($param['pic'] == '1') {
  409. $where['vod_pic'] = ['eq', ''];
  410. } elseif ($param['pic'] == '2') {
  411. $where['vod_pic'] = ['like', 'http%'];
  412. } elseif ($param['pic'] == '3') {
  413. $where['vod_pic'] = ['like', '%#err%'];
  414. }
  415. }
  416. if (!empty($param['wd'])) {
  417. $param['wd'] = htmlspecialchars(urldecode($param['wd']));
  418. $where['vod_name'] = ['like', '%' . $param['wd'] . '%'];
  419. }
  420. if (!empty($param['weekday'])) {
  421. $where['vod_weekday'] = ['like', '%' . $param['weekday'] . '%'];
  422. }
  423. if (!empty($param['player'])) {
  424. if ($param['player'] == 'no') {
  425. $where['vod_play_from'] = [['eq', ''], ['eq', 'no'], 'or'];
  426. } else {
  427. $where['vod_play_from'] = ['like', '%' . $param['player'] . '%'];
  428. }
  429. }
  430. if (!empty($param['downer'])) {
  431. if ($param['downer'] == 'no') {
  432. $where['vod_down_from'] = [['eq', ''], ['eq', 'no'], 'or'];
  433. } else {
  434. $where['vod_down_from'] = ['like', '%' . $param['downer'] . '%'];
  435. }
  436. }
  437. if (!empty($param['server'])) {
  438. $where['vod_play_server|vod_down_server'] = ['like', '%' . $param['server'] . '%'];
  439. }
  440. if (!empty($param['recycle'])) {
  441. $where['vod_recycle_time'] = ['>', 0];
  442. }
  443. return $where;
  444. }
  445. public function exportData()
  446. {
  447. $param = input();
  448. $where = $this->vodBatchFilterWhere($param);
  449. $this->base_export($param,'vod',$where);
  450. }
  451. public function importData()
  452. {
  453. $this->base_import('vod');
  454. }
  455. public function info()
  456. {
  457. if (Request()->isPost()) {
  458. $param = input('post.');
  459. $res = model('Vod')->saveData($param);
  460. if($res['code']>1){
  461. return $this->error($res['msg']);
  462. }
  463. return $this->success($res['msg']);
  464. }
  465. $id = input('id');
  466. $where=[];
  467. $where['vod_id'] = $id;
  468. $where['_recycle'] = 'all';
  469. $res = model('Vod')->infoData($where);
  470. $info = $res['info'];
  471. $this->assign('info',$info);
  472. $seoAiStatus = 0;
  473. if (!empty($info['vod_id'])) {
  474. $seoAi = model('SeoAiResult')->getByObject(1, intval($info['vod_id']));
  475. if (!empty($seoAi)) {
  476. $seoAiStatus = intval($seoAi['seo_status']);
  477. }
  478. }
  479. $this->assign('seo_ai_status', $seoAiStatus);
  480. //分类
  481. $type_tree = model('Type')->getCache('type_tree');
  482. $this->assign('type_tree',$type_tree);
  483. //地区、语言
  484. $config = config('maccms.app');
  485. $area_list = explode(',',$config['vod_area']);
  486. $lang_list = explode(',',$config['vod_lang']);
  487. $this->assign('area_list',$area_list);
  488. $this->assign('lang_list',$lang_list);
  489. //用户组
  490. $group_list = model('Group')->getCache('group_list');
  491. $this->assign('group_list',$group_list);
  492. //播放器
  493. $this->assignBaseListByConfig();
  494. //播放组、下载租
  495. $this->assign('vod_play_list',(array)$info['vod_play_list']);
  496. $this->assign('vod_down_list',(array)$info['vod_down_list']);
  497. $this->assign('vod_plot_list',(array)$info['vod_plot_list']);
  498. $this->assign('title',lang('admin/vod/title'));
  499. return $this->fetch('admin@vod/info');
  500. }
  501. public function aiSeoGenerate()
  502. {
  503. if (!Request()->isPost()) {
  504. return json(['code' => 0, 'msg' => lang('illegal_request'), 'data' => []]);
  505. }
  506. $id = intval(input('post.id'));
  507. if ($id <= 0) {
  508. return json(['code' => 0, 'msg' => lang('param_err'), 'data' => []]);
  509. }
  510. try {
  511. $res = \app\common\util\SeoAi::generateByMidObj(1, $id);
  512. } catch (\Exception $e) {
  513. \think\Log::error('AI SEO generate failed (vod_id=' . $id . '): ' . $e->getMessage());
  514. return json(['code' => 0, 'msg' => $e->getMessage(), 'data' => []]);
  515. }
  516. if (empty($res['code']) || intval($res['code']) !== 1) {
  517. return json(['code' => 0, 'msg' => isset($res['msg']) ? $res['msg'] : lang('save_err'), 'data' => []]);
  518. }
  519. return json(['code' => 1, 'msg' => lang('save_ok'), 'data' => isset($res['data']) ? $res['data'] : []]);
  520. }
  521. public function iplot()
  522. {
  523. if (Request()->isPost()) {
  524. $param = input('post.');
  525. $res = model('Vod')->savePlot($param);
  526. if($res['code']>1){
  527. return $this->error($res['msg']);
  528. }
  529. return $this->success($res['msg']);
  530. }
  531. $id = input('id');
  532. $where=[];
  533. $where['vod_id'] = $id;
  534. $where['_recycle'] = 'all';
  535. $res = model('Vod')->infoData($where);
  536. $info = $res['info'];
  537. $this->assign('info',$info);
  538. $this->assign('vod_plot_list',$info['vod_plot_list']);
  539. $this->assign('title',lang('admin/vod/plot/title'));
  540. return $this->fetch('admin@vod/iplot');
  541. }
  542. public function restore()
  543. {
  544. $param = input();
  545. $ids = $param['ids'];
  546. if (empty($ids)) {
  547. return $this->error(lang('param_err'));
  548. }
  549. $where = ['vod_id' => ['in', $ids]];
  550. $res = model('Vod')->restoreData($where);
  551. if ($res['code'] > 1) {
  552. return $this->error($res['msg']);
  553. }
  554. Cache::rm('vod_repeat_table_created_time');
  555. return $this->success($res['msg']);
  556. }
  557. public function del()
  558. {
  559. $param = input();
  560. $ids = $param['ids'];
  561. $purge = !empty($param['purge']);
  562. if(!empty($ids)){
  563. $where=[];
  564. $where['vod_id'] = ['in',$ids];
  565. if ($purge) {
  566. $res = model('Vod')->delData($where);
  567. } else {
  568. $res = model('Vod')->recycleData($where);
  569. }
  570. if($res['code']>1){
  571. return $this->error($res['msg']);
  572. }
  573. Cache::rm('vod_repeat_table_created_time');
  574. return $this->success($res['msg']);
  575. }
  576. elseif(!empty($param['repeat'])){
  577. if($param['retain']=='max') {
  578. // 保留最大ID - 先用子查询找出要保留的ID
  579. $sql = 'DELETE FROM '.config('database.prefix').'vod WHERE vod_id IN (
  580. SELECT * FROM (
  581. SELECT v1.vod_id
  582. FROM '.config('database.prefix').'vod v1
  583. INNER JOIN '.config('database.prefix').'vod v2
  584. ON v1.vod_name = v2.vod_name AND v1.vod_id < v2.vod_id
  585. ) tmp
  586. )';
  587. } else {
  588. // 保留最小ID - 先用子查询找出要保留的ID
  589. $sql = 'DELETE FROM '.config('database.prefix').'vod WHERE vod_id IN (
  590. SELECT * FROM (
  591. SELECT v1.vod_id
  592. FROM '.config('database.prefix').'vod v1
  593. INNER JOIN '.config('database.prefix').'vod v2
  594. ON v1.vod_name = v2.vod_name AND v1.vod_id > v2.vod_id
  595. ) tmp
  596. )';
  597. }
  598. $res = model('Vod')->execute($sql);
  599. if($res===false){
  600. return $this->success(lang('del_err'));
  601. }
  602. Cache::rm('vod_repeat_table_created_time');
  603. return $this->success(lang('del_ok'));
  604. }
  605. return $this->error(lang('param_err'));
  606. }
  607. public function field()
  608. {
  609. $param = input();
  610. $ids = $param['ids'];
  611. $col = $param['col'];
  612. $val = $param['val'];
  613. $start = $param['start'];
  614. $end = $param['end'];
  615. if ($col == 'type_id' && $val==''){
  616. return $this->error("请选择分类提交");
  617. }
  618. if(!empty($ids) && in_array($col,['vod_status','vod_lock','vod_level','vod_hits','type_id','vod_copyright'])){
  619. $where=[];
  620. $where['vod_id'] = ['in',$ids];
  621. $update = [];
  622. if(empty($start)) {
  623. $update[$col] = $val;
  624. if($col == 'type_id'){
  625. $type_list = model('Type')->getCache();
  626. $id1 = intval($type_list[$val]['type_pid']);
  627. $update['type_id_1'] = $id1;
  628. }
  629. $res = model('Vod')->fieldData($where, $update);
  630. }
  631. else{
  632. if(empty($end)){$end = 9999;}
  633. $ids = explode(',',$ids);
  634. foreach($ids as $k=>$v){
  635. $val = rand($start,$end);
  636. $where['vod_id'] = ['eq',$v];
  637. $update[$col] = $val;
  638. $res = model('Vod')->fieldData($where, $update);
  639. }
  640. }
  641. if($res['code']>1){
  642. return $this->error($res['msg']);
  643. }
  644. return $this->success($res['msg']);
  645. }
  646. return $this->error(lang('param_err'));
  647. }
  648. public function updateToday()
  649. {
  650. $param = input();
  651. $flag = $param['flag'];
  652. $res = model('Vod')->updateToday($flag);
  653. return json($res);
  654. }
  655. private function assignBaseListByConfig() {
  656. $player_list = config('vodplayer');
  657. $downer_list = config('voddowner');
  658. $server_list = config('vodserver');
  659. $player_list = mac_multisort($player_list,'sort',SORT_DESC,'status','1');
  660. $downer_list = mac_multisort($downer_list,'sort',SORT_DESC,'status','1');
  661. $server_list = mac_multisort($server_list,'sort',SORT_DESC,'status','1');
  662. $this->assign('player_list',$player_list);
  663. $this->assign('downer_list',$downer_list);
  664. $this->assign('server_list',$server_list);
  665. }
  666. }