PcIssue.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. ];
  18. public static $STATUS = [
  19. 0 => '草稿',
  20. 1 => '投注中',
  21. 2 => '封盘',
  22. 3 => '开奖',
  23. 4 => '失败',
  24. ];
  25. public static function getWhere($search = []): array
  26. {
  27. $where = [];
  28. if (isset($search['issue_no']) && !empty($search['issue_no'])) {
  29. $where[] = ['issue_no', '=', $search['issue_no']];
  30. }
  31. return $where;
  32. }
  33. function getEndTimestampAttribute()
  34. {
  35. return strtotime($this->end_time);
  36. }
  37. function getWinningArrayAttribute()
  38. {
  39. if (!empty($this->winning_numbers)) {
  40. $winning_numbers = explode(',', $this->winning_numbers);
  41. $winning_numbers = array_map('intval', $winning_numbers);
  42. $winning_numbers[] = array_sum($winning_numbers);
  43. return $winning_numbers;
  44. }
  45. return [];
  46. }
  47. function getKenoAttribute($value)
  48. {
  49. return json_decode($value, true);
  50. }
  51. function getAwardAttribute()
  52. {
  53. if (!empty($this->winning_numbers)) {
  54. $winning_numbers = explode(',', $this->winning_numbers);
  55. $winning_numbers = array_map('intval', $winning_numbers);
  56. return IssueService::award($winning_numbers);
  57. }
  58. return [];
  59. }
  60. public static function getStatus($val = -1)
  61. {
  62. $array = self::$STATUS;
  63. if ($val < 0) {
  64. $arr = [];
  65. foreach ($array as $k => $v) {
  66. $item = [];
  67. $item['id'] = $k;
  68. $item['title'] = $v;
  69. $arr[] = $item;
  70. }
  71. return $arr;
  72. } else {
  73. return $array[$val];
  74. }
  75. }
  76. }