Page.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\store\controller;
  13. use think\response\Json;
  14. use app\store\model\Page as PageModel;
  15. /**
  16. * 店铺页面管理
  17. * Class Page
  18. * @package app\store\controller\wxapp
  19. */
  20. class Page extends Controller
  21. {
  22. /**
  23. * 页面列表
  24. * @return Json
  25. * @throws \think\db\exception\DataNotFoundException
  26. * @throws \think\db\exception\DbException
  27. * @throws \think\db\exception\ModelNotFoundException
  28. */
  29. public function list(): Json
  30. {
  31. $model = new PageModel;
  32. $list = $model->getList($this->request->param());
  33. return $this->renderSuccess(compact('list'));
  34. }
  35. /**
  36. * 页面设计默认数据
  37. * @return Json
  38. */
  39. public function defaultData(): Json
  40. {
  41. $model = new PageModel;
  42. return $this->renderSuccess([
  43. 'page' => $model->getDefaultPage(),
  44. 'items' => $model->getDefaultItems()
  45. ]);
  46. }
  47. /**
  48. * 页面详情
  49. * @param int $pageId
  50. * @return Json
  51. */
  52. public function detail(int $pageId): Json
  53. {
  54. $detail = PageModel::detail($pageId);
  55. return $this->renderSuccess(compact('detail'));
  56. }
  57. /**
  58. * 新增页面
  59. * @return Json
  60. */
  61. public function add(): Json
  62. {
  63. $model = new PageModel;
  64. if (!$model->add($this->postForm('form', false))) {
  65. return $this->renderError($model->getError() ?: '添加失败');
  66. }
  67. return $this->renderSuccess('添加成功');
  68. }
  69. /**
  70. * 编辑页面
  71. * @param int $pageId
  72. * @return Json
  73. */
  74. public function edit(int $pageId): Json
  75. {
  76. $model = PageModel::detail($pageId);
  77. if (!$model->edit($this->postForm('form', false))) {
  78. return $this->renderError($model->getError() ?: '更新失败');
  79. }
  80. return $this->renderSuccess('更新成功');
  81. }
  82. /**
  83. * 删除页面
  84. * @param int $pageId
  85. * @return Json
  86. */
  87. public function delete(int $pageId): Json
  88. {
  89. // 帮助详情
  90. $model = PageModel::detail($pageId);
  91. if (!$model->setDelete()) {
  92. return $this->renderError($model->getError() ?: '删除失败');
  93. }
  94. return $this->renderSuccess('删除成功');
  95. }
  96. /**
  97. * 设置默认首页
  98. * @param int $pageId
  99. * @return Json
  100. */
  101. public function setHome(int $pageId): Json
  102. {
  103. // 帮助详情
  104. $model = PageModel::detail($pageId);
  105. if (!$model->setHome()) {
  106. return $this->renderError($model->getError() ?: '设置失败');
  107. }
  108. return $this->renderSuccess('设置成功');
  109. }
  110. }