feat: finish all member func
This commit is contained in:
parent
5c98a03391
commit
7f25d329e4
|
@ -95,6 +95,8 @@ message UpdateUserInfoReq {
|
||||||
optional int64 birthday = 6;
|
optional int64 birthday = 6;
|
||||||
optional VerifyType verify_type = 7;
|
optional VerifyType verify_type = 7;
|
||||||
optional AlarmType alarm_type = 8;
|
optional AlarmType alarm_type = 8;
|
||||||
|
optional string role_id = 9;
|
||||||
|
optional MemberStatus status = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetUIDByAccountReq {
|
message GetUIDByAccountReq {
|
||||||
|
|
|
@ -2,8 +2,9 @@ package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"member/gen_result/pb/member"
|
"member/gen_result/pb/member"
|
||||||
|
"member/internal/domain"
|
||||||
|
ers "member/internal/lib/error"
|
||||||
"member/internal/svc"
|
"member/internal/svc"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
@ -25,7 +26,16 @@ func NewUpdateUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Up
|
||||||
|
|
||||||
// UpdateUserInfo 更新 User Info
|
// UpdateUserInfo 更新 User Info
|
||||||
func (l *UpdateUserInfoLogic) UpdateUserInfo(in *member.UpdateUserInfoReq) (*member.Response, error) {
|
func (l *UpdateUserInfoLogic) UpdateUserInfo(in *member.UpdateUserInfoReq) (*member.Response, error) {
|
||||||
// todo: add your logic here and delete this line
|
err := l.svcCtx.UserModel.UpdateSome(l.ctx, in)
|
||||||
|
if err != nil {
|
||||||
|
return nil, ers.DBError(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
return &member.Response{}, nil
|
return &member.Response{
|
||||||
|
Status: &member.BaseResp{
|
||||||
|
Code: domain.CodeOk.ToString(),
|
||||||
|
Message: "success",
|
||||||
|
Error: "",
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
"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)
|
accountAccountKey := fmt.Sprintf("%s%v", cacheAccountAccountPrefix, data.Account)
|
||||||
accountIdKey := fmt.Sprintf("%s%v", cacheAccountIdPrefix, data.Id)
|
accountIdKey := fmt.Sprintf("%s%v", cacheAccountIdPrefix, data.Id)
|
||||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
_, 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)
|
return conn.ExecCtx(ctx, query, token, data.Id)
|
||||||
}, accountAccountKey, accountIdKey)
|
}, accountAccountKey, accountIdKey)
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -7,7 +7,9 @@ import (
|
||||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
"member/gen_result/pb/member"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ UserTableModel = (*customUserTableModel)(nil)
|
var _ UserTableModel = (*customUserTableModel)(nil)
|
||||||
|
@ -21,6 +23,7 @@ type (
|
||||||
ListMembers(ctx context.Context, params *UserQueryParams) ([]*UserTable, error)
|
ListMembers(ctx context.Context, params *UserQueryParams) ([]*UserTable, error)
|
||||||
Count(ctx context.Context) (int64, error)
|
Count(ctx context.Context) (int64, error)
|
||||||
UpdateStatus(ctx context.Context, uid string, status int32) error
|
UpdateStatus(ctx context.Context, uid string, status int32) error
|
||||||
|
UpdateSome(ctx context.Context, newData *member.UpdateUserInfoReq) error
|
||||||
}
|
}
|
||||||
|
|
||||||
customUserTableModel struct {
|
customUserTableModel struct {
|
||||||
|
@ -146,3 +149,72 @@ func (m *defaultUserTableModel) UpdateStatus(ctx context.Context, uid string, st
|
||||||
}, userTableIdKey, userTableUidKey)
|
}, userTableIdKey, userTableUidKey)
|
||||||
return err
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package svc
|
package svc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
|
||||||
"member/internal/config"
|
"member/internal/config"
|
||||||
"member/internal/domain"
|
"member/internal/domain"
|
||||||
"member/internal/lib/required"
|
"member/internal/lib/required"
|
||||||
"member/internal/model"
|
"member/internal/model"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||||
|
|
||||||
"github.com/bwmarrin/snowflake"
|
"github.com/bwmarrin/snowflake"
|
||||||
|
|
||||||
ers "member/internal/lib/error"
|
ers "member/internal/lib/error"
|
||||||
|
|
Loading…
Reference in New Issue