广告平台(站长下代理使用)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

79 lines
1.7 KiB

  1. package svc
  2. import (
  3. "applet/app/db/implement"
  4. db "code.fnuoos.com/zhimeng/model.git/src"
  5. "github.com/gin-gonic/gin"
  6. "xorm.io/xorm"
  7. "applet/app/md"
  8. "applet/app/utils/cache"
  9. )
  10. // 单挑记录获取
  11. func SysCfgGet(c *gin.Context, key string) string {
  12. masterId := GetMasterId(c)
  13. eg := db.DBs[masterId]
  14. sysCfgDb := implement.NewSysCfgDb(eg, masterId)
  15. return sysCfgDb.SysCfgGetWithDb(key)
  16. }
  17. // 多条记录获取
  18. func SysCfgFind(c *gin.Context, keys ...string) map[string]string {
  19. var masterId string
  20. if c == nil {
  21. masterId = ""
  22. } else {
  23. masterId = GetMasterId(c)
  24. }
  25. tmp := SysCfgFindComm(masterId, keys...)
  26. return tmp
  27. }
  28. func SysCfgFindComm(masterId string, keys ...string) map[string]string {
  29. var eg *xorm.Engine
  30. if masterId == "" {
  31. eg = db.Db
  32. } else {
  33. eg = db.DBs[masterId]
  34. }
  35. res := map[string]string{}
  36. //TODO::判断keys长度(大于10个直接查数据库)
  37. sysCfgDb := implement.NewSysCfgDb(eg, masterId)
  38. if len(keys) > 10 {
  39. cfgList, _ := sysCfgDb.SysCfgGetAll()
  40. if cfgList == nil {
  41. return nil
  42. }
  43. for _, v := range *cfgList {
  44. res[v.K] = v.V
  45. }
  46. } else {
  47. for _, key := range keys {
  48. res[key] = sysCfgDb.SysCfgGetWithDb(key)
  49. }
  50. }
  51. return res
  52. }
  53. // 清理系统配置信息
  54. func SysCfgCleanCache() {
  55. cache.Del(md.KEY_SYS_CFG_CACHE)
  56. }
  57. // 写入系统设置
  58. func SysCfgSet(c *gin.Context, key, val, memo string) bool {
  59. masterId := GetMasterId(c)
  60. eg := db.DBs[masterId]
  61. sysCfgDb := implement.NewSysCfgDb(eg, masterId)
  62. cfg, err := sysCfgDb.SysCfgGetOne(key)
  63. if err != nil || cfg == nil {
  64. return sysCfgDb.SysCfgInsert(key, val, memo)
  65. }
  66. if memo != "" && cfg.Memo != memo {
  67. cfg.Memo = memo
  68. }
  69. SysCfgCleanCache()
  70. return sysCfgDb.SysCfgUpdate(key, val)
  71. }