Issue.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace App\Models;
  3. use App\Services\IssueService;
  4. use Illuminate\Database\Eloquent\Builder;
  5. use Illuminate\Foundation\Auth\User as Authenticatable;
  6. use Illuminate\Notifications\Notifiable;
  7. use Laravel\Sanctum\HasApiTokens;
  8. /**
  9. * Bet
  10. * @mixin Builder
  11. * @method static Builder|static where($column, $operator = null, $value = null, $boolean = 'and')
  12. */
  13. class Issue extends Authenticatable
  14. {
  15. use HasApiTokens, Notifiable;
  16. protected $table = 'issues';
  17. // protected $hidden = ['created_at', 'updated_at'];
  18. protected $fillable = ['issue_no', 'start_time', 'end_time', 'winning_numbers', 'status', 'combo', 'extreme', 'image'];
  19. protected $appends = [
  20. 'award'
  21. ];
  22. function getAwardAttribute()
  23. {
  24. if(!empty($this->winning_numbers))
  25. return IssueService::award($this->winning_numbers);
  26. return [];
  27. }
  28. const STATUS_DRAFT = 0;
  29. const STATUS_BETTING = 1;
  30. const STATUS_CLOSE = 2;
  31. const STATUS_DRAW = 3;
  32. public static $STATUS = [
  33. 0 => '草稿',
  34. 1 => '投注中',
  35. 2 => '封盘',
  36. 3 => '开奖',
  37. ];
  38. public static function getStatus($val = -1)
  39. {
  40. $array = self::$STATUS;
  41. if ($val < 0) {
  42. $arr = [];
  43. foreach ($array as $k => $v) {
  44. $item = [];
  45. $item['id'] = $k;
  46. $item['title'] = $v;
  47. $arr[] = $item;
  48. }
  49. return $arr;
  50. } else {
  51. return $array[$val];
  52. }
  53. }
  54. protected function getCreatedAtAttribute($value)
  55. {
  56. return \Carbon\Carbon::parse($value)->setTimezone('Asia/Shanghai')->format('Y-m-d H:i:s');
  57. }
  58. protected function getUpdatedAtAttribute($value)
  59. {
  60. return \Carbon\Carbon::parse($value)->setTimezone('Asia/Shanghai')->format('Y-m-d H:i:s');
  61. }
  62. // public function children()
  63. // {
  64. // return $this->hasMany(Menu::class, 'parent_id');
  65. // }
  66. // public function parent()
  67. // {
  68. // return $this->belongsTo(Menu::class, 'parent_id');
  69. // }
  70. }