离婚流程全面升级:①发起方专属确认弹窗(含对方拒绝后果+魅力/金币惩罚实时值)②被申请方三选弹窗(同意/不同意/稍后)③不同意=强制离婚申请人赔一半金币④所有惩罚数值从后台实时查询
This commit is contained in:
@@ -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, // 不同意→强制,申请方受此惩罚
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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} 枚金币给你,婚姻已解除。"];
|
||||
}
|
||||
|
||||
/**
|
||||
* 强制离婚(单方立即生效,发起方金币全转对方)。
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user