Manga.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. use think\Cache;
  5. use app\common\util\Pinyin;
  6. class Manga extends Base {
  7. use RecycleBinTrait;
  8. // 设置数据表(不含前缀)
  9. protected $name = 'manga';
  10. protected function getRecycleTimeField(): string
  11. {
  12. return 'manga_recycle_time';
  13. }
  14. // 定义时间戳字段名
  15. protected $createTime = '';
  16. protected $updateTime = '';
  17. // 自动完成
  18. protected $auto = [];
  19. protected $insert = [];
  20. protected $update = [];
  21. public function getMangaStatusTextAttr($val,$data)
  22. {
  23. $arr = [0=>lang('disable'),1=>lang('enable')];
  24. return $arr[$data['manga_status']];
  25. }
  26. public function getMangaContentTextAttr($val,$data)
  27. {
  28. $arr = explode('$$$',$data['manga_content']);
  29. return $arr;
  30. }
  31. public function countData($where)
  32. {
  33. $this->ensureRecycleColumnExists();
  34. if(!is_array($where)){
  35. $where = json_decode($where,true);
  36. }
  37. $where = $this->mergeRecycleWhere($where);
  38. $total = $this->where($where)->count();
  39. return $total;
  40. }
  41. public function listData($where,$order,$page=1,$limit=20,$start=0,$field='*',$addition=1,$totalshow=1)
  42. {
  43. $this->ensureRecycleColumnExists();
  44. $page = $page > 0 ? (int)$page : 1;
  45. $limit = $limit ? (int)$limit : 20;
  46. $start = $start ? (int)$start : 0;
  47. if(!is_array($where)){
  48. $where = json_decode($where,true);
  49. }
  50. $where = $this->mergeRecycleWhere($where);
  51. $where2='';
  52. if(!empty($where['_string'])){
  53. $where2 = $where['_string'];
  54. unset($where['_string']);
  55. }
  56. $limit_str = ($limit * ($page-1) + $start) .",". $limit;
  57. if($totalshow==1) {
  58. $total = $this->where($where)->count();
  59. }
  60. $list = Db::name('Manga')->field($field)->where($where)->where($where2)->order($order)->limit($limit_str)->select();
  61. //dump($where);die;
  62. //echo $this->getLastSql();die;
  63. //分类
  64. $type_list = model('Type')->getCache('type_list');
  65. //用户组
  66. $group_list = model('Group')->getCache('group_list');
  67. foreach($list as $k=>$v){
  68. if($addition==1){
  69. if(!empty($v['type_id'])) {
  70. $list[$k]['type'] = $type_list[$v['type_id']];
  71. $list[$k]['type_1'] = $type_list[$list[$k]['type']['type_pid']];
  72. }
  73. if(!empty($v['group_id'])) {
  74. $list[$k]['group'] = $group_list[$v['group_id']];
  75. }
  76. }
  77. }
  78. return ['code'=>1,'msg'=>lang('data_list'),'page'=>$page,'pagecount'=>ceil($total/$limit),'limit'=>$limit,'total'=>$total,'list'=>$list];
  79. }
  80. public function listRepeatData($where,$order,$page=1,$limit=20,$start=0,$field='*',$addition=1)
  81. {
  82. $this->ensureRecycleColumnExists();
  83. $page = $page > 0 ? (int)$page : 1;
  84. $limit = $limit ? (int)$limit : 20;
  85. $start = $start ? (int)$start : 0;
  86. if(!is_array($where)){
  87. $where = json_decode($where,true);
  88. }
  89. $where = $this->mergeRecycleWhere($where);
  90. $limit_str = ($limit * ($page-1) + $start) .",". $limit;
  91. $total = $this
  92. ->join('tmpmanga t','t.name1 = manga_name')
  93. ->where($where)
  94. ->count();
  95. $list = Db::name('Manga')
  96. ->join('tmpmanga t','t.name1 = manga_name')
  97. ->field($field)
  98. ->where($where)
  99. ->order($order)
  100. ->limit($limit_str)
  101. ->select();
  102. //dump($where);die;
  103. //echo $this->getLastSql();die;
  104. //分类
  105. $type_list = model('Type')->getCache('type_list');
  106. //用户组
  107. $group_list = model('Group')->getCache('group_list');
  108. foreach($list as $k=>$v){
  109. if($addition==1){
  110. if(!empty($v['type_id'])) {
  111. $list[$k]['type'] = $type_list[$v['type_id']];
  112. $list[$k]['type_1'] = $type_list[$list[$k]['type']['type_pid']];
  113. }
  114. if(!empty($v['group_id'])) {
  115. $list[$k]['group'] = $group_list[$v['group_id']];
  116. }
  117. }
  118. }
  119. return ['code'=>1,'msg'=>lang('data_list'),'page'=>$page,'pagecount'=>ceil($total/$limit),'limit'=>$limit,'total'=>$total,'list'=>$list];
  120. }
  121. public function listCacheData($lp)
  122. {
  123. if (!is_array($lp)) {
  124. $lp = json_decode($lp, true);
  125. }
  126. $order = $lp['order'];
  127. $by = $lp['by'];
  128. $type = $lp['type'];
  129. $ids = $lp['ids'];
  130. $rel = $lp['rel'];
  131. $paging = $lp['paging'];
  132. $pageurl = $lp['pageurl'];
  133. $level = $lp['level'];
  134. $wd = $lp['wd'];
  135. $tag = $lp['tag'];
  136. $class = $lp['class'];
  137. $letter = $lp['letter'];
  138. $start = intval(abs($lp['start']));
  139. $num = intval(abs($lp['num']));
  140. $half = intval(abs($lp['half']));
  141. $timeadd = $lp['timeadd'];
  142. $timehits = $lp['timehits'];
  143. $time = $lp['time'];
  144. $hitsmonth = $lp['hitsmonth'];
  145. $hitsweek = $lp['hitsweek'];
  146. $hitsday = $lp['hitsday'];
  147. $hits = $lp['hits'];
  148. $not = $lp['not'];
  149. $cachetime = $lp['cachetime'];
  150. $typenot = $lp['typenot'];
  151. $name = $lp['name'];
  152. $page = 1;
  153. $where = [];
  154. $totalshow=0;
  155. if(empty($num)){
  156. $num = 20;
  157. }
  158. if($start>1){
  159. $start--;
  160. }
  161. if(!in_array($paging, ['yes', 'no'])) {
  162. $paging = 'no';
  163. }
  164. $param = mac_param_url();
  165. if($paging=='yes') {
  166. $param = mac_search_len_check($param);
  167. $totalshow = 1;
  168. if(!empty($param['id'])) {
  169. //$type = intval($param['id']);
  170. }
  171. if(!empty($param['ids'])){
  172. $ids = $param['ids'];
  173. }
  174. if(!empty($param['tid'])) {
  175. $tid = intval($param['tid']);
  176. }
  177. if(!empty($param['level'])) {
  178. $level = $param['level'];
  179. }
  180. if(!empty($param['letter'])) {
  181. $letter = $param['letter'];
  182. }
  183. if(!empty($param['wd'])) {
  184. $wd = $param['wd'];
  185. }
  186. if(!empty($param['name'])) {
  187. $name = $param['name'];
  188. }
  189. if(!empty($param['tag'])) {
  190. $tag = $param['tag'];
  191. }
  192. if(!empty($param['class'])) {
  193. $class = $param['class'];
  194. }
  195. if(!empty($param['by'])){
  196. $by = $param['by'];
  197. }
  198. if(!empty($param['order'])){
  199. $order = $param['order'];
  200. }
  201. if(!empty($param['page'])){
  202. $page = intval($param['page']);
  203. }
  204. foreach($param as $k=>$v){
  205. if(empty($v)){
  206. unset($param[$k]);
  207. }
  208. }
  209. if(empty($pageurl)){
  210. $pageurl = 'manga/type';
  211. }
  212. $param['page'] = 'PAGELINK';
  213. if($pageurl=='manga/type' || $pageurl=='manga/show'){
  214. $type = intval( $GLOBALS['type_id'] );
  215. $type_list = model('Type')->getCache('type_list');
  216. $type_info = $type_list[$type];
  217. $flag='type';
  218. if($pageurl == 'manga/show'){
  219. $flag='show';
  220. }
  221. $pageurl = mac_url_type($type_info,$param,$flag);
  222. }
  223. else{
  224. $pageurl = mac_url($pageurl,$param);
  225. }
  226. }
  227. $where['manga_status'] = ['eq',1];
  228. if(!empty($level)) {
  229. if($level=='all'){
  230. $level = '1,2,3,4,5,6,7,8,9';
  231. }
  232. $where['manga_level'] = ['in',explode(',',$level)];
  233. }
  234. if(!empty($ids)) {
  235. if($ids!='all'){
  236. $where['manga_id'] = ['in',explode(',',$ids)];
  237. }
  238. }
  239. if(!empty($not)){
  240. $where['manga_id'] = ['not in',explode(',',$not)];
  241. }
  242. if(!empty($rel)){
  243. $tmp = explode(',',$rel);
  244. if(is_numeric($rel) || mac_array_check_num($tmp)==true ){
  245. $where['manga_id'] = ['in',$tmp];
  246. }
  247. else{
  248. $where['manga_rel_manga'] = ['like', mac_like_arr($rel),'OR'];
  249. }
  250. }
  251. if(!empty($letter)){
  252. if(substr($letter,0,1)=='0' && substr($letter,2,1)=='9'){
  253. $letter='0,1,2,3,4,5,6,7,8,9';
  254. }
  255. $where['manga_letter'] = ['in',explode(',',$letter)];
  256. }
  257. if(!empty($timeadd)){
  258. $s = intval(strtotime($timeadd));
  259. $where['manga_time_add'] =['gt',$s];
  260. }
  261. if(!empty($timehits)){
  262. $s = intval(strtotime($timehits));
  263. $where['manga_time_hits'] =['gt',$s];
  264. }
  265. if(!empty($time)){
  266. $s = intval(strtotime($time));
  267. $where['manga_time'] =['gt',$s];
  268. }
  269. if(!empty($type)) {
  270. if($type=='current'){
  271. $type = intval( $GLOBALS['type_id'] );
  272. }
  273. if($type!='all') {
  274. $tmp_arr = explode(',', $type);
  275. $type_list = model('Type')->getCache('type_list');
  276. $type = [];
  277. foreach ($type_list as $k2 => $v2) {
  278. if (in_array($v2['type_id'] . '', $tmp_arr) || in_array($v2['type_pid'] . '', $tmp_arr)) {
  279. $type[] = $v2['type_id'];
  280. }
  281. }
  282. $type = array_unique($type);
  283. $where['type_id'] = ['in', implode(',', $type)];
  284. }
  285. }
  286. if(!empty($typenot)){
  287. $where['type_id'] = ['not in',$typenot];
  288. }
  289. if(!empty($tid)) {
  290. $where['type_id|type_id_1'] = ['eq',$tid];
  291. }
  292. if(!empty($hitsmonth)){
  293. $tmp = explode(' ',$hitsmonth);
  294. if(count($tmp)==1){
  295. $where['manga_hits_month'] = ['gt', $tmp];
  296. }
  297. else{
  298. $where['manga_hits_month'] = [$tmp[0],$tmp[1]];
  299. }
  300. }
  301. if(!empty($hitsweek)){
  302. $tmp = explode(' ',$hitsweek);
  303. if(count($tmp)==1){
  304. $where['manga_hits_week'] = ['gt', $tmp];
  305. }
  306. else{
  307. $where['manga_hits_week'] = [$tmp[0],$tmp[1]];
  308. }
  309. }
  310. if(!empty($hitsday)){
  311. $tmp = explode(' ',$hitsday);
  312. if(count($tmp)==1){
  313. $where['manga_hits_day'] = ['gt', $tmp];
  314. }
  315. else{
  316. $where['manga_hits_day'] = [$tmp[0],$tmp[1]];
  317. }
  318. }
  319. if(!empty($hits)){
  320. $tmp = explode(' ',$hits);
  321. if(count($tmp)==1){
  322. $where['manga_hits'] = ['gt', $tmp];
  323. }
  324. else{
  325. $where['manga_hits'] = [$tmp[0],$tmp[1]];
  326. }
  327. }
  328. if(!empty($wd)) {
  329. $role = 'manga_name';
  330. if(!empty($GLOBALS['config']['app']['search_manga_rule'])){
  331. $role .= '|'.$GLOBALS['config']['app']['search_manga_rule'];
  332. }
  333. $where[$role] = ['like', '%' . $wd . '%'];
  334. }
  335. if(!empty($name)) {
  336. $where['manga_name'] = ['like', mac_like_arr($name),'OR'];
  337. }
  338. if(!empty($tag)) {
  339. $where['manga_tag'] = ['like', mac_like_arr($tag),'OR'];
  340. }
  341. if(!empty($class)) {
  342. $where['manga_class'] = ['like',mac_like_arr($class),'OR'];
  343. }
  344. if(defined('ENTRANCE') && ENTRANCE == 'index' && $GLOBALS['config']['app']['popedom_filter'] ==1){
  345. $type_ids = mac_get_popedom_filter($GLOBALS['user']['group']['group_type']);
  346. if(!empty($type_ids)){
  347. if(!empty($where['type_id'])){
  348. $where['type_id'] = [ $where['type_id'],['not in', explode(',',$type_ids)] ];
  349. }
  350. else{
  351. $where['type_id'] = ['not in', explode(',',$type_ids)];
  352. }
  353. }
  354. }
  355. if($by=='rnd'){
  356. $data_count = $this->countData($where);
  357. $page_total = floor($data_count / $lp['num']) + 1;
  358. if($data_count < $lp['num']){
  359. $lp['num'] = $data_count;
  360. }
  361. $randi = @mt_rand(1, $page_total);
  362. $page = $randi;
  363. $by = 'hits_week';
  364. $order = 'desc';
  365. }
  366. if(!in_array($by, ['id', 'time','time_add','score','hits','hits_day','hits_week','hits_month','up','down','level','rnd'])) {
  367. $by = 'time';
  368. }
  369. if(!in_array($order, ['asc', 'desc'])) {
  370. $order = 'desc';
  371. }
  372. $order= 'manga_'.$by .' ' . $order;
  373. $where_cache = $where;
  374. if(!empty($randi)){
  375. unset($where_cache['manga_id']);
  376. $where_cache['order'] = 'rnd';
  377. }
  378. $cach_name = $GLOBALS['config']['app']['cache_flag']. '_' .md5('manga_listcache_'.http_build_query($where_cache).'_'.$order.'_'.$page.'_'.$num.'_'.$start.'_'.$pageurl);
  379. $res = Cache::get($cach_name);
  380. if(empty($cachetime)){
  381. $cachetime = $GLOBALS['config']['app']['cache_time'];
  382. }
  383. if($GLOBALS['config']['app']['cache_core']==0 || empty($res)) {
  384. $res = $this->listData($where,$order,$page,$num,$start,'*',1,$totalshow);
  385. if($GLOBALS['config']['app']['cache_core']==1) {
  386. Cache::set($cach_name, $res, $cachetime);
  387. }
  388. }
  389. $res['pageurl'] = $pageurl;
  390. $res['half'] = $half;
  391. return $res;
  392. }
  393. public function infoData($where,$field='*',$cache=0)
  394. {
  395. if(empty($where) || !is_array($where)){
  396. return ['code'=>1001,'msg'=>lang('param_err')];
  397. }
  398. $this->ensureRecycleColumnExists();
  399. $where = $this->mergeRecycleWhere($where);
  400. $data_cache = false;
  401. $key = $GLOBALS['config']['app']['cache_flag']. '_'.'manga_detail_'.$where['manga_id'][1].'_'.$where['manga_en'][1];
  402. if($where['manga_id'][0]=='eq' || $where['manga_en'][0]=='eq'){
  403. $data_cache = true;
  404. }
  405. if($GLOBALS['config']['app']['cache_core']==1 && $data_cache) {
  406. $info = Cache::get($key);
  407. }
  408. if($GLOBALS['config']['app']['cache_core']==0 || $cache==0 || empty($info['manga_id'])) {
  409. $info = $this->field($field)->where($where)->find();
  410. if (empty($info)) {
  411. return ['code' => 1002, 'msg' => lang('obtain_err')];
  412. }
  413. $info = $info->toArray();
  414. //内容
  415. if (!empty($info['manga_chapter_url'])) {
  416. $info['manga_page_list'] = mac_manga_list($info['manga_chapter_from'], $info['manga_chapter_url'], $info['manga_play_server'], $info['manga_play_note']);
  417. $info['manga_page_total'] = count($info['manga_page_list']);
  418. }
  419. if(!empty($info['manga_pic_screenshot'])){
  420. $info['manga_pic_screenshot_list'] = mac_screenshot_list($info['manga_pic_screenshot']);
  421. }
  422. //分类
  423. if (!empty($info['type_id'])) {
  424. $type_list = model('Type')->getCache('type_list');
  425. $info['type'] = $type_list[$info['type_id']];
  426. $info['type_1'] = $type_list[$info['type']['type_pid']];
  427. }
  428. //用户组
  429. if (!empty($info['group_id'])) {
  430. $group_list = model('Group')->getCache('group_list');
  431. $info['group'] = $group_list[$info['group_id']];
  432. }
  433. if($GLOBALS['config']['app']['cache_core']==1 && $data_cache && $cache==1) {
  434. Cache::set($key, $info);
  435. }
  436. }
  437. return ['code'=>1,'msg'=>lang('obtain_ok'),'info'=>$info];
  438. }
  439. public function saveData($data)
  440. {
  441. $validate = \think\Loader::validate('Manga');
  442. if(!$validate->check($data)){
  443. return ['code'=>1001,'msg'=>lang('param_err').':'.$validate->getError() ];
  444. }
  445. $key = 'manga_detail_'.$data['manga_id'];
  446. Cache::rm($key);
  447. $key = 'manga_detail_'.$data['manga_en'];
  448. Cache::rm($key);
  449. $key = 'manga_detail_'.$data['manga_id'].'_'.$data['manga_en'];
  450. Cache::rm($key);
  451. $type_list = model('Type')->getCache('type_list');
  452. $type_info = $type_list[$data['type_id']];
  453. $data['type_id_1'] = $type_info['type_pid'];
  454. if(empty($data['manga_en'])){
  455. $data['manga_en'] = Pinyin::get($data['manga_name']);
  456. }
  457. if(empty($data['manga_letter'])){
  458. $data['manga_letter'] = strtoupper(substr($data['manga_en'],0,1));
  459. }
  460. if(!empty($data['manga_pic_screenshot'])){
  461. $data['manga_pic_screenshot'] = str_replace( array(chr(10),chr(13)), array('','#'),$data['manga_pic_screenshot']);
  462. }
  463. if(!empty($data['manga_content'])) {
  464. if(is_array($data['manga_content'])){
  465. $data['manga_content'] = join('$$$', $data['manga_content']);
  466. }
  467. if(is_array($data['manga_title'])){
  468. $data['manga_title'] = join('$$$', $data['manga_title']);
  469. }
  470. if(is_array($data['manga_note'])){
  471. $data['manga_note'] = join('$$$', $data['manga_note']);
  472. }
  473. $pattern_src = '/<img[\s\S]*?src\s*=\s*[\"|\"](.*?)[\"|\"][\s\S]*?>/';
  474. @preg_match_all($pattern_src, $data['manga_content'], $match_src1);
  475. if (!empty($match_src1)) {
  476. foreach ($match_src1[1] as $v1) {
  477. $v2 = str_replace($GLOBALS['config']['upload']['protocol'] . ':', 'mac:', $v1);
  478. $data['manga_content'] = str_replace($v1, $v2, $data['manga_content']);
  479. }
  480. if (empty($data['manga_pic'])) {
  481. $data['manga_pic'] = (string)$match_src1[1][0];
  482. }
  483. }
  484. unset($match_src1);
  485. }
  486. if(empty($data['manga_blurb'])){
  487. $data['manga_blurb'] = mac_substring( str_replace('$$$','', strip_tags($data['manga_content'])),100);
  488. }
  489. if($data['uptime']==1){
  490. $data['manga_time'] = time();
  491. }
  492. if($data['uptag']==1){
  493. $data['manga_tag'] = mac_get_tag($data['manga_name'], $data['manga_content']);
  494. }
  495. unset($data['uptime']);
  496. unset($data['uptag']);
  497. // xss过滤
  498. $filter_fields = [
  499. 'manga_name',
  500. 'manga_sub',
  501. 'manga_en',
  502. 'manga_color',
  503. 'manga_from',
  504. 'manga_author',
  505. 'manga_tag',
  506. 'manga_class',
  507. 'manga_pic',
  508. 'manga_pic_thumb',
  509. 'manga_pic_slide',
  510. 'manga_blurb',
  511. 'manga_remarks',
  512. 'manga_jumpurl',
  513. 'manga_tpl',
  514. 'manga_rel_manga',
  515. 'manga_rel_vod',
  516. 'manga_pwd',
  517. 'manga_pwd_url',
  518. ];
  519. foreach ($filter_fields as $filter_field) {
  520. if (!isset($data[$filter_field])) {
  521. continue;
  522. }
  523. $data[$filter_field] = mac_filter_xss($data[$filter_field]);
  524. }
  525. if(!empty($data['manga_id'])){
  526. $where=[];
  527. $where['manga_id'] = ['eq',$data['manga_id']];
  528. $res = $this->allowField(true)->where($where)->update($data);
  529. }
  530. else{
  531. $data['manga_time_add'] = time();
  532. $data['manga_time'] = time();
  533. $res = $this->allowField(true)->insert($data);
  534. }
  535. if(false === $res){
  536. return ['code'=>1002,'msg'=>lang('save_err').':'.$this->getError() ];
  537. }
  538. return ['code'=>1,'msg'=>lang('save_ok')];
  539. }
  540. public function delData($where)
  541. {
  542. if(!is_array($where)){
  543. $where = json_decode($where,true);
  544. }
  545. if(!is_array($where)){
  546. return ['code'=>1001,'msg'=>lang('param_err')];
  547. }
  548. $where['_recycle'] = 'all';
  549. $list = $this->listData($where,'',1,9999);
  550. if($list['code'] !==1){
  551. return ['code'=>1001,'msg'=>lang('del_err').':'.$this->getError() ];
  552. }
  553. $where = $this->mergeRecycleWhere($where);
  554. $path = './';
  555. foreach($list['list'] as $k=>$v){
  556. $pic = $path.$v['manga_pic'];
  557. if(file_exists($pic) && (substr($pic,0,8) == "./upload") || count( explode("./",$pic) ) ==1){
  558. unlink($pic);
  559. }
  560. $pic = $path.$v['manga_pic_thumb'];
  561. if(file_exists($pic) && (substr($pic,0,8) == "./upload") || count( explode("./",$pic) ) ==1){
  562. unlink($pic);
  563. }
  564. $pic = $path.$v['manga_pic_slide'];
  565. if(file_exists($pic) && (substr($pic,0,8) == "./upload") || count( explode("./",$pic) ) ==1){
  566. unlink($pic);
  567. }
  568. if($GLOBALS['config']['view']['manga_detail'] ==2 ){
  569. $lnk = mac_url_manga_detail($v);
  570. $lnk = reset_html_filename($lnk);
  571. if(file_exists($lnk)){
  572. unlink($lnk);
  573. }
  574. }
  575. }
  576. $res = $this->where($where)->delete();
  577. if($res===false){
  578. return ['code'=>1001,'msg'=>lang('del_err').':'.$this->getError() ];
  579. }
  580. return ['code'=>1,'msg'=>lang('del_ok')];
  581. }
  582. public function fieldData($where,$update)
  583. {
  584. if(!is_array($update)){
  585. return ['code'=>1001,'msg'=>lang('param_err')];
  586. }
  587. $res = $this->allowField(true)->where($where)->update($update);
  588. if($res===false){
  589. return ['code'=>1001,'msg'=>lang('set_err').':'.$this->getError() ];
  590. }
  591. $list = $this->field('manga_id,manga_name,manga_en')->where($where)->select();
  592. foreach($list as $k=>$v){
  593. $key = 'manga_detail_'.$v['manga_id'];
  594. Cache::rm($key);
  595. $key = 'manga_detail_'.$v['manga_en'];
  596. Cache::rm($key);
  597. }
  598. return ['code'=>1,'msg'=>lang('set_ok')];
  599. }
  600. public function updateToday($flag='manga')
  601. {
  602. $today = strtotime(date('Y-m-d'));
  603. $where = [];
  604. $where['manga_time'] = ['gt',$today];
  605. if($flag=='type'){
  606. $ids = $this->where($where)->column('type_id');
  607. }
  608. else{
  609. $ids = $this->where($where)->column('manga_id');
  610. }
  611. if(empty($ids)){
  612. $ids = [];
  613. }else{
  614. $ids = array_unique($ids);
  615. }
  616. return ['code'=>1,'msg'=>lang('obtain_ok'),'data'=> join(',',$ids) ];
  617. }
  618. }