golang 的 rabbitmq 消费项目
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.
 
 
 

144 lines
4.1 KiB

  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/md"
  5. "applet/app/utils"
  6. "applet/app/utils/logx"
  7. "fmt"
  8. "time"
  9. "xorm.io/xorm"
  10. )
  11. // 拉新
  12. // 统计奖励金额
  13. func SumAcquisitionReward(Db *xorm.Engine, condition *model.AcquisitionRewardLog) (string, error) {
  14. total, err := Db.Sum(condition, "money")
  15. if err != nil {
  16. return "0", err
  17. }
  18. return utils.AnyToString(total), nil
  19. }
  20. // 统计拉新人数
  21. func CountAcquisitionUser(Db *xorm.Engine, condition *model.AcquisitionLog) (string, error) {
  22. total, err := Db.Count(condition)
  23. if err != nil {
  24. return "0", err
  25. }
  26. return utils.AnyToString(total), nil
  27. }
  28. // 获取拉新记录
  29. func GetAcquisitionLog(Db *xorm.Engine, condition *model.AcquisitionLog) (*model.AcquisitionLog, bool, error) {
  30. r := new(model.AcquisitionLog)
  31. has, err := Db.Get(condition)
  32. if err != nil {
  33. return r, false, err
  34. }
  35. return condition, has, nil
  36. }
  37. // 获取拉新奖励记录
  38. func GetAcquisitionRewardLog(Db *xorm.Engine, condition *model.AcquisitionRewardLog) (*model.AcquisitionRewardLog, bool, error) {
  39. r := new(model.AcquisitionRewardLog)
  40. has, err := Db.Get(condition)
  41. if err != nil {
  42. return r, false, err
  43. }
  44. return condition, has, nil
  45. }
  46. // 插入拉新记录
  47. func InsertAcqLog(Db *xorm.Engine, acqLog *model.AcquisitionLog) {
  48. row, err := Db.InsertOne(acqLog)
  49. if err != nil || row == 0 {
  50. _ = logx.Warn(err)
  51. }
  52. }
  53. // 更新拉新记录
  54. func UpdateAcqLog(Db *xorm.Engine, acqLog *model.AcquisitionLog) {
  55. row, err := Db.ID(acqLog.Id).Cols("state,complete_con").Update(acqLog)
  56. if err != nil || row == 0 {
  57. _ = logx.Warn(err)
  58. }
  59. }
  60. // 查询是否存在奖励记录
  61. func HasRewardLog(Db *xorm.Engine, condition *model.AcquisitionRewardLog) (string, error) {
  62. has, err := Db.Get(condition)
  63. s := "0"
  64. if err != nil {
  65. return s, err
  66. }
  67. if has {
  68. s = "1"
  69. }
  70. if condition.State == 1 {
  71. s = "2"
  72. }
  73. return s, nil
  74. }
  75. // 查询是否存在奖励记录
  76. func GetRewardLog(Db *xorm.Engine, condition *model.AcquisitionRewardLog) (*model.AcquisitionRewardLog, error) {
  77. r := new(model.AcquisitionRewardLog)
  78. has, err := Db.Get(condition)
  79. if err != nil || !has {
  80. return r, err
  81. }
  82. return condition, nil
  83. }
  84. // 插入奖励记录
  85. func InsertRewardLog(Db *xorm.Engine, rewardLog *model.AcquisitionRewardLog) {
  86. row, err := Db.InsertOne(rewardLog)
  87. if err != nil || row == 0 {
  88. _ = logx.Warn(err)
  89. }
  90. }
  91. // 更新奖励记录
  92. func UpdateRewardLog(Db *xorm.Engine, rewardLog *model.AcquisitionRewardLog) (int64, error) {
  93. affected, err := Db.ID(rewardLog.Id).AllCols().Update(rewardLog)
  94. return affected, err
  95. }
  96. //
  97. func FindRewardLog(Db *xorm.Engine, state string, forbiddenState string, uid string) ([]*model.AcquisitionRewardLog, error) {
  98. var logs []*model.AcquisitionRewardLog
  99. err := Db.Where("state=? and is_frozen=? and uid=?", state, forbiddenState, uid).Find(&logs)
  100. return logs, err
  101. }
  102. func FindRewardLogLimit(Db *xorm.Engine, state, forbiddenState string, limit, start int) ([]*model.AcquisitionRewardLog, error) {
  103. var logs []*model.AcquisitionRewardLog
  104. err := Db.Where("state=? and is_frozen=?", state, forbiddenState).Limit(limit, start).Find(&logs)
  105. return logs, err
  106. }
  107. func FindAcqLogLimit(Db *xorm.Engine, state string, limit, start int) ([]*model.AcquisitionLog, error) {
  108. var logs []*model.AcquisitionLog
  109. err := Db.Where("state=?", state).Limit(limit, start).Find(&logs)
  110. return logs, err
  111. }
  112. func FindAcqRewardLogLimit(Db *xorm.Engine, state string, limit, start int, acqCfgLocal *md.AcquisitionCfg) ([]*model.AcquisitionRewardLog, error) {
  113. var logs []*model.AcquisitionRewardLog
  114. lastTime := time.Now().Unix()
  115. if acqCfgLocal != nil && utils.StrToInt(acqCfgLocal.RewardAccountDay) > 0 {
  116. lastTime = lastTime - utils.StrToInt64(acqCfgLocal.RewardAccountDay)*86400
  117. }
  118. err := Db.Where("state=? and created_at >? and created_at <? and source=? and is_frozen=?", state, "0", lastTime, 1, 0).Limit(limit, start).Find(&logs)
  119. fmt.Println(err)
  120. return logs, err
  121. }
  122. func FindAcqRewardLogLimitByIds(Db *xorm.Engine, ids []string) ([]*model.AcquisitionRewardLog, error) {
  123. var logs []*model.AcquisitionRewardLog
  124. err := Db.In("id", ids).And("state=?", 0).Find(&logs)
  125. fmt.Println(err)
  126. return logs, err
  127. }