1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace App\Console\Commands;
- use Illuminate\Console\Command;
- use DB;
- use App\Order;
- use App\OrderGoodsSkus;
- use App\GoodsSkus;
- class AfreshOrderCost extends Command {
- protected $signature = 'AfreshOrderCost';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '重洗C仓订单成本';
- public function handle()
- {
- $this->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;
- }
-
- }
- }
|