1
0
Files
GongShangLian/app/Bonus/Agent.php
2020-08-06 15:36:28 +08:00

64 lines
1.5 KiB
PHP

<?php
namespace App\Bonus;
use App\User;
use RuLong\Bonus\Contracts\Settlement;
use RuLong\Bonus\Models\Bonus;
use RuLong\Bonus\Traits\Settlementable;
use RuLong\Identity\Models\UserIdentity;
class Agent implements Settlement
{
use Settlementable;
public $order;
public $other;
public $bonus;
public function __construct($order, array $other = null, $bonus = null)
{
$this->order = $order;
$this->other = $other;
$this->bonus = $bonus;
}
/**
* 直接推荐成单
* @Date:2018-11-05T13:21:47+0800
* @return [type] [description]
*/
public function fire()
{
$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);
}
$user = UserIdentity::where('identity_id', 6)->first();
if ($user) {
$parent = $user->user;
$proportion = $parent->identity->info->configs['Agent'] ?? 0;
if ($proportion > 0) {
//确实享受佣金
$price = (int) $this->order->amount * $proportion / 100 - $this->bonus->settlement->ref_price;
if ($price > 0) {
$parent->rule('Agent', $price, false, $source);
return true;
}
return false;
}
return false;
} else {
return false;
}
}
}