Page.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. namespace app\shop\controller\page;
  3. use app\common\enum\settings\SettingEnum;
  4. use app\shop\controller\Controller;
  5. use app\shop\model\page\Page as PageModel;
  6. use app\shop\model\page\PageCategory as PageCategoryModel;
  7. use app\shop\model\settings\Setting as SettingModel;
  8. /**
  9. * App页面管理
  10. */
  11. class Page extends Controller
  12. {
  13. /**
  14. * 页面列表
  15. */
  16. public function index()
  17. {
  18. $model = new PageModel;
  19. $list = $model->getList($this->postData());
  20. return $this->renderSuccess('', compact('list'));
  21. }
  22. /**
  23. * 新增页面
  24. */
  25. public function add()
  26. {
  27. $model = new PageModel;
  28. if ($this->request->isGet()) {
  29. return $this->renderSuccess('', [
  30. 'defaultData' => $model->getDefaultItems(),
  31. 'jsonData' => ['page' => $model->getDefaultPage(), 'items' => []],
  32. 'opts' => [
  33. 'catgory' => [],
  34. ]
  35. ]);
  36. }
  37. // 接收post数据
  38. $post = $this->postData();
  39. if (!$model->add(json_decode($post['params'], true))) {
  40. return $this->renderError($model->getError() ?:'添加失败');
  41. }
  42. return $this->renderSuccess('添加成功');
  43. }
  44. /**
  45. * 首页编辑
  46. * @return \think\response\Json
  47. */
  48. public function home(){
  49. return $this->edit();
  50. }
  51. /**
  52. * 编辑页面
  53. */
  54. public function edit($page_id = null)
  55. {
  56. $model = $page_id > 0 ? PageModel::detail($page_id) : PageModel::getHomePage();
  57. if ($this->request->isGet()) {
  58. $jsonData = $model['page_data'];
  59. jsonRecursive($jsonData);
  60. return $this->renderSuccess('', [
  61. 'defaultData' => $model->getDefaultItems(),
  62. 'jsonData' => $jsonData,
  63. 'opts' => [
  64. 'catgory' => [],
  65. ]
  66. ]);
  67. }
  68. // 接收post数据
  69. $post = $this->postData();
  70. if (!$model->edit(json_decode($post['params'], true))) {
  71. return $this->renderError($model->getError() ?:'更新失败');
  72. }
  73. return $this->renderSuccess('更新成功');
  74. }
  75. /**
  76. * 删除页面
  77. */
  78. public function delete($page_id)
  79. {
  80. // 帮助详情
  81. $model = PageModel::detail($page_id);
  82. if (!$model->setDelete()) {
  83. return $this->renderError($model->getError() ?:'删除失败');
  84. }
  85. return $this->renderSuccess('删除成功');
  86. }
  87. /**
  88. * 分类模板
  89. */
  90. public function category()
  91. {
  92. $model = PageCategoryModel::detail();
  93. if($this->request->isGet()){
  94. return $this->renderSuccess('', compact('model'));
  95. }
  96. if ($model->edit($this->postData())) {
  97. return $this->renderSuccess('更新成功');
  98. }
  99. return $this->renderError($model->getError() ?: '更新失败');
  100. }
  101. /**
  102. * 商城设置
  103. */
  104. public function nav()
  105. {
  106. if($this->request->isGet()){
  107. $data = SettingModel::getItem('nav');
  108. return $this->renderSuccess('', compact('data'));
  109. }
  110. $model = new SettingModel;
  111. $data = $this->postData();
  112. if ($model->edit('nav', $data)) {
  113. return $this->renderSuccess('操作成功');
  114. }
  115. return $this->renderError($model->getError() ?: '操作失败');
  116. }
  117. /**
  118. * 商城设置
  119. */
  120. public function bottomnav()
  121. {
  122. if($this->request->isGet()){
  123. $data = SettingModel::getItem(SettingEnum::BOTTOMNAV);
  124. return $this->renderSuccess('', compact('data'));
  125. }
  126. $model = new SettingModel;
  127. $data = $this->postData();
  128. if ($model->edit(SettingEnum::BOTTOMNAV, $data)) {
  129. return $this->renderSuccess('操作成功');
  130. }
  131. return $this->renderError($model->getError() ?: '操作失败');
  132. }
  133. public function bottomedit(){
  134. $model = new SettingModel;
  135. $data = $this->postData();
  136. $vars = SettingModel::getItem(SettingEnum::BOTTOMNAV);
  137. if($data['type'] == 'image'){
  138. $vars['menus'][$data['index']] = [
  139. 'index' => $data['index'],
  140. 'text' => $data['text'],
  141. 'iconPath' => $data['iconPath'],
  142. 'selectedIconPath' => $data['selectedIconPath'],
  143. ];
  144. } else if($data['type'] == 'color'){
  145. $vars['color'] = $data['color'];
  146. $vars['no_color'] = $data['no_color'];
  147. }
  148. if ($model->edit(SettingEnum::BOTTOMNAV, $vars)) {
  149. return $this->renderSuccess('操作成功');
  150. }
  151. return $this->renderError($model->getError() ?: '操作失败');
  152. }
  153. }