67 lines
1.9 KiB
PHP
67 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Bonus;
|
|
|
|
use App\User;
|
|
use RuLong\Bonus\Contracts\Settlement;
|
|
use RuLong\Bonus\Models\Bonus;
|
|
use RuLong\Bonus\Traits\BloodLine;
|
|
use RuLong\Bonus\Traits\Settlementable;
|
|
use RuLong\Order\Models\Order;
|
|
|
|
class Direct implements Settlement
|
|
{
|
|
use Settlementable, BloodLine;
|
|
|
|
public $config;
|
|
public $user;
|
|
public $bloodLine;
|
|
public $strLine;
|
|
public $source = [];
|
|
public $other;
|
|
|
|
public function __construct($user, array $other = null)
|
|
{
|
|
$this->user = $user;
|
|
$this->other = $other;
|
|
}
|
|
|
|
/**
|
|
* 直接推荐成单
|
|
* @Author:<Leady>
|
|
* @Date:2018-11-05T13:21:47+0800
|
|
* @return [type] [description]
|
|
*/
|
|
public function fire()
|
|
{
|
|
$this->config = config('rulong_bonus.Settlement.Direct');
|
|
$this->strLine = $this->user->relation->bloodline;
|
|
$this->source['user_id'] = $this->user->id;
|
|
if (!is_null($this->other)) {
|
|
$this->source = array_merge($this->source, $this->other);
|
|
}
|
|
|
|
$order = Order::find($this->source['orderid']);
|
|
if ($order->profit != 1) {
|
|
$this->bloodLine = self::getUpBloodLine($this->user, $this->config['layer']); //获取上级血缘线
|
|
|
|
foreach ($this->bloodLine as $key => $userRelation) {
|
|
//见点
|
|
$userFire = User::find($userRelation->user_id);
|
|
if ($userFire && $userFire->identity->identity_id > 0) {
|
|
$this->source['layer'] = $this->user->relation->layer - $userRelation->layer;
|
|
$userFire->rule('Point', $this->config['point'][$this->source['layer']], false, $this->source);
|
|
}
|
|
}
|
|
|
|
$this->user->direct = 1;
|
|
$this->user->save();
|
|
|
|
$order->profit = 1;
|
|
$order->save();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
}
|