request->param(); $list = $model->getList($params); return $this->renderSuccess(compact('list')); } /** * 详情 * @param int $id * @return array * @throws BaseException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function detail(int $id) { // 获取详情 $model = new ShopGoodsModel; $info = $model->getDetail($id); return $this->renderSuccess(compact('info')); } /** * 添加商品(支持批量) * * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function add() { $model = new ShopGoodsModel; if ($model->add($this->postForm())) { return $this->renderSuccess('添加成功'); } return $this->renderError($model->getError() ?: '添加失败'); } /** * 设置门店商品库存 */ public function setStock($id) { $model = ShopGoodsModel::get($id); if (empty($model)) { return $this->renderError("数据不存在"); } if ($model->setStock($this->postForm())) { return $this->renderSuccess('保存成功'); } return $this->renderError($model->getError() ?: '保存失败'); } /** * 移除商品 * @param $id * @return array */ public function delete($id) { $model = ShopGoodsModel::get($id); if (empty($model)) { return $this->renderError("数据不存在"); } if (!$model->remove()) { return $this->renderError($model->getError() ?: '删除失败'); } return $this->renderSuccess('删除成功'); } /** * 获取门店自提商品ID集合 */ public function getShopGoodsIds($shopId) { $goods_ids = ShopGoodsModel::where('shop_id', $shopId)->column('goods_id'); return $this->renderSuccess(compact('goods_ids')); } }