feat: user items
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"user/internal/dao"
|
||||
"user/internal/model"
|
||||
"user/internal/svc"
|
||||
"user/user"
|
||||
"user/validator"
|
||||
|
||||
"pkg.local/log"
|
||||
"pkg.local/modelbase"
|
||||
"pkg.local/utils"
|
||||
validateService "pkg.local/validate"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UserItemsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUserItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserItemsLogic {
|
||||
return &UserItemsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserItemsLogic) UserItems(in *user.UserItemsReq) (*user.Response, error) {
|
||||
var v validator.UserItemsValidator
|
||||
if msg := validateService.ValidateFromProto(in, &v); msg != utils.StringEmpty {
|
||||
return outResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return failResponse(utils.ErrorNoLoginInfo), nil
|
||||
}
|
||||
|
||||
page := int(v.Page)
|
||||
size := int(v.Size)
|
||||
if page < modelbase.DefaultPage {
|
||||
page = modelbase.DefaultPage
|
||||
}
|
||||
if size < utils.NumberOne {
|
||||
size = modelbase.DefaultSize
|
||||
}
|
||||
|
||||
where := map[string]string{}
|
||||
if v.Mobile != utils.StringEmpty {
|
||||
mobile, cErr := utils.Crypto{}.AESEncryptECB(v.Mobile)
|
||||
if cErr != nil {
|
||||
log.Errorf("user items encrypt mobile: %v", cErr)
|
||||
return failResponse(utils.ErrorEncryptAesError), nil
|
||||
}
|
||||
where["mobile"] = mobile
|
||||
}
|
||||
|
||||
var list []dao.UserListRow
|
||||
result, err := model.UserModel{}.Init().Page(modelbase.Params{
|
||||
Eq: where,
|
||||
Order: "id DESC",
|
||||
Page: page,
|
||||
Size: size,
|
||||
}, &list)
|
||||
if err != nil {
|
||||
log.Errorf("user items: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
items := make([]dao.UserListItem, 0, len(list))
|
||||
for _, row := range list {
|
||||
headPortrait, _ := utils.BuildImageURL(row.Avatar).(string)
|
||||
items = append(items, dao.UserListItem{
|
||||
Id: row.Id,
|
||||
Username: row.Username,
|
||||
Nickname: row.Nickname,
|
||||
HeadPortrait: headPortrait,
|
||||
Mobile: utils.DecryptMobile(row.Mobile),
|
||||
OnTrialNum: row.OnTrialNum,
|
||||
Gender: row.Gender,
|
||||
Birthday: row.Birthday,
|
||||
CreatedAt: row.CreatedAt,
|
||||
UpdatedAt: row.UpdatedAt,
|
||||
})
|
||||
}
|
||||
|
||||
return okResponse(dao.UserItemsData{
|
||||
Count: result.Count,
|
||||
Items: items,
|
||||
}), nil
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"user/internal/model"
|
||||
"user/internal/svc"
|
||||
"user/user"
|
||||
"user/validator"
|
||||
|
||||
"pkg.local/log"
|
||||
"pkg.local/modelbase"
|
||||
"pkg.local/utils"
|
||||
validateService "pkg.local/validate"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UserStatusLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUserStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserStatusLogic {
|
||||
return &UserStatusLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserStatusLogic) UserStatus(in *user.UserStatusReq) (*user.Response, error) {
|
||||
var v validator.UserStatusValidator
|
||||
if msg := validateService.ValidateFromProto(in, &v); msg != utils.StringEmpty {
|
||||
return outResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return failResponse(utils.ErrorNoLoginInfo), nil
|
||||
}
|
||||
|
||||
_, err := model.UserModel{}.Init().Edit(modelbase.Params{
|
||||
Eq: map[string]string{
|
||||
"id": strconv.FormatInt(v.Id, utils.NumberTen),
|
||||
},
|
||||
}, map[string]interface{}{
|
||||
"status": v.Status,
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorf("user status: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
return okResponse(nil), nil
|
||||
}
|
||||
Reference in New Issue
Block a user