6
0
Fork 0
release
李静 2021-12-25 14:25:56 +08:00
parent 1ca958fce8
commit 155cd897a9
3 changed files with 89 additions and 75 deletions

View File

@ -7,6 +7,7 @@ use App\Exceptions\BizException;
use App\Helpers\Order as OrderHelper; use App\Helpers\Order as OrderHelper;
use App\Models\AfterSale; use App\Models\AfterSale;
use App\Models\AfterSaleLog; use App\Models\AfterSaleLog;
use App\Models\DistributionPreIncomeJob;
use App\Models\Order; use App\Models\Order;
use App\Models\OrderProduct; use App\Models\OrderProduct;
use App\Models\User; use App\Models\User;
@ -363,6 +364,7 @@ class AfterSaleService
OrderProduct::create([ OrderProduct::create([
'user_id' => $changeOrder->user_id, 'user_id' => $changeOrder->user_id,
'order_id' => $changeOrder->id, 'order_id' => $changeOrder->id,
'gift_for_sku_id' => $afterSale->orderProduct->gift_for_sku_id,
'spu_id' => $afterSale->orderProduct->spu_id, 'spu_id' => $afterSale->orderProduct->spu_id,
'sku_id' => $afterSale->orderProduct->sku_id, 'sku_id' => $afterSale->orderProduct->sku_id,
'category_id' => $afterSale->orderProduct->category_id, 'category_id' => $afterSale->orderProduct->category_id,
@ -372,6 +374,7 @@ class AfterSaleService
'weight' => $afterSale->orderProduct->weight, 'weight' => $afterSale->orderProduct->weight,
'sell_price' => $afterSale->orderProduct->sell_price, 'sell_price' => $afterSale->orderProduct->sell_price,
'vip_price' => $afterSale->orderProduct->vip_price, 'vip_price' => $afterSale->orderProduct->vip_price,
'sales_value' => $afterSale->orderProduct->sales_value,
'quantity' => $afterSale->num, 'quantity' => $afterSale->num,
'coupon_discount_amount'=> 0, 'coupon_discount_amount'=> 0,
'vip_discount_amount' => $afterSale->orderProduct->sell_price - $afterSale->orderProduct->vip_price, 'vip_discount_amount' => $afterSale->orderProduct->sell_price - $afterSale->orderProduct->vip_price,
@ -386,6 +389,18 @@ class AfterSaleService
]); ]);
} }
if (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() ? '订单换货' : '支付退货',
]);
}
AfterSaleLog::create([ AfterSaleLog::create([
'after_sale_id' => $afterSale->id, 'after_sale_id' => $afterSale->id,
'name' => '财务审核', 'name' => '财务审核',

View File

@ -245,12 +245,7 @@ class DistributionPreIncomeJobService
$preIncomeLogs = []; $preIncomeLogs = [];
/* // 推粉丝赚差价
|-----------------------------------------------
| 推粉丝赚差价
|-----------------------------------------------
*/
// 1. 总差价必须大于0 // 1. 总差价必须大于0
// 2. 下单用户必须有邀请人 // 2. 下单用户必须有邀请人
// 3. 下单用户的邀请人必须可以享受分红 // 3. 下单用户的邀请人必须可以享受分红
@ -261,7 +256,7 @@ class DistributionPreIncomeJobService
) { ) {
// 手续费率 // 手续费率
$feeRate = $config['price_diff_fee_rate'] ?? '0'; $feeRate = $config['price_diff_fee_rate'] ?? '0';
// 奖比例 // 奖比例
$bonusRate = '1'; $bonusRate = '1';
// 总收益 // 总收益
$totalRevenue = bcmul($totalDiffPrice, $bonusRate); $totalRevenue = bcmul($totalDiffPrice, $bonusRate);
@ -294,22 +289,13 @@ class DistributionPreIncomeJobService
]; ];
} }
/* // 如果总销售值大于0需计算各级代理的奖励
|----------------------------------------------- if ($totalSalesValue > 0) {
| 代理奖励
|-----------------------------------------------
*/
// 如果总成长值小于或等于0则直接不计算代理奖励
if ($totalSalesValue <= 0) {
return;
}
// 可获取奖励 // 可获取奖励
$agents = $this->getAgentsByUser($user); $agents = $this->getAgentsByUser($user);
$lastAgent = null; $lastAgent = null;
// 已分配的级差奖金比例 // 已分配的级差奖励比例
$assignedLvlDiffBonusRate = 0; $assignedLvlDiffBonusRate = 0;
foreach ($agents as $agent) { foreach ($agents as $agent) {
@ -400,7 +386,7 @@ class DistributionPreIncomeJobService
'fee_rate' => bcmul($feeRate, '1', 2), 'fee_rate' => bcmul($feeRate, '1', 2),
// 实际奖励比例 // 实际奖励比例
'bonus_rate' => bcmul($bonusRate, '1', 2), 'bonus_rate' => bcmul($bonusRate, '1', 2),
// 级差奖比例 // 级差奖比例
'lvl_diff_bonus_rate' => bcmul($lvlDiffBonusRate, '1', 2), 'lvl_diff_bonus_rate' => bcmul($lvlDiffBonusRate, '1', 2),
], ],
'remarks' => "级差奖励-订单号: {$order->sn}", 'remarks' => "级差奖励-订单号: {$order->sn}",
@ -425,6 +411,7 @@ class DistributionPreIncomeJobService
$lastAgent = $agent; $lastAgent = $agent;
} }
}
DistributionPreIncomeLog::insert($preIncomeLogs); DistributionPreIncomeLog::insert($preIncomeLogs);
} }

