Files
lone-services/services/order/internal/logic/webAddressInfoLogic.go
T
2026-08-25 08:58:22 +08:00

63 lines
1.6 KiB
Go

package logic
import (
"context"
"lone-services/pkg/modelbase"
"lone-services/pkg/utils"
"lone-services/services/order/internal/dao"
"lone-services/services/order/internal/model"
"lone-services/services/order/validator"
"strconv"
"lone-services/rpc/order/pb"
"lone-services/services/order/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type WebAddressInfoLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
BaseLogic
}
func NewWebAddressInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebAddressInfoLogic {
return &WebAddressInfoLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *WebAddressInfoLogic) WebAddressInfo(in *order.IdAndTypeRequest) (*order.Response, error) {
var v validator.AddressDefValidator
if fail := l.checkParams(in, &v); fail != nil {
return fail, nil
}
adminInfo := utils.GetUserFromCtx(l.ctx)
if adminInfo.ID < utils.NumberOne {
return l.fail(utils.ErrorNoLoginInfo)
}
var info dao.WebAddressInfo
w := modelbase.Params{
Order: "`default` asc, `status` desc",
Not: map[string]string{"status": strconv.Itoa(utils.StatusDel)},
Eq: map[string]string{
"id": strconv.FormatInt(in.Id, utils.NumberTen),
"target_id": strconv.FormatInt(adminInfo.ID, utils.NumberTen),
"type": strconv.Itoa(int(in.Type))},
}
err := model.AddressModel{}.Init().GetOne(w, &info)
if err != nil {
l.Logger.Error(err)
return l.fail(utils.ErrorNotFund)
}
mobile, aErr := utils.DecryptPhone(info.Mobile)
if aErr == nil {
info.Mobile = mobile
}
return l.ok(info)
}