1
0

提交代码

This commit is contained in:
2020-08-06 14:45:56 +08:00
commit 9d0d5f4be9
361 changed files with 36445 additions and 0 deletions

69
app/Bonus/TeamCard.php Normal file
View File

@@ -0,0 +1,69 @@
<?php
namespace App\Bonus;
use App\Models\CardPayment;
use RuLong\Bonus\Contracts\Settlement;
use RuLong\Bonus\Models\Bonus;
use RuLong\Bonus\Traits\Settlementable;
/**
* 团队卡酬
*/
class TeamCard implements Settlement
{
use Settlementable;
public $payment;
public function __construct(CardPayment $payment)
{
$this->payment = $payment->fresh();
}
/**
* 购卡佣金
* @return [type] [description]
*/
public function fire()
{
if ($this->payment && $this->payment->state == 'SUCCESS') {
//判断订单状态
$order = $this->payment->order; //获取订单
$user = $order->user; //获取会员
if ($order && $user) {
//基础判断
$parent = $user->parent; //获取推荐人
$eventName = 'team_card'; //默认直推
$lastPrice = 0; //默认直推
while ($parent) {
$price = $parent->identity->info->configs[$eventName] ?? 0; //结算单价
if ($price) {
$amount = $this->payment->amount; //代理金额
$num = $order->num; //代理金额
$cash = $price * $num; //实际佣金
$cash -= $lastPrice;
$lastPrice += $cash;
$log = $parent->accountLogs()->where('rule_id', 9)->where('source->order_id', $order->id)->first(); //查看是否结算过佣金
if ($cash > 0 && !$log) {
$source = [
'user_id' => $user->id, //会员ID
'payment_id' => $this->payment->id, //升级订单ID
'order_id' => $order->id, //升级订单ID
'price' => $price, //结算比例
'num' => $num, //结算数量
];
$parent->rule($eventName, $cash, false, $source); //执行立即到账
}
}
$parent = $parent->parent;
}
} else {
\Log::channel('bonus')->error('购卡订单或会员不存在' . $this->payment->order_id);
}
} else {
\Log::channel('bonus')->error('购卡订单状态不正确(ID:' . ($this->payment->id ?? '无') . ')');
}
}
}