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.
|
|
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;use Illuminate\Support\Facades\DB;use Illuminate\Support\Facades\Schema;
class MigrateStoreImg extends Command{ /** * The name and signature of the console command. * * @var string */ protected $signature = 'migrateData:storeImg';
/** * The console command description. * * @var string */ protected $description = 'Command 添加店铺小程序码图片路径数据';
/** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); }
/** * Execute the console command. * * @return int */ public function handle() {
$newTableName = 'lanzu_store_new'; $storeImgPath = 'QR_code/code_store_img/wx_store_';/* 商户小程序码 */ $storePayPath = 'QR_code/code_pay_img/wx_pay_';/* 收银二维码 */ if(!Schema::hasTable($newTableName)){ var_dump('新表不存在'); return 0; }
$oldData = DB::table($newTableName)->orderBy('id','desc')->get(); $bar = $this->output->createProgressBar(count($oldData)); $bar->start(); $startTime = time(); $error = []; $newData = []; foreach ($oldData as $key => $value){ $storeId = $value->id; $storeData =[ 'store_applet_img' => $storeImgPath.$storeId.'.jpg', 'cash_code_img' => $storePayPath.$storeId.'.jpg', 'updated_at' => time(), ]; $newData = $storeData; $res = DB::table($newTableName)->where('id',$storeId)->update($newData); if(!$res){ $error[] = ['id'=>$storeId]; break; } $bar->advance(); } $bar->finish(); var_dump([time()-$startTime]); var_dump($error); return 0; }}
|