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

144 lines
5.0 KiB

  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\DB;
  5. use Illuminate\Support\Facades\Schema;
  6. class MigrateStore extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'migrateData:store';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'Command 迁移店铺数据';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return int
  33. */
  34. public function handle()
  35. {
  36. $oldTableName = 'ims_cjdc_store';
  37. $newTableName = 'lanzu_store';
  38. // $storeImgPath = 'QR_code/code_store_img/wx_store_';/* 商户小程序码 */
  39. // $storePayPath = 'QR_code/code_pay_img/wx_pay_';/* 收银二维码 */
  40. // 判断表是否存在
  41. if(!Schema::hasTable($oldTableName)){
  42. var_dump('旧表不存在');
  43. return 0;
  44. }
  45. if(!Schema::hasTable($newTableName)){
  46. var_dump('新表不存在');
  47. return 0;
  48. }
  49. $oldData = DB::table($oldTableName)->orderBy('id','desc')->get();
  50. $bar = $this->output->createProgressBar(count($oldData));
  51. $bar->start();
  52. $startTime = time();
  53. $error = [];
  54. $newData = [];
  55. foreach ($oldData as $key => $value){
  56. $storeId = $value->id ?? 0;
  57. // 判断是否存在
  58. $exist = DB::table($newTableName)->where('id',$storeId)->exists();
  59. if($exist || $storeId == 0){
  60. $error[] = ['store_id'=>$storeId,'msg'=>'已存在或者id为0'];
  61. continue;
  62. }
  63. $storeData =[
  64. 'id'=>$storeId,
  65. 'market_id'=>$value->market_id ?? 0,
  66. 'is_open'=> $value->is_open == 1 ? 1 : 0,
  67. 'is_rest'=> $value->is_rest == 1 ? 1 : 0,
  68. 'status'=>$value->state ?? 0,
  69. 'category_id'=>$value->md_type ?? 0,
  70. 'user_id'=>$value->user_id ?? 0,
  71. 'admin_id'=>$value->admin_id ?? 0,
  72. 'mm_user_id'=>$value->mm_user_id ?? 0,
  73. 'sort'=>$value->number ?? 0,
  74. 'loudspeaker_imei'=>$value->loudspeaker_imei ?? '',
  75. 'name'=>$value->name ?? '',
  76. 'logo'=>$value->logo ?? '',
  77. 'announcement'=>$value->announcement ?? '',
  78. 'address' => $value->address ?? '',
  79. 'business_license'=> ($storeId == 365) ? '' :$value->yyzz ?? '',/* 因为365的数据的营业资质数据乱码,目前只有365这个店铺的有问题 */
  80. 'zm_img' => $value->zm_img ?? '',
  81. 'fm_img'=>$value->fm_img ?? '',
  82. 'tel' => $value->tel ?? '',
  83. 'link_name'=>$value->link_name ?? '',
  84. 'link_tel' => $value->link_tel ?? '',
  85. 'expire_time'=> $value->rzdq_time ? strtotime($value->rzdq_time) : 0,
  86. 'time1' => (empty($value->time) || $value->time == 'null')? '': $value->time,
  87. 'time2'=> (empty($value->time2) || $value->time2 == 'null')? '': $value->time2,
  88. 'time3' => (empty($value->time3) || $value->time3 == 'null')? '': $value->time3,
  89. 'time4'=> (empty($value->time4) || $value->time4 == 'null')? '': $value->time4,
  90. 'award_money' => $value->award_money ?? 0,
  91. 'sales'=>$value->score ?? 0,
  92. 'grade' => $value->sales ?? 0,
  93. 'code'=>$value->code ?? '',
  94. 'environment' => $value->environment ?? '',
  95. 'introduction'=> $value->details ? strip_tags($value->details) :'',
  96. 'store_applet_img' => '',
  97. 'cash_code_img' => '',
  98. 'created_at' => $value->time_add ? strtotime($value->time_add) : 0,
  99. 'updated_at' => time(),
  100. ];
  101. // 获商户摊号
  102. $stallInfo = '';
  103. $res = preg_match('/[0-9]/', $value->name, $matches, PREG_OFFSET_CAPTURE);
  104. if($res && count($matches)>0){
  105. $stallInfo = substr($value->name,$matches[0][1]);
  106. }
  107. $storeData['stall_info'] = $stallInfo;
  108. // 商户经纬度
  109. if(!empty($value->coordinates)){
  110. $coordinatesArr = explode(',',$value->coordinates);
  111. $storeData['lng'] = $coordinatesArr[1];
  112. $storeData['lat'] = $coordinatesArr[0];
  113. }
  114. $newData = $storeData;
  115. $res = DB::table($newTableName)->insert($newData);
  116. if(!$res){
  117. $error[] = ['id'=>$storeId];
  118. break;
  119. }
  120. $bar->advance();
  121. }
  122. $bar->finish();
  123. var_dump([time()-$startTime]);
  124. var_dump($error);
  125. return 0;
  126. }
  127. }