2026-06-17 13:15:05 +08:00

129 lines
3.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package roomadmin
import (
"encoding/json"
"fmt"
"strconv"
"strings"
)
type listQuery struct {
Page int
PageSize int
Keyword string
Status string
RegionID int64
SortBy string
SortDirection string
}
type roomPinListQuery struct {
Keyword string
Page int
PageSize int
PinType string
RegionID int64
Status string
}
type robotRoomListQuery struct {
Page int
PageSize int
Status string
}
type createRobotRoomRequest struct {
OwnerRobotUserID flexibleJSONInt64 `json:"ownerRobotUserId"`
CandidateRobotUserIDs flexibleJSONInt64Slice `json:"candidateRobotUserIds"`
MinRobotCount int32 `json:"minRobotCount"`
MaxRobotCount int32 `json:"maxRobotCount"`
RoomName string `json:"roomName"`
RoomAvatar string `json:"roomAvatar"`
VisibleRegionID int64 `json:"visibleRegionId"`
GiftIDs []string `json:"giftIds"`
LuckyGiftIDs []string `json:"luckyGiftIds"`
NormalGiftIntervalMS int64 `json:"normalGiftIntervalMs"`
LuckyComboMin int64 `json:"luckyComboMin"`
LuckyComboMax int64 `json:"luckyComboMax"`
LuckyPauseMinMS int64 `json:"luckyPauseMinMs"`
LuckyPauseMaxMS int64 `json:"luckyPauseMaxMs"`
}
type flexibleJSONInt64 int64
type flexibleJSONInt64Slice []int64
func (v *flexibleJSONInt64) UnmarshalJSON(data []byte) error {
// 机器人用户 ID 来自 int64前端必须按字符串提交才能避开 JS 安全整数上限;这里同时兼容旧脚本传数字。
value, err := parseFlexibleJSONInt64(data)
if err != nil {
return err
}
*v = flexibleJSONInt64(value)
return nil
}
func (values *flexibleJSONInt64Slice) UnmarshalJSON(data []byte) error {
// JSON 数组逐项走同一套 int64 解析,避免候选机器人列表里混入浮点或科学计数法。
var raw []json.RawMessage
if err := json.Unmarshal(data, &raw); err != nil {
return err
}
out := make([]int64, 0, len(raw))
for _, item := range raw {
value, err := parseFlexibleJSONInt64(item)
if err != nil {
return err
}
out = append(out, value)
}
*values = out
return nil
}
func parseFlexibleJSONInt64(data []byte) (int64, error) {
raw := strings.TrimSpace(string(data))
if raw == "" || raw == "null" {
return 0, nil
}
if strings.HasPrefix(raw, "\"") {
var text string
if err := json.Unmarshal(data, &text); err != nil {
return 0, err
}
raw = strings.TrimSpace(text)
}
if raw == "" {
return 0, nil
}
if strings.ContainsAny(raw, ".eE") {
// ID 没有小数语义,拒绝 float/scientific notation避免 18 位 ID 被中间层改写精度。
return 0, fmt.Errorf("integer id must not be decimal")
}
return strconv.ParseInt(raw, 10, 64)
}
type createRoomPinRequest struct {
DurationDays int64 `json:"durationDays"`
ExpiresAtMS int64 `json:"expiresAtMs"`
PinType string `json:"pinType"`
PinnedAtMS int64 `json:"pinnedAtMs"`
RoomID string `json:"roomId"`
Weight int64 `json:"weight"`
}
type updateRoomRequest struct {
CoverURL *string `json:"coverUrl"`
CloseReason *string `json:"closeReason"`
Description *string `json:"description"`
Mode *string `json:"mode"`
Status *string `json:"status"`
Title *string `json:"title"`
VisibleRegionID *int64 `json:"visibleRegionId"`
}
type updateRoomConfigRequest struct {
AllowedSeatCounts []int32 `json:"allowedSeatCounts"`
DefaultSeatCount int32 `json:"defaultSeatCount"`
}