Browse Source

打印机表迁移

master
liangyuyan 5 years ago
parent
commit
adaa27adb4
  1. 80
      app/Console/Commands/MigrateFePrint.php
  2. 93
      app/Console/Commands/MigrateShoppingCart.php
  3. 192
      app/Console/Commands/MigrateUserAccount.php
  4. 65
      app/Console/Commands/SetGoodsMarketId.php

80
app/Console/Commands/MigrateFePrint.php

@ -0,0 +1,80 @@
<?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_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,
'name' => $value->name,
'sn' => $value->sn,
'market_id' => $value->market_id ,
'simnum' => $value->simnum,
'addtime' => $value->addtime,
'status' => $value->status,
'created_at' => strtotime($value->addtime),
'updated_at' => time(),
];
$bar->advance();
}
DB::table($newTableName)->insert($newData);
$bar->finish();
return 0;
}
}

93
app/Console/Commands/MigrateShoppingCart.php

@ -1,93 +0,0 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class MigrateShoppingCart extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'migrateData:shoppingCart';
/**
* 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_shopcar';
$oldStoreTableName = 'ims_cjdc_store';
$newTableName = 'lanzu_shopping_cart';
// 判断表是否存在
if(!Schema::hasTable($oldTableName)){
var_dump('旧表不存在');
return 0;
}
if(!Schema::hasTable($newTableName)){
var_dump('新表不存在');
return 0;
}
return 0;
$oldData = DB::table($oldTableName)->orderBy('id','asc')->get();
$oldStoreData = DB::table($oldStoreTableName)->pluck('market_id','id');
$bar = $this->output->createProgressBar(count($oldData));
$bar->start();
$startTime = time();
$error = [];
foreach ($oldData as $key => $value){
$cartId = $value->id;
// 判断是否存在
$exist = DB::table($newTableName)->where('id',$cartId)->exists();
if($exist){
continue;
}
$newData =[
'id'=>$cartId,
'market_id'=> isset($oldStoreData[$value->store_id])?$oldStoreData[$value->store_id]:0,
'store_id'=>$value->store_id,
'goods_id'=>$value->good_id,
'user_id'=>$value->user_id,
'num'=>$value->num,
'activity_type'=>1,
'created_at' => time(),
'updated_at' => time(),
];
$res = DB::table($newTableName)->insert($newData);
if(!$res){
$error[] = ['id'=>$cartId];
break;
}
$bar->advance();
}
$bar->finish();
var_dump([time()-$startTime]);
var_dump($error);
return 0;
}
}

192
app/Console/Commands/MigrateUserAccount.php

@ -1,192 +0,0 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class MigrateUserAccount extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'migrateData:userAccount';
/**
* 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_qbmx';
$newTableName = 'lanzu_financial_record';
// 判断表是否存在
if(!Schema::hasTable($oldTableName)){
var_dump('旧表不存在');
return 0;
}
if(!Schema::hasTable($newTableName)){
var_dump('新表不存在');
return 0;
}
$oldData = DB::table($oldTableName)->orderBy('id','asc')->get();
$bar = $this->output->createProgressBar(count($oldData));
$bar->start();
$startTime = time();
$error = [];
foreach ($oldData as $key => $value){
$type = $value->type;
$note = $value->note;
$userId = $value->user_id;
if(empty($userId) || empty($type) || empty($note)){
$error[] = ['id'=>$value->id];
continue;
}
$typeArr = $this->getType($type,$note);
$userType = 1;
$money = $value->money;
$moneyType = $typeArr['money_type'];
$sourceId = $value->order_id;
$sourceType = $typeArr['source_type'];
$desc = $typeArr['desc'];
$comment = $typeArr['comment'];
$newData =[
'user_id'=>$userId,
'user_type'=>$userType,
'money'=>$money,
'money_type'=>$moneyType,
'source_id'=>$sourceId,
'source_type'=>$sourceType,
'desc'=>$desc,
'comment'=>$comment,
'status'=>1,
'created_at' => $moneyType == 8 ? $value->time : strtotime($value->time),
'updated_at' => time(),
];
// 判断是否存在 总账
$exist = DB::table($newTableName)
->where('user_id',$userId)
->where('user_type',$userType)
->where('source_id',$sourceId)
->where('source_type',$sourceType)
->where('money',$money)
->where('money_type',$moneyType)
->exists();
if(!$exist){
if(!DB::table($newTableName)->insert($newData)){
$error[] = ['id'=>$value->id,'msg'=>'总账添加失败'];
break;
}
}
// 判断是否存在 用户账
$mod = bcmod((string)$userId, '5', 0);
$newSubTableName = $newTableName.'_'.$mod;
$existSub = DB::table($newSubTableName)
->where('user_id',$userId)
->where('user_type',$userType)
->where('source_id',$sourceId)
->where('source_type',$sourceType)
->where('money',$money)
->where('money_type',$moneyType)
->exists();
if(!$existSub){
if(!DB::table($newSubTableName)->insert($newData)){
$error[] = ['id'=>$value->id,'msg'=>'用户账添加失败'];
break;
}
}
$bar->advance();
}
$bar->finish();
var_dump([time()-$startTime]);
var_dump($error);
return 0;
}
public function getType($type,$note)
{
$array = [];
// 1加,2减
switch($type){
case 1:
if($note == '当面付订单'){
$array['money_type'] = 100;
$array['source_type'] = 1;
$array['desc'] = '用户下单(线下)';
$array['comment'] = '用户下单';
}else if($note == '外卖订单'){
$array['money_type'] = 101;
$array['source_type'] = 1;
$array['desc'] = '用户下单(线上)';
$array['comment'] = '用户下单';
}
break;
case 2:
if($note == '订单退款'){
$array['money_type'] = 8;
$array['source_type'] = 1;
$array['desc'] = '线上订单退款';
$array['comment'] = '线上订单退款到微信';
}
break;
default:
break;
}
return $array;
}
// 当面付订单
// $desc='用户下单(线下)',
// $comment='用户下单'
// 外卖订单
// $desc='用户下单(线上)',
// $comment='用户下单'
// 订单退款
// $desc = '线上订单退款',
// $comment = '线上订单退款到微信'
// 后台充值
// 在线充值
// 订单拒绝
}

65
app/Console/Commands/SetGoodsMarketId.php

@ -1,65 +0,0 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\LanzuGoods;
use App\Models\LanzuStore;
class SetGoodsMarketId extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'migrateData:SetGoodsMarketId';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command 根据商品表中storeid设置市场id';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$goods = LanzuGoods::all();
$no_store_ids = [];
foreach($goods as $key => $item){
$store = LanzuStore::find($item->store_id);
if($store){
$item->market_id = $store->market_id;
$item->save();
print_r($item->id.'\r\n');
}else{
$no_store_ids[] = $item->store_id;
break;
}
}
var_dump($no_store_ids);
return 0;
}
}
Loading…
Cancel
Save