|
|
|
|
@ -99,16 +99,58 @@ class DayCutService
|
|
|
|
|
return ['status'=>true,'msg'=>$msg];
|
|
|
|
|
}
|
|
|
|
|
private static function processMemberDayCut($member, $Carbon_day, $daysToAdd, $cunkuan_rate, $day){
|
|
|
|
|
$transactions = DB::table("transactions")->where([ //查找未计算利息的交易
|
|
|
|
|
"member_id" => $member->id,
|
|
|
|
|
"is_del" => 0,
|
|
|
|
|
"status" => 3,
|
|
|
|
|
"is_interest_eligible" => 0
|
|
|
|
|
])->whereIn("type",[1,3])->orderBy("verify_time","asc")->get();
|
|
|
|
|
// 查询1:已审核通过的交易(status=3)——包括充值(type=1)和提现(type=3)
|
|
|
|
|
$transactions1 = DB::table("transactions")
|
|
|
|
|
->where("member_id", $member->id)
|
|
|
|
|
->where("is_del", 0)
|
|
|
|
|
->where("status", 3)
|
|
|
|
|
->where("is_interest_eligible", 0)
|
|
|
|
|
->whereIn("type", [1, 3])
|
|
|
|
|
->orderBy("verify_time", "asc") // 这里用 verify_time 排序没问题
|
|
|
|
|
->get();
|
|
|
|
|
|
|
|
|
|
// 查询2:提现申请(type=3, status=1)——因系统在申请时已扣款并需立即止息
|
|
|
|
|
$transactions2 = DB::table("transactions")
|
|
|
|
|
->where("member_id", $member->id)
|
|
|
|
|
->where("is_del", 0)
|
|
|
|
|
->where("status", 1)
|
|
|
|
|
->where("type", 3)
|
|
|
|
|
->where("is_interest_eligible", 0)
|
|
|
|
|
->orderBy("created_at", "asc") // 👈 关键:这里按 created_at 排序!
|
|
|
|
|
->get();
|
|
|
|
|
|
|
|
|
|
// 合并后统一按“实际生效时间”排序(需自定义)
|
|
|
|
|
$transactions = $transactions1->merge($transactions2);
|
|
|
|
|
|
|
|
|
|
// 自定义排序:status=1 用 created_at,其他用 verify_time
|
|
|
|
|
$transactions = $transactions->sortBy(function ($tx) {
|
|
|
|
|
if ($tx->type == 3 && $tx->status == 1) {
|
|
|
|
|
return $tx->created_at;
|
|
|
|
|
}
|
|
|
|
|
return $tx->verify_time;
|
|
|
|
|
})->values();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$member_interest_balance = (string)$member->interest_balance;//用户表计息本金余额
|
|
|
|
|
foreach($transactions as $transaction){
|
|
|
|
|
Log::info("处理交易 - 用户ID: {$member->id}, 交易ID: {$transaction->id}, 审核时间: {$transaction->verify_time}, 类型: {$transaction->type}");
|
|
|
|
|
$shenHeDate_n = Carbon::parse($transaction->verify_time)->startOfDay()->addDays($daysToAdd);
|
|
|
|
|
if ($transaction->type == 3 && $transaction->status == 1) {
|
|
|
|
|
// 提现申请:用 created_at 作为起息/止息基准
|
|
|
|
|
$baseTime = $transaction->created_at;
|
|
|
|
|
} else {
|
|
|
|
|
// 充值(type=1, status=3)或其他成功交易:用 verify_time
|
|
|
|
|
$baseTime = $transaction->verify_time;
|
|
|
|
|
}
|
|
|
|
|
if (empty($baseTime)) {
|
|
|
|
|
Log::warning("交易缺少生效时间,跳过处理", [
|
|
|
|
|
'member_id' => $member->id,
|
|
|
|
|
'transaction_id' => $transaction->id,
|
|
|
|
|
'type' => $transaction->type,
|
|
|
|
|
'status' => $transaction->status,
|
|
|
|
|
]);
|
|
|
|
|
continue; // 跳过这条异常数据
|
|
|
|
|
}
|
|
|
|
|
Log::info("处理交易 - 用户ID: {$member->id}, 交易ID: {$transaction->id}, 生效时间: {$baseTime}, 类型: {$transaction->type}, 状态: {$transaction->status}");
|
|
|
|
|
$shenHeDate_n = Carbon::parse($baseTime)->startOfDay()->addDays($daysToAdd);
|
|
|
|
|
$trans_amount= (string)$transaction->amount; //本笔流水金额
|
|
|
|
|
|
|
|
|
|
if($transaction->type == 1){//充值
|
|
|
|
|
|