feat: 信用IEO系统 — 授信+申购+还款+逾期+后台

This commit is contained in:
testadmin
2026-04-28 19:22:00 +08:00
parent 928d573b11
commit a323b7da8e
7 changed files with 650 additions and 0 deletions
@@ -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");
}
}
}
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class CreditIeoOrder extends Model
{
protected $table = 'credit_ieo_order';
protected $fillable = ['user_id','credit_line_id','project_id','amount','token_amount','status','repaid_amount','interest'];
public function user() { return $this->belongsTo(Users::class, 'user_id'); }
public function creditLine() { return $this->belongsTo(CreditLine::class, 'credit_line_id'); }
public function project() { return $this->belongsTo(IeoProject::class, 'project_id'); }
}
+11
View File
@@ -0,0 +1,11 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class CreditLine extends Model
{
protected $table = 'credit_line';
protected $fillable = ['user_id','total_amount','used_amount','available_amount','daily_rate','cycle_days','credit_score','status'];
public function user() { return $this->belongsTo(Users::class, 'user_id'); }
}
@@ -0,0 +1,113 @@
<?php
namespace App\Http\Controllers\Admin;
use App\CreditLine;
use App\CreditIeoOrder;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class CreditController extends Controller
{
public function index() { return view('manages.credit.index'); }
public function orderIndex() { return view('manages.credit.orders'); }
public function list(Request $request)
{
$query = CreditLine::query()
->leftJoin('users', 'credit_line.user_id', '=', 'users.id')
->select(
'credit_line.*',
'users.phone as user_phone',
'users.email as user_email'
);
$user_id = $request->input('user_id');
if ($user_id) $query->where('credit_line.user_id', $user_id);
$keyword = $request->input('keyword');
if ($keyword) {
$query->where(function ($q) use ($keyword) {
$q->where('users.phone', 'like', "%{$keyword}%")
->orWhere('users.email', 'like', "%{$keyword}%");
});
}
$data = $query->orderBy('credit_line.id', 'desc')->paginate($request->input('limit', 20));
$statusMap = ['0' => 'Disabled', '1' => 'Active'];
foreach ($data as $item) {
$item->status_text = $statusMap[$item->status] ?? '';
}
return $this->layuiData($data);
}
public function grant(Request $request)
{
$user_id = intval($request->input('user_id'));
$total_amount = floatval($request->input('total_amount'));
$daily_rate = floatval($request->input('daily_rate'));
$cycle_days = intval($request->input('cycle_days'));
$credit_score = intval($request->input('credit_score', 0));
$status = intval($request->input('status', 1));
if (!$user_id || $total_amount < 0 || $daily_rate < 0 || $cycle_days <= 0) {
return $this->error('Invalid params');
}
DB::beginTransaction();
try {
$line = CreditLine::where('user_id', $user_id)->lockForUpdate()->first();
if (!$line) {
CreditLine::create([
'user_id' => $user_id,
'total_amount' => $total_amount,
'used_amount' => 0,
'available_amount' => $total_amount,
'daily_rate' => $daily_rate,
'cycle_days' => $cycle_days,
'credit_score' => $credit_score,
'status' => $status,
]);
} else {
$used = floatval($line->used_amount);
if ($total_amount < $used) { DB::rollBack(); return $this->error('Total cannot be less than used'); }
$line->total_amount = $total_amount;
$line->available_amount = bc_sub($total_amount, $used, 6);
$line->daily_rate = $daily_rate;
$line->cycle_days = $cycle_days;
$line->credit_score = $credit_score;
$line->status = $status;
$line->save();
}
DB::commit();
return $this->success('OK');
} catch (\Exception $e) {
DB::rollBack();
return $this->error('System error');
}
}
public function orderList(Request $request)
{
$query = CreditIeoOrder::query()
->leftJoin('users', 'credit_ieo_order.user_id', '=', 'users.id')
->leftJoin('ieo_project', 'credit_ieo_order.project_id', '=', 'ieo_project.id')
->select(
'credit_ieo_order.*',
'users.phone as user_phone',
'users.email as user_email',
'ieo_project.name as project_name',
'ieo_project.symbol as symbol'
);
$status = $request->input('status');
if ($status !== null && $status !== '') $query->where('credit_ieo_order.status', intval($status));
$project_id = $request->input('project_id');
if ($project_id) $query->where('credit_ieo_order.project_id', $project_id);
$data = $query->orderBy('credit_ieo_order.id', 'desc')->paginate($request->input('limit', 20));
$statusMap = ['0' => 'Pending Repayment', '1' => 'Repaid', '2' => 'Overdue'];
foreach ($data as $item) {
$item->status_text = $statusMap[$item->status] ?? '';
}
return $this->layuiData($data);
}
}
@@ -0,0 +1,250 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Api\Controller;
use App\CreditLine;
use App\CreditIeoOrder;
use App\IeoProject;
use App\UsersWallet;
use App\AccountLog;
use Illuminate\Http\Request;
use App\Token;
use App\Users;
use Illuminate\Support\Facades\DB;
class CreditController extends Controller
{
public function dashboard(Request $request)
{
$user_id = Token::getUserIdByToken(Token::getToken());
$user = \App\Users::find($user_id);
if (!$user) return $this->error('Please login');
$line = CreditLine::where('user_id', $user->id)->first();
if (!$line) {
return $this->success([
'has_credit' => 0,
'total_amount' => '0.00',
'used_amount' => '0.00',
'available_amount' => '0.00',
'daily_rate' => '0.0000',
'cycle_days' => 0,
'credit_score' => 0,
'status' => 0,
]);
}
$line->has_credit = 1;
return $this->success($line);
}
public function creditSubscribe(Request $request)
{
$user_id = Token::getUserIdByToken(Token::getToken());
$user = \App\Users::find($user_id);
if (!$user) return $this->error('Please login');
$project_id = intval($request->input('project_id'));
$amount = floatval($request->input('amount'));
if (!$project_id || $amount <= 0) return $this->error('Invalid params');
$project = IeoProject::find($project_id);
if (!$project || $project->status != 1) return $this->error('IEO not active');
if ($amount < $project->min_buy) return $this->error('Min: ' . $project->min_buy . ' USDC');
if ($project->max_buy > 0 && $amount > $project->max_buy) return $this->error('Max: ' . $project->max_buy . ' USDC');
$existingNormal = DB::table('ieo_order')->where('user_id', $user->id)->where('project_id', $project_id)->where('status', '!=', 2)->exists();
if ($existingNormal) return $this->error('Already subscribed via normal IEO');
DB::beginTransaction();
try {
$line = CreditLine::where('user_id', $user->id)->lockForUpdate()->first();
if (!$line || $line->status != 1) { DB::rollBack(); return $this->error('No active credit line'); }
if ($line->available_amount < $amount) { DB::rollBack(); return $this->error('Insufficient credit'); }
$existingCredit = CreditIeoOrder::where('user_id', $user->id)->where('project_id', $project_id)->whereIn('status', [0, 1])->exists();
if ($existingCredit) { DB::rollBack(); return $this->error('Already subscribed via credit'); }
$line->available_amount = bc_sub($line->available_amount, $amount, 6);
$line->used_amount = bc_add($line->used_amount, $amount, 6);
$line->save();
$token_amount = $project->token_price > 0 ? sprintf("%.6f", $amount / $project->token_price) : 0;
$order = CreditIeoOrder::create([
'user_id' => $user->id,
'credit_line_id' => $line->id,
'project_id' => $project_id,
'amount' => $amount,
'token_amount' => $token_amount,
'status' => 0,
'repaid_amount' => 0,
'interest' => 0,
]);
AccountLog::insertLog(
['user_id' => $user->id, 'value' => -$amount, 'info' => 'Credit IEO subscribe #' . $project->name, 'type' => AccountLog::MICRO_TRADE_SUBMIT, 'currency' => 3],
['balance_type' => 1, 'wallet_id' => 0, 'lock_type' => 0, 'before' => bc_add($line->available_amount, $amount, 6), 'change' => -$amount, 'after' => $line->available_amount]
);
DB::commit();
return $this->success(['order_id' => $order->id, 'msg' => 'Credit subscription successful']);
} catch (\Exception $e) {
DB::rollBack();
return $this->error($e->getMessage());
}
}
public function myCreditOrders(Request $request)
{
$user_id = Token::getUserIdByToken(Token::getToken());
$user = \App\Users::find($user_id);
if (!$user) return $this->error('Please login');
$list = CreditIeoOrder::where('user_id', $user->id)
->with('project:id,name,symbol,token_price,listing_time,unlock_time')
->orderBy('id', 'desc')
->get();
$statusMap = ['0' => 'Pending Repayment', '1' => 'Repaid', '3' => 'Overdue'];
foreach ($list as $item) {
$item->status_text = $statusMap[$item->status] ?? '';
$line = $item->creditLine ?? CreditLine::find($item->credit_line_id);
$dailyRate = $line ? floatval($line->daily_rate) : 0;
$createdTs = strtotime((string)$item->created_at);
if (!$createdTs) $createdTs = time();
$days = max(1, (int)ceil((time() - $createdTs) / 86400));
$item->accrued_interest = sprintf('%.6f', $item->amount * $dailyRate * $days);
$item->repay_total = sprintf('%.6f', $item->amount + ($item->amount * $dailyRate * $days));
$item->days_elapsed = $days;
}
return $this->success($list);
}
public function repay(Request $request)
{
$user_id = Token::getUserIdByToken(Token::getToken());
$user = \App\Users::find($user_id);
if (!$user) return $this->error('Please login');
$order_id = intval($request->input('order_id'));
if (!$order_id) return $this->error('Invalid order');
DB::beginTransaction();
try {
$order = CreditIeoOrder::where('id', $order_id)->where('user_id', $user->id)->lockForUpdate()->first();
if (!$order) { DB::rollBack(); return $this->error('Order not found'); }
if ($order->status == 1) { DB::rollBack(); return $this->error('Already repaid'); }
$line = CreditLine::where('id', $order->credit_line_id)->lockForUpdate()->first();
if (!$line) { DB::rollBack(); return $this->error('Credit line missing'); }
$dailyRate = floatval($line->daily_rate);
$createdTs = strtotime((string)$order->created_at);
if (!$createdTs) $createdTs = time();
$days = max(1, (int)ceil((time() - $createdTs) / 86400));
$interest = sprintf('%.6f', $order->amount * $dailyRate * $days);
$total = bc_add($order->amount, $interest, 6);
$wallet = UsersWallet::where('user_id', $user->id)->where('currency', 3)->lockForUpdate()->first();
if (!$wallet || $wallet->legal_balance < $total) { DB::rollBack(); return $this->error('Insufficient balance to repay'); }
$before = $wallet->legal_balance;
$wallet->legal_balance = bc_sub($wallet->legal_balance, $total, 6);
$wallet->save();
AccountLog::insertLog(
['user_id' => $user->id, 'value' => -$total, 'info' => 'Credit IEO Repay #' . $order->id, 'type' => AccountLog::IEO_OPERATION, 'currency' => 3],
['balance_type' => 1, 'wallet_id' => $wallet->id, 'lock_type' => 0, 'before' => $before, 'change' => -$total, 'after' => $wallet->legal_balance]
);
$line->used_amount = max(0, bc_sub($line->used_amount, $order->amount, 6));
$line->available_amount = bc_add($line->available_amount, $order->amount, 6);
if ($line->available_amount > $line->total_amount) {
$line->available_amount = $line->total_amount;
}
$line->save();
$order->interest = $interest;
$order->repaid_amount = $total;
$order->status = 1;
$order->save();
if ($order->token_amount > 0) {
$project = \App\IeoProject::find($order->project_id);
if ($project) {
$tokenCurrency = \App\Currency::where('name', $project->symbol)->first();
if ($tokenCurrency) {
$tokenWallet = UsersWallet::where('user_id', $user->id)
->where('currency', $tokenCurrency->id)->lockForUpdate()->first();
if ($tokenWallet) {
$beforeToken = $tokenWallet->change_balance;
$tokenWallet->change_balance = bc_add($tokenWallet->change_balance, $order->token_amount, 6);
$tokenWallet->save();
AccountLog::insertLog(
['user_id' => $user->id, 'value' => $order->token_amount, 'info' => 'Credit IEO Token Unlock - ' . $project->name, 'type' => AccountLog::IEO_OPERATION, 'currency' => $tokenCurrency->id],
['balance_type' => 2, 'wallet_id' => $tokenWallet->id, 'lock_type' => 0, 'before' => $beforeToken, 'change' => $order->token_amount, 'after' => $tokenWallet->change_balance]
);
}
}
}
}
DB::commit();
return $this->success(['msg' => 'Repaid', 'total' => $total, 'interest' => $interest]);
} catch (\Exception $e) {
DB::rollBack();
return $this->error($e->getMessage());
}
}
public function repayAll(Request $request)
{
$user_id = Token::getUserIdByToken(Token::getToken());
$user = \App\Users::find($user_id);
if (!$user) return $this->error('Please login');
$credit = CreditLine::where('user_id', $user->id)->lockForUpdate()->first();
if (!$credit) return $this->error('No credit line');
$orders = CreditIeoOrder::where('user_id', $user->id)
->whereIn('status', [0, 3])
->get();
if ($orders->isEmpty()) return $this->error('No pending orders');
$totalRepay = 0;
foreach ($orders as $order) {
$days = max(1, ceil((time() - strtotime($order->created_at)) / 86400));
$interest = sprintf('%.6f', $order->amount * floatval($credit->daily_rate) * $days);
$totalRepay = bc_add($totalRepay, bc_add($order->amount, $interest, 6), 6);
}
$wallet = UsersWallet::where('user_id', $user->id)->where('currency', 3)->lockForUpdate()->first();
if (!$wallet || bc_comp($wallet->legal_balance, $totalRepay) < 0) {
return $this->error('Insufficient balance, need ' . $totalRepay . ' USDC');
}
DB::beginTransaction();
try {
$before = $wallet->legal_balance;
foreach ($orders as $order) {
$days = max(1, ceil((time() - strtotime($order->created_at)) / 86400));
$interest = sprintf('%.6f', $order->amount * floatval($credit->daily_rate) * $days);
$repayAmount = bc_add($order->amount, $interest, 6);
$wallet->legal_balance = bc_sub($wallet->legal_balance, $repayAmount, 6);
$credit->used_amount = bc_sub($credit->used_amount, $order->amount, 6);
$credit->available_amount = bc_add($credit->available_amount, $order->amount, 6);
$order->update(['status' => 1, 'repaid_amount' => $repayAmount, 'interest' => $interest]);
}
$wallet->save();
AccountLog::insertLog(
['user_id' => $user->id, 'value' => -$totalRepay, 'info' => 'Credit IEO Repay All', 'type' => AccountLog::IEO_OPERATION, 'currency' => 3],
['balance_type' => 1, 'wallet_id' => $wallet->id, 'lock_type' => 0, 'before' => $before, 'change' => -$totalRepay, 'after' => $wallet->legal_balance]
);
if (bc_comp($credit->available_amount, $credit->total_amount) > 0) {
$credit->available_amount = $credit->total_amount;
}
$credit->save();
DB::commit();
return $this->success('All orders repaid');
} catch (\Throwable $e) {
DB::rollBack();
return $this->error($e->getMessage());
}
}
}
@@ -0,0 +1,139 @@
@extends('admin._layoutNew')
@section('title', '信用额度管理')
@section('page-content')
<div class="layui-card">
<div class="layui-card-header">信用额度管理</div>
<div class="layui-card-body">
<form class="layui-form" style="margin-bottom:10px;">
<div class="layui-inline">
<input id="f_user_id" class="layui-input" placeholder="用户ID">
</div>
<div class="layui-inline">
<input id="f_keyword" class="layui-input" placeholder="手机号/邮箱">
</div>
<div class="layui-inline">
<button type="button" class="layui-btn layui-btn-sm" onclick="searchList()">搜索</button>
<button type="button" class="layui-btn layui-btn-sm" onclick="grantOpen({})">授信</button>
<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="loadData()">刷新</button>
</div>
</form>
<table id="creditTable" lay-filter="creditTable"></table>
</div>
</div>
<script type="text/html" id="statusTpl">
@{{# if(d.status==1){ }}<span class="layui-badge layui-bg-green">启用</span>@{{# } }}
@{{# if(d.status==0){ }}<span class="layui-badge layui-bg-gray">禁用</span>@{{# } }}
</script>
<script type="text/html" id="actionTpl">
<button class="layui-btn layui-btn-xs" lay-event="edit">编辑</button>
</script>
@endsection
@section('scripts')
<script>
layui.use(['table','layer','form'], function(){
var table = layui.table;
window.loadData = function(){ table.reload('creditTable', {where:{user_id:$('#f_user_id').val(), keyword:$('#f_keyword').val()}}); };
window.searchList = loadData;
table.render({
elem:'#creditTable', id:'creditTable',
url:'/admin/credit/list', page:true, limit:20,
cols:[[
{field:'id',title:'ID',width:60},
{field:'user_id',title:'用户ID',width:80},
{field:'user_phone',title:'手机号',width:130},
{field:'user_email',title:'邮箱',width:180},
{field:'total_amount',title:'总额度',width:100},
{field:'used_amount',title:'已使用',width:100},
{field:'available_amount',title:'可用额度',width:100},
{field:'daily_rate',title:'日利率',width:100},
{field:'cycle_days',title:'周期(天)',width:80},
{field:'credit_score',title:'信用分',width:80},
{field:'status',title:'状态',width:80,templet:'#statusTpl'},
{field:'created_at',title:'创建时间',width:160},
{fixed:'right',title:'操作',width:80,toolbar:'#actionTpl'}
]]
});
table.on('tool(creditTable)', function(obj){
if(obj.event==='edit') grantOpen(obj.data);
});
window.grantOpen = function(d){
var isEdit = !!d.id;
var html = '<form class="layui-form" style="padding:20px;">';
if(!isEdit){
html += '<div class="layui-form-item">'
+'<label class="layui-form-label">搜索用户</label>'
+'<div class="layui-input-inline" style="width:200px;"><input id="grant_search" class="layui-input" placeholder="手机号/邮箱/用户ID"></div>'
+'<button type="button" class="layui-btn layui-btn-sm" onclick="searchUser()">查询</button>'
+'</div>'
+'<div class="layui-form-item" id="user_search_result" style="display:none;padding-left:110px;">'
+'<div id="user_result_list" style="max-height:150px;overflow-y:auto;border:1px solid #e6e6e6;border-radius:4px;"></div>'
+'</div>';
}
html += '<div class="layui-form-item"><label class="layui-form-label">用户ID</label><div class="layui-input-block"><input name="user_id" id="grant_user_id" class="layui-input" value="'+(d.user_id||'')+'" '+(isEdit?'readonly':'')+' placeholder="通过上方搜索选择用户"></div></div>'
+'<div id="selected_user_info" style="padding:0 110px 10px;color:#666;font-size:12px;">'+(isEdit?'<span>'+((d.user_phone||'')+(d.user_email?' / '+d.user_email:''))+'</span>':'')+'</div>'
+'<div class="layui-form-item"><label class="layui-form-label">总额度(USDT)</label><div class="layui-input-block"><input name="total_amount" class="layui-input" value="'+(d.total_amount||0)+'"></div></div>'
+'<div class="layui-form-item"><label class="layui-form-label">日利率</label><div class="layui-input-block"><input name="daily_rate" class="layui-input" value="'+(d.daily_rate||0.001)+'" placeholder="0.001 = 0.1%/天"></div></div>'
+'<div class="layui-form-item"><label class="layui-form-label">信用周期(天)</label><div class="layui-input-block"><input name="cycle_days" class="layui-input" value="'+(d.cycle_days||30)+'"></div></div>'
+'<div class="layui-form-item"><label class="layui-form-label">信用分</label><div class="layui-input-block"><input name="credit_score" class="layui-input" value="'+(d.credit_score||0)+'"></div></div>'
+'<div class="layui-form-item"><label class="layui-form-label">状态</label><div class="layui-input-block"><select name="status"><option value="1" '+(d.status==1?'selected':'')+'>启用</option><option value="0" '+(d.status==0?'selected':'')+'>禁用</option></select></div></div>'
+'</form>';
layer.open({
type:1, title:isEdit?'编辑信用额度':'授信', area:['540px','560px'], content:html,
btn:['保存','取消'],
yes:function(index,layero){
var form = layero.find('form');
var postData = {};
form.find('input[name],select[name]').each(function(){postData[this.name]=this.value;});
if(!postData.user_id){layer.msg('请先选择用户',{icon:2});return;}
postData._token = '{{csrf_token()}}';
$.post('/admin/credit/grant', postData, function(r){
layer.close(index);
if(r.type=='ok'){layer.msg('保存成功');loadData();}else layer.msg(r.message,{icon:2});
});
}
});
};
window.searchUser = function(){
var kw = $('#grant_search').val();
if(!kw){layer.msg('请输入搜索关键词',{icon:2});return;}
$.get('/admin/user/list', {account_number:kw, limit:10}, function(res){
var list = res.data || [];
if(!list.length){
$('#user_search_result').show();
$('#user_result_list').html('<div style="padding:10px;color:#999;text-align:center;">未找到用户</div>');
return;
}
var h = '';
for(var i=0;i<list.length;i++){
var u = list[i];
h += '<div class="grant-user-item" style="padding:8px 12px;cursor:pointer;border-bottom:1px solid #f0f0f0;display:flex;justify-content:space-between;" '
+'onclick="pickUser('+u.id+',\''+((u.phone||'').replace(/'/g,''))+ '\',\''+ ((u.email||'').replace(/'/g,'')) +'\')">'
+'<span>ID: '+u.id+'</span>'
+'<span>'+(u.phone||'-')+'</span>'
+'<span>'+(u.email||'-')+'</span>'
+'</div>';
}
$('#user_search_result').show();
$('#user_result_list').html(h);
});
};
window.pickUser = function(id, phone, email){
$('#grant_user_id').val(id);
$('#selected_user_info').html('<span style="color:#00c48c;">已选择: ID '+id+' / '+(phone||'-')+' / '+(email||'-')+'</span>');
$('#user_search_result').hide();
};
});
</script>
<style>
.grant-user-item:hover{background:#f6f6f6!important;}
</style>
@endsection
@@ -0,0 +1,61 @@
@extends('admin._layoutNew')
@section('title', '信用IEO订单')
@section('page-content')
<div class="layui-card">
<div class="layui-card-header">信用IEO订单管理</div>
<div class="layui-card-body">
<form class="layui-form" style="margin-bottom:10px;">
<div class="layui-inline">
<input id="f_project_id" class="layui-input" placeholder="项目ID">
</div>
<div class="layui-inline">
<select id="f_status">
<option value="">全部状态</option>
<option value="0">冻结中</option>
<option value="1">已还款</option>
<option value="3">逾期</option>
</select>
</div>
<div class="layui-inline">
<button type="button" class="layui-btn layui-btn-sm" onclick="searchList()">搜索</button>
<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="loadData()">刷新</button>
</div>
</form>
<table id="coTable" lay-filter="coTable"></table>
</div>
</div>
<script type="text/html" id="statusTpl">
@{{# if(d.status==0){ }}<span class="layui-badge layui-bg-orange">冻结中</span>@{{# } }}
@{{# if(d.status==1){ }}<span class="layui-badge layui-bg-green">已还款</span>@{{# } }}
@{{# if(d.status==3){ }}<span class="layui-badge">逾期</span>@{{# } }}
</script>
@endsection
@section('scripts')
<script>
layui.use(['table','layer','form'], function(){
var table = layui.table;
window.loadData = function(){ table.reload('coTable', {where:{project_id:$('#f_project_id').val(), status:$('#f_status').val()}}); };
window.searchList = loadData;
table.render({
elem:'#coTable', id:'coTable',
url:'/admin/credit/order/list', page:true, limit:20,
cols:[[
{field:'id',title:'ID',width:70},
{field:'user_id',title:'用户ID',width:80},
{field:'user_phone',title:'手机号',width:130},
{field:'project_name',title:'项目',width:140},
{field:'symbol',title:'代号',width:80},
{field:'amount',title:'认购金额',width:100},
{field:'token_amount',title:'获得代币',width:110},
{field:'interest',title:'利息',width:100},
{field:'repaid_amount',title:'已还款',width:100},
{field:'status',title:'状态',width:90,templet:'#statusTpl'},
{field:'created_at',title:'创建时间',width:160}
]]
});
});
</script>
@endsection