131 lines
2.6 KiB
PHP
131 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class DistributionPreIncome extends Model
|
|
{
|
|
use HasDateTimeFormatter;
|
|
|
|
public const STATUS_PENDING = 0;
|
|
public const STATUS_PROCESSING = 1;
|
|
public const STATUS_PROCESSED = 2;
|
|
|
|
public const TYPE_PRICE_DIFF = 1;
|
|
public const TYPE_LEVEL_SAME = 2;
|
|
public const TYPE_LEVEL_DIFF = 3;
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $attributes = [
|
|
'status' => self::STATUS_PENDING,
|
|
];
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $casts = [
|
|
'rule' => 'json',
|
|
'completed_at' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'user_id',
|
|
'order_id',
|
|
'type',
|
|
'agent_level',
|
|
'total_amount',
|
|
'total_sales_value',
|
|
'total_revenue',
|
|
'rule',
|
|
'status',
|
|
'remarks',
|
|
'rule',
|
|
'completed_at',
|
|
];
|
|
|
|
public static $typeTexts = [
|
|
self::TYPE_PRICE_DIFF => '推粉丝赚差价',
|
|
self::TYPE_LEVEL_SAME => '平级奖励',
|
|
self::TYPE_LEVEL_DIFF => '级差奖励',
|
|
];
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
public static $statusTexts = [
|
|
self::STATUS_PENDING => '待结算',
|
|
self::STATUS_PROCESSING => '结算中',
|
|
self::STATUS_PROCESSED => '已结算',
|
|
];
|
|
|
|
/**
|
|
* 仅查询未结算的预收益
|
|
*/
|
|
public function scopeUnsettlement($query)
|
|
{
|
|
return $query->whereIn('status', [
|
|
static::STATUS_PENDING,
|
|
static::STATUS_PROCESSING,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 仅查询结算中的预收益
|
|
*/
|
|
public function scopeProcessing($query)
|
|
{
|
|
return $query->where('status', static::STATUS_PROCESSING);
|
|
}
|
|
|
|
/**
|
|
* 此预收益的所属的用户
|
|
*/
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
/**
|
|
* 此预收益的所属订单
|
|
*/
|
|
public function order()
|
|
{
|
|
return $this->belongsTo(Order::class);
|
|
}
|
|
|
|
/**
|
|
* 此预收益的变更记录
|
|
*/
|
|
public function logs()
|
|
{
|
|
return $this->hasMany(DistributionPreIncomeLog::class, 'pre_income_id');
|
|
}
|
|
|
|
/**
|
|
* 等级名称
|
|
*
|
|
* @return void
|
|
*/
|
|
public function getAgentLevelNameAttribute()
|
|
{
|
|
return UserInfo::$agentLevelTexts[$this->agent_level] ?? '未知';
|
|
}
|
|
|
|
/**
|
|
* 获取类型文本
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getTypeTextAttribute(): string
|
|
{
|
|
return static::$typeTexts[$this->type] ?? '其它';
|
|
}
|
|
}
|