| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- namespace app\admin\controller\system;
- use app\common\controller\AdminController;
- use app\common\model\CouponPlanModel;
- use app\common\model\SystemBannerModel;
- use think\App;
- use think\cache\driver\Redis;
- use think\facade\Db;
- /**
- * @ControllerAnnotation(title="系统banner配置")
- */
- class Banner extends AdminController
- {
- use \app\admin\traits\Curd;
- public function __construct (App $app)
- {
- parent::__construct($app);
- $this->model = new SystemBannerModel();
- }
- public function index ()
- {
- if ($this->request->isAjax()) {
- if (input('selectFields')) {
- return $this->selectList();
- }
- list($page, $limit, $where) = $this->buildTableParames();
- $count = $this->model
- ->where($where)
- ->count();
- // return 11;
- // return json_decode('[{"price":10, "fee":1},{"price":50, "fee":0.5},{"price":100, "fee":0}]');
- $list = $this->model
- ->where($where)
- ->withAttr('img_pic', function ($val, $data){
- return __HTTPGETIMGADMIN($val);
- })
- ->page($page, $limit)
- ->order($this->sort)
- ->select();
- $data = [
- 'code' => 0,
- 'msg' => '',
- 'count' => $count,
- 'data' => $list,
- ];
- return json($data);
- }
- return $this->fetch();
- }
- /**
- * @NodeAnotation(title="修改")
- */
- public function edit ($id)
- {
- $row = $this->model->find($id);
- empty($row) && $this->error('数据不存在');
- if ($this->request->isAjax()) {
- $post = $this->request->post();
- $rule = [];
- $this->validate($post, $rule);
- try {
- $post['banner_desc'] = htmlspecialchars_decode($post['banner_desc']);
- $post['img_pic'] = __HTTPSAVEIMGADMIN($post['img_pic']);
- $save = $row->save($post);
- $redis = new Redis();
- $redis->delete('getAppBanner'.$row['type']);
- } catch (\Exception $e) {
- $this->error('保存失败');
- }
- $save ? $this->success('保存成功') : $this->error('保存失败');
- }
- $row['img_pic'] = __HTTPGETIMGADMIN($row['img_pic']);
- $this->assign('row', $row);
- return $this->fetch();
- }
- /**
- * @NodeAnotation(title="添加")
- */
- public function add()
- {
- if ($this->request->isAjax()){
- $row = request()->post();
- $row['img_pic'] = __HTTPSAVEIMGADMIN($row['img_pic']);
- $row['banner_desc'] = htmlspecialchars_decode($row['banner_desc']);
- $row['create_time'] = sr_getcurtime(time());
- unset($row['file']);
- $save = $this->model->insert($row);
- $redis = new Redis();
- $redis->delete('getAppBanner'.$row['type']);
- $save?$this->success('添加成功'):$this->error('添加失败');
- }
- return $this->fetch();
- }
- // /**
- // * @NodeAnotation(title="删除")
- // */
- // public function delete ($id)
- // {
- // $row = $this->model->find($id);
- // if ($row->id == 1) {
- // $this->error('父类常见问题不能删除');
- // }
- // empty($row) && $this->error('数据不存在');
- // try {
- // $save = $row->delete();
- // } catch (\Exception $e) {
- // $this->error('删除失败');
- // }
- // if ($save) {
- // $this->success('删除成功');
- // } else {
- // $this->error('删除失败');
- // }
- // }
- }
|