49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"lone-services/pkg/redis"
|
|
"lone-services/pkg/utils"
|
|
"lone-services/services/equipment/internal/dao"
|
|
"strconv"
|
|
"time"
|
|
|
|
"lone-services/rpc/equipment/pb"
|
|
"lone-services/services/equipment/internal/svc"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type AuthorizationCodeLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
BaseLogic
|
|
}
|
|
|
|
func NewAuthorizationCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AuthorizationCodeLogic {
|
|
return &AuthorizationCodeLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *AuthorizationCodeLogic) AuthorizationCode(in *equipment.EmptyRequest) (*equipment.Response, error) {
|
|
adminInfo := utils.GetUserFromCtx(l.ctx)
|
|
if adminInfo.ID < utils.NumberOne {
|
|
return l.fail(utils.ErrorNoLoginInfo)
|
|
}
|
|
|
|
key := dao.CodeName + strconv.FormatInt(adminInfo.StoreId, utils.NumberTen)
|
|
|
|
code := utils.RandNumber(utils.NumberSix)
|
|
out := utils.GetConfigInt("code.out-time")
|
|
_, err := redis.Client.Set(l.ctx, key, code, time.Duration(out)*time.Second).Result()
|
|
if err != nil {
|
|
l.Logger.Error(err)
|
|
return l.fail(utils.Fail)
|
|
}
|
|
return l.ok(code)
|
|
}
|