66 lines
2.0 KiB
PHP
66 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\User;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
/**
|
|
* 分红队列
|
|
*/
|
|
class ProfitJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, SerializesModels;
|
|
public $queue = 'Profit';
|
|
public $tries = 1;
|
|
public $timeout = 30;
|
|
|
|
protected $user; //用户模型
|
|
protected $profit; //执行的分红记录
|
|
protected $allPoint; //总积分数组
|
|
protected $selfPoint; //个人积分数组
|
|
protected $proportion;
|
|
public function __construct($user_id, $profit)
|
|
{
|
|
$this->user = User::find($user_id); //用户模型
|
|
$this->profit = $profit; //分红记录模型
|
|
$this->allPoint = [
|
|
'3' => $profit->portion(3),
|
|
'4' => $profit->portion(4),
|
|
'5' => $profit->portion(5),
|
|
'6' => $profit->portion(6),
|
|
]; //每一份金额
|
|
$this->selfPoint = [
|
|
'3' => $profit->portion(3, $this->user->id),
|
|
'4' => $profit->portion(4, $this->user->id),
|
|
'5' => $profit->portion(5, $this->user->id),
|
|
'6' => $profit->portion(6, $this->user->id),
|
|
]; //参与分红身份ID
|
|
|
|
$this->proportion = [
|
|
'3' => 0.2,
|
|
'4' => 0.2,
|
|
'5' => 0.2,
|
|
'6' => 0.2,
|
|
]; //分红比例
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
foreach ($this->allPoint as $key => $all) {
|
|
$self = $this->selfPoint[$key];
|
|
if ($self <= 0 || $all <= 0) {
|
|
continue;
|
|
}
|
|
$share = round($this->profit->price * $this->proportion[$key] / $all, 2);
|
|
$cash = $self * (int) $share;
|
|
if ($cash > 0) {
|
|
$this->user->rule('profit' . $key, $cash, false, ['allPoint' => $all, 'selfPoint' => $self, 'identity_id' => $key, 'no' => $this->profit->end_at->format('Ymd')]);
|
|
}
|
|
}
|
|
}
|
|
}
|