Manga.php 12 KB

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