62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"lone-services/pkg/modelbase"
|
|
"lone-services/pkg/utils"
|
|
"lone-services/pkg/validate"
|
|
product "lone-services/rpc/product/pb"
|
|
"lone-services/services/product/internal/apply"
|
|
"lone-services/services/product/internal/dao"
|
|
"lone-services/services/product/internal/model"
|
|
"lone-services/services/product/internal/svc"
|
|
"lone-services/services/product/validator"
|
|
"strconv"
|
|
|
|
"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 *product.InfoReq) (*product.Response, error) {
|
|
var req validator.ProductInfoValidator
|
|
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
|
return outResponse(utils.ErrorParams, msg), nil
|
|
}
|
|
|
|
var info dao.ProductInfo
|
|
err := model.ProductModel{}.Init().GetOne(modelbase.Params{
|
|
Eq: map[string]string{"id": strconv.FormatInt(req.Id, 10)},
|
|
}, &info)
|
|
if err != nil {
|
|
l.Errorf("product info: %v", err)
|
|
return failResponse(utils.Fail), nil
|
|
}
|
|
if info.Id < 1 {
|
|
return failResponse(utils.ErrorNotFund), nil
|
|
}
|
|
|
|
adminInfo := utils.GetUserFromCtx(l.ctx)
|
|
if adminInfo.ID < utils.NumberOne {
|
|
return failResponse(utils.ErrorNoLoginInfo), nil
|
|
}
|
|
adminId := int(adminInfo.ID)
|
|
if applyData, err := apply.Get(l.ctx, adminId, info.Id); err == nil {
|
|
info.Edit = applyData.Status
|
|
}
|
|
|
|
return okResponse(utils.StructToJson(toProductItem(info))), nil
|
|
}
|