Collect.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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. @session_write_close();
  134. if ($param['mid'] == '' || $param['mid'] == '1') {
  135. return $this->vod($param);
  136. } elseif ($param['mid'] == '2') {
  137. return $this->art($param);
  138. } elseif ($param['mid'] == '8') {
  139. return $this->actor($param);
  140. }
  141. elseif ($param['mid'] == '9') {
  142. return $this->role($param);
  143. }
  144. elseif ($param['mid'] == '11') {
  145. return $this->website($param);
  146. }
  147. }
  148. public function timing()
  149. {
  150. //当日视频分类ids
  151. $res = model('Vod')->updateToday('type');
  152. $this->assign('vod_type_ids_today', $res['data']);
  153. return $this->fetch('admin@collect/timing');
  154. }
  155. public function clearbind()
  156. {
  157. $param = input();
  158. $config = [];
  159. if(!empty($param['cjflag'])){
  160. $bind_list = config('bind');
  161. foreach($bind_list as $k=>$v){
  162. if(strpos($k,$param['cjflag'])===false){
  163. $config[$k] = $v;
  164. }
  165. }
  166. }
  167. $res = mac_arr2file( APP_PATH .'extra/bind.php', $config);
  168. if($res===false){
  169. return json(['code'=>0,'msg'=>lang('clear_err')]);
  170. }
  171. return json(['code'=>1,'msg'=>lang('clear_ok')]);
  172. }
  173. public function bind()
  174. {
  175. $param = input();
  176. $ids = $param['ids'];
  177. $col = $param['col'];
  178. $val = $param['val'];
  179. if(!empty($col)){
  180. $config = config('bind');
  181. $config[$col] = intval($val);
  182. $data = [];
  183. $data['id'] = $col;
  184. $data['st'] = 0;
  185. $data['local_type_id'] = $val;
  186. $data['local_type_name'] = '';
  187. if(intval($val)>0){
  188. $data['st'] = 1;
  189. $type_list = model('Type')->getCache('type_list');
  190. $data['local_type_name'] = $type_list[$val]['type_name'];
  191. }
  192. $res = mac_arr2file( APP_PATH .'extra/bind.php', $config);
  193. if($res===false){
  194. return $this->error(lang('save_err'));
  195. }
  196. return $this->success(lang('save_ok'),null, $data);
  197. }
  198. return $this->error(lang('param_err'));
  199. }
  200. public function vod($param)
  201. {
  202. if($param['ac'] != 'list'){
  203. $key = $GLOBALS['config']['app']['cache_flag']. '_'.'collect_break_vod';
  204. Cache::set($key, url('collect/api').'?'. http_build_query($param) );
  205. }
  206. $res = model('Collect')->vod($param);
  207. if($res['code']>1){
  208. return $this->error($res['msg']);
  209. }
  210. if($param['ac'] == 'list'){
  211. $bind_list = config('bind');
  212. $type_list = model('Type')->getCache('type_list');
  213. foreach($res['type'] as $k=>$v){
  214. $key = $param['cjflag'] . '_' . $v['type_id'];
  215. $res['type'][$k]['isbind'] = 0;
  216. $local_id = intval($bind_list[$key]);
  217. if( $local_id>0 ){
  218. $res['type'][$k]['isbind'] = 1;
  219. $res['type'][$k]['local_type_id'] = $local_id;
  220. $type_name = $type_list[$local_id]['type_name'];
  221. if(empty($type_name)){
  222. $type_name = lang('unknown_type');
  223. }
  224. $res['type'][$k]['local_type_name'] = $type_name;
  225. }
  226. }
  227. $this->assign('page',$res['page']);
  228. $this->assign('type',$res['type']);
  229. $this->assign('list',$res['data']);
  230. $this->assign('total',$res['page']['recordcount']);
  231. $this->assign('page',$res['page']['page']);
  232. $this->assign('limit',$res['page']['pagesize']);
  233. $param['page'] = '{page}';
  234. $param['limit'] = '{limit}';
  235. $this->assign('param',$param);
  236. $this->assign('param_str',http_build_query($param)) ;
  237. return $this->fetch('admin@collect/vod');
  238. }
  239. $page_now = isset($param['page']) && strlen($param['page']) > 0 ? (int)$param['page'] : 1;
  240. mac_echo('<title>' . $page_now . '/' . (int)$res['page']['pagecount'] . ' collecting..</title>');
  241. mac_echo('<style type="text/css">body{font-size:12px;color: #333333;line-height:21px;}span{font-weight:bold;color:#FF0000}</style>');
  242. model('Collect')->vod_data($param,$res );
  243. }
  244. public function art($param)
  245. {
  246. if($param['ac'] != 'list'){
  247. $key = $GLOBALS['config']['app']['cache_flag']. '_'.'collect_break_art';
  248. Cache::set($key, url('collect/api').'?'. http_build_query($param) );
  249. }
  250. $res = model('Collect')->art($param);
  251. if($res['code']>1){
  252. return $this->error($res['msg']);
  253. }
  254. if($param['ac'] == 'list'){
  255. $bind_list = config('bind');
  256. $type_list = model('Type')->getCache('type_list');
  257. foreach($res['type'] as $k=>$v){
  258. $key = $param['cjflag'] . '_' . $v['type_id'];
  259. $res['type'][$k]['isbind'] = 0;
  260. $local_id = intval($bind_list[$key]);
  261. if( $local_id>0 ){
  262. $res['type'][$k]['isbind'] = 1;
  263. $res['type'][$k]['local_type_id'] = $local_id;
  264. $type_name = $type_list[$local_id]['type_name'];
  265. if(empty($type_name)){
  266. $type_name = lang('unknown_type');
  267. }
  268. $res['type'][$k]['local_type_name'] = $type_name;
  269. }
  270. }
  271. $this->assign('page',$res['page']);
  272. $this->assign('type',$res['type']);
  273. $this->assign('list',$res['data']);
  274. $this->assign('total',$res['page']['recordcount']);
  275. $this->assign('page',$res['page']['page']);
  276. $this->assign('limit',$res['page']['pagesize']);
  277. $param['page'] = '{page}';
  278. $param['limit'] = '{limit}';
  279. $this->assign('param',$param);
  280. $this->assign('param_str',http_build_query($param)) ;
  281. return $this->fetch('admin@collect/art');
  282. }
  283. mac_echo('<style type="text/css">body{font-size:12px;color: #333333;line-height:21px;}span{font-weight:bold;color:#FF0000}</style>');
  284. model('Collect')->art_data($param,$res );
  285. }
  286. public function actor($param)
  287. {
  288. if($param['ac'] != 'list'){
  289. $key = $GLOBALS['config']['app']['cache_flag']. '_'.'collect_break_actor';
  290. Cache::set($key, url('collect/api').'?'. http_build_query($param) );
  291. }
  292. $res = model('Collect')->actor($param);
  293. if($res['code']>1){
  294. return $this->error($res['msg']);
  295. }
  296. if($param['ac'] == 'list'){
  297. $bind_list = config('bind');
  298. $type_list = model('Type')->getCache('type_list');
  299. foreach($res['type'] as $k=>$v){
  300. $key = $param['cjflag'] . '_' . $v['type_id'];
  301. $res['type'][$k]['isbind'] = 0;
  302. $local_id = intval($bind_list[$key]);
  303. if( $local_id>0 ){
  304. $res['type'][$k]['isbind'] = 1;
  305. $res['type'][$k]['local_type_id'] = $local_id;
  306. $type_name = $type_list[$local_id]['type_name'];
  307. if(empty($type_name)){
  308. $type_name = lang('unknown_type');
  309. }
  310. $res['type'][$k]['local_type_name'] = $type_name;
  311. }
  312. }
  313. $this->assign('page',$res['page']);
  314. $this->assign('type',$res['type']);
  315. $this->assign('list',$res['data']);
  316. $this->assign('total',$res['page']['recordcount']);
  317. $this->assign('page',$res['page']['page']);
  318. $this->assign('limit',$res['page']['pagesize']);
  319. $param['page'] = '{page}';
  320. $param['limit'] = '{limit}';
  321. $this->assign('param',$param);
  322. $this->assign('param_str',http_build_query($param)) ;
  323. return $this->fetch('admin@collect/actor');
  324. }
  325. mac_echo('<style type="text/css">body{font-size:12px;color: #333333;line-height:21px;}span{font-weight:bold;color:#FF0000}</style>');
  326. model('Collect')->actor_data($param,$res );
  327. }
  328. public function role($param)
  329. {
  330. if ($param['ac'] != 'list') {
  331. $key = $GLOBALS['config']['app']['cache_flag']. '_'.'collect_break_role';
  332. Cache::set($key, url('collect/api') . '?' . http_build_query($param));
  333. }
  334. $res = model('Collect')->role($param);
  335. if ($res['code'] > 1) {
  336. return $this->error($res['msg']);
  337. }
  338. if ($param['ac'] == 'list') {
  339. $bind_list = config('bind');
  340. $type_list = model('Type')->getCache('type_list');
  341. foreach ($res['type'] as $k => $v) {
  342. $key = $param['cjflag'] . '_' . $v['type_id'];
  343. $res['type'][$k]['isbind'] = 0;
  344. $local_id = intval($bind_list[$key]);
  345. if ($local_id > 0) {
  346. $res['type'][$k]['isbind'] = 1;
  347. $res['type'][$k]['local_type_id'] = $local_id;
  348. $type_name = $type_list[$local_id]['type_name'];
  349. if (empty($type_name)) {
  350. $type_name = lang('unknown_type');
  351. }
  352. $res['type'][$k]['local_type_name'] = $type_name;
  353. }
  354. }
  355. $this->assign('page', $res['page']);
  356. $this->assign('type', $res['type']);
  357. $this->assign('list', $res['data']);
  358. $this->assign('total', $res['page']['recordcount']);
  359. $this->assign('page', $res['page']['page']);
  360. $this->assign('limit', $res['page']['pagesize']);
  361. $param['page'] = '{page}';
  362. $param['limit'] = '{limit}';
  363. $this->assign('param', $param);
  364. $this->assign('param_str', http_build_query($param));
  365. return $this->fetch('admin@collect/role');
  366. }
  367. mac_echo('<style type="text/css">body{font-size:12px;color: #333333;line-height:21px;}span{font-weight:bold;color:#FF0000}</style>');
  368. model('Collect')->role_data($param,$res );
  369. }
  370. public function website($param)
  371. {
  372. if ($param['ac'] != 'list') {
  373. $key = $GLOBALS['config']['app']['cache_flag']. '_'.'collect_break_website';
  374. Cache::set($key, url('collect/api') . '?' . http_build_query($param));
  375. }
  376. $res = model('Collect')->website($param);
  377. if ($res['code'] > 1) {
  378. return $this->error($res['msg']);
  379. }
  380. if ($param['ac'] == 'list') {
  381. $bind_list = config('bind');
  382. $type_list = model('Type')->getCache('type_list');
  383. foreach ($res['type'] as $k => $v) {
  384. $key = $param['cjflag'] . '_' . $v['type_id'];
  385. $res['type'][$k]['isbind'] = 0;
  386. $local_id = intval($bind_list[$key]);
  387. if ($local_id > 0) {
  388. $res['type'][$k]['isbind'] = 1;
  389. $res['type'][$k]['local_type_id'] = $local_id;
  390. $type_name = $type_list[$local_id]['type_name'];
  391. if (empty($type_name)) {
  392. $type_name = lang('unknown_type');
  393. }
  394. $res['type'][$k]['local_type_name'] = $type_name;
  395. }
  396. }
  397. $this->assign('page', $res['page']);
  398. $this->assign('type', $res['type']);
  399. $this->assign('list', $res['data']);
  400. $this->assign('total', $res['page']['recordcount']);
  401. $this->assign('page', $res['page']['page']);
  402. $this->assign('limit', $res['page']['pagesize']);
  403. $param['page'] = '{page}';
  404. $param['limit'] = '{limit}';
  405. $this->assign('param', $param);
  406. $this->assign('param_str', http_build_query($param));
  407. return $this->fetch('admin@collect/website');
  408. }
  409. mac_echo('<style type="text/css">body{font-size:12px;color: #333333;line-height:21px;}span{font-weight:bold;color:#FF0000}</style>');
  410. model('Collect')->website_data($param,$res );
  411. }
  412. }