面包店
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

64 行
1.3 KiB

  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/md"
  5. "applet/app/utils/cache"
  6. "errors"
  7. "fmt"
  8. "xorm.io/xorm"
  9. )
  10. func GetVirtualCoinList(eg *xorm.Engine, masterId string) ([]*model.VirtualCoin, error) {
  11. var m []*model.VirtualCoin
  12. cacheKey := fmt.Sprintf(md.VirtualCoinCfgCacheKey, masterId)
  13. err := cache.GetJson(cacheKey, &m)
  14. if err != nil || len(m) == 0 {
  15. err := eg.Where("is_use=1").Find(&m)
  16. if err != nil {
  17. return nil, err
  18. }
  19. cache.SetJson(cacheKey, m, md.CfgCacheTime)
  20. }
  21. return m, nil
  22. }
  23. // InsertUserVirtualFlow 插入一条虚拟币流水
  24. func InsertUserVirtualFlow(eg *xorm.Engine, m model.UserVirtualCoinFlow) error {
  25. insert, err := eg.Insert(m)
  26. if err != nil {
  27. return err
  28. }
  29. if insert == 0 {
  30. return errors.New("插入虚拟币流水错误")
  31. }
  32. return nil
  33. }
  34. func InsertUserVirtualFlowWithSess(sess *xorm.Session, m model.UserVirtualCoinFlow) error {
  35. insert, err := sess.Insert(m)
  36. if err != nil {
  37. return err
  38. }
  39. if insert == 0 {
  40. return errors.New("插入虚拟币流水错误")
  41. }
  42. return nil
  43. }
  44. func GetBlockCoin(eg *xorm.Engine) (*model.VirtualCoin, error) {
  45. var m model.VirtualCoin
  46. get, err := eg.Where("is_block = 1").Get(&m)
  47. if err != nil {
  48. return nil, err
  49. }
  50. if get {
  51. return &m, nil
  52. }
  53. return nil, errors.New("查询有误!")
  54. }