链街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.

143 lines
4.5 KiB

  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\DB;
  5. class MigrateGoods extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'migrateData:goods';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = 'Command 迁移商品数据';
  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. // 如果表不存在则创建
  36. // if(!Schema::hasTable('lanzu_store_users')){
  37. // Schema::create('lanzu_store_users',function (Blueprint $table){
  38. // $table->id();
  39. // });
  40. // }
  41. $specData = [
  42. '克' => '净含量',
  43. '斤' => '净含量',
  44. '两' => '净含量',
  45. '只' => '净含量',
  46. '份' => '净含量',
  47. 'g' => '净含量',
  48. 'l' => '净含量',
  49. 'ml' => '净含量',
  50. 'ML' => '净含量',
  51. 'L' => '净含量',
  52. '个' => '净含量',
  53. '条' => '净含量',
  54. '公分' => '净含量',
  55. '边' => '净含量',
  56. '包' => '净含量',
  57. '辣' => '口味',
  58. '馅' => '馅料',
  59. 'mm' => '尺寸'
  60. ];
  61. $oldData = DB::table('ims_cjdc_goods_new')->get();
  62. $bar = $this->output->createProgressBar(count($oldData));
  63. $bar->start();
  64. $startTime = time();
  65. $total = 0;
  66. foreach ($oldData as $value){
  67. $goodsData =[
  68. // 'id'=>$value->id,
  69. 'market_id'=>$value->market_id,
  70. 'store_id'=>$value->store_id,
  71. 'on_sale'=> $value->is_show == 1 ? 1 : 0,
  72. 'sort'=>$value->num,
  73. 'price'=>$value->money,
  74. 'original_price'=>$value->money2,
  75. 'vip_price'=>$value->vip_money,
  76. 'sales'=>$value->sales,
  77. 'start_num'=>$value->start_num,
  78. 'restrict_num'=>$value->restrict_num,
  79. 'is_infinite'=> $value->is_max == 1 ? 1 :0,
  80. 'inventory'=>$value->inventory,
  81. 'name'=>$value->name,
  82. 'cover_img'=>$value->logo,
  83. 'goods_unit'=>$value->good_unit,
  84. 'spec'=>$value->spec,
  85. 'content'=>$value->content,
  86. 'details'=>$value->details,
  87. ];
  88. $specs = DB::table('ims_cjdc_spec_combination_new')->where('good_id',$value->id)->get();
  89. if(!empty($specs)){
  90. foreach($specs as $vs){
  91. $spec = ['spec_key'=>'净含量','spec_value'=>$vs->combination];
  92. if(strstr($vs->combination,'辣')){
  93. $spec['spec_key'] = '口味';
  94. }else if(strstr($vs->combination,'馅')){
  95. $spec['spec_key'] = '馅料';
  96. }else if(strstr($vs->combination,'mm')){
  97. $spec['spec_key'] = '尺寸';
  98. }
  99. $goodsData['spec'] = json_encode($spec);
  100. $newData = $goodsData;
  101. $newBanner = [
  102. 'type' =>1,
  103. 'path' =>$value->logo,
  104. 'created_at' =>time(),
  105. 'updated_at' =>time(),
  106. ];
  107. $id = DB::table('lanzu_goods_new')->insertGetId($newData);
  108. $newBanner['goods_id'] = $id;
  109. DB::table('lanzu_goods_banners_new')->insertGetId($newBanner);
  110. $total++;
  111. if($total == 2){
  112. break;
  113. }
  114. }
  115. }else{
  116. $newData = $goodsData;
  117. $id = DB::table('lanzu_goods_new')->insertGetId($newData);
  118. $newBanner['goods_id'] = $id;
  119. DB::table('lanzu_goods_banners_new')->insertGetId($newBanner);
  120. $total++;
  121. if($total == 2){
  122. break;
  123. }
  124. }
  125. $bar->advance();
  126. }
  127. $bar->finish();
  128. echo '\r\n ';
  129. echo time()-$startTime;
  130. echo '\r\n '.$total;
  131. return 0;
  132. }
  133. }