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 MigrateCouponUse extends Command{ /** * The name and signature of the console command. * * @var string */ protected $signature = 'migrateData:couponUse';
/** * 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_system_coupon_user_use'; $newTableName = 'lanzu_coupon_use'; // 判断表是否存在
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, 'coupon_id' => $value->system_coupon_user_id ?? 0, 'user_id' => $value->user_id ?? 0, 'order_main_id' => $value->order_main_id ?? 0, 'user_receive_id' => $value->user_receive_id ?? 0, 'number' => $value->number ?? 0, 'use_time' => $value->use_time ?? 0, 'status' => $value->status ?? 0, 'return_time' => $value->return_time ?? 0, 'created_at' => $value->created_at ?? 0, 'updated_at' => time(), ]; $bar->advance(); } // insert new data to new table
DB::table($newTableName)->insert($newData);
$bar->finish(); return 0; }}
|