diff --git a/app/store/controller/goods/Source.php b/app/store/controller/goods/Source.php index 07eaa5ad..2f6ddc94 100644 --- a/app/store/controller/goods/Source.php +++ b/app/store/controller/goods/Source.php @@ -30,4 +30,45 @@ class Source extends Controller $list = $modal->getList($this->request->param()); return $this->renderSuccess(compact('list')); } + + /** + * 货源新增 + * return Json + */ + public function add(): Json + { + $modal = new GoodsSourceModel; + if ($modal->add($this->postForm())) { + return $this->renderSuccess('添加成功'); + } + return $this->renderError($modal->getError() ?: '添加失败'); + } + + /** + * 货源编辑 + * @param int $sourceId + * @return Json + */ + public function edit(int $sourceId): Json + { + $modal = GoodsSourceModel::detail($sourceId); + if ($modal->edit($this->postForm())) { + return $this->renderSuccess('更新成功'); + } + return $this->renderError($modal->getError() ?: '更新失败'); + } + + /** + * 货源删除 + * @param int $sourceId + * @return Json + */ + public function delete(int $sourceId): Json + { + $modal = GoodsSourceModel::detail($sourceId); + if ($modal->setDelete()) { + return $this->renderSuccess('删除成功'); + } + return $this->renderError($modal->getError() ?: '删除失败'); + } } diff --git a/app/store/model/GoodsSource.php b/app/store/model/GoodsSource.php index 3c12a4af..8ce47e52 100644 --- a/app/store/model/GoodsSource.php +++ b/app/store/model/GoodsSource.php @@ -39,4 +39,36 @@ class GoodsSource extends GoodSourceModel 'query' => request()->request() ]); } + + /** + * 新增记录 + * @param array $data + * @return bool + */ + public function add(array $data): bool + { + // 新增记录 + $data['store_id'] = self::$storeId; + return $this->save($data); + } + + /** + * 更新记录 + * @param array $data + * @return bool + */ + public function edit(array $data): bool + { + // 更新记录 + return $this->save($data) !== false; + } + + /** + * 删除记录 + * @return bool + */ + public function setDelete(): bool + { + return $this->delete(); + } }