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.
39 lines
758 B
39 lines
758 B
|
1 year ago
|
package handler
|
||
|
|
|
||
|
|
import (
|
||
|
|
"math/rand"
|
||
|
|
"server/common"
|
||
|
|
"server/db"
|
||
|
|
"server/modules/backend/values"
|
||
|
|
"server/modules/web/app"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
"gorm.io/gorm"
|
||
|
|
)
|
||
|
|
|
||
|
|
type LuckyCodeResp struct {
|
||
|
|
Code int
|
||
|
|
}
|
||
|
|
|
||
|
|
func GetLuckyCode(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.ResponseB()
|
||
|
|
}()
|
||
|
|
resp := &LuckyCodeResp{}
|
||
|
|
a.Data = resp
|
||
|
|
date := time.Now().Format("20060102")
|
||
|
|
data := &common.ActivityLuckyCode{Date: date}
|
||
|
|
err := db.Mysql().Get(data)
|
||
|
|
resp.Code = data.Code
|
||
|
|
if err == gorm.ErrRecordNotFound {
|
||
|
|
code := rand.Intn(90000) + 10000
|
||
|
|
db.Mysql().Create(&common.ActivityLuckyCode{Date: date, Code: code, Type: common.LuckyCodeTypeNormal})
|
||
|
|
resp.Code = code
|
||
|
|
} else if err != nil {
|
||
|
|
a.Code = values.CodeRetry
|
||
|
|
return
|
||
|
|
}
|
||
|
|
}
|