51 lines
1.4 KiB
PHP
51 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
/**
|
|
* 分红队列
|
|
*/
|
|
class ProfitBonus implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, SerializesModels;
|
|
public $queue = 'PROFIT';
|
|
public $tries = 1;
|
|
public $timeout = 30;
|
|
|
|
protected $user; //用户模型
|
|
protected $profit; //执行的分红记录
|
|
protected $eachCash; //每一份金额
|
|
protected $config; //等级全部分红
|
|
protected $identity; //身份集合
|
|
|
|
public function __construct($user, $profit, $eachCash = 0, $identity = null)
|
|
{
|
|
$this->user = $user; //用户模型
|
|
$this->profit = $profit; //分红记录模型
|
|
$this->eachCash = $eachCash; //每一份金额
|
|
$this->identity = $identity; //参与分红身份ID
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
|
|
if ($this->eachCash <= 0) {
|
|
return false;
|
|
}
|
|
|
|
$selfPoint = $this->user->pointlogs()
|
|
->where('identity_id', $this->identity)
|
|
->where('created_at', '<', $this->profit->end_at)
|
|
->sum('point');
|
|
$cash = round($this->eachCash * $selfPoint, 2);
|
|
if ($cash > 0) {
|
|
$this->user->rule('profit' . $this->identity, $cash, false, [date('Y-m-d', strtotime($this->profit->end_at))]);
|
|
}
|
|
}
|
|
}
|