change layout
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lone-services/pkg/log"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
product "lone-services/rpc/product/pb"
|
||||
"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 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 := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return outResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
|
||||
if req.Status == uint32(dao.ProductStatusDisabled) && len(req.Reason) < 1 {
|
||||
return failResponse(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
|
||||
}
|
||||
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return failResponse(utils.ErrorNoLoginInfo), nil
|
||||
}
|
||||
|
||||
update := dao.ProductStatusUpdate{
|
||||
Status: uint8(req.Status),
|
||||
Reason: req.Reason,
|
||||
AdminName: adminInfo.Name,
|
||||
AdminId: int(adminInfo.ID),
|
||||
}
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user