29 lines
1.2 KiB
Go
29 lines
1.2 KiB
Go
package business
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
"kra/internal/biz/business"
|
|
)
|
|
|
|
func approvedGamesAvailable(db *gorm.DB) (bool, error) {
|
|
for _, table := range []string{"tab_game", "tab_promote", "tab_promote_apply"} {
|
|
available, err := businessTableAvailable(db, table)
|
|
if err != nil || !available {
|
|
return available, err
|
|
}
|
|
}
|
|
return true, nil
|
|
}
|
|
|
|
// 游戏可选范围来自可见渠道的有效申请,不受统计时是否包含下级的开关影响。
|
|
// 用平台和 ID 配对,避免同号游戏或其他商务的申请扩大可选范围。
|
|
func approvedGamesQuery(db *gorm.DB, viewer business.UserScope, sources []string) *gorm.DB {
|
|
promotes := ledgerBasePromotes(db, business.LedgerScope{Viewer: viewer, IncludeSub: true, Unrestricted: viewer.All}, business.LedgerFilter{Sources: sources}, "approved_p").Select("approved_p.source_db,approved_p.id")
|
|
applications := db.Table("tab_promote_apply a").Select("a.source_db,a.game_id").Where("a.status=1").Where("(a.source_db,a.promote_id) IN (?)", promotes)
|
|
q := db.Table("tab_game g").Where("(g.source_db,g.id) IN (?)", applications)
|
|
if len(sources) > 0 {
|
|
q = q.Where("g.source_db IN ?", sources)
|
|
}
|
|
return q
|
|
}
|