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

178 lines
6.2 KiB

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