feat/member #1

Merged
daniel.w merged 5 commits from feat/member into main 2024-08-02 02:20:17 +00:00
5 changed files with 91 additions and 5 deletions
Showing only changes of commit 7f25d329e4 - Show all commits

View File

@ -95,6 +95,8 @@ message UpdateUserInfoReq {
optional int64 birthday = 6;
optional VerifyType verify_type = 7;
optional AlarmType alarm_type = 8;
optional string role_id = 9;
optional MemberStatus status = 10;
}
message GetUIDByAccountReq {

View File

@ -2,8 +2,9 @@ package logic
import (
"context"
"member/gen_result/pb/member"
"member/internal/domain"
ers "member/internal/lib/error"
"member/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
@ -25,7 +26,16 @@ func NewUpdateUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Up
// UpdateUserInfo 更新 User Info
func (l *UpdateUserInfoLogic) UpdateUserInfo(in *member.UpdateUserInfoReq) (*member.Response, error) {
// todo: add your logic here and delete this line
return &member.Response{}, nil
err := l.svcCtx.UserModel.UpdateSome(l.ctx, in)
if err != nil {
return nil, ers.DBError(err.Error())
}
return &member.Response{
Status: &member.BaseResp{
Code: domain.CodeOk.ToString(),
Message: "success",
Error: "",
},
}, nil
}

View File

@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"fmt"
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
@ -32,7 +33,7 @@ func (m *defaultAccountModel) UpdateTokenByLoginID(ctx context.Context, account
accountAccountKey := fmt.Sprintf("%s%v", cacheAccountAccountPrefix, data.Account)
accountIdKey := fmt.Sprintf("%s%v", cacheAccountIdPrefix, data.Id)
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("update %s set `token` = ? where `id` = ?", m.table, accountRowsWithPlaceHolder)
query := fmt.Sprintf("update %s set `token` = ? where `id` = ?", m.table)
return conn.ExecCtx(ctx, query, token, data.Id)
}, accountAccountKey, accountIdKey)
return err

View File

@ -7,7 +7,9 @@ import (
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"member/gen_result/pb/member"
"strings"
"time"
)
var _ UserTableModel = (*customUserTableModel)(nil)
@ -21,6 +23,7 @@ type (
ListMembers(ctx context.Context, params *UserQueryParams) ([]*UserTable, error)
Count(ctx context.Context) (int64, error)
UpdateStatus(ctx context.Context, uid string, status int32) error
UpdateSome(ctx context.Context, newData *member.UpdateUserInfoReq) error
}
customUserTableModel struct {
@ -146,3 +149,72 @@ func (m *defaultUserTableModel) UpdateStatus(ctx context.Context, uid string, st
}, userTableIdKey, userTableUidKey)
return err
}
func (m *defaultUserTableModel) UpdateSome(ctx context.Context, newData *member.UpdateUserInfoReq) error {
data, err := m.FindOneByUid(ctx, newData.Uid)
if err != nil {
return err
}
// 初始化缓存键
userTableIdKey := fmt.Sprintf("%s%v", cacheUserTableIdPrefix, data.Id)
userTableUidKey := fmt.Sprintf("%s%v", cacheUserTableUidPrefix, data.Uid)
query := fmt.Sprintf("update %s set ", m.table)
var args []interface{}
var updates []string
if newData.VerifyType != nil {
updates = append(updates, "verify_type = ?")
args = append(args, *newData.VerifyType)
}
if newData.AlarmType != nil {
updates = append(updates, "alarm_type = ?")
args = append(args, *newData.AlarmType)
}
if newData.Status != nil {
updates = append(updates, "status = ?")
args = append(args, *newData.Status)
}
if newData.RoleId != nil {
updates = append(updates, "role_id = ?")
args = append(args, *newData.RoleId)
}
if newData.Language != nil {
updates = append(updates, "language = ?")
args = append(args, *newData.Language)
}
if newData.Currency != nil {
updates = append(updates, "currency = ?")
args = append(args, *newData.Currency)
}
if newData.NickName != nil {
updates = append(updates, "nick_name = ?")
args = append(args, *newData.NickName)
}
if newData.Gender != nil {
updates = append(updates, "gender = ?")
args = append(args, *newData.Gender)
}
if newData.Birthday != nil {
updates = append(updates, "birthday = ?")
args = append(args, *newData.Birthday)
}
if len(updates) == 0 {
return nil
}
update := time.Now().UTC().Unix()
updates = append(updates, "update_time = ?")
args = append(args, &update)
query += strings.Join(updates, ", ") + " where `id` = ?"
args = append(args, data.Id)
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
return conn.ExecCtx(ctx, query, args...)
}, userTableIdKey, userTableUidKey)
return err
}

View File

@ -1,12 +1,13 @@
package svc
import (
"github.com/zeromicro/go-zero/core/stores/redis"
"member/internal/config"
"member/internal/domain"
"member/internal/lib/required"
"member/internal/model"
"github.com/zeromicro/go-zero/core/stores/redis"
"github.com/bwmarrin/snowflake"
ers "member/internal/lib/error"