Banner.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\admin\controller\system;
  3. use app\admin\logic\SystemBannerLogic;
  4. use app\common\controller\AdminController;
  5. use app\common\model\SystemBannerModel;
  6. use think\App;
  7. use utils\RedisCache;
  8. /**
  9. * @ControllerAnnotation(title="系统banner配置")
  10. */
  11. class Banner extends AdminController
  12. {
  13. use \app\admin\traits\Curd;
  14. public function __construct(App $app)
  15. {
  16. parent::__construct($app);
  17. $this->model = new SystemBannerModel();
  18. }
  19. public function index()
  20. {
  21. if ($this->request->isAjax()) {
  22. if (input('selectFields')) {
  23. return $this->selectList();
  24. }
  25. list($page, $limit, $where) = $this->buildTableParames();
  26. list($count, $list) = SystemBannerLogic::getList($page, $limit, $where, $this->sort);
  27. $data = [
  28. 'code' => 0,
  29. 'msg' => '',
  30. 'count' => $count,
  31. 'data' => $list,
  32. ];
  33. return json($data);
  34. }
  35. return $this->fetch();
  36. }
  37. /**
  38. * @NodeAnotation(title="修改")
  39. */
  40. public function edit($id)
  41. {
  42. $row = $this->model->find($id);
  43. empty($row) && $this->error('数据不存在');
  44. if ($this->request->isAjax()) {
  45. $post = $this->request->post();
  46. $rule = [];
  47. $this->validate($post, $rule);
  48. $save = SystemBannerLogic::edit($post);
  49. $save === true ? $this->success('保存成功') : $this->error('保存失败');
  50. }
  51. $row['img_pic'] = __HTTPGETIMGADMIN($row['img_pic']);
  52. $this->assign('row', $row);
  53. return $this->fetch();
  54. }
  55. /**
  56. * @NodeAnotation(title="添加")
  57. */
  58. public function add()
  59. {
  60. if ($this->request->isAjax()) {
  61. $row = request()->post();
  62. $save = SystemBannerLogic::add($row);
  63. $save === true ? $this->success('添加成功') : $this->error('添加失败');
  64. }
  65. return $this->fetch();
  66. }
  67. }