Ecshop模板网
首页 > ecshop教程 > ecshop经验分享 > ECSHOP商品库存会突变为65535的问题解决方法!
文章详情

ECSHOP商品库存会突变为65535的问题解决方法!

ecshop模板网 / 2014-08-06

需要补充的一点就是,这里说的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');

下一篇: 如何限制ecshop底部帮助中心文章条数 上一篇: ecshop后台编辑专题报错--无法重新声明json类
 用户评论(共 0 条评论)
  • 暂时还没有任何用户评论
用户名: 匿名用户 E-mail:
当前心情:
评论内容:
验证码: captcha
返回顶部 返回首页
 
QQ在线咨询
售前电话热线
#
售前QQ客服