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

55
app/Bonus/AddPerf.php Normal file
View File

@@ -0,0 +1,55 @@
<?php
namespace App\Bonus;
use App\Models\User;
use App\Models\UserPerf;
use RuLong\Bonus\Contracts\Settlement;
use RuLong\Bonus\Models\Bonus;
use RuLong\Bonus\Traits\Settlementable;
/**
* 添加业绩
*/
class AddPerf implements Settlement
{
use Settlementable;
public $user;
public $perf;
public $source;
public function __construct(User $user, $perf, $source = [])
{
$this->user = $user->fresh();
$this->perf = $perf;
$this->source = $source;
}
/**
* 添加业绩
* @return [type] [description]
*/
public function fire()
{
$data = [
'user_id' => $this->user->id,
'perf' => $this->perf,
'from_id' => $this->user->id,
'source' => json_encode($this->source),
'created_at' => now()->format('Y-m-d H:i:s'),
'updated_at' => now()->format('Y-m-d H:i:s'),
];
$parent = $this->user;
$lists = [];
while ($parent) {
$data['user_id'] = $parent->id;
$lists[] = $data;
$parent = $parent->parent;
}
if (count($lists) > 0) {
UserPerf::insert($lists);
}
}
}

72
app/Bonus/BuyCard.php Normal file
View File

@@ -0,0 +1,72 @@
<?php
namespace App\Bonus;
use App\Models\CardPayment;
use RuLong\Bonus\Contracts\Settlement;
use RuLong\Bonus\Models\Bonus;
use RuLong\Bonus\Traits\Settlementable;
/**
* 购卡佣金
*/
class BuyCard 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 = 'direct_card'; //默认直推
while ($parent) {
$price = $parent->identity->info->configs[$eventName] ?? 0; //结算单价
if ($price) {
$amount = $this->payment->amount; //代理金额
$num = $order->num; //代理金额
$cash = $price * $num; //实际佣金
$log = $parent->accountLogs()->whereIn('rule_id', [7, 8])->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); //执行立即到账
}
if ($eventName == 'indirect_card') {
break;
} else {
$eventName = 'indirect_card'; //更改间接推荐
}
}
$parent = $parent->parent;
}
} else {
\Log::channel('bonus')->error('购卡订单或会员不存在' . $this->payment->order_id);
}
} else {
\Log::channel('bonus')->error('购卡订单状态不正确(ID:' . ($this->payment->id ?? '无') . ')');
}
}
}

View 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 DirectAgency 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 == 'agent' && $this->payment->state == 'SUCCESS') {
//判断订单状态
$user = $this->payment->user; //获取会员
if ($user) {
//基础判断
$parent = $user->parent; //获取推荐人
$eventName = 'direct_agency'; //默认直推
while ($parent) {
$rate = $parent->identity->info->configs[$eventName] ?? 0; //结算比例
if ($rate) {
$amount = $this->payment->amount; //代理金额
$cash = round($amount * $rate / 100, 2); //实际佣金
$log = $parent->accountLogs()->whereIn('rule_id', [5, 6])->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); //执行立即到账
}
if ($eventName == 'indirect_agency') {
break;
} else {
$eventName = 'indirect_agency'; //更改间接推荐
}
}
$parent = $parent->parent;
}
return true;
} else {
\Log::channel('bonus')->error('升级代理不存在' . $this->payment->user_id);
}
} else {
\Log::channel('bonus')->error('升级代理状态不正确或不存在(ID:' . ($this->payment->id ?? '无') . ')');
}
}
}

69
app/Bonus/DirectVip.php Normal file
View 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 ?? '无') . ')');
}
}
}

65
app/Bonus/ProfitStart.php Normal file
View File

@@ -0,0 +1,65 @@
<?php
namespace App\Bonus;
use App\Models\Profit;
use App\Models\ProfitLog;
use App\Models\User;
use RuLong\Bonus\Contracts\Settlement;
use RuLong\Bonus\Models\Bonus;
use RuLong\Bonus\Traits\Settlementable;
/**
* 购卡佣金
*/
class ProfitStart implements Settlement
{
use Settlementable;
public $profit;
public function __construct(Profit $profit)
{
$this->profit = $profit->fresh();
}
/**
* 购卡佣金
* @return [type] [description]
*/
public function fire()
{
if ($this->profit && $this->profit->sett === 0) {
$users = User::when($this->profit->identity_id, function ($query) {
$query->whereHas('identity', function ($q) {
$q->where('identity_id', $this->profit->identity_id);
});
})->get();
$this->profit->num = $users->count();
if ($this->profit->num == 0) {
$this->profit->single = 0;
} else {
$this->profit->single = bcadd($this->profit->price / $users->count(), 0, 2);
}
$this->profit->realPrice = $this->profit->single * $this->profit->num;
$this->profit->sett = 1;
$this->profit->setted_at = now();
if ($this->profit->save()) {
$source = [
'profit_id' => $this->profit->id,
];
foreach ($users as $key => $user) {
$user->rule('profit', $this->profit->single, false, $source);
ProfitLog::create([
'profit_id' => $this->profit->id,
'user_id' => $user->id,
'price' => $this->profit->single,
]);
}
}
} else {
\Log::channel('bonus')->error('全球分红不正确(ID:' . ($this->profit->id ?? '无') . ')');
}
}
}

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 ?? '无') . ')');
}
}
}