diff --git a/app/Events/MarriageDivorceRequested.php b/app/Events/MarriageDivorceRequested.php index ac45755..6892d09 100644 --- a/app/Events/MarriageDivorceRequested.php +++ b/app/Events/MarriageDivorceRequested.php @@ -58,6 +58,8 @@ class MarriageDivorceRequested implements ShouldBroadcastNow // 读取协议离婚魅力惩罚供前端展示 $penalty = (int) \App\Models\MarriageConfig::where('key', 'divorce_mutual_charm')->value('value'); + // 读取强制离婚魅力惩罚(被拒=强制离婚时申请方受此惩罚) + $forcedPenalty = (int) \App\Models\MarriageConfig::where('key', 'divorce_forced_charm')->value('value'); return [ 'marriage_id' => $this->marriage->id, @@ -66,6 +68,7 @@ class MarriageDivorceRequested implements ShouldBroadcastNow 'timeout_hours' => 72, 'requested_at' => $this->marriage->divorce_requested_at, 'mutual_charm_penalty' => $penalty, // 协议离婚双方各扣魅力 + 'forced_charm_penalty' => $forcedPenalty, // 不同意→强制,申请方受此惩罚 ]; } diff --git a/app/Http/Controllers/MarriageController.php b/app/Http/Controllers/MarriageController.php index 876f4ba..bb678a5 100644 --- a/app/Http/Controllers/MarriageController.php +++ b/app/Http/Controllers/MarriageController.php @@ -20,6 +20,7 @@ use App\Events\MarriageProposed; use App\Events\MarriageRejected; use App\Models\Marriage; use App\Models\UserPurchase; +use App\Services\MarriageConfigService; use App\Services\MarriageService; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -28,8 +29,23 @@ class MarriageController extends Controller { public function __construct( private readonly MarriageService $marriage, + private readonly MarriageConfigService $config, ) {} + /** + * 获取离婚相关惩罚配置(供前端展示风险提示)。 + * 返回协议离婚魅力惩罚、强制离婚魅力惩罚及各冷静期天数。 + */ + public function divorceConfig(): JsonResponse + { + return response()->json([ + 'mutual_charm_penalty' => (int) $this->config->get('divorce_mutual_charm', 100), + 'forced_charm_penalty' => (int) $this->config->get('divorce_forced_charm', 300), + 'mutual_cooldown_days' => (int) $this->config->get('divorce_mutual_cooldown', 70), + 'forced_cooldown_days' => (int) $this->config->get('divorce_forced_cooldown', 90), + ]); + } + /** * 获取当前用户的婚姻状态(名片/用户列表用)。 */ @@ -221,4 +237,20 @@ class MarriageController extends Controller return response()->json($result); } + + /** + * 拒绝协议离婚申请(被申请方选择不同意 = 视为强制离婚)。 + * 申请人赔偿一半金币给对方,婚姻以 forced 类型解除。 + */ + public function rejectDivorce(Request $request, Marriage $marriage): JsonResponse + { + $result = $this->marriage->rejectDivorce($marriage, $request->user()); + + if ($result['ok']) { + $marriage->refresh(); + broadcast(new MarriageDivorced($marriage, 'forced')); + } + + return response()->json($result); + } } diff --git a/app/Services/MarriageService.php b/app/Services/MarriageService.php index 94a8b00..e75ed59 100644 --- a/app/Services/MarriageService.php +++ b/app/Services/MarriageService.php @@ -304,6 +304,69 @@ class MarriageService return ['ok' => true, 'message' => '协议离婚已完成。']; } + /** + * 被申请方拒绝协议离婚申请(等同于强制离婚)。 + * + * 规则: + * - 婚姻立即以 forced 类型解除 + * - 申请人(divorcer)被扣除 divorce_forced_charm 点魅力作为惩罚 + * - 申请人一半金币赔偿给被申请方 + * - 申请人进入强制离婚冷静期 + * + * @param Marriage $marriage 婚姻记录 + * @param User $respondent 被申请方(拒绝者) + * @return array{ok: bool, message: string} + */ + public function rejectDivorce(Marriage $marriage, User $respondent): array + { + if ($marriage->status !== 'married' || $marriage->divorce_type !== 'mutual') { + return ['ok' => false, 'message' => '没有待处理的离婚申请。']; + } + if ($marriage->divorcer_id === $respondent->id) { + return ['ok' => false, 'message' => '不能拒绝自己发起的离婚申请。']; + } + if (! $marriage->involves($respondent->id)) { + return ['ok' => false, 'message' => '无权操作此婚姻。']; + } + + // 申请方(被拒的一方) + $divorcer = $marriage->user_id === $marriage->divorcer_id + ? $marriage->user + : $marriage->partner; + + DB::transaction(function () use ($marriage, $divorcer, $respondent) { + $charmPenalty = $this->config->get('divorce_forced_charm', 300); + + // 申请人扣魅力 + $this->currency->change($divorcer, 'charm', -$charmPenalty, CurrencySource::DIVORCE_CHARM, '拒绝离婚时视为强制离婚,扣除魅力惩罚'); + + // 申请人一半金币赔偿给对方 + $divorcerJjb = $divorcer->fresh()->jjb ?? 0; + if ($divorcerJjb > 0) { + $half = (int) floor($divorcerJjb / 2); + if ($half > 0) { + $this->currency->change($divorcer, 'gold', -$half, CurrencySource::FORCED_DIVORCE_TRANSFER, "协议离婚被拒,赔偿一半金币给 {$respondent->username}"); + $this->currency->change($respondent, 'gold', $half, CurrencySource::FORCED_DIVORCE_TRANSFER, "对方协议离婚被拒,获得 {$divorcer->username} 一半金币赔偿"); + } + } + + // 更新婚姻为强制离婚 + $marriage->update([ + 'status' => 'divorced', + 'divorce_type' => 'forced', + 'divorcer_id' => $divorcer->id, + 'divorced_at' => now(), + 'intimacy' => 0, + 'level' => 1, + ]); + }); + + $divorcerJjb = $divorcer->fresh()->jjb ?? 0; + $half = (int) floor(($divorcer->jjb ?? 0) / 2); + + return ['ok' => true, 'message' => "你已拒绝离婚申请,视为强制离婚,{$divorcer->username} 赔偿了 {$half} 枚金币给你,婚姻已解除。"]; + } + /** * 强制离婚(单方立即生效,发起方金币全转对方)。 * diff --git a/resources/views/chat/frame.blade.php b/resources/views/chat/frame.blade.php index 14f0b7d..5d0c13b 100644 --- a/resources/views/chat/frame.blade.php +++ b/resources/views/chat/frame.blade.php @@ -74,6 +74,8 @@ rejectUrl: (id) => `/marriage/${id}/reject`, divorceUrl: (id) => `/marriage/${id}/divorce`, confirmDivorceUrl: (id) => `/marriage/${id}/confirm-divorce`, + rejectDivorceUrl: (id) => `/marriage/${id}/reject-divorce`, + divorceConfigUrl: '/marriage/divorce-config', weddingTiersUrl: "/wedding/tiers", weddingSetupUrl: (id) => `/wedding/${id}/setup`, claimEnvelopeUrl: (id, ceremonyId) => `/wedding/${id}/claim`, diff --git a/resources/views/chat/partials/marriage-modals.blade.php b/resources/views/chat/partials/marriage-modals.blade.php index 1c523a5..0361119 100644 --- a/resources/views/chat/partials/marriage-modals.blade.php +++ b/resources/views/chat/partials/marriage-modals.blade.php @@ -340,6 +340,181 @@ +{{-- ═══════════ 3.5. 发起离婚确认弹窗(发起方专用 + 后果说明) ═══════════ --}} +