76 lines
1.7 KiB
Go
76 lines
1.7 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
|
|
"product/internal/dao"
|
|
"product/internal/model"
|
|
"product/internal/svc"
|
|
"product/product"
|
|
"product/validator"
|
|
|
|
"pkg.local/log"
|
|
"pkg.local/modelbase"
|
|
"pkg.local/utils"
|
|
validateService "pkg.local/validate"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type StatusLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StatusLogic {
|
|
return &StatusLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *StatusLogic) Status(in *product.StatusReq) (*product.Response, error) {
|
|
var req validator.ProductStatusValidator
|
|
if msg := validateService.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
|
return outResponse(utils.ErrorParams, msg), nil
|
|
}
|
|
|
|
if req.Status == uint32(dao.ProductStatusDisabled) && len(req.Reason) < 1 {
|
|
return failErr(utils.ErrorReasonParams), nil
|
|
}
|
|
|
|
var info dao.ProductCheckExist
|
|
w := modelbase.Params{
|
|
Eq: map[string]string{
|
|
"id": strconv.FormatInt(req.Id, 10),
|
|
"verify_status": strconv.Itoa(int(dao.VerifyStatusPass)),
|
|
},
|
|
}
|
|
m := model.ProductModel{}.Init()
|
|
err := m.GetOne(w, &info)
|
|
if err != nil {
|
|
log.Errorf("product status get: %v", err)
|
|
return failResponse(utils.Fail), nil
|
|
}
|
|
if info.Id < 1 {
|
|
return failResponse(utils.ErrorNotFund), nil
|
|
}
|
|
|
|
// 管理员信息后续从 ctx / metadata 取
|
|
update := dao.ProductStatusUpdate{
|
|
Status: uint8(req.Status),
|
|
Reason: req.Reason,
|
|
AdminName: "",
|
|
AdminId: 0,
|
|
}
|
|
if _, err = m.Edit(w, &update); err != nil {
|
|
log.Errorf("product status edit: %v", err)
|
|
return failResponse(utils.Fail), nil
|
|
}
|
|
|
|
return okResponse(utils.StringEmpty), nil
|
|
}
|