下面就具体说一说怎么来防止这种错误的发生。 $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); } 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'); 将之修改为 { $minus_stock_sql = "UPDATE " . $GLOBALS['ecs']->table('products') . " SET
product_number = if( product_number > $value[sums], product_number
-$value[sums],0 )
$GLOBALS['db']->query($minus_stock_sql, 'SILENT'); } $minus_stock_sql = "UPDATE " .
$GLOBALS['ecs']->table('goods') . " WHERE goods_id =
" . $value['goods_id']; $GLOBALS['db']->query($minus_stock_sql, 'SILENT'); 这样就OK了。
|