85 lines
2.2 KiB
Go
85 lines
2.2 KiB
Go
package analysisstorelogic
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
|
|
"lone-services/pkg/modelbase"
|
|
"lone-services/pkg/utils"
|
|
"lone-services/pkg/validate"
|
|
analysis "lone-services/rpc/analysis/pb"
|
|
"lone-services/services/analysis/internal/dao"
|
|
"lone-services/services/analysis/internal/logic/common"
|
|
"lone-services/services/analysis/internal/model"
|
|
"lone-services/services/analysis/internal/svc"
|
|
"lone-services/services/analysis/validator"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type StoreUserInfoLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewStoreUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StoreUserInfoLogic {
|
|
return &StoreUserInfoLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *StoreUserInfoLogic) StoreUserInfo(in *analysis.StoreUserInfoReq) (*analysis.Response, error) {
|
|
var req validator.StoreUserInfoValidator
|
|
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
|
return common.OutResponse(utils.ErrorParams, msg), nil
|
|
}
|
|
|
|
storeId, _, fail := common.RequireStoreId(l.ctx)
|
|
if fail != nil {
|
|
return fail, nil
|
|
}
|
|
|
|
var remark dao.UserRemark
|
|
err := model.UserRemarkModel{}.Init().GetOne(modelbase.Params{
|
|
Eq: map[string]string{
|
|
"user_id": strconv.FormatInt(req.UserId, utils.NumberTen),
|
|
"store_id": strconv.FormatInt(storeId, utils.NumberTen),
|
|
},
|
|
}, &remark)
|
|
if err != nil {
|
|
l.Errorf("store user info remark: %v", err)
|
|
return common.FailResponse(utils.Fail), nil
|
|
}
|
|
|
|
var tagRows []dao.UserImageTag
|
|
err = model.UserImageTagModel{}.Init().Items(modelbase.Params{
|
|
Eq: map[string]string{
|
|
"user_id": strconv.FormatInt(req.UserId, utils.NumberTen),
|
|
"store_id": strconv.FormatInt(storeId, utils.NumberTen),
|
|
"status": strconv.Itoa(int(dao.StatusEnabled)),
|
|
},
|
|
}, &tagRows)
|
|
if err != nil {
|
|
l.Errorf("store user info tags: %v", err)
|
|
return common.FailResponse(utils.Fail), nil
|
|
}
|
|
|
|
tags := make([]string, 0, len(tagRows))
|
|
for _, row := range tagRows {
|
|
if row.Tag != utils.StringEmpty {
|
|
tags = append(tags, row.Tag)
|
|
}
|
|
}
|
|
|
|
return common.OkResponse(dao.StoreUserRemark{
|
|
UserId: req.UserId,
|
|
Name: remark.Name,
|
|
Gender: int(remark.Gender),
|
|
Birthday: dateOnly(remark.Birthday),
|
|
Tag: tags,
|
|
}), nil
|
|
}
|