Ad.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\store\controller\home;
  4. use app\store\controller\Controller;
  5. use app\common\model\Ad as AdModel;
  6. /**
  7. * 广告管理
  8. * Class Ad
  9. * @package app\store\controller\home
  10. */
  11. class Ad extends Controller
  12. {
  13. /**
  14. * 列表
  15. * @return array
  16. * @throws \think\db\exception\DbException
  17. */
  18. public function list()
  19. {
  20. $model = new AdModel;
  21. $list = $model->getList($this->request->param());
  22. return $this->renderSuccess(compact('list'));
  23. }
  24. /**
  25. * 获取广告位置
  26. * @return array
  27. */
  28. public function adType()
  29. {
  30. $ad_type = AdModel::AD_TYPE;
  31. return $this->renderSuccess($ad_type);
  32. }
  33. /**
  34. * 获取链接分类id
  35. * @return array
  36. */
  37. public function jumpType() {
  38. $jump_type = AdModel::JUMP_TYPE;
  39. return $this->renderSuccess($jump_type);
  40. }
  41. /**
  42. * 获取详情记录
  43. * @param int $id
  44. * @return array
  45. */
  46. public function detail(int $id)
  47. {
  48. $detail = AdModel::detail($id);
  49. return $this->renderSuccess(compact('detail'));
  50. }
  51. /**
  52. * 添加
  53. * @return array
  54. */
  55. public function add()
  56. {
  57. // 新增记录
  58. $model = new AdModel;
  59. if ($model->add($this->postForm())) {
  60. return $this->renderSuccess('添加成功');
  61. }
  62. return $this->renderError($model->getError() ?: '添加失败');
  63. }
  64. /**
  65. * 编辑
  66. * @param int $id
  67. * @return array
  68. */
  69. public function edit(int $id)
  70. {
  71. // 详情
  72. $model = AdModel::detail($id);
  73. // 更新记录
  74. if ($model->edit($this->postForm())) {
  75. return $this->renderSuccess('更新成功');
  76. }
  77. return $this->renderError($model->getError() ?: '更新失败');
  78. }
  79. /**
  80. * 删除
  81. * @param int $id
  82. * @return array
  83. */
  84. public function delete(int $id)
  85. {
  86. // 详情
  87. $model = AdModel::detail($id);
  88. if (!$model->delete()) {
  89. return $this->renderError($model->getError() ?: '删除失败');
  90. }
  91. return $this->renderSuccess('删除成功');
  92. }
  93. }