1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- declare (strict_types = 1);
- namespace app\store\controller\home;
- use app\store\controller\Controller;
- use app\common\model\CustomBlockGoods as CustomBlockGoodsModel;
- /**
- * 首页自定义模块商品
- * Class home
- * @package app\store\controller\home
- */
- class CustomBlockGoods extends Controller
- {
- /**
- * 列表
- * @return array
- * @throws \think\db\exception\DbException
- */
- public function list()
- {
- $model = new CustomBlockGoodsModel;
- $list = $model->getList($this->request->param());
- return $this->renderSuccess(compact('list'));
- }
- /**
- * 添加
- * @return array
- */
- public function add()
- {
- // 新增记录
- $model = new CustomBlockGoodsModel;
- if ($model->add($this->postForm())) {
- return $this->renderSuccess('添加成功');
- }
- return $this->renderError($model->getError() ?: '添加失败');
- }
- /**
- * 移除
- * @param int $id
- * @return array
- */
- public function delete(int $id = 0, $blockId = 0, $goodsId = 0)
- {
- // 详情
- if ($id) {
- $model = CustomBlockGoodsModel::detail($id);
- } elseif ($blockId && $goodsId) {
- $model = CustomBlockGoodsModel::getByGoodsIdBlockId($blockId, $goodsId);
- } else {
- return $this->renderError('参数无效');
- }
- if (!$model->delete()) {
- return $this->renderError($model->getError() ?: '删除失败');
- }
- return $this->renderSuccess('删除成功');
- }
- /**
- * 编辑
- * @param int $id
- * @return array
- */
- public function edit(int $id)
- {
- // 详情
- $model = CustomBlockGoodsModel::detail($id);
- // 更新记录
- if ($model->edit($this->postForm())) {
- return $this->renderSuccess('更新成功');
- }
- return $this->renderError($model->getError() ?: '更新失败');
- }
- }
|