This commit is contained in:
JNG 2025-12-16 19:50:31 +08:00
parent 7801b5f88d
commit 6663f8cea8
6 changed files with 137 additions and 38 deletions

View File

@ -4391,13 +4391,16 @@ func (*RemoveResponse) Descriptor() ([]byte, []int) {
}
type UpdateRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
ID uint64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID"` //ID
Domain string `protobuf:"bytes,2,opt,name=Domain,json=domain,proto3" json:"Domain"`
Language string `protobuf:"bytes,3,opt,name=Language,json=language,proto3" json:"Language"`
NickName string `protobuf:"bytes,4,opt,name=NickName,json=nickName,proto3" json:"NickName"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
state protoimpl.MessageState `protogen:"open.v1"`
ID uint64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID"` //ID
Domain string `protobuf:"bytes,2,opt,name=Domain,json=domain,proto3" json:"Domain"`
Language string `protobuf:"bytes,3,opt,name=Language,json=language,proto3" json:"Language"`
NickName string `protobuf:"bytes,4,opt,name=NickName,json=nickName,proto3" json:"NickName"`
Email string `protobuf:"bytes,5,opt,name=Email,json=email,proto3" json:"Email"`
AbroadTel string `protobuf:"bytes,6,opt,name=AbroadTel,json=abroadTel,proto3" json:"AbroadTel"`
AbroadTelAreaCode string `protobuf:"bytes,7,opt,name=AbroadTelAreaCode,json=abroadTelAreaCode,proto3" json:"AbroadTelAreaCode"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *UpdateRequest) Reset() {
@ -4458,6 +4461,27 @@ func (x *UpdateRequest) GetNickName() string {
return ""
}
func (x *UpdateRequest) GetEmail() string {
if x != nil {
return x.Email
}
return ""
}
func (x *UpdateRequest) GetAbroadTel() string {
if x != nil {
return x.AbroadTel
}
return ""
}
func (x *UpdateRequest) GetAbroadTelAreaCode() string {
if x != nil {
return x.AbroadTelAreaCode
}
return ""
}
type Operator struct {
state protoimpl.MessageState `protogen:"open.v1"`
ID uint32 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID"`
@ -10461,12 +10485,15 @@ const file_api_accountFiee_accountFiee_proto_rawDesc = "" +
"\x14WriteOffListResponse\x12\x14\n" +
"\x05total\x18\x01 \x01(\x03R\x05total\x12@\n" +
"\fwriteOffList\x18\x02 \x03(\v2\x1c.accountFiee.WriteOffRequestR\fwriteOffList\"\x10\n" +
"\x0eRemoveResponse\"o\n" +
"\x0eRemoveResponse\"\xd1\x01\n" +
"\rUpdateRequest\x12\x0e\n" +
"\x02ID\x18\x01 \x01(\x04R\x02ID\x12\x16\n" +
"\x06Domain\x18\x02 \x01(\tR\x06domain\x12\x1a\n" +
"\bLanguage\x18\x03 \x01(\tR\blanguage\x12\x1a\n" +
"\bNickName\x18\x04 \x01(\tR\bnickName\".\n" +
"\bNickName\x18\x04 \x01(\tR\bnickName\x12\x14\n" +
"\x05Email\x18\x05 \x01(\tR\x05email\x12\x1c\n" +
"\tAbroadTel\x18\x06 \x01(\tR\tabroadTel\x12,\n" +
"\x11AbroadTelAreaCode\x18\a \x01(\tR\x11abroadTelAreaCode\".\n" +
"\bOperator\x12\x0e\n" +
"\x02ID\x18\x01 \x01(\rR\x02ID\x12\x12\n" +
"\x04Name\x18\x02 \x01(\tR\x04Name\"\x82\x01\n" +

View File

@ -541,6 +541,9 @@ message UpdateRequest {
string Domain = 2 [json_name = "domain"];
string Language = 3 [json_name = "language"];
string NickName = 4 [json_name = "nickName"];
string Email = 5 [json_name = "email"];
string AbroadTel = 6 [json_name = "abroadTel"];
string AbroadTelAreaCode = 7 [json_name = "abroadTelAreaCode"];
}
message Operator {

View File

@ -51,6 +51,8 @@ const (
IdNum_Need_RealName = "身份证校验需要您的真实姓名"
EmailCreateWrong = "邮箱创建失败"
AccountDoesNotExist = "账号不存在"
Email_Already_Exists = "邮箱已存在"
Tel_Already_Exists = "国际手机号已存在"
)
const (

View File

@ -29,6 +29,8 @@ func migration() {
AddColumn(&User{}, "nickname")
AddColumn(&User{}, "language")
AddColumn(&User{}, "subscriber_number")
AddColumn(&User{}, "abroad_tel")
AddColumn(&User{}, "abroad_tel_area_code")
AddColumn(&RealName{}, "id_number")
AddColumn(&RealName{}, "date_of_birth")
}

View File

@ -5,6 +5,10 @@ import (
"encoding/json"
"errors"
"fmt"
"strconv"
"strings"
"time"
account "github.com/fonchain_enterprise/micro-account/api/accountFiee"
"github.com/fonchain_enterprise/micro-account/pkg/cache"
"github.com/fonchain_enterprise/micro-account/pkg/common/redis_key"
@ -15,9 +19,6 @@ import (
"github.com/mozillazg/go-pinyin"
"golang.org/x/crypto/bcrypt"
"gorm.io/plugin/soft_delete"
"strconv"
"strings"
"time"
)
type Extend struct {
@ -34,24 +35,27 @@ type Operator struct {
// User 用户模型
type User struct {
ID uint `gorm:"primarykey"`
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at;type:int(11)" json:"deletedAt"`
Domain *string `gorm:"size:50"`
SubNum string `gorm:"column:sub_num;comment:用户编号" json:"subNum"`
TelNum string `gorm:"column:tel_num;comment:" json:"telNum"`
TelAreaCode string `gorm:"column:tel_area_code;comment:手机区号" json:"telAreaCode"`
Status int `gorm:"column:status;comment:状态 1:未实名 2:审核中 3:审核失败 4:审核通过" json:"status"`
RegistrationTime string `gorm:"column:registration_time;comment:注册时间" json:"registrationTime"`
AuditTime string `gorm:"column:audit_time;comment:审核时间" json:"auditTime"`
RealNameID *uint
RealName *RealName `gorm:"foreignKey:RealNameID" json:"RealName"`
PasswordDigest string
NotPassRemarks string `gorm:"column:not_pass_remarks;comment:不通过备注" json:"notPassRemarks"`
Nickname string `gorm:"column:nickname;comment:昵称" json:"nickname"`
Language string `gorm:"column:language;comment:语言" json:"language"`
SubscriberNumber string `gorm:"column:subscriber_number;comment:用户id" json:"subscriberNumber"`
ID uint `gorm:"primarykey"`
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at;type:int(11)" json:"deletedAt"`
Domain *string `gorm:"size:50"`
SubNum string `gorm:"column:sub_num;comment:用户编号" json:"subNum"`
TelNum string `gorm:"column:tel_num;comment:" json:"telNum"`
TelAreaCode string `gorm:"column:tel_area_code;comment:手机区号" json:"telAreaCode"`
Status int `gorm:"column:status;comment:状态 1:未实名 2:审核中 3:审核失败 4:审核通过" json:"status"`
RegistrationTime string `gorm:"column:registration_time;comment:注册时间" json:"registrationTime"`
AuditTime string `gorm:"column:audit_time;comment:审核时间" json:"auditTime"`
RealNameID *uint
RealName *RealName `gorm:"foreignKey:RealNameID" json:"RealName"`
PasswordDigest string
NotPassRemarks string `gorm:"column:not_pass_remarks;comment:不通过备注" json:"notPassRemarks"`
Nickname string `gorm:"column:nickname;comment:昵称" json:"nickname"`
Language string `gorm:"column:language;comment:语言" json:"language"`
SubscriberNumber string `gorm:"column:subscriber_number;comment:用户id" json:"subscriberNumber"`
Email string `gorm:"column:email;comment:邮箱" json:"email"`
AbroadTel string `gorm:"column:abroad_tel;comment:国外手机号" json:"abroadTel"`
AbroadTelAreaCode string `gorm:"column:abroad_tel_area_code;comment:国外手机区号" json:"abroadTelAreaCode"`
}
const (

View File

@ -1128,17 +1128,78 @@ func (a *AccountFieeProvider) UpdateTelNum(_ context.Context, in *account.SendNe
return response, err
}
func (a *AccountFieeProvider) Update(_ context.Context, in *account.UpdateRequest) (*account.UpdateResponse, error) {
response := &account.UpdateResponse{}
var user *model.User
if err := model.DB.First(&user, in.ID).Error; err != nil {
return response, errors.New(m.Not_Found)
resp := &account.UpdateResponse{}
db := model.DB
// ---------- 1⃣ Email 唯一校验 ----------
if in.Email != "" {
var cnt int64
err := db.Model(&model.User{}).
Where("email = ? AND id <> ?", in.Email, in.ID).
Count(&cnt).Error
if err != nil {
return nil, err
}
if cnt > 0 {
return resp, errors.New(m.Email_Already_Exists)
}
}
err := model.DB.Model(&model.User{}).Where("id = ?", in.ID).Updates(&model.User{Language: in.Language, Nickname: in.NickName}).Error
if err != nil {
return nil, err
// ---------- 2⃣ 国际手机号唯一校验 ----------
if in.AbroadTel != "" && in.AbroadTelAreaCode != "" {
var cnt int64
err := db.Model(&model.User{}).
Where("abroad_tel = ? AND abroad_tel_area_code = ? AND id <> ?",
in.AbroadTel, in.AbroadTelAreaCode, in.ID).
Count(&cnt).Error
if err != nil {
return nil, err
}
if cnt > 0 {
return resp, errors.New(m.Tel_Already_Exists)
}
}
return response, nil
// ---------- 3⃣ 构建更新字段 ----------
updates := map[string]interface{}{}
if in.NickName != "" {
updates["nickname"] = in.NickName
}
if in.Email != "" {
updates["email"] = in.Email
}
if in.Language != "" {
updates["language"] = in.Language
}
if in.AbroadTel != "" {
updates["abroad_tel"] = in.AbroadTel
}
if in.AbroadTelAreaCode != "" {
updates["abroad_tel_area_code"] = in.AbroadTelAreaCode
}
if len(updates) == 0 {
return resp, nil
}
// ---------- 4⃣ 执行更新 ----------
tx := db.Model(&model.User{}).
Where("id = ?", in.ID).
Updates(updates)
if tx.Error != nil {
return nil, tx.Error
}
if tx.RowsAffected == 0 {
return resp, errors.New(m.Not_Found)
}
return resp, nil
}
func (a *AccountFieeProvider) SendCustomMsg(ctx context.Context, in *account.SendCustomMsgRequest) (*account.SendMsgStatusResponse, error) {
response := &account.SendMsgStatusResponse{}
var user *model.User