feat: 临时调整马豆结算与兑换券释放为1分钟执行一次

这个提交包含在:
chen
2026-09-18 10:42:38 +08:00
父节点 813a36c908
当前提交 195a098101
共有 9 个文件被更改,包括 428 次插入 和 10 次删除

查看文件

@@ -144,7 +144,8 @@ class VoucherService
return null;
}
$daily = round($total / $days, 2);
$startDate = date('Y-m-d', strtotime('+1 day', $this->orderTime($order)));
// 临时模式:当天立即生效起算,支持 1 分钟释放联调
$startDate = date('Y-m-d', $this->orderTime($order));
$plan = VoucherPlan::create([
'user_id' => $buyerId,
@@ -183,6 +184,73 @@ class VoucherService
return $plan;
}
/**
* 临时分钟级释放兑换券:每 1 分钟对所有释放中的计划释放一期
*
* @return float 本次释放总金额
*/
public function releaseMinute()
{
$plans = VoucherPlan::where('status', 1)->select();
$totalReleased = 0;
foreach ($plans as $plan) {
if ($plan->released_days >= $plan->total_days || bccomp((string) $plan->released_amount, (string) $plan->total_amount, 2) >= 0) {
$plan->status = 2;
$plan->save();
continue;
}
$leftDays = $plan->total_days - $plan->released_days;
if ($leftDays <= 1) {
$amount = round((float) $plan->total_amount - (float) $plan->released_amount, 2);
$plan->status = 2;
} else {
$amount = (float) $plan->daily_amount;
}
if ($amount <= 0) {
$plan->status = 2;
$plan->save();
continue;
}
$plan->released_amount = round((float) $plan->released_amount + $amount, 2);
$plan->released_days += 1;
if (bccomp((string) $plan->released_amount, (string) $plan->total_amount, 2) >= 0) {
$plan->status = 2;
}
$plan->save();
$agent = AgentModel::where('user_id', $plan->user_id)->find();
if ($agent) {
$agent->setInc('voucher_released', $amount);
}
// 唯一负数 order_id 规避与历史冲突;settle_date 设为 NULL 规避 uk_daily_user_type 唯一索引
$virtualOrderId = -(intval($plan->id) * 1000 + (intval($plan->released_days) % 1000));
PartnerRewardService::write([
'order_id' => $virtualOrderId,
'buyer_id' => $plan->user_id,
'user_id' => $plan->user_id,
'role' => 'taster',
'reward_type' => 'voucher_release',
'amount' => $amount,
'base_amount' => $amount,
'settle_date' => null,
'ext' => [
'formula' => "兑换券释放 {$amount}(第{$plan->released_days}/{$plan->total_days}期)",
'plan_id' => $plan->id,
'order_id' => $plan->order_id,
'released_days' => $plan->released_days,
],
'status' => 1,
]);
$totalReleased = bcadd((string) $totalReleased, (string) $amount, 2);
}
return (float) $totalReleased;
}
public function releaseByDate($settleDate)
{
$plans = VoucherPlan::where('status', 1)