87 lines
1.7 KiB
PHP
87 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
class LotteryGift extends Model
|
|
{
|
|
static $levels = [
|
|
'1' => '一等奖',
|
|
'2' => '二等奖',
|
|
'3' => '三等奖',
|
|
'4' => '四等奖',
|
|
'5' => '五等奖',
|
|
'6' => '六等奖',
|
|
'7' => '七等奖',
|
|
'8' => '谢谢参与',
|
|
];
|
|
|
|
static $chances = [
|
|
'1' => 0,
|
|
'2' => 1,
|
|
'3' => 2,
|
|
'4' => 7,
|
|
'5' => 3,
|
|
'6' => 5,
|
|
'7' => 4,
|
|
'8' => 6,
|
|
];
|
|
|
|
static $types = [
|
|
'0' => '谢谢参与',
|
|
'1' => '正常奖品',
|
|
];
|
|
|
|
static $class = [
|
|
'activity' => 'App\Models\Activity',
|
|
'coupon' => 'RuLong\Coupon\Models\CouponInfo',
|
|
'goods' => 'App\Models\GoodsParams',
|
|
];
|
|
|
|
public function lottery()
|
|
{
|
|
return $this->belongsTo(Lottery::class)->withDefault();
|
|
}
|
|
|
|
public function item()
|
|
{
|
|
return $this->morphTo();
|
|
}
|
|
|
|
public function getLevelTextAttribute()
|
|
{
|
|
return self::$levels[$this->level] ?? '未知';
|
|
}
|
|
|
|
public function getTypeTextAttribute()
|
|
{
|
|
return self::$types[$this->type] ?? '未知';
|
|
}
|
|
|
|
public function getClassAttribute()
|
|
{
|
|
foreach (self::$class as $key => $class) {
|
|
if ($this->item_type == $class) {
|
|
return $key;
|
|
}
|
|
}
|
|
|
|
return 'Null';
|
|
}
|
|
|
|
public function getChanceTextAttribute()
|
|
{
|
|
$all = $this->lottery->gifts()->sum('chance');
|
|
return round($this->chance / $all * 100, 2);
|
|
}
|
|
|
|
public function getTitle()
|
|
{
|
|
if ($this->item) {
|
|
return $this->item->getTitle();
|
|
} else {
|
|
return '谢谢参与';
|
|
}
|
|
}
|
|
|
|
}
|