User.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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', 'game_id', 'username', 'secret_key', 'secret_pass', 'language'];
  23. protected $attributes = [
  24. 'language' => 'zh',
  25. ];
  26. protected $hidden = ['updated_at'];
  27. // public function newQuery($excludeDeleted = true): Builder
  28. // {
  29. // // 1. 获取原生 Eloquent 查询构建器
  30. // $query = parent::newQuery($excludeDeleted);
  31. // // 2. 强制清空当前连接的表前缀(从根源阻止拼接)
  32. // $this->getConnection()->setTablePrefix('');
  33. // // 3. 强制指定查询的表名为 la_operation(覆盖所有拼接逻辑)
  34. // $query->from('bot_users');
  35. // return $query;
  36. // }
  37. function getLastActiveTimeAttribute($value): string
  38. {
  39. if ($value > 0 && !is_numeric($value)) {
  40. return date('Y-m-d H:i', strtotime($value));
  41. }
  42. return "";
  43. }
  44. function getCreatedAtAttribute($value): string
  45. {
  46. return Carbon::parse($value)->setTimezone('Asia/Shanghai')->format('Y-m-d');
  47. }
  48. public function wallet()
  49. {
  50. return $this->belongsTo(Wallet::class, 'user_id', 'user_id')
  51. ->select('id', 'user_id', 'member_id', 'address', 'available_balance');
  52. }
  53. public function setLanguage($language): void
  54. {
  55. $this->language = $language;
  56. }
  57. public function getMemberId()
  58. {
  59. return $this->member_id;
  60. }
  61. public function getUsername()
  62. {
  63. return $this->username;
  64. }
  65. public function getFirstName()
  66. {
  67. return $this->first_name;
  68. }
  69. }