User.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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_member_id','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. ->select('id', 'user_id', 'member_id', 'address', 'available_balance');
  53. }
  54. public function setLanguage($language): void
  55. {
  56. $this->language = $language;
  57. }
  58. public function getMemberId()
  59. {
  60. return $this->member_id;
  61. }
  62. public function getUsername()
  63. {
  64. return $this->username;
  65. }
  66. public function getFirstName()
  67. {
  68. return $this->first_name;
  69. }
  70. }