activity_signup.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_mfyx/models"
  6. "hongze/hongze_mfyx/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. activtyPayTotal := GetCygxOrderVirtualAssetdCountTotal(wxUser.Mobile, activityInfo.ActivityId) // 判断用户是否购买单场活动
  102. if companyPointsNum-userPointsNum < 0 && activtyPayTotal == 0 {
  103. checkPoints = false
  104. var popupPriceMsg string
  105. if utils.IS_SHOW_WX_PAY {
  106. goodsList := GetGoodsInfoByActivity(activityInfo) //单场活动信息
  107. for _, v := range goodsList {
  108. popupPriceMsg = v.PopupPriceMsg //价格弹窗信息
  109. }
  110. popupMsg = "<div>点数不足,您可以通过单场付费 <span style=\"color:#D54941\">" + popupPriceMsg + "</span> 参与或者联系销售机构充值 <br /> </div>"
  111. } else {
  112. popupMsg = "点数不足,若想报名,\n请联系对口销售充值"
  113. }
  114. }
  115. companyPoints = fmt.Sprint(companyPointsNum)
  116. activityPoints = fmt.Sprint(userPointsNum)
  117. }
  118. return
  119. }
  120. // 校验报名是否需要绑定邮箱
  121. func CheckActivityUserEmail(activityInfo *models.ActivityDetail, wxUser *models.WxUserItem) (checkEmail bool, popupMsg string) {
  122. checkEmail = true
  123. if activityInfo.IsNeedEmail == 1 {
  124. if wxUser.Email == "" {
  125. checkEmail = false
  126. popupMsg = "应上市公司要求,该会议报名需\n提供邮箱,请填写您的工作邮箱"
  127. }
  128. }
  129. return
  130. }
  131. // 处理取消报名截止时间的弹窗文案
  132. func ActivityCancelDeadlineMsg(activityInfo *models.ActivityDetail) (popupMsg string, err error) {
  133. if !activityInfo.IsResearchPoints {
  134. return
  135. }
  136. activityId := activityInfo.ActivityId
  137. //获取活动是否扣点以及扣点规则明细
  138. activityPointsSetDetail, e := models.GetCygxActivityPointsSetDetail(activityId)
  139. if e != nil {
  140. err = errors.New("GetCygxActivityPointsSetDetail" + e.Error())
  141. return
  142. }
  143. cancelDeadlineType := activityPointsSetDetail.CancelDeadlineType
  144. popupMsg = "活动开始前1小时取消报名,可返还点数"
  145. //if activityInfo.CancelDeadlineType == 0 {
  146. // popupMsg = "活动开始前1小时取消报名,可返还点数"
  147. //}
  148. if cancelDeadlineType == 1 && activityInfo.SiginupDeadline != utils.FormatDateTimeInit && activityInfo.SiginupDeadline != "" {
  149. siginupDeadline := utils.GetTimeDateRemoveYearAndSecond(activityInfo.SiginupDeadline)
  150. popupMsg = siginupDeadline + "前取消报名,可返还点数"
  151. }
  152. if cancelDeadlineType == 2 {
  153. popupMsg = "活动开始前24小时取消报名,可返还点数"
  154. }
  155. if cancelDeadlineType == 3 {
  156. popupMsg = "活动开始前48小时取消报名,可返还点数"
  157. }
  158. return
  159. }
  160. // 校验取消报名截止时间
  161. func CheckCancelDeadline(activityInfo *models.ActivityDetail) (popupMsg string) {
  162. if !activityInfo.IsResearchPoints {
  163. return
  164. }
  165. //获取活动是否扣点以及扣点规则明细
  166. if activityInfo.CancelDeadline != utils.FormatDateTimeInit {
  167. timeResp := utils.StrTimeToTime(activityInfo.CancelDeadline)
  168. if timeResp.Before(time.Now()) {
  169. popupMsg = "当前时间点已无法取消报名,\n\n若想取消,请联系对口销售"
  170. }
  171. }
  172. return
  173. }
  174. // // 校验报名顺序 截止时间>点数>邮箱
  175. func CheckActivityUserAll(activityInfo *models.ActivityDetail, wxUser *models.WxUserItem) (popupMsg string, err error) {
  176. _, popupMsg = CheckSiginupDeadline(activityInfo)
  177. if popupMsg != "" {
  178. return
  179. }
  180. _, popupMsg, _, _, err = CheckActivityPoints(activityInfo, wxUser)
  181. if popupMsg != "" {
  182. return
  183. }
  184. _, popupMsg = CheckActivityUserEmail(activityInfo, wxUser)
  185. if popupMsg != "" {
  186. return
  187. }
  188. return
  189. }
  190. // 校验是否人员已满
  191. func CheckActivityUserSiginUpNum(activityInfo *models.ActivityDetail) (checkSiginUpNum bool, popupMsg string, err error) {
  192. checkSiginUpNum = true
  193. if activityInfo.IsLimitPeople == 0 {
  194. return
  195. }
  196. signupCount, e := models.GetActivitySignupSuccessByUserCountNoHz(activityInfo.ActivityId)
  197. if e != nil {
  198. err = errors.New("GetCygxActivityPointsSetDetail" + e.Error())
  199. return
  200. }
  201. if signupCount >= activityInfo.LimitPeopleNum {
  202. checkSiginUpNum = false
  203. popupMsg = "此活动报名人数已满,请留意下期活动"
  204. return
  205. }
  206. return
  207. }