mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 20:17:24 +08:00
add medal max allow wear number
This commit is contained in:
@@ -127,6 +127,10 @@ class EditSetting extends Page implements Forms\Contracts\HasForms
|
|||||||
->integer()
|
->integer()
|
||||||
->label(__('label.setting.system.change_username_min_interval_in_days'))
|
->label(__('label.setting.system.change_username_min_interval_in_days'))
|
||||||
,
|
,
|
||||||
|
Forms\Components\TextInput::make('system.maximum_number_of_medals_can_be_worn')
|
||||||
|
->integer()
|
||||||
|
->label(__('label.setting.system.maximum_number_of_medals_can_be_worn'))
|
||||||
|
,
|
||||||
])->columns(2);
|
])->columns(2);
|
||||||
|
|
||||||
$tabs = apply_filter('nexus_setting_tabs', $tabs);
|
$tabs = apply_filter('nexus_setting_tabs', $tabs);
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace App\Repositories;
|
namespace App\Repositories;
|
||||||
|
|
||||||
|
use App\Exceptions\NexusException;
|
||||||
use App\Models\Medal;
|
use App\Models\Medal;
|
||||||
|
use App\Models\Setting;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\UserMedal;
|
use App\Models\UserMedal;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
@@ -99,17 +101,23 @@ class MedalRepository extends BaseRepository
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
$statusCaseWhens = $priorityCaseWhens = $idArr = [];
|
$statusCaseWhens = $priorityCaseWhens = $idArr = [];
|
||||||
|
$wearCount = 0;
|
||||||
foreach ($validMedals as $medal) {
|
foreach ($validMedals as $medal) {
|
||||||
$id = $medal->pivot->id;
|
$id = $medal->pivot->id;
|
||||||
$idArr[] = $id;
|
$idArr[] = $id;
|
||||||
if (isset($userMedalData[$id]['status'])) {
|
if (isset($userMedalData[$id]['status'])) {
|
||||||
$status = UserMedal::STATUS_WEARING;
|
$status = UserMedal::STATUS_WEARING;
|
||||||
|
$wearCount++;
|
||||||
} else {
|
} else {
|
||||||
$status = UserMedal::STATUS_NOT_WEARING;
|
$status = UserMedal::STATUS_NOT_WEARING;
|
||||||
}
|
}
|
||||||
$statusCaseWhens[] = sprintf('when `id` = %s then %s', $id, $status);
|
$statusCaseWhens[] = sprintf('when `id` = %s then %s', $id, $status);
|
||||||
$priorityCaseWhens[] = sprintf('when `id` = %s then %s', $id, $userMedalData[$id]['priority'] ?? 0);
|
$priorityCaseWhens[] = sprintf('when `id` = %s then %s', $id, $userMedalData[$id]['priority'] ?? 0);
|
||||||
}
|
}
|
||||||
|
$maxWearAllow = Setting::get('system.maximum_number_of_medals_can_be_worn');
|
||||||
|
if ($maxWearAllow && $wearCount > $maxWearAllow) {
|
||||||
|
throw new NexusException(nexus_trans('medal.max_allow_wearing', ['count' => $maxWearAllow]));
|
||||||
|
}
|
||||||
$sql = sprintf(
|
$sql = sprintf(
|
||||||
'update user_medals set `status` = case %s end, `priority` = case %s end where id in (%s)',
|
'update user_medals set `status` = case %s end, `priority` = case %s end where id in (%s)',
|
||||||
implode(' ', $statusCaseWhens), implode(' ', $priorityCaseWhens), implode(',', $idArr)
|
implode(' ', $statusCaseWhens), implode(' ', $priorityCaseWhens), implode(',', $idArr)
|
||||||
|
|||||||
@@ -438,5 +438,6 @@ return array (
|
|||||||
'system' => [
|
'system' => [
|
||||||
'change_username_min_interval_in_days' => '365',
|
'change_username_min_interval_in_days' => '365',
|
||||||
'change_username_card_allow_characters_outside_the_alphabets' => 'no',
|
'change_username_card_allow_characters_outside_the_alphabets' => 'no',
|
||||||
|
'maximum_number_of_medals_can_be_worn' => 3,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -84,7 +84,8 @@ return [
|
|||||||
'system' => [
|
'system' => [
|
||||||
'tab_header' => 'System',
|
'tab_header' => 'System',
|
||||||
'change_username_card_allow_characters_outside_the_alphabets' => 'Does the name change card allow characters other than English letters',
|
'change_username_card_allow_characters_outside_the_alphabets' => 'Does the name change card allow characters other than English letters',
|
||||||
'change_username_min_interval_in_days' => 'the minimum interval days of Change user name',
|
'change_username_min_interval_in_days' => 'The minimum interval days of Change user name',
|
||||||
|
'maximum_number_of_medals_can_be_worn' => 'Maximum number of medals that can be worn',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'user' => [
|
'user' => [
|
||||||
|
|||||||
@@ -43,4 +43,5 @@ return [
|
|||||||
'inventory_empty' => 'Inventory empty',
|
'inventory_empty' => 'Inventory empty',
|
||||||
'gift_btn' => 'Gift',
|
'gift_btn' => 'Gift',
|
||||||
'confirm_to_gift' => 'Confirm to gift to user ',
|
'confirm_to_gift' => 'Confirm to gift to user ',
|
||||||
|
'max_allow_wearing' => 'A maximum of :count medals can be worn at the same time',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ return [
|
|||||||
'tab_header' => '系统',
|
'tab_header' => '系统',
|
||||||
'change_username_card_allow_characters_outside_the_alphabets' => '改名卡是否允许英文字母外的字符',
|
'change_username_card_allow_characters_outside_the_alphabets' => '改名卡是否允许英文字母外的字符',
|
||||||
'change_username_min_interval_in_days' => '修改用户名最小间隔天数',
|
'change_username_min_interval_in_days' => '修改用户名最小间隔天数',
|
||||||
|
'maximum_number_of_medals_can_be_worn' => '勋章最大可佩戴数',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'user' => [
|
'user' => [
|
||||||
|
|||||||
@@ -43,4 +43,5 @@ return [
|
|||||||
'inventory_empty' => '库存不足',
|
'inventory_empty' => '库存不足',
|
||||||
'gift_btn' => '赠送',
|
'gift_btn' => '赠送',
|
||||||
'confirm_to_gift' => '确定要赠送给用户 ',
|
'confirm_to_gift' => '确定要赠送给用户 ',
|
||||||
|
'max_allow_wearing' => '最多允许同时佩戴 :count 个勋章',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ return [
|
|||||||
'tab_header' => '系統',
|
'tab_header' => '系統',
|
||||||
'change_username_card_allow_characters_outside_the_alphabets' => '改名卡是否允許英文字母外的字符',
|
'change_username_card_allow_characters_outside_the_alphabets' => '改名卡是否允許英文字母外的字符',
|
||||||
'change_username_min_interval_in_days' => '修改用戶名最小間隔天數',
|
'change_username_min_interval_in_days' => '修改用戶名最小間隔天數',
|
||||||
|
'maximum_number_of_medals_can_be_worn' => '勛章最大可佩戴數',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'user' => [
|
'user' => [
|
||||||
|
|||||||
@@ -43,4 +43,5 @@ return [
|
|||||||
'inventory_empty' => '庫存不足',
|
'inventory_empty' => '庫存不足',
|
||||||
'gift_btn' => '贈送',
|
'gift_btn' => '贈送',
|
||||||
'confirm_to_gift' => '確定要贈送給用戶 ',
|
'confirm_to_gift' => '確定要贈送給用戶 ',
|
||||||
|
'max_allow_wearing' => '最多允許同時佩戴 :count 個勛章',
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user