Banner.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace app\admin\controller\system;
  3. use app\common\controller\AdminController;
  4. use app\common\model\CouponPlanModel;
  5. use app\common\model\SystemBannerModel;
  6. use think\App;
  7. use think\cache\driver\Redis;
  8. use think\facade\Db;
  9. use utils\RedisCache;
  10. /**
  11. * @ControllerAnnotation(title="系统banner配置")
  12. */
  13. class Banner extends AdminController
  14. {
  15. use \app\admin\traits\Curd;
  16. public function __construct (App $app)
  17. {
  18. parent::__construct($app);
  19. $this->model = new SystemBannerModel();
  20. }
  21. public function index ()
  22. {
  23. if ($this->request->isAjax()) {
  24. if (input('selectFields')) {
  25. return $this->selectList();
  26. }
  27. list($page, $limit, $where) = $this->buildTableParames();
  28. $count = $this->model
  29. ->where($where)
  30. ->count();
  31. // return 11;
  32. // return json_decode('[{"price":10, "fee":1},{"price":50, "fee":0.5},{"price":100, "fee":0}]');
  33. $list = $this->model
  34. ->where($where)
  35. ->withAttr('img_pic', function ($val, $data){
  36. return __HTTPGETIMGADMIN($val);
  37. })
  38. ->page($page, $limit)
  39. ->order($this->sort)
  40. ->select();
  41. $data = [
  42. 'code' => 0,
  43. 'msg' => '',
  44. 'count' => $count,
  45. 'data' => $list,
  46. ];
  47. return json($data);
  48. }
  49. return $this->fetch();
  50. }
  51. /**
  52. * @NodeAnotation(title="修改")
  53. */
  54. public function edit ($id)
  55. {
  56. $row = $this->model->find($id);
  57. empty($row) && $this->error('数据不存在');
  58. if ($this->request->isAjax()) {
  59. $post = $this->request->post();
  60. $rule = [];
  61. $this->validate($post, $rule);
  62. try {
  63. $post['banner_desc'] = htmlspecialchars_decode($post['banner_desc']);
  64. $post['img_pic'] = __HTTPSAVEIMGADMIN($post['img_pic']);
  65. $save = $row->save($post);
  66. RedisCache::clear('getAppBanner'.$row['type']);
  67. } catch (\Exception $e) {
  68. $this->error('保存失败');
  69. }
  70. $save ? $this->success('保存成功') : $this->error('保存失败');
  71. }
  72. $row['img_pic'] = __HTTPGETIMGADMIN($row['img_pic']);
  73. $this->assign('row', $row);
  74. return $this->fetch();
  75. }
  76. /**
  77. * @NodeAnotation(title="添加")
  78. */
  79. public function add()
  80. {
  81. if ($this->request->isAjax()){
  82. $row = request()->post();
  83. $row['img_pic'] = __HTTPSAVEIMGADMIN($row['img_pic']);
  84. $row['banner_desc'] = htmlspecialchars_decode($row['banner_desc']);
  85. $row['create_time'] = sr_getcurtime(time());
  86. unset($row['file']);
  87. $save = $this->model->insert($row);
  88. RedisCache::clear('getAppBanner'.$row['type']);
  89. $save?$this->success('添加成功'):$this->error('添加失败');
  90. }
  91. return $this->fetch();
  92. }
  93. }