9 changed files with 64 additions and 468 deletions
-
29app/Admin/Controllers/v3/CouponController.php
-
30app/Admin/Controllers/v3/StoreController.php
-
139app/Console/Commands/MigrateCoupon.php
-
23app/Console/Commands/MigrateCouponReceive.php
-
2app/Console/Commands/MigrateCouponUse.php
-
80app/Console/Commands/MigrateFePrint.php
-
80app/Console/Commands/MigrateMarketData.php
-
143app/Console/Commands/MigrateStore.php
-
2app/Models/v3/CouponReceiveType.php
@ -1,139 +0,0 @@ |
|||
<?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; |
|||
} |
|||
} |
|||
@ -1,80 +0,0 @@ |
|||
<?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'; |
|||
// 判断表是否存在
|
|||
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 ?? 0, |
|||
'simnum' => $value->simnum ?? 0 , |
|||
'addtime' => $value->addtime ?? 0, |
|||
'status' => $value->status ?? 0, |
|||
|
|||
'created_at' => $value->addtime ? strtotime($value->addtime) : 0, |
|||
'updated_at' => time(), |
|||
]; |
|||
|
|||
$bar->advance(); |
|||
} |
|||
|
|||
DB::table($newTableName)->insert($newData); |
|||
|
|||
$bar->finish(); |
|||
return 0; |
|||
} |
|||
} |
|||
@ -1,80 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace App\Console\Commands; |
|||
|
|||
use Illuminate\Console\Command; |
|||
use Illuminate\Support\Facades\DB; |
|||
|
|||
class MigrateMarketData extends Command |
|||
{ |
|||
/** |
|||
* The name and signature of the console command. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $signature = 'migrateData:market'; |
|||
|
|||
/** |
|||
* The console command description. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $description = 'migrate market 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_market')->get(); |
|||
|
|||
$bar = $this->output->createProgressBar(count($oldData)); |
|||
$bar->start(); |
|||
|
|||
$newData = []; |
|||
foreach ($oldData as $key => $value) { |
|||
$coordinates = explode(',', $value->coordinates); |
|||
$newData[] = [ |
|||
'id' => $value->id, |
|||
'mp_id' => $value->mp_id ?? 0, |
|||
'name' => $value->name ?? '', |
|||
'logo' => $value->logo ?? '', |
|||
'introduce' => $value->introduce ?? '', |
|||
'imgs' => $value->imgs ?? '', |
|||
'province_id' => 2162, |
|||
'city_id' => 2163, |
|||
'region_id' => 0, |
|||
'address' => $value->address ?? '', |
|||
'tel' => $value->tel ?? '', |
|||
'lat' => $coordinates[0] ?? '', |
|||
'lng' => $coordinates[1] ?? '', |
|||
'status' => $value->status ?? 1, |
|||
'sort' => $value->sort ?? 1, |
|||
'created_at' => $value->addtime ? strtotime($value->addtime) : 0, |
|||
'updated_at' => time(), |
|||
]; |
|||
|
|||
$bar->advance(); |
|||
} |
|||
|
|||
// insert new data to new table
|
|||
DB::table('lanzu_market')->insert($newData); |
|||
|
|||
$bar->finish(); |
|||
return 0; |
|||
} |
|||
} |
|||
@ -1,143 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace App\Console\Commands; |
|||
|
|||
use Illuminate\Console\Command; |
|||
use Illuminate\Support\Facades\DB; |
|||
use Illuminate\Support\Facades\Schema; |
|||
|
|||
class MigrateStore extends Command |
|||
{ |
|||
/** |
|||
* The name and signature of the console command. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $signature = 'migrateData:store'; |
|||
|
|||
/** |
|||
* The console command description. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $description = 'Command 迁移店铺数据'; |
|||
|
|||
/** |
|||
* Create a new command instance. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
} |
|||
|
|||
/** |
|||
* Execute the console command. |
|||
* |
|||
* @return int |
|||
*/ |
|||
public function handle() |
|||
{ |
|||
$oldTableName = 'ims_cjdc_store'; |
|||
$newTableName = 'lanzu_store'; |
|||
// $storeImgPath = 'QR_code/code_store_img/wx_store_';/* 商户小程序码 */
|
|||
// $storePayPath = 'QR_code/code_pay_img/wx_pay_';/* 收银二维码 */
|
|||
// 判断表是否存在
|
|||
if(!Schema::hasTable($oldTableName)){ |
|||
var_dump('旧表不存在'); |
|||
return 0; |
|||
} |
|||
if(!Schema::hasTable($newTableName)){ |
|||
var_dump('新表不存在'); |
|||
return 0; |
|||
} |
|||
|
|||
$oldData = DB::table($oldTableName)->orderBy('id','desc')->get(); |
|||
$bar = $this->output->createProgressBar(count($oldData)); |
|||
$bar->start(); |
|||
$startTime = time(); |
|||
$error = []; |
|||
$newData = []; |
|||
foreach ($oldData as $key => $value){ |
|||
$storeId = $value->id; |
|||
// 判断是否存在
|
|||
$exist = DB::table($newTableName)->where('id',$storeId)->exists(); |
|||
if($exist){ |
|||
continue; |
|||
} |
|||
$storeData =[ |
|||
'id'=>$storeId, |
|||
'market_id'=>$value->market_id, |
|||
'is_open'=> $value->is_open == 1 ? 1 : 0, |
|||
'is_rest'=> $value->is_rest == 1 ? 1 : 0, |
|||
'status'=>$value->state, |
|||
'category_id'=>$value->md_type, |
|||
'user_id'=>$value->user_id, |
|||
'admin_id'=>$value->admin_id, |
|||
|
|||
'mm_user_id'=>$value->mm_user_id, |
|||
'sort'=>$value->number, |
|||
'loudspeaker_imei'=>$value->loudspeaker_imei, |
|||
'name'=>$value->name, |
|||
'logo'=>$value->logo, |
|||
|
|||
'announcement'=>$value->announcement, |
|||
'address' => $value->address, |
|||
'business_license'=> ($storeId == 365) ? '' :$value->yyzz,/* 因为365的数据的营业资质数据乱码,目前只有365这个店铺的有问题 */ |
|||
'zm_img' => $value->zm_img, |
|||
'fm_img'=>$value->fm_img, |
|||
|
|||
'tel' => $value->tel, |
|||
'link_name'=>$value->link_name, |
|||
'link_tel' => $value->link_tel, |
|||
'expire_time'=> strtotime($value->rzdq_time), |
|||
'time1' => (empty($value->time) || $value->time == 'null')? '': $value->time, |
|||
'time2'=> (empty($value->time2) || $value->time2 == 'null')? '': $value->time2, |
|||
'time3' => (empty($value->time3) || $value->time3 == 'null')? '': $value->time3, |
|||
'time4'=> (empty($value->time4) || $value->time4 == 'null')? '': $value->time4, |
|||
|
|||
'award_money' => $value->award_money, |
|||
'sales'=>$value->score, |
|||
'grade' => $value->sales, |
|||
|
|||
'code'=>$value->code, |
|||
'environment' => $value->environment, |
|||
|
|||
'introduction'=> strip_tags($value->details), |
|||
|
|||
'store_applet_img' => '', |
|||
'cash_code_img' => '', |
|||
|
|||
'created_at' => $value->time_add ?strtotime($value->time_add) : 0, |
|||
'updated_at' => time(), |
|||
]; |
|||
|
|||
// 获商户摊号
|
|||
$stallInfo = ''; |
|||
$res = preg_match('/[0-9]/', $value->name, $matches, PREG_OFFSET_CAPTURE); |
|||
if($res && count($matches)>0){ |
|||
$stallInfo = substr($value->name,$matches[0][1]); |
|||
} |
|||
$storeData['stall_info'] = $stallInfo; |
|||
|
|||
// 商户经纬度
|
|||
if(!empty($value->coordinates)){ |
|||
$coordinatesArr = explode(',',$value->coordinates); |
|||
$storeData['lng'] = $coordinatesArr[1]; |
|||
$storeData['lat'] = $coordinatesArr[0]; |
|||
} |
|||
$newData = $storeData; |
|||
$res = DB::table($newTableName)->insert($newData); |
|||
if(!$res){ |
|||
$error[] = ['id'=>$storeId]; |
|||
break; |
|||
} |
|||
$bar->advance(); |
|||
} |
|||
$bar->finish(); |
|||
var_dump([time()-$startTime]); |
|||
var_dump($error); |
|||
return 0; |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue