config.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. package service
  2. import (
  3. "fmt"
  4. "sort"
  5. "strconv"
  6. "strings"
  7. "crazy-fox-backend-api/config"
  8. "crazy-fox-backend-api/global"
  9. "crazy-fox-backend-api/model"
  10. "crazy-fox-backend-api/plugin/nsq"
  11. "crazy-fox-backend-api/repo"
  12. "crazy-fox-backend-api/repo/okeys"
  13. "crazy-fox-backend-api/utils"
  14. "crazy-fox-backend-api/utils/fileop"
  15. "github.com/dablelv/go-huge-util/conv"
  16. jsoniter "github.com/json-iterator/go"
  17. "github.com/pkg/errors"
  18. "golang.org/x/sync/errgroup"
  19. )
  20. // configService 配置模块服务
  21. type configService struct{}
  22. // GetGeneralConf 获取公共配置
  23. func (This *configService) GetGeneralConf() model.ResGeneralConf {
  24. actListMap := Props.MakeActSkinMap()
  25. var eg errgroup.Group
  26. var generalConf model.ResGeneralConf
  27. // 遍历活动型道具类型列表
  28. generalConf.NormalProps = Props.BuildPropsConf(&config.NormalPropsList, actListMap)
  29. // 遍历功能型道具类型列表
  30. generalConf.SimpleProps = Props.BuildPropsConf(&config.SimplePropsList, actListMap)
  31. // 获取用户数数分组
  32. eg.Go(func() error {
  33. generalConf.SsGroup = Config.BuildSsGroup()
  34. return nil
  35. })
  36. // 获取老虎机权重分组
  37. eg.Go(func() error {
  38. generalConf.SlotWeightGroup = Config.BuildSlotWeightGroup()
  39. return nil
  40. })
  41. // 获取老虎机权重分组
  42. eg.Go(func() error {
  43. generalConf.VersionList = Config.getVersions()
  44. return nil
  45. })
  46. _ = eg.Wait()
  47. return generalConf
  48. }
  49. // SaveJson 保存Json文件
  50. func (This *configService) SaveJson(data any, key string) error {
  51. filename := fmt.Sprintf("%s%d.json", key, utils.CurTimestamp())
  52. // 保存文件名到数据库
  53. oneStaticConf, err := repo.Config.GetOneStaticConf(key)
  54. oneStaticConf.Path = filename
  55. if err != nil {
  56. // insert
  57. oneStaticConf.Config = key
  58. if _, err = repo.Insert(&oneStaticConf); err != nil {
  59. return errors.WithStack(err)
  60. }
  61. } else {
  62. // update
  63. if err = repo.Update(&oneStaticConf, "config"); err != nil {
  64. return errors.WithStack(err)
  65. }
  66. }
  67. repo.HSetCache(okeys.StaticConfig(), key, filename)
  68. // 保存文件数据到文件
  69. json, err := jsoniter.Marshal(data)
  70. if err != nil {
  71. return errors.WithStack(err)
  72. }
  73. dirPath := utils.BuildAP("config")
  74. return fileop.FileSave(json, dirPath, filename)
  75. }
  76. // GetBasicConf 获取基础配置
  77. func (This *configService) GetBasicConf(it model.ItemTitle) (string, error) {
  78. if it.Item == "" || it.Title == "" {
  79. return "", errors.New("参数不能为空字符串")
  80. }
  81. basicConf, _ := repo.Config.GetBasicConf(it)
  82. return basicConf.Content, nil
  83. }
  84. // UpdateBasicConf 更新基础配置
  85. func (This *configService) UpdateBasicConf(updateConf model.TBasicConfig) error {
  86. // update
  87. if updateConf.Id != 0 {
  88. if err := repo.Config.UpdateBasicConf(updateConf); err != nil {
  89. return errors.WithStack(err)
  90. }
  91. } else {
  92. basicConf, err := repo.Config.GetBasicConf(updateConf.ItemTitle)
  93. if err != nil {
  94. // 配置不存在 Insert
  95. if _, err = repo.Insert(&updateConf); err != nil {
  96. return errors.WithStack(err)
  97. }
  98. } else {
  99. // update
  100. updateConf.Id = basicConf.Id
  101. if err = repo.Config.UpdateBasicConf(updateConf); err != nil {
  102. return errors.WithStack(err)
  103. }
  104. }
  105. }
  106. // 缓存
  107. repo.HSetCache(okeys.BasicConfigKey(), updateConf.ItemTitle.String(), updateConf.Content)
  108. if err := This.updateConJson(); err != nil {
  109. return err
  110. }
  111. return nil
  112. }
  113. // GetSystemConf 获取系统配置
  114. func (This *configService) GetSystemConf(it model.ItemTitle) (string, error) {
  115. if it.Item == "" || it.Title == "" {
  116. return "", errors.New("参数不能为空字符串")
  117. }
  118. basicConf, _ := repo.Config.GetSystemConf(it)
  119. return basicConf.Content, nil
  120. }
  121. // UpdateSystemConf 更新系统配置
  122. func (This *configService) UpdateSystemConf(updateConf model.TSystemConfig) error {
  123. // update
  124. if updateConf.Id != 0 {
  125. if err := repo.Config.UpdateSystemConf(updateConf); err != nil {
  126. return errors.WithStack(err)
  127. }
  128. } else {
  129. systemConf, err := repo.Config.GetSystemConf(updateConf.ItemTitle)
  130. if err != nil {
  131. // 配置不存在 Insert
  132. if _, err = repo.Insert(&updateConf); err != nil {
  133. return errors.WithStack(err)
  134. }
  135. } else {
  136. // update
  137. updateConf.Id = systemConf.Id
  138. if err = repo.Config.UpdateSystemConf(updateConf); err != nil {
  139. return errors.WithStack(err)
  140. }
  141. }
  142. }
  143. // 缓存
  144. repo.HSetCache(okeys.SystemConfig(), updateConf.ItemTitle.String(), updateConf.Content)
  145. return nil
  146. }
  147. func (This *configService) updateConJson() error {
  148. basicConfList := repo.Search[model.TBasicConfig]("")
  149. mapItem := []string{"android", "ios", "getSpinAd", "onoff"}
  150. jsonMap := make(map[string]map[string]any, len(mapItem))
  151. epItem := []string{"Url", "BeginnerReward", "Game"}
  152. epTitle := []string{"fbInviteSpin", "initialSpins", "repairMoney"}
  153. json := make(map[string]any, len(basicConfList)-len(mapItem))
  154. for _, basicConfig := range basicConfList {
  155. if utils.InSlice(basicConfig.Item, mapItem) {
  156. if _, OK := jsonMap[basicConfig.Item]; OK {
  157. jsonMap[basicConfig.Item][basicConfig.Title] = basicConfig.Content
  158. } else {
  159. jsonMap[basicConfig.Item] = map[string]any{basicConfig.Title: basicConfig.Content}
  160. }
  161. } else if basicConfig.Title == "repairMoney" {
  162. json["initialCoins"] = basicConfig.Content
  163. } else if utils.InSlice(basicConfig.Item, epItem) || utils.InSlice(basicConfig.Title, epTitle) {
  164. json[basicConfig.Title] = basicConfig.Content
  165. }
  166. }
  167. for s, m := range jsonMap {
  168. json[s] = m
  169. }
  170. return This.SaveJson(json, "Game")
  171. }
  172. // GetCommonConf 获取公共配置
  173. func (This *configService) GetCommonConf(typ string) (commonConf model.CommonConf, err error) {
  174. if typ == "" {
  175. return commonConf, errors.New("参数不能为空字符串")
  176. }
  177. commonConf, err = repo.Config.GetCommonConf(typ)
  178. return
  179. }
  180. // UpdateCommonConf 更新公共配置
  181. func (This *configService) UpdateCommonConf(commonConf model.CommonConf) (err error) {
  182. // update
  183. if commonConf.Id != 0 {
  184. if err = repo.Update(&commonConf, "id"); err != nil {
  185. return errors.WithStack(err)
  186. }
  187. } else {
  188. var basicConf model.CommonConf
  189. basicConf, err = This.GetCommonConf(commonConf.Type)
  190. if err != nil {
  191. // 配置不存在 Insert
  192. if _, err = repo.Insert(&commonConf); err != nil {
  193. return errors.WithStack(err)
  194. }
  195. } else {
  196. // update
  197. commonConf.Id = basicConf.Id
  198. if err = repo.Update(&commonConf, "id"); err != nil {
  199. return errors.WithStack(err)
  200. }
  201. }
  202. }
  203. return
  204. }
  205. // GetChestRewardBySkin 获取皮肤宝箱奖励配置
  206. func (This *configService) GetChestRewardBySkin(skin int64) []model.ChestSkinReward {
  207. // 有缓存
  208. if cache := repo.Config.HGetChestReward(skin); cache != "" {
  209. var reward []model.ChestSkinReward
  210. if err := jsoniter.UnmarshalFromString(cache, &reward); err != nil {
  211. panic(errors.Wrap(err, "皮肤宝箱奖励Json解析失败"))
  212. }
  213. }
  214. return repo.Config.GetChestReward(skin)
  215. }
  216. // GetTimeLimitSkinChests 获取限时皮肤宝箱选项
  217. func (This *configService) GetTimeLimitSkinChests() model.Options {
  218. chests := repo.Search[model.TChestSkinConfig2]("")
  219. options := make([]model.Option, 0, len(chests))
  220. for _, chest := range chests {
  221. if chest.StarPro.CardType == 1 {
  222. options = append(options, model.Option{
  223. Value: chest.Id,
  224. Label: chest.Name,
  225. })
  226. }
  227. }
  228. return options
  229. }
  230. func (This *configService) getVersions() []string {
  231. versions := repo.SearchOne[model.TVersionSet]("").Content
  232. split := strings.Split(versions, ",")
  233. if len(split) != 0 {
  234. return split
  235. }
  236. return []string{"1.7.5.0", "1.7.6.0", "1.7.7.0", "1.7.8.0", "1.7.9.0", "1.8.0.0", "1.8.1.0", "1.8.2.0",
  237. "1.8.3.0", "1.8.4.0", "1.8.5", "1.8.6", "1.9"}
  238. }
  239. func (This *configService) BasicConf() []model.TBasicConfig {
  240. return repo.Search[model.TBasicConfig]("")
  241. }
  242. func (This *configService) BasicConfEdit(req model.TBasicConfig) error {
  243. if err := This.UpdateBasicConf(req); err != nil {
  244. return errors.WithStack(err)
  245. }
  246. return nil
  247. }
  248. func (This *configService) BasicBet() []model.TCrazyBetConfig {
  249. return repo.Search[model.TCrazyBetConfig]("Where actData = 0")
  250. }
  251. func (This *configService) BasicBetEdit(req []model.TCrazyBetConfig, typ int64) error {
  252. if _, err := repo.ReplaceStruct[model.TCrazyBetConfig](req, repo.WithKeys("id"), repo.WithWhere("Where actData = ?", typ)); err != nil {
  253. return errors.WithStack(err)
  254. }
  255. data := This.buildBasicBetJson()
  256. if err := This.SaveJson(data, "CrazyBetConfig"); err != nil {
  257. return errors.WithStack(err)
  258. }
  259. return nil
  260. }
  261. func (This *configService) SuperBet() (conf model.SuperCrazyBetConf) {
  262. conf.BetList = repo.Search[model.TCrazyBetConfig]("Where actData = 1")
  263. actSpinsLimit, _ := This.GetSystemConf(model.ItemTitle{Item: "activtity14", Title: "actSpinsLimit"})
  264. conf.Limit = conv.ToAny[int64](actSpinsLimit)
  265. return conf
  266. }
  267. func (This *configService) SuperBetEdit(req model.SuperCrazyBetConf) error {
  268. sysConf := model.TSystemConfig{
  269. ItemTitle: model.ItemTitle{Item: "activtity14", Title: "actSpinsLimit"},
  270. Content: strconv.FormatInt(req.Limit, 10),
  271. Memo: "超级Bet触发体力配置",
  272. }
  273. if err := This.UpdateSystemConf(sysConf); err != nil {
  274. return err
  275. }
  276. if err := This.BasicBetEdit(req.BetList, 1); err != nil {
  277. return errors.WithStack(err)
  278. }
  279. return nil
  280. }
  281. func (This *configService) buildBasicBetJson() (json model.CrazyBetStatic) {
  282. list := repo.Search[model.TCrazyBetConfig]("")
  283. for _, betConfig := range list {
  284. switch betConfig.ActData {
  285. case 0:
  286. json.NormalConfig = append(json.NormalConfig, betConfig.CrazyBetBaseConf)
  287. case 1:
  288. json.SuperBetConfig = append(json.SuperBetConfig, betConfig.CrazyBetBaseConf)
  289. }
  290. }
  291. actSpinsLimit, _ := This.GetSystemConf(model.ItemTitle{Item: "activtity14", Title: "actSpinsLimit"})
  292. json.ActSpinsLimit = conv.ToAny[int64](actSpinsLimit)
  293. return json
  294. }
  295. func (This *configService) UpLimitConf() map[string][]model.UpLimitConf {
  296. confList := repo.Search[model.TUpLimitConfig]("")
  297. confMap := make(map[string][]model.UpLimitConf, len(confList))
  298. for _, limit := range confList {
  299. confMap[limit.Type] = limit.Data
  300. }
  301. return confMap
  302. }
  303. func (This *configService) UpLimitConfEdit(req map[string][]model.UpLimitConf) error {
  304. updateConf := make([]map[string]any, 0, len(req))
  305. for s, confs := range req {
  306. updateConf = append(updateConf, map[string]any{"type": s, "data": confs})
  307. }
  308. if err := repo.UpdateByMap[model.TUpLimitConfig](updateConf, "type"); err != nil {
  309. return errors.WithStack(err)
  310. }
  311. return nil
  312. }
  313. func (This *configService) UserGroups() []model.UserSsGroup {
  314. confList := repo.Search[model.TUserGroup2]("Where cid = 5")
  315. ssGroupsHide := repo.Config.HGetAllSSGroupHide()
  316. ssGroupsUpdate := repo.Config.HGetAllSSGroupUpdate()
  317. groups := make([]model.UserSsGroup, 0, len(confList))
  318. for _, conf := range confList {
  319. if conf.GroupId != 0 {
  320. conf.GroupId = conf.Id
  321. }
  322. groups = append(groups, model.UserSsGroup{
  323. UserGroupBaseConf: conf.UserGroupBaseConf,
  324. ShowStatus: utils.Ternary(utils.InSlice(conf.Id, ssGroupsHide), int64(0), 1),
  325. UpdateStatus: utils.Ternary(utils.InSlice(conf.Id, ssGroupsUpdate), int64(1), 0),
  326. })
  327. }
  328. sort.SliceStable(groups, func(i, j int) bool { return groups[i].Sort > groups[j].Sort })
  329. return groups
  330. }
  331. func (This *configService) UserGroupsShow(req *model.UserGroupStatus) error {
  332. // 全量更新
  333. if req.Id == -1 {
  334. ssGroups := repo.Search[model.TSsGroup]("where cid = ?", 5)
  335. cacheMap := make(map[string]any, len(ssGroups))
  336. for _, one := range ssGroups {
  337. if one.Name == "数数-默认分组" {
  338. one.Id = 0
  339. }
  340. id := strconv.FormatInt(one.Id, 10)
  341. cacheMap[id] = id
  342. }
  343. repo.ClearAndHMSetCache(okeys.SsGroupHide(), cacheMap)
  344. } else {
  345. id := strconv.FormatInt(req.Id, 10)
  346. if !utils.IsEmpty(req.Status) {
  347. repo.Config.HDelSSGroupHide(id)
  348. } else {
  349. repo.Config.HMSetSSGroupHide(map[string]any{id: id})
  350. }
  351. }
  352. return nil
  353. }
  354. func (This *configService) UserGroupsUpdate(req *model.UserGroupStatus) error {
  355. id := strconv.FormatInt(req.Id, 10)
  356. if req.Status < 1 {
  357. repo.Config.HDelSSGroupUpdate(id)
  358. } else {
  359. repo.Config.HMSetSSGroupUpdate(map[string]any{id: id})
  360. }
  361. return nil
  362. }
  363. func (This *configService) GetOtherConf() (model.CommonOtherConf, error) {
  364. var otherConf model.CommonOtherConf
  365. otherConf.GuideLastStep = This.getGuideLastStepConf()
  366. return otherConf, nil
  367. }
  368. func (This *configService) getGuideLastStepConf() (guideConf model.GuideLastStep) {
  369. conf, err := This.GetCommonConf(okeys.GuideLastStep())
  370. if err != nil {
  371. return
  372. }
  373. err = jsoniter.UnmarshalFromString(conf.Conf, &guideConf)
  374. if err != nil {
  375. return
  376. }
  377. return guideConf
  378. }
  379. func (This *configService) GuideLastStepEdit(req model.GuideLastStep) error {
  380. confStr, err := jsoniter.MarshalToString(req)
  381. if err != nil {
  382. return errors.WithStack(err)
  383. }
  384. // 更新数据库
  385. if err = This.UpdateCommonConf(model.CommonConf{Type: okeys.GuideLastStep(), Name: "新手引导最后一步配置", Conf: confStr}); err != nil {
  386. return errors.WithStack(err)
  387. }
  388. // 更新缓存
  389. repo.SetCache(okeys.GuideLastStep(), confStr)
  390. return nil
  391. }
  392. func (This *configService) GetSkinOptions(skinName string) []model.Option2 {
  393. skinList := Activity.GetOneActImgNameByType(skinName).Content
  394. if utils.IsEmpty(skinList) {
  395. return []model.Option2{}
  396. }
  397. options := make([]model.Option2, 0, len(skinList))
  398. for _, content := range skinList {
  399. options = append(options, model.Option2{Value: content.Type, Label: content.Name})
  400. }
  401. return options
  402. }
  403. // BuildSsGroup 构建数数分组
  404. func (This *configService) BuildSsGroup() model.Options {
  405. cacheKey := config.SsGroup
  406. // 缓存存在 且未过期
  407. if cache, exist := global.LocalCache.Get(cacheKey); exist {
  408. return cache.(model.Options)
  409. }
  410. ssGroups := repo.Search[model.TSsGroup]("where cid = ?", 5)
  411. hideIdArr := repo.Config.GetHideSsGroup()
  412. ssGroupOptions := make(model.Options, 0, len(ssGroups))
  413. for i := 0; i < len(ssGroups); i++ {
  414. one := ssGroups[i]
  415. if utils.InSlice(one.Id, hideIdArr) {
  416. continue
  417. }
  418. if one.Name == "数数-默认分组" {
  419. one.Id = 0
  420. }
  421. ssGroupOptions = append(ssGroupOptions, model.Option{
  422. Label: one.Name,
  423. Value: one.Id,
  424. })
  425. }
  426. if len(ssGroupOptions) == 0 {
  427. ssGroupOptions = append(ssGroupOptions, model.Option{
  428. Label: "数数-默认分组",
  429. Value: 0,
  430. })
  431. }
  432. // 缓存道具皮肤配置
  433. global.LocalCache.SetDefault(cacheKey, ssGroupOptions)
  434. return ssGroupOptions
  435. }
  436. // BuildSlotWeightGroup 构建老虎机权重分组
  437. func (This *configService) BuildSlotWeightGroup() model.Options {
  438. cacheKey := config.SlotWeightGroupCacheKey
  439. // 缓存存在 且未过期
  440. if cache, exist := global.LocalCache.Get(cacheKey); exist {
  441. return cache.(model.Options)
  442. }
  443. slotWeightGroupsList := repo.Search[model.TSlotWeightGroup]("")
  444. slotWeightGroups := make(model.Options, 0, len(slotWeightGroupsList))
  445. for i := 0; i < len(slotWeightGroupsList); i++ {
  446. one := slotWeightGroupsList[i]
  447. slotWeightGroups = append(slotWeightGroups, model.Option{
  448. Label: one.Name,
  449. Value: one.Id,
  450. })
  451. }
  452. // 缓存配置
  453. global.LocalCache.SetDefault(cacheKey, slotWeightGroups)
  454. return slotWeightGroups
  455. }
  456. func (This *configService) SysNotice() []model.AnnouncementShow {
  457. confList := repo.Search[model.TAnnouncement](" Order By id desc")
  458. showList := make([]model.AnnouncementShow, 0, len(confList))
  459. for _, one := range confList {
  460. oneShow := model.AnnouncementShow{
  461. Id: one.Id,
  462. Title: one.Title,
  463. Content: one.Content,
  464. DateRange: []int64{one.Stime * 1000, one.Etime * 1000},
  465. Device: one.Device,
  466. Usertype: one.Usertype,
  467. }
  468. _ = utils.Explode(&oneShow.Whitelist, one.Wlist, ",")
  469. _ = utils.Explode(&oneShow.Blacklist, one.Blist, ",")
  470. showList = append(showList, oneShow)
  471. }
  472. return showList
  473. }
  474. func (This *configService) SysNoticeEdit(req []model.AnnouncementShow) error {
  475. updateConf := make([]model.TAnnouncement, 0, len(req))
  476. cacheMap := make(map[string]any, len(req))
  477. for _, conf := range req {
  478. one := model.TAnnouncement{
  479. AnnouncementCache: model.AnnouncementCache{
  480. Id: conf.Id,
  481. Title: conf.Title,
  482. Content: conf.Content,
  483. Stime: conf.DateRange[0] / 1000,
  484. Etime: conf.DateRange[1] / 1000,
  485. Device: conf.Device,
  486. Usertype: conf.Usertype,
  487. Type: 0,
  488. Wlist: utils.Implode(conf.Whitelist, ","),
  489. Blist: utils.Implode(conf.Blacklist, ","),
  490. },
  491. Isvalid: 0,
  492. AnnounceType: 0,
  493. }
  494. updateConf = append(updateConf, one)
  495. cacheMap[strconv.FormatInt(one.Id, 10)] = one.AnnouncementCache
  496. }
  497. delIds, err := repo.ReplaceStruct[model.TAnnouncement](updateConf, repo.WithKeys("id"))
  498. if err != nil {
  499. return errors.WithStack(err)
  500. }
  501. if !utils.IsEmpty(delIds) {
  502. delKeys := make([]string, 0, len(delIds))
  503. for _, id := range delIds {
  504. delKeys = append(delKeys, okeys.AnnouncementNew(id))
  505. }
  506. repo.DelCache(delKeys...)
  507. }
  508. repo.ClearAndHMSetCache(okeys.Announcement(), cacheMap)
  509. for id, one := range cacheMap {
  510. repo.ClearAndHMSetCacheByStruct(okeys.AnnouncementNew(id), one)
  511. }
  512. return nil
  513. }
  514. func (This *configService) StopServer() (showConf model.StopServerShowConf) {
  515. showConf.BasicConf = This.getStopServerConf()
  516. noticeList := repo.Search[model.TAnnouncement](" Order By id desc")
  517. showConf.NoticeOptions = make(model.Options, 0, len(noticeList))
  518. for _, notice := range noticeList {
  519. showConf.NoticeOptions = append(showConf.NoticeOptions, model.Option{
  520. Value: notice.Id,
  521. Label: notice.Title,
  522. })
  523. }
  524. return showConf
  525. }
  526. func (This *configService) getStopServerConf() (showConf model.StopServerConf) {
  527. conf, err := This.GetCommonConf(okeys.StopServiceConfig())
  528. if err != nil {
  529. return showConf
  530. }
  531. if err = jsoniter.UnmarshalFromString(conf.Conf, &showConf); err != nil {
  532. return showConf
  533. }
  534. return showConf
  535. }
  536. func (This *configService) StopServerEdit(req *model.StopServerConf) error {
  537. oldConf := This.getStopServerConf()
  538. // 配置改变 发送nsq
  539. if utils.IsEmpty(oldConf.Type) || oldConf.Type != req.Type {
  540. if err := nsq.SendNsqMsg(config.TopicActOnlineOff, req); err != nil {
  541. panic(errors.Wrap(err, "nsq 停服推送失败"))
  542. }
  543. }
  544. conf, err := jsoniter.MarshalToString(req)
  545. if err != nil {
  546. return errors.WithStack(err)
  547. }
  548. key := okeys.StopServiceConfig()
  549. if err = This.UpdateCommonConf(model.CommonConf{Type: key, Name: "停服配置", Conf: conf}); err != nil {
  550. return errors.WithStack(err)
  551. }
  552. repo.SetCache(key, conf)
  553. // 生成停服动态
  554. staticJson := This.buildStopServerJson(req)
  555. if err = This.SaveJson(staticJson, "StopConfig"); err != nil {
  556. return errors.WithStack(err)
  557. }
  558. return nil
  559. }
  560. func (This *configService) buildStopServerJson(conf *model.StopServerConf) model.StopServerStatic {
  561. staticInfo := model.StopServerStatic{Type: conf.Type, Url: conf.Url}
  562. var content model.StopServerStaticContent
  563. if conf.Type > 1 {
  564. noticeInfo := repo.SearchOne[model.TAnnouncement]("Where id = ?", conf.AnnouncementId)
  565. content.Title = noticeInfo.Title
  566. content.Content = noticeInfo.Content
  567. content.Whitelist = []int64{}
  568. if conf.Type == 3 && !utils.IsEmpty(noticeInfo.Wlist) {
  569. _ = utils.Explode(&content.Whitelist, noticeInfo.Wlist, ",")
  570. }
  571. }
  572. staticInfo.Content = content
  573. return staticInfo
  574. }
  575. func (This *configService) Version() []string {
  576. versions := repo.SearchOne[model.TVersionSet]("").Content
  577. return strings.Split(versions, ",")
  578. }
  579. func (This *configService) VersionEdit(req []string) error {
  580. if err := repo.Update(&model.TVersionSet{Content: utils.Implode(req, ",")}, "content"); err != nil {
  581. return errors.WithStack(err)
  582. }
  583. return nil
  584. }
  585. func (This *configService) IosVersion() model.IosVersionConf {
  586. return repo.Config.MGetIosVersionConf()
  587. }
  588. func (This *configService) IosVersionEdit(req *model.IosVersionConf) error {
  589. mapCache := map[string]any{
  590. okeys.OpenOline(): req.OpenOline,
  591. okeys.OpenOlineVersion(): req.OpenOlineVer,
  592. okeys.IsOpenMaple(): req.IsOpenMaple,
  593. }
  594. repo.MSetCache(mapCache)
  595. return nil
  596. }
  597. func (This *configService) LoginPopup() []model.TLoginBulletBox {
  598. return repo.Search[model.TLoginBulletBox]("")
  599. }
  600. func (This *configService) LoginPopupEdit(req []model.TLoginBulletBox) error {
  601. if _, err := repo.ReplaceStruct[model.TLoginBulletBox](req, repo.WithKeys("id")); err != nil {
  602. return errors.WithStack(err)
  603. }
  604. repo.DelCache(okeys.LoginBulletBox())
  605. staticJson := This.buildLoginPopupJson(req)
  606. if err := Config.SaveJson(staticJson, "LoginDialog"); err != nil {
  607. return errors.WithStack(err)
  608. }
  609. return nil
  610. }
  611. func (This *configService) buildLoginPopupJson(list []model.TLoginBulletBox) []model.LoginPopupStatic {
  612. statics := make([]model.LoginPopupStatic, 0, len(list))
  613. for _, box := range list {
  614. box.Desc = utils.Concat(box.Name, ":", box.Desc)
  615. statics = append(statics, box.LoginPopupStatic)
  616. }
  617. return statics
  618. }