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