From c12d1c0b8c353e6f5022f4b4bcb65d4800d36d78 Mon Sep 17 00:00:00 2001 From: Wayne <943146732@qq.com> Date: Mon, 26 Feb 2024 15:54:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=BD=AE=E6=92=AD=E5=9B=BE?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/store/controller/content/Banner.php | 76 +++++++++++++++++++++++++ app/store/model/Banner.php | 75 ++++++++++++++++++++++++ app/store/model/GoodsSource.php | 16 +++++- 3 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 app/store/controller/content/Banner.php create mode 100644 app/store/model/Banner.php diff --git a/app/store/controller/content/Banner.php b/app/store/controller/content/Banner.php new file mode 100644 index 00000000..e5e6c225 --- /dev/null +++ b/app/store/controller/content/Banner.php @@ -0,0 +1,76 @@ +getList(); + return $this->renderSuccess(compact('list')); + } + + /** + * 添加Banner + * @return Json + */ + public function add(): Json + { + // 新增记录 + $model = new BannerModel; + + if ($model->add($this->postForm())) { + return $this->renderSuccess('添加成功'); + } + return $this->renderError($model->getError() ?: '添加失败'); + } + + /** + * 更新Banner + * @param int $bannerId + * @return Json + */ + public function edit(int $bannerId): Json + { + // Banner详情 + $model = BannerModel::detail($bannerId); + // 更新记录 + if ($model->edit($this->postForm())) { + return $this->renderSuccess('更新成功'); + } + return $this->renderError($model->getError() ?: '更新失败'); + } + + /** + * 删除Banner + * @param int $bannerId + * @return Json + */ + public function delete(int $bannerId): Json + { + // Banner详情 + $model = BannerModel::detail($bannerId); + // 删除记录 + if ($model->setDelete()) { + return $this->renderSuccess('删除成功'); + } + return $this->renderError($model->getError() ?: '删除失败'); + } +} \ No newline at end of file diff --git a/app/store/model/Banner.php b/app/store/model/Banner.php new file mode 100644 index 00000000..c8cbffbb --- /dev/null +++ b/app/store/model/Banner.php @@ -0,0 +1,75 @@ + +// +---------------------------------------------------------------------- +declare(strict_types=1); + +namespace app\store\model; + +use app\common\model\Banner as BannerModel; + +/** + * 模型类:帮助中心 + * Class Help + * @package app\store\model + */ +class Banner extends BannerModel +{ + /** + * 获取列表记录 + * @return \think\Paginator + * @throws \think\db\exception\DbException + */ + public function getList(): \think\Paginator + { + $data = $this->paginate(); + return self::preload($data, ['image']); + } + + /** + * 详情 + * @param mixed $bannerId + * @param array $with + * @return static|array|null + */ + public static function detail($bannerId, array $with = []) + { + return self::get($bannerId, $with); + } + + /** + * 新增记录 + * @param array $data + * @return bool|false + */ + 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(); + } +} diff --git a/app/store/model/GoodsSource.php b/app/store/model/GoodsSource.php index 8ce47e52..bb1992f5 100644 --- a/app/store/model/GoodsSource.php +++ b/app/store/model/GoodsSource.php @@ -40,6 +40,16 @@ class GoodsSource extends GoodSourceModel ]); } + /** + * 获取货源详情 + * @param int $goodsId + * @return static|null + */ + public static function detail(int $goodsId, array $with = []) + { + return self::get($goodsId, $with); + } + /** * 新增记录 * @param array $data @@ -48,8 +58,10 @@ class GoodsSource extends GoodSourceModel public function add(array $data): bool { // 新增记录 - $data['store_id'] = self::$storeId; - return $this->save($data); + return $this->save(array_merge($data, [ + 'store_id' => self::$storeId, + 'created_at' => time(), + ])); } /**