37 lines
903 B
PHP
37 lines
903 B
PHP
<?php
|
|
|
|
namespace App\Repositories\Payments;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
final class GcPinsRepository
|
|
{
|
|
public function lockAvailablePins(int $productId, int $skuId, int $qty): array
|
|
{
|
|
$rows = DB::table('gc_pins')
|
|
->where('product_id', $productId)
|
|
->where('sku_id', $skuId)
|
|
->where('status', 'AVAILABLE')
|
|
->orderBy('id', 'asc')
|
|
->lockForUpdate()
|
|
->limit($qty)
|
|
->get();
|
|
|
|
return array_map(fn ($r) => (array)$r, $rows->all());
|
|
}
|
|
|
|
public function updateStatusByIds(array $ids, string $status, array $extra = []): void
|
|
{
|
|
if (empty($ids)) return;
|
|
|
|
$payload = array_merge([
|
|
'status' => $status,
|
|
'updated_at' => now(),
|
|
], $extra);
|
|
|
|
DB::table('gc_pins')
|
|
->whereIn('id', $ids)
|
|
->update($payload);
|
|
}
|
|
}
|