26 lines
542 B
PHP
26 lines
542 B
PHP
<?php
|
|
|
|
namespace App\Repositories\Shop;
|
|
|
|
use App\Models\Shop\Offer;
|
|
use App\Traits\Model\Basic;
|
|
|
|
class OfferStocks
|
|
{
|
|
public static function decreaseStock($item)
|
|
{
|
|
$offer = Offers::get($item['offer_id']);
|
|
$offer->stock_current = $offer->stock_current - $item['quantity'];
|
|
if ($offer->stock_current <= 0) {
|
|
$offer->stock_current = 0;
|
|
}
|
|
|
|
return $offer->save();
|
|
}
|
|
|
|
public static function getStockCurrent($id)
|
|
{
|
|
return Offers::getField($id, 'stock_current');
|
|
}
|
|
}
|