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

79 lines
2.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 MigrateStoreImg extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'migrateData:storeImg';
  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. $newTableName = 'lanzu_store_new';
  37. $storeImgPath = 'QR_code/code_store_img/wx_store_';/* 商户小程序码 */
  38. $storePayPath = 'QR_code/code_pay_img/wx_pay_';/* 收银二维码 */
  39. if(!Schema::hasTable($newTableName)){
  40. var_dump('新表不存在');
  41. return 0;
  42. }
  43. $oldData = DB::table($newTableName)->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. $storeData =[
  52. 'store_applet_img' => $storeImgPath.$storeId.'.jpg',
  53. 'cash_code_img' => $storePayPath.$storeId.'.jpg',
  54. 'updated_at' => time(),
  55. ];
  56. $newData = $storeData;
  57. $res = DB::table($newTableName)->where('id',$storeId)->update($newData);
  58. if(!$res){
  59. $error[] = ['id'=>$storeId];
  60. break;
  61. }
  62. $bar->advance();
  63. }
  64. $bar->finish();
  65. var_dump([time()-$startTime]);
  66. var_dump($error);
  67. return 0;
  68. }
  69. }