Cj.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. use app\common\util\Collection as cjOper;
  5. class Cj extends Base
  6. {
  7. var $_isall=0;
  8. public function __construct()
  9. {
  10. parent::__construct();
  11. }
  12. //列表
  13. public function index()
  14. {
  15. $param = input();
  16. $param['page'] = intval($param['page']) <1 ? 1 : $param['page'];
  17. $param['limit'] = intval($param['limit']) <1 ? $this->_pagesize : $param['limit'];
  18. $where=[];
  19. $order='nodeid desc';
  20. $res = model('Cj')->listData('cj_node',$where,$order,$param['page'],$param['limit']);
  21. $this->assign('list',$res['list']);
  22. $this->assign('total',$res['total']);
  23. $this->assign('page',$res['page']);
  24. $this->assign('limit',$res['limit']);
  25. $param['page'] = '{page}';
  26. $param['limit'] = '{limit}';
  27. $this->assign('param',$param);
  28. $this->assign('title',lang('admin/cj/title'));
  29. return $this->fetch('admin@cj/index');
  30. }
  31. public function info()
  32. {
  33. if (Request()->isPost()) {
  34. $param = input();
  35. $data = $param['data'];
  36. $data['urlpage'] = $param['urlpage'.$data['sourcetype']];
  37. if(!empty($data['customize_config'])){
  38. $customize_config = $data['customize_config'];
  39. unset($data['customize_config']);
  40. foreach ($customize_config['name'] as $k => $v) {
  41. if (empty($v) || empty($customize_config['name'][$k])) continue;
  42. $data['customize_config'][] = array('name'=>$customize_config['name'][$k], 'en_name'=>$customize_config['en_name'][$k], 'rule'=>$customize_config['rule'][$k], 'html_rule'=>$customize_config['html_rule'][$k]);
  43. }
  44. $data['customize_config'] = json_encode($data['customize_config'],JSON_FORCE_OBJECT);
  45. }
  46. $res = model('Cj')->saveData($data);
  47. if($res['code']>1){
  48. return $this->error($res['msg']);
  49. }
  50. return $this->success($res['msg']);
  51. }
  52. $id = input('id');
  53. $where=[];
  54. $where['nodeid'] = ['eq',$id];
  55. $res = model('Cj')->infoData('cj_node',$where);
  56. if(!empty($res['info']['customize_config'])){
  57. $res['info']['customize_config'] = json_decode($res['info']['customize_config'],true);
  58. }
  59. $this->assign('data',$res['info']);
  60. $this->assign('title',lang('admin/cj/title'));
  61. return $this->fetch('admin@cj/info');
  62. }
  63. public function program()
  64. {
  65. $param = input();
  66. $where=[];
  67. $where['nodeid'] = $param['id'];
  68. $res = model('Cj')->infoData('cj_node',$where);
  69. if($res['code']>1){
  70. return $this->error($res['msg']);
  71. }
  72. if (Request()->isPost()) {
  73. $program_config = [];
  74. foreach($param['model_field'] as $k=>$v){
  75. if(!empty($param['node_field'][$k])){
  76. $program_config['map'][$v] = $param['node_field'][$k];
  77. $program_config['funcs'][$v] = $param['funcs'][$k];
  78. }
  79. }
  80. $update=[];
  81. $update['nodeid'] = $param['id'];
  82. $update['program_config'] = json_encode($program_config);
  83. $res = model('Cj')->saveData($update);
  84. if($res['code']>1){
  85. return $this->error(lang('save_err'));
  86. }
  87. return $this->success(lang('save_ok'));
  88. }
  89. $program_config = [];
  90. if(!empty($res['info']['program_config'])){
  91. $program_config = json_decode($res['info']['program_config'],true);
  92. }
  93. $this->assign('program_config',$program_config);
  94. $node_field = array('title'=>lang('title'),'type'=>lang('type'), 'content'=>lang('content'));
  95. $customize_config = [];
  96. if(!empty($res['info']['customize_config'])){
  97. $customize_config = json_decode($res['info']['customize_config'],true);
  98. }
  99. if (is_array($customize_config)) foreach ($customize_config as $k=>$v) {
  100. if (empty($v['en_name']) || empty($v['name'])) continue;
  101. $node_field[$v['en_name']] = $v['name'];
  102. }
  103. $this->assign('node_field',$node_field);
  104. $table = 'vod';
  105. if($res['info']['mid'] =='2'){
  106. $table='art';
  107. }
  108. $column_list = Db::query('SHOW COLUMNS FROM '.config('database.prefix').$table);
  109. $this->assign('column_list',$column_list);
  110. $this->assign('param',$param);
  111. return $this->fetch('admin@cj/program');
  112. }
  113. public function col_all($param)
  114. {
  115. $this->_isall=1;
  116. $this->col_url($param);
  117. }
  118. //采集网址
  119. public function col_url($param=[]) {
  120. if(empty($param)){
  121. $param = input();
  122. }
  123. $where=[];
  124. $where['nodeid'] = $param['id'];
  125. $res = model('Cj')->infoData('cj_node',$where);
  126. if($res['code']>1){
  127. return $this->error($res['msg']);
  128. }
  129. $data = $res['info'];
  130. $collection = new cjOper();
  131. $urls = $collection->url_list($data);
  132. $total_page = count($urls);
  133. if (empty($total_page)){
  134. return $this->error(lang('admin/cj/url_list_err'));
  135. }
  136. $param['page'] = isset($param['page']) ? intval($param['page']) : 1;
  137. $url_list = $urls[$param['page']-1];
  138. $url = $collection->get_url_lists($url_list, $data);
  139. $total = count($url);
  140. $re = 0;
  141. if (is_array($url) && !empty($url)) {
  142. foreach ($url as $v) {
  143. if (empty($v['url']) || empty($v['title'])) {
  144. $re++;
  145. continue;
  146. }
  147. $v['title'] = strip_tags($v['title']);
  148. $md5 = md5($v['url']);
  149. $where=[];
  150. $where['md5'] = $md5;
  151. $history = model('Cj')->infoData('cj_history',$where);
  152. if($history['code']>1){
  153. Db::name('cj_history')->insert(array('md5' => $md5));
  154. Db::name('cj_content')->insert(array('nodeid'=>$param['id'], 'status'=>1, 'url'=>$v['url'], 'title'=>$v['title']));
  155. }
  156. else {
  157. $re++;
  158. }
  159. }
  160. }
  161. if ($total_page <= $param['page']) {
  162. $time = time();
  163. Db::name('cj_node')->where('nodeid',$param['id'])->update(array('lastdate' => $time));
  164. }
  165. if($this->_isall==1){
  166. mac_echo(lang('admin/cj/url_cj_complete'));
  167. $this->col_content($param);
  168. exit;
  169. }
  170. $this->assign('param',$param);
  171. $this->assign('url_list', $url_list);
  172. $this->assign('total_page', $total_page);
  173. $this->assign('re', $re);
  174. $this->assign('url', $url);
  175. $this->assign('page',$param['page']);
  176. $this->assign('total',$total);
  177. $this->assign('title',lang('admin/cj/url/title'));
  178. if($total_page > $param['page']){
  179. mac_echo(lang('server_rest'));
  180. $param['page'] ++;
  181. $link = url('cj/col_url') . '?'. http_build_query($param);
  182. mac_jump( $link ,3);
  183. }
  184. else{
  185. mac_echo(lang('admin/cj/url_cj_complete'));
  186. }
  187. return $this->fetch('admin@cj/col_url');
  188. }
  189. //采集文章
  190. public function col_content($param=[]) {
  191. if(empty($param)){
  192. $param = input();
  193. }
  194. $collection = new cjOper();
  195. $page = isset($_GET['page']) ? intval($_GET['page']) : 1;
  196. $total = isset($_GET['total']) ? intval($_GET['total']) : 0;
  197. $where=[];
  198. $where['nodeid'] = $param['id'];
  199. $res = model('Cj')->infoData('cj_node',$where);
  200. if($res['code']>1){
  201. return $this->error($res['msg']);
  202. }
  203. $data = $res['info'];
  204. mac_echo('<style type="text/css">body{font-size:12px;color: #333333;line-height:21px;}span{font-weight:bold;color:#FF0000}</style>');
  205. if(empty($total)){
  206. $total = Db::name('cj_content')->where('nodeid',$param['id'])->where('status',1)->count();
  207. }
  208. $limit = 20;
  209. $total_page = ceil($total/$limit);
  210. mac_echo(lang('admin/cj/content/tip',[$total,$total_page,$limit,$page]));
  211. $list = Db::name('cj_content')->where('nodeid',$param['id'])->where('status',1)->page($total_page-1,$limit)->select();
  212. $i = 0;
  213. $ids=[];
  214. if(!empty($list) && is_array($list)){
  215. foreach($list as $v){
  216. $html = $collection->get_content($v['url'],$data);
  217. Db::name('cj_content')->where('id',$v['id'])->update(['status'=>2, 'data'=>json_encode($html)]);
  218. $ids[] = $v['id'];
  219. $i++;
  220. mac_echo($v['url'].'&nbsp;&nbsp;'.'ok');
  221. }
  222. }
  223. else{
  224. mac_echo(lang('admin/cj/content_cj_complete'));
  225. exit;
  226. }
  227. if($this->_isall==1){
  228. mac_echo(lang('admin/cj/content_cj_complete'));
  229. $param['ids'] = implode(',',$ids);
  230. $param['limit'] = 999;
  231. $this->content_into($param);
  232. exit;
  233. }
  234. if ($total_page > $page){
  235. mac_echo(lang('server_rest'));
  236. $param['page'] ++;
  237. $link = url('cj/col_content') . '?'. http_build_query($param);
  238. mac_jump( $link ,3);
  239. }
  240. else{
  241. $time = time();
  242. Db::name('cj_node')->where('nodeid',$param['id'])->update(array('lastdate' => $time));
  243. mac_echo(lang('admin/cj/cj_complete'));
  244. exit;
  245. }
  246. }
  247. public function publish()
  248. {
  249. $param = input();
  250. $param['page'] = intval($param['page']) <1 ? 1 : $param['page'];
  251. $param['limit'] = intval($param['limit']) <20 ? $this->_pagesize : $param['limit'];
  252. $where=[];
  253. $where['nodeid'] = $param['id'];
  254. if(!empty($param['status'])){
  255. $where['status'] = ['eq',$param['status']];
  256. }
  257. $order='id desc';
  258. $res = model('Cj')->listData('cj_content',$where,$order,$param['page'],$param['limit']);
  259. $this->assign('list',$res['list']);
  260. $this->assign('total',$res['total']);
  261. $this->assign('page',$res['page']);
  262. $this->assign('limit',$res['limit']);
  263. $param['page'] = '{page}';
  264. $param['limit'] = '{limit}';
  265. $this->assign('param',$param);
  266. $this->assign('title',lang('admin/cj/publish/title'));
  267. return $this->fetch('admin@cj/publish');
  268. }
  269. public function show()
  270. {
  271. $id = input('id');
  272. $where=[];
  273. $where['id'] = ['eq',$id];
  274. $info = Db::name('cj_content')->where($where)->find();
  275. if(!empty($info['data'])){
  276. $info['data'] = @json_decode($info['data'],true);
  277. }
  278. $this->assign('info',$info);
  279. $this->assign('title',lang('admin/cj/title'));
  280. return $this->fetch('admin@cj/show');
  281. }
  282. public function content_del()
  283. {
  284. $param = input();
  285. $ids = $param['ids'];
  286. $all = $param['all'];
  287. if(!empty($ids)){
  288. $where=[];
  289. $where['id'] = ['in',$ids];
  290. if($all=='1'){
  291. $where['id'] = ['gt',0];
  292. }
  293. $urls = [];
  294. $list = Db::name('cj_content')->field('url')->where($where)->select();
  295. foreach ($list as $k => $v) {
  296. $md5 = md5($v['url']);
  297. $urls[] = $md5;
  298. }
  299. $where2=[];
  300. $where2['md5'] = ['in',$md5];
  301. Db::name('cj_history')->where($where2)->delete();
  302. $res = Db::name('cj_content')->where($where)->delete();
  303. if($res===false){
  304. return $this->error(lang('del_err').''.$this->getError());
  305. }
  306. }
  307. return $this->success(lang('del_ok'));
  308. }
  309. public function content_into($param=[])
  310. {
  311. if(empty($param)){
  312. $param = input();
  313. }
  314. $nodeid = $param['id'];
  315. $ids = $param['ids'];
  316. $all = $param['all'];
  317. $param['page'] = intval($param['page']) <1 ? 1 : $param['page'];
  318. $param['limit'] = intval($param['limit']) <20 ? $this->_pagesize : $param['limit'];
  319. $where=[];
  320. $where['nodeid'] = $param['id'];
  321. $res = model('Cj')->infoData('cj_node',$where);
  322. if($res['code']>1){
  323. return $this->error($res['msg']);
  324. }
  325. $node = $res['info'];
  326. $where=[];
  327. $where['nodeid'] = $nodeid;
  328. $where['status'] =['eq',2];
  329. $where['id'] = ['in',$ids];
  330. if($all=='1'){
  331. $where['id'] = ['gt',0];
  332. }
  333. mac_echo('<style type="text/css">body{font-size:12px;color: #333333;line-height:21px;}span{font-weight:bold;color:#FF0000}</style>');
  334. if(empty($param['total'])) {
  335. $param['total'] = Db::name('cj_content')->where($where)->count();
  336. }
  337. $list = Db::name('cj_content')->where($where)->page($param['page'],$param['limit'])->select();
  338. $total_page = ceil($param['total']/$param['limit']);
  339. mac_echo(lang('admin/cj/content_into/tip',[$param['total'],$total_page,$param['limit'],$param['page']]));
  340. $program_config =[];
  341. if(!empty($node['program_config'])){
  342. $program_config = json_decode($node['program_config'],true);
  343. }
  344. $inter = mac_interface_type();
  345. $update_ids = [];
  346. foreach($list as $k=>$v){
  347. $data=[];
  348. $content_data = json_decode($v['data'],true);
  349. foreach ($program_config['map'] as $a=>$b) {
  350. if (isset($program_config['funcs'][$a]) && function_exists($program_config['funcs'][$a])) {
  351. $data['data'][$k][$a] = $program_config['funcs'][$a]($v['data'][$b]);
  352. }
  353. else {
  354. $data['data'][$k][$a] = $content_data[$b];
  355. }
  356. if($b=='type' && !is_numeric($content_data[$b])) {
  357. if($node['mid'] ==2 ) {
  358. $data['data'][$k][$a] = $inter['arttype'][$content_data[$b]];
  359. }
  360. else{
  361. $data['data'][$k][$a] = $inter['vodtype'][$content_data[$b]];
  362. }
  363. }
  364. }
  365. if($node['mid'] == '2'){
  366. $res = model('Collect')->art_data([],$data,0);
  367. }
  368. else{
  369. $res = model('Collect')->vod_data([],$data,0);
  370. }
  371. if($res['code'] ==1){
  372. $update_ids[] = $v['id'];
  373. }
  374. mac_echo($res['msg']);
  375. }
  376. if(!empty($update_ids)){
  377. $where=[];
  378. $where['id'] = ['in',$update_ids];
  379. $res = Db::name('cj_content')->where($where)->update(['status' => 3]);
  380. }
  381. if($this->_isall==1){
  382. mac_echo(lang('admin/cj/content_into/complete'));
  383. exit;
  384. }
  385. if ($total_page > $param['page']){
  386. mac_echo(lang('server_rest'));
  387. $param['page'] ++;
  388. $link = url('cj/content_into') . '?'. http_build_query($param);
  389. mac_jump( $link ,3);
  390. }
  391. else{
  392. mac_echo(lang('import_ok'));
  393. exit;
  394. }
  395. }
  396. //序列网址测试
  397. public function show_url()
  398. {
  399. $param = input();
  400. $data = $param['data'];
  401. $data['urlpage'] = $param['urlpage'.$data['sourcetype']];
  402. $collection = new cjOper();
  403. $urls = $collection->url_list($data);
  404. $this->assign('urls',$urls);
  405. return $this->fetch('admin@cj/show_url');
  406. }
  407. public function del()
  408. {
  409. $param = input();
  410. $ids = $param['ids'];
  411. if(!empty($ids)){
  412. $where=[];
  413. $where['nodeid'] = ['in',$ids];
  414. $res = model('Cj')->delData($where);
  415. if($res['code']>1){
  416. return $this->error($res['msg']);
  417. }
  418. return $this->success($res['msg']);
  419. }
  420. return $this->error(lang('param_err'));
  421. }
  422. public function export()
  423. {
  424. $param = input();
  425. $where=[];
  426. $where['nodeid'] = $param['id'];
  427. $res = model('Cj')->infoData('cj_node',$where);
  428. if($res['code']>1){
  429. return $this->error($res['msg']);
  430. }
  431. $node = $res['info'];
  432. header("Content-type: application/octet-stream");
  433. if(strpos($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
  434. header("Content-Disposition: attachment; filename=mac_cj_" . urlencode($node['name']) . '.txt');
  435. }
  436. else{
  437. header("Content-Disposition: attachment; filename=mac_cj_" . $node['name'] . '.txt');
  438. }
  439. echo base64_encode(json_encode($node));
  440. }
  441. public function import()
  442. {
  443. $file = $this->request->file('file');
  444. $info = $file->rule('uniqid')->validate(['size' => 10240000, 'ext' => 'txt']);
  445. if ($info) {
  446. $data = json_decode(base64_decode(file_get_contents($info->getpathName())), true);
  447. @unlink($info->getpathName());
  448. if($data){
  449. unset($data['nodeid']);
  450. $res = model('Cj')->saveData($data);
  451. if($res['code']>1){
  452. return $this->success($res['msg']);
  453. }
  454. return $this->success($res['msg']);
  455. }
  456. return $this->success(lang('import_err'));
  457. }
  458. else{
  459. return $this->error($file->getError());
  460. }
  461. }
  462. }