View File

@ -10,6 +10,7 @@ use App\Exceptions\BizException;
use App\Exceptions\ShippingNotSupportedException; use App\Exceptions\ShippingNotSupportedException;
use App\Helpers\Numeric; use App\Helpers\Numeric;
use App\Helpers\Order as OrderHelper; use App\Helpers\Order as OrderHelper;
use App\Models\DistributionPreIncomeJob;
use App\Models\Order; use App\Models\Order;
use App\Models\OrderProduct; use App\Models\OrderProduct;
use App\Models\ProductGift; use App\Models\ProductGift;
@ -191,6 +192,7 @@ class OrderService
'weight' => $sku->weight, 'weight' => $sku->weight,
'sell_price' => $sku->sell_price, 'sell_price' => $sku->sell_price,
'vip_price' => $sku->vip_price, 'vip_price' => $sku->vip_price,
'sales_value' => $sku->sales_value,
'quantity' => $qty, 'quantity' => $qty,
'remain_quantity' => $qty, // 剩余发货数量 'remain_quantity' => $qty, // 剩余发货数量
'coupon_discount_amount' => $product['coupon_discount_amount'], 'coupon_discount_amount' => $product['coupon_discount_amount'],
@ -219,6 +221,7 @@ class OrderService
'weight' => $giftSku->weight, 'weight' => $giftSku->weight,
'sell_price' => $giftSku->sell_price, 'sell_price' => $giftSku->sell_price,
'vip_price' => $giftSku->vip_price, 'vip_price' => $giftSku->vip_price,
'sales_value' => 0, // 赠品不算销售值
'quantity' => $gift['num'], 'quantity' => $gift['num'],
'remain_quantity' => $gift['num'], // 剩余发货数量 'remain_quantity' => $gift['num'], // 剩余发货数量
'coupon_discount_amount' => 0, 'coupon_discount_amount' => 0,
@ -753,8 +756,11 @@ class OrderService
report($th); report($th);
} }
DistributionPreIncomeJob::create([
// todo 处理预收益 'jobable_id' => $order->id,
'jobable_type' => $order->getMorphClass(),
'remarks' => '支付订单',
]);
return $order; return $order;
} }
@ -796,11 +802,17 @@ class OrderService
} }
if ($order->isWaitShipping()) { if ($order->isWaitShipping()) {
$order->refundLogs()->create([ $refundLog = $order->refundLogs()->create([
'sn' => OrderHelper::serialNumber(), 'sn' => OrderHelper::serialNumber(),
'amount' => $order->total_amount, 'amount' => $order->total_amount,
'reason' => '取消订单', 'reason' => '取消订单',
]); ]);
DistributionPreIncomeJob::create([
'jobable_id' => $refundLog->id,
'jobable_type' => $refundLog->getMorphClass(),
'remarks' => '取消订单',
]);
} }
$products = $order->products()->get(); $products = $order->products()->get();