Issue.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace App\Models;
  3. use App\Services\IssueService;
  4. class Issue extends BaseModel
  5. {
  6. protected $table = 'issues';
  7. protected $fillable = ['issue_no', 'start_time', 'end_time', 'winning_numbers', 'status', 'combo', 'extreme', 'image', 'keno'];
  8. protected $appends = [
  9. 'award',
  10. 'winning_array',
  11. 'end_timestamp',
  12. ];
  13. function getEndTimestampAttribute()
  14. {
  15. return strtotime($this->end_time);
  16. }
  17. function getWinningArrayAttribute()
  18. {
  19. if (!empty($this->winning_numbers)) {
  20. $winning_numbers = explode(',', $this->winning_numbers);
  21. $winning_numbers = array_map('intval', $winning_numbers);
  22. $winning_numbers[] = array_sum($winning_numbers);
  23. return $winning_numbers;
  24. }
  25. return [];
  26. }
  27. function getKenoAttribute($value)
  28. {
  29. return json_decode($value, true);
  30. }
  31. function getAwardAttribute()
  32. {
  33. if (!empty($this->winning_numbers)) {
  34. $winning_numbers = explode(',', $this->winning_numbers);
  35. $winning_numbers = array_map('intval', $winning_numbers);
  36. return IssueService::award($winning_numbers);
  37. }
  38. return [];
  39. }
  40. const STATUS_DRAFT = 0;
  41. const STATUS_BETTING = 1;
  42. const STATUS_CLOSE = 2;
  43. const STATUS_DRAW = 3;
  44. const STATUS_FAIL = 4;
  45. public static $STATUS = [
  46. 0 => '草稿',
  47. 1 => '投注中',
  48. 2 => '封盘',
  49. 3 => '开奖',
  50. 4 => '失败',
  51. ];
  52. public static function getStatus($val = -1)
  53. {
  54. $array = self::$STATUS;
  55. if ($val < 0) {
  56. $arr = [];
  57. foreach ($array as $k => $v) {
  58. $item = [];
  59. $item['id'] = $k;
  60. $item['title'] = $v;
  61. $arr[] = $item;
  62. }
  63. return $arr;
  64. } else {
  65. return $array[$val];
  66. }
  67. }
  68. }