From 454e5d39d3a8973129e9b3fb6553b63523ce1973 Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Sun, 24 Apr 2022 10:22:10 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=89=B9=E9=9B=B6=E7=AB=AF?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E4=B8=8B=E5=8D=95=E4=BB=B7=E6=A0=BC=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Dealer/OrderController.php | 6 +- app/Services/Dealer/OrderService.php | 89 ++++++++++++------- 2 files changed, 60 insertions(+), 35 deletions(-) diff --git a/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php b/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php index a64f7ba9..72544a8f 100644 --- a/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php +++ b/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php @@ -182,9 +182,13 @@ class OrderController extends Controller ]); $product = DealerProduct::online()->findOrFail($input['product_id']); + $user = $request->user(); + + $totalAmount = $orderService->totalAmount($user, $product, $input['num']); return response()->json([ - 'total_amount'=> $orderService->totalAmount($request->user(), $product, $input['num']), + 'total_amount'=> $totalAmount, + 'to_lvl'=>$orderService->willBecome($user, $totalAmount), ]); } diff --git a/app/Services/Dealer/OrderService.php b/app/Services/Dealer/OrderService.php index 1dbf30ea..4a665c9f 100644 --- a/app/Services/Dealer/OrderService.php +++ b/app/Services/Dealer/OrderService.php @@ -67,6 +67,39 @@ class OrderService return bcmul($this->getSalePrice($user, $product, $allNumber ?? $number), $number, 2); } + /** + * 计算即将成为的身份 + * + * @param User $user + * @param [float] $totalAmount + * @return DealerLvl + */ + public function willBecome(User $user, $totalAmount): DealerLvl + { + $rules = [ + [ + 'amount' => app_settings('dealer.upgrade_amount_'.DealerLvl::Contracted->value), + 'lvl' => DealerLvl::Contracted, + ], + [ + 'amount' => app_settings('dealer.upgrade_amount_'.DealerLvl::Special->value), + 'lvl' => DealerLvl::Special, + ], + [ + 'amount' => app_settings('dealer.upgrade_amount_'.DealerLvl::Gold->value), + 'lvl' => DealerLvl::Gold, + ], + ]; + $lvl = $user->dealer->lvl; + //计算通过这个订单可能升级成为的身份 + foreach ($rules as $rule) { + if ($totalAmount >= $rule['amount'] && $lvl->value < $rule['lvl']->value) { + $lvl = $rule['lvl']; + } + } + return $lvl; + } + /** * 快捷创建订单(单个商品下单) * @@ -695,44 +728,32 @@ class OrderService private function getConsignor(User $user, $totalAmount, ?User $lastConsignor = null) { - $rules = [ - [ - 'amount' => app_settings('dealer.upgrade_amount_'.DealerLvl::Contracted->value), - 'lvl' => DealerLvl::Contracted, - ], - [ - 'amount' => app_settings('dealer.upgrade_amount_'.DealerLvl::Special->value), - 'lvl' => DealerLvl::Special, - ], - [ - 'amount' => app_settings('dealer.upgrade_amount_'.DealerLvl::Gold->value), - 'lvl' => DealerLvl::Gold, - ], - ]; - $lvl = $user->dealer->lvl; - //计算通过这个订单可能升级成为的身份 - foreach ($rules as $rule) { - if ($totalAmount >= $rule['amount'] && $lvl->value < $rule['lvl']->value) { - $lvl = $rule['lvl']; - } - } + // $rules = [ + // [ + // 'amount' => app_settings('dealer.upgrade_amount_'.DealerLvl::Contracted->value), + // 'lvl' => DealerLvl::Contracted, + // ], + // [ + // 'amount' => app_settings('dealer.upgrade_amount_'.DealerLvl::Special->value), + // 'lvl' => DealerLvl::Special, + // ], + // [ + // 'amount' => app_settings('dealer.upgrade_amount_'.DealerLvl::Gold->value), + // 'lvl' => DealerLvl::Gold, + // ], + // ]; + // $lvl = $user->dealer->lvl; + // //计算通过这个订单可能升级成为的身份 + // foreach ($rules as $rule) { + // if ($totalAmount >= $rule['amount'] && $lvl->value < $rule['lvl']->value) { + // $lvl = $rule['lvl']; + // } + // } + $lvl = $this->willBecome($user, $totalAmount); //如果是签约单,直接抛到公司后台发货 if ($lvl->value >= DealerLvl::Contracted->value) { return null; } - // //老逻辑; - // $query = UserInfo::with('dealer'); - // if ($lastConsignor) { - // $query->whereIn('user_id', $lastConsignor->userInfo->real_parent_ids);//上个发货人的上级 - // } else { - // $query->whereIn('user_id', $user->userInfo->real_parent_ids);//自己的上级 - // } - // $consignor = $query->whereHas('dealer', function ($q) use ($lvl) { - // return $q->where('is_sale', true)->where('lvl', '>', $lvl);//可销售的经销商,且身份大于自己的 - // })->orderBy('depth', 'desc')->first();//深度逆序第一个 - // if (!$consignor) { - // $consignor = $lastConsignor; - // } //新逻辑 $consignor = null; $_lastConsignor = $lastConsignor;