修复:单次上限三态逻辑(null=不限/-1=不限/0=禁止/正整数=有上限)

frame.blade.php:
- max_reward=null → myMaxReward=-1(不限,有权限)
- max_reward=0   → myMaxReward=0(禁止发放)
- max_reward=N   → myMaxReward=N(有具体上限)

user-actions.blade.php:
- 按钮显示条件:myMaxReward !== 0(-1 和正整数都显示)
- 面板上限文字:-1 显示「不限」,正整数显示具体数值
- sendReward 校验:0=禁止阻断,-1=不限跳过上限校验,N=有上限
- 输入框 :max:-1 时上限 999999(实际不限),N 时上限 N
This commit is contained in:
2026-03-01 11:39:28 +08:00
parent 57f515e2eb
commit 8dcf23d7e4
2 changed files with 19 additions and 6 deletions
+5 -1
View File
@@ -46,7 +46,11 @@
chatBotClearUrl: "{{ route('chatbot.clear') }}", chatBotClearUrl: "{{ route('chatbot.clear') }}",
chatBotEnabled: {{ \App\Models\Sysparam::getValue('chatbot_enabled', '0') === '1' ? 'true' : 'false' }}, chatBotEnabled: {{ \App\Models\Sysparam::getValue('chatbot_enabled', '0') === '1' ? 'true' : 'false' }},
hasPosition: {{ Auth::user()->activePosition || Auth::user()->user_level >= $superLevel ? 'true' : 'false' }}, hasPosition: {{ Auth::user()->activePosition || Auth::user()->user_level >= $superLevel ? 'true' : 'false' }},
myMaxReward: {{ Auth::user()->activePosition?->position?->max_reward ?? 0 }}, myMaxReward: @php
$pos = Auth::user()->activePosition?->position;
// -1 = 有权限但无上限(null),0 = 禁止,正整数 = 有具体上限
echo $pos ? ($pos->max_reward === null ? -1 : (int) $pos->max_reward) : 0;
@endphp,
appointPositionsUrl: "{{ route('chat.appoint.positions') }}", appointPositionsUrl: "{{ route('chat.appoint.positions') }}",
appointUrl: "{{ route('chat.appoint.appoint') }}", appointUrl: "{{ route('chat.appoint.appoint') }}",
revokeUrl: "{{ route('chat.appoint.revoke') }}", revokeUrl: "{{ route('chat.appoint.revoke') }}",
@@ -473,7 +473,13 @@
this.$alert('请输入有效的奖励金额', '提示', '#f59e0b'); this.$alert('请输入有效的奖励金额', '提示', '#f59e0b');
return; return;
} }
if (amount > maxOnce) { // 0 = 禁止(前端按钮不显示,此处二次保护)
if (maxOnce === 0) {
this.$alert('你的职务没有奖励发放权限', '无权限', '#cc4444');
return;
}
// -1 = 不限,跳过上限校验;正整数 = 有具体上限
if (maxOnce > 0 && amount > maxOnce) {
this.$alert(`单次奖励上限为 ${maxOnce} 金币`, '超出上限', '#cc4444'); this.$alert(`单次奖励上限为 ${maxOnce} 金币`, '超出上限', '#cc4444');
return; return;
} }
@@ -674,8 +680,8 @@
🎁 送礼物 🎁 送礼物
</button> </button>
{{-- 送金币按钮:仅职务持有者且有 max_reward 时显示 --}} {{-- 送金币按钮:有在职职务且 max_reward 不为 00=禁止,-1=不限,正数=有上限) --}}
<button x-show="window.chatContext?.myMaxReward > 0" <button x-show="window.chatContext?.myMaxReward !== 0"
style="flex:1; padding: 7px 10px; border-radius: 5px; font-size: 12px; font-weight: bold; cursor: pointer; style="flex:1; padding: 7px 10px; border-radius: 5px; font-size: 12px; font-weight: bold; cursor: pointer;
background: linear-gradient(135deg,#f59e0b,#d97706); color:#fff; border:none;" background: linear-gradient(135deg,#f59e0b,#d97706); color:#fff; border:none;"
x-on:click="showRewardPanel = !showRewardPanel; showGiftPanel = false;"> x-on:click="showRewardPanel = !showRewardPanel; showGiftPanel = false;">
@@ -742,7 +748,9 @@
style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;"> style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;">
<span style="font-size: 13px; color: #92400e; font-weight: bold;">🪙 发放奖励金币</span> <span style="font-size: 13px; color: #92400e; font-weight: bold;">🪙 发放奖励金币</span>
<span style="font-size: 11px; color: #b45309;"> <span style="font-size: 11px; color: #b45309;">
单次上限:<b x-text="window.chatContext?.myMaxReward ?? 0"></b> 金币 单次上限:<b
x-text="window.chatContext?.myMaxReward === -1 ? '不限' : (window.chatContext?.myMaxReward ?? 0)"></b>
<span x-show="window.chatContext?.myMaxReward !== -1"> 金币</span>
</span> </span>
<button x-on:click="showRewardPanel = false" <button x-on:click="showRewardPanel = false"
style="background: none; border: none; color: #94a3b8; cursor: pointer; font-size: 18px; line-height: 1;">×</button> style="background: none; border: none; color: #94a3b8; cursor: pointer; font-size: 18px; line-height: 1;">×</button>
@@ -750,7 +758,8 @@
<div style="display: flex; gap: 8px; align-items: center;"> <div style="display: flex; gap: 8px; align-items: center;">
<input type="number" x-model.number="rewardAmount" :min="1" <input type="number" x-model.number="rewardAmount" :min="1"
:max="window.chatContext?.myMaxReward ?? 9999" placeholder="输入金额" :max="window.chatContext?.myMaxReward > 0 ? window.chatContext.myMaxReward : 999999"
placeholder="输入金额"
style="flex:1; height: 36px; padding: 0 10px; border: 1px solid #fcd34d; style="flex:1; height: 36px; padding: 0 10px; border: 1px solid #fcd34d;
border-radius: 6px; font-size: 14px; color: #92400e; background: #fff; border-radius: 6px; font-size: 14px; color: #92400e; background: #fff;
outline: none; box-sizing: border-box;"> outline: none; box-sizing: border-box;">