isEmpty()) throw new Exception("未找到订单数据"); if($order->origin_price==0){ $temp = CgdPrice::checkCgdPrice($order); }else{ $temp = CgdPrice::checkCgdNum($order); } if(!empty($temp))self::insertAll($temp); } public static function RePrice($orderId,$num){ return ; $order = Sale::findOrEmpty($orderId); if($order->isEmpty()) throw new Exception('未找到订单数据'); if($order->is_activity==0){ while ($num>0){ $saleCgd=self::where(['orderCode'=>$order->orderCode])->order("id","desc")->findOrEmpty(); if($saleCgd->isEmpty())throw new Exception('未找到订单成本数据'); $tempNum=0; if($saleCgd->num<=$num){ $tempNum=$saleCgd->num; $num -=$saleCgd->num; $saleCgd->delete(); }else{ $tempNum=$num; $saleCgd->num-=$num; $num=0; $saleCgd->save(); } if($saleCgd->cgd_price_id!=0){ $cgdinfo = CgdPrice::findOrEmpty($saleCgd->cgd_price_id); if($cgdinfo->usedNum< $tempNum)throw new Exception('订单成本数据有误'); $save=[ 'usedNum'=>$cgdinfo->usedNum-$tempNum, 'status'=>$cgdinfo->usedNum-$tempNum<$cgdinfo->goodNum?1:2 ]; $cgdinfo->save($save); } } $origin = self::where(['orderCode'=>$order->orderCode])->order('id','desc')->sum(Db::raw("goodPrice*num")); $order->origin_price = bcdiv($origin,strval($order->good_num-$num-$order->th_num),6); $order->save(); } } }