83 lines
2.8 KiB
PHP
83 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Mypage;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
final class UsageRepository
|
|
{
|
|
public function findAttemptWithOrder(int $attemptId): ?object
|
|
{
|
|
return DB::table('gc_payment_attempts as a')
|
|
->leftJoin('gc_pin_order as o', 'o.id', '=', 'a.order_id')
|
|
->select([
|
|
'a.id as attempt_id',
|
|
'a.provider as attempt_provider',
|
|
'a.oid as attempt_oid',
|
|
'a.mem_no as attempt_mem_no',
|
|
'a.order_id as attempt_order_id',
|
|
'a.pay_method as attempt_pay_method',
|
|
'a.status as attempt_status',
|
|
'a.pg_tid as attempt_pg_tid',
|
|
'a.return_code as attempt_return_code',
|
|
'a.return_msg as attempt_return_msg',
|
|
'a.request_payload as attempt_request_payload',
|
|
'a.response_payload as attempt_response_payload',
|
|
'a.return_payload as attempt_return_payload',
|
|
'a.noti_payload as attempt_noti_payload',
|
|
'a.created_at as attempt_created_at',
|
|
'a.updated_at as attempt_updated_at',
|
|
|
|
'o.id as order_id',
|
|
'o.oid as order_oid',
|
|
'o.mem_no as order_mem_no',
|
|
'o.stat_pay as order_stat_pay',
|
|
'o.provider as order_provider',
|
|
'o.pay_method as order_pay_method',
|
|
'o.pg_tid as order_pg_tid',
|
|
'o.ret_code as order_ret_code',
|
|
'o.ret_msg as order_ret_msg',
|
|
'o.subtotal_amount as order_subtotal_amount',
|
|
'o.fee_amount as order_fee_amount',
|
|
'o.pg_fee_amount as order_pg_fee_amount',
|
|
'o.pay_money as order_pay_money',
|
|
'o.pay_data as order_pay_data',
|
|
'o.ret_data as order_ret_data',
|
|
'o.created_at as order_created_at',
|
|
'o.updated_at as order_updated_at',
|
|
])
|
|
->where('a.id', $attemptId)
|
|
->first();
|
|
}
|
|
|
|
public function getOrderItems(int $orderId)
|
|
{
|
|
return DB::table('gc_pin_order_items')
|
|
->where('order_id', $orderId)
|
|
->orderBy('id', 'asc')
|
|
->get();
|
|
}
|
|
|
|
public function countAssignedPins(int $orderId): int
|
|
{
|
|
return (int) DB::table('gc_pins')
|
|
->where('order_id', $orderId)
|
|
->count();
|
|
}
|
|
|
|
public function getAssignedPinsStatusSummary(int $orderId): array
|
|
{
|
|
$rows = DB::table('gc_pins')
|
|
->selectRaw('status, COUNT(*) as cnt')
|
|
->where('order_id', $orderId)
|
|
->groupBy('status')
|
|
->get();
|
|
|
|
$out = [];
|
|
foreach ($rows as $r) {
|
|
$out[(string)$r->status] = (int)$r->cnt;
|
|
}
|
|
return $out;
|
|
}
|
|
}
|