解决ecshop后台商品库存突然变成65535的问题(2)
时间:2011-11-16 07:15来源:未知 作者:最模板 点击:次
库存突然变到了65535 产生这个问题的原因是在includes\lib_order.php 中的change_goods_storage有bug /** * 商品库存增与减 货品库存增与减 * * @param int $good_id 商品ID *
库存突然变到了65535
产生这个问题的原因是在includes\lib_order.php 中的change_goods_storage有bug
- /**
- * 商品库存增与减 货品库存增与减
- *
- * @param int $good_id 商品ID
- * @param int $product_id 货品ID
- * @param int $number 增减数量,默认0;
- *
- * @return bool true,成功;false,失败;
- */
- function change_goods_storage($good_id, $product_id, $number = 0)
- {
- if ($number == 0)
- {
- return true; // 值为0即不做、增减操作,返回true
- }
- if (empty($good_id) || empty($number))
- {
- return false;
- }
- $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 ($query && $products_query)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
复制代码
最开始时候最模板是这样去修复这个bug:
-
- /* 处理货品库存 */
- $products_query = true;
- if (!empty($product_id))
- {
- $sql = "UPDATE " . $GLOBALS['ecs']->table('products') ."
- SET product_number = if( product_number $number>=0,product_number $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 $number >=0, goods_number $number ,0)
- WHERE goods_id = '$good_id' LIMIT 1";
- $query = $GLOBALS['db']->query($sql);
复制代码
(责任编辑:最模板) |
------分隔线----------------------------