saveAll($list); } /** * @param string $spuCode * @param string $bnCode * @param string $num */ public function subBN($spuCode='',$bnCode='',$stock_id='',$num=''){ $stockinfo = $this->where(["spuCode"=>$spuCode,"bnCode"=>$bnCode,"stock_id"=>$stock_id])->where("childBnNum",">",0)->order("id desc") ->select()->toArray(); if(empty($stockinfo)) throw new \Exception("未找到关联得bn库存数据"); foreach ($stockinfo as $item){ $tempnum=0; if($num > $item['childBnNum']){ $tempnum = $item['childBnNum']; $num= $num -$item['childBnNum']; $item['childBnNum']=0; }else{ $tempnum = $num; $item['childBnNum']=$item['childBnNum'] -$num; $num =0; } $this->save($item); $up=GoodStockInfo::AddBn($item['stock_id'],$item['child_bnCode'],$tempnum,$item['origin_price']); if($up==false) throw new \Exception('bn库存数据更新失败'); } return true; } }