From c426a5e7f6ad3c64a1340c495657b15d91f679fe Mon Sep 17 00:00:00 2001 From: testadmin Date: Tue, 28 Apr 2026 20:53:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=B4=B7=E6=AC=BE=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E5=90=8E=E7=AB=AF=20=E2=80=94=20=E7=94=B3=E8=AF=B7+=E5=AE=A1?= =?UTF-8?q?=E6=89=B9+=E6=94=BE=E6=AC=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Admin/LoanController.php | 112 +++++++++++++++++ app/Http/Controllers/Api/LoanController.php | 74 ++++++++++++ app/Loan.php | 17 +++ resources/views/manages/loan/index.blade.php | 113 ++++++++++++++++++ 4 files changed, 316 insertions(+) create mode 100644 app/Http/Controllers/Admin/LoanController.php create mode 100644 app/Http/Controllers/Api/LoanController.php create mode 100644 app/Loan.php create mode 100644 resources/views/manages/loan/index.blade.php diff --git a/app/Http/Controllers/Admin/LoanController.php b/app/Http/Controllers/Admin/LoanController.php new file mode 100644 index 0000000..842f682 --- /dev/null +++ b/app/Http/Controllers/Admin/LoanController.php @@ -0,0 +1,112 @@ +input('limit', 20); + $status = $request->input('status', ''); + + $query = Loan::query() + ->leftJoin('users', 'loan.user_id', '=', 'users.id') + ->select('loan.*', 'users.phone as user_phone', 'users.email as user_email', 'users.account_number'); + + if ($status !== '') { + $query->where('loan.status', $status); + } + + $keyword = $request->input('keyword'); + if ($keyword) { + $query->where(function ($q) use ($keyword) { + $q->where('loan.user_id', $keyword) + ->orWhere('users.phone', 'like', "%{$keyword}%") + ->orWhere('users.email', 'like', "%{$keyword}%"); + }); + } + + $data = $query->orderBy('loan.id', 'desc')->paginate($limit); + + return $this->layuiData($data); + } + + public function approve(Request $request) + { + $id = $request->input('id'); + $loan = Loan::find($id); + if (!$loan) return $this->error('Loan not found'); + if ($loan->status != 0) return $this->error('Loan already processed'); + + DB::beginTransaction(); + try { + $wallet = UsersWallet::where('user_id', $loan->user_id) + ->where('currency', 3)->lockForUpdate()->first(); + if (!$wallet) { + DB::rollBack(); + return $this->error('User wallet not found'); + } + + $before = $wallet->legal_balance; + $wallet->legal_balance = bc_add($wallet->legal_balance, $loan->amount, 6); + $wallet->save(); + + AccountLog::insertLog( + [ + 'user_id' => $loan->user_id, + 'value' => $loan->amount, + 'created_time' => time(), + 'info' => 'Loan Approved - ' . $loan->institution, + 'type' => AccountLog::USER_LOAN_ORDER_BUY, + 'currency' => 3, + ], + [ + 'balance_type' => 1, + 'wallet_id' => $wallet->id, + 'lock_type' => 0, + 'before' => $before, + 'change' => $loan->amount, + 'after' => $wallet->legal_balance, + 'create_time' => time(), + ] + ); + + $loan->status = 1; + $loan->update_time = now(); + $loan->save(); + + DB::commit(); + return $this->success('Loan approved'); + } catch (\Exception $e) { + DB::rollBack(); + return $this->error('Error: ' . $e->getMessage()); + } + } + + public function reject(Request $request) + { + $id = $request->input('id'); + $remark = $request->input('remark', ''); + $loan = Loan::find($id); + if (!$loan) return $this->error('Loan not found'); + if ($loan->status != 0) return $this->error('Loan already processed'); + + $loan->status = 2; + $loan->remark = $remark; + $loan->update_time = now(); + $loan->save(); + + return $this->success('Loan rejected'); + } +} diff --git a/app/Http/Controllers/Api/LoanController.php b/app/Http/Controllers/Api/LoanController.php new file mode 100644 index 0000000..9459917 --- /dev/null +++ b/app/Http/Controllers/Api/LoanController.php @@ -0,0 +1,74 @@ +where('key', 'loan_institution')->value('value') ?? 'Global Finance'; + return $this->success(['institution' => $name]); + } + + public function submit(Request $request) + { + $user_id = Token::getUserIdByToken(Token::getToken()); + $user = \App\Users::find($user_id); + if (!$user) return $this->error('Please login first'); + + $amount = $request->input('amount'); + $card_image = $request->input('card_image', ''); + $cardbm_image = $request->input('cardbm_image', ''); + $hand_image = $request->input('hand_image', ''); + + if (!$amount || !is_numeric($amount) || $amount <= 0) { + return $this->error('Please enter a valid amount'); + } + if (!$card_image || !$cardbm_image || !$hand_image) { + return $this->error('Please upload all required documents'); + } + + $pending = Loan::where('user_id', $user->id)->where('status', 0)->first(); + if ($pending) { + return $this->error('You already have a pending loan application'); + } + + $institution = DB::table('settings')->where('key', 'loan_institution')->value('value') ?? 'Global Finance'; + + Loan::create([ + 'user_id' => $user->id, + 'amount' => $amount, + 'card_image' => $card_image, + 'cardbm_image' => $cardbm_image, + 'hand_image' => $hand_image, + 'institution' => $institution, + 'status' => 0, + 'create_time' => now(), + ]); + + return $this->success('Loan application submitted successfully'); + } + + public function myLoans(Request $request) + { + $user_id = Token::getUserIdByToken(Token::getToken()); + $user = \App\Users::find($user_id); + if (!$user) return $this->error('Please login first'); + + $list = Loan::where('user_id', $user->id)->orderBy('id', 'desc')->limit(20)->get(); + $statusMap = ['0' => 'Pending', '1' => 'Approved', '2' => 'Rejected']; + foreach ($list as $item) { + $item->status_text = $statusMap[$item->status] ?? ''; + } + return $this->success($list); + } +} diff --git a/app/Loan.php b/app/Loan.php new file mode 100644 index 0000000..a60f8dd --- /dev/null +++ b/app/Loan.php @@ -0,0 +1,17 @@ +belongsTo(Users::class, 'user_id', 'id'); + } +} diff --git a/resources/views/manages/loan/index.blade.php b/resources/views/manages/loan/index.blade.php new file mode 100644 index 0000000..8b57271 --- /dev/null +++ b/resources/views/manages/loan/index.blade.php @@ -0,0 +1,113 @@ +@extends('admin._layoutNew') +@section('title', '贷款管理') +@section('page-content') +
+
贷款审核管理
+
+
+
+ +
+
+ +
+
+
+ + + + + +
+
+
+
+ + + + + + + +@endsection +@section('scripts') + +@endsection