Collect.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. use think\Cache;
  5. class Collect extends Base
  6. {
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. header('X-Accel-Buffering: no');
  11. }
  12. public function index()
  13. {
  14. $param = input();
  15. $param['page'] = intval($param['page']) < 1 ? 1 : $param['page'];
  16. $param['limit'] = intval($param['limit']) < 1 ? 100 : $param['limit'];
  17. $where = [];
  18. $order = 'collect_id desc';
  19. $res = model('Collect')->listData($where, $order, $param['page'], $param['limit']);
  20. $this->assign('list', $res['list']);
  21. $this->assign('total', $res['total']);
  22. $this->assign('page', $res['page']);
  23. $this->assign('limit', $res['limit']);
  24. $param['page'] = '{page}';
  25. $param['limit'] = '{limit}';
  26. $this->assign('param', $param);
  27. $key = $GLOBALS['config']['app']['cache_flag']. '_'. 'collect_break_vod';
  28. $collect_break_vod = Cache::get($key);
  29. $key = $GLOBALS['config']['app']['cache_flag']. '_'. 'collect_break_art';
  30. $collect_break_art = Cache::get($key);
  31. $key = $GLOBALS['config']['app']['cache_flag']. '_'. 'collect_break_actor';
  32. $collect_break_actor = Cache::get($key);
  33. $key = $GLOBALS['config']['app']['cache_flag']. '_'. 'collect_break_role';
  34. $collect_break_role = Cache::get($key);
  35. $key = $GLOBALS['config']['app']['cache_flag']. '_'. 'collect_break_website';
  36. $collect_break_website = Cache::get($key);
  37. $this->assign('collect_break_vod', $collect_break_vod);
  38. $this->assign('collect_break_art', $collect_break_art);
  39. $this->assign('collect_break_actor', $collect_break_actor);
  40. $this->assign('collect_break_role', $collect_break_role);
  41. $this->assign('collect_break_website', $collect_break_website);
  42. $this->assign('title',lang('admin/collect/title'));
  43. return $this->fetch('admin@collect/index');
  44. }
  45. public function test()
  46. {
  47. $param = input();
  48. $res = model('Collect')->vod($param);
  49. return json($res);
  50. }
  51. public function info()
  52. {
  53. if (Request()->isPost()) {
  54. $param = input('post.');
  55. $validate = \think\Loader::validate('Token');
  56. if(!$validate->check($param)){
  57. return $this->error($validate->getError());
  58. }
  59. $res = model('Collect')->saveData($param);
  60. if ($res['code'] > 1) {
  61. return $this->error($res['msg']);
  62. }
  63. return $this->success($res['msg']);
  64. }
  65. $id = input('id');
  66. $where = [];
  67. $where['collect_id'] = ['eq', $id];
  68. $res = model('Collect')->infoData($where);
  69. $this->assign('info', $res['info']);
  70. $this->assign('title', lang('admin/collect/title'));
  71. return $this->fetch('admin@collect/info');
  72. }
  73. public function del()
  74. {
  75. $param = input();
  76. $ids = $param['ids'];
  77. if (!empty($ids)) {
  78. $where = [];
  79. $where['collect_id'] = ['in', $ids];
  80. $res = model('Collect')->delData($where);
  81. if ($res['code'] > 1) {
  82. return $this->error($res['msg']);
  83. }
  84. return $this->success($res['msg']);
  85. }
  86. return $this->error(lang('param_err'));
  87. }
  88. public function union()
  89. {
  90. $key = $GLOBALS['config']['app']['cache_flag']. '_'. 'collect_break_vod';
  91. $collect_break_vod = Cache::get($key);
  92. $key = $GLOBALS['config']['app']['cache_flag']. '_'. 'collect_break_art';
  93. $collect_break_art = Cache::get($key);
  94. $key = $GLOBALS['config']['app']['cache_flag']. '_'. 'collect_break_actor';
  95. $collect_break_actor = Cache::get($key);
  96. $key = $GLOBALS['config']['app']['cache_flag']. '_'. 'collect_break_role';
  97. $collect_break_role = Cache::get($key);
  98. $key = $GLOBALS['config']['app']['cache_flag']. '_'. 'collect_break_website';
  99. $collect_break_website = Cache::get($key);
  100. $this->assign('collect_break_vod', $collect_break_vod);
  101. $this->assign('collect_break_art', $collect_break_art);
  102. $this->assign('collect_break_actor', $collect_break_actor);
  103. $this->assign('collect_break_role', $collect_break_role);
  104. $this->assign('collect_break_website', $collect_break_website);
  105. $this->assign('title', lang('admin/collect/title'));
  106. return $this->fetch('admin@collect/union');
  107. }
  108. public function load()
  109. {
  110. $param = input();
  111. $key = $GLOBALS['config']['app']['cache_flag']. '_'. 'collect_break_' . $param['flag'];
  112. $collect_break = Cache::get($key);
  113. $url = $this->_ref;
  114. if (!empty($collect_break)) {
  115. echo lang('admin/collect/load_break');
  116. $url = $collect_break;
  117. }
  118. mac_jump($url);
  119. }
  120. public function api($pp = [])
  121. {
  122. $param = input();
  123. if (!empty($pp)) {
  124. $param = $pp;
  125. }
  126. //分类
  127. $type_list = model('Type')->getCache('type_list');
  128. $this->assign('type_list', $type_list);
  129. if (!empty($param['pg'])) {
  130. $param['page'] = $param['pg'];
  131. unset($param['pg']);
  132. }
  133. if ($param['mid'] == '' || $param['mid'] == '1') {
  134. return $this->vod($param);
  135. } elseif ($param['mid'] == '2') {
  136. return $this->art($param);
  137. } elseif ($param['mid'] == '8') {
  138. return $this->actor($param);
  139. }
  140. elseif ($param['mid'] == '9') {
  141. return $this->role($param);
  142. }
  143. elseif ($param['mid'] == '11') {
  144. return $this->website($param);
  145. }
  146. }
  147. public function timing()
  148. {
  149. //当日视频分类ids
  150. $res = model('Vod')->updateToday('type');
  151. $this->assign('vod_type_ids_today', $res['data']);
  152. return $this->fetch('admin@collect/timing');
  153. }
  154. public function clearbind()
  155. {
  156. $param = input();
  157. $config = [];
  158. if(!empty($param['cjflag'])){
  159. $bind_list = config('bind');
  160. foreach($bind_list as $k=>$v){
  161. if(strpos($k,$param['cjflag'])===false){
  162. $config[$k] = $v;
  163. }
  164. }
  165. }
  166. $res = mac_arr2file( APP_PATH .'extra/bind.php', $config);
  167. if($res===false){
  168. return json(['code'=>0,'msg'=>lang('clear_err')]);
  169. }
  170. return json(['code'=>1,'msg'=>lang('clear_ok')]);
  171. }
  172. public function bind()
  173. {
  174. $param = input();
  175. $ids = $param['ids'];
  176. $col = $param['col'];
  177. $val = $param['val'];
  178. if(!empty($col)){
  179. $config = config('bind');
  180. $config[$col] = intval($val);
  181. $data = [];
  182. $data['id'] = $col;
  183. $data['st'] = 0;
  184. $data['local_type_id'] = $val;
  185. $data['local_type_name'] = '';
  186. if(intval($val)>0){
  187. $data['st'] = 1;
  188. $type_list = model('Type')->getCache('type_list');
  189. $data['local_type_name'] = $type_list[$val]['type_name'];
  190. }
  191. $res = mac_arr2file( APP_PATH .'extra/bind.php', $config);
  192. if($res===false){
  193. return $this->error(lang('save_err'));
  194. }
  195. return $this->success(lang('save_ok'),null, $data);
  196. }
  197. return $this->error(lang('param_err'));
  198. }
  199. public function vod($param)
  200. {
  201. if($param['ac'] != 'list'){
  202. $key = $GLOBALS['config']['app']['cache_flag']. '_'.'collect_break_vod';
  203. Cache::set($key, url('collect/api').'?'. http_build_query($param) );
  204. }
  205. $res = model('Collect')->vod($param);
  206. if($res['code']>1){
  207. return $this->error($res['msg']);
  208. }
  209. if($param['ac'] == 'list'){
  210. $bind_list = config('bind');
  211. $type_list = model('Type')->getCache('type_list');
  212. foreach($res['type'] as $k=>$v){
  213. $key = $param['cjflag'] . '_' . $v['type_id'];
  214. $res['type'][$k]['isbind'] = 0;
  215. $local_id = intval($bind_list[$key]);
  216. if( $local_id>0 ){
  217. $res['type'][$k]['isbind'] = 1;
  218. $res['type'][$k]['local_type_id'] = $local_id;
  219. $type_name = $type_list[$local_id]['type_name'];
  220. if(empty($type_name)){
  221. $type_name = lang('unknown_type');
  222. }
  223. $res['type'][$k]['local_type_name'] = $type_name;
  224. }
  225. }
  226. $this->assign('page',$res['page']);
  227. $this->assign('type',$res['type']);
  228. $this->assign('list',$res['data']);
  229. $this->assign('total',$res['page']['recordcount']);
  230. $this->assign('page',$res['page']['page']);
  231. $this->assign('limit',$res['page']['pagesize']);
  232. $param['page'] = '{page}';
  233. $param['limit'] = '{limit}';
  234. $this->assign('param',$param);
  235. $this->assign('param_str',http_build_query($param)) ;
  236. return $this->fetch('admin@collect/vod');
  237. }
  238. mac_echo('<style type="text/css">body{font-size:12px;color: #333333;line-height:21px;}span{font-weight:bold;color:#FF0000}</style>');
  239. model('Collect')->vod_data($param,$res );
  240. }
  241. public function art($param)
  242. {
  243. if($param['ac'] != 'list'){
  244. $key = $GLOBALS['config']['app']['cache_flag']. '_'.'collect_break_art';
  245. Cache::set($key, url('collect/api').'?'. http_build_query($param) );
  246. }
  247. $res = model('Collect')->art($param);
  248. if($res['code']>1){
  249. return $this->error($res['msg']);
  250. }
  251. if($param['ac'] == 'list'){
  252. $bind_list = config('bind');
  253. $type_list = model('Type')->getCache('type_list');
  254. foreach($res['type'] as $k=>$v){
  255. $key = $param['cjflag'] . '_' . $v['type_id'];
  256. $res['type'][$k]['isbind'] = 0;
  257. $local_id = intval($bind_list[$key]);
  258. if( $local_id>0 ){
  259. $res['type'][$k]['isbind'] = 1;
  260. $res['type'][$k]['local_type_id'] = $local_id;
  261. $type_name = $type_list[$local_id]['type_name'];
  262. if(empty($type_name)){
  263. $type_name = lang('unknown_type');
  264. }
  265. $res['type'][$k]['local_type_name'] = $type_name;
  266. }
  267. }
  268. $this->assign('page',$res['page']);
  269. $this->assign('type',$res['type']);
  270. $this->assign('list',$res['data']);
  271. $this->assign('total',$res['page']['recordcount']);
  272. $this->assign('page',$res['page']['page']);
  273. $this->assign('limit',$res['page']['pagesize']);
  274. $param['page'] = '{page}';
  275. $param['limit'] = '{limit}';
  276. $this->assign('param',$param);
  277. $this->assign('param_str',http_build_query($param)) ;
  278. return $this->fetch('admin@collect/art');
  279. }
  280. mac_echo('<style type="text/css">body{font-size:12px;color: #333333;line-height:21px;}span{font-weight:bold;color:#FF0000}</style>');
  281. model('Collect')->art_data($param,$res );
  282. }
  283. public function actor($param)
  284. {
  285. if($param['ac'] != 'list'){
  286. $key = $GLOBALS['config']['app']['cache_flag']. '_'.'collect_break_actor';
  287. Cache::set($key, url('collect/api').'?'. http_build_query($param) );
  288. }
  289. $res = model('Collect')->actor($param);
  290. if($res['code']>1){
  291. return $this->error($res['msg']);
  292. }
  293. if($param['ac'] == 'list'){
  294. $bind_list = config('bind');
  295. $type_list = model('Type')->getCache('type_list');
  296. foreach($res['type'] as $k=>$v){
  297. $key = $param['cjflag'] . '_' . $v['type_id'];
  298. $res['type'][$k]['isbind'] = 0;
  299. $local_id = intval($bind_list[$key]);
  300. if( $local_id>0 ){
  301. $res['type'][$k]['isbind'] = 1;
  302. $res['type'][$k]['local_type_id'] = $local_id;
  303. $type_name = $type_list[$local_id]['type_name'];
  304. if(empty($type_name)){
  305. $type_name = lang('unknown_type');
  306. }
  307. $res['type'][$k]['local_type_name'] = $type_name;
  308. }
  309. }
  310. $this->assign('page',$res['page']);
  311. $this->assign('type',$res['type']);
  312. $this->assign('list',$res['data']);
  313. $this->assign('total',$res['page']['recordcount']);
  314. $this->assign('page',$res['page']['page']);
  315. $this->assign('limit',$res['page']['pagesize']);
  316. $param['page'] = '{page}';
  317. $param['limit'] = '{limit}';
  318. $this->assign('param',$param);
  319. $this->assign('param_str',http_build_query($param)) ;
  320. return $this->fetch('admin@collect/actor');
  321. }
  322. mac_echo('<style type="text/css">body{font-size:12px;color: #333333;line-height:21px;}span{font-weight:bold;color:#FF0000}</style>');
  323. model('Collect')->actor_data($param,$res );
  324. }
  325. public function role($param)
  326. {
  327. if ($param['ac'] != 'list') {
  328. $key = $GLOBALS['config']['app']['cache_flag']. '_'.'collect_break_role';
  329. Cache::set($key, url('collect/api') . '?' . http_build_query($param));
  330. }
  331. $res = model('Collect')->role($param);
  332. if ($res['code'] > 1) {
  333. return $this->error($res['msg']);
  334. }
  335. if ($param['ac'] == 'list') {
  336. $bind_list = config('bind');
  337. $type_list = model('Type')->getCache('type_list');
  338. foreach ($res['type'] as $k => $v) {
  339. $key = $param['cjflag'] . '_' . $v['type_id'];
  340. $res['type'][$k]['isbind'] = 0;
  341. $local_id = intval($bind_list[$key]);
  342. if ($local_id > 0) {
  343. $res['type'][$k]['isbind'] = 1;
  344. $res['type'][$k]['local_type_id'] = $local_id;
  345. $type_name = $type_list[$local_id]['type_name'];
  346. if (empty($type_name)) {
  347. $type_name = lang('unknown_type');
  348. }
  349. $res['type'][$k]['local_type_name'] = $type_name;
  350. }
  351. }
  352. $this->assign('page', $res['page']);
  353. $this->assign('type', $res['type']);
  354. $this->assign('list', $res['data']);
  355. $this->assign('total', $res['page']['recordcount']);
  356. $this->assign('page', $res['page']['page']);
  357. $this->assign('limit', $res['page']['pagesize']);
  358. $param['page'] = '{page}';
  359. $param['limit'] = '{limit}';
  360. $this->assign('param', $param);
  361. $this->assign('param_str', http_build_query($param));
  362. return $this->fetch('admin@collect/role');
  363. }
  364. mac_echo('<style type="text/css">body{font-size:12px;color: #333333;line-height:21px;}span{font-weight:bold;color:#FF0000}</style>');
  365. model('Collect')->role_data($param,$res );
  366. }
  367. public function website($param)
  368. {
  369. if ($param['ac'] != 'list') {
  370. $key = $GLOBALS['config']['app']['cache_flag']. '_'.'collect_break_website';
  371. Cache::set($key, url('collect/api') . '?' . http_build_query($param));
  372. }
  373. $res = model('Collect')->website($param);
  374. if ($res['code'] > 1) {
  375. return $this->error($res['msg']);
  376. }
  377. if ($param['ac'] == 'list') {
  378. $bind_list = config('bind');
  379. $type_list = model('Type')->getCache('type_list');
  380. foreach ($res['type'] as $k => $v) {
  381. $key = $param['cjflag'] . '_' . $v['type_id'];
  382. $res['type'][$k]['isbind'] = 0;
  383. $local_id = intval($bind_list[$key]);
  384. if ($local_id > 0) {
  385. $res['type'][$k]['isbind'] = 1;
  386. $res['type'][$k]['local_type_id'] = $local_id;
  387. $type_name = $type_list[$local_id]['type_name'];
  388. if (empty($type_name)) {
  389. $type_name = lang('unknown_type');
  390. }
  391. $res['type'][$k]['local_type_name'] = $type_name;
  392. }
  393. }
  394. $this->assign('page', $res['page']);
  395. $this->assign('type', $res['type']);
  396. $this->assign('list', $res['data']);
  397. $this->assign('total', $res['page']['recordcount']);
  398. $this->assign('page', $res['page']['page']);
  399. $this->assign('limit', $res['page']['pagesize']);
  400. $param['page'] = '{page}';
  401. $param['limit'] = '{limit}';
  402. $this->assign('param', $param);
  403. $this->assign('param_str', http_build_query($param));
  404. return $this->fetch('admin@collect/website');
  405. }
  406. mac_echo('<style type="text/css">body{font-size:12px;color: #333333;line-height:21px;}span{font-weight:bold;color:#FF0000}</style>');
  407. model('Collect')->website_data($param,$res );
  408. }
  409. }