PcIssue.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. function getEndTimestampAttribute()
  26. {
  27. return strtotime($this->end_time);
  28. }
  29. function getWinningArrayAttribute()
  30. {
  31. if (!empty($this->winning_numbers)) {
  32. $winning_numbers = explode(',', $this->winning_numbers);
  33. $winning_numbers = array_map('intval', $winning_numbers);
  34. $winning_numbers[] = array_sum($winning_numbers);
  35. return $winning_numbers;
  36. }
  37. return [];
  38. }
  39. function getAwardAttribute()
  40. {
  41. if (!empty($this->winning_numbers)) {
  42. $winning_numbers = explode(',', $this->winning_numbers);
  43. $winning_numbers = array_map('intval', $winning_numbers);
  44. return IssueService::award($winning_numbers);
  45. }
  46. return [];
  47. }
  48. public static function getStatus($val = -1)
  49. {
  50. $array = self::$STATUS;
  51. if ($val < 0) {
  52. $arr = [];
  53. foreach ($array as $k => $v) {
  54. $item = [];
  55. $item['id'] = $k;
  56. $item['title'] = $v;
  57. $arr[] = $item;
  58. }
  59. return $arr;
  60. } else {
  61. return $array[$val];
  62. }
  63. }
  64. }