AfreshOrderCost(); } public function AfreshOrderCost(){ $order_list = Order::where('warehouse', 3)->where('is_del', 0)->where('status', '=', 3)->get(); foreach($order_list as $k=>$order){ $order_cost = 0; //获取商品 $goods = OrderGoodsSkus::where('order_id', $order->id)->where('is_del', 0)->get(); foreach($goods as $good){ //获取sku成本 $sku = GoodsSkus::select('referenceCost', 'price')->where('id', $good->sku_id)->first(); if($good->send_num>=400){ //修改订单商品信息 $send_num = $good->send_num / 500; OrderGoodsSkus::where('id', $good->id)->update(['send_num'=>$send_num, 'price'=>$sku->price, 'num'=>$send_num]); $good->send_num = $send_num; } //重新计算订单成本 $order_cost += $good->send_num * $sku->referenceCost; } //更新成本 $res = Order::where('id', $order->id)->update(['cost'=>$order_cost]); echo "\n".$order->id. ' 成本:'.$order_cost.' 结果:'.$res; } } }