first commit

This commit is contained in:
Blizzard
2026-02-27 13:54:01 +08:00
commit fc585fa4df
127 changed files with 18548 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
package global
// 1. 勋章类型定义 (Medal Type) - 早安电台成就系统
const (
MedalEarlyBird7 = "EARLY_BIRD_7" // 早起达人 - 连续7天收听
MedalEarlyBird30 = "EARLY_BIRD_30" // 晨间守护者 - 连续30天收听
MedalEarlyBird100 = "EARLY_BIRD_100" // 百日坚持 - 连续100天收听
MedalExplorer = "EXPLORER" // 探索者 - 收听3个不同场景
MedalAllRounder = "ALL_ROUNDER" // 全能达人 - 收听全部场景
MedalFirstListen = "FIRST_LISTEN" // 初次体验 - 首次完整收听
)
// 2. 场景定义 (Scene) - 对应垂直领域方向
const (
SceneMorningCareer = "morning_career" // 硬核职场 - AI 商业机会
SceneMorningHealth = "morning_health" // 效率健康 - 数字健康
SceneMorningLife = "morning_life" // 极简生活 - 晨间管家
SceneMorningStudy = "morning_study" // 知识胶囊 - 备考进阶
)
// 3. 抓取源类型 (Source Type)
const (
SourceTypeGithub = "github" // GitHub API
SourceTypeProductH = "producthunt" // Product Hunt API
SourceTypeRSS = "rss" // RSS 订阅
SourceTypeHuggingF = "huggingface" // HuggingFace Trending
SourceTypeWebScrape = "webscrape" // 网页爬取
)
// 4. 音频状态 (Audio Status)
const (
AudioStatusDraft = 0 // 草稿
AudioStatusPublished = 1 // 已发布
AudioStatusOffline = 2 // 已下线
)
// 5. 抓取记录状态 (Crawl Status)
const (
CrawlStatusPending = "pending" // 待处理
CrawlStatusProcessed = "processed" // 已处理
CrawlStatusFailed = "failed" // 处理失败
)
+27
View File
@@ -0,0 +1,27 @@
package global
import (
"sundynix-go/config"
"sundynix-go/utils/timer"
"github.com/bsm/redislock"
"github.com/redis/go-redis/v9"
"github.com/spf13/viper"
"github.com/wechatpay-apiv3/wechatpay-go/core"
"go.uber.org/zap"
"golang.org/x/sync/singleflight"
"gorm.io/gorm"
)
// 全局变量 加载在内存中
var (
Viper *viper.Viper
Logger *zap.Logger
Config *config.Config
DB *gorm.DB
Redis redis.UniversalClient
Locker *redislock.Client // 分布式锁
ConcurrencyControl = &singleflight.Group{}
Timer timer.Timer = timer.NewTimerTask()
WxPayClient *core.Client
)
+35
View File
@@ -0,0 +1,35 @@
package global
import (
"sundynix-go/utils/uniqueid"
"time"
"gorm.io/gorm"
)
type BaseModel struct {
Id string `gorm:"size:50;primaryKey" json:"id"` // 主键ID
CreatedAt time.Time `json:"createdAt" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updatedAt" gorm:"autoCreateTime;autoUpdateTime"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` // 删除时间
CreatedAtStr string `json:"createdAtStr" gorm:"-"`
}
// BeforeCreate 定义一个钩子,在创建之前执行自动插入字段
func (model *BaseModel) BeforeCreate(db *gorm.DB) (err error) {
//生成主键的string uniqueid
db.Statement.SetColumn("id", uniqueid.GenerateId())
return
}
// BeforeUpdate 定义一个钩子,在更新之前执行自动更新字段
func (model *BaseModel) BeforeUpdate(db *gorm.DB) (err error) {
db.Statement.SetColumn("updated_at", time.Now())
return
}
// AfterFind 钩子,在查询之后执行
func (model *BaseModel) AfterFind(tx *gorm.DB) (err error) {
model.CreatedAtStr = model.CreatedAt.Format("2006-01-02 15:04:05")
return
}