PcIssue.php 2.4 KB

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