52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
|
|
"lone-services/pkg/modelbase"
|
|
"lone-services/pkg/utils"
|
|
"lone-services/pkg/validate"
|
|
sale "lone-services/rpc/sale/pb"
|
|
"lone-services/services/sale/internal/dao"
|
|
"lone-services/services/sale/internal/model"
|
|
"lone-services/services/sale/internal/svc"
|
|
"lone-services/services/sale/validator"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type InfoLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoLogic {
|
|
return &InfoLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *InfoLogic) Info(in *sale.InfoReq) (*sale.Response, error) {
|
|
var req validator.InfoValidator
|
|
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
|
return outResponse(utils.ErrorParams, msg), nil
|
|
}
|
|
|
|
var info dao.SaleInfo
|
|
if err := (model.SaleModel{}.Init().GetOne(modelbase.Params{
|
|
Eq: map[string]string{"id": strconv.FormatInt(req.Id, 10)},
|
|
}, &info)); err != nil {
|
|
l.Errorf("sale info: %v", err)
|
|
return failResponse(utils.Fail), nil
|
|
}
|
|
if info.Id < utils.NumberOne {
|
|
return failResponse(utils.ErrorNotFund), nil
|
|
}
|
|
maskSaleMobile(&info)
|
|
return okResponse(info), nil
|
|
}
|