0
0
Files
Babyclass/app/Bonus/Continuous.php
2020-08-04 10:09:42 +08:00

65 lines
2.2 KiB
PHP

<?php
namespace App\Bonus;
use App\User;
use RuLong\Bonus\Contracts\Settlement;
use RuLong\Bonus\Traits\Settlementable;
use RuLong\UserAccount\Models\UserAccountLog;
class Continuous implements Settlement
{
use Settlementable;
public $config;
public $user;
public $other = [];
public function __construct($user, array $other = null)
{
$this->user = User::find($user->id);
$this->other = $other;
}
/**
* 直接推荐成单
* @Author:<Leady>
* @Date:2018-11-05T13:21:47+0800
* @return [type] [description]
*/
public function fire()
{
$this->config = $this->user->identity->info->configs; //获取当前身份配置
if (!isset($this->config['upday']) || !isset($this->config['upid'])) {
//当前身份没有设定升级参数
return false;
}
if ($this->user->account->act_a < $this->config['upday']) {
//满仓总数不满足连续天数 直接退出。
return false;
}
$startTime = (string) $this->user->identity->created_at;
$startTime = date('Y-m-d', strtotime($startTime)) . ' 00:00:00';
$startTime = strtotime($startTime);
$lastTime = $startTime + $this->config['upday'] * 86400;
$logCount = UserAccountLog::where('user_id', $this->user->id)
->where('rule_id', 4)->whereBetween('created_at', [date('Y-m-d H:i:s', $startTime), date('Y-m-d H:i:s', $lastTime)])->count(); //获取时间范围内满仓记录数量
if ($logCount === $this->config['upday']) {
//满仓记录数量 等于 设定数量 达成条件
$identity = $this->config['upid']; //获取升级目标身份ID
$this->user->identityUpdate($identity); //改变会员身份
$this->user->addPoint($identity); //增加对应身份股权
if ($this->user->parent) {
if ($this->user->parent->id > 0 && $this->user->parent->identity->identity_id > 1) {
$this->user->parent->rule('tui' . 3, 1, false);
Identity::settlement($this->user->parent, $identity);
}
}
}
}
}