Page.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace app\shop\controller\page;
  3. use app\shop\controller\Controller;
  4. use app\shop\model\page\Page as PageModel;
  5. use app\shop\model\page\PageCategory as PageCategoryModel;
  6. /**
  7. * App页面管理
  8. */
  9. class Page extends Controller
  10. {
  11. /**
  12. * 页面列表
  13. */
  14. public function index()
  15. {
  16. $model = new PageModel;
  17. $list = $model->getList($this->postData());
  18. return $this->renderSuccess('', compact('list'));
  19. }
  20. /**
  21. * 新增页面
  22. */
  23. public function add()
  24. {
  25. $model = new PageModel;
  26. if ($this->request->isGet()) {
  27. return $this->renderSuccess('', [
  28. 'defaultData' => $model->getDefaultItems(),
  29. 'jsonData' => ['page' => $model->getDefaultPage(), 'items' => []],
  30. 'opts' => [
  31. 'catgory' => [],
  32. ]
  33. ]);
  34. }
  35. // 接收post数据
  36. $post = $this->postData();
  37. if (!$model->add(json_decode($post['params'], true))) {
  38. return $this->renderError($model->getError() ?:'添加失败');
  39. }
  40. return $this->renderSuccess('添加成功');
  41. }
  42. /**
  43. * 首页编辑
  44. * @return \think\response\Json
  45. */
  46. public function home(){
  47. return $this->edit();
  48. }
  49. /**
  50. * 编辑页面
  51. */
  52. public function edit($page_id = null)
  53. {
  54. $model = $page_id > 0 ? PageModel::detail($page_id) : PageModel::getHomePage();
  55. if ($this->request->isGet()) {
  56. $jsonData = $model['page_data'];
  57. jsonRecursive($jsonData);
  58. return $this->renderSuccess('', [
  59. 'defaultData' => $model->getDefaultItems(),
  60. 'jsonData' => $jsonData,
  61. 'opts' => [
  62. 'catgory' => [],
  63. ]
  64. ]);
  65. }
  66. // 接收post数据
  67. $post = $this->postData();
  68. if (!$model->edit(json_decode($post['params'], true))) {
  69. return $this->renderError($model->getError() ?:'更新失败');
  70. }
  71. return $this->renderSuccess('更新成功');
  72. }
  73. /**
  74. * 删除页面
  75. */
  76. public function delete($page_id)
  77. {
  78. // 帮助详情
  79. $model = PageModel::detail($page_id);
  80. if (!$model->setDelete()) {
  81. return $this->renderError($model->getError() ?:'删除失败');
  82. }
  83. return $this->renderSuccess('删除成功');
  84. }
  85. /**
  86. * 分类模板
  87. */
  88. public function category()
  89. {
  90. $model = PageCategoryModel::detail();
  91. if($this->request->isGet()){
  92. return $this->renderSuccess('', compact('model'));
  93. }
  94. if ($model->edit($this->postData())) {
  95. return $this->renderSuccess('更新成功');
  96. }
  97. return $this->renderError($model->getError() ?: '更新失败');
  98. }
  99. }