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

134 lines
4.1 KiB

  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\DB;
  5. class MigrateStore extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'migrateData:store';
  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. $oldTableName = 'ims_cjdc_store_new';
  42. $newTableName = 'lanzu_store_new';
  43. $oldData = DB::table($oldTableName)->orderBy('id','desc')->get();
  44. $bar = $this->output->createProgressBar(count($oldData));
  45. $bar->start();
  46. $startTime = time();
  47. $error = [];
  48. $newData = [];
  49. foreach ($oldData as $key => $value){
  50. $storeId = $value->id;
  51. // 判断在新表是否存在
  52. $exist = DB::table($newTableName)->where('id',$storeId)->exists();
  53. if($exist){
  54. continue;
  55. }
  56. $storeData =[
  57. 'id'=>$storeId,
  58. 'market_id'=>$value->market_id,
  59. 'is_open'=> $value->is_open == 1 ? 1 : 0,
  60. 'is_rest'=> $value->is_rest == 1 ? 1 : 0,
  61. 'status'=>$value->state,
  62. 'category_id'=>$value->md_type,
  63. 'user_id'=>$value->user_id,
  64. 'admin_id'=>$value->admin_id,
  65. 'mm_user_id'=>$value->mm_user_id,
  66. 'sort'=>$value->number,
  67. 'loudspeaker_imei'=>$value->loudspeaker_imei,
  68. 'name'=>$value->name,
  69. 'logo'=>$value->logo,
  70. 'announcement'=>$value->announcement,
  71. 'address' => $value->address,
  72. 'business_license'=> ($storeId == 365) ? '' :$value->yyzz,/* 因为365的数据的营业资质数据乱码,目前只有365这个店铺的有问题 */
  73. 'zm_img' => $value->zm_img,
  74. 'fm_img'=>$value->fm_img,
  75. 'tel' => $value->tel,
  76. 'link_name'=>$value->link_name,
  77. 'link_tel' => $value->link_tel,
  78. 'expire_time'=> strtotime($value->rzdq_time),
  79. 'time1' => $value->time,
  80. 'time2'=>$value->time2,
  81. 'time3' => $value->time3,
  82. 'time4'=>$value->time4,
  83. 'award_money' => $value->award_money,
  84. 'sales'=>$value->score,
  85. 'grade' => $value->sales,
  86. 'code'=>$value->code,
  87. 'environment' => $value->environment,
  88. 'introduction'=> strip_tags($value->details),
  89. 'created_at' => time(),
  90. 'updated_at' => time(),
  91. ];
  92. // 获商户摊号
  93. $stallInfo = '';
  94. $res = preg_match('/[0-9]/', $value->name, $matches, PREG_OFFSET_CAPTURE);
  95. if($res && count($matches)>0){
  96. $stallInfo = substr($value->name,$matches[0][1]);
  97. }
  98. $storeData['stall_info'] = $stallInfo;
  99. // 商户经纬度
  100. if(!empty($value->coordinates)){
  101. $coordinatesArr = explode(',',$value->coordinates);
  102. $storeData['lng'] = $coordinatesArr[1];
  103. $storeData['lat'] = $coordinatesArr[0];
  104. }
  105. $newData = $storeData;
  106. $res = DB::table($newTableName)->insert($newData);
  107. if(!$res){
  108. $error[] = ['id'=>$storeId];
  109. break;
  110. }
  111. $bar->advance();
  112. }
  113. $bar->finish();
  114. var_dump([time()-$startTime]);
  115. var_dump($error);
  116. return 0;
  117. }
  118. }