postData(); $data['shop_supplier_id'] = $this->getSupplierId(); $list = $model->getList($data, 10); //查找默认 $default = $model::getDefault($this->getSupplierId()); return $this->renderSuccess('', compact('list', 'default')); } /** * 页面列表 */ public function index() { $model = new PageModel; $data = $this->postData(); $data['shop_supplier_id'] = $this->getSupplierId(); $list = $model->getList($data); return $this->renderSuccess('', compact('list')); } /** * 新增页面 */ public function add() { $model = new PageModel; if ($this->request->isGet()) { return $this->renderSuccess('', [ 'defaultData' => $model->getDefaultItems(), 'jsonData' => ['page' => $model->getDefaultPage(), 'items' => []], 'opts' => [ 'catgory' => [], ] ]); } // 接收post数据 $post = $this->postData(); $params=json_decode($post['params'], true); $params['shop_supplier_id'] = $this->getSupplierId(); if (!$model->add($params)) { return $this->renderError($model->getError() ?: '添加失败'); } return $this->renderSuccess('添加成功'); } /** * 首页编辑 * @return \think\response\Json */ public function home() { return $this->edit(); } /** * 编辑页面 */ public function edit($page_id = null) { $model = $page_id > 0 ? PageModel::detail($page_id) : PageModel::getHomePage(); if ($this->request->isGet()) { $jsonData = $model['page_data']; jsonRecursive($jsonData); return $this->renderSuccess('', [ 'defaultData' => $model->getDefaultItems(), 'jsonData' => $jsonData, 'opts' => [ 'catgory' => [], ] ]); } // 接收post数据 $post = $this->postData(); $params=json_decode($post['params'], true); $params['shop_supplier_id'] = $this->getSupplierId(); if (!$model->edit($params)) { return $this->renderError($model->getError() ?:'更新失败'); } return $this->renderSuccess('更新成功'); } /** * 删除页面 */ public function delete($page_id) { // 帮助详情 $model = PageModel::detail($page_id); if (!$model->setDelete()) { return $this->renderError($model->getError() ?:'删除失败'); } return $this->renderSuccess('删除成功'); } /** * 分类模板 */ public function category() { $model = PageCategoryModel::detail(); if($this->request->isGet()){ return $this->renderSuccess('', compact('model')); } if ($model->edit($this->postData())) { return $this->renderSuccess('更新成功'); } return $this->renderError($model->getError() ?: '更新失败'); } /** * 新增页面 */ public function addPage() { $model = new PageModel; if ($this->request->isGet()) { return $this->renderSuccess('', [ 'defaultData' => $model->getDefaultItems(), 'jsonData' => ['page' => $model->getDefaultPage(), 'items' => []], 'opts' => [ 'catgory' => [], ] ]); } // 接收post数据 $post = $this->postData(); $params=json_decode($post['params'], true); $params['shop_supplier_id'] = $this->getSupplierId(); if (!$model->add($params, 10)) { return $this->renderError($model->getError() ?: '添加失败'); } return $this->renderSuccess('添加成功'); } /** * 编辑页面 */ public function editPage($page_id) { $model = PageModel::detail($page_id); if ($this->request->isGet()) { $jsonData = $model['page_data']; jsonRecursive($jsonData); return $this->renderSuccess('', [ 'defaultData' => $model->getDefaultItems(), 'jsonData' => $jsonData, 'opts' => [ 'catgory' => [], ] ]); } // 接收post数据 $post = $this->postData(); $params=json_decode($post['params'], true); $params['shop_supplier_id'] = $this->getSupplierId(); if (!$model->edit($params)) { return $this->renderError($model->getError() ?: '更新失败'); } return $this->renderSuccess('更新成功'); } /** * 删除页面 */ public function deletePage($page_id) { // 详情 $model = PageModel::detail($page_id); if (!$model->setDelete()) { return $this->renderError($model->getError() ?: '删除失败'); } return $this->renderSuccess('删除成功'); } /** * 设置默认 */ public function setPage($page_id) { // 页面详情 $model = PageModel::detail($page_id); if (!$model->setDefault()) { return $this->renderError($model->getError() ?: '设置失败'); } return $this->renderSuccess('设置成功'); } /** * 商城设置 */ public function nav() { if($this->request->isGet()){ $data = SettingModel::getItem('nav'); return $this->renderSuccess('', compact('data')); } $model = new SettingModel; $data = $this->postData(); if ($model->edit('nav', $data)) { return $this->renderSuccess('操作成功'); } return $this->renderError($model->getError() ?: '操作失败'); } /** * 底部菜单 */ public function bottomnav() { $vars = SettingModel::getItem(SettingEnum::NAV.'_'.$this->getSupplierId()); return $this->renderSuccess('', compact('vars')); } /** * 底部菜单设置 */ public function bottomedit() { $model = new SettingModel; $data = $this->postData(); if ($model->edit(SettingEnum::NAV.'_'.$this->getSupplierId(), $data)) { return $this->renderSuccess('操作成功'); } return $this->renderError($model->getError() ?: '操作失败'); } public function setHome($page_id) { //取消原来的首页 PageModel::getHomePage()->setPageType(20); $model = PageModel::detail($page_id); if (!$model->setPageType(10)) { return $this->renderError($model->getError() ?:'设置失败'); } return $this->renderSuccess('设置成功'); } }