User.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace App\Models;
  3. // // 关键:导入正确的 Builder 类(Eloquent 构建器)
  4. // use Illuminate\Database\Eloquent\Builder;
  5. use Carbon\Carbon;
  6. /**
  7. * @property int $id
  8. * @property string $member_id
  9. * @property string $username
  10. * @property string $first_name
  11. * @property string $language
  12. * @property string $register_ip
  13. * @property integer $status
  14. * @property string $visitor_id
  15. * @property string $phone 用户手机号
  16. * @property string $admin_note
  17. * @property $last_active_time 最后活跃时间
  18. */
  19. class User extends BaseModel
  20. {
  21. protected $table = 'users';
  22. protected $fillable = ['usdt', 'is_banned', 'last_active_time', 'visitor_id', 'register_ip', 'status', 'admin_note', 'member_id', 'first_name',
  23. 'game_id', 'username', 'secret_key', 'secret_pass', 'language','user_code', 'agent_user_code','level'];
  24. protected $attributes = [
  25. 'language' => 'zh',
  26. ];
  27. protected $hidden = ['updated_at'];
  28. // public function newQuery($excludeDeleted = true): Builder
  29. // {
  30. // // 1. 获取原生 Eloquent 查询构建器
  31. // $query = parent::newQuery($excludeDeleted);
  32. // // 2. 强制清空当前连接的表前缀(从根源阻止拼接)
  33. // $this->getConnection()->setTablePrefix('');
  34. // // 3. 强制指定查询的表名为 la_operation(覆盖所有拼接逻辑)
  35. // $query->from('bot_users');
  36. // return $query;
  37. // }
  38. function getLastActiveTimeAttribute($value): string
  39. {
  40. if ($value > 0 && !is_numeric($value)) {
  41. return date('Y-m-d H:i', strtotime($value));
  42. }
  43. return "";
  44. }
  45. function getCreatedAtAttribute($value): string
  46. {
  47. return Carbon::parse($value)->setTimezone('Asia/Shanghai')->format('Y-m-d');
  48. }
  49. public function wallet()
  50. {
  51. return $this->belongsTo(Wallet::class, 'user_id', 'user_id');
  52. }
  53. public function level()
  54. {
  55. return $this->belongsTo(Level::class, 'level', 'level')->select('id', 'level', 'level_name','img','recharge');
  56. }
  57. public function agent()
  58. {
  59. return $this->belongsTo(User::class, 'agent_user_code', 'user_code')->select('id', 'user_code', 'account','first_name','member_id');
  60. }
  61. public function setLanguage($language): void
  62. {
  63. $this->language = $language;
  64. }
  65. public function getMemberId()
  66. {
  67. return $this->member_id;
  68. }
  69. public function getUsername()
  70. {
  71. return $this->username;
  72. }
  73. public function getFirstName()
  74. {
  75. return $this->first_name;
  76. }
  77. }