From 0918976250e488f94fb0e38a32bf4a878ef0a257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Fri, 7 Jan 2022 21:54:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=86=E9=94=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/AfterSaleService.php | 75 +++++++++++-------- .../DistributionPreIncomeJobService.php | 28 +++---- app/Services/PayService.php | 3 - 3 files changed, 57 insertions(+), 49 deletions(-) diff --git a/app/Services/AfterSaleService.php b/app/Services/AfterSaleService.php index 74900aa4..87a4dee5 100644 --- a/app/Services/AfterSaleService.php +++ b/app/Services/AfterSaleService.php @@ -389,7 +389,7 @@ class AfterSaleService 'reason' => '售后退款', ]); } - } elseif (in_array($afterSale->type, [AfterSale::TYPE_CHANGE])) {//换货流程 + } elseif ($afterSale->isChange()) {//换货流程 $qty = $afterSale->num; if ($qty > $afterSaleProduct->quantity) { @@ -397,11 +397,49 @@ class AfterSaleService } $salesValue = bcmul($afterSaleProduct->sales_value, $qty, 2); + } - $vipDiscountAmount = 0; + $afterSale->update([ + 'sales_value' => $salesValue, + 'state' => AfterSale::STATE_FINISH, + 'remarks' => $remarks, + ]); + + $afterSale->logs()->create([ + 'name' => '财务审核', + 'desc' => $remarks, + ]); + + // 1.先扣除预收益(可能会将店铺降级为粉丝) + // 2.生成分销任务 + // 3.生成新订单 + + if (bccomp($afterSale->sales_value, '0', 2) === 1) { + $order->user->userInfo->incrPreGrowthValue(bcmul($afterSale->sales_value, '-1', 2)); + } + + // 非赠品售后单,且售后单类型是换货、退款、退款退货 + if (! $afterSaleProduct->isGift() + && in_array($afterSale->type, [ + AfterSale::TYPE_REFUND_AND_RETURN, + AfterSale::TYPE_REFUND, + AfterSale::TYPE_CHANGE, + ]) + ) { + DistributionPreIncomeJob::create([ + 'jobable_id' => $afterSale->id, + 'jobable_type' => $afterSale->getMorphClass(), + 'remarks' => $afterSale->isChange() ? '订单换货' : '订单退货', + ]); + } + + // 如果是换货单 + if ($afterSale->isChange()) { // 如果订单享受了会员折扣,则需计算会员折扣 + $vipDiscountAmount = 0; + if ($afterSaleProduct->vip_discount_amount > 0) { - $vipDiscountAmount = bcmul(($afterSaleProduct->sell_price-$afterSaleProduct->vip_price), $afterSale->num); + $vipDiscountAmount = bcmul(($afterSaleProduct->sell_price - $afterSaleProduct->vip_price), $qty); } //复制一个订单(存商品价格,支付价格为0;) @@ -414,7 +452,7 @@ class AfterSaleService $changeOrder->reduced_amount = 0; $changeOrder->shipping_fee = 0; $changeOrder->total_amount = 0; - $changeOrder->sales_value = $salesValue; + $changeOrder->sales_value = $afterSale->sales_value; // 收货地址 $changeOrder->consignee_name = $order->consignee_name; @@ -454,35 +492,6 @@ class AfterSaleService 'shipping_state' => Order::SHIPPING_STATE_PROCESSING, ]); } - $afterSale->logs()->create([ - 'name' => '财务审核', - 'desc' => $remarks, - ]); - - $afterSale->update([ - 'sales_value' => $salesValue, - 'state' => AfterSale::STATE_FINISH, - 'remarks' => $remarks, - ]); - - // 非赠品售后单,且售后单类型是换货、退款、退款退货 - if (! $afterSaleProduct->isGift() - && in_array($afterSale->type, [ - AfterSale::TYPE_REFUND_AND_RETURN, - AfterSale::TYPE_REFUND, - AfterSale::TYPE_CHANGE, - ]) - ) { - DistributionPreIncomeJob::create([ - 'jobable_id' => $afterSale->id, - 'jobable_type' => $afterSale->getMorphClass(), - 'remarks' => $afterSale->isChange() ? '订单换货' : '订单退货', - ]); - } - - if (bccomp($afterSale->sales_value, '0', 2) === 1) { - $order->user->userInfo->incrPreGrowthValue(bcmul($afterSale->sales_value, '-1', 2)); - } } else { throw new BizException('该售后订单状态异常'); } diff --git a/app/Services/DistributionPreIncomeJobService.php b/app/Services/DistributionPreIncomeJobService.php index d16ad816..cf2cc16d 100644 --- a/app/Services/DistributionPreIncomeJobService.php +++ b/app/Services/DistributionPreIncomeJobService.php @@ -230,26 +230,26 @@ class DistributionPreIncomeJobService // 下单用户信息 $user = $order->user->userInfo; // 总销售值 - $totalSalesValue = 0; + $totalSalesValue = $order->sales_value; // 总差价 $totalDiffPrice = 0; - foreach ($order->products as $product) { - // 赠品不算成长值和差价 - if ($product->isGift()) { - continue; - } + if ($order->vip_discount_count === 0) { + foreach ($order->products as $product) { + // 赠品不算成长值和差价 + if ($product->isGift()) { + continue; + } - // 如果订单商品有会员价,并且没有会员折扣时,才计算总差价 - if (! is_null($product->vip_price) && $product->vip_discount_amount === 0) { - $diffPrice = $product->sell_price - $product->vip_price; + // 如果订单商品有会员价,并且没有会员折扣时,才计算总差价 + if (! is_null($product->vip_price) && $product->vip_discount_amount === 0) { + $diffPrice = $product->sell_price - $product->vip_price; - if ($diffPrice > 0) { - $totalDiffPrice = bcadd($totalDiffPrice, bcmul(bcdiv($diffPrice, '100'), $product->quantity)); + if ($diffPrice > 0) { + $totalDiffPrice = bcadd($totalDiffPrice, bcmul(bcdiv($diffPrice, '100'), $product->quantity)); + } } } - - $totalSalesValue = bcadd($totalSalesValue, bcmul($product->sales_value, $product->quantity)); } // 分销配置 @@ -423,6 +423,8 @@ class DistributionPreIncomeJobService $lastAgent = $agent; } + + $user->incrPreGrowthValue($totalSalesValue, false); } DistributionPreIncomeLog::insert($preIncomeLogs); diff --git a/app/Services/PayService.php b/app/Services/PayService.php index 030d93c9..8de076aa 100644 --- a/app/Services/PayService.php +++ b/app/Services/PayService.php @@ -89,9 +89,6 @@ class PayService 'status' => Order::STATUS_PAID, ]); - // 增加用户的预成长值 - $payable->user->userInfo->incrPreGrowthValue($payable->sales_value, false); - DistributionPreIncomeJob::create([ 'jobable_id' => $payable->id, 'jobable_type' => $payable->getMorphClass(),