activity_signup.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_clpt/models"
  6. "hongze/hongze_clpt/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. fmt.Println(timeResp)
  79. if timeResp.Before(time.Now()) {
  80. checkTime = false
  81. popupMsg = "该活动已截止报名\n\n若想参加,请联系对口销售"
  82. }
  83. }
  84. return
  85. }
  86. // 校验报名点数
  87. func CheckActivityPoints(activityInfo *models.ActivityDetail, wxUser *models.WxUserItem) (checkPoints bool, popupMsg, companyPoints, activityPoints string, err error) {
  88. checkPoints = true
  89. if activityInfo.IsResearchPoints {
  90. //获取活动对用户要扣的点
  91. userPointsNum, e := models.GetCygxActivityPointsSetUserNum(activityInfo.ActivityId)
  92. if e != nil {
  93. err = errors.New("GetActivitySignupSuccessByUserCountNoHz, Err: " + e.Error())
  94. return
  95. }
  96. // 获取用户所在公司剩余的点
  97. companyPointsNum, e := models.GetCompanyPoints(wxUser.CompanyId)
  98. if e != nil && e.Error() != utils.ErrNoRow() {
  99. err = errors.New("GetCompanyPoints, Err: " + e.Error())
  100. return
  101. }
  102. if companyPointsNum-userPointsNum < 0 {
  103. checkPoints = false
  104. popupMsg = "点数不足,若想报名,\n请联系对口销售充值"
  105. }
  106. companyPoints = fmt.Sprint(companyPointsNum)
  107. activityPoints = fmt.Sprint(userPointsNum)
  108. }
  109. return
  110. }
  111. // 校验报名是否需要绑定邮箱
  112. func CheckActivityUserEmail(activityInfo *models.ActivityDetail, wxUser *models.WxUserItem) (checkEmail bool, popupMsg string) {
  113. checkEmail = true
  114. if activityInfo.IsNeedEmail == 1 {
  115. if wxUser.Email == "" {
  116. checkEmail = false
  117. popupMsg = "应上市公司要求,该会议报名需\n提供邮箱,请填写您的工作邮箱"
  118. }
  119. }
  120. return
  121. }
  122. // 处理取消报名截止时间的弹窗文案
  123. func ActivityCancelDeadlineMsg(activityInfo *models.ActivityDetail) (popupMsg string, err error) {
  124. if !activityInfo.IsResearchPoints {
  125. return
  126. }
  127. activityId := activityInfo.ActivityId
  128. //获取活动是否扣点以及扣点规则明细
  129. activityPointsSetDetail, e := models.GetCygxActivityPointsSetDetail(activityId)
  130. if e != nil {
  131. err = errors.New("GetCygxActivityPointsSetDetail" + e.Error())
  132. return
  133. }
  134. cancelDeadlineType := activityPointsSetDetail.CancelDeadlineType
  135. popupMsg = "活动开始前1小时取消报名,可返还点数"
  136. //if activityInfo.CancelDeadlineType == 0 {
  137. // popupMsg = "活动开始前1小时取消报名,可返还点数"
  138. //}
  139. if cancelDeadlineType == 1 && activityInfo.SiginupDeadline != utils.FormatDateTimeInit && activityInfo.SiginupDeadline != "" {
  140. siginupDeadline := utils.GetTimeDateRemoveYearAndSecond(activityInfo.SiginupDeadline)
  141. popupMsg = siginupDeadline + "前取消报名,可返还点数"
  142. }
  143. if cancelDeadlineType == 2 {
  144. popupMsg = "活动开始前24小时取消报名,可返还点数"
  145. }
  146. if cancelDeadlineType == 3 {
  147. popupMsg = "活动开始前48小时取消报名,可返还点数"
  148. }
  149. return
  150. }
  151. // 校验取消报名截止时间
  152. func CheckCancelDeadline(activityInfo *models.ActivityDetail) (popupMsg string) {
  153. if !activityInfo.IsResearchPoints {
  154. return
  155. }
  156. //获取活动是否扣点以及扣点规则明细
  157. if activityInfo.CancelDeadline != utils.FormatDateTimeInit {
  158. timeResp := utils.StrTimeToTime(activityInfo.CancelDeadline)
  159. if timeResp.Before(time.Now()) {
  160. popupMsg = "当前时间点已无法取消报名,\n\n若想取消,请联系对口销售"
  161. }
  162. }
  163. return
  164. }
  165. // 校验报名是否需要绑定邮箱
  166. func CheckActivityUserAll(activityInfo *models.ActivityDetail, wxUser *models.WxUserItem) (popupMsg string, err error) {
  167. _, popupMsg = CheckSiginupDeadline(activityInfo)
  168. if popupMsg != "" {
  169. return
  170. }
  171. _, popupMsg, _, _, err = CheckActivityPoints(activityInfo, wxUser)
  172. if popupMsg != "" {
  173. return
  174. }
  175. _, popupMsg = CheckActivityUserEmail(activityInfo, wxUser)
  176. if popupMsg != "" {
  177. return
  178. }
  179. return
  180. }