94 lines
2.6 KiB
PHP
94 lines
2.6 KiB
PHP
<?php
|
|
|
|
|
|
namespace Yunshop\TeamDividend\models;
|
|
|
|
use app\backend\models\BackendModel;
|
|
use app\common\models\Member;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class TeamReward extends BackendModel
|
|
{
|
|
|
|
use SoftDeletes;
|
|
public $table = 'yz_team_reward';
|
|
|
|
public $LevelService;
|
|
public $SubordinateService;
|
|
protected $appends = ['level_name','subordinate_name'];
|
|
|
|
public static function getReward($search)
|
|
{
|
|
$Model = self::uniacid();
|
|
|
|
if (!empty($search['member'])) {
|
|
$Model->whereHas('hasOneMember', function ($query) use ($search) {
|
|
return $query->searchLike($search['member']);
|
|
});
|
|
}
|
|
$Model->with('hasOneMember');
|
|
$Model->with('hasOneLevel');
|
|
$Model->with('hasOneSubordinate');
|
|
$Model->with('hasOneSubordinateLevel');
|
|
|
|
if ($search['searchtime']) {
|
|
if ($search['times']) {
|
|
$range = [strtotime($search['times']['start']), strtotime($search['times']['end'])];
|
|
$Model->whereBetween('created_at', $range);
|
|
}
|
|
}
|
|
|
|
return $Model;
|
|
}
|
|
|
|
public static function getDividendByMonth()
|
|
{
|
|
$model = self::uniacid();
|
|
$model->where('member_id', \YunShop::app()->getMemberId());
|
|
$model->orderBy('id', 'desc');
|
|
return $model;
|
|
}
|
|
|
|
public function getSubordinateNameAttribute()
|
|
{
|
|
if (!isset($this->SubordinateService)) {
|
|
$member = Member::getMemberById($this->subordinate_agency);
|
|
$this->SubordinateService = $member->nickname;
|
|
}
|
|
return $this->SubordinateService;
|
|
}
|
|
public function getLevelNameAttribute()
|
|
{
|
|
if (!isset($this->LevelService)) {
|
|
$level = TeamDividendLevelModel::getLevelById($this->subordinate_level);
|
|
$this->LevelService = $level->level_name;
|
|
}
|
|
return $this->LevelService;
|
|
}
|
|
|
|
public function hasManyReward()
|
|
{
|
|
return $this->hasMany(self::class, "create_month", "create_month");
|
|
}
|
|
|
|
public function hasOneMember()
|
|
{
|
|
return $this->hasOne('app\common\models\Member', 'uid', 'member_id');
|
|
}
|
|
|
|
public function hasOneSubordinate()
|
|
{
|
|
return $this->hasOne('app\common\models\Member', 'uid', 'subordinate_agency');
|
|
}
|
|
|
|
public function hasOneLevel()
|
|
{
|
|
return $this->hasOne('Yunshop\TeamDividend\models\TeamDividendLevelModel', 'id', 'level');
|
|
}
|
|
|
|
public function hasOneSubordinateLevel()
|
|
{
|
|
return $this->hasOne('Yunshop\TeamDividend\models\TeamDividendLevelModel', 'id', 'subordinate_level');
|
|
}
|
|
|
|
} |