需要补充的一点就是,这里说的ecshop商品库存,既包括商品总库存(goods表里的goods_number字段),也包括货品库存,即不同属性对应的库存(products表里的product_number字段)。
至于为什么会突变为65535,而不是15565,也不是255255,那是因为这两个地段的类型都是无符号的 smallint(5),取值范围为 0---65535,所以某个节点某个原因才会突变为 65535。
下面就具体说一说怎么来防止这种错误的发生。ECSHOP系统 商品库存会突变为65535的问题解决方法!
1)
第一步,主要是对 includes/lib_order.php 文件进行一下二次开发。
先找到下面这段代码
$number = ($number > 0) ? '+ ' . $number : $number;
/* 处理货品库存 */
$products_query = true;
if (!empty($product_id))
{
$sql = "UPDATE " . $GLOBALS['ecs']->table('products') ."
SET product_number = product_number $number
WHERE goods_id = '$good_id'
AND product_id = '$product_id'
LIMIT 1";
$products_query = $GLOBALS['db']->query($sql);
}
/* 处理商品库存 */
$sql = "UPDATE " . $GLOBALS['ecs']->table('goods') ."
SET goods_number = goods_number $number
WHERE goods_id = '$good_id'
LIMIT 1";
$query = $GLOBALS['db']->query($sql);
将其修改为
if($number>=0)
{
/* 处理货品库存 */
$products_query = true;
if (!empty($product_id))
{
$sql = "UPDATE " . $GLOBALS['ecs']->table('products') .
" SET product_number = product_number + $number ".
" WHERE goods_id = '$good_id' AND product_id = '$product_id' LIMIT 1";
$products_query = $GLOBALS['db']->query($sql);
}
/* 处理商品库存 */
$sql = "UPDATE " . $GLOBALS['ecs']->table('goods') .
" SET goods_number = goods_number + $number ".
" WHERE goods_id = '$good_id' LIMIT 1";
$query = $GLOBALS['db']->query($sql);
}
else
{
/* 处理货品库存 */
$products_query = true;
$abs_number = abs($number);
if (!empty($product_id))
{
$sql = "UPDATE " . $GLOBALS['ecs']->table('products') . " SET product_number =".
" if( product_number >= $abs_number,product_number - $abs_number,0) ".
" WHERE goods_id = '$good_id' AND product_id = '$product_id' LIMIT 1";
$products_query = $GLOBALS['db']->query($sql);
}
/* 处理商品库存 */
$sql = "UPDATE " . $GLOBALS['ecs']->table('goods') . " SET goods_number = ".
" if( goods_number >= $abs_number , goods_number - $abs_number ,0) ".
" WHERE goods_id = '$good_id' LIMIT 1";
$query = $GLOBALS['db']->query($sql);
}
ECSHOP系统 商品库存会突变为65535的问题解决方法!
2)、
接下来,还需要修改后台文件 /admin/order.php,
找到下面代码,大概在811行左右。
if (!empty($value['product_id']))
{
$minus_stock_sql = "UPDATE " . $GLOBALS['ecs']->table('products') . "
SET product_number = product_number - " . $value['sums'] . "
WHERE product_id = " . $value['product_id'];
$GLOBALS['db']->query($minus_stock_sql, 'SILENT');
}
$minus_stock_sql = "UPDATE " . $GLOBALS['ecs']->table('goods') . "
SET goods_number = goods_number - " . $value['sums'] . "
WHERE goods_id = " . $value['goods_id'];
$GLOBALS['db']->query($minus_stock_sql, 'SILENT');
将之修改为
if (!empty($value['product_id']))
{
$minus_stock_sql = "UPDATE " . $GLOBALS['ecs']->table('products') . "
SET product_number = if( product_number > $value[sums], product_number -$value[sums],0 )
WHERE product_id = " . $value['product_id'];
$GLOBALS['db']->query($minus_stock_sql, 'SILENT');
}
$minus_stock_sql = "UPDATE " . $GLOBALS['ecs']->table('goods') . "
SET goods_number = if ( goods_number > $value[sums], goods_number -$value[sums],0 )
WHERE goods_id = " . $value['goods_id'];
$GLOBALS['db']->query($minus_stock_sql, 'SILENT');