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

@ -4396,6 +4396,9 @@ type UpdateRequest struct {
Domain string `protobuf:"bytes,2,opt,name=Domain,json=domain,proto3" json:"Domain"` 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"` 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"` 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 unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
} }
@ -4458,6 +4461,27 @@ func (x *UpdateRequest) GetNickName() string {
return "" 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 { type Operator struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
ID uint32 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID"` 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" + "\x14WriteOffListResponse\x12\x14\n" +
"\x05total\x18\x01 \x01(\x03R\x05total\x12@\n" + "\x05total\x18\x01 \x01(\x03R\x05total\x12@\n" +
"\fwriteOffList\x18\x02 \x03(\v2\x1c.accountFiee.WriteOffRequestR\fwriteOffList\"\x10\n" + "\fwriteOffList\x18\x02 \x03(\v2\x1c.accountFiee.WriteOffRequestR\fwriteOffList\"\x10\n" +
"\x0eRemoveResponse\"o\n" + "\x0eRemoveResponse\"\xd1\x01\n" +
"\rUpdateRequest\x12\x0e\n" + "\rUpdateRequest\x12\x0e\n" +
"\x02ID\x18\x01 \x01(\x04R\x02ID\x12\x16\n" + "\x02ID\x18\x01 \x01(\x04R\x02ID\x12\x16\n" +
"\x06Domain\x18\x02 \x01(\tR\x06domain\x12\x1a\n" + "\x06Domain\x18\x02 \x01(\tR\x06domain\x12\x1a\n" +
"\bLanguage\x18\x03 \x01(\tR\blanguage\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" + "\bOperator\x12\x0e\n" +
"\x02ID\x18\x01 \x01(\rR\x02ID\x12\x12\n" + "\x02ID\x18\x01 \x01(\rR\x02ID\x12\x12\n" +
"\x04Name\x18\x02 \x01(\tR\x04Name\"\x82\x01\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 Domain = 2 [json_name = "domain"];
string Language = 3 [json_name = "language"]; string Language = 3 [json_name = "language"];
string NickName = 4 [json_name = "nickName"]; 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 { message Operator {

View File

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

View File

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

View File

@ -5,6 +5,10 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"strconv"
"strings"
"time"
account "github.com/fonchain_enterprise/micro-account/api/accountFiee" account "github.com/fonchain_enterprise/micro-account/api/accountFiee"
"github.com/fonchain_enterprise/micro-account/pkg/cache" "github.com/fonchain_enterprise/micro-account/pkg/cache"
"github.com/fonchain_enterprise/micro-account/pkg/common/redis_key" "github.com/fonchain_enterprise/micro-account/pkg/common/redis_key"
@ -15,9 +19,6 @@ import (
"github.com/mozillazg/go-pinyin" "github.com/mozillazg/go-pinyin"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
"gorm.io/plugin/soft_delete" "gorm.io/plugin/soft_delete"
"strconv"
"strings"
"time"
) )
type Extend struct { type Extend struct {
@ -52,6 +53,9 @@ type User struct {
Nickname string `gorm:"column:nickname;comment:昵称" json:"nickname"` Nickname string `gorm:"column:nickname;comment:昵称" json:"nickname"`
Language string `gorm:"column:language;comment:语言" json:"language"` Language string `gorm:"column:language;comment:语言" json:"language"`
SubscriberNumber string `gorm:"column:subscriber_number;comment:用户id" json:"subscriberNumber"` 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 ( const (

View File

@ -1128,17 +1128,78 @@ func (a *AccountFieeProvider) UpdateTelNum(_ context.Context, in *account.SendNe
return response, err return response, err
} }
func (a *AccountFieeProvider) Update(_ context.Context, in *account.UpdateRequest) (*account.UpdateResponse, error) { func (a *AccountFieeProvider) Update(_ context.Context, in *account.UpdateRequest) (*account.UpdateResponse, error) {
response := &account.UpdateResponse{} resp := &account.UpdateResponse{}
var user *model.User
if err := model.DB.First(&user, in.ID).Error; err != nil { db := model.DB
return response, errors.New(m.Not_Found)
} // ---------- 1⃣ Email 唯一校验 ----------
err := model.DB.Model(&model.User{}).Where("id = ?", in.ID).Updates(&model.User{Language: in.Language, Nickname: in.NickName}).Error 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 { if err != nil {
return nil, err return nil, err
} }
return response, nil if cnt > 0 {
return resp, errors.New(m.Email_Already_Exists)
}
}
// ---------- 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)
}
}
// ---------- 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) { func (a *AccountFieeProvider) SendCustomMsg(ctx context.Context, in *account.SendCustomMsgRequest) (*account.SendMsgStatusResponse, error) {
response := &account.SendMsgStatusResponse{} response := &account.SendMsgStatusResponse{}
var user *model.User var user *model.User