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.

db_acquisition.go 4.1 KiB

6 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. }