变更:修复求婚同意消息未收到问题,重构求婚流程支持直接选婚礼档位
This commit is contained in:
@@ -144,6 +144,66 @@ class WeddingService
|
||||
});
|
||||
}
|
||||
|
||||
// ──────────────────────────── 婚礼生命周期钩子 ───────────────────
|
||||
|
||||
/**
|
||||
* 将预先设置好的定时婚礼(因求婚冻结)转为即刻开始(解冻并记录消费)。
|
||||
*
|
||||
* @param WeddingCeremony $ceremony
|
||||
*/
|
||||
public function confirmCeremony(WeddingCeremony $ceremony): void
|
||||
{
|
||||
DB::transaction(function () use ($ceremony) {
|
||||
$marriage = $ceremony->marriage;
|
||||
$tierName = $ceremony->tier?->name ?? '婚礼';
|
||||
|
||||
if ($ceremony->ceremony_type === 'scheduled') {
|
||||
// 解除冻结,正式扣款记账
|
||||
if ($ceremony->groom_amount > 0) {
|
||||
$groom = clone $marriage->user;
|
||||
$marriage->user->decrement('frozen_jjb', $ceremony->groom_amount);
|
||||
$this->currency->change($groom, 'gold', 0, CurrencySource::WEDDING_ENV_SEND, "求婚成功,正式发红包({$tierName})");
|
||||
}
|
||||
if ($ceremony->partner_amount > 0) {
|
||||
$partner = clone $marriage->partner;
|
||||
$marriage->partner->decrement('frozen_jjb', $ceremony->partner_amount);
|
||||
$this->currency->change($partner, 'gold', 0, CurrencySource::WEDDING_ENV_SEND, "求婚成功,正式发红包({$tierName})");
|
||||
}
|
||||
|
||||
// 将类型转为即时开始
|
||||
$ceremony->update([
|
||||
'ceremony_type' => 'immediate',
|
||||
'ceremony_at' => now(),
|
||||
'expires_at' => now()->addHours($this->config->get('envelope_expire_hours', 24))
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤销由于求婚设置的婚礼,并且解冻/退还因为该婚礼冻结的金币。
|
||||
*
|
||||
* @param WeddingCeremony $ceremony
|
||||
*/
|
||||
public function cancelAndRefund(WeddingCeremony $ceremony): void
|
||||
{
|
||||
DB::transaction(function () use ($ceremony) {
|
||||
$ceremony->update(['status' => 'cancelled']);
|
||||
|
||||
if ($ceremony->ceremony_type === 'scheduled') {
|
||||
$marriage = $ceremony->marriage;
|
||||
if ($ceremony->groom_amount > 0) {
|
||||
$marriage->user?->decrement('frozen_jjb', $ceremony->groom_amount);
|
||||
$marriage->user?->increment('jjb', $ceremony->groom_amount);
|
||||
}
|
||||
if ($ceremony->partner_amount > 0) {
|
||||
$marriage->partner?->decrement('frozen_jjb', $ceremony->partner_amount);
|
||||
$marriage->partner?->increment('jjb', $ceremony->partner_amount);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ──────────────────────────── 触发婚礼 ────────────────────────────
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user