支付模块
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.

51 lines
1.2 KiB

  1. package db
  2. import (
  3. "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/db/model"
  4. "code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/md"
  5. cache "code.fnuoos.com/go_rely_warehouse/zyos_go_tools.git/utils/cache"
  6. "fmt"
  7. "xorm.io/xorm"
  8. )
  9. // 获取一条记录
  10. func SysCfgGetOne(Db *xorm.Engine, key string) (*model.SysCfg, error) {
  11. var cfgList model.SysCfg
  12. if has, err := Db.Where("`key`=?", key).Get(&cfgList); err != nil || has == false {
  13. return nil, err
  14. }
  15. return &cfgList, nil
  16. }
  17. //单条记录获取DB
  18. func SysCfgGetWithDb(eg *xorm.Engine, masterId string, HKey string) string {
  19. cacheKey := fmt.Sprintf(md.AppCfgCacheKey, masterId, HKey[0:1])
  20. get, err := cache.HGetString(cacheKey, HKey)
  21. if err != nil || get == "" {
  22. cfg, err := SysCfgGetOne(eg, HKey)
  23. if err != nil || cfg == nil {
  24. return ""
  25. }
  26. // key是否存在
  27. cacheKeyExist := false
  28. if cache.Exists(cacheKey) {
  29. cacheKeyExist = true
  30. }
  31. // 设置缓存
  32. _, err = cache.HSet(cacheKey, HKey, cfg.Val)
  33. if err != nil {
  34. return ""
  35. }
  36. if !cacheKeyExist { // 如果是首次设置 设置过期时间
  37. _, err := cache.Expire(cacheKey, md.CfgCacheTime)
  38. if err != nil {
  39. return ""
  40. }
  41. }
  42. return cfg.Val
  43. }
  44. return get
  45. }