//计算库存 foreach($aGoodsLst as $goodsid => $aGoods) { $aGoods['price'] = $aGoods['buy']==0?0:($aGoods['buymoney']/ $aGoods['buy']); $aGoods['stock'] = $aGoods['buy'] - $aGoods['sell'] + $aGoods['return']; $aGoods['stockmoney'] = $aGoods['stock'] * $aGoods['price']; //库存金额以进价为准 //重新计算销售金额 $aGoods['sell'] = $aGoods['sell'] - $aGoods['return']; $aGoods['sellmoney'] = $aGoods['sellmoney'] - $aGoods['returnmoney']; //盈余 $aGoods['earn'] = $aGoods['sellmoney']-$aGoods['buymoney']; extract($aGoods); $sSql = "UPDATE goods SET buy='$buy',buymoney='$buymoney',stock='$stock',stockmoney='$stockmoney',sell='$sell',sellmoney='$sellmoney',`return`='$return',returnmoney='$returnmoney',earn='$earn' WHERE id=$goodsid"; $oDb->query($sSql); }
在for循环中的extract时,如果数组的下标不包含到$buy等后续要使用的变量,会导致使用其他不相关的或者前一次生成的变量,需要特别的注意