refactor(dao): remove BaseAuth stock mutation dependency
Made-with: Cursor
This commit is contained in:
@@ -238,3 +238,22 @@
|
|||||||
| 6.1 | 企业微信客户列表 | GET | admin | token、筛选条件 | 待预发填写 | 待预发填写 | `list`、`count` | 待测 | 当前项目未启用企业微信,部署验证时确认明确错误或正常列表。 |
|
| 6.1 | 企业微信客户列表 | GET | admin | token、筛选条件 | 待预发填写 | 待预发填写 | `list`、`count` | 待测 | 当前项目未启用企业微信,部署验证时确认明确错误或正常列表。 |
|
||||||
| 6.1 | 企业微信成员列表 | GET | admin | token、筛选条件 | 待预发填写 | 待预发填写 | `list`、`count` | 待测 | 当前项目未启用企业微信,部署验证时确认明确错误或正常列表。 |
|
| 6.1 | 企业微信成员列表 | GET | admin | token、筛选条件 | 待预发填写 | 待预发填写 | `list`、`count` | 待测 | 当前项目未启用企业微信,部署验证时确认明确错误或正常列表。 |
|
||||||
| 6.1 | 企业微信欢迎语列表 | GET | admin | token、筛选条件 | 待预发填写 | 待预发填写 | `list`、`count` | 待测 | 当前项目未启用企业微信,部署验证时确认明确错误或正常列表。 |
|
| 6.1 | 企业微信欢迎语列表 | GET | admin | token、筛选条件 | 待预发填写 | 待预发填写 | `list`、`count` | 待测 | 当前项目未启用企业微信,部署验证时确认明确错误或正常列表。 |
|
||||||
|
|
||||||
|
## 阶段 6.2:库存扣减/回滚
|
||||||
|
|
||||||
|
### 自动化检查
|
||||||
|
|
||||||
|
| 命令 | 结果 | 备注 |
|
||||||
|
|------|------|------|
|
||||||
|
| `php -l app/services/product/StockMutationService.php` | 通过 | PHP 提示 `swoole_loader` 已加载,不影响语法检查结果。 |
|
||||||
|
| `php -l app/dao/BaseDao.php` | 通过 | PHP 提示 `swoole_loader` 已加载,不影响语法检查结果。 |
|
||||||
|
| `rg "BaseAuth" app/dao/BaseDao.php` | 通过 | `BaseDao` 已无 `BaseAuth` 引用。 |
|
||||||
|
|
||||||
|
### 手工回归记录
|
||||||
|
|
||||||
|
| 阶段 | 接口/命令 | 方法 | 身份 | 关键参数 | HTTP 状态 | 业务 `status` | 关键字段 | 结果 | 备注 |
|
||||||
|
|------|-----------|------|------|----------|-----------|---------------|----------|------|------|
|
||||||
|
| 6.2 | 创建订单/支付成功 | POST | user/admin | 商品、规格、数量 | 待预发填写 | 待预发填写 | 库存、销量、订单状态 | 待测 | 当前项目暂不使用相关链路,部署验证时补充。 |
|
||||||
|
| 6.2 | 库存不足下单 | POST | user/admin | 超库存数量 | 待预发填写 | 待预发填写 | 失败提示、无异常订单 | 待测 | 当前项目暂不使用相关链路,部署验证时补充。 |
|
||||||
|
| 6.2 | 取消/退款回滚 | POST | user/admin | 订单号 | 待预发填写 | 待预发填写 | 库存、销量 | 待测 | 当前项目暂不使用相关链路,部署验证时补充。 |
|
||||||
|
| 6.2 | 并发扣减 | POST | user/admin | 同商品多请求 | 待预发填写 | 待预发填写 | 库存不为负 | 待测 | 需在预发压测或脚本验证。 |
|
||||||
|
|||||||
@@ -5,11 +5,11 @@
|
|||||||
|
|
||||||
namespace app\dao;
|
namespace app\dao;
|
||||||
|
|
||||||
|
use app\services\product\StockMutationService;
|
||||||
use think\helper\Str;
|
use think\helper\Str;
|
||||||
use think\Model;
|
use think\Model;
|
||||||
use think\Collection;
|
use think\Collection;
|
||||||
use think\db\BaseQuery;
|
use think\db\BaseQuery;
|
||||||
use crmeb\basic\BaseAuth;
|
|
||||||
use crmeb\basic\BaseModel;
|
use crmeb\basic\BaseModel;
|
||||||
use think\db\exception\DbException;
|
use think\db\exception\DbException;
|
||||||
use crmeb\traits\dao\CacheDaoTrait;
|
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')
|
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')
|
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