链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
5.8 KiB

  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\DB;
  5. class MigrateOrder extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'migrateData:order';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = 'migrate order data';
  19. /**
  20. * Create a new command instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. }
  28. /**
  29. * Execute the console command.
  30. *
  31. * @return int
  32. */
  33. public function handle()
  34. {
  35. // main order
  36. $orderMain = DB::table('ims_cjdc_order_main')->get();
  37. $bar = $this->output->createProgressBar(count($orderMain));
  38. $bar->start();
  39. foreach ($orderMain as $k => $main) {
  40. DB::beginTransaction();
  41. try {
  42. // 主订单
  43. $dataMain = [
  44. 'market_id' => $main->market_id ?? 0,
  45. 'order_num' => $main->order_num ?? '',
  46. 'global_order_id' => $main->global_order_id ?? 0,
  47. 'user_id' => $main->user_id ?? 0,
  48. 'pay_type' => $main->pay_type ?? 0,
  49. 'type' => $main->type ?? 0,
  50. 'order_type' => $main->order_type ?? 0,
  51. 'shipping_type' => $main->dada_status == 0 ? 1 : 2,
  52. 'money' => $main->money ?? 0,
  53. 'total_money' => $main->total_money ?? 0,
  54. 'services_money' => 0,
  55. 'coupon_money' => $main->yhq_money2 ?? 0,
  56. 'delivery_money' => $main->dada_fee ?? 0,
  57. 'state' => $main->state ?? 0,
  58. 'pay_time' => $main->pay_time ? strtotime($main->pay_time) : 0,
  59. 'receive_time' => $main->jd_time ? strtotime($main->jd_time) : 0,
  60. 'delivery_time' => 0,
  61. 'complete_time' => $main->complete_time ? strtotime($main->complete_time) : 0,
  62. 'cancel_time' => $main->complete_time ? strtotime($main->complete_time) : 0,
  63. 'refund_time' => $main->refund_time ?? 0,
  64. 'tel' => $main->tel ?? '',
  65. 'address' => $main->address ?? '',
  66. 'lat' => $main->lat ?? '',
  67. 'lng' => $main->lng ?? '',
  68. 'name' => $main->name ?? '',
  69. 'print_num' => $main->print_num ?? 0,
  70. 'plat' => $main->plat ?? 0,
  71. 'refuse_refund_note' => $main->refuse_refund_note ?? '',
  72. 'delivery_time_note' => $main->delivery_time ?? '',
  73. 'total_refund_note' => $main->total_refund_note ?? '',
  74. 'note' => $main->note ?? '',
  75. 'created_at' => $main->time_add ?? 0,
  76. 'updated_at' => 0,
  77. ];
  78. $newMainId = DB::table('lanzu_order_main')->insertGetId($dataMain);
  79. // 子订单
  80. $orderChildren = DB::table('ims_cjdc_order')->where(['order_main_id' => $main->id])->get();
  81. foreach ($orderChildren as $kChild => $child) {
  82. // 子订单
  83. $dataChild = [
  84. 'order_main_id' => $newMainId ?? 0,
  85. 'user_id' => $child->user_id ?? 0,
  86. 'store_id' => $child->store_id ?? 0,
  87. 'status' => 1,
  88. 'refund_time' => 0,
  89. 'order_num' => $child->order_num ?? '',
  90. 'money' => $child->money ?? 0,
  91. 'oid' => $child->oid ?? 0,
  92. 'refuse_refund_note' => '',
  93. 'refund_note' => '',
  94. 'note' => $child->note ?? '',
  95. 'created_at' => $child->time_add ? strtotime($child->time_add) : 0,
  96. 'updated_at' => $child->time_add ? strtotime($child->time_add) : 0,
  97. ];
  98. $newChildId = DB::table('lanzu_order')->insertGetId($dataChild);
  99. // 订单商品
  100. $orderGoods = DB::table('ims_cjdc_order_goods')->where(['order_id' => $child->id])->get();
  101. $dataGoods = [];
  102. foreach ($orderGoods as $kGoods => $goods) {
  103. // 订单商品
  104. $dataGoods[] = [
  105. 'order_id' => $newChildId ?? 0,
  106. 'goods_id' => $goods->good_id ?? 0,
  107. 'number' => $goods->number ?? 0,
  108. 'status' => 1,
  109. 'price' => $goods->money ?? 0,
  110. 'original_price' => $goods->money2 ?? 0,
  111. 'vip_price' => $goods->vip_money ?? 0,
  112. 'name' => $goods->name ?? '',
  113. 'goods_unit' => $goods->good_unit ?? '',
  114. 'cover_img' => $goods->img ?? '',
  115. 'spec' => json_encode([]),
  116. 'refund_time' => 0,
  117. 'created_at' => time(),
  118. 'updated_at' => time(),
  119. 'refuse_refund_note' => '',
  120. ];
  121. }
  122. DB::table('lanzu_order_goods')->insert($dataGoods);
  123. }
  124. $bar->advance();
  125. DB::commit();
  126. } catch (\Exception $e) {
  127. $this->info(json_encode(['order_id' => $main->id, 'exception' => $e->getMessage()]));
  128. DB::rollBack();
  129. }
  130. }
  131. $bar->finish();
  132. return 0;
  133. }
  134. }