feat: Implement client payment history endpoint and add type filtering to product category API.
This commit is contained in:
@@ -8,8 +8,10 @@ use App\Http\Requests\DepositRequest;
|
||||
use App\Http\Services\VNPayService;
|
||||
use App\Jobs\Mail\Customer\DepositSuccessJob;
|
||||
use App\Models\Customer;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Log;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log as FacadesLog;
|
||||
@@ -242,6 +244,57 @@ class TransactionController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /v1/client/payment-history — combined deposit transactions + order invoice payments
|
||||
*/
|
||||
public function getClientPaymentHistory(Request $request): JsonResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
$deposits = Transaction::where('customer_id', $user->id)
|
||||
->orderByDesc('created_at')
|
||||
->get()
|
||||
->map(fn(Transaction $t) => [
|
||||
'type' => 'deposit',
|
||||
'public_code' => $t->public_code,
|
||||
'trans' => $t->trans,
|
||||
'description' => 'Nạp tiền vào tài khoản',
|
||||
'amount' => (float) $t->amount,
|
||||
'status' => $t->status,
|
||||
'status_label' => TransactionStatus::from((int) $t->status)->label(),
|
||||
'reference_id' => null,
|
||||
'reference_num'=> null,
|
||||
'created_at' => $t->created_at?->toISOString(),
|
||||
]);
|
||||
|
||||
$invoicePayments = Invoice::with(['order.orderItems.product'])
|
||||
->where('customer_id', $user->id)
|
||||
->orderByDesc('created_at')
|
||||
->get()
|
||||
->map(fn(Invoice $inv) => [
|
||||
'type' => 'order_payment',
|
||||
'public_code' => $inv->invoice_number,
|
||||
'trans' => null,
|
||||
'description' => 'Thanh toán đơn hàng: ' . ($inv->order?->orderItems->first()?->product?->name ?? $inv->order?->order_num),
|
||||
'amount' => (float) $inv->total,
|
||||
'status' => $inv->status,
|
||||
'status_label' => \App\Enums\Invoice\InvoiceStatus::tryFrom((int) $inv->status)?->label() ?? '-',
|
||||
'reference_id' => $inv->order?->id,
|
||||
'reference_num'=> $inv->order?->order_num,
|
||||
'created_at' => $inv->created_at?->toISOString(),
|
||||
]);
|
||||
|
||||
$combined = $deposits->concat($invoicePayments)
|
||||
->sortByDesc('created_at')
|
||||
->values();
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => 'Lấy lịch sử thanh toán thành công',
|
||||
'data' => $combined,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getByPublicCode(Request $request)
|
||||
{
|
||||
$code = $request->query('code');
|
||||
|
||||
Reference in New Issue
Block a user