2025-12-26 03:51:24 +08:00
|
|
|
package service
|
|
|
|
|
|
|
|
|
|
import (
|
2025-12-26 23:46:10 +08:00
|
|
|
"blazing/common/data"
|
2025-12-26 03:51:24 +08:00
|
|
|
"blazing/cool"
|
|
|
|
|
"blazing/modules/config/model"
|
2025-12-26 20:38:08 +08:00
|
|
|
"context"
|
2025-12-26 23:46:10 +08:00
|
|
|
"encoding/json"
|
2025-12-26 20:38:08 +08:00
|
|
|
|
2025-12-26 23:46:10 +08:00
|
|
|
"github.com/gogf/gf/v2/database/gdb"
|
2025-12-26 20:38:08 +08:00
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
2025-12-26 23:46:10 +08:00
|
|
|
"github.com/gogf/gf/v2/util/grand"
|
2025-12-26 03:51:24 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type ShinyService struct {
|
|
|
|
|
*cool.Service
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewShinyService() *ShinyService {
|
|
|
|
|
return &ShinyService{
|
|
|
|
|
&cool.Service{
|
|
|
|
|
Model: model.NewColorfulSkin(),
|
2025-12-26 20:38:08 +08:00
|
|
|
InsertParam: func(ctx context.Context) g.MapStrAny {
|
|
|
|
|
admin := cool.GetAdmin(ctx)
|
|
|
|
|
userId := admin.UserId
|
|
|
|
|
return g.MapStrAny{
|
|
|
|
|
"author": userId,
|
|
|
|
|
}
|
|
|
|
|
},
|
2025-12-26 03:51:24 +08:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-12-26 23:46:10 +08:00
|
|
|
|
|
|
|
|
func (s *ShinyService) Args(id uint32) *data.GlowFilter {
|
|
|
|
|
var ret []model.ColorfulSkin
|
|
|
|
|
|
|
|
|
|
// 执行 Raw SQL 并扫描返回值
|
|
|
|
|
cool.DBM(s.Model).Wheref(`bind_elf_ids @> ?::jsonb`, id).Wheref(`jsonb_typeof(bind_elf_ids) = ?`, "array").Cache(gdb.CacheOption{
|
|
|
|
|
// Duration: time.Hour,
|
|
|
|
|
|
|
|
|
|
Force: false,
|
|
|
|
|
}).Scan(&ret)
|
|
|
|
|
|
|
|
|
|
for _, v := range ret {
|
|
|
|
|
//print(v.ID)
|
|
|
|
|
|
|
|
|
|
id := v.ID
|
|
|
|
|
|
|
|
|
|
if grand.Meet(int(v.ElfProbability), 1000) {
|
|
|
|
|
var t data.GlowFilter
|
|
|
|
|
|
|
|
|
|
r := json.Unmarshal([]byte(v.Color), &t)
|
|
|
|
|
if r == nil {
|
|
|
|
|
m := cool.DBM(s.Model).Where("id", id)
|
|
|
|
|
m.Increment("refresh_count", 1)
|
|
|
|
|
return &t
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|