|
|
@@ -22,7 +22,7 @@ class MigrateFrozenRewards extends Command
|
|
|
{
|
|
|
private const LEGACY_TYPES = ['即充即送', '老用户回归'];
|
|
|
|
|
|
- protected $signature = 'wagering:migrate-frozen-rewards {--dry-run : 只统计不写入} {--member= : 只处理指定会员ID}';
|
|
|
+ protected $signature = 'wagering:migrate-frozen-rewards {--dry-run : 只统计不写入} {--member= : 只处理指定会员ID} {--wager-only : 不动冻结金额,只把进行中申请活动的剩余打码量计入统一打码量}';
|
|
|
protected $description = '把冻结中的活动奖励转入可用余额,并把未完成流水计入提现打码量';
|
|
|
|
|
|
/** @var array<int,true> 已匹配过的 wallet_bonus,避免同一笔充值的两条同额奖励共用一条流水要求 */
|
|
|
@@ -38,9 +38,10 @@ class MigrateFrozenRewards extends Command
|
|
|
return self::FAILURE;
|
|
|
}
|
|
|
$dryRun = (bool)$this->option('dry-run');
|
|
|
- foreach ($this->members() as $memberId) {
|
|
|
+ $wagerOnly = (bool)$this->option('wager-only');
|
|
|
+ foreach ($this->members($wagerOnly) as $memberId) {
|
|
|
try {
|
|
|
- DB::transaction(fn () => $this->migrateMember((string)$memberId, $dryRun), 3);
|
|
|
+ DB::transaction(fn () => $this->migrateMember((string)$memberId, $dryRun, $wagerOnly), 3);
|
|
|
} catch (\Throwable $e) {
|
|
|
++$this->stats['skipped'];
|
|
|
$this->warn("会员 {$memberId} 迁移失败:" . $e->getMessage());
|
|
|
@@ -53,11 +54,11 @@ class MigrateFrozenRewards extends Command
|
|
|
}
|
|
|
|
|
|
/** @return string[] */
|
|
|
- private function members(): array
|
|
|
+ private function members(bool $wagerOnly): array
|
|
|
{
|
|
|
if ($this->option('member')) return [(string)$this->option('member')];
|
|
|
- $ids = BalanceLog::where('type', 2)->where('frozen_status', 1)->whereIn('change_type', self::LEGACY_TYPES)->distinct()->pluck('member_id')->all();
|
|
|
- if (Schema::hasTable('promotion_rewards')) {
|
|
|
+ $ids = $wagerOnly ? [] : BalanceLog::where('type', 2)->where('frozen_status', 1)->whereIn('change_type', self::LEGACY_TYPES)->distinct()->pluck('member_id')->all();
|
|
|
+ if (!$wagerOnly && Schema::hasTable('promotion_rewards')) {
|
|
|
$ids = array_merge($ids, DB::table('promotion_rewards as r')->join('users as u', 'u.id', '=', 'r.user_id')
|
|
|
->where('r.status', 'locked')->distinct()->pluck('u.member_id')->all());
|
|
|
}
|
|
|
@@ -67,7 +68,7 @@ class MigrateFrozenRewards extends Command
|
|
|
return array_values(array_unique(array_map('strval', $ids)));
|
|
|
}
|
|
|
|
|
|
- private function migrateMember(string $memberId, bool $dryRun): void
|
|
|
+ private function migrateMember(string $memberId, bool $dryRun, bool $wagerOnly = false): void
|
|
|
{
|
|
|
$wallet = Wallet::where('member_id', $memberId)->lockForUpdate()->first();
|
|
|
if (!$wallet) throw new \RuntimeException('钱包不存在');
|
|
|
@@ -75,8 +76,9 @@ class MigrateFrozenRewards extends Command
|
|
|
$now = PromotionFacts::now();
|
|
|
$moved = '0'; $wager = '0'; $touched = false;
|
|
|
|
|
|
+ // --wager-only:旧冻结奖励留在冻结余额,继续由原有解冻逻辑处理
|
|
|
// 1) 旧版冻结返彩
|
|
|
- foreach (BalanceLog::where('member_id', $memberId)->where('type', 2)->where('frozen_status', 1)
|
|
|
+ if (!$wagerOnly) foreach (BalanceLog::where('member_id', $memberId)->where('type', 2)->where('frozen_status', 1)
|
|
|
->whereIn('change_type', self::LEGACY_TYPES)->orderBy('id')->lockForUpdate()->get() as $log) {
|
|
|
$key = 'balance_log:' . $log->id;
|
|
|
if ($this->done($memberId, $key)) continue;
|
|
|
@@ -103,7 +105,7 @@ class MigrateFrozenRewards extends Command
|
|
|
}
|
|
|
|
|
|
// 2) 新活动 locked 奖励
|
|
|
- if ($user && Schema::hasTable('promotion_rewards')) {
|
|
|
+ if (!$wagerOnly && $user && Schema::hasTable('promotion_rewards')) {
|
|
|
$facts = new PromotionFacts();
|
|
|
foreach (DB::table('promotion_rewards')->where('user_id', $user->id)->where('status', 'locked')->orderBy('id')->lockForUpdate()->get() as $reward) {
|
|
|
$key = 'promotion_reward:' . $reward->id;
|