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.

87 lines
1.6 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"
"strconv"
"strings"
"time"
)
func Almanac(ctx *gin.Context) {
if !user.Auth(ctx, apity.Almanac) {
return
}
date := ctx.Query("date")
if 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])
if dd == nil {
httpx.ErrInterrupt(ctx, errcode.InvalidParam)
return
}
data, err := dd.Map(hour)
if err != nil {
httpx.ErrInterrupt(ctx, errcode.WithErrcode(2, err))
return
}
httpx.PkgMsgWrite(ctx, data)
}
func Horoscope(ctx *gin.Context) {
if !user.Auth(ctx, apity.Almanac) {
return
}
tm := ctx.Query("time")
if tm == "" {
tm = time.Now().Format(consts.DateFormat)
}
strs := strings.Split(tm, "_")
if len(strs) < 2 {
httpx.ErrInterrupt(ctx, errcode.New(1, "日期时辰格式错误"))
return
}
h, err := strconv.Atoi(strs[1])
if err != nil {
httpx.ErrInterrupt(ctx, errcode.New(1, "时辰错误"))
return
}
dd := astro.GetDate(strs[0])
if dd == nil {
httpx.ErrInterrupt(ctx, errcode.New(2, "日期错误"))
return
}
ew := dd.NewEightWord(h)
data := map[string]interface{}{
"eight_word": ew.Word(),
}
httpx.PkgMsgWrite(ctx, data)
}