Bet.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Builder;
  4. use Illuminate\Foundation\Auth\User as Authenticatable;
  5. use Illuminate\Notifications\Notifiable;
  6. use Laravel\Sanctum\HasApiTokens;
  7. /**
  8. * Bet
  9. * @mixin Builder
  10. * @method static Builder|static where($column, $operator = null, $value = null, $boolean = 'and')
  11. */
  12. class Bet extends Authenticatable
  13. {
  14. use HasApiTokens, Notifiable;
  15. protected $table = 'bets';
  16. // protected $hidden = ['created_at', 'updated_at'];
  17. protected $fillable = ['issue_no', 'keywords', 'amount', 'odds', 'status', 'profit', 'issue_id', 'member_id', 'user_id'];
  18. const STATUS_STAY = 1;
  19. const STATUS_SETTLED = 2;
  20. const STATUS_CANCEL = 3;
  21. public function user()
  22. {
  23. return $this->belongsTo(User::class, 'member_id', 'member_id');
  24. }
  25. public static $STATUS = [
  26. 1 => '待结算',
  27. 2 => '已结算',
  28. 3 => '取消',
  29. ];
  30. public static function getStatus($val = -1)
  31. {
  32. $array = self::$STATUS;
  33. if ($val < 0) {
  34. $arr = [];
  35. foreach ($array as $k => $v) {
  36. $item = [];
  37. $item['id'] = $k;
  38. $item['title'] = $v;
  39. $arr[] = $item;
  40. }
  41. return $arr;
  42. } else {
  43. return $array[$val];
  44. }
  45. }
  46. protected function getCreatedAtAttribute($value)
  47. {
  48. return \Carbon\Carbon::parse($value)->setTimezone('Asia/Shanghai')->format('Y-m-d H:i:s');
  49. }
  50. protected function getUpdatedAtAttribute($value)
  51. {
  52. return \Carbon\Carbon::parse($value)->setTimezone('Asia/Shanghai')->format('Y-m-d H:i:s');
  53. }
  54. // public function children()
  55. // {
  56. // return $this->hasMany(Menu::class, 'parent_id');
  57. // }
  58. // public function parent()
  59. // {
  60. // return $this->belongsTo(Menu::class, 'parent_id');
  61. // }
  62. }