【產(chǎn)品名稱】:多店版
【產(chǎn)品版本】::v3.2.1
當(dāng)減少的庫存數(shù)量跟商品表stock數(shù)量一樣,會(huì)報(bào):
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)'
報(bào)錯(cuò)原因:
- UNSIGNED 類型特性:
UNSIGNED
字段只能存儲(chǔ)0
到18446744073709551615
的值。 - 運(yùn)算邏輯:例:stock值為
2
,MySQL 在執(zhí)行2 - 2
時(shí)會(huì)先計(jì)算結(jié)果-2
,然后發(fā)現(xiàn)-2
超出了UNSIGNED
的范圍,直接報(bào)錯(cuò)。
修改文件: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);
...
...
}