PcIssue.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 getAwardAttribute()
  48. {
  49. if (!empty($this->winning_numbers)) {
  50. $winning_numbers = explode(',', $this->winning_numbers);
  51. $winning_numbers = array_map('intval', $winning_numbers);
  52. return IssueService::award($winning_numbers);
  53. }
  54. return [];
  55. }
  56. public static function getStatus($val = -1)
  57. {
  58. $array = self::$STATUS;
  59. if ($val < 0) {
  60. $arr = [];
  61. foreach ($array as $k => $v) {
  62. $item = [];
  63. $item['id'] = $k;
  64. $item['title'] = $v;
  65. $arr[] = $item;
  66. }
  67. return $arr;
  68. } else {
  69. return $array[$val];
  70. }
  71. }
  72. }