From 255b72272f690024a2a901d3d109747d21ec3845 Mon Sep 17 00:00:00 2001 From: Wayne <943146732@qq.com> Date: Sun, 25 Feb 2024 23:57:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=B4=A7=E6=BA=90=E5=A2=9E?= =?UTF-8?q?=E5=88=A0=E6=94=B9=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/store/controller/goods/Source.php | 41 +++++++++++++++++++++++++++ app/store/model/GoodsSource.php | 32 +++++++++++++++++++++ 2 files changed, 73 insertions(+) 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(); + } }