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

189 lines
4.9 KiB

5 years ago
5 years ago
5 years ago
  1. package activity_service
  2. import (
  3. "fmt"
  4. "github.com/ouxuanserver/osmanthuswine/src/core"
  5. "hudongzhuanjia/models"
  6. "hudongzhuanjia/utils/define"
  7. )
  8. func GetActivitiesByCustomerId(cid int64) ([]*models.Activity, error) {
  9. // 登陆限制
  10. // 获取用户拥有的activity
  11. activities := make([]*models.Activity, 0)
  12. err := core.GetXormAuto().Where("is_delete=0 and customer_id=?", cid).
  13. Desc("created_at").Find(&activities)
  14. if err != nil {
  15. return nil, err
  16. }
  17. // customer -> activity -> activity module service -> module service history -> module service
  18. // customer -> activity -> 某次具体的活动(已经启动了的)
  19. aids := make([]int64, 0)
  20. for _, activity := range activities {
  21. aids = append(aids, activity.Id)
  22. }
  23. areaStores := make([]*models.AreaStore, 0)
  24. err = core.GetXormAuto().Where("is_delete=0").In("activity_id", aids).Find(&areaStores)
  25. if err != nil {
  26. return nil, err
  27. }
  28. for j := range activities {
  29. for i := range areaStores {
  30. if areaStores[i].ActivityId == activities[j].Id {
  31. activities[j].AreaStores = append(activities[j].AreaStores, areaStores[i])
  32. }
  33. }
  34. }
  35. services := make([]*models.ActivityModuleService, 0)
  36. err = core.GetXormAuto().Where("is_delete=0 and service_module_status=?", "开启").
  37. In("activity_id", aids).Find(&services)
  38. if err != nil {
  39. return nil, err
  40. }
  41. hids := make([]int64, 0)
  42. for _, service := range services {
  43. hids = append(hids, service.ServiceModuleHistoryId)
  44. }
  45. histories := make([]*models.ModuleServiceHistory, 0)
  46. err = core.GetXormAuto().Where("is_delete=0").In("id", hids).Find(&histories)
  47. if err != nil {
  48. return nil, err
  49. }
  50. for j := range services {
  51. for i := range histories {
  52. if histories[i].Id == services[j].ServiceModuleHistoryId {
  53. services[j].ServiceModuleName = histories[i].Name
  54. break
  55. }
  56. }
  57. }
  58. for j := range activities {
  59. for i := range services {
  60. if activities[j].Id == services[i].ActivityId {
  61. activities[j].Services = append(activities[j].Services, services[i])
  62. }
  63. }
  64. }
  65. return activities, nil
  66. }
  67. func GetActivityById(id int64) (*models.Activity, bool, error) {
  68. activity := new(models.Activity)
  69. exist, err := models.Get(activity, id)
  70. if err != nil || !exist {
  71. return nil, exist, err
  72. }
  73. services := make([]*models.ActivityModuleService, 0)
  74. err = core.GetXormAuto().Where("is_delete=0 and activity_id=? and service_module_status=?", id, define.StatusOpen).
  75. Find(&services)
  76. if err != nil {
  77. return nil, false, err
  78. }
  79. hids := make([]int64, 0)
  80. for _, service := range services {
  81. hids = append(hids, service.ServiceModuleHistoryId)
  82. }
  83. histories := make([]*models.ModuleServiceHistory, 0)
  84. err = core.GetXormAuto().Where("is_delete=0").In("id", hids).Find(&histories)
  85. if err != nil {
  86. return nil, false, err
  87. }
  88. for j := range services {
  89. for i := range histories {
  90. if histories[i].Id == services[j].ServiceModuleHistoryId {
  91. services[j].ServiceModuleName = histories[i].Name
  92. break
  93. }
  94. }
  95. }
  96. activity.Services = services
  97. // 增加对上墙 霸屏 弹幕 打赏
  98. mServer := new(models.MsgWallServer)
  99. exist, err = mServer.GetByActivityId(id)
  100. if err != nil {
  101. return nil, false, err
  102. }
  103. if !exist {
  104. activity.UpperWallStatus = define.StatusClose
  105. } else {
  106. activity.UpperWallStatus = mServer.UpWallStatus
  107. }
  108. rServer := new(models.RewardServer)
  109. exist, err = rServer.GetByActivityId(id)
  110. if err != nil {
  111. return nil, false, err
  112. }
  113. if !exist {
  114. activity.RewardStatus = define.StatusClose
  115. } else {
  116. activity.RewardStatus = rServer.ServerStart
  117. }
  118. dServer := new(models.DanMuServer)
  119. exist, err = dServer.GetByActivityId(id)
  120. if err != nil {
  121. return nil, false, err
  122. }
  123. if !exist {
  124. activity.BarrageStatus = define.StatusClose
  125. } else {
  126. activity.BarrageStatus = dServer.DanmuSwitch
  127. }
  128. bServer := new(models.BullyScreenServer)
  129. exist, err = bServer.GetByActivityId(id)
  130. if err != nil {
  131. return nil, false, err
  132. }
  133. if !exist {
  134. activity.BullyScreenStatus = define.StatusClose
  135. } else {
  136. activity.BullyScreenStatus = bServer.Start
  137. }
  138. return activity, true, nil
  139. }
  140. func ExistModuleByActivityId(aid int64, module string) (bool, error) {
  141. switch module {
  142. case define.MODULE_TUGWAR: // 拔河
  143. bahe := new(models.TugOfWar)
  144. return bahe.GetCurrent(aid)
  145. case define.MODULE_ORDER: //下订单
  146. option := new(models.CustomerOrderOption)
  147. return option.GetOpen(aid)
  148. case define.MODULE_SHAKRB: //摇红包
  149. rule := new(models.ShakeRedEnvelopeRule)
  150. return rule.GetCurrent(aid)
  151. case define.MODULE_AUCTION: // 竞拍
  152. auction := new(models.NewAuctionActivity)
  153. return auction.GetCurrent(aid)
  154. case define.MODULE_VOTE:
  155. vote := new(models.NewVoteActivity)
  156. return vote.GetCurrent(aid)
  157. case define.MODULE_CALORIE:
  158. calorie := new(models.Calorie)
  159. return calorie.GetCurrent(aid)
  160. case define.MODULE_BARRAGE:
  161. fallthrough
  162. case define.MODULE_BULLYS:
  163. fallthrough
  164. case define.MODULE_REWARD:
  165. fallthrough
  166. case define.MODULE_UPPERW:
  167. return true, nil
  168. default:
  169. return false, fmt.Errorf("不存在该活动模块")
  170. }
  171. }