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.
80 lines
1.9 KiB
80 lines
1.9 KiB
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
class MigrateFePrint extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'migrateData:fePrint';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'migrate 迁移打印机数据';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function handle()
|
|
{
|
|
$oldTableName = 'ims_cjdc_feprint';
|
|
$newTableName = 'lanzu_feprint_copy';
|
|
// 判断表是否存在
|
|
if(!Schema::hasTable($oldTableName)){
|
|
var_dump('旧表不存在');
|
|
return 0;
|
|
}
|
|
if(!Schema::hasTable($newTableName)){
|
|
var_dump('新表不存在');
|
|
return 0;
|
|
}
|
|
$oldData = DB::table($oldTableName)->get();
|
|
|
|
$bar = $this->output->createProgressBar(count($oldData));
|
|
$bar->start();
|
|
$newData = [];
|
|
foreach ($oldData as $key => $value) {
|
|
$newData[] = [
|
|
'id' => $value->id,
|
|
'name' => $value->name,
|
|
'sn' => $value->sn,
|
|
'market_id' => $value->market_id ,
|
|
'simnum' => $value->simnum,
|
|
'addtime' => $value->addtime,
|
|
'status' => $value->status,
|
|
|
|
'created_at' => strtotime($value->addtime),
|
|
'updated_at' => time(),
|
|
];
|
|
|
|
$bar->advance();
|
|
}
|
|
|
|
DB::table($newTableName)->insert($newData);
|
|
|
|
$bar->finish();
|
|
return 0;
|
|
}
|
|
}
|