activity_signup.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/utils"
  7. "time"
  8. )
  9. // GetActivitySignupResp 处理用户的报名方式
  10. func GetActivitySignupResp(activityIdS []int, user *models.WxUserItem) (mapItem map[int]int, err error) {
  11. var condition string
  12. var pars []interface{}
  13. lenActivityId := len(activityIdS)
  14. if lenActivityId == 0 || user.Mobile == "" {
  15. return
  16. }
  17. condition = ` AND do_fail_type = 0 AND activity_id IN (` + utils.GetOrmInReplace(lenActivityId) + `) AND mobile = ?`
  18. pars = append(pars, activityIdS, user.Mobile)
  19. listSignup, e := models.GetActivitySignupList(condition, pars)
  20. if e != nil {
  21. err = errors.New("GetResourceDataList, Err: " + e.Error())
  22. return
  23. }
  24. mapItem = make(map[int]int, 0)
  25. for _, v := range listSignup {
  26. mapItem[v.ActivityId] = v.SignupType
  27. }
  28. return
  29. }
  30. // CheckActivitySignUpLimit 校验报名限制
  31. func CheckActivitySignUpLimit(user *models.WxUserItem, activityInfo *models.ActivityDetail) (signupStatus, popupMsg string, failType int, err error) {
  32. //判断优先级:总人数限制→单机构2人限制→爽约3次限制
  33. signupStatus = "Success"
  34. activityId := activityInfo.ActivityId
  35. //弘则下面的用户不做单机构两人限制、不受报名总人数限制
  36. if user.CompanyId != utils.HZ_COMPANY_ID {
  37. totaSignupPeopleNum, e := models.GetActivitySignupSuccessByUserCountNoHz(activityId)
  38. if e != nil {
  39. err = errors.New("GetActivitySignupSuccessByUserCountNoHz, Err: " + e.Error())
  40. return
  41. }
  42. if totaSignupPeopleNum >= activityInfo.LimitPeopleNum {
  43. signupStatus = "FullStarffed"
  44. popupMsg = "此活动报名人数已满,请留意下期活动"
  45. failType = 1
  46. return
  47. }
  48. totalSignupCompany, e := models.GetActivitySignupCompanyCount(activityId, user.CompanyId)
  49. if e != nil {
  50. err = errors.New("GetActivitySignupCompanyCount, Err: " + e.Error())
  51. return
  52. }
  53. if totalSignupCompany >= 2 {
  54. signupStatus = "TwoPeople"
  55. popupMsg = "单机构最多2人报名同一活动,您所在机构报名人数已满"
  56. failType = 2
  57. return
  58. }
  59. }
  60. //totalRestrict, e := models.GetUserRestrictCount(user.Mobile)
  61. //if e != nil {
  62. // err = errors.New("GetUserRestrictCount, Err: " + e.Error())
  63. // return
  64. //}
  65. //if totalRestrict >= 1 {
  66. // signupStatus = "BreakPromise"
  67. // popupMsg = "由于爽约次数过多,您暂时被限制报名资格,请联系对口销售"
  68. // failType = 3
  69. // return
  70. //}
  71. return
  72. }
  73. // 校验报名截止时间
  74. func CheckSiginupDeadline(activityInfo *models.ActivityDetail) (checkTime bool, popupMsg string) {
  75. checkTime = true
  76. if activityInfo.SiginupDeadline != utils.FormatDateTimeInit && activityInfo.SiginupDeadline != "" {
  77. timeResp := utils.StrTimeToTime(activityInfo.SiginupDeadline)
  78. if timeResp.Before(time.Now()) {
  79. checkTime = false
  80. popupMsg = "该活动已截止报名\n\n若想参加,请联系对口销售"
  81. }
  82. }
  83. return
  84. }
  85. // 校验报名点数
  86. func CheckActivityPoints(activityInfo *models.ActivityDetail, wxUser *models.WxUserItem) (checkPoints bool, popupMsg, companyPoints, activityPoints string, err error) {
  87. checkPoints = true
  88. if activityInfo.IsResearchPoints {
  89. //获取活动对用户要扣的点
  90. userPointsNum, e := models.GetCygxActivityPointsSetUserNum(activityInfo.ActivityId)
  91. if e != nil {
  92. err = errors.New("GetCygxActivityPointsSetUserNum, Err: " + e.Error())
  93. return
  94. }
  95. // 获取用户所在公司剩余的点
  96. companyPointsNum, e := models.GetCompanyPoints(wxUser.CompanyId)
  97. if e != nil && e.Error() != utils.ErrNoRow() {
  98. err = errors.New("GetCompanyPoints, Err: " + e.Error())
  99. return
  100. }
  101. if companyPointsNum-userPointsNum < 0 {
  102. checkPoints = false
  103. popupMsg = "点数不足,若想报名,\n请联系对口销售充值"
  104. }
  105. companyPoints = fmt.Sprint(companyPointsNum)
  106. activityPoints = fmt.Sprint(userPointsNum)
  107. }
  108. return
  109. }
  110. // 校验报名是否需要绑定邮箱
  111. func CheckActivityUserEmail(activityInfo *models.ActivityDetail, wxUser *models.WxUserItem) (checkEmail bool, popupMsg string) {
  112. checkEmail = true
  113. if activityInfo.IsNeedEmail == 1 {
  114. if wxUser.Email == "" {
  115. checkEmail = false
  116. popupMsg = "应上市公司要求,该会议报名需\n提供邮箱,请填写您的工作邮箱"
  117. }
  118. }
  119. return
  120. }
  121. // 处理取消报名截止时间的弹窗文案
  122. func ActivityCancelDeadlineMsg(activityInfo *models.ActivityDetail) (popupMsg string, err error) {
  123. if !activityInfo.IsResearchPoints {
  124. return
  125. }
  126. activityId := activityInfo.ActivityId
  127. //获取活动是否扣点以及扣点规则明细
  128. activityPointsSetDetail, e := models.GetCygxActivityPointsSetDetail(activityId)
  129. if e != nil {
  130. err = errors.New("GetCygxActivityPointsSetDetail" + e.Error())
  131. return
  132. }
  133. cancelDeadlineType := activityPointsSetDetail.CancelDeadlineType
  134. popupMsg = "活动开始前1小时取消报名,可返还点数"
  135. //if activityInfo.CancelDeadlineType == 0 {
  136. // popupMsg = "活动开始前1小时取消报名,可返还点数"
  137. //}
  138. if cancelDeadlineType == 1 && activityInfo.SiginupDeadline != utils.FormatDateTimeInit && activityInfo.SiginupDeadline != "" {
  139. siginupDeadline := utils.GetTimeDateRemoveYearAndSecond(activityInfo.SiginupDeadline)
  140. popupMsg = siginupDeadline + "前取消报名,可返还点数"
  141. }
  142. if cancelDeadlineType == 2 {
  143. popupMsg = "活动开始前24小时取消报名,可返还点数"
  144. }
  145. if cancelDeadlineType == 3 {
  146. popupMsg = "活动开始前48小时取消报名,可返还点数"
  147. }
  148. return
  149. }
  150. // 校验取消报名截止时间
  151. func CheckCancelDeadline(activityInfo *models.ActivityDetail) (popupMsg string) {
  152. if !activityInfo.IsResearchPoints {
  153. return
  154. }
  155. //获取活动是否扣点以及扣点规则明细
  156. if activityInfo.CancelDeadline != utils.FormatDateTimeInit {
  157. timeResp := utils.StrTimeToTime(activityInfo.CancelDeadline)
  158. if timeResp.Before(time.Now()) {
  159. popupMsg = "当前时间点已无法取消报名,\n\n若想取消,请联系对口销售"
  160. }
  161. }
  162. return
  163. }
  164. // // 校验报名顺序 截止时间>点数>邮箱
  165. func CheckActivityUserAll(activityInfo *models.ActivityDetail, wxUser *models.WxUserItem) (popupMsg string, err error) {
  166. _, popupMsg = CheckSiginupDeadline(activityInfo)
  167. if popupMsg != "" {
  168. return
  169. }
  170. _, popupMsg, _, _, err = CheckActivityPoints(activityInfo, wxUser)
  171. if popupMsg != "" {
  172. return
  173. }
  174. _, popupMsg = CheckActivityUserEmail(activityInfo, wxUser)
  175. if popupMsg != "" {
  176. return
  177. }
  178. return
  179. }