链街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.7 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_new';
  37. $newTableName = 'lanzu_store_new';
  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;
  57. // 判断是否存在
  58. $exist = DB::table($newTableName)->where('id',$storeId)->exists();
  59. if($exist){
  60. continue;
  61. }
  62. $storeData =[
  63. 'id'=>$storeId,
  64. 'market_id'=>$value->market_id,
  65. 'is_open'=> $value->is_open == 1 ? 1 : 0,
  66. 'is_rest'=> $value->is_rest == 1 ? 1 : 0,
  67. 'status'=>$value->state,
  68. 'category_id'=>$value->md_type,
  69. 'user_id'=>$value->user_id,
  70. 'admin_id'=>$value->admin_id,
  71. 'mm_user_id'=>$value->mm_user_id,
  72. 'sort'=>$value->number,
  73. 'loudspeaker_imei'=>$value->loudspeaker_imei,
  74. 'name'=>$value->name,
  75. 'logo'=>$value->logo,
  76. 'announcement'=>$value->announcement,
  77. 'address' => $value->address,
  78. 'business_license'=> ($storeId == 365) ? '' :$value->yyzz,/* 因为365的数据的营业资质数据乱码,目前只有365这个店铺的有问题 */
  79. 'zm_img' => $value->zm_img,
  80. 'fm_img'=>$value->fm_img,
  81. 'tel' => $value->tel,
  82. 'link_name'=>$value->link_name,
  83. 'link_tel' => $value->link_tel,
  84. 'expire_time'=> strtotime($value->rzdq_time),
  85. 'time1' => (empty($value->time) || $value->time == 'null')? '': $value->time,
  86. 'time2'=> (empty($value->time2) || $value->time2 == 'null')? '': $value->time2,
  87. 'time3' => (empty($value->time3) || $value->time3 == 'null')? '': $value->time3,
  88. 'time4'=> (empty($value->time4) || $value->time4 == 'null')? '': $value->time4,
  89. 'award_money' => $value->award_money,
  90. 'sales'=>$value->score,
  91. 'grade' => $value->sales,
  92. 'code'=>$value->code,
  93. 'environment' => $value->environment,
  94. 'introduction'=> strip_tags($value->details),
  95. 'store_applet_img' => $storeImgPath.$storeId.'.jpg',
  96. 'cash_code_img' => $storePayPath.$storeId.'.jpg',
  97. 'created_at' => strtotime($value->sq_time),
  98. 'updated_at' => time(),
  99. ];
  100. // 获商户摊号
  101. $stallInfo = '';
  102. $res = preg_match('/[0-9]/', $value->name, $matches, PREG_OFFSET_CAPTURE);
  103. if($res && count($matches)>0){
  104. $stallInfo = substr($value->name,$matches[0][1]);
  105. }
  106. $storeData['stall_info'] = $stallInfo;
  107. // 商户经纬度
  108. if(!empty($value->coordinates)){
  109. $coordinatesArr = explode(',',$value->coordinates);
  110. $storeData['lng'] = $coordinatesArr[1];
  111. $storeData['lat'] = $coordinatesArr[0];
  112. }
  113. $newData = $storeData;
  114. $res = DB::table($newTableName)->insert($newData);
  115. if(!$res){
  116. $error[] = ['id'=>$storeId];
  117. break;
  118. }
  119. $bar->advance();
  120. }
  121. $bar->finish();
  122. var_dump([time()-$startTime]);
  123. var_dump($error);
  124. return 0;
  125. }
  126. }