43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Author: ScottPan Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\services\product;
|
|
|
|
/**
|
|
* 本项目自有库存变更服务,不依赖 CRMEB 商业授权基础类。
|
|
*/
|
|
class StockMutationService
|
|
{
|
|
public function decreaseStockIncreaseSales($model, array $where, int $num, string $stock, string $sales): bool
|
|
{
|
|
if ($num <= 0) {
|
|
return false;
|
|
}
|
|
|
|
$affected = $model->where($where)
|
|
->where($stock, '>=', $num)
|
|
->dec($stock, $num)
|
|
->inc($sales, $num)
|
|
->update();
|
|
|
|
return (int)$affected > 0;
|
|
}
|
|
|
|
public function increaseStockDecreaseSales($model, array $where, int $num, string $stock, string $sales): bool
|
|
{
|
|
if ($num <= 0) {
|
|
return false;
|
|
}
|
|
|
|
$affected = $model->where($where)
|
|
->where($sales, '>=', $num)
|
|
->inc($stock, $num)
|
|
->dec($sales, $num)
|
|
->update();
|
|
|
|
return (int)$affected > 0;
|
|
}
|
|
}
|