更新轮播图相关接口

wxl
Wayne 9 months ago
parent a1771b455c
commit c12d1c0b8c
  1. 76
      app/store/controller/content/Banner.php
  2. 75
      app/store/model/Banner.php
  3. 16
      app/store/model/GoodsSource.php

@ -0,0 +1,76 @@
<?php
declare(strict_types=1);
namespace app\store\controller\content;
use think\response\Json;
use app\store\controller\Controller;
use app\store\model\Banner as BannerModel;
/**
* Banner管理
* Class Carousel
* @package app\store\controller\content
*/
class Banner extends Controller
{
/**
* 获取列表记录
* @return Json
* @throws \think\db\exception\DbException
*/
public function list(): Json
{
$model = new BannerModel;
$list = $model->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() ?: '删除失败');
}
}

@ -0,0 +1,75 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
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();
}
}

@ -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 * @param array $data
@ -48,8 +58,10 @@ class GoodsSource extends GoodSourceModel
public function add(array $data): bool public function add(array $data): bool
{ {
// 新增记录 // 新增记录
$data['store_id'] = self::$storeId; return $this->save(array_merge($data, [
return $this->save($data); 'store_id' => self::$storeId,
'created_at' => time(),
]));
} }
/** /**

Loading…
Cancel
Save