refactor: 进一步区分banner的pc与mobile
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
// +----------------------------------------------------------------------
|
||||
// | 模板设置
|
||||
// +----------------------------------------------------------------------
|
||||
$view_deivce_name = 'pc';
|
||||
$view_device_name = 'pc';
|
||||
if (request()->isMobile()) {
|
||||
$view_deivce_name = 'mobile';
|
||||
$view_device_name = 'mobile';
|
||||
}
|
||||
|
||||
return [
|
||||
@@ -13,7 +13,7 @@ return [
|
||||
// 默认模板渲染规则 1 解析为小写+下划线 2 全部转换小写 3 保持操作方法
|
||||
'auto_rule' => 1,
|
||||
// 模板目录名
|
||||
'view_dir_name' => "view/{$view_deivce_name}",
|
||||
'view_dir_name' => "view/{$view_device_name}",
|
||||
// 模板后缀
|
||||
'view_suffix' => 'html',
|
||||
// 模板文件名分隔符
|
||||
@@ -28,8 +28,8 @@ return [
|
||||
'taglib_end' => '}',
|
||||
// 模板输出替换
|
||||
'tpl_replace_string' => [
|
||||
'__CSS__' => "/static/index/{$view_deivce_name}/css",
|
||||
'__JS__' => "/static/index/{$view_deivce_name}/js",
|
||||
'__IMAGES__' => "/static/index/{$view_deivce_name}/images",
|
||||
'__CSS__' => "/static/index/{$view_device_name}/css",
|
||||
'__JS__' => "/static/index/{$view_device_name}/js",
|
||||
'__IMAGES__' => "/static/index/{$view_device_name}/images",
|
||||
]
|
||||
];
|
||||
|
||||
@@ -54,11 +54,12 @@ class Index extends Common
|
||||
$banners = SysBannerModel::with(['items' => function($query) {
|
||||
$query->where('type', 'IN', ['image', 'video'])->where('status', '=', 1)->order(['sort' => 'asc', 'id' => 'desc']);
|
||||
}])
|
||||
->atPlatform(request()->from)
|
||||
->uniqueLabel([
|
||||
'BANNER_67f61cd70e8e1',
|
||||
'BANNER_67f61cd70e8e1',
|
||||
'BANNER_67f633023a5b3',
|
||||
'BANNER_67f63f8ab5029',
|
||||
'BANNER_67f724ed81b1e',
|
||||
'BANNER_67f63f8ab5029',
|
||||
'BANNER_67f724ed81b1e',
|
||||
'BANNER_67f7392b4d83a',
|
||||
'BANNER_67f7410e244fb',
|
||||
'BANNER_67f76a96545f9',
|
||||
|
||||
@@ -3,4 +3,6 @@
|
||||
return [
|
||||
// 启用多语言支持
|
||||
think\middleware\LoadLangPack::class,
|
||||
// 确认请求来源
|
||||
app\index\middleware\ConfirmRequestFrom::class,
|
||||
];
|
||||
|
||||
25
app/index/middleware/ConfirmRequestFrom.php
Normal file
25
app/index/middleware/ConfirmRequestFrom.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\index\middleware;
|
||||
|
||||
class ConfirmRequestFrom
|
||||
{
|
||||
/**
|
||||
* 处理请求
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param \Closure $next
|
||||
* @return Response
|
||||
*/
|
||||
public function handle($request, \Closure $next)
|
||||
{
|
||||
// 确认请求来源
|
||||
$request->from = 'pc';
|
||||
if ($request->isMobile()) {
|
||||
$request->from = 'mobile';
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,16 @@ class SysBannerModel extends SysBannerBaseModel
|
||||
return $this->hasMany(SysBannerItemModel::class, 'banner_id', 'id');
|
||||
}
|
||||
|
||||
// 所属平台范围查询
|
||||
public function scopeAtPlatform($query, string|array $platform)
|
||||
{
|
||||
if (is_array($platform)) {
|
||||
$query->whereIn('at_platform', $platform);
|
||||
return;
|
||||
}
|
||||
$query->where('at_platform', '=', $platform);
|
||||
}
|
||||
|
||||
// 唯一标识范围查询
|
||||
public function scopeUniqueLabel($query, string|array $unique_label)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user