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

176 lines
6.1 KiB

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