From 8b36409cf9a141ef7bf23426fcb3a4ee1d1e96af Mon Sep 17 00:00:00 2001 From: guojia <445241500@qq.com> Date: Wed, 24 Apr 2024 20:48:30 +0800 Subject: [PATCH] code add --- app/store/controller/Merchant.php | 19 +++++++++++++++++++ app/store/model/Merchant.php | 21 +++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/app/store/controller/Merchant.php b/app/store/controller/Merchant.php index e313ee56..4f34e6d8 100644 --- a/app/store/controller/Merchant.php +++ b/app/store/controller/Merchant.php @@ -48,6 +48,25 @@ class Merchant extends Controller return $this->renderError($model->getError() ?: '更新失败'); } return $this->renderSuccess('更新成功'); + + } + + /** + * 更新商城信息 + * @return Json + */ + public function add(): Json + { + // 商城详情 + //$model = MerchantModel::detail($this->storeId); + + // 新增记录 + $model = new MerchantModel; + $data = $this->postForm(); + if ($model->add($data)) { + return $this->renderSuccess('添加成功'); + } + return $this->renderError($model->getError() ?: '添加失败'); } /** diff --git a/app/store/model/Merchant.php b/app/store/model/Merchant.php index cc8061a0..d47f2b66 100644 --- a/app/store/model/Merchant.php +++ b/app/store/model/Merchant.php @@ -32,4 +32,25 @@ class Merchant extends StoreModel !isset($data['logo_image_id']) && $data['logo_image_id'] = 0; return $this->save($data) !== false; } + + /** + * 新增记录 + * @param array $data + * @return bool + */ + public function add(array $data): bool + { + return $this->save($this->createData($data)); + } + + /** + * 创建数据 + * @param array $data + * @return array + */ + private function createData(array $data): array + { + $data['store_id'] = self::$storeId; + return $data; + } }