6
0
Fork 0

优化分销

release
李静 2022-01-07 21:54:11 +08:00
parent b517325b5f
commit 0918976250
3 changed files with 57 additions and 49 deletions

View File

@ -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('该售后订单状态异常');
}

View File

@ -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);

View File

@ -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(),