feat: 信用IEO系统 — 授信+申购+还款+逾期+后台
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\CreditIeoOrder;
|
||||
use App\CreditLine;
|
||||
use App\AccountLog;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AutoCreditOverdue extends Command
|
||||
{
|
||||
protected $signature = "auto_credit_overdue";
|
||||
protected $description = "标记超期信用IEO订单为逾期";
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$orders = CreditIeoOrder::where('status', 0)->get();
|
||||
$marked = 0;
|
||||
|
||||
foreach ($orders as $order) {
|
||||
$line = CreditLine::find($order->credit_line_id);
|
||||
if (!$line) continue;
|
||||
|
||||
$cycleDays = intval($line->cycle_days) ?: 15;
|
||||
$createdTs = strtotime((string)$order->created_at);
|
||||
if (!$createdTs) continue;
|
||||
|
||||
$elapsed = (int)ceil((time() - $createdTs) / 86400);
|
||||
if ($elapsed <= $cycleDays) continue;
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$affected = CreditIeoOrder::where('id', $order->id)
|
||||
->where('status', 0)
|
||||
->update(['status' => 3]);
|
||||
|
||||
if ($affected > 0) {
|
||||
$maxInterestDays = min($elapsed, $cycleDays * 3);
|
||||
$interest = sprintf("%.6f", $order->amount * $line->daily_rate * $maxInterestDays);
|
||||
|
||||
CreditIeoOrder::where('id', $order->id)
|
||||
->update(['interest' => $interest]);
|
||||
|
||||
AccountLog::insertLog(
|
||||
['user_id' => $order->user_id, 'value' => 0, 'info' => 'Credit IEO overdue #' . $order->id, 'type' => AccountLog::MICRO_TRADE_CLOSE_SETTLE, 'currency' => 3],
|
||||
['balance_type' => 1, 'wallet_id' => 0, 'lock_type' => 0, 'before' => 0, 'change' => 0, 'after' => 0]
|
||||
);
|
||||
$marked++;
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
$this->error("Order #{$order->id} error: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if ($marked > 0) {
|
||||
$this->info("Marked {$marked} orders as overdue");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user