57 行
2.1 KiB
PHP
57 行
2.1 KiB
PHP
<?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();
|
||
}
|
||
}
|
||
}
|