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

70 lines
1.3 KiB
Go

/**
* @Author: jager
* @Email: lhj168os@gmail.com
* @File: almanac
* @Date: 2022/1/6 6:13 下午
* @package: almanac
* @Version: v1.0.0
*
* @Description:
*
*/
package almanac
import (
"github.com/gin-gonic/gin"
"github.com/jageros/hawox/astro"
"github.com/jageros/hawox/errcode"
"github.com/jageros/hawox/httpx"
"idata/internal/apity"
"idata/internal/consts"
"idata/internal/service/user"
"idata/internal/types"
"strconv"
"strings"
"time"
)
func Almanac(ctx *gin.Context) {
uid, ok := httpx.DecodeUrlVal(ctx, "uid")
if !ok {
return
}
var opened bool
err := user.OperateSync(uid, func(u types.RWUser) {
opened = u.ApiCanReq(apity.Astro)
if opened && !u.IsVip() {
u.SetScore(u.Score() - 1)
}
})
if err != nil {
httpx.ErrInterrupt(ctx, errcode.WithErrcode(1, err))
return
}
if !opened {
httpx.ErrInterrupt(ctx, errcode.New(1, "未获得此Api权限"))
return
}
date, ok := httpx.DecodeUrlVal(ctx, "date")
if !ok || date == "" {
date = time.Now().Format(consts.DateFormat)
}
strs := strings.Split(date, "_")
var hour = -1
if len(strs) >= 2 {
h, err := strconv.Atoi(strs[1])
if err == nil {
hour = h
}
}
dd := astro.GetDate(strs[0])
data, err := dd.Map(hour)
if err != nil {
httpx.ErrInterrupt(ctx, errcode.WithErrcode(2, err))
return
}
httpx.PkgMsgWrite(ctx, data)
}