f458e00431
CI / changes (push) Successful in 38s
CI / ad (push) Successful in 46s
CI / admin (push) Successful in 47s
CI / bff (push) Successful in 3s
CI / chore (push) Successful in 49s
CI / equipment (push) Successful in 52s
CI / express (push) Successful in 48s
CI / factory (push) Successful in 48s
CI / message (push) Failing after 5s
CI / payment (push) Successful in 42s
CI / product (push) Successful in 48s
CI / record (push) Successful in 50s
CI / sale (push) Successful in 51s
CI / task (push) Successful in 47s
CI / user (push) Successful in 48s
CI / wecom (push) Successful in 46s
104 lines
2.4 KiB
Go
104 lines
2.4 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"lone-services/pkg/modelbase"
|
|
"lone-services/pkg/utils"
|
|
"lone-services/services/equipment/internal/dao"
|
|
"lone-services/services/equipment/internal/model"
|
|
"lone-services/services/equipment/validator"
|
|
"strconv"
|
|
"time"
|
|
|
|
"lone-services/rpc/equipment/pb"
|
|
"lone-services/services/equipment/internal/svc"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type ApiBindExpiryLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
BaseLogic
|
|
}
|
|
|
|
func NewApiBindExpiryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiBindExpiryLogic {
|
|
return &ApiBindExpiryLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *ApiBindExpiryLogic) ApiBindExpiry(in *equipment.ApiBindExpiryRequest) (*equipment.Response, error) {
|
|
var v validator.BindExpiryValidator
|
|
if fail := l.checkParams(in, &v); fail != nil {
|
|
return fail, nil
|
|
}
|
|
adminInfo := utils.GetUserFromCtx(l.ctx)
|
|
if adminInfo.ID < utils.NumberOne {
|
|
return l.fail(utils.ErrorNoLoginInfo)
|
|
}
|
|
|
|
var info dao.BindExpiry
|
|
w := modelbase.Params{
|
|
Eq: map[string]string{
|
|
"host_code": v.HostCode,
|
|
"user_id": strconv.FormatInt(adminInfo.ID, utils.NumberTen),
|
|
"status": utils.StringStatusOk},
|
|
}
|
|
|
|
modelObj := model.BindModel{}.Init()
|
|
err := modelObj.GetOne(w, &info)
|
|
if err != nil {
|
|
l.Logger.Error(err)
|
|
return l.fail(utils.Fail)
|
|
}
|
|
if info.Id < utils.NumberOne {
|
|
return l.fail(utils.SetError(utils.ErrorNotFund, "没有找到数据或没有绑定用户"))
|
|
}
|
|
|
|
if len(info.ExpiryTime) > utils.NumberOne {
|
|
return l.ok(info.ExpiryTime)
|
|
}
|
|
|
|
ww := modelbase.Params{
|
|
Order: "id desc",
|
|
Eq: map[string]string{
|
|
"host_code": v.HostCode,
|
|
"user_id": strconv.FormatInt(adminInfo.ID, utils.NumberTen),
|
|
"status": utils.StatusFailString},
|
|
}
|
|
|
|
var info2 dao.BindExpiry
|
|
err = modelObj.GetOne(ww, &info2)
|
|
if err != nil {
|
|
l.Logger.Error(err)
|
|
return l.fail(utils.Fail)
|
|
}
|
|
|
|
if info2.Id < utils.NumberOne {
|
|
if v.Type == utils.NumberOne {
|
|
info.ExpiryTime = "9999-12-31"
|
|
} else {
|
|
now := time.Now()
|
|
oneYearLater := now.AddDate(1, 0, 0)
|
|
info.ExpiryTime = oneYearLater.Format(time.DateOnly)
|
|
}
|
|
} else {
|
|
info.ExpiryTime = info2.ExpiryTime
|
|
}
|
|
|
|
w = modelbase.Params{
|
|
Eq: map[string]string{"id": strconv.FormatInt(info.Id, utils.NumberTen)},
|
|
}
|
|
_, err = modelObj.Edit(w, &info)
|
|
if err != nil {
|
|
l.Logger.Error(err)
|
|
return l.fail(utils.Fail)
|
|
}
|
|
|
|
return l.ok(info.ExpiryTime)
|
|
}
|