From 3eb9c25ba7823eb3ad6a522045167c227407685a Mon Sep 17 00:00:00 2001
From: lanzu_qinsheng <334039090@qq.com>
Date: Fri, 18 Sep 2020 19:45:06 +0800
Subject: [PATCH 1/4] =?UTF-8?q?=E9=9A=90=E8=97=8F=E8=AE=A2=E5=8D=95?=
=?UTF-8?q?=E8=AF=A6=E6=83=85=E9=87=8C=E6=B2=A1=E6=9C=89=E5=A4=87=E6=B3=A8?=
=?UTF-8?q?=E7=9A=84=20=E5=A4=87=E6=B3=A8=E5=AD=97=E6=AE=B5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
resources/views/orderdetail.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/resources/views/orderdetail.php b/resources/views/orderdetail.php
index 1e811ec..697f483 100644
--- a/resources/views/orderdetail.php
+++ b/resources/views/orderdetail.php
@@ -23,7 +23,7 @@
配送费:{{delivery_money}} 元 |
- | 订单备注:{{note}} |
+ 订单备注:{{note}} |
拒绝退款原因:{{refuse_refund_note}} |
From 41426b5b85c9be2368eafff8760856e78605ddf9 Mon Sep 17 00:00:00 2001
From: liangyuyan <1103300295@qq.com>
Date: Fri, 18 Sep 2020 20:15:48 +0800
Subject: [PATCH 2/4] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=BF=81=E7=A7=BB?=
=?UTF-8?q?=E8=84=9A=E6=9C=AC=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Admin/Actions/Grid/v3/CouponForbidden.php | 6 +-
app/Console/Commands/MigrateOrder.php | 102 ++++---
.../Commands/MigrateOrderStatistics.php | 3 +-
app/Console/Commands/MigrateStore.php | 144 ++++++++++
app/Console/Commands/MigrateStoreBalance.php | 264 ++++++++++++++----
.../Commands/MigrateStoreFinancial.php | 22 +-
.../Commands/MigrateStoreWithdrawal.php | 1 +
app/Console/Commands/MigrateUser.php | 25 +-
app/Console/Commands/MigrateUserAddr.php | 2 +-
.../Commands/MigrateUserCollection.php | 11 +-
app/Console/Commands/SetStoreBalance.php | 5 +-
app/Console/Commands/SetStoreUsers.php | 57 ++--
12 files changed, 506 insertions(+), 136 deletions(-)
create mode 100644 app/Console/Commands/MigrateStore.php
diff --git a/app/Admin/Actions/Grid/v3/CouponForbidden.php b/app/Admin/Actions/Grid/v3/CouponForbidden.php
index df8e597..3a10c81 100644
--- a/app/Admin/Actions/Grid/v3/CouponForbidden.php
+++ b/app/Admin/Actions/Grid/v3/CouponForbidden.php
@@ -17,11 +17,15 @@ class CouponForbidden extends RowAction
{
$id = $this->getKey();
$coupon = CouponModel::getInfo($id);
- if(!empty($coupon)){
+ if(empty($coupon)){
+ return $this->response()->success('找不到优惠券!');
+ }else if($coupon->status == 1){
$coupon->status = 3;
if($coupon->save()){
return $this->response()->success('禁用成功!','/coupon');
}
+ }else if($coupon->status == 3){
+ return $this->response()->error('优惠券已禁用!');
}
return $this->response()->success('禁用失败!');
}
diff --git a/app/Console/Commands/MigrateOrder.php b/app/Console/Commands/MigrateOrder.php
index b9d3a85..6b33410 100644
--- a/app/Console/Commands/MigrateOrder.php
+++ b/app/Console/Commands/MigrateOrder.php
@@ -19,7 +19,7 @@ class MigrateOrder extends Command
*
* @var string
*/
- protected $description = 'migrate order data';
+ protected $description = 'migrate 迁移订单数据';
/**
* Create a new command instance.
@@ -38,21 +38,39 @@ class MigrateOrder extends Command
*/
public function handle()
{
+
+ $oldOrderMain = 'ims_cjdc_order_main';
+ $oldOrder = 'ims_cjdc_order';
+ $oldOrderGood = 'ims_cjdc_order_goods';
+
+ $newOrderMain = 'lanzu_order_main';
+ $newOrder = 'lanzu_order';
+ $newOrderGood = 'lanzu_order_goods';
// main order
- $orderMain = DB::table('ims_cjdc_order_main')->get();
+ $orderMain = DB::table($oldOrderMain)->where('id',1)->get();
$bar = $this->output->createProgressBar(count($orderMain));
$bar->start();
+ $mainIds = '已存在的订单id:';
+ $childIds = '已存在的订单id:';
foreach ($orderMain as $k => $main) {
DB::beginTransaction();
try {
+ // 查询记录是否存在
+ $exist_main = DB::table($newOrderMain)->where('id',$main->id)->exists();
+ if($exist_main){
+ $mainIds .= ','.$main->id;
+ continue;
+ }
+
// 主订单
$dataMain = [
+ 'id' => $main->id,
'market_id' => $main->market_id ?? 0,
'order_num' => $main->order_num ?? '',
- 'global_order_id' => $main->global_order_id ?? time().mt_rand(100000,999999),
+ 'global_order_id' => $main->global_order_id ? $main->global_order_id : time().mt_rand(100000,999999),
'user_id' => $main->user_id ?? 0,
'pay_type' => $main->pay_type ?? 0,
'type' => $main->type ?? 0,
@@ -68,7 +86,7 @@ class MigrateOrder extends Command
'receive_time' => $main->jd_time ? strtotime($main->jd_time) : 0,
'delivery_time' => 0,
'complete_time' => $main->complete_time ? strtotime($main->complete_time) : 0,
- 'cancel_time' => $main->complete_time ? strtotime($main->complete_time) : 0,
+ 'cancel_time' => $main->cancel_time ? strtotime($main->cancel_time) : 0,
'refund_time' => $main->refund_time ?? 0,
'tel' => $main->tel ?? '',
'address' => $main->address ?? '',
@@ -89,17 +107,24 @@ class MigrateOrder extends Command
'created_at' => $main->time_add ?? 0,
'updated_at' => time(),
];
- $newMainId = DB::table('lanzu_order_main')->insertGetId($dataMain);
+ $newMainId = DB::table($newOrderMain)->insertGetId($dataMain);
// 子订单
- $orderChildren = DB::table('ims_cjdc_order')->where(['order_main_id' => $main->id])->get();
+ $orderChildren = DB::table($oldOrder)->where(['order_main_id' => $main->id])->get();
foreach ($orderChildren as $kChild => $child) {
+ // 查询记录是否存在
+ $exist_main = DB::table($newOrder)->where('id',$child->id)->exists();
+ if($exist_main){
+ $childIds .= ','.$child->id;
+ DB::rollBack();
+ continue;
+ }
// 子订单
$dataChild = [
+ 'id' => $child->id,
'order_main_id' => $dataMain['global_order_id'] ?? 0,
'user_id' => $child->user_id ?? 0,
'store_id' => $child->store_id ?? 0,
- 'status' => 1,
'refund_time' => 0,
'order_num' => $child->order_num ?? '',
'money' => $child->money ?? 0,
@@ -110,33 +135,43 @@ class MigrateOrder extends Command
'created_at' => $child->time_add ? strtotime($child->time_add) : 0,
'updated_at' => time(),
];
- $newChildId = DB::table('lanzu_order')->insertGetId($dataChild);
-
+ if($child->state == 9){
+ $dataChild['status'] = 3;
+ }else if($child->state == 8){
+ $dataChild['status'] = 2;
+ }else{
+ $dataChild['status'] = 1;
+ }
+
+ $newChildId = DB::table($newOrder)->insertGetId($dataChild);
+
// 订单商品
- $orderGoods = DB::table('ims_cjdc_order_goods')->where(['order_id' => $child->id])->get();
- $dataGoods = [];
- foreach ($orderGoods as $kGoods => $goods) {
- // 订单商品
- $dataGoods[] = [
- 'order_id' => $newChildId ?? 0,
- 'goods_id' => $goods->good_id ?? 0,
- 'number' => $goods->number ?? 0,
- 'status' => 1,
- 'price' => $goods->money ?? 0,
- 'original_price' => $goods->money2 ?? 0,
- 'vip_price' => $goods->vip_money ?? 0,
- 'name' => $goods->name ?? '',
- 'goods_unit' => $goods->good_unit ?? '',
- 'cover_img' => $goods->img ?? '',
- 'spec' => json_encode([]),
- 'refund_time' => 0,
- 'created_at' => time(),
- 'updated_at' => time(),
- 'refuse_refund_note' => '',
- 'note' => '',
- ];
+ $orderGoods = DB::table($oldOrderGood)->where(['order_id' => $child->id])->get();
+ if(count($orderGoods) > 0){
+ $dataGoods = [];
+ foreach ($orderGoods as $kGoods => $goods) {
+ // 订单商品
+ $dataGoods[] = [
+ 'order_id' => $newChildId ?? 0,
+ 'goods_id' => $goods->good_id ?? 0,
+ 'number' => $goods->number ?? 0,
+ 'status' => $dataChild['status'],
+ 'price' => $goods->money ?? 0,
+ 'original_price' => $goods->money2 ?? 0,
+ 'vip_price' => $goods->vip_money ?? 0,
+ 'name' => $goods->name ?? '',
+ 'goods_unit' => $goods->good_unit ?? '',
+ 'cover_img' => $goods->img ?? '',
+ 'spec' => json_encode([]),
+ 'refund_time' => 0,
+ 'created_at' => time(),
+ 'updated_at' => time(),
+ 'refuse_refund_note' => '',
+ 'note' => '',
+ ];
+ }
+ DB::table($newOrderGood)->insert($dataGoods);
}
- DB::table('lanzu_order_goods')->insert($dataGoods);
}
$bar->advance();
DB::commit();
@@ -145,7 +180,8 @@ class MigrateOrder extends Command
DB::rollBack();
}
}
-
+ var_dump($mainIds);
+ var_dump($childIds);
$bar->finish();
return 0;
}
diff --git a/app/Console/Commands/MigrateOrderStatistics.php b/app/Console/Commands/MigrateOrderStatistics.php
index 88c735b..0f61774 100644
--- a/app/Console/Commands/MigrateOrderStatistics.php
+++ b/app/Console/Commands/MigrateOrderStatistics.php
@@ -57,11 +57,10 @@ class MigrateOrderStatistics extends Command
$newData = [];
foreach ($oldData as $key => $value) {
$newData[] = [
- 'id' => $value->id,
'money' => $value->money ?? 0,
'user_id' => $value->user_id ?? 0,
'store_id' => $value->store_id ?? 0,
- 'market_id' => $value->market_id ?? 0 ,
+ 'market_id' => $value->market_id ?? 0,
'order_id' => $value->order_id ?? 0,
'created_at' => $value->createtime ?? 0,
diff --git a/app/Console/Commands/MigrateStore.php b/app/Console/Commands/MigrateStore.php
new file mode 100644
index 0000000..b251552
--- /dev/null
+++ b/app/Console/Commands/MigrateStore.php
@@ -0,0 +1,144 @@
+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;
+ }
+}
diff --git a/app/Console/Commands/MigrateStoreBalance.php b/app/Console/Commands/MigrateStoreBalance.php
index 0d3464c..b29f4e3 100644
--- a/app/Console/Commands/MigrateStoreBalance.php
+++ b/app/Console/Commands/MigrateStoreBalance.php
@@ -32,72 +32,157 @@ class MigrateStoreBalance extends Command
parent::__construct();
}
- /**
- * Execute the console command.
- *
- * @return int
- */
- public function handle()
+ public function getBalanceById($id)
{
- $oldAccountTableName = 'ims_cjdc_store_account';
+ $oldStoreTableName = 'ims_cjdc_store';
+ $oldStoreSetTableName = 'ims_cjdc_storeset';
+ $oldStoreTypeTableName = 'ims_cjdc_storetype';
+ $oldOrderTableName = 'ims_cjdc_order';
+ $oldWithdrawalTableName = 'ims_cjdc_withdrawal';
- $newBalanceTableName = 'lanzu_user_balance';
+ // 查询店铺
+ $stores = DB::table($oldStoreTableName)->select('id','md_type','ps_poundage','award_money')->where('id',$id)->get();
- // 判断表是否存在
- if(!Schema::hasTable($oldAccountTableName)){
- var_dump('旧表不存在');
- return 0;
- }
- if(!Schema::hasTable($newBalanceTableName)){
- var_dump('新表不存在');
- return 0;
+ if(count($stores) <= 0){
+ var_dump('店铺不存在');
+ return ;
}
- // 流水算法
- $newData = $this->countStore($oldAccountTableName);
- // 订单算法
- // $newData = $this->countOrder();
+ //店铺设置
+ $storeSets = DB::table($oldStoreSetTableName)
+ ->select('id','store_id','is_poundage','poundage','dn_poundage','dm_poundage','yd_poundage')
+ ->where('store_id',$id)->first();
- // var_dump($newData);
- // var_dump(count($newData));
- // return 0;
+ // 所有分类
+ $storeTypes = DB::table($oldStoreTypeTableName)->get()->toArray();
+ $storeTypeArr = array_column($storeTypes,null,'id');
- $bar = $this->output->createProgressBar(count($newData));
- $bar->start();
- $startTime = time();
- $error = [];
+ foreach($stores as $key => $value){
+ $storeId = $value->id;
- foreach($newData as $store_id => $money){
- $exist = DB::table($newBalanceTableName)->where('source_id',$store_id)->where('user_type',5)->exists();
- if($exist){
- $error[] = ['store_id'=>$store_id,'money'=>$money,'msg'=>'已存在'];
- // $saveData = [
- // 'balance' => number_format($money,2,'.',''),
- // 'updated_at' => time()
- // ];
- // $res = DB::table($newBalanceTableName)->where('source_id',$store_id)->where('user_type',5)->increment('balance',$saveData['balance']);
- // if(!$res){
- // $error[] = ['store_id'=>$store_id,'money'=>$money];
- // }
+ // 获取商家手续费 % 如果商家设置有自己的手续费则用商家的
+ if(!empty($storeSets) && $storeSets->is_poundage == 1){
+ $poundage = $storeSets;
}else{
- $saveData = [
- 'source_id' => $store_id,
- 'user_type' => 5,
- 'balance' => number_format($money,2,'.',''),
- 'updated_at' => time()
- ];
- $res = DB::table($newBalanceTableName)->insert($saveData);
- if(!$res){
- $error[] = ['store_id'=>$store_id,'money'=>$money];
- }
+ $poundage = $storeTypeArr[$value->md_type];
}
- $bar->advance();
+
+ // 商家订单金额
+ // type '1.外卖2.店内3.预定4.当面付',
+ // pay_type '1.微信支付2.余额支付3.积分支付4.货到付款',
+ // state '1.待付款2.待结单3.等待送达4.完成5.已评价6.取消7.拒绝8.退款中9.已退款10.退款拒绝',
+
+ // 外卖
+ $wmOrder = DB::table($oldOrderTableName)
+ ->select(DB::raw('sum(money) as total_money'),DB::raw('sum(ps_money) as ps_money'),DB::raw('sum(yhq_money2) as hb_money'))
+ ->where('store_id',$storeId)
+ ->where('type',1)
+ ->whereIn('state',[4,5,10])
+ ->whereIn('pay_type',[1,2])
+ ->first();
+
+ // 店内
+ $dnOrder = DB::table($oldOrderTableName)
+ ->select(DB::raw('sum(money) as total_money'),DB::raw('sum(yhq_money2) as hb_money'))
+ ->where('store_id',$storeId)
+ ->where('type',2)
+ ->where('dn_state',2)
+ ->whereIn('pay_type',[1,2])
+ ->first();
+ // 当面
+ $dmOrder = DB::table($oldOrderTableName)
+ ->select(DB::raw('sum(money) as total_money'))
+ ->where('store_id',$storeId)
+ ->where('type',4)
+ ->where('dm_state',2)
+ ->whereIn('pay_type',[1,2])
+ ->first();
+ // 预约
+ $yyOrder = DB::table($oldOrderTableName)
+ ->select(DB::raw('sum(money) as total_money'))
+ ->where('store_id',$storeId)
+ ->where('type',3)
+ ->where('yy_state',3)
+ ->whereIn('pay_type',[1,2])
+ ->first();
+ // 提现
+ $txTotal = DB::table($oldWithdrawalTableName)
+ ->select(DB::raw('sum(tx_cost) as total'))
+ ->where('store_id',$storeId)
+ ->whereIn('state',[1,2])
+ ->first();
+
+ // 商家奖励
+ $awardTotal = empty($value->award_money) ? 0 : $value->award_money;
+
+ // 商户配送手续费
+ $psMoney = number_format(floatval($wmOrder->ps_money)*floatval($value->ps_poundage)/100,2,'.','');
+
+ // 不计算拼团和抢购的订单,目前没有这样的订单,在另外的订单表
+
+ // 计算 金额 = 奖励 + 订单(外卖+店内+当面+预约) - 手续费 - 提现 - 配送费
+ $balance = $awardTotal
+ + ($wmOrder->total_money + $wmOrder->hb_money + $dnOrder->total_money + $dnOrder->hb_money + $dmOrder->total_money + $yyOrder->total_money )
+ - ((
+ ($wmOrder->total_money + $wmOrder->ps_money + $wmOrder->hb_money) * floatval($poundage->poundage)
+ + ($dnOrder->total_money + $dnOrder->hb_money ) * floatval($poundage->dn_poundage)
+ + $dmOrder->total_money * floatval($poundage->dm_poundage)
+ + $yyOrder->total_money * floatval($poundage->yd_poundage)
+ )/100)
+ - $txTotal->total
+ - $psMoney;
+
+ // $newData[$storeId] = number_format($balance,2,'.','');
+
}
- $bar->finish();
- var_dump([time()-$startTime]);
- var_dump($error);
- return 0;
+ return number_format($balance,2,'.','');
+ }
+
+ /**
+ * Execute the console command.
+ * 单个店铺处理
+ * @return int
+ */
+ public function handle()
+ {
+ $oldStoreTableName = 'ims_cjdc_store';
+ $newBalanceTableName = 'lanzu_user_balance';
+
+ $store_id = 2 ; // 店铺id
+ $balance = $this->getBalanceById($store_id);
+
+ // var_dump(number_format($balance,2,'.',''));
+ // return ;
+ $res = 1;
+ $userId = 0;// 店铺的提现用户id
+ $storeInfo = DB::table($oldStoreTableName)->select('user_id')->find($store_id);
+ if(empty($storeInfo) || empty($storeInfo->user_id)){
+ $res = ['store_id'=>$store_id,'balance'=>$balance,'msg'=>'店铺的用户不存在'];
+ var_dump($res);
+ return ;
+ }
+ $userId = $storeInfo->user_id;
+
+ $exist = DB::table($newBalanceTableName)->where('source_id',$userId)->where('user_type',5)->exists();
+ if($exist){
+ $res = ['store_id'=>$store_id,'balance'=>$balance,'msg'=>'已存在'];
+ }else{
+ $saveData = [
+ 'source_id' => $userId,
+ 'user_type' => 5,
+ 'balance' => $balance,
+ 'created_at' => time(),
+ 'updated_at' => time()
+ ];
+ // var_dump($saveData);
+ $res = DB::table($newBalanceTableName)->insert($saveData);
+ if(!$res){
+ $res = ['store_id'=>$store_id,'user_id'=>$userId,'balance'=>$balance,'msg'=>'添加失败'];
+ }
+ };
+ var_dump($res);
+ return ;
}
/**
@@ -135,7 +220,7 @@ class MigrateStoreBalance extends Command
$newData = [];
// 查询所有店铺
- $stores = DB::table($oldStoreTableName)->select('id','md_type','ps_poundage','award_money')->get();
+ $stores = DB::table($oldStoreTableName)->select('id','md_type','ps_poundage','award_money')->where('id',)->get();
//店铺设置
$storeSets = DB::table($oldStoreSetTableName)->select('id','store_id','is_poundage','poundage','dn_poundage','dm_poundage','yd_poundage')->get()->toArray();
@@ -225,4 +310,73 @@ class MigrateStoreBalance extends Command
return $newData;
}
+
+ /**
+ * 旧的处理方式
+ */
+ public function old()
+ {
+ $oldAccountTableName = 'ims_cjdc_store_account';
+ $newBalanceTableName = 'lanzu_user_balance';
+
+ // 判断表是否存在
+ if(!Schema::hasTable($oldAccountTableName)){
+ var_dump('旧表不存在');
+ return 0;
+ }
+ if(!Schema::hasTable($newBalanceTableName)){
+ var_dump('新表不存在');
+ return 0;
+ }
+
+ // 流水算法
+ $newData = $this->countStore($oldAccountTableName);
+ // 订单算法
+ // $newData = $this->countOrder();
+
+ var_dump($newData);
+ var_dump(count($newData));
+ return 0;
+ $storeList = DB::table($newBalanceTableName)->pluck('user_id','id');
+ $bar = $this->output->createProgressBar(count($newData));
+ $bar->start();
+ $startTime = time();
+ $error = [];
+
+ foreach($newData as $store_id => $money){
+ $userId = 0;
+ if(!isset($storeList[$store_id])){
+ $error[] = ['store_id'=>$store_id,'money'=>$money,'msg'=>'店铺的用户不存在'];
+ }
+ $exist = DB::table($newBalanceTableName)->where('source_id',$userId)->where('user_type',5)->exists();
+ if($exist){
+ $error[] = ['store_id'=>$store_id,'money'=>$money,'msg'=>'已存在'];
+ // $saveData = [
+ // 'balance' => number_format($money,2,'.',''),
+ // 'updated_at' => time()
+ // ];
+ // $res = DB::table($newBalanceTableName)->where('source_id',$store_id)->where('user_type',5)->increment('balance',$saveData['balance']);
+ // if(!$res){
+ // $error[] = ['store_id'=>$store_id,'money'=>$money];
+ // }
+ }else{
+ $saveData = [
+ 'source_id' => $userId,
+ 'user_type' => 5,
+ 'balance' => number_format($money,2,'.',''),
+ 'updated_at' => time()
+ ];
+ // $res = DB::table($newBalanceTableName)->insert($saveData);
+ // if(!$res){
+ // $error[] = ['store_id'=>$store_id,'money'=>$money];
+ // }
+ }
+ $bar->advance();
+ }
+
+ $bar->finish();
+ var_dump([time()-$startTime]);
+ var_dump($error);
+ return 0;
+ }
}
diff --git a/app/Console/Commands/MigrateStoreFinancial.php b/app/Console/Commands/MigrateStoreFinancial.php
index 53791f4..05dd7b1 100644
--- a/app/Console/Commands/MigrateStoreFinancial.php
+++ b/app/Console/Commands/MigrateStoreFinancial.php
@@ -59,12 +59,12 @@ class MigrateStoreFinancial extends Command
$startTime = time();
$error = [];
foreach ($oldData as $key => $value){
- $type = $value->type;
- $note = $value->note;
- $storeId = $value->store_id;
- $userId = $value->user_id;
+ $type = $value->type ?? 0;
+ $note = $value->note ?? '';
+ $storeId = $value->store_id ?? 0;
+ $userId = $value->user_id ?? 0;
if(empty($storeId) || empty($type) || empty($note)){
- $error[] = ['id'=>$value->id];
+ $error[] = ['id'=>$value->id,'msg'=>'数据错误或者为空'];
continue;
}
if(empty($userId)){
@@ -117,7 +117,10 @@ class MigrateStoreFinancial extends Command
->where('money_type',$moneyType)
->exists();
- if(!$exist){
+ if($exist){
+ $error[] = ['id'=>$value->id,'msg'=>'总帐已存在'];
+ continue;
+ }else{
if(!DB::table($newTableName)->insert($newData)){
$error[] = ['id'=>$value->id,'msg'=>'总账添加失败'];
break;
@@ -135,7 +138,10 @@ class MigrateStoreFinancial extends Command
->where('money',$money)
->where('money_type',$moneyType)
->exists();
- if(!$existSub){
+ if($existSub){
+ $error[] = ['id'=>$value->id,'msg'=>'已存在'];
+ continue;
+ }else{
if(!DB::table($newSubTableName)->insert($newData)){
$error[] = ['id'=>$value->id,'msg'=>'用户账添加失败'];
break;
@@ -146,7 +152,7 @@ class MigrateStoreFinancial extends Command
}
$bar->finish();
var_dump([time()-$startTime]);
- var_dump($error);
+ var_dump(count($error));
return 0;
}
diff --git a/app/Console/Commands/MigrateStoreWithdrawal.php b/app/Console/Commands/MigrateStoreWithdrawal.php
index 2782dab..0287ddc 100644
--- a/app/Console/Commands/MigrateStoreWithdrawal.php
+++ b/app/Console/Commands/MigrateStoreWithdrawal.php
@@ -62,6 +62,7 @@ class MigrateStoreWithdrawal extends Command
// 判断是否存在
$exist = DB::table($newTableName)->where('id',$withdrawalId)->exists();
if($exist){
+ $error[] = ['id'=>$withdrawalId,'msg'=>'已存在'];
continue;
}
$newData =[
diff --git a/app/Console/Commands/MigrateUser.php b/app/Console/Commands/MigrateUser.php
index 6e0ad7e..d207e48 100644
--- a/app/Console/Commands/MigrateUser.php
+++ b/app/Console/Commands/MigrateUser.php
@@ -55,35 +55,36 @@ class MigrateUser extends Command
$bar = $this->output->createProgressBar(count($oldData));
$bar->start();
$startTime = time();
- $error = [];
+ $error = '用户已存在:';
foreach ($oldData as $key => $value){
- $userId = $value->id;
+ $userId = $value->id ?? 0;
// 判断是否存在
$exist = DB::table($newTableName)->where('id',$userId)->exists();
if($exist){
+ $error .= ','.$value->id;
continue;
}
$newData =[
'id'=>$userId,
- 'nick_name'=>$value->name,
+ 'nick_name'=>$value->name ?? '',
- 'avatar'=>$value->img,
- 'openid'=>$value->openid,
+ 'avatar'=>$value->img ?? '',
+ 'openid'=>$value->openid ?? '',
- 'total_score'=>$value->total_score,
- 'wallet'=>$value->wallet,
+ 'total_score'=>$value->total_score ?? 0,
+ 'wallet'=>$value->wallet ?? 0,
- 'real_name'=>$value->user_name,
- 'tel'=>$value->user_tel,
+ 'real_name'=>$value->user_name ?? '',
+ 'tel'=>$value->user_tel ?? '',
'unionid'=>$value->unionid,
- 'created_at' => strtotime($value->join_time),
- 'updated_at' => $value->updated_at,
+ 'created_at' => $value->join_time ?? time(),
+ 'updated_at' => time(),
];
$res = DB::table($newTableName)->insert($newData);
if(!$res){
- $error[] = ['id'=>$userId];
+ $error[] = ['id'=>$userId,'msg'=>'添加失败'];
break;
}
$bar->advance();
diff --git a/app/Console/Commands/MigrateUserAddr.php b/app/Console/Commands/MigrateUserAddr.php
index d724190..a50b2d7 100644
--- a/app/Console/Commands/MigrateUserAddr.php
+++ b/app/Console/Commands/MigrateUserAddr.php
@@ -60,7 +60,7 @@ class MigrateUserAddr extends Command
foreach ($oldData as $key => $value) {
$addressArr = explode('|',$value->address);
- $address = $addressArr[0];
+ $address = isset($addressArr[0])?$addressArr[0]:'';
$doorplate = isset($addressArr[1])?$addressArr[1]:'';
$newData[] = [
diff --git a/app/Console/Commands/MigrateUserCollection.php b/app/Console/Commands/MigrateUserCollection.php
index 8b3d6bb..839c468 100644
--- a/app/Console/Commands/MigrateUserCollection.php
+++ b/app/Console/Commands/MigrateUserCollection.php
@@ -57,23 +57,24 @@ class MigrateUserCollection extends Command
$bar = $this->output->createProgressBar(count($oldData));
$bar->start();
$startTime = time();
- $error = [];
+ $error = '已存在:';
foreach ($oldData as $key => $value){
- $collectionId = $value->id;
+ $collectionId = $value->id ?? 0;
// 判断是否存在
$exist = DB::table($newTableName)->where('id',$collectionId)->exists();
if($exist){
+ $error .= ','.$collectionId;
continue;
}
// 店铺存在
if(isset($oldStoreData[$value->store_id])){
$newData =[
'id'=>$collectionId,
- 'store_id'=>$value->store_id,
- 'user_id'=>$value->user_id,
+ 'store_id'=>$value->store_id ?? 0,
+ 'user_id'=>$value->user_id ?? 0,
'market_id'=> isset($oldStoreData[$value->store_id])?$oldStoreData[$value->store_id]:0,
- 'created_at' => $value->time,
+ 'created_at' => $value->time ?? time(),
'updated_at' => time(),
];
diff --git a/app/Console/Commands/SetStoreBalance.php b/app/Console/Commands/SetStoreBalance.php
index 3902d76..e209379 100644
--- a/app/Console/Commands/SetStoreBalance.php
+++ b/app/Console/Commands/SetStoreBalance.php
@@ -53,13 +53,13 @@ class SetStoreBalance extends Command
foreach ($oldData as $key => $value){
// 查询店铺是否存在balance
$exist = DB::table($newTableName)
- ->where('source_id',$value->id)
+ ->where('source_id',$value->user_id)
->where('user_type',5)
->first();
if(empty($exist)){
$newData[] = [
- 'source_id' => $value->id,
+ 'source_id' => $value->user_id,
'user_type' => 5,
'balance' => 0,
'created_at' => time(),
@@ -68,6 +68,7 @@ class SetStoreBalance extends Command
}else{
$data[] = [
'store_id' => $value->id,
+ 'user_id' => $value->user_id,
'balance_id' => $exist->id
];
}
diff --git a/app/Console/Commands/SetStoreUsers.php b/app/Console/Commands/SetStoreUsers.php
index 711e1d2..512438a 100644
--- a/app/Console/Commands/SetStoreUsers.php
+++ b/app/Console/Commands/SetStoreUsers.php
@@ -41,31 +41,54 @@ class SetStoreUsers extends Command
*/
public function handle()
{
- // 如果表不存在则创建
- // if(!Schema::hasTable('lanzu_store_users')){
- // Schema::create('lanzu_store_users',function (Blueprint $table){
- // $table->id();
- // });
- // }
- $account = DB::table('ims_cjdc_account')->get();
+ $oldAccount = 'ims_cjdc_account';
+ $oldTable = 'ims_users';
+
+ $newTable = 'lanzu_store_users';
+
+ $oldData = DB::table($oldTable)->get();
+
+ $account = DB::table($oldAccount)->select('uid','role','storeid')->get()->toArray();
+ $accountArr = array_column($account,null,'uid');
+
$bar = $this->output->createProgressBar(count($account));
$bar->start();
+ $accountStr = '已经存在的账号id:';
+ $newData = [];
+ foreach ($oldData as $k => $v){
+
+ $exist = DB::table($newTable)->where('id',$v->uid)->exists();
+ if($exist){
+ $accountStr .= ','.$v->uid;
+ }else{
+ $newData[] =[
+ 'id' => $v->uid,
+ 'openid' => $v->openid ?? '',
+ 'username' => $v->username ?? '',
+ 'password' => $v->password ?? '',
+ 'salt' => $v->salt ?? '',
+ 'register_type' => 0,
+ 'status' => $v->status ?? 0,
+ 'join_ip' => $v->joinip ?? '',
+
+ 'last_visit_time' => $v->lastvisit ?? 0,
+ 'last_ip' => $v->lastip ?? '',
+ 'token' => $v->token ?? '',
+ 'token_expire' => $v->token_expire ?? '',
+ 'remark' => $v->remark ?? '',
+
+ 'created_at' => $v->joindate ?? 0,
+ 'updated_at' => time(),
- foreach ($account as $ka => $va){
- $data = [];
- $storeUsers = DB::table('lanzu_store_users')->find($va->uid);
- if(!empty($storeUsers)){
- $data =[
- 'user_category'=>$va->role,
- 'store_id'=>$va->storeid
+ 'user_category'=> isset($accountArr[$v->uid]) ? $accountArr[$v->uid]->role ?? 0 : 0,
+ 'store_id'=> isset($accountArr[$v->uid]) ? $accountArr[$v->uid]->storeid ?? 0 : 0,
];
- DB::table('lanzu_store_users')->where('id',$va->uid)->update($data);
}
- $bar->advance();
}
+ DB::table($newTable)->insert($newData);
$bar->finish();
-
+ var_dump($accountStr);
return 0;
}
}
From 98fa56a444237fd8db31b3b24a4dddfaea6374d0 Mon Sep 17 00:00:00 2001
From: liangyuyan <1103300295@qq.com>
Date: Fri, 18 Sep 2020 20:55:10 +0800
Subject: [PATCH 3/4] =?UTF-8?q?banners-=E6=B7=BB=E5=8A=A0=E8=89=B2?=
=?UTF-8?q?=E5=80=BC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Controllers/v3/BannersController.php | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/app/Admin/Controllers/v3/BannersController.php b/app/Admin/Controllers/v3/BannersController.php
index 92576a9..62867cd 100644
--- a/app/Admin/Controllers/v3/BannersController.php
+++ b/app/Admin/Controllers/v3/BannersController.php
@@ -20,13 +20,22 @@ class BannersController extends AdminController
protected function grid()
{
return Grid::make(new Banners(), function (Grid $grid) {
+ $marketList = MarketModel::getMarket();
$grid->column('id')->sortable();
- $grid->column('market_id')->display(function($markerId){
- $market = MarketModel::getMarketInfo($markerId,'name');
- return empty($market) ? '' : $market['name'];
+ $grid->column('market_ids','适用市场')->display(function($marketIds) use($marketList){
+ $item = '';
+ if(!empty($marketIds)){
+ foreach($marketIds as $value){
+ $item .= isset($marketList[$value])?$marketList[$value].'' : '';
+ }
+ }
+ return $item;
});
$grid->column('title');
$grid->column('cover_url')->image('',100);
+ $grid->column('bg_color')->display(function($bgColor){
+ return "";
+ });
$grid->column('cover_type_text');
$grid->column('path');
$grid->column('path_type_text');
@@ -63,6 +72,7 @@ class BannersController extends AdminController
$show->width(6)->field('sub_title');
$show->width(6)->field('cover_type_text');
$show->width(6)->field('cover')->image();
+ $show->width(6)->field('bg_color')->color();
$show->width(6)->field('type_text');
});
$show->row(function (Show\Row $show) {
@@ -89,7 +99,7 @@ class BannersController extends AdminController
$form->hidden('id');
// 市场
$marketList = MarketModel::getMarket();
- $form->select('market_id')->options($marketList)->default(0);
+ $form->hidden('market_id')->options($marketList)->default(0);
// 多个市场
$form->multipleSelect('market_ids')->options($marketList);
$form->select('type')->options(BannersModel::$_TYPE)->required();
@@ -105,6 +115,7 @@ class BannersController extends AdminController
});
});
$form->column(6, function (Form $form) {
+ $form->color('bg_color')->required()->default('#FF7B21');
$form->image('cover')->autoUpload()->required()->uniqueName();
$form->select('cover_type')->options(BannersModel::$_COVER_TYPE)->required();
$form->text('path')->default('');
From 70a3513b7c4c38828e9ebd7b1da3a7b202437153 Mon Sep 17 00:00:00 2001
From: liangyuyan <1103300295@qq.com>
Date: Fri, 18 Sep 2020 21:05:20 +0800
Subject: [PATCH 4/4] =?UTF-8?q?banners-=E9=A2=9C=E8=89=B2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Admin/Controllers/v3/BannersController.php | 2 +-
resources/lang/zh-CN/banners.php | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/app/Admin/Controllers/v3/BannersController.php b/app/Admin/Controllers/v3/BannersController.php
index 62867cd..c1a4d83 100644
--- a/app/Admin/Controllers/v3/BannersController.php
+++ b/app/Admin/Controllers/v3/BannersController.php
@@ -34,7 +34,7 @@ class BannersController extends AdminController
$grid->column('title');
$grid->column('cover_url')->image('',100);
$grid->column('bg_color')->display(function($bgColor){
- return "";
+ return "";
});
$grid->column('cover_type_text');
$grid->column('path');
diff --git a/resources/lang/zh-CN/banners.php b/resources/lang/zh-CN/banners.php
index 32f3352..ed20ad3 100644
--- a/resources/lang/zh-CN/banners.php
+++ b/resources/lang/zh-CN/banners.php
@@ -21,6 +21,7 @@ return [
'status_text' => '状态',
'type' => '位置',
'type_text' => '位置',
+ 'bg_color' => '色值',
],
'options' => [
],