73 lines
1.9 KiB
PHP
73 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Bonus;
|
|
|
|
use App\User;
|
|
use RuLong\Bonus\Contracts\Settlement;
|
|
use RuLong\Bonus\Traits\BloodLine;
|
|
use RuLong\Bonus\Traits\Settlementable;
|
|
|
|
class Repeat implements Settlement
|
|
{
|
|
use Settlementable, BloodLine;
|
|
|
|
public $user;
|
|
public $order;
|
|
public $Repeat;
|
|
public $other;
|
|
public $source = [];
|
|
|
|
public function __construct($order, array $other = null)
|
|
{
|
|
$this->order = $order;
|
|
$this->other = $other;
|
|
$this->Repeat = self::getRepeat($order);
|
|
}
|
|
|
|
public function getRepeat($order)
|
|
{
|
|
$repeat = 0;
|
|
foreach ($order->details as $key => $detail) {
|
|
$repeat += $detail->item->repeat;
|
|
}
|
|
return $repeat;
|
|
}
|
|
|
|
/**
|
|
* 重消奖
|
|
* @Author:<Leady>
|
|
* @Date:2018-11-05T13:21:47+0800
|
|
* @return [type] [description]
|
|
*/
|
|
public function fire()
|
|
{
|
|
$config = config('rulong_bonus.Settlement.Repeat');
|
|
$user = $this->order->user;
|
|
$this->strLine = $user->relation->bloodline;
|
|
|
|
$this->source['user_id'] = $user->id;
|
|
$this->source['orderid'] = $this->order->orderid;
|
|
if (!is_null($this->other)) {
|
|
$this->source = array_merge($this->source, $this->other);
|
|
}
|
|
if ($this->Repeat <= 0) {
|
|
return false;
|
|
}
|
|
|
|
if ($user->identity->identity_id > 0) {
|
|
$bloodLine = self::getUpBloodLine($user, 6); //获取上级血缘线
|
|
$cash = round($this->Repeat * $config, 2); //计算复消单笔金额
|
|
|
|
foreach ($bloodLine as $key => $userRelation) {
|
|
//见点
|
|
$userFire = User::find($userRelation->user_id);
|
|
if ($userFire && $userFire->identity->identity_id > 0) {
|
|
$userFire->rule('Repeat', $cash, true, $this->source);
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
}
|