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..f95b9e4c --- /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->order(['sort' => 'asc', 'create_time' => 'desc'])->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(), + ])); } /**