@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\service\partner;
|
||||
|
||||
use app\admin\model\shopro\commission\Agent as AgentModel;
|
||||
|
||||
/**
|
||||
* 推三返一:398/400/600 循环,计到直推上级,自购不发
|
||||
*/
|
||||
class Push3Reward
|
||||
{
|
||||
public function run($order, $buyerId, $parent, ActiveService $active)
|
||||
{
|
||||
if (!$parent) {
|
||||
PartnerRewardService::writeSkip($order, $buyerId, 0, 'push3', 'taster', 'no_parent', '无直推上级');
|
||||
return;
|
||||
}
|
||||
if (intval($parent['user_id']) === intval($buyerId)) {
|
||||
PartnerRewardService::writeSkip($order, $buyerId, $parent['user_id'], 'push3', 'taster', 'self_buy', '自购不产生推三返一');
|
||||
return;
|
||||
}
|
||||
if (intval($parent['level']) < 1) {
|
||||
PartnerRewardService::writeSkip($order, $buyerId, $parent['user_id'], 'push3', 'taster', 'no_parent', '直推上级不是品酒师/创客');
|
||||
return;
|
||||
}
|
||||
if (!$active->isActive($parent['agent'] ?? $parent)) {
|
||||
PartnerRewardService::writeSkip($order, $buyerId, $parent['user_id'], 'push3', 'taster', 'inactive_30d', '直推上级 30 日无自购');
|
||||
return;
|
||||
}
|
||||
|
||||
$agent = AgentModel::where('user_id', $parent['user_id'])->lock(true)->find();
|
||||
if (!$agent) {
|
||||
return;
|
||||
}
|
||||
$agent->direct_order_seq = intval($agent->direct_order_seq) + 1;
|
||||
$agent->save();
|
||||
|
||||
$amounts = PartnerConfig::push3Amounts();
|
||||
$seq = intval($agent->direct_order_seq);
|
||||
$amount = $amounts[($seq - 1) % 3];
|
||||
|
||||
PartnerRewardService::account($order, $buyerId, $agent->user_id, 'push3', 'taster', $amount, $amount, [
|
||||
'formula' => "直推第{$seq}单,循环第" . ((($seq - 1) % 3) + 1) . "档 +{$amount}",
|
||||
'seq' => $seq,
|
||||
]);
|
||||
}
|
||||
|
||||
public function rollbackSeq($userId)
|
||||
{
|
||||
$agent = AgentModel::where('user_id', $userId)->lock(true)->find();
|
||||
if ($agent && $agent->direct_order_seq > 0) {
|
||||
$agent->direct_order_seq = $agent->direct_order_seq - 1;
|
||||
$agent->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户