|
|
@@ -69,7 +69,7 @@ class Banner extends Controller
|
|
|
$limit = request()->input('limit', 15);
|
|
|
$type = $params['type'] ?? '';
|
|
|
if (isset($params['platform']) && $params['platform'] !== '') {
|
|
|
- // The existing mobile banner enum is "app"; H5 filtering preserves that storage contract.
|
|
|
+ // H5 uses the same banner type as APP.
|
|
|
$platformType = $params['platform'] === 'pc' ? 'pc' : 'app';
|
|
|
if ($type !== '' && $type !== $platformType) {
|
|
|
throw ValidationException::withMessages(['platform' => '平台与原类型筛选不一致']);
|
|
|
@@ -80,7 +80,7 @@ class Banner extends Controller
|
|
|
$query = BannerModel::query();
|
|
|
|
|
|
if ($type !== '') {
|
|
|
- $query->where('type', $type);
|
|
|
+ $query->whereIn('type', [$type, BannerModel::TYPE_BOTH]);
|
|
|
}
|
|
|
if (isset($params['lang']) && $params['lang'] !== '') {
|
|
|
$query->where('lang', $params['lang']);
|
|
|
@@ -129,12 +129,18 @@ class Banner extends Controller
|
|
|
}],
|
|
|
'link_pc' => ['nullable', 'string', 'max:2048'],
|
|
|
'link_h5' => ['nullable', 'string', 'max:2048'],
|
|
|
- 'type' => ['required', 'in:pc,app'],
|
|
|
+ 'type' => ['required_without:types', 'nullable', 'in:pc,app'],
|
|
|
+ 'types' => ['sometimes', 'required', 'array', 'list', 'max:2'],
|
|
|
+ 'types.*' => ['bail', 'required', 'string', 'in:pc,app', 'distinct:strict'],
|
|
|
'sort' => ['nullable', 'integer'],
|
|
|
'lang' => ['required'],
|
|
|
'status' => ['sometimes', 'integer', 'in:0,1'],
|
|
|
'manual_status' => ['nullable', 'integer', 'in:0,1'],
|
|
|
- ], ['click_type.in' => '点击方式仅支持无链接、跳转活动、外站链接、站内相对路径']);
|
|
|
+ ], [
|
|
|
+ 'click_type.in' => '点击方式仅支持无链接、跳转活动、外站链接、站内相对路径',
|
|
|
+ 'types.required' => '请至少选择一个类型',
|
|
|
+ 'types.*.in' => '类型仅支持 APP 和 PC',
|
|
|
+ ]);
|
|
|
$id = $params['id'] ?? null;
|
|
|
$banner = $id === null ? new BannerModel() : BannerModel::where('id', $id)->lockForUpdate()->first();
|
|
|
if (!$banner) throw new Exception('数据不存在', HttpStatus::CUSTOM_ERROR);
|
|
|
@@ -152,6 +158,7 @@ class Banner extends Controller
|
|
|
// Both the row button and the editor write status; a stale compatibility alias must not override it.
|
|
|
$manualStatus = $params['status'] ?? $params['manual_status'] ?? $manualStatus;
|
|
|
}
|
|
|
+ $types = $params['types'] ?? [$params['type']];
|
|
|
$banner->fill([
|
|
|
'title' => $params['title'],
|
|
|
'image' => Util::replacePartInUrl($params['image']),
|
|
|
@@ -159,7 +166,7 @@ class Banner extends Controller
|
|
|
'link' => $links['link'],
|
|
|
'link_pc' => $links['link_pc'],
|
|
|
'link_h5' => $links['link_h5'],
|
|
|
- 'type' => $params['type'],
|
|
|
+ 'type' => count($types) === 2 ? BannerModel::TYPE_BOTH : $types[0],
|
|
|
'sort' => array_key_exists('sort', $params) ? ($params['sort'] ?? 0) : ($banner->sort ?? 0),
|
|
|
'lang' => $params['lang'],
|
|
|
'status' => $manualStatus,
|