Açıklama Yok

AfreshOrderCost.php 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use DB;
  5. use App\Order;
  6. use App\OrderGoodsSkus;
  7. use App\GoodsSkus;
  8. class AfreshOrderCost extends Command {
  9. protected $signature = 'AfreshOrderCost';
  10. /**
  11. * The console command description.
  12. *
  13. * @var string
  14. */
  15. protected $description = '重洗C仓订单成本';
  16. public function handle()
  17. {
  18. $this->AfreshOrderCost();
  19. }
  20. public function AfreshOrderCost(){
  21. $order_list = Order::where('warehouse', 3)->where('is_del', 0)->where('status', '=', 3)->get();
  22. foreach($order_list as $k=>$order){
  23. $order_cost = 0;
  24. //获取商品
  25. $goods = OrderGoodsSkus::where('order_id', $order->id)->where('is_del', 0)->get();
  26. foreach($goods as $good){
  27. //获取sku成本
  28. $sku = GoodsSkus::select('referenceCost', 'price')->where('id', $good->sku_id)->first();
  29. if($good->send_num>=400){
  30. //修改订单商品信息
  31. $send_num = $good->send_num / 500;
  32. OrderGoodsSkus::where('id', $good->id)->update(['send_num'=>$send_num, 'price'=>$sku->price, 'num'=>$send_num]);
  33. $good->send_num = $send_num;
  34. }
  35. //重新计算订单成本
  36. $order_cost += $good->send_num * $sku->referenceCost;
  37. }
  38. //更新成本
  39. $res = Order::where('id', $order->id)->update(['cost'=>$order_cost]);
  40. echo "\n".$order->id. ' 成本:'.$order_cost.' 结果:'.$res;
  41. }
  42. }
  43. }