64 lines
1.6 KiB
PHP
64 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Bonus;
|
|
|
|
use App\User;
|
|
use RuLong\Bonus\Contracts\Settlement;
|
|
use RuLong\Bonus\Models\Bonus;
|
|
use RuLong\Bonus\Traits\Settlementable;
|
|
|
|
class Direct implements Settlement
|
|
{
|
|
use Settlementable;
|
|
|
|
public $order;
|
|
public $other;
|
|
public $ref_price;
|
|
|
|
public function __construct($order, array $other = null, $number = 1)
|
|
{
|
|
$this->order = $order;
|
|
$this->other = $other;
|
|
|
|
$user = $this->order->user;
|
|
$price = 0;
|
|
|
|
$source['user_id'] = $user->id;
|
|
$source['orderid'] = $this->order->orderid;
|
|
if (!is_null($this->other)) {
|
|
$source = array_merge($source, $this->other);
|
|
}
|
|
$parent = $user->relation->parent_id > 0 ? $user->parent : false;
|
|
while ($parent) {
|
|
if ($parent->identity->identity_id > 1) {
|
|
$proportion = $parent->identity->info->configs['Direct'] ?? 0; //获取身份对应分润比例
|
|
if ($proportion > 0) {
|
|
//确实享受佣金
|
|
$price = $this->order->amount * $proportion / 100;
|
|
$parent->rule('Direct', $price, false, $source);
|
|
break; //退出循环
|
|
}
|
|
}
|
|
$parent = $parent->relation->parent_id > 0 ? $parent->parent : false;
|
|
}
|
|
$this->ref_price = $price;
|
|
|
|
}
|
|
|
|
/**
|
|
* 直接推荐成单
|
|
* @Date:2018-11-05T13:21:47+0800
|
|
* @return [type] [description]
|
|
*/
|
|
public function fire()
|
|
{
|
|
|
|
}
|
|
|
|
public function getRefPirce()
|
|
{
|
|
return $this->ref_price;
|
|
}
|
|
|
|
}
|