印度包网
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.1 KiB

1 year ago
package handler
import (
1 year ago
"errors"
1 year ago
"math/rand"
1 year ago
"server/call"
1 year ago
"server/common"
"server/db"
"server/modules/backend/values"
"server/modules/web/app"
"time"
"github.com/gin-gonic/gin"
1 year ago
"github.com/liangdas/mqant/log"
1 year ago
"gorm.io/gorm"
)
1 year ago
type LuckyCodeReq struct {
Type int `form:"type" ` // code类型
}
1 year ago
type LuckyCodeResp struct {
1 year ago
Configs []*common.ConfigTgRobot
Code int
1 year ago
}
func GetLuckyCode(c *gin.Context) {
a := app.NewApp(c)
defer func() {
a.ResponseB()
}()
1 year ago
req := &LuckyCodeReq{}
if !a.SB(req) {
return
}
log.Info("req:%v", req)
1 year ago
resp := &LuckyCodeResp{}
a.Data = resp
1 year ago
typ := req.Type
if req.Type != common.LuckyCodeTypeVip {
typ = common.LuckyCodeTypeNormal
}
1 year ago
date := time.Now().Format("20060102")
1 year ago
data := &common.ActivityLuckyCode{Date: date, Type: typ}
1 year ago
err := db.Mysql().Get(data)
resp.Code = data.Code
1 year ago
if errors.Is(err, gorm.ErrRecordNotFound) {
1 year ago
code := rand.Intn(90000) + 10000
1 year ago
db.Mysql().Create(&common.ActivityLuckyCode{Date: date, Code: code, Type: typ})
1 year ago
resp.Code = code
} else if err != nil {
a.Code = values.CodeRetry
return
}
1 year ago
resp.Configs = call.GetConfigTgRobot()
1 year ago
}