优化复购功能:指定商品复购付款时直接立减(不返现),解耦分销买家佣金,纯后端实现
这个提交包含在:
@@ -128,11 +128,8 @@ class Commission
|
||||
|
||||
|
||||
|
||||
$hasRepurchaseSelf = $this->isRepurchase()
|
||||
&& $this->_config->isRepurchaseSelfEnable()
|
||||
&& $this->goods->isRepurchaseEnable();
|
||||
|
||||
|
||||
// 复购已在下单付款时直接减免,分销佣金奖池中不再发放买家本人复购返现
|
||||
$hasRepurchaseSelf = false;
|
||||
|
||||
if (!$hasChainCommission && !$hasTierCommission && !$hasRepurchaseSelf) {
|
||||
|
||||
@@ -677,135 +674,29 @@ class Commission
|
||||
|
||||
|
||||
protected function runRepurchaseRewards($commissionOrder)
|
||||
|
||||
{
|
||||
|
||||
if (!$this->isRepurchase() || !$this->_config->isRepurchaseSelfEnable() || !$this->goods->isRepurchaseEnable()) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$commission = 0;
|
||||
|
||||
$rule = ['award_type' => 'repurchase_self'];
|
||||
|
||||
if ($this->_config->getRepurchaseSelfType() === 'fixed') {
|
||||
|
||||
$commission = round($this->_config->getRepurchaseSelfAmount(), 2);
|
||||
|
||||
$rule['type'] = 'fixed';
|
||||
|
||||
$rule['amount'] = $commission;
|
||||
|
||||
} else {
|
||||
|
||||
$rate = $this->_config->getRepurchaseSelfRate();
|
||||
|
||||
if ($rate <= 0) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
$commission = round($this->amount * $rate * 0.01, 2);
|
||||
|
||||
$rule['type'] = 'rate';
|
||||
|
||||
$rule['rate'] = $rate;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($commission <= 0) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$rewards = RewardModel::where('commission_order_id', $commissionOrder->id)
|
||||
|
||||
->where('agent_id', $this->buyer->user->id)
|
||||
|
||||
->where('commission_level', 0)
|
||||
|
||||
->select();
|
||||
|
||||
foreach ($rewards as $reward) {
|
||||
|
||||
$rewardRules = json_decode($reward->commission_rules, true);
|
||||
|
||||
if (($rewardRules['award_type'] ?? '') === 'repurchase_self') {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$reward = RewardModel::create([
|
||||
|
||||
'order_id' => $commissionOrder->order_id,
|
||||
|
||||
'order_item_id' => $commissionOrder->order_item_id,
|
||||
|
||||
'buyer_id' => $commissionOrder->buyer_id,
|
||||
|
||||
'commission_order_id' => $commissionOrder->id,
|
||||
|
||||
'agent_id' => $this->buyer->user->id,
|
||||
|
||||
'type' => 'money',
|
||||
|
||||
'commission' => $commission,
|
||||
|
||||
'status' => 0,
|
||||
|
||||
'original_commission' => $commission,
|
||||
|
||||
'commission_level' => 0,
|
||||
|
||||
'commission_rules' => json_encode($rule),
|
||||
|
||||
'agent_level' => 0,
|
||||
|
||||
]);
|
||||
|
||||
|
||||
|
||||
Log::write($this->buyer->user->id, 'reward', [
|
||||
|
||||
'action' => 'repurchase_self',
|
||||
|
||||
'reward' => $reward,
|
||||
|
||||
], ['oper_type' => 'user', 'oper_id' => $commissionOrder->buyer_id]);
|
||||
|
||||
// 复购优惠已在商品下单付款时直接立减,此处不再发放买家本人复购返现佣金
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected function isRepurchase()
|
||||
|
||||
{
|
||||
$goodsId = $this->item['goods_id'] ?? 0;
|
||||
$userId = $this->buyer->user->id ?? 0;
|
||||
if (!$goodsId || !$userId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$count = \addons\shopro\model\Order::where('user_id', $this->buyer->user->id)
|
||||
|
||||
->where('status', 'in', [1, 2])
|
||||
|
||||
->where('id', '<', $this->item['order_id'])
|
||||
|
||||
$count = \addons\shopro\model\OrderItem::alias('oi')
|
||||
->join('shopro_order o', 'o.id = oi.order_id')
|
||||
->where('o.user_id', $userId)
|
||||
->where('o.status', 'in', [1, 2])
|
||||
->where('oi.goods_id', $goodsId)
|
||||
->where('o.id', '<', $this->item['order_id'])
|
||||
->where('oi.refund_status', '<=', 0)
|
||||
->count();
|
||||
|
||||
return $count > 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
在新工单中引用
屏蔽一个用户