解决ecshop后台商品库存突然变成65535的问题(3)
时间:2011-11-16 07:15来源:未知 作者:好模板 点击:次
其实并不能很好的解决问题,因为 goods_number $number 0 这个判断不成立,当 mysql 中goods_number=0时 变态的mysql 执行 goods_number-1的结果是65535,起不到 0-1 =-1 大于
其实并不能很好的解决问题,因为
goods_number $number >0 这个判断不成立,当mysql中goods_number=0时 变态的mysql 执行 goods_number-1的结果是65535,起不到 0-1 =-1 大于0的作用
最后改成这样:
-
- /**
- * 商品库存增与减 货品库存增与减
- *
- * @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;
- }
-
- 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 - $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 , goods_number - $number ,0)
- WHERE goods_id = '$good_id' LIMIT 1";
- $query = $GLOBALS['db']->query($sql);
-
- }
- if ($query && $products_query)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
复制代码
解决ecshop后台商品库存突然变成65535的问题才得真正的得到解决 (责任编辑:好模板) |
------分隔线----------------------------