feat: Implement client payment history endpoint and add type filtering to product category API.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\Service;
|
||||
|
||||
use App\Enums\Product\ProductTypeEnums;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\Api\Service\ProductCategoryResource;
|
||||
use App\Http\Resources\Api\Service\ServiceResource;
|
||||
@@ -23,7 +24,14 @@ class ProductCategoryController extends Controller
|
||||
* operationId="getProductCategoryList",
|
||||
* tags={"Product Categories"},
|
||||
* summary="Get list of product categories",
|
||||
* description="Returns a list of active product categories with their children",
|
||||
* description="Returns a list of active product categories filtered by type. The `type` parameter is required.",
|
||||
* @OA\Parameter(
|
||||
* name="type",
|
||||
* in="query",
|
||||
* description="Product type filter (e.g. vps, hosting, cloud, email, ssl, domain, web design, addon)",
|
||||
* required=true,
|
||||
* @OA\Schema(type="string")
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="Successful operation",
|
||||
@@ -47,12 +55,35 @@ class ProductCategoryController extends Controller
|
||||
* ))
|
||||
* ))
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=422,
|
||||
* description="Missing or invalid type filter"
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function getCategories(Request $request)
|
||||
{
|
||||
$type = $request->query('type');
|
||||
|
||||
if (!$type) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => 'Vui lòng chọn Phân loại sản phẩm',
|
||||
'data' => [],
|
||||
], 422);
|
||||
}
|
||||
|
||||
if (!ProductTypeEnums::tryFrom($type)) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
'message' => 'Phân loại sản phẩm không hợp lệ',
|
||||
'data' => [],
|
||||
], 422);
|
||||
}
|
||||
|
||||
$categories = ProductCategories::where('is_active', true)
|
||||
->where('type', $type)
|
||||
->whereNull('parent_id')
|
||||
->with(['children' => function($query) {
|
||||
$query->where('is_active', true)
|
||||
|
||||
@@ -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