75 lines
1.9 KiB
Go
75 lines
1.9 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 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 *sale.StatusReq) (*sale.Response, error) {
|
|
var req validator.StatusValidator
|
|
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
|
return outResponse(utils.ErrorParams, msg), nil
|
|
}
|
|
|
|
adminInfo := utils.GetUserFromCtx(l.ctx)
|
|
if adminInfo.ID < utils.NumberOne {
|
|
return failResponse(utils.ErrorNoLoginInfo), nil
|
|
}
|
|
|
|
w := modelbase.Params{
|
|
Eq: map[string]string{"id": strconv.FormatInt(req.Id, 10)},
|
|
In: map[string][]string{
|
|
"status": {
|
|
strconv.Itoa(int(dao.SaleStatusApproved)),
|
|
strconv.Itoa(int(dao.SaleStatusDisabled)),
|
|
},
|
|
},
|
|
}
|
|
var info dao.SaleStatusUpdate
|
|
m := model.SaleModel{}.Init()
|
|
if err := m.GetOne(w, &info); err != nil {
|
|
l.Errorf("sale status get: %v", err)
|
|
return failResponse(utils.Fail), nil
|
|
}
|
|
if info.Id < utils.NumberOne {
|
|
return failResponse(utils.ErrorNotFund), nil
|
|
}
|
|
|
|
info.Status = uint8(req.Status)
|
|
info.Reason = req.Reason
|
|
info.AdminId = adminInfo.ID
|
|
info.AdminName = adminInfo.Name
|
|
|
|
if _, err := m.Edit(modelbase.Params{Eq: map[string]string{"id": strconv.FormatInt(req.Id, 10)}}, &info); err != nil {
|
|
l.Errorf("sale status edit: %v", err)
|
|
return failResponse(utils.Fail), nil
|
|
}
|
|
|
|
return okStringResponse(utils.StringEmpty), nil
|
|
}
|