123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- declare (strict_types = 1);
- namespace app\store\controller\home;
- use app\store\controller\Controller;
- use app\common\model\Ad as AdModel;
- /**
- * 广告管理
- * Class Ad
- * @package app\store\controller\home
- */
- class Ad extends Controller
- {
- /**
- * 列表
- * @return array
- * @throws \think\db\exception\DbException
- */
- public function list()
- {
- $model = new AdModel;
- $list = $model->getList($this->request->param());
- return $this->renderSuccess(compact('list'));
- }
- /**
- * 获取广告位置
- * @return array
- */
- public function adType()
- {
- $ad_type = AdModel::AD_TYPE;
- return $this->renderSuccess($ad_type);
- }
- /**
- * 获取链接分类id
- * @return array
- */
- public function jumpType() {
- $jump_type = AdModel::JUMP_TYPE;
- return $this->renderSuccess($jump_type);
- }
- /**
- * 获取详情记录
- * @param int $id
- * @return array
- */
- public function detail(int $id)
- {
- $detail = AdModel::detail($id);
- return $this->renderSuccess(compact('detail'));
- }
- /**
- * 添加
- * @return array
- */
- public function add()
- {
- // 新增记录
- $model = new AdModel;
- if ($model->add($this->postForm())) {
- return $this->renderSuccess('添加成功');
- }
- return $this->renderError($model->getError() ?: '添加失败');
- }
- /**
- * 编辑
- * @param int $id
- * @return array
- */
- public function edit(int $id)
- {
- // 详情
- $model = AdModel::detail($id);
- // 更新记录
- if ($model->edit($this->postForm())) {
- return $this->renderSuccess('更新成功');
- }
- return $this->renderError($model->getError() ?: '更新失败');
- }
- /**
- * 删除
- * @param int $id
- * @return array
- */
- public function delete(int $id)
- {
- // 详情
- $model = AdModel::detail($id);
- if (!$model->delete()) {
- return $this->renderError($model->getError() ?: '删除失败');
- }
- return $this->renderSuccess('删除成功');
- }
- }
|