2025_12_12_085132_update_to_users_table.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. return new class extends Migration
  6. {
  7. /**
  8. * Run the migrations.
  9. */
  10. public function up(): void
  11. {
  12. Schema::table('users', function (Blueprint $table) {
  13. $table->string('membership_level_code')
  14. ->default('silver') // 默认白银会员
  15. ->after('id')
  16. ->comment('会员等级编码,关联user_membership_levels表的code字段');
  17. // 交易密码(加密存储)
  18. $table->string('transaction_password', 255)
  19. ->nullable()
  20. ->after('password')
  21. ->comment('交易密码,加密存储');
  22. $table->string('mobile', 20)
  23. ->nullable()
  24. ->after('transaction_password')
  25. ->comment('手机号');
  26. // 手机号验证状态
  27. $table->tinyInteger('mobile_verified')
  28. ->default(0)
  29. ->after('mobile')
  30. ->comment('手机号是否验证:0=未验证,1=已验证');
  31. // 手机号验证时间
  32. $table->timestamp('mobile_verified_at')
  33. ->nullable()
  34. ->after('mobile_verified')
  35. ->comment('手机号验证时间');
  36. // 邀请码(唯一,用于邀请注册)
  37. $table->string('invite_code', 32)
  38. ->unique()
  39. ->nullable()
  40. ->after('transaction_password')
  41. ->comment('用户邀请码,唯一');
  42. // 直接上级(一级代理)
  43. $table->unsignedBigInteger('inviter_id_1')
  44. ->nullable()
  45. ->after('transaction_password')
  46. ->comment('一级邀请人ID');
  47. // 间接上级(二级代理)
  48. $table->unsignedBigInteger('inviter_id_2')
  49. ->nullable()
  50. ->after('inviter_id_1')
  51. ->comment('二级邀请人ID');
  52. // 间接上级(三级代理)
  53. $table->unsignedBigInteger('inviter_id_3')
  54. ->nullable()
  55. ->after('inviter_id_2')
  56. ->comment('三级邀请人ID');
  57. // 余额(decimal类型适合存储金额)
  58. $table->decimal('balance', 15, 4)
  59. ->default(0.00)
  60. ->after('invite_code')
  61. ->comment('用户余额');
  62. // 信用分(用于信用体系)
  63. $table->unsignedInteger('credit_score')
  64. ->default(100)
  65. ->after('balance')
  66. ->comment('信用分,默认100分');
  67. // 注册IP
  68. $table->string('register_ip', 45)
  69. ->nullable()
  70. ->after('credit_score')
  71. ->comment('注册IP地址');
  72. // 最后登录IP
  73. $table->string('last_login_ip', 45)
  74. ->nullable()
  75. ->after('register_ip')
  76. ->comment('最后登录IP地址');
  77. // 状态(1=正常,0=封禁)
  78. $table->tinyInteger('status')
  79. ->default(1)
  80. ->after('last_login_ip')
  81. ->comment('状态:1=正常,0=封禁');
  82. // 备注(管理员备注)
  83. $table->text('remark')
  84. ->nullable()
  85. ->after('status')
  86. ->comment('管理员备注信息');
  87. // 最后登录时间(如果还没有这个字段)
  88. if (!Schema::hasColumn('users', 'last_login_at')) {
  89. $table->timestamp('last_login_at')
  90. ->nullable()
  91. ->after('last_login_ip')
  92. ->comment('最后登录时间');
  93. }
  94. });
  95. }
  96. /**
  97. * Reverse the migrations.
  98. */
  99. public function down(): void
  100. {
  101. Schema::table('users', function (Blueprint $table) {
  102. //
  103. });
  104. }
  105. };