67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
|
|
"lone-services/pkg/modelbase"
|
|
"lone-services/pkg/utils"
|
|
"lone-services/pkg/validate"
|
|
ad "lone-services/rpc/ad/pb"
|
|
"lone-services/services/ad/internal/dao"
|
|
"lone-services/services/ad/internal/model"
|
|
"lone-services/services/ad/internal/svc"
|
|
"lone-services/services/ad/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 *ad.StatusReq) (*ad.Response, error) {
|
|
var req validator.AdStatusValidator
|
|
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
|
return outResponse(utils.ErrorParams, msg), nil
|
|
}
|
|
|
|
w := modelbase.Params{Eq: map[string]string{"id": strconv.FormatInt(req.Id, 10)}}
|
|
var info dao.AdStatus
|
|
m := model.AdModel{}.Init()
|
|
if err := m.GetOne(w, &info); err != nil {
|
|
l.Errorf("ad status get: %v", err)
|
|
return failResponse(utils.Fail), nil
|
|
}
|
|
if info.Id < utils.NumberOne {
|
|
return failResponse(utils.ErrorNotFund), nil
|
|
}
|
|
|
|
adminInfo := utils.GetUserFromCtx(l.ctx)
|
|
if adminInfo.ID < utils.NumberOne {
|
|
return failResponse(utils.ErrorNoLoginInfo), nil
|
|
}
|
|
|
|
info.Reason = req.Reason
|
|
info.Status = uint8(req.Status)
|
|
info.AdminId = int(adminInfo.ID)
|
|
info.AdminName = adminInfo.Name
|
|
|
|
if _, err := m.Edit(w, &info); err != nil {
|
|
l.Errorf("ad status edit: %v", err)
|
|
return failResponse(utils.Fail), nil
|
|
}
|
|
|
|
return okResponse(nil), nil
|
|
}
|