feat 添加轮播图和海报接口
This commit is contained in:
parent
b5686e6cf7
commit
e873f8c300
126
app/admin/controller/Banners/Banner.php
Normal file
126
app/admin/controller/Banners/Banner.php
Normal file
@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\Banners;
|
||||
|
||||
use app\BaseController;
|
||||
use app\common\model\Banners\Banner as ModelBanner;
|
||||
use app\Request;
|
||||
use think\Validate;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Filesystem;
|
||||
use app\common\arw\adjfut\src\Excel;
|
||||
use app\common\arw\adjfut\src\UploadFile;
|
||||
use app\common\exception\Tool;
|
||||
use think\facade\Db;
|
||||
use think\facade\Env;
|
||||
|
||||
|
||||
class Banner extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取轮播图列表
|
||||
*/
|
||||
public function getBannerList(Request $request): array
|
||||
{
|
||||
$con = Tool::getOptionalQuery();
|
||||
|
||||
$query = ModelBanner::where($con)
|
||||
->field([
|
||||
'banner_id',
|
||||
'banner_img',
|
||||
'banner_location',
|
||||
'banner_order',
|
||||
'banner_guid'
|
||||
])
|
||||
->order('banner_order', 'asc');
|
||||
|
||||
return msg("获取轮播图列表成功!", $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加轮播图
|
||||
*/
|
||||
public function addBanner(Request $request): array
|
||||
{
|
||||
Db::startTrans();
|
||||
Tool::adminLockTableWrite('banner');
|
||||
try {
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'banner_img|轮播图图片' => 'require',
|
||||
// 'banner_order
|
||||
]);
|
||||
ModelBanner::create($params, [
|
||||
'banner_guid',
|
||||
'banner_create_user_guid',
|
||||
'banner_update_user_guid',
|
||||
'banner_img',
|
||||
'banner_location',
|
||||
'banner_order'
|
||||
]);
|
||||
Db::commit();
|
||||
Tool::unlockTable();
|
||||
return msg('添加成功!');
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
Tool::unlockTable();
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑轮播图
|
||||
*/
|
||||
public function editBanner(Request $request): array
|
||||
{
|
||||
Db::startTrans();
|
||||
Tool::adminLockTableWrite('banner');
|
||||
try {
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'banner_img|轮播图图片' => 'require',
|
||||
]);
|
||||
$model = ModelBanner::where('banner_guid', $params['banner_guid'])->find();
|
||||
if (!$model) throwErrorMsg("该轮播图不存在", 1);
|
||||
$model->allowField([
|
||||
'banner_update_user_guid',
|
||||
'banner_img',
|
||||
'banner_location',
|
||||
'banner_order'
|
||||
])->save($params);
|
||||
Db::commit();
|
||||
Tool::unlockTable();
|
||||
return msg('编辑成功!');
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
Tool::unlockTable();
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除轮播图
|
||||
*/
|
||||
public function deleteBanner(Request $request): array
|
||||
{
|
||||
Db::startTrans();
|
||||
Tool::adminLockTableWrite('banner');
|
||||
try {
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'banner_guid' => 'require',
|
||||
]);
|
||||
$banner = ModelBanner::where([
|
||||
'banner_guid' => explode(',', $params['banner_guid'])
|
||||
])->select();
|
||||
$banner->delete();
|
||||
Db::commit();
|
||||
Tool::unlockTable();
|
||||
return msg('删除成功!');
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
Tool::unlockTable();
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
}
|
134
app/admin/controller/Banners/Poster.php
Normal file
134
app/admin/controller/Banners/Poster.php
Normal file
@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\Banners;
|
||||
|
||||
use app\BaseController;
|
||||
use app\common\model\Banners\Poster as ModelPoster;
|
||||
use app\Request;
|
||||
use think\Validate;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Filesystem;
|
||||
use app\common\arw\adjfut\src\Excel;
|
||||
use app\common\arw\adjfut\src\UploadFile;
|
||||
use app\common\exception\Tool;
|
||||
use think\facade\Db;
|
||||
use think\facade\Env;
|
||||
|
||||
|
||||
class Poster extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取海报列表
|
||||
*/
|
||||
public function getPosterList(Request $request): array
|
||||
{
|
||||
$params = $request->param();
|
||||
$con = Tool::getOptionalQuery(['poster_location', '='],);
|
||||
|
||||
$query = ModelPoster::where($con)
|
||||
->field([
|
||||
'poster_id',
|
||||
'poster_guid',
|
||||
'poster_location',
|
||||
'poster_img',
|
||||
'poster_title',
|
||||
'poster_describe',
|
||||
'poster_sort'
|
||||
])
|
||||
->order('poster_sort', 'asc');
|
||||
|
||||
return msg("获取海报列表成功!", $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑海报
|
||||
*/
|
||||
public function editPoster(Request $request): array
|
||||
{
|
||||
Db::startTrans();
|
||||
Tool::adminLockTableWrite('poster');
|
||||
try {
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'poster_location|位置' => 'require',
|
||||
'poster_img|图片' => 'require',
|
||||
]);
|
||||
$model = ModelPoster::where('poster_guid', $params['poster_guid'])->find();
|
||||
if (!$model) throwErrorMsg("该海报不存在", 1);
|
||||
$model->allowField([
|
||||
'poster_update_user_guid',
|
||||
'poster_location',
|
||||
'poster_img',
|
||||
'poster_title',
|
||||
'poster_describe',
|
||||
'poster_sort'
|
||||
])->save($params);
|
||||
Db::commit();
|
||||
Tool::unlockTable();
|
||||
return msg('编辑成功!');
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
Tool::unlockTable();
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加海报
|
||||
*/
|
||||
public function addPoster(Request $request): array
|
||||
{
|
||||
Db::startTrans();
|
||||
Tool::adminLockTableWrite('poster');
|
||||
try {
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'poster_location|位置' => 'require',
|
||||
'poster_img|图片' => 'require',
|
||||
]);
|
||||
$model = ModelPoster::create($params, [
|
||||
'poster_guid',
|
||||
'poster_create_user_guid',
|
||||
'poster_update_user_guid',
|
||||
'poster_location',
|
||||
'poster_img',
|
||||
'poster_title',
|
||||
'poster_describe',
|
||||
'poster_sort'
|
||||
]);
|
||||
Db::commit();
|
||||
Tool::unlockTable();
|
||||
return msg('添加成功!');
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
Tool::unlockTable();
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除海报
|
||||
*/
|
||||
public function deletePoster(Request $request): array
|
||||
{
|
||||
Db::startTrans();
|
||||
Tool::adminLockTableWrite('poster');
|
||||
try {
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'poster_guid' => 'require',
|
||||
]);
|
||||
$poster = ModelPoster::where([
|
||||
'poster_guid' => explode(',', $params['poster_guid'])
|
||||
])->select();
|
||||
$poster->delete();
|
||||
Db::commit();
|
||||
Tool::unlockTable();
|
||||
return msg('删除成功!');
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
Tool::unlockTable();
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
}
|
43
app/api/controller/Banners/Banner.php
Normal file
43
app/api/controller/Banners/Banner.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller\Banners;
|
||||
|
||||
use app\BaseController;
|
||||
use app\common\model\Banners\Banner as ModelBanner;
|
||||
use app\Request;
|
||||
use think\Validate;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Filesystem;
|
||||
use app\common\arw\adjfut\src\Excel;
|
||||
use app\common\arw\adjfut\src\UploadFile;
|
||||
use think\facade\Db;
|
||||
use app\common\exception\Tool;
|
||||
use think\facade\Env;
|
||||
|
||||
|
||||
class Banner extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取轮播图列表
|
||||
*/
|
||||
public function getBannerList(Request $request): array
|
||||
{
|
||||
$params = $request->param();
|
||||
$con = [];
|
||||
$this->validate($params, ['banner_location|轮播图位置' => 'require']);
|
||||
|
||||
$query = ModelBanner::where($con)
|
||||
->field([
|
||||
'banner_img',
|
||||
'banner_location',
|
||||
])
|
||||
->where('banner_location', $params['banner_location'])
|
||||
->order('banner_order', 'asc')
|
||||
->select();
|
||||
|
||||
return msg(0, "获取轮播图列表成功!", [
|
||||
'data' => $query,
|
||||
'count' => count($query)
|
||||
]);
|
||||
}
|
||||
}
|
39
app/api/controller/Banners/Poster.php
Normal file
39
app/api/controller/Banners/Poster.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller\Banners;
|
||||
|
||||
use app\BaseController;
|
||||
use app\common\model\Banners\Poster as ModelPoster;
|
||||
use app\Request;
|
||||
use think\Validate;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Filesystem;
|
||||
use app\common\arw\adjfut\src\Excel;
|
||||
use app\common\arw\adjfut\src\UploadFile;
|
||||
use think\facade\Db;
|
||||
use app\common\exception\Tool;
|
||||
use think\facade\Env;
|
||||
|
||||
|
||||
class Poster extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取海报详情
|
||||
*/
|
||||
public function getPoster(Request $request): array
|
||||
{
|
||||
$params = $request->param();
|
||||
|
||||
$this->validate($params, ['poster_location|海报位置' => 'require']);
|
||||
|
||||
$find = ModelPoster::field([
|
||||
'poster_img' => 'imgSrc',
|
||||
'poster_title' => 'title',
|
||||
'poster_describe' => 'text',
|
||||
])
|
||||
->where('poster_location', $params['poster_location'])
|
||||
->find();
|
||||
|
||||
return msg(0, '获取海报详情成功!', ['data' => $find]);
|
||||
}
|
||||
}
|
74
app/common/model/Banners/Banner.php
Normal file
74
app/common/model/Banners/Banner.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\Banners;
|
||||
|
||||
use app\common\arw\adjfut\src\Validate;
|
||||
use app\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
use app\common\arw\adjfut\src\Excel;
|
||||
use app\Request;
|
||||
use app\common\exception\Tool;
|
||||
use think\facade\Db;
|
||||
|
||||
class Banner extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
// 删除字段
|
||||
protected $deleteTime = 'banner_delete_time';
|
||||
// 设置主键名
|
||||
protected $pk = 'banner_guid';
|
||||
// 设置废弃字段
|
||||
protected $disuse = [];
|
||||
// 设置字段信息
|
||||
protected $schema = [
|
||||
"banner_id" => "int",
|
||||
"banner_img" => "string",
|
||||
"banner_location" => "string",
|
||||
"banner_order" => "int",
|
||||
"banner_guid" => "string",
|
||||
"banner_create_time" => "datetime",
|
||||
"banner_create_user_guid" => "string",
|
||||
"banner_update_time" => "datetime",
|
||||
"banner_update_user_guid" => "string",
|
||||
"banner_delete_time" => "datetime",
|
||||
"banner_delete_user_guid" => "string",
|
||||
];
|
||||
// 设置json类型字段
|
||||
protected $json = [''];
|
||||
// 开启自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'datetime';
|
||||
// 创建时间
|
||||
protected $createTime = 'banner_create_time';
|
||||
// 修改时间
|
||||
protected $updateTime = 'banner_update_time';
|
||||
|
||||
//排序字段
|
||||
public $order_field = 'banner_order';
|
||||
|
||||
/**
|
||||
* 新增前
|
||||
*/
|
||||
public static function onBeforeInsert(self $model): void
|
||||
{
|
||||
Tool::dataAddSortProc($model);
|
||||
$model->completeCreateField();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新前
|
||||
*/
|
||||
public static function onBeforeUpdate(self $model): void
|
||||
{
|
||||
Tool::dataEditSortProc($model);
|
||||
$model->completeUpdateField();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除前
|
||||
*/
|
||||
public static function onBeforeDelete(self $model): void
|
||||
{
|
||||
Tool::dataDeleteSortProc($model);
|
||||
$model->completeDeleteField();
|
||||
}
|
||||
}
|
95
app/common/model/Banners/Poster.php
Normal file
95
app/common/model/Banners/Poster.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\Banners;
|
||||
|
||||
use app\common\arw\adjfut\src\Validate;
|
||||
use app\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
use app\common\arw\adjfut\src\Excel;
|
||||
use app\Request;
|
||||
use app\common\exception\Tool;
|
||||
use think\facade\Db;
|
||||
|
||||
class Poster extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
// 删除字段
|
||||
protected $deleteTime = 'poster_delete_time';
|
||||
// 设置主键名
|
||||
protected $pk = 'poster_guid';
|
||||
// 设置废弃字段
|
||||
protected $disuse = [];
|
||||
// 设置字段信息
|
||||
protected $schema = [
|
||||
|
||||
"poster_id" => "int",
|
||||
|
||||
"poster_guid" => "string",
|
||||
|
||||
"poster_location" => "string",
|
||||
|
||||
"poster_img" => "string",
|
||||
|
||||
"poster_title" => "string",
|
||||
|
||||
"poster_describe" => "string",
|
||||
|
||||
"poster_sort" => "string",
|
||||
|
||||
"poster_create_time" => "datetime",
|
||||
|
||||
"poster_create_user_guid" => "string",
|
||||
|
||||
"poster_update_time" => "datetime",
|
||||
|
||||
"poster_update_user_guid" => "string",
|
||||
|
||||
"poster_delete_time" => "datetime",
|
||||
|
||||
"poster_delete_user_guid" => "string",
|
||||
|
||||
];
|
||||
// 设置json类型字段
|
||||
protected $json = [''];
|
||||
// 开启自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'datetime';
|
||||
// 创建时间
|
||||
protected $createTime = 'poster_create_time';
|
||||
// 修改时间
|
||||
protected $updateTime = 'poster_update_time';
|
||||
|
||||
|
||||
|
||||
//排序字段
|
||||
public $order_field = 'poster_sort';
|
||||
|
||||
/**
|
||||
* 新增前
|
||||
*/
|
||||
public static function onBeforeInsert(self $model): void
|
||||
{
|
||||
Validate::unique(self::class, $model->poster_guid, $model->getData(), [
|
||||
'poster_location' => '海报位置',
|
||||
]);
|
||||
Tool::dataAddSortProc($model);
|
||||
$model->completeCreateField();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新前
|
||||
*/
|
||||
public static function onBeforeUpdate(self $model): void
|
||||
{
|
||||
Tool::dataEditSortProc($model);
|
||||
$model->completeUpdateField();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除前
|
||||
*/
|
||||
public static function onBeforeDelete(self $model): void
|
||||
{
|
||||
Tool::dataDeleteSortProc($model);
|
||||
$model->completeDeleteField();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user