add medal max allow wear number

This commit is contained in:
xiaomlove
2023-01-30 14:47:02 +08:00
parent 2eaf5eabd1
commit 3edb283b62
9 changed files with 20 additions and 1 deletions

View File

@@ -127,6 +127,10 @@ class EditSetting extends Page implements Forms\Contracts\HasForms
->integer()
->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);
$tabs = apply_filter('nexus_setting_tabs', $tabs);

View File

@@ -1,7 +1,9 @@
<?php
namespace App\Repositories;
use App\Exceptions\NexusException;
use App\Models\Medal;
use App\Models\Setting;
use App\Models\User;
use App\Models\UserMedal;
use Carbon\Carbon;
@@ -99,17 +101,23 @@ class MedalRepository extends BaseRepository
return true;
}
$statusCaseWhens = $priorityCaseWhens = $idArr = [];
$wearCount = 0;
foreach ($validMedals as $medal) {
$id = $medal->pivot->id;
$idArr[] = $id;
if (isset($userMedalData[$id]['status'])) {
$status = UserMedal::STATUS_WEARING;
$wearCount++;
} else {
$status = UserMedal::STATUS_NOT_WEARING;
}
$statusCaseWhens[] = sprintf('when `id` = %s then %s', $id, $status);
$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(
'update user_medals set `status` = case %s end, `priority` = case %s end where id in (%s)',
implode(' ', $statusCaseWhens), implode(' ', $priorityCaseWhens), implode(',', $idArr)

View File

@@ -438,5 +438,6 @@ return array (
'system' => [
'change_username_min_interval_in_days' => '365',
'change_username_card_allow_characters_outside_the_alphabets' => 'no',
'maximum_number_of_medals_can_be_worn' => 3,
],
);

View File

@@ -84,7 +84,8 @@ return [
'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_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' => [

View File

@@ -43,4 +43,5 @@ return [
'inventory_empty' => 'Inventory empty',
'gift_btn' => 'Gift',
'confirm_to_gift' => 'Confirm to gift to user ',
'max_allow_wearing' => 'A maximum of :count medals can be worn at the same time',
];

View File

@@ -85,6 +85,7 @@ return [
'tab_header' => '系统',
'change_username_card_allow_characters_outside_the_alphabets' => '改名卡是否允许英文字母外的字符',
'change_username_min_interval_in_days' => '修改用户名最小间隔天数',
'maximum_number_of_medals_can_be_worn' => '勋章最大可佩戴数',
],
],
'user' => [

View File

@@ -43,4 +43,5 @@ return [
'inventory_empty' => '库存不足',
'gift_btn' => '赠送',
'confirm_to_gift' => '确定要赠送给用户 ',
'max_allow_wearing' => '最多允许同时佩戴 :count 个勋章',
];

View File

@@ -85,6 +85,7 @@ return [
'tab_header' => '系統',
'change_username_card_allow_characters_outside_the_alphabets' => '改名卡是否允許英文字母外的字符',
'change_username_min_interval_in_days' => '修改用戶名最小間隔天數',
'maximum_number_of_medals_can_be_worn' => '勛章最大可佩戴數',
],
],
'user' => [

View File

@@ -43,4 +43,5 @@ return [
'inventory_empty' => '庫存不足',
'gift_btn' => '贈送',
'confirm_to_gift' => '確定要贈送給用戶 ',
'max_allow_wearing' => '最多允許同時佩戴 :count 個勛章',
];