12 changed files with 506 additions and 136 deletions
-
6app/Admin/Actions/Grid/v3/CouponForbidden.php
-
60app/Console/Commands/MigrateOrder.php
-
3app/Console/Commands/MigrateOrderStatistics.php
-
144app/Console/Commands/MigrateStore.php
-
250app/Console/Commands/MigrateStoreBalance.php
-
22app/Console/Commands/MigrateStoreFinancial.php
-
1app/Console/Commands/MigrateStoreWithdrawal.php
-
25app/Console/Commands/MigrateUser.php
-
2app/Console/Commands/MigrateUserAddr.php
-
11app/Console/Commands/MigrateUserCollection.php
-
5app/Console/Commands/SetStoreBalance.php
-
57app/Console/Commands/SetStoreUsers.php
@ -0,0 +1,144 @@ |
|||
<?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 ?? 0; |
|||
// 判断是否存在
|
|||
$exist = DB::table($newTableName)->where('id',$storeId)->exists(); |
|||
if($exist || $storeId == 0){ |
|||
$error[] = ['store_id'=>$storeId,'msg'=>'已存在或者id为0']; |
|||
continue; |
|||
} |
|||
$storeData =[ |
|||
'id'=>$storeId, |
|||
'market_id'=>$value->market_id ?? 0, |
|||
'is_open'=> $value->is_open == 1 ? 1 : 0, |
|||
'is_rest'=> $value->is_rest == 1 ? 1 : 0, |
|||
'status'=>$value->state ?? 0, |
|||
'category_id'=>$value->md_type ?? 0, |
|||
'user_id'=>$value->user_id ?? 0, |
|||
'admin_id'=>$value->admin_id ?? 0, |
|||
|
|||
'mm_user_id'=>$value->mm_user_id ?? 0, |
|||
'sort'=>$value->number ?? 0, |
|||
'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'=> $value->rzdq_time ? strtotime($value->rzdq_time) : 0, |
|||
'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 ?? 0, |
|||
'sales'=>$value->score ?? 0, |
|||
'grade' => $value->sales ?? 0, |
|||
|
|||
'code'=>$value->code ?? '', |
|||
'environment' => $value->environment ?? '', |
|||
|
|||
'introduction'=> $value->details ? 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