refactor(dao): remove BaseAuth stock mutation dependency
Made-with: Cursor
This commit is contained in:
@@ -5,11 +5,11 @@
|
||||
|
||||
namespace app\dao;
|
||||
|
||||
use app\services\product\StockMutationService;
|
||||
use think\helper\Str;
|
||||
use think\Model;
|
||||
use think\Collection;
|
||||
use think\db\BaseQuery;
|
||||
use crmeb\basic\BaseAuth;
|
||||
use crmeb\basic\BaseModel;
|
||||
use think\db\exception\DbException;
|
||||
use crmeb\traits\dao\CacheDaoTrait;
|
||||
@@ -480,7 +480,8 @@ abstract class BaseDao
|
||||
*/
|
||||
public function decStockIncSales(array $where, int $num, string $stock = 'stock', string $sales = 'sales')
|
||||
{
|
||||
return app()->make(BaseAuth::class)->_____($this->getModel(), $where, $num, $stock, $sales) !== false;
|
||||
return app()->make(StockMutationService::class)
|
||||
->decreaseStockIncreaseSales($this->getModel(), $where, $num, $stock, $sales);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -493,7 +494,8 @@ abstract class BaseDao
|
||||
*/
|
||||
public function incStockDecSales(array $where, int $num, string $stock = 'stock', string $sales = 'sales')
|
||||
{
|
||||
return app()->make(BaseAuth::class)->___($this->getModel(), $where, $num, $stock, $sales) !== false;
|
||||
return app()->make(StockMutationService::class)
|
||||
->increaseStockDecreaseSales($this->getModel(), $where, $num, $stock, $sales);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
42
pro_v3.5.1/app/services/product/StockMutationService.php
Normal file
42
pro_v3.5.1/app/services/product/StockMutationService.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user