Manga.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. use app\common\util\Pinyin;
  5. class Manga 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['manga_level'] = ['eq', $param['level']];
  22. }
  23. if (in_array($param['status'], ['0', '1'])) {
  24. $where['manga_status'] = ['eq', $param['status']];
  25. }
  26. if (!empty($param['lock'])) {
  27. $where['manga_lock'] = ['eq', $param['lock']];
  28. }
  29. if(!empty($param['pic'])){
  30. if($param['pic'] == '1'){
  31. $where['manga_pic'] = ['eq',''];
  32. }
  33. elseif($param['pic'] == '2'){
  34. $where['manga_pic'] = ['like','http%'];
  35. }
  36. elseif($param['pic'] == '3'){
  37. $where['manga_pic'] = ['like','%#err%'];
  38. }
  39. }
  40. if(!empty($param['wd'])){
  41. $param['wd'] = urldecode($param['wd']);
  42. $param['wd'] = mac_filter_xss($param['wd']);
  43. $where['manga_name'] = ['like','%'.$param['wd'].'%'];
  44. }
  45. if (!empty($param['recycle'])) {
  46. $where['manga_recycle_time'] = ['>', 0];
  47. }
  48. if(!empty($param['url'])){
  49. if($param['url'] == '1'){
  50. $where['manga_chapter_url'] = ['eq',''];
  51. }
  52. }
  53. if(!empty($param['points'])){
  54. if($param['points'] == '1'){
  55. $where['manga_points'] = ['gt',0];
  56. }
  57. }
  58. if(!empty($param['repeat'])){
  59. if($param['page'] ==1){
  60. Db::execute('DROP TABLE IF EXISTS '.config('database.prefix').'tmpmanga');
  61. Db::execute('CREATE TABLE `'.config('database.prefix').'tmpmanga` (`id1` int unsigned DEFAULT NULL, `name1` varchar(1024) NOT NULL DEFAULT \'\') ENGINE=MyISAM');
  62. Db::execute('INSERT INTO `'.config('database.prefix').'tmpmanga` (SELECT min(manga_id)as id1,manga_name as name1 FROM '.config('database.prefix').'manga WHERE manga_recycle_time = 0 GROUP BY name1 HAVING COUNT(name1)>1)');
  63. }
  64. $order='manga_name asc';
  65. $res = model('Manga')->listRepeatData($where,$order,$param['page'],$param['limit']);
  66. }
  67. else{
  68. $order='manga_time desc';
  69. $res = model('Manga')->listData($where,$order,$param['page'],$param['limit']);
  70. }
  71. foreach($res['list'] as $k=>&$v){
  72. $v['ismake'] = 1;
  73. if($GLOBALS['config']['view']['manga_detail'] >0 && $v['manga_time_make'] < $v['manga_time']){
  74. $v['ismake'] = 0;
  75. }
  76. }
  77. $this->assign('list', $res['list']);
  78. $this->assign('total', $res['total']);
  79. $this->assign('page', $res['page']);
  80. $this->assign('limit', $res['limit']);
  81. $param['page'] = '{page}';
  82. $param['limit'] = '{limit}';
  83. $this->assign('param', $param);
  84. $type_tree = model('Type')->getCache('type_tree');
  85. $this->assign('type_tree', $type_tree);
  86. $this->assign('title', lang('admin/manga/title'));
  87. return $this->fetch('admin@manga/index');
  88. }
  89. public function batch()
  90. {
  91. $param = input();
  92. if (!empty($param)) {
  93. mac_echo('<style type="text/css">body{font-size:12px;color: #333333;line-height:21px;}span{font-weight:bold;color:#FF0000}</style>');
  94. if(empty($param['ck_del']) && empty($param['ck_level']) && empty($param['ck_status']) && empty($param['ck_lock']) && empty($param['ck_hits']) && empty($param['ck_replace']) ){
  95. return $this->error(lang('param_err'));
  96. }
  97. $where = $this->mangaBatchFilterWhere($param);
  98. if($param['ck_del'] == 1){
  99. $res = model('Manga')->recycleData($where);
  100. mac_echo($res['code'] == 1 ? lang('recycle_ok') : $res['msg']);
  101. mac_jump( url('manga/batch') ,3);
  102. exit;
  103. }
  104. if($param['ck_del'] == 4){
  105. $res = model('Manga')->delData($where);
  106. mac_echo(lang('multi_del_ok'));
  107. mac_jump( url('manga/batch') ,3);
  108. exit;
  109. }
  110. if(empty($param['page'])){
  111. $param['page'] = 1;
  112. }
  113. if(empty($param['limit'])){
  114. $param['limit'] = 100;
  115. }
  116. if(empty($param['total'])) {
  117. $param['total'] = model('Manga')->countData($where);
  118. $param['page_count'] = ceil($param['total'] / $param['limit']);
  119. }
  120. if($param['page'] > $param['page_count']) {
  121. mac_echo(lang('multi_set_ok'));
  122. mac_jump( url('manga/batch') ,3);
  123. exit;
  124. }
  125. mac_echo( "<font color=red>".lang('admin/batch_tip',[$param['total'],$param['limit'],$param['page_count'],$param['page']])."</font>");
  126. $page = $param['page_count'] - $param['page'] + 1;
  127. $order='manga_id desc';
  128. $res = model('Manga')->listData($where,$order,$page,$param['limit']);
  129. foreach($res['list'] as $k=>$v){
  130. $where2 = [];
  131. $where2['manga_id'] = $v['manga_id'];
  132. $update = [];
  133. $des = $v['manga_id'].','.$v['manga_name'];
  134. if(!empty($param['ck_level']) && !empty($param['val_level'])){
  135. $update['manga_level'] = $param['val_level'];
  136. $des .= '&nbsp;'.lang('level').':'.$param['val_level'].';';
  137. }
  138. if(!empty($param['ck_status']) && isset($param['val_status'])){
  139. $update['manga_status'] = $param['val_status'];
  140. $des .= '&nbsp;'.lang('status').':'.($param['val_status'] ==1 ? '['.lang('reviewed').']':'['.lang('reviewed_not').']') .';';
  141. }
  142. if(!empty($param['ck_lock']) && isset($param['val_lock'])){
  143. $update['manga_lock'] = $param['val_lock'];
  144. $des .= '&nbsp;'.lang('lock').':'.($param['val_lock']==1 ? '['.lang('lock').']':'['.lang('unlock').']').';';
  145. }
  146. if(!empty($param['ck_hits']) && !empty($param['val_hits_min']) && !empty($param['val_hits_max']) ){
  147. $update['manga_hits'] = rand($param['val_hits_min'],$param['val_hits_max']);
  148. $des .= '&nbsp;'.lang('hits').':'.$update['manga_hits'].';';
  149. }
  150. // 新增:批量替换功能
  151. if(!empty($param['ck_replace']) && !empty($param['replace_field']) && isset($param['replace_search'])){
  152. $field = $param['replace_field'];
  153. $replaceres = $this->batch_replace($field,$v,$param['replace_search'],$param['replace_with'],'manga');
  154. if(isset($replaceres[$field])) $update[$field] = $replaceres[$field];
  155. if(!empty($replaceres['des'])) $des .= $replaceres['des'];
  156. }
  157. mac_echo($des);
  158. $res2 = model('Manga')->where($where2)->update($update);
  159. }
  160. $param['page']++;
  161. $url = url('manga/batch') .'?'. http_build_query($param);
  162. mac_jump( $url ,3);
  163. exit;
  164. }
  165. $type_tree = model('Type')->getCache('type_tree');
  166. $this->assign('type_tree',$type_tree);
  167. $this->assign('title',lang('admin/manga/title'));
  168. return $this->fetch('admin@manga/batch');
  169. }
  170. private function mangaBatchFilterWhere(&$param)
  171. {
  172. $where = [];
  173. if (!empty($param['type'])) {
  174. $where['type_id'] = ['eq', $param['type']];
  175. }
  176. if (!empty($param['level'])) {
  177. $where['manga_level'] = ['eq', $param['level']];
  178. }
  179. if (in_array($param['status'] ?? '', ['0', '1'])) {
  180. $where['manga_status'] = ['eq', $param['status']];
  181. }
  182. if (!empty($param['lock'])) {
  183. $where['manga_lock'] = ['eq', $param['lock']];
  184. }
  185. if (!empty($param['pic'])) {
  186. if ($param['pic'] == '1') {
  187. $where['manga_pic'] = ['eq', ''];
  188. } elseif ($param['pic'] == '2') {
  189. $where['manga_pic'] = ['like', 'http%'];
  190. } elseif ($param['pic'] == '3') {
  191. $where['manga_pic'] = ['like', '%#err%'];
  192. }
  193. }
  194. if (!empty($param['wd'])) {
  195. $param['wd'] = htmlspecialchars(urldecode($param['wd']));
  196. $where['manga_name'] = ['like', '%' . $param['wd'] . '%'];
  197. }
  198. if (!empty($param['recycle'])) {
  199. $where['manga_recycle_time'] = ['>', 0];
  200. }
  201. return $where;
  202. }
  203. public function exportData()
  204. {
  205. $param = input();
  206. $where = $this->mangaBatchFilterWhere($param);
  207. $this->base_export($param,'manga',$where);
  208. }
  209. public function importData()
  210. {
  211. $this->base_import('manga');
  212. }
  213. public function info()
  214. {
  215. if (Request()->isPost()) {
  216. $param = input('post.');
  217. $res = model('Manga')->saveData($param);
  218. if($res['code']>1){
  219. return $this->error($res['msg']);
  220. }
  221. return $this->success($res['msg']);
  222. }
  223. $id = input('id');
  224. $where=[];
  225. $where['manga_id'] = ['eq',$id];
  226. $where['_recycle'] = 'all';
  227. $res = model('Manga')->infoData($where);
  228. $info = $res['info'];
  229. if (empty($info)) {
  230. $info = [];
  231. }
  232. $this->assign('info',$info);
  233. $this->assign('manga_page_list', !empty($info['manga_page_list']) ? (array)$info['manga_page_list'] : []);
  234. $type_tree = model('Type')->getCache('type_tree');
  235. $this->assign('type_tree',$type_tree);
  236. $this->assign('title',lang('admin/manga/title'));
  237. return $this->fetch('admin@manga/info');
  238. }
  239. public function restore()
  240. {
  241. $param = input();
  242. $ids = $param['ids'];
  243. if (empty($ids)) {
  244. return $this->error(lang('param_err'));
  245. }
  246. $where = ['manga_id' => ['in', $ids]];
  247. $res = model('Manga')->restoreData($where);
  248. if ($res['code'] > 1) {
  249. return $this->error($res['msg']);
  250. }
  251. return $this->success($res['msg']);
  252. }
  253. public function del()
  254. {
  255. $param = input();
  256. $ids = $param['ids'];
  257. $purge = !empty($param['purge']);
  258. if(!empty($ids)){
  259. $where=[];
  260. $where['manga_id'] = ['in',$ids];
  261. if ($purge) {
  262. $res = model('Manga')->delData($where);
  263. } else {
  264. $res = model('Manga')->recycleData($where);
  265. }
  266. if($res['code']>1){
  267. return $this->error($res['msg']);
  268. }
  269. return $this->success($res['msg']);
  270. }
  271. elseif(!empty($param['repeat'])){
  272. $st = ' not in ';
  273. if($param['retain']=='max'){
  274. $st=' in ';
  275. }
  276. $sql = 'delete from '.config('database.prefix').'manga where manga_name in(select name1 from '.config('database.prefix').'tmpmanga) and manga_id '.$st.'(select id1 from '.config('database.prefix').'tmpmanga)';
  277. $res = model('Manga')->execute($sql);
  278. if($res===false){
  279. return $this->success(lang('del_err'));
  280. }
  281. return $this->success(lang('del_ok'));
  282. }
  283. return $this->error(lang('param_err'));
  284. }
  285. public function field()
  286. {
  287. $param = input();
  288. $ids = $param['ids'];
  289. $col = $param['col'];
  290. $val = $param['val'];
  291. $start = $param['start'];
  292. $end = $param['end'];
  293. if ($col == 'type_id' && $val==''){
  294. return $this->error("请选择分类提交");
  295. }
  296. if(!empty($ids) && in_array($col,['manga_status','manga_lock','manga_level','manga_hits','type_id'])){
  297. $where=[];
  298. $where['manga_id'] = ['in',$ids];
  299. $update = [];
  300. if(empty($start)) {
  301. $update[$col] = $val;
  302. if($col == 'type_id'){
  303. $type_list = model('Type')->getCache();
  304. $id1 = intval($type_list[$val]['type_pid']);
  305. $update['type_id_1'] = $id1;
  306. }
  307. $res = model('Manga')->fieldData($where, $update);
  308. }
  309. else{
  310. if(empty($end)){$end = 9999;}
  311. $ids = explode(',',$ids);
  312. foreach($ids as $k=>$v){
  313. $val = rand($start,$end);
  314. $where['manga_id'] = ['eq',$v];
  315. $update[$col] = $val;
  316. $res = model('Manga')->fieldData($where, $update);
  317. }
  318. }
  319. if($res['code']>1){
  320. return $this->error($res['msg']);
  321. }
  322. return $this->success($res['msg']);
  323. }
  324. return $this->error(lang('param_err'));
  325. }
  326. public function updateToday()
  327. {
  328. $param = input();
  329. $flag = $param['flag'];
  330. $res = model('Manga')->updateToday($flag);
  331. return json($res);
  332. }
  333. public function batchGenerateTag()
  334. {
  335. $ids = input('post.ids/a');
  336. if(empty($ids)){
  337. return json(['code'=>0,'msg'=>lang('admin/tag/select_manga_tag')]);
  338. }
  339. $success = 0;
  340. $fail = 0;
  341. foreach($ids as $id){
  342. $info = model('Manga')->where('manga_id',$id)->find();
  343. if($info){
  344. $tag = mac_get_tag($info['manga_name'], $info['manga_content']);
  345. if($tag !== false){
  346. $res = model('Manga')->where('manga_id',$id)->update(['manga_tag'=>$tag]);
  347. if($res){
  348. $success++;
  349. }else{
  350. $fail++;
  351. }
  352. }else{
  353. $fail++;
  354. }
  355. }
  356. }
  357. return json(['code'=>1,'msg'=>sprintf(lang('admin/tag/generate_tag_result'), $success, $fail)]);
  358. }
  359. }