Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 25ba002da2 |
33
pkg/rpc/holiday.go
Normal file
33
pkg/rpc/holiday.go
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package rpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 节假日相关RPC
|
||||||
|
type Holiday struct{}
|
||||||
|
|
||||||
|
// 判断某个日期是否是节假日
|
||||||
|
func (h *Holiday) IsHoliday(date time.Time) (*bool, error) {
|
||||||
|
body := map[string]any{
|
||||||
|
"date": date.Format(time.DateOnly),
|
||||||
|
}
|
||||||
|
result := &Result[bool]{}
|
||||||
|
if err := GetRequest().Send("holiday.is_holiday", body, result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if result.Code != 0 {
|
||||||
|
return nil, fmt.Errorf("%s", result.Message)
|
||||||
|
}
|
||||||
|
return &result.Data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var holiday *Holiday
|
||||||
|
|
||||||
|
func GetHoliday() *Holiday {
|
||||||
|
if holiday == nil {
|
||||||
|
holiday = &Holiday{}
|
||||||
|
}
|
||||||
|
return holiday
|
||||||
|
}
|
||||||
31
pkg/rpc/system.go
Normal file
31
pkg/rpc/system.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package rpc
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
// 系统相关RPC
|
||||||
|
type System struct{}
|
||||||
|
|
||||||
|
// 获取系统位置
|
||||||
|
func (s *System) GetSystemLocation() (*SystemLocation, error) {
|
||||||
|
body := map[string]any{
|
||||||
|
"key": "system_location",
|
||||||
|
}
|
||||||
|
result := &Result[SystemLocation]{}
|
||||||
|
if err := GetRequest().Send("system.get_config", body, result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if result.Code != 0 {
|
||||||
|
return nil, fmt.Errorf("%s", result.Message)
|
||||||
|
}
|
||||||
|
return &result.Data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var system *System
|
||||||
|
|
||||||
|
// 获取系统相关RPC
|
||||||
|
func GetSystem() *System {
|
||||||
|
if system == nil {
|
||||||
|
system = &System{}
|
||||||
|
}
|
||||||
|
return system
|
||||||
|
}
|
||||||
@@ -153,3 +153,18 @@ type AutomationTask struct {
|
|||||||
ConditionList []AutomationCondition `json:"condition_list"` // 条件列表
|
ConditionList []AutomationCondition `json:"condition_list"` // 条件列表
|
||||||
ActionList []AutomationAction `json:"action_list"` // 动作列表
|
ActionList []AutomationAction `json:"action_list"` // 动作列表
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 系统位置
|
||||||
|
type SystemLocation struct {
|
||||||
|
Longitude float64 `json:"longitude,string"` // 经度
|
||||||
|
Latitude float64 `json:"latitude,string"` // 维度
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用户详情
|
||||||
|
type UserDetail struct {
|
||||||
|
Mobile *string `json:"mobile,omitempty"` // 手机号
|
||||||
|
Email *string `json:"email,omitempty"` // 邮箱
|
||||||
|
Nickname *string `json:"nickname,omitempty"` // 昵称
|
||||||
|
QQ *string `json:"qq,omitempty"` // QQ
|
||||||
|
Status uint8 `json:"status"` // 状态
|
||||||
|
}
|
||||||
|
|||||||
32
pkg/rpc/user.go
Normal file
32
pkg/rpc/user.go
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package rpc
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
// 用户相关RPC
|
||||||
|
type User struct{}
|
||||||
|
|
||||||
|
// 获取用户详情
|
||||||
|
func (u *User) GetDetail(userId uint32) (*UserDetail, error) {
|
||||||
|
body := map[string]any{
|
||||||
|
"user_id": userId,
|
||||||
|
"field_list": []string{"mobile", "email", "nickname", "qq", "status"},
|
||||||
|
}
|
||||||
|
result := &Result[UserDetail]{}
|
||||||
|
if err := GetRequest().Send("user.get_detail", body, result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if result.Code != 0 {
|
||||||
|
return nil, fmt.Errorf("%s", result.Message)
|
||||||
|
}
|
||||||
|
return &result.Data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var user *User
|
||||||
|
|
||||||
|
// 获取用户相关RPC
|
||||||
|
func GetUser() *User {
|
||||||
|
if user == nil {
|
||||||
|
user = &User{}
|
||||||
|
}
|
||||||
|
return user
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user