提交代码
This commit is contained in:
69
app/Bonus/DirectVip.php
Normal file
69
app/Bonus/DirectVip.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Bonus;
|
||||
|
||||
use App\Models\UpgradePayment;
|
||||
use RuLong\Bonus\Contracts\Settlement;
|
||||
use RuLong\Bonus\Models\Bonus;
|
||||
use RuLong\Bonus\Traits\Settlementable;
|
||||
|
||||
/**
|
||||
* 开通员工执行事件
|
||||
*/
|
||||
class DirectVip implements Settlement
|
||||
{
|
||||
use Settlementable;
|
||||
|
||||
public $payment;
|
||||
|
||||
public function __construct(UpgradePayment $payment)
|
||||
{
|
||||
$this->payment = $payment->fresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* 推荐会员佣金
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function fire()
|
||||
{
|
||||
if ($this->payment && $this->payment->type == 'vip' && $this->payment->state == 'SUCCESS') {
|
||||
//判断订单状态
|
||||
$user = $this->payment->user; //获取会员
|
||||
if ($user) {
|
||||
//基础判断
|
||||
$parent = $user->parent; //获取推荐人
|
||||
if ($parent) {
|
||||
//基础判断
|
||||
$odd_num = $parent->accountLogs()->where('rule_id', 3)->count(); //奇数次数
|
||||
$even_num = $parent->accountLogs()->where('rule_id', 4)->count(); //偶数次数
|
||||
$eventName = 'direct_odd'; //默认奇数
|
||||
if ($odd_num > $even_num) {
|
||||
//如果奇数大于偶数
|
||||
$eventName = 'direct_even'; //偶数
|
||||
}
|
||||
$amount = $this->payment->amount; //会员金额
|
||||
$rate = $parent->identity->info->configs[$eventName] ?? 0; //结算比例
|
||||
$cash = round($amount * $rate / 100, 2); //实际佣金
|
||||
$log = $parent->accountLogs()->whereIn('rule_id', [3, 4])->where('source->user_id', $user->id)->first(); //查看是否结算过佣金
|
||||
if ($cash > 0 && !$log) {
|
||||
$source = [
|
||||
'user_id' => $user->id, //会员ID
|
||||
'payment_id' => $this->payment->id, //升级订单ID
|
||||
'rate' => $rate, //结算比例
|
||||
'amount' => $amount, //结算金额
|
||||
];
|
||||
$parent->rule($eventName, $cash, false, $source); //执行立即到账
|
||||
}
|
||||
} else {
|
||||
\Log::channel('bonus')->error('升级会员不存在推荐人' . $this->payment->user_id);
|
||||
}
|
||||
} else {
|
||||
\Log::channel('bonus')->error('升级会员不存在' . $this->payment->user_id);
|
||||
}
|
||||
} else {
|
||||
\Log::channel('bonus')->error('升级会员状态不正确或不存在(ID:' . ($this->payment->id ?? '无') . ')');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user