Topic.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class Topic extends Base
  5. {
  6. public function __construct()
  7. {
  8. parent::__construct();
  9. }
  10. public function data()
  11. {
  12. $param = input();
  13. $param['page'] = intval($param['page']) <1 ? 1 : $param['page'];
  14. $param['limit'] = intval($param['limit']) <1 ? $this->_pagesize : $param['limit'];
  15. $where=[];
  16. if(in_array($param['status'],['0','1'],true)){
  17. $where['topic_status'] = ['eq',$param['status']];
  18. }
  19. if(!empty($param['wd'])){
  20. $param['wd'] = htmlspecialchars(urldecode($param['wd']));
  21. $where['topic_name'] = ['like','%'.$param['wd'].'%'];
  22. }
  23. $order='topic_time desc';
  24. $res = model('Topic')->listData($where,$order,$param['page'],$param['limit']);
  25. foreach($res['list'] as $k=>&$v){
  26. $v['ismake'] = 1;
  27. if($GLOBALS['config']['view']['topic_detail'] >0 && $v['topic_time_make'] < $v['topic_time']){
  28. $v['ismake'] = 0;
  29. }
  30. }
  31. $this->assign('list',$res['list']);
  32. $this->assign('total',$res['total']);
  33. $this->assign('page',$res['page']);
  34. $this->assign('limit',$res['limit']);
  35. $param['page'] = '{page}';
  36. $param['limit'] = '{limit}';
  37. $this->assign('param',$param);
  38. $this->assign('title',lang('admin/topic/title'));
  39. return $this->fetch('admin@topic/index');
  40. }
  41. public function info()
  42. {
  43. if (Request()->isPost()) {
  44. $param = input('post.');
  45. $res = model('Topic')->saveData($param);
  46. if($res['code']>1){
  47. return $this->error($res['msg']);
  48. }
  49. return $this->success($res['msg']);
  50. }
  51. $id = input('id');
  52. $where=[];
  53. $where['topic_id'] = ['eq',$id];
  54. $res = model('Topic')->infoData($where);
  55. $this->assign('info',$res['info']);
  56. $config = config('maccms.site');
  57. $this->assign('install_dir',$config['install_dir']);
  58. $this->assign('title',lang('admin/topic/title'));
  59. return $this->fetch('admin@topic/info');
  60. }
  61. public function del()
  62. {
  63. $param = input();
  64. $ids = $param['ids'];
  65. if(!empty($ids)){
  66. $where=[];
  67. $where['topic_id'] = ['in',$ids];
  68. $res = model('Topic')->delData($where);
  69. if($res['code']>1){
  70. return $this->error($res['msg']);
  71. }
  72. return $this->success($res['msg']);
  73. }
  74. return $this->error(lang('param_err'));
  75. }
  76. public function field()
  77. {
  78. $param = input();
  79. $ids = $param['ids'];
  80. $col = $param['col'];
  81. $val = $param['val'];
  82. if(!empty($ids) && in_array($col,['topic_status','topic_level']) ){
  83. $where=[];
  84. $where['topic_id'] = ['in',$ids];
  85. $res = model('Topic')->fieldData($where,$col,$val);
  86. if($res['code']>1){
  87. return $this->error($res['msg']);
  88. }
  89. return $this->success($res['msg']);
  90. }
  91. return $this->error(lang('param_err'));
  92. }
  93. }