model = new SystemArticleModel(); } 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('type', function ($val, $data){ return config('type.article')[$val]?config('type.article')[$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); } 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']); $type_info = Db::name('article_type')->where('id', $row['type'])->find(); if ($type_info){ $count = $this->model->where('type', $row['type'])->count(); if ($count >= $type_info['max_count']){ $this->error('这种类型只能存在'.$type_info['max_count'].'种'); } } $save = $this->model->insert($row); $save?$this->success('添加成功'):$this->error('添加失败'); } return $this->fetch(); } public function articleType() { $model = new ArticleTypeModel(); $list = $model ->where('status', 1) ->field('id,name') ->select() ->toArray(); $this->success('成功', $list); } }