activity_signup.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 == 1 && activityInfo.LimitPeopleNum == 1 {
  43. signupStatus = "FullStarffed"
  44. popupMsg = "该活动为非公开活动,如有专家访谈需求请联系对口销售"
  45. failType = 1
  46. return
  47. }
  48. if totaSignupPeopleNum >= activityInfo.LimitPeopleNum {
  49. signupStatus = "FullStarffed"
  50. popupMsg = "此活动报名人数已满,请留意下期活动"
  51. failType = 1
  52. return
  53. }
  54. totalSignupCompany, e := models.GetActivitySignupCompanyCount(activityId, user.CompanyId)
  55. if e != nil {
  56. err = errors.New("GetActivitySignupCompanyCount, Err: " + e.Error())
  57. return
  58. }
  59. if totalSignupCompany >= 2 {
  60. signupStatus = "TwoPeople"
  61. popupMsg = "单机构最多2人报名同一活动,您所在机构报名人数已满"
  62. failType = 2
  63. return
  64. }
  65. }
  66. //totalRestrict, e := models.GetUserRestrictCount(user.Mobile)
  67. //if e != nil {
  68. // err = errors.New("GetUserRestrictCount, Err: " + e.Error())
  69. // return
  70. //}
  71. //if totalRestrict >= 1 {
  72. // signupStatus = "BreakPromise"
  73. // popupMsg = "由于爽约次数过多,您暂时被限制报名资格,请联系对口销售"
  74. // failType = 3
  75. // return
  76. //}
  77. return
  78. }
  79. // 校验报名截止时间
  80. func CheckSiginupDeadline(activityInfo *models.ActivityDetail) (checkTime bool, popupMsg string) {
  81. checkTime = true
  82. if activityInfo.SiginupDeadline != utils.FormatDateTimeInit && activityInfo.SiginupDeadline != "" {
  83. timeResp := utils.StrTimeToTime(activityInfo.SiginupDeadline)
  84. if timeResp.Before(time.Now()) {
  85. checkTime = false
  86. popupMsg = "该活动已截止报名\n\n若想参加,请联系对口销售"
  87. }
  88. }
  89. return
  90. }
  91. // 校验报名点数
  92. func CheckActivityPoints(activityInfo *models.ActivityDetail, wxUser *models.WxUserItem) (checkPoints bool, popupMsg, companyPoints, activityPoints string, err error) {
  93. checkPoints = true
  94. if activityInfo.IsResearchPoints {
  95. //获取活动对用户要扣的点
  96. userPointsNum, e := models.GetCygxActivityPointsSetUserNum(activityInfo.ActivityId)
  97. if e != nil {
  98. err = errors.New("GetCygxActivityPointsSetUserNum, Err: " + e.Error())
  99. return
  100. }
  101. // 获取用户所在公司剩余的点
  102. companyPointsNum, e := models.GetCompanyPoints(wxUser.CompanyId)
  103. if e != nil && e.Error() != utils.ErrNoRow() {
  104. err = errors.New("GetCompanyPoints, Err: " + e.Error())
  105. return
  106. }
  107. if companyPointsNum-userPointsNum < 0 {
  108. checkPoints = false
  109. popupMsg = "点数不足,若想报名,\n请联系对口销售充值"
  110. }
  111. companyPoints = fmt.Sprint(companyPointsNum)
  112. activityPoints = fmt.Sprint(userPointsNum)
  113. }
  114. return
  115. }
  116. // 校验报名是否需要绑定邮箱
  117. func CheckActivityUserEmail(activityInfo *models.ActivityDetail, wxUser *models.WxUserItem) (checkEmail bool, popupMsg string) {
  118. checkEmail = true
  119. if activityInfo.IsNeedEmail == 1 {
  120. if wxUser.Email == "" {
  121. checkEmail = false
  122. popupMsg = "应上市公司要求,该会议报名需\n提供邮箱,请填写您的工作邮箱"
  123. }
  124. }
  125. return
  126. }
  127. // 处理取消报名截止时间的弹窗文案
  128. func ActivityCancelDeadlineMsg(activityInfo *models.ActivityDetail) (popupMsg string, err error) {
  129. if !activityInfo.IsResearchPoints {
  130. return
  131. }
  132. activityId := activityInfo.ActivityId
  133. //获取活动是否扣点以及扣点规则明细
  134. activityPointsSetDetail, e := models.GetCygxActivityPointsSetDetail(activityId)
  135. if e != nil {
  136. err = errors.New("GetCygxActivityPointsSetDetail" + e.Error())
  137. return
  138. }
  139. cancelDeadlineType := activityPointsSetDetail.CancelDeadlineType
  140. popupMsg = "活动开始前1小时取消报名,可返还点数"
  141. //if activityInfo.CancelDeadlineType == 0 {
  142. // popupMsg = "活动开始前1小时取消报名,可返还点数"
  143. //}
  144. if cancelDeadlineType == 1 && activityInfo.SiginupDeadline != utils.FormatDateTimeInit && activityInfo.SiginupDeadline != "" {
  145. siginupDeadline := utils.GetTimeDateRemoveYearAndSecond(activityInfo.SiginupDeadline)
  146. popupMsg = siginupDeadline + "前取消报名,可返还点数"
  147. }
  148. if cancelDeadlineType == 2 {
  149. popupMsg = "活动开始前24小时取消报名,可返还点数"
  150. }
  151. if cancelDeadlineType == 3 {
  152. popupMsg = "活动开始前48小时取消报名,可返还点数"
  153. }
  154. return
  155. }
  156. // 校验取消报名截止时间
  157. func CheckCancelDeadline(activityInfo *models.ActivityDetail) (popupMsg string) {
  158. if !activityInfo.IsResearchPoints {
  159. return
  160. }
  161. //获取活动是否扣点以及扣点规则明细
  162. if activityInfo.CancelDeadline != utils.FormatDateTimeInit {
  163. timeResp := utils.StrTimeToTime(activityInfo.CancelDeadline)
  164. if timeResp.Before(time.Now()) {
  165. popupMsg = "当前时间点已无法取消报名,\n\n若想取消,请联系对口销售"
  166. }
  167. }
  168. return
  169. }
  170. // // 校验报名顺序 截止时间>点数>邮箱
  171. func CheckActivityUserAll(activityInfo *models.ActivityDetail, wxUser *models.WxUserItem) (popupMsg string, err error) {
  172. _, popupMsg = CheckSiginupDeadline(activityInfo)
  173. if popupMsg != "" {
  174. return
  175. }
  176. _, popupMsg, _, _, err = CheckActivityPoints(activityInfo, wxUser)
  177. if popupMsg != "" {
  178. return
  179. }
  180. _, popupMsg = CheckActivityUserEmail(activityInfo, wxUser)
  181. if popupMsg != "" {
  182. return
  183. }
  184. return
  185. }