89 lines
2.3 KiB
PHP
89 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
class UserGuess extends Model
|
|
{
|
|
use HasFactory, HasDateTimeFormatter;
|
|
|
|
protected $table = 'user_guess';
|
|
|
|
protected $fillable = ['guess_id', 'user_id', 'correct_state', 'prize_state', 'convert_time', 'convert_prize_time', 'prize'];
|
|
|
|
protected $dates = ['convert_time', 'convert_prize_time'];
|
|
|
|
protected $attributes = [
|
|
'correct_state' => self::UN_SET, //2,
|
|
'prize_state' => self::PRIZE_UN_SET, //2,
|
|
// 'convert_time' => 0,
|
|
];
|
|
|
|
protected $casts = [
|
|
'prize' => 'array'
|
|
];
|
|
|
|
protected static function booted()
|
|
{
|
|
static::deleting(function ($info) {
|
|
$info->options()->detach();
|
|
});
|
|
}
|
|
|
|
const CORRECT = 1; // 竞猜正确
|
|
const UN_CORRECT = 0; // 竞猜错误
|
|
const UN_SET = 2; //未设置
|
|
|
|
const PRIZE_YES = 1; // 中大奖
|
|
const PRIZE_NO = 0; // 未中大奖
|
|
const PRIZE_UN_SET = 2; // 未中大奖
|
|
|
|
|
|
public static $correctStateMap = [
|
|
self::UN_SET => '结果统计中',
|
|
self::CORRECT => '竞猜正确',
|
|
self::UN_CORRECT => '竞猜失败',
|
|
];
|
|
|
|
public static $correctIcoMap = [
|
|
self::UN_SET => 'danger',
|
|
self::CORRECT => 'success',
|
|
self::UN_CORRECT => 'warning',
|
|
];
|
|
|
|
public static $prizeStateMap = [
|
|
// self::PRIZE_YES => '中得现金奖励',
|
|
// self::PRIZE_NO => '未中现金奖励',
|
|
// self::PRIZE_UN_SET => '未公布结果'
|
|
self::PRIZE_YES => '恭喜中奖',
|
|
self::PRIZE_NO => '未中奖',
|
|
self::PRIZE_UN_SET => '结果统计中'
|
|
];
|
|
|
|
public function guess()
|
|
{
|
|
return $this->belongsTo(Guess::class, 'guess_id');
|
|
}
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class, 'user_id');
|
|
}
|
|
|
|
public function options()
|
|
{
|
|
return $this->belongsToMany(GuessOption::class, 'user_guess_option', 'user_guess_id', 'guess_option_id');
|
|
}
|
|
|
|
public function getPrizeStateNameAttribute() {
|
|
return data_get(self::$prizeStateMap, $this->prize_state);
|
|
}
|
|
|
|
public function getCorrectStateNameAttribute() {
|
|
return data_get(self::$correctStateMap, $this->correct_state);
|
|
}
|
|
}
|