【产品名称】:多店版
【产品版本】::v3.2.1
当减少的库存数量跟商品表stock数量一样,会报:
think\db\exception\PDOException: SQLSTATE[22003]: Numeric value out of range: 1690 BIGINT UNSIGNED value is out of range in '(`eb_store_product`.`stock` - 2)'
报错原因:
- UNSIGNED 类型特性:
UNSIGNED
字段只能存储0
到18446744073709551615
的值。 - 运算逻辑:例:stock值为
2
,MySQL 在执行2 - 2
时会先计算结果-2
,然后发现-2
超出了UNSIGNED
的范围,直接报错。
修改文件:app/services/product/product/StoreProductServices.php
public function decProductStock(int $num, int $productId, string $unique = '', int $store_id = 0)
{
$res = true;
...
...
//2927行,注释掉这一行,增加[条件减法],即下方的['stock', '>=', $num]
// $res = $res && $this->dao->decStockIncSales(['id' => $productId], $num);
$res = $res && $this->dao->decStockIncSales([
['id', '=', $productId],
['stock', '>=', $num]
], $num);
...
...
}