Initial commit

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-23 11:07:42 +08:00
co-authored by Claude Opus 5.5
commit 7974a42301
633 changed files with 120248 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
package pubdef
// 卡类型
type CardTypeInt int32
// vip类型
type VipType int32
const (
VipTypeNone VipType = 0 + iota // 没卡
VipTypeMonth VipType = 1 // 月卡
VipTypeYear VipType = 2 // 年卡
)
var VipTypeNamedMap = map[VipType]string{
VipTypeNone: "无",
VipTypeMonth: "月卡",
VipTypeYear: "年卡",
}
type BannerInfo struct {
Img string `json:"img" bson:"img"` // banner图片
Text string `json:"text" bson:"text"` // banner文字类
BackgroundColor string `json:"backgroundColor" bson:"backgroundColor"` // banner背景图
SkipUrl string `json:"skipUrl" bson:"skipUrl"` // banner跳转地址
}
+125
View File
@@ -0,0 +1,125 @@
package pubdef
import (
"slices"
)
type IMedia interface {
GetID() int64
GetTitle() string
GetPrice() int64
GetCover() string
GetPublishID() int64
GetLocationType() LocationType
GetIsVIP() bool
GetIsDark() bool
GetCollectionIds() []int64
GetEpisodeIds() []int64
}
type DateCount struct {
Date string `json:"date" bson:"date"` // 日期: yyyy-MM-dd
Count int64 `json:"count" bson:"count"` // 数量
}
type DateCountList []DateCount
type MediaType = LocationType
type ContentType int32
const (
ContentTypeVideoLong ContentType = 1 // 长视频
ContentTypeVideoDsp ContentType = 2 // 短视频
)
type LocationType int32
const (
LocationTypeNone LocationType = 0 // 占位符,无意义
LocationTypeVideo LocationType = 1 // 视频
LocationTypeVideoLLD LocationType = 2 // 萝莉岛
LocationTypeCartoon LocationType = 3 // 动漫
LocationTypePost LocationType = 4 // 帖子
LocationTypeComment LocationType = 5 // 评论
LocationTypeCollection LocationType = 6 // 合集
LocationTypeComics LocationType = 7 // 漫画
LocationTypeNovel LocationType = 8 // 小说
LocationTypeVoiceNovel LocationType = 9 // 有声小说
LocationTypePhoto LocationType = 10 // 图集
LocationTypeGame LocationType = 11 // 黄游
LocationTypeShort LocationType = 12 // 短视频
)
func (s LocationType) String() string {
switch s {
case LocationTypeVideo:
return "长视频"
case LocationTypeVideoLLD:
return "萝莉岛"
case LocationTypeCartoon:
return "动漫"
case LocationTypePost:
return "动态"
case LocationTypeComment:
return "评论"
case LocationTypeCollection:
return "合集"
case LocationTypeComics:
return "漫画"
case LocationTypeNovel:
return "小说"
case LocationTypeVoiceNovel:
return "有声小说"
case LocationTypePhoto:
return "图集"
case LocationTypeGame:
return "黄游"
case LocationTypeShort:
return "短视频"
default:
return "未知"
}
}
func (s LocationType) HasIntersection(other ...LocationType) bool {
for _, v := range other {
if s == v {
return true
}
}
return false
}
// 哪些类型可以分配创作者收益, 目前是所有类型
func (s LocationType) CanDistributionWorkerIncome() bool {
return slices.Contains([]LocationType{
LocationTypeVideo,
LocationTypeVideoLLD,
LocationTypeCartoon,
LocationTypePost,
LocationTypeCollection,
LocationTypeComics,
LocationTypeNovel,
LocationTypePhoto,
LocationTypeGame,
}, s)
}
type MediaTagInfo struct {
Id int64 `json:"id"`
Name string `json:"name"`
}
type MediaTagInfoList []MediaTagInfo
func (s MediaTagInfoList) ToUniqueList() MediaTagInfoList {
var ret MediaTagInfoList
dict := make(map[int64]struct{})
for _, v := range s {
if _, ok := dict[v.Id]; !ok {
dict[v.Id] = struct{}{}
ret = append(ret, v)
}
}
return ret
}
+52
View File
@@ -0,0 +1,52 @@
package pubdef
import "videoweb/pub/common/maths"
// VipOrderStatus 订单状态
type VipOrderStatus int32
const (
VipOrderPending VipOrderStatus = 1 // 待支付
VipOrderSuccess VipOrderStatus = 2 // 支付成功
VipOrderFailed VipOrderStatus = 3 // 支付失败
)
func (s VipOrderStatus) Desc() string {
switch s {
case VipOrderPending:
return "待支付"
case VipOrderSuccess:
return "支付成功"
case VipOrderFailed:
return "支付失败"
}
return "未知"
}
// PayMode 支付方式
const (
PayModeAlipay = "alipay" // 支付宝
PayModeWechat = "wechat" // 微信
)
// SubmitVipOrderInfo 第三方下单成功后的返回信息
type SubmitVipOrderInfo struct {
TradeNo string
Oid string // 第三方订单号
PayUrl string // 支付链接
PayUrlMode string // 支付链接模式(webview/scheme)
PayChannel string // 支付渠道
PayRate string // 费率
}
// VipOrderCallbackParam 支付回调参数(标准化后)
type VipOrderCallbackParam struct {
TradeNo string // 本地订单号
Oid string // 第三方订单号
RealAmount int64 // 实际支付金额(分)
PaymentAt interface{} // 支付时间(time.Time)
}
func GetTrandNoWithUUID() string {
return AppNameZhifuUUID + maths.GenUUID()
}
+48
View File
@@ -0,0 +1,48 @@
package pubdef
import "fmt"
type Page struct {
PageNum int64 `form:"pageNum" json:"pageNum,omitempty"`
PageSize int64 `form:"pageSize" json:"pageSize,omitempty"`
}
const (
OutputDir = "../h5/templates/page/"
DateISO = "2006-01-02"
TimeISO = "2006-01-02 15:04:05"
AppId = 1043
AppName = "黄果短剧"
AppNameZhifu = "黄果短剧2"
AppNameZhifuUUID = "CZ-HGDJ2-"
DefaultChannelCode = "HGDL"
)
// TrackerAppId 数据上报 SDK / 服务端埋点共用的应用 ID
func TrackerAppId() string {
return fmt.Sprintf("JHA-%d", AppId)
}
const PageSize int64 = 36
func GetTotalPage(total int64, page int64) int64 {
totalPage := total / PageSize
if total%PageSize > 0 {
totalPage++
}
return totalPage
}
type SeoValue struct {
Title string `json:"title" bson:"webTitle"` // 网站SEO标题
Keyworld []string `json:"keyworld" bson:"webKeyworld"` // 网站SEO关键字
Description string `json:"description" bson:"webDescription"` // 网站SEO描述
}
type TranslationType int64
const (
TranslationTypeUrl TranslationType = 1 // URL模式
TranslationTypeSub TranslationType = 2 // 二级导航
TranslationTypeBottom TranslationType = 3 // 底部导航
)
+132
View File
@@ -0,0 +1,132 @@
package pubdef
import "strings"
type OSType string
const (
OSTypeNone OSType = ""
OSTypeIOS OSType = "ios"
OSTypeAndroid OSType = "android"
)
func (o OSType) String() string {
switch o {
case OSTypeIOS:
return string(OSTypeIOS)
case OSTypeAndroid:
return string(OSTypeAndroid)
default:
return string(OSTypeNone)
}
}
type SysType string
const (
ST_None SysType = ""
ST_IOS SysType = "ios"
ST_Android SysType = "android"
ST_H5 SysType = "h5"
ST_PC SysType = "pc"
ST_H5IOS SysType = "h5_ios"
ST_H5Android SysType = "h5_android"
ST_H5PC SysType = "h5_pc"
ST_Light SysType = "light"
ST_TG SysType = "tg"
)
func (s SysType) String() string {
return string(s)
}
func SysTypeFromString(s string) SysType {
s = strings.ToLower(strings.TrimSpace(s))
switch s {
case string(ST_IOS):
return ST_IOS
case string(ST_Android):
return ST_Android
case string(ST_H5):
return ST_H5
case string(ST_PC):
return ST_PC
case string(ST_H5IOS):
return ST_H5IOS
case string(ST_H5Android):
return ST_H5Android
case string(ST_H5PC):
return ST_H5PC
case string(ST_Light):
return ST_Light
case string(ST_TG):
return ST_TG
default:
return ST_None
}
}
func ParseOSType(sysType SysType, device string) OSType {
device = strings.ToLower(device)
switch sysType {
case ST_IOS, ST_H5IOS, ST_Light:
return OSTypeIOS
case ST_Android, ST_H5Android, ST_H5PC, ST_PC:
return OSTypeAndroid
case ST_H5, ST_TG:
if strings.Contains(device, "ios") || strings.Contains(device, "iphone") || strings.Contains(device, "apple") {
return OSTypeIOS
}
return OSTypeAndroid
default:
return OSTypeNone
}
}
// GetCenterType 获取统计中心系统类型和设备类型。
// sysType: android / ios;devType: h5 / ios / tg 或原始 device。
func GetCenterType(sysType SysType, device string) (sType string, dType string) {
sType = "ios"
dType = "h5"
//osType := ParseOSType(sysType, device)
//sType = osType.String()
//switch sysType {
//case ST_IOS:
// dType = "ios"
// if sType == "" {
// sType = "ios"
// }
//case ST_Android:
// dType = device
// if sType == "" {
// sType = "android"
// }
//case ST_H5IOS, ST_Light:
// dType = "h5"
// if sType == "" {
// sType = "ios"
// }
//case ST_H5Android, ST_H5PC, ST_H5, ST_PC:
// dType = "h5"
// if sType == "" {
// sType = "android"
// }
//case ST_TG:
// dType = "tg"
// if sType == "" {
// if strings.Contains(strings.ToLower(device), "ios") ||
// strings.Contains(strings.ToLower(device), "iphone") ||
// strings.Contains(strings.ToLower(device), "apple") {
// sType = "ios"
// } else {
// sType = "android"
// }
// }
//default:
// dType = device
// if sType == "" {
// sType = "android"
// }
//}
return
}
+99
View File
@@ -0,0 +1,99 @@
package pubdef
import (
"time"
)
// 机器人
const (
RobotId_Min = 9000
RobotId_Max = 10000
)
// CrawlerUserId 爬虫观看会话的虚拟用户 ID。
// 不对应任何真实用户;业务侧按 userId<=0 当作未登录,免费内容仍可看。
const CrawlerUserId int64 = -1
func IsCrawlerUser(userId int64) bool {
return userId == CrawlerUserId
}
// 性别
type Gender int32
const (
Gender_male Gender = 0 // 男
Gender_female Gender = 1 // 女
)
// 用户类型(身份)
type UserType int32
const (
UserTypeGuest UserType = 0 // 游客用户
UserTypeNormal UserType = 1 // 普通用户(已注册)
)
// UserTypeNone 兼容旧命名,等同游客
const UserTypeNone = UserTypeGuest
var UserTypeMap = map[UserType]string{
UserTypeGuest: "游客用户",
UserTypeNormal: "普通用户",
}
func (s UserType) String() string {
return UserTypeMap[s]
}
// 用户状态
type UserStatus int32
const (
UserStatusNormal UserStatus = 0 // 正常
UserStatusDisable UserStatus = 1 // 封禁
UserStatusSlient UserStatus = 2 // 禁言
)
var UserStatusMap = map[UserStatus]string{
UserStatusNormal: "正常",
UserStatusDisable: "封禁",
UserStatusSlient: "禁止登陆",
}
type LoginType int32
const (
LoginTypeDevice LoginType = 0 + iota // 设备登陆
LoginTypeAccount // 账号登陆
LoginTypeEmail // 邮箱登陆
)
type VipInfo struct {
CardId int64 `json:"cardId" bson:"cardId,omitempty"` // 会员卡ID
VipType VipType `json:"vipType" bson:"vipType,omitempty"` // VIP类型 0:没卡、1:月卡、2:年卡
VipExpire time.Time `json:"vipExpire" bson:"vipExpire,omitempty"` // 会员过期时间
CardName string `json:"cardName" bson:"cardName,omitempty"` // 会员卡名字
VipExpireInt int64 `json:"vipExpireInt" bson:"-"` // 会员过期时间
VipExpireStr string `json:"vipExpireStr" bson:"-"` // 会员过期时间
IsUpgrade bool `json:"isUpgrade" bson:"-"` // 是否可升级
}
func (vi *VipInfo) IsValid() bool {
return vi.VipType > VipTypeNone && vi.VipExpire.After(time.Now())
}
func (vi *VipInfo) ReSet() {
vi.CardId = 0
vi.VipType = VipTypeNone
vi.VipExpire = time.Now().AddDate(0, 0, -1)
vi.CardName = ""
}
func (vi *VipInfo) ToJson() VipInfo {
if !vi.IsValid() {
vi.ReSet()
}
vi.VipExpireInt = vi.VipExpire.Unix()
vi.VipExpireStr = vi.VipExpire.Format(TimeISO)
return *vi
}