【產(chǎn)品名稱】:多店版
【產(chǎn)品版本】::v3.2.1
當減少的庫存數(shù)量跟商品表stock數(shù)量一樣,會報:
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 在執(zhí)行2 - 2
時會先計算結(jié)果-2
,然后發(fā)現(xiàn)-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);
...
...
}