model = new \app\api\model\Ad(); } /** * 显示资源列表 * * @return \think\Response */ public function index() { //接受参数 $_get = $this->request->get(); //验证参数 // validate(\app\api\validate\Block::class)->scene('lists')->check($_get); //数据处理 $_data = $this->model->index(); //返回数据 return send_http_status($_data); } /** * 获取广告位类型 * * @return \think\Response */ public function getAdType(){ //获取栏目类型 $_ad_type = config('dictionary.sqlfields.ad_type'); //返回数据 return send_http_status($_ad_type); } /** * 添加数据 * @return \think\Response * @Log [sys_name] 在 [sys_time] 创建了广告位:[name] */ public function add() { //接收参数 $_post = $this->request->post(); //验证参数 validate(\app\api\validate\Ad::class)->check($_post); //处理并返回参数 $insertId = $this->model->parentAdd($_post); return send_http_status($insertId, $insertId ? 201 : 202); } /** * 读取单条数据 * @param int $id * @return \think\Response */ public function read($id = '') { //验证参数 validate(\app\api\validate\Block::class)->scene('read')->check(['id' => $id]); //返回数据 return send_http_status($this->model->parentRead($id)); } /** * 保存更新的资源 * @param \think\Request $request * @param int $id * @return \think\Response * @Log [sys_name]在[sys_time]修改了广告位[id]的数据 */ public function edit($id = 0) { //接收参数 $_post = $this->request->post(); $_post['id'] = $id; //安全赋值,以免客户端没传id,修改需要id字段 //验证参数 validate(\app\api\validate\Ad::class)->scene('update')->check($_post); //处理并返回数据 return send_http_status('', $this->model->parentEdit($_post, $id) ? 203 : 204); } /** * 删除指定资源 * @Log [sys_name] 在 [sys_time] 删除了广告位id:[id] * @param int $id * @return \think\Response */ public function delete() { //接收参数 $ids = $this->request->get('id'); //验证参数 validate(['ids|id' => 'require|length:1,10'])->check(['ids' => $ids]); //处理并返回数据 return send_http_status('', $this->model->parentDel($ids) ? 205 : 206); } /** * 显示广告列表 * * @return \think\Response */ public function data() { //接受参数 $_get = $this->request->get(); //验证参数 // validate(\app\api\validate\Block::class)->scene('lists')->check($_get); //数据处理 $_data = $this->model->AdData(); //返回数据 return send_http_status($_data); } public function dataAdd(){ $this->model = new \app\api\model\AdData(); //接收参数 $_post = $this->request->post(); //验证参数 validate(\app\api\validate\AdData::class)->check($_post); //处理并返回参数 $insertId = $this->model->parentAdd($_post); return send_http_status($insertId, $insertId ? 201 : 202); } public function dataEdit($id = 0){ $this->model = new \app\api\model\AdData(); //接收参数 $_post = $this->request->post(); $_post['id'] = $id; //安全赋值,以免客户端没传id,修改需要id字段 //验证参数 validate(\app\api\validate\AdData::class)->scene('update')->check($_post); //处理并返回数据 return send_http_status('', $this->model->parentEdit($_post, $id) ? 203 : 204); } public function dataRead($id=0){ $this->model = new \app\api\model\AdData(); //验证参数 validate(\app\api\validate\AdData::class)->scene('read')->check(['id' => $id]); //返回数据 return send_http_status($this->model->parentRead($id)); } /** * 删除指定资源 * @Log [sys_name] 在 [sys_time] 删除了广告id:[id] * @param int $id * @return \think\Response */ public function dataDelete() { $this->model = new \app\api\model\AdData(); //接收参数 $ids = $this->request->get('id'); //验证参数 validate(['ids|id' => 'require|length:1,10'])->check(['ids' => $ids]); //处理并返回数据 return send_http_status('', $this->model->parentDel($ids) ? 205 : 206); } }