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;
class MigrateOrderGoods extends Command{ /** * The name and signature of the console command. * * @var string */ protected $signature = 'migrateData:orderGoods';
/** * The console command description. * * @var string */ protected $description = 'migrate order goods data';
/** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); }
/** * Execute the console command. * * @return int */ public function handle() {
// get old data from old table
$oldData = DB::table('ims_cjdc_order_goods')->get();
$bar = $this->output->createProgressBar(count($oldData)); $bar->start();
$newData = []; foreach ($oldData as $key => $value) {
$goods =DB::table('ims_cjdc_goods')->find($value->good_id);
$newData[] = [ 'order_id' => $value->order_id ?? 0, 'goods_id' => $value->good_id ?? 0, 'number' => $value->number ?? 0, 'status' => 1, 'price' => $value->money ?? 0, 'original_price' => $goods->money2 ?? 0, 'vip_price' => $goods->vip_money ?? 0, 'name' => $value->name ?? '', 'goods_unit' => $value->good_unit ?? '', 'cover_img' => $value->img ?? '', 'spec' => json_encode([]), 'refund_time' => 0, 'created_at' => time(), 'updated_at' => time(), 'refuse_refund_note' => '', ];
$bar->advance(); }
// insert new data to new table
DB::table('lanzu_order_goods')->insert($newData);
$bar->finish(); return 0; }}
|