101 lines
2.4 KiB
Go
101 lines
2.4 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
|
|
}
|
|
|
|
params := modelbase.Params{
|
|
Order: "id DESC",
|
|
Page: page,
|
|
Size: size,
|
|
}
|
|
if v.Mobile != utils.StringEmpty {
|
|
phone := utils.GetSearchPhone(v.Mobile)
|
|
if len(phone) > utils.NumberZero {
|
|
params.Like = map[string]string{
|
|
"mobile LIKE ? ": "%%" + phone + "%%",
|
|
}
|
|
}
|
|
}
|
|
|
|
var list []dao.UserListRow
|
|
result, err := model.UserModel{}.Init().Page(params, &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)
|
|
mobile := row.Mobile
|
|
if plain, dErr := utils.DecryptPhone(row.Mobile); dErr == nil {
|
|
mobile = utils.DecryptPhoneReplace(plain)
|
|
}
|
|
items = append(items, dao.UserListItem{
|
|
Id: row.Id,
|
|
Username: row.Username,
|
|
Nickname: row.Nickname,
|
|
HeadPortrait: headPortrait,
|
|
Mobile: mobile,
|
|
OriginMobile: 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
|
|
}
|