Browse Source

迁移订单数据添加配送距离字段

master
liangyuyan 5 years ago
parent
commit
091525a3b8
  1. 2
      app/Console/Commands/MigrateOrder.php
  2. 223
      app/Console/Commands/MigrateStoreAccount.php
  3. 79
      app/Console/Commands/MigrateStoreImg.php

2
app/Console/Commands/MigrateOrder.php

@ -84,6 +84,8 @@ class MigrateOrder extends Command
'shipping_name' => $main->shipping_name ?? '', 'shipping_name' => $main->shipping_name ?? '',
'horseman_id' => $main->horseman_id ?? 0, 'horseman_id' => $main->horseman_id ?? 0,
'delivery_distance' => $main->delivery_distance ?? 0,
'created_at' => $main->time_add ?? 0, 'created_at' => $main->time_add ?? 0,
'updated_at' => time(), 'updated_at' => time(),
]; ];

223
app/Console/Commands/MigrateStoreAccount.php

@ -1,223 +0,0 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class MigrateStoreAccount extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'migrateData:storeAccount';
/**
* 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_account';
$oldStoreTableName = 'ims_cjdc_store';
$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();
$oldStoreData = DB::table($oldStoreTableName)->pluck('user_id','id');
$bar = $this->output->createProgressBar(count($oldData));
$bar->start();
$startTime = time();
$error = [];
foreach ($oldData as $key => $value){
$type = $value->type;
$note = $value->note;
$storeId = $value->store_id;
$userId = $value->user_id;
if(empty($storeId) || empty($type) || empty($note)){
$error[] = ['id'=>$value->id];
continue;
}
if(empty($userId)){
if(isset($oldStoreData[$storeId])){
$userId = $oldStoreData[$storeId];
}else{
$error[] = ['id'=>$value->id,'msg'=>'找不到用户'];
continue;
}
}
$typeArr = $this->getType($type,$note);
$userType = 5;
$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' => 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'] = 5;
$array['source_type'] = 1;
$array['desc'] = '用户店铺首单奖励';
$array['comment'] = '用户当面付商户奖励';
}else if($note == '新用户下单成功,平台奖励'){
$array['money_type'] = 4;
$array['source_type'] = 1;
$array['desc'] = '新用户下单奖励';
$array['comment'] = '用户当面付商户奖励';
}else if($note == '当面付订单收入'){
$array['money_type'] = 7;
$array['source_type'] = 1;
$array['desc'] = '线下当面付订单收入';
$array['comment'] = '用户订单完成';
}else if($note == '线上订单' || $note == '线上订单收入' || $note == '线上订单收入-测试'){
$array['money_type'] = 6;
$array['source_type'] = 1;
$array['desc'] = '线上外卖订单收入';
$array['comment'] = '用户订单完成';
}
break;
case 2:
if($note == '提现到微信'){
$array['money_type'] = 105;
$array['source_type'] = 2;
$array['desc'] = '商户提现';
$array['comment'] = '商户提现打款';
}
break;
default:
break;
}
return $array;
}
// 用户下单成功,平台奖励
// $desc='用户店铺首单奖励';
// $comment='用户当面付商户奖励';
// 新用户下单成功,平台奖励
// $desc='新用户下单奖励';
// $comment='用户当面付商户奖励';
// 线上订单
// $desc = '线上外卖订单收入';
// $comment = '用户订单完成';
// 当面付订单收入
// $desc = '线下当面付订单收入';
// $comment = '用户订单完成';
// 线上订单退款
// $desc = '线上订单退款';
// $comment = '线上订单退款到微信';
// 提现到微信
// $desc = '商户提现';
// $comment = '商户提现打款';
}

79
app/Console/Commands/MigrateStoreImg.php

@ -1,79 +0,0 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class MigrateStoreImg extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'migrateData:storeImg';
/**
* 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()
{
$newTableName = 'lanzu_store_new';
$storeImgPath = 'QR_code/code_store_img/wx_store_';/* 商户小程序码 */
$storePayPath = 'QR_code/code_pay_img/wx_pay_';/* 收银二维码 */
if(!Schema::hasTable($newTableName)){
var_dump('新表不存在');
return 0;
}
$oldData = DB::table($newTableName)->orderBy('id','desc')->get();
$bar = $this->output->createProgressBar(count($oldData));
$bar->start();
$startTime = time();
$error = [];
$newData = [];
foreach ($oldData as $key => $value){
$storeId = $value->id;
$storeData =[
'store_applet_img' => $storeImgPath.$storeId.'.jpg',
'cash_code_img' => $storePayPath.$storeId.'.jpg',
'updated_at' => time(),
];
$newData = $storeData;
$res = DB::table($newTableName)->where('id',$storeId)->update($newData);
if(!$res){
$error[] = ['id'=>$storeId];
break;
}
$bar->advance();
}
$bar->finish();
var_dump([time()-$startTime]);
var_dump($error);
return 0;
}
}
Loading…
Cancel
Save