Banner.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. /**
  10. * @ControllerAnnotation(title="系统banner配置")
  11. */
  12. class Banner extends AdminController
  13. {
  14. use \app\admin\traits\Curd;
  15. public function __construct (App $app)
  16. {
  17. parent::__construct($app);
  18. $this->model = new SystemBannerModel();
  19. }
  20. public function index ()
  21. {
  22. if ($this->request->isAjax()) {
  23. if (input('selectFields')) {
  24. return $this->selectList();
  25. }
  26. list($page, $limit, $where) = $this->buildTableParames();
  27. $count = $this->model
  28. ->where($where)
  29. ->count();
  30. // return 11;
  31. // return json_decode('[{"price":10, "fee":1},{"price":50, "fee":0.5},{"price":100, "fee":0}]');
  32. $list = $this->model
  33. ->where($where)
  34. ->withAttr('img_pic', function ($val, $data){
  35. return __HTTPGETIMGADMIN($val);
  36. })
  37. ->page($page, $limit)
  38. ->order($this->sort)
  39. ->select();
  40. $data = [
  41. 'code' => 0,
  42. 'msg' => '',
  43. 'count' => $count,
  44. 'data' => $list,
  45. ];
  46. return json($data);
  47. }
  48. return $this->fetch();
  49. }
  50. /**
  51. * @NodeAnotation(title="修改")
  52. */
  53. public function edit ($id)
  54. {
  55. $row = $this->model->find($id);
  56. empty($row) && $this->error('数据不存在');
  57. if ($this->request->isAjax()) {
  58. $post = $this->request->post();
  59. $rule = [];
  60. $this->validate($post, $rule);
  61. try {
  62. $post['banner_desc'] = htmlspecialchars_decode($post['banner_desc']);
  63. $post['img_pic'] = __HTTPSAVEIMGADMIN($post['img_pic']);
  64. $save = $row->save($post);
  65. $redis = new Redis();
  66. $redis->delete('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. $redis = new Redis();
  89. $redis->delete('getAppBanner'.$row['type']);
  90. $save?$this->success('添加成功'):$this->error('添加失败');
  91. }
  92. return $this->fetch();
  93. }
  94. // /**
  95. // * @NodeAnotation(title="删除")
  96. // */
  97. // public function delete ($id)
  98. // {
  99. // $row = $this->model->find($id);
  100. // if ($row->id == 1) {
  101. // $this->error('父类常见问题不能删除');
  102. // }
  103. // empty($row) && $this->error('数据不存在');
  104. // try {
  105. // $save = $row->delete();
  106. // } catch (\Exception $e) {
  107. // $this->error('删除失败');
  108. // }
  109. // if ($save) {
  110. // $this->success('删除成功');
  111. // } else {
  112. // $this->error('删除失败');
  113. // }
  114. // }
  115. }