// +---------------------------------------------------------------------- namespace app\controller\admin; use app\controller\Admin; use app\model\AdPlace; use app\model\Ad as AdModel; class Ad extends Admin{ /** * @title 广告位列表 */ public function index(AdPlace $adp){ if ($this->request->isAjax()) { $param = $this->request->param(); $res = $adp->paginate($this->request->pageConfig); $data = $res->append(['show_type_text', 'status_text'])->toArray(); $this->data['data'] = $data; return $this->data; } } /** * @title 添加广告位 */ public function add(AdPlace $adp){ if ($this->request->isPost()) { $data = $this->request->post(); $result = $adp->save($data); if (false !== $result) { return $this->success('成功添加', url('/admin/ad/index')); }else{ return $this->error($this->model->getError()); } }else{ $info['appid'] = rand_string(10, 1); //八位数字appid $info['appsecret'] = rand_string(32); //32位数字加字母秘钥 $this->data['data'] = array( 'show_type' => $adp->show_type, 'info' => $info ); return $this->data; } } /** * @title 编辑广告位 */ public function edit(AdPlace $adp){ if ($this->request->isPost()) { $data = $this->request->post(); if (!isset($data['id']) || !$data['id']) { return $this->error('非法操作!'); } $result = $adp->exists(true)->save($data); if (false !== $result) { return $this->success('修改成功', url('/admin/ad/index')); }else{ return $this->error($this->model->getError()); } }else{ $info = $adp->where('id', $this->request->param('id'))->find(); $this->data['template'] = "add"; $this->data['data'] = array( 'show_type' => $adp->show_type, 'info' => $info ); return $this->data; } } /** * @title 删除广告位 */ public function del(AdPlace $adp){ $ids = $this->request->param('ids', 0); if(!$ids){ return $this->error('非法操作!'); }else{ $ids = \explode(",", $ids); } $result = $adp->where('id', 'IN', $ids)->delete(); if(false !== $result){ return $this->success('删除成功!'); }else{ return $this->error('删除失败!'); } } /** * @title 广告列表 */ public function lists(AdModel $ad){ if ($this->request->isAjax()) { $res = $ad->paginate($this->request->pageConfig); $data = $res->append(['cover','status_text'])->toArray(); $this->data['data'] = $data; return $this->data; } } /** * @title 添加广告 */ public function addad(AdModel $ad){ if ($this->request->isPost()) { $data = $this->request->post(); $result = $ad->save($data); if (false !== $result) { return $this->success('成功添加', url('/admin/ad/index')); }else{ return $this->error($this->model->getError()); } }else{ $info['appid'] = rand_string(10, 1); //八位数字appid $info['appsecret'] = rand_string(32); //32位数字加字母秘钥 $this->data['data'] = array( 'info' => $info ); return $this->data; } } /** * @title 编辑广告 */ public function editad(AdModel $ad){ if ($this->request->isPost()) { $data = $this->request->post(); if (!isset($data['id']) || !$data['id']) { return $this->error('非法操作!'); } $result = $ad->exists(true)->save($data); if (false !== $result) { return $this->success('修改成功', url('/admin/ad/index')); }else{ return $this->error($this->model->getError()); } }else{ $info = $ad->where('id', $this->request->param('id'))->find(); $this->data['template'] = "addad"; $this->data['data'] = array( 'info' => $info ); return $this->data; } } /** * @title 删除广告 */ public function delad(AdModel $ad){ $ids = $this->request->param('ids', 0); if(!$ids){ return $this->error('非法操作!'); }else{ $ids = \explode(",", $ids); } $result = $ad->where('id', 'IN', $ids)->delete(); if(false !== $result){ return $this->success('删除成功!'); }else{ return $this->error('删除失败!'); } } }