|
|
@ -0,0 +1,79 @@ |
|
|
|
|
|
<?php |
|
|
|
|
|
|
|
|
|
|
|
namespace App\Console\Commands; |
|
|
|
|
|
|
|
|
|
|
|
use Illuminate\Console\Command; |
|
|
|
|
|
use Illuminate\Support\Facades\DB; |
|
|
|
|
|
use Illuminate\Support\Facades\Schema; |
|
|
|
|
|
|
|
|
|
|
|
class MigrateOrderStatistics extends Command |
|
|
|
|
|
{ |
|
|
|
|
|
/** |
|
|
|
|
|
* The name and signature of the console command. |
|
|
|
|
|
* |
|
|
|
|
|
* @var string |
|
|
|
|
|
*/ |
|
|
|
|
|
protected $signature = 'migrateData:orderStatistics'; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 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_order_sales_statistics'; |
|
|
|
|
|
$newTableName = 'lanzu_order_sales_statistics_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, |
|
|
|
|
|
'money' => $value->money ?? 0, |
|
|
|
|
|
'user_id' => $value->user_id ?? 0, |
|
|
|
|
|
'store_id' => $value->store_id ?? 0, |
|
|
|
|
|
'market_id' => $value->market_id ?? 0 , |
|
|
|
|
|
'order_id' => $value->order_id ?? 0, |
|
|
|
|
|
|
|
|
|
|
|
'created_at' => $value->createtime ?? 0, |
|
|
|
|
|
'updated_at' => time(), |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
$bar->advance(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
DB::table($newTableName)->insert($newData); |
|
|
|
|
|
|
|
|
|
|
|
$bar->finish(); |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
} |