互动
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.

173 lines
6.4 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package bully_reward_service
  2. import (
  3. "hudongzhuanjia/models"
  4. "github.com/ouxuanserver/osmanthuswine/src/core"
  5. )
  6. type BullyListResult struct {
  7. Id int `json:"id"`
  8. Content string `json:"content"`
  9. Status int `json:"status"`
  10. Second int `json:"second"`
  11. }
  12. func GetBullyList(userId, bullyId int) ([]*BullyListResult, error) {
  13. list := make([]*BullyListResult, 0)
  14. err := core.GetXormAuto().Table(new(models.BullyScreenHistory)).Select("id, content, status, second").
  15. Where("is_delete=0 and user_id=? and bully_screen_server_id=? and status<> -1", userId, bullyId).
  16. OrderBy("created_at desc").Find(&list)
  17. return list, err
  18. }
  19. type RewardListResult struct {
  20. Id int `json:"id"`
  21. Content string `json:"content"`
  22. Amount float64 `json:"amount"`
  23. Status int `json:"status"`
  24. }
  25. func GetRewardList(userId, rehearsalId, rewardId int, archId interface{}) ([]*RewardListResult, error) {
  26. list := make([]*RewardListResult, 0)
  27. err := core.GetXormAuto().Table(new(models.RewardHistory)).Select("id, content, amount, status").
  28. Where("is_delete=0 and user_id=? and reward_server_id=? and rehearsal_id=? and arch_id=? and status <> -1",
  29. userId, rewardId, rehearsalId, archId).Desc("created_at").Find(&list)
  30. return list, err
  31. }
  32. type RewardResult struct {
  33. models.RewardHistory `xorm:"extends"`
  34. User *models.User `json:"user" xorm:"extends"`
  35. }
  36. func GetRewardLatest(serverId, rehearsalId int, archId interface{}) (*RewardResult, error) {
  37. result := new(RewardResult)
  38. _, err := core.GetXormAuto().Table(new(models.RewardHistory)).Alias("h").
  39. Join("LEFT", new(models.User).Alias("u"), "h.user_id=u.id and u.is_delete=0").
  40. Where("h.is_delete=0 and h.status=2 and h.reward_server_id=? and h.rehearsal_id=? and h.arch_id=?",
  41. serverId, rehearsalId, archId).Desc("h.review_time").Get(result)
  42. return result, err
  43. }
  44. func GetRewardReview(serverId, rehearsalId int, archId interface{}) ([]*RewardResult, error) {
  45. result := make([]*RewardResult, 0)
  46. err := core.GetXormAuto().Table(new(models.RewardHistory)).Alias("h").
  47. Join("LEFT", new(models.User).Alias("u"), "h.user_id=u.id and u.is_delete=0").
  48. Where("h.is_delete=0 and h.status=0 and h.reward_server_id=? and h.rehearsal_id=? and h.arch_id=?",
  49. serverId, rehearsalId, archId).Desc("h.created_at").Find(&result)
  50. return result, err
  51. }
  52. func GetRewardBlacklist(serverId, rehearsalId int, archId interface{}) ([]*RewardResult, error) {
  53. result := make([]*RewardResult, 0)
  54. err := core.GetXormAuto().Table(new(models.RewardHistory)).Alias("h").
  55. Join("LEFT", new(models.User).Alias("u"), "h.user_id=u.id and u.is_delete=0").
  56. Where("h.is_delete=0 and h.status=1 and h.reward_server_id=? and h.rehearsal_id=? and arch_id=?",
  57. serverId, rehearsalId, archId).Desc("h.review_time").Find(&result)
  58. return result, err
  59. }
  60. type RewardStatus struct {
  61. History *models.RewardHistory `json:"history" xorm:"extends"`
  62. Order *models.UserOrder `json:"order" xorm:"extends"`
  63. }
  64. func CheckRewardStatus(serverId int, archId int) error {
  65. result := make([]*RewardStatus, 0)
  66. err := core.GetXormAuto().Table(new(models.RewardHistory)).Alias("h").
  67. Join("LEFT", new(models.UserOrder).AliasName("u"),
  68. "h.out_trade_no=u.out_trade_no and u.is_delete=0").
  69. Where("h.is_delete=0 and h.status=-1 and h.reward_server_id=? and h.arch_id=?",
  70. serverId, archId).Find(&result)
  71. if err != nil {
  72. return err
  73. }
  74. success := make([]int, 0)
  75. destroy := make([]int, 0)
  76. for _, v := range result {
  77. if v.Order.Status == 1 {
  78. success = append(success, v.History.Id)
  79. } else if v.Order.Status != 0 {
  80. destroy = append(destroy, v.History.Id)
  81. }
  82. }
  83. err = new(models.RewardHistory).UpdateStatusByIds(success, 0)
  84. if err != nil {
  85. return err
  86. }
  87. err = new(models.RewardHistory).UpdateStatusByIds(success, 4)
  88. if err != nil {
  89. return err
  90. }
  91. return nil
  92. }
  93. type BullyScreenResult struct {
  94. models.BullyScreenHistory `xorm:"extends"`
  95. User *models.User `json:"user" xorm:"extends"`
  96. }
  97. func GetBullyScreenReview(bullyScreenServerId, rehearsalId int, archId interface{}) ([]*BullyScreenResult, error) {
  98. result := make([]*BullyScreenResult, 0)
  99. err := core.GetXormAuto().Table(new(models.BullyScreenHistory)).Alias("h").
  100. Join("LEFT", new(models.User).Alias("u"), "h.user_id=u.id and u.is_delete=0").
  101. Where("h.bully_screen_server_id=? and h.is_delete=0 and h.status=0 and h.rehearsal_id=? and h.arch_id=?",
  102. bullyScreenServerId, rehearsalId, archId).Desc("h.created_at").Find(&result)
  103. return result, err
  104. }
  105. func GetBullyScreenBlacklist(bullyScreenServerId, rehearsalId int, archId interface{}) ([]*BullyScreenResult, error) {
  106. result := make([]*BullyScreenResult, 0)
  107. err := core.GetXormAuto().Table(new(models.BullyScreenHistory)).Alias("h").
  108. Join("LEFT", new(models.User).Alias("u"), "u.id=h.user_id and u.is_delete=0").
  109. Where("h.is_delete=0 and h.bully_screen_server_id=? and h.status=1 and h.rehearsal_id=? and h.arch_id=?",
  110. bullyScreenServerId, rehearsalId, archId).Desc("review_time").Find(&result)
  111. return result, err
  112. }
  113. func GetBullyScreenLatest(bullyScreenServerId, rehearsalId int, archId interface{}) (*BullyScreenResult, error) {
  114. result := new(BullyScreenResult)
  115. _, err := core.GetXormAuto().Table(new(models.BullyScreenHistory)).Alias("h").
  116. Join("LEFT", new(models.User).Alias("u"), "u.id=h.user_id and u.is_delete=0").
  117. Where("h.bully_screen_server_id=? and h.status=2 and h.rehearsal_id=? and h.arch_id=? and h.is_delete=0",
  118. bullyScreenServerId, rehearsalId, archId).Desc("review_time").Get(result)
  119. return result, err
  120. }
  121. type BullyScreenStatus struct {
  122. History *models.BullyScreenHistory `json:"history" xorm:"extends"`
  123. Order *models.UserOrder `json:"order" xorm:"extends"`
  124. }
  125. func CheckBullyScreenStatus(serverId int) error {
  126. result := make([]*BullyScreenStatus, 0)
  127. err := core.GetXormAuto().Table(new(models.BullyScreenHistory)).Alias("h").
  128. Join("LEFT", new(models.UserOrder).AliasName("u"),
  129. "u.out_trade_no=h.out_trade_no and u.is_delete=0").
  130. Where("h.bully_screen_server_id=? and h.status=-1 and h.is_delete=0",
  131. serverId).Find(&result)
  132. if err != nil {
  133. return err
  134. }
  135. success := make([]int, 0)
  136. destroy := make([]int, 0)
  137. for _, v := range result {
  138. if v.Order.Status == 1 {
  139. success = append(success, v.History.Id)
  140. } else if v.Order.Status != 0 {
  141. destroy = append(destroy, v.History.Id)
  142. }
  143. }
  144. err = new(models.BullyScreenHistory).UpdateStatusByIds(success, 0)
  145. if err != nil {
  146. return err
  147. }
  148. err = new(models.BullyScreenHistory).UpdateStatusByIds(success, 4)
  149. if err != nil {
  150. return err
  151. }
  152. return nil
  153. }