origin_price = bcdiv($totalPrice,$orderInfo->good_num,6); Sale::save($orderInfo->toArray()); return $temp; } /**修改成本数量 * @param $orderInfo * @param string $totalPrice * @return array * @throws \think\Exception */ public static function checkCgdNum($orderInfo,&$totalPrice="0"){ $temp=[]; $num = $orderInfo->good_num; $totalPrice='0'; while ($num>0){ $item =self::where([['goodNo','=',$orderInfo->good_code],['status','=',1]])->findOrEmpty(); if($item->isEmpty()){ $tempNum = $num; $num=0; }else{ $balance = $item->goodNum-$item->usedNum; if($num>=$balance){ $tempNum = $balance; $num-=$balance; }else{ $tempNum = $num; $num=0; } self::where($item->toArray())->save(['usedNum'=>$item->usedNum+$tempNum,'status'=>$item->usedNum+$tempNum>=$item->goodNum?2:1]); } $tep=[ 'orderCode'=>$orderInfo->orderCode, 'cgd_price_id'=>$item->id??0, 'num'=>$tempNum, 'goodPrice'=>$item->goodPrice??0, ]; $totalPrice =bcadd(bcmul($item->goodPrice,strval($tempNum),6),$totalPrice,6); $temp[]=$tep; } return $temp; } public static function checkCgdPriceLow($orderInfo,$num){ } }