3 changed files with 312 additions and 0 deletions
-
139app/Console/Commands/MigrateCoupon.php
-
89app/Console/Commands/MigrateCouponReceive.php
-
84app/Console/Commands/MigrateCouponUse.php
@ -0,0 +1,139 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Console\Commands; |
||||
|
|
||||
|
use Illuminate\Console\Command; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
use Illuminate\Support\Facades\Schema; |
||||
|
|
||||
|
class MigrateCoupon extends Command |
||||
|
{ |
||||
|
/** |
||||
|
* The name and signature of the console command. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $signature = 'migrateData:coupon'; |
||||
|
|
||||
|
/** |
||||
|
* 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() |
||||
|
{ |
||||
|
$oldSetTableName = 'ims_system_coupon_setting'; |
||||
|
$oldTableName = 'ims_system_coupon_user'; |
||||
|
$oldTypeTableName = 'ims_system_coupon_user_receivetype'; |
||||
|
$newSetTableName = 'lanzu_coupon_setting'; |
||||
|
$newTableName = 'lanzu_coupon'; |
||||
|
$newTypeTableName = 'lanzu_coupon_receive_type'; |
||||
|
|
||||
|
// 判断表是否存在
|
||||
|
if(!Schema::hasTable($oldTableName)){ |
||||
|
var_dump('旧表不存在'); |
||||
|
return 0; |
||||
|
} |
||||
|
if(!Schema::hasTable($newTableName)){ |
||||
|
var_dump('新表不存在'); |
||||
|
return 0; |
||||
|
} |
||||
|
$oldSetData = DB::table($oldSetTableName)->get(); |
||||
|
$oldData = DB::table($oldTableName)->get(); |
||||
|
$oldTypeData = DB::table($oldTypeTableName)->get(); |
||||
|
$bar = $this->output->createProgressBar(count($oldData)); |
||||
|
$bar->start(); |
||||
|
|
||||
|
$newSetData = []; |
||||
|
$newData = []; |
||||
|
$newTypeData = []; |
||||
|
foreach ($oldSetData as $key => $value) { |
||||
|
$newSetData[] = [ |
||||
|
'id' => $value->id, |
||||
|
'name' => $value->name ?? 0, |
||||
|
'category' => $value->category ?? 0, |
||||
|
'value' => $value->value ?? 0, |
||||
|
'desc' => $value->desc ?? '', |
||||
|
'sort' => $value->sort ?? 0, |
||||
|
'status' => $value->status ?? 0, |
||||
|
|
||||
|
'created_at' => time(), |
||||
|
'updated_at' => time(), |
||||
|
]; |
||||
|
} |
||||
|
foreach ($oldData as $key => $value) { |
||||
|
$newData[] = [ |
||||
|
'id' => $value->id, |
||||
|
'status' => $value->status ?? 0, |
||||
|
'active_type' => $value->active_type ?? 0, |
||||
|
'type' => $value->type ?? 0, |
||||
|
'title' => $value->title ?? '', |
||||
|
'introduce' => $value->introduce ?? '', |
||||
|
'start_time' => $value->start_time ?? 0, |
||||
|
'end_time' => $value->end_time, |
||||
|
'full_amount' => $value->full_amount, |
||||
|
'discounts' => $value->discounts ?? 0, |
||||
|
'is_new_user' => $value->is_new_user ?? 0, |
||||
|
|
||||
|
'inventory' => $value->inventory, |
||||
|
'inventory_use' => $value->inventory_use ?? 0, |
||||
|
'market_ids' => json_encode([]), |
||||
|
'category_ids' => json_encode([]), |
||||
|
'category' => $value->category ?? 0, |
||||
|
'discount_type' => $value->discount_type ?? 0, |
||||
|
'activity_available' => json_encode([]), |
||||
|
'weigh' => $value->weigh ?? 0, |
||||
|
'usable_number' => $value->usable_number ?? 0, |
||||
|
'usable_start_time' => $value->usable_start_time ?? 0, |
||||
|
'usable_end_time' => $value->usable_end_time ?? 0, |
||||
|
|
||||
|
'remark' => $value->remark ?? 0, |
||||
|
'add_user_id' => $value->add_user_id ?? 0, |
||||
|
'update_user_id' => $value->update_user_id ?? 0, |
||||
|
'tags' => json_encode([]), |
||||
|
|
||||
|
'created_at' => $value->addtime ?? 0, |
||||
|
'updated_at' => time(), |
||||
|
'deleted_at' => $value->status == -1 ? time() : $value->deleted_at ?? null, |
||||
|
]; |
||||
|
} |
||||
|
foreach ($oldTypeData as $key => $value) { |
||||
|
$newTypeData[] = [ |
||||
|
'id' => $value->id, |
||||
|
'coupon_id' => $value->system_coupon_user_id ?? 0, |
||||
|
|
||||
|
'receive_type' => $value->receive_type ?? 0, |
||||
|
'one_receive_number' => $value->one_receive_number ?? 0, |
||||
|
|
||||
|
'created_at' => $value->add_time ?? 0, |
||||
|
'updated_at' => time(), |
||||
|
]; |
||||
|
$bar->advance(); |
||||
|
} |
||||
|
|
||||
|
// insert new data to new table
|
||||
|
DB::table($newSetTableName)->insert($newSetData); |
||||
|
DB::table($newTableName)->insert($newData); |
||||
|
DB::table($newTypeTableName)->insert($newTypeData); |
||||
|
|
||||
|
$bar->finish(); |
||||
|
return 0; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,89 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Console\Commands; |
||||
|
|
||||
|
use Illuminate\Console\Command; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
use Illuminate\Support\Facades\Schema; |
||||
|
|
||||
|
class MigrateCouponReceive extends Command |
||||
|
{ |
||||
|
/** |
||||
|
* The name and signature of the console command. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $signature = 'migrateData:couponReceive'; |
||||
|
|
||||
|
/** |
||||
|
* 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_receive'; |
||||
|
$newTableName = 'lanzu_coupon_receive_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, |
||||
|
'coupon_id' => $value->system_coupon_user_id ?? 0, |
||||
|
|
||||
|
'user_id' => $value->user_id ?? 0, |
||||
|
'order_main_id' => $value->order_main_id ?? 0, |
||||
|
'receive_time' => $value->receive_time ?? 0, |
||||
|
'number' => $value->number ?? 0, |
||||
|
'number_remain' => $value->number_remain ?? 0, |
||||
|
'status' => $value->status ?? 0, |
||||
|
'update_time' => $value->update_time ?? 0, |
||||
|
'receive_type' => $value->receive_type ?? 0, |
||||
|
|
||||
|
'rebate_type' => $value->rebate_type ?? 0, |
||||
|
'send_user_id' => $value->send_user_id ?? 0, |
||||
|
'phone' => $value->phone ?? '', |
||||
|
|
||||
|
'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; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,84 @@ |
|||||
|
<?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_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, |
||||
|
'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; |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue