Website.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. use app\common\util\Pinyin;
  5. class Website 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['website_level'] = ['eq', $param['level']];
  22. }
  23. if (in_array($param['status'], ['0', '1'])) {
  24. $where['website_status'] = ['eq', $param['status']];
  25. }
  26. if (!empty($param['lock'])) {
  27. $where['website_lock'] = ['eq', $param['lock']];
  28. }
  29. if(!empty($param['pic'])){
  30. if($param['pic'] == '1'){
  31. $where['website_pic'] = ['eq',''];
  32. }
  33. elseif($param['pic'] == '2'){
  34. $where['website_pic'] = ['like','http%'];
  35. }
  36. elseif($param['pic'] == '3'){
  37. $where['website_pic'] = ['like','%#err%'];
  38. }
  39. }
  40. if(!empty($param['wd'])){
  41. $param['wd'] = htmlspecialchars(urldecode($param['wd']));
  42. $where['website_name'] = ['like','%'.$param['wd'].'%'];
  43. }
  44. if(!empty($param['repeat'])){
  45. if($param['page'] ==1){
  46. Db::execute('DROP TABLE IF EXISTS '.config('database.prefix').'tmpwebsite');
  47. Db::execute('CREATE TABLE `'.config('database.prefix').'tmpwebsite` (`id1` int unsigned DEFAULT NULL, `name1` varchar(1024) NOT NULL DEFAULT \'\') ENGINE=MyISAM');
  48. Db::execute('INSERT INTO `'.config('database.prefix').'tmpwebsite` (SELECT min(website_id)as id1,website_name as name1 FROM '.config('database.prefix').'website GROUP BY name1 HAVING COUNT(name1)>1)');
  49. }
  50. $order='website_name asc';
  51. $res = model('Website')->listRepeatData($where,$order,$param['page'],$param['limit']);
  52. }
  53. else{
  54. $order='website_time desc';
  55. $res = model('Website')->listData($where,$order,$param['page'],$param['limit']);
  56. }
  57. foreach($res['list'] as $k=>&$v){
  58. $v['ismake'] = 1;
  59. if($GLOBALS['config']['view']['website_detail'] >0 && $v['website_time_make'] < $v['website_time']){
  60. $v['ismake'] = 0;
  61. }
  62. }
  63. $this->assign('list', $res['list']);
  64. $this->assign('total', $res['total']);
  65. $this->assign('page', $res['page']);
  66. $this->assign('limit', $res['limit']);
  67. $param['page'] = '{page}';
  68. $param['limit'] = '{limit}';
  69. $this->assign('param', $param);
  70. $type_tree = model('Type')->getCache('type_tree');
  71. $this->assign('type_tree', $type_tree);
  72. $this->assign('title',lang('admin/website/title'));
  73. return $this->fetch('admin@website/index');
  74. }
  75. public function batch()
  76. {
  77. $param = input();
  78. if (!empty($param)) {
  79. mac_echo('<style type="text/css">body{font-size:12px;color: #333333;line-height:21px;}span{font-weight:bold;color:#FF0000}</style>');
  80. if(empty($param['ck_del']) && empty($param['ck_level']) && empty($param['ck_status']) && empty($param['ck_lock']) && empty($param['ck_hits']) ){
  81. return $this->error(lang('param_err'));
  82. }
  83. $where = [];
  84. if(!empty($param['type'])){
  85. $where['type_id'] = ['eq',$param['type']];
  86. }
  87. if(!empty($param['level'])){
  88. $where['website_level'] = ['eq',$param['level']];
  89. }
  90. if(in_array($param['status'],['0','1'])){
  91. $where['website_status'] = ['eq',$param['status']];
  92. }
  93. if(!empty($param['lock'])){
  94. $where['website_lock'] = ['eq',$param['lock']];
  95. }
  96. if(!empty($param['pic'])){
  97. if($param['pic'] == '1'){
  98. $where['website_pic'] = ['eq',''];
  99. }
  100. elseif($param['pic'] == '2'){
  101. $where['website_pic'] = ['like','http%'];
  102. }
  103. elseif($param['pic'] == '3'){
  104. $where['website_pic'] = ['like','%#err%'];
  105. }
  106. }
  107. if(!empty($param['wd'])){
  108. $param['wd'] = htmlspecialchars(urldecode($param['wd']));
  109. $where['website_name'] = ['like','%'.$param['wd'].'%'];
  110. }
  111. if($param['ck_del'] == 1){
  112. $res = model('Website')->delData($where);
  113. mac_echo(lang('multi_del_ok'));
  114. mac_jump( url('website/batch') ,3);
  115. exit;
  116. }
  117. if(empty($param['page'])){
  118. $param['page'] = 1;
  119. }
  120. if(empty($param['limit'])){
  121. $param['limit'] = 100;
  122. }
  123. if(empty($param['total'])) {
  124. $param['total'] = model('Website')->countData($where);
  125. $param['page_count'] = ceil($param['total'] / $param['limit']);
  126. }
  127. if($param['page'] > $param['page_count']) {
  128. mac_echo(lang('multi_opt_ok'));
  129. mac_jump( url('website/batch') ,3);
  130. exit;
  131. }
  132. mac_echo( "<font color=red>".lang('admin/batch_tip',[$param['total'],$param['limit'],$param['page_count'],$param['page']])."</font>");
  133. $order='website_id desc';
  134. $res = model('Website')->listData($where,$order,$param['page'],$param['limit']);
  135. foreach($res['list'] as $k=>$v){
  136. $where2 = [];
  137. $where2['website_id'] = $v['website_id'];
  138. $update = [];
  139. $des = $v['website_id'].','.$v['website_name'];
  140. if(!empty($param['ck_level']) && !empty($param['val_level'])){
  141. $update['website_level'] = $param['val_level'];
  142. $des .= '&nbsp;'.lang('level').':'.$param['val_level'].';';
  143. }
  144. if(!empty($param['ck_status']) && isset($param['val_status'])){
  145. $update['website_status'] = $param['val_status'];
  146. $des .= '&nbsp;'.lang('status').':'.($param['val_status'] ==1 ? '['.lang('reviewed').']':'['.lang('reviewed_not').']') .';';
  147. }
  148. if(!empty($param['ck_lock']) && isset($param['val_lock'])){
  149. $update['website_lock'] = $param['val_lock'];
  150. $des .= '&nbsp;'.lang('lock').':'.($param['val_lock']==1 ? '['.lang('lock').']':'['.lang('ublock').']').';';
  151. }
  152. if(!empty($param['ck_hits']) && !empty($param['val_hits_min']) && !empty($param['val_hits_max']) ){
  153. $update['website_hits'] = rand($param['val_hits_min'],$param['val_hits_max']);
  154. $des .= '&nbsp;'.lang('hits').':'.$update['website_hits'].';';
  155. }
  156. mac_echo($des);
  157. $res2 = model('Website')->where($where2)->update($update);
  158. }
  159. $param['page']++;
  160. $url = url('website/batch') .'?'. http_build_query($param);
  161. mac_jump( $url ,3);
  162. exit;
  163. }
  164. $type_tree = model('Type')->getCache('type_tree');
  165. $this->assign('type_tree',$type_tree);
  166. $this->assign('title',lang('admin/website/title'));
  167. return $this->fetch('admin@website/batch');
  168. }
  169. public function info()
  170. {
  171. if (Request()->isPost()) {
  172. $param = input('post.');
  173. $param['website_content'] = str_replace( $GLOBALS['config']['upload']['protocol'].':','mac:',$param['website_content']);
  174. $res = model('Website')->saveData($param);
  175. if($res['code']>1){
  176. return $this->error($res['msg']);
  177. }
  178. return $this->success($res['msg']);
  179. }
  180. $id = input('id');
  181. $where=[];
  182. $where['website_id'] = ['eq',$id];
  183. $res = model('Website')->infoData($where);
  184. $info = $res['info'];
  185. $this->assign('info',$info);
  186. $this->assign('website_page_list',$info['website_page_list']);
  187. $type_tree = model('Type')->getCache('type_tree');
  188. $this->assign('type_tree',$type_tree);
  189. $this->assign('title',lang('admin/website/title'));
  190. return $this->fetch('admin@website/info');
  191. }
  192. public function del()
  193. {
  194. $param = input();
  195. $ids = $param['ids'];
  196. if(!empty($ids)){
  197. $where=[];
  198. $where['website_id'] = ['in',$ids];
  199. $res = model('Website')->delData($where);
  200. if($res['code']>1){
  201. return $this->error($res['msg']);
  202. }
  203. return $this->success($res['msg']);
  204. }
  205. elseif(!empty($param['repeat'])){
  206. $st = ' not in ';
  207. if($param['retain']=='max'){
  208. $st=' in ';
  209. }
  210. $sql = 'delete from '.config('database.prefix').'website where website_name in(select name1 from '.config('database.prefix').'tmpwebsite) and website_id '.$st.'(select id1 from '.config('database.prefix').'tmpwebsite)';
  211. $res = model('Website')->execute($sql);
  212. if($res===false){
  213. return $this->success(lang('del_err'));
  214. }
  215. return $this->success(lang('del_ok'));
  216. }
  217. return $this->error(lang('param_err'));
  218. }
  219. public function field()
  220. {
  221. $param = input();
  222. $ids = $param['ids'];
  223. $col = $param['col'];
  224. $val = $param['val'];
  225. $start = $param['start'];
  226. $end = $param['end'];
  227. if ($col == 'type_id' && $val==''){
  228. return $this->error("请选择分类提交");
  229. }
  230. if(!empty($ids) && in_array($col,['website_status','website_lock','website_level','website_hits','type_id'])){
  231. $where=[];
  232. $where['website_id'] = ['in',$ids];
  233. $update = [];
  234. if(empty($start)) {
  235. $update[$col] = $val;
  236. if($col == 'type_id'){
  237. $type_list = model('Type')->getCache();
  238. $id1 = intval($type_list[$val]['type_pid']);
  239. $update['type_id_1'] = $id1;
  240. }
  241. $res = model('Website')->fieldData($where, $update);
  242. }
  243. else{
  244. if(empty($end)){$end = 9999;}
  245. $ids = explode(',',$ids);
  246. foreach($ids as $k=>$v){
  247. $val = rand($start,$end);
  248. $where['website_id'] = ['eq',$v];
  249. $update[$col] = $val;
  250. $res = model('Website')->fieldData($where, $update);
  251. }
  252. }
  253. if($res['code']>1){
  254. return $this->error($res['msg']);
  255. }
  256. return $this->success($res['msg']);
  257. }
  258. return $this->error(lang('param_err'));
  259. }
  260. public function updateToday()
  261. {
  262. $param = input();
  263. $flag = $param['flag'];
  264. $res = model('Website')->updateToday($flag);
  265. return json($res);
  266. }
  267. }