97 lines
2.3 KiB
Go
97 lines
2.3 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
|
|
"lone-services/pkg/modelbase"
|
|
"lone-services/pkg/utils"
|
|
"lone-services/pkg/validate"
|
|
user "lone-services/rpc/user/pb"
|
|
"lone-services/services/user/internal/dao"
|
|
"lone-services/services/user/internal/model"
|
|
"lone-services/services/user/internal/svc"
|
|
"lone-services/services/user/validator"
|
|
|
|
"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 := validate.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 {
|
|
l.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 {
|
|
l.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,
|
|
Status: row.Status,
|
|
CreatedAt: row.CreatedAt,
|
|
UpdatedAt: row.UpdatedAt,
|
|
})
|
|
}
|
|
|
|
return okResponse(dao.UserItemsData{
|
|
Count: result.Count,
|
|
Items: items,
|
|
}), nil
|
|
}
|