更新代码
This commit is contained in:
86
app/Models/LotteryGift.php
Normal file
86
app/Models/LotteryGift.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?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 '谢谢参与';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user