package services import ( "errors" "fmt" "hongze/hongze_mfyx/models" "hongze/hongze_mfyx/utils" "time" ) // GetActivitySignupResp 处理用户的报名方式 func GetActivitySignupResp(activityIdS []int, user *models.WxUserItem) (mapItem map[int]int, err error) { var condition string var pars []interface{} lenActivityId := len(activityIdS) if lenActivityId == 0 || user.Mobile == "" { return } condition = ` AND do_fail_type = 0 AND activity_id IN (` + utils.GetOrmInReplace(lenActivityId) + `) AND mobile = ?` pars = append(pars, activityIdS, user.Mobile) listSignup, e := models.GetActivitySignupList(condition, pars) if e != nil { err = errors.New("GetResourceDataList, Err: " + e.Error()) return } mapItem = make(map[int]int, 0) for _, v := range listSignup { mapItem[v.ActivityId] = v.SignupType } return } // CheckActivitySignUpLimit 校验报名限制 func CheckActivitySignUpLimit(user *models.WxUserItem, activityInfo *models.ActivityDetail) (signupStatus, popupMsg string, failType int, err error) { //判断优先级:总人数限制→单机构2人限制→爽约3次限制 signupStatus = "Success" activityId := activityInfo.ActivityId //弘则下面的用户不做单机构两人限制、不受报名总人数限制 if user.CompanyId != utils.HZ_COMPANY_ID { totaSignupPeopleNum, e := models.GetActivitySignupSuccessByUserCountNoHz(activityId) if e != nil { err = errors.New("GetActivitySignupSuccessByUserCountNoHz, Err: " + e.Error()) return } if totaSignupPeopleNum >= activityInfo.LimitPeopleNum { signupStatus = "FullStarffed" popupMsg = "此活动报名人数已满,请留意下期活动" failType = 1 return } totalSignupCompany, e := models.GetActivitySignupCompanyCount(activityId, user.CompanyId) if e != nil { err = errors.New("GetActivitySignupCompanyCount, Err: " + e.Error()) return } if totalSignupCompany >= 2 { signupStatus = "TwoPeople" popupMsg = "单机构最多2人报名同一活动,您所在机构报名人数已满" failType = 2 return } } //totalRestrict, e := models.GetUserRestrictCount(user.Mobile) //if e != nil { // err = errors.New("GetUserRestrictCount, Err: " + e.Error()) // return //} //if totalRestrict >= 1 { // signupStatus = "BreakPromise" // popupMsg = "由于爽约次数过多,您暂时被限制报名资格,请联系对口销售" // failType = 3 // return //} return } // 校验报名截止时间 func CheckSiginupDeadline(activityInfo *models.ActivityDetail) (checkTime bool, popupMsg string) { checkTime = true if activityInfo.SiginupDeadline != utils.FormatDateTimeInit && activityInfo.SiginupDeadline != "" { timeResp := utils.StrTimeToTime(activityInfo.SiginupDeadline) if timeResp.Before(time.Now()) { checkTime = false popupMsg = "该活动已截止报名\n\n若想参加,请联系对口销售" } } return } // 校验报名点数 func CheckActivityPoints(activityInfo *models.ActivityDetail, wxUser *models.WxUserItem) (checkPoints bool, popupMsg, companyPoints, activityPoints string, err error) { checkPoints = true if activityInfo.IsResearchPoints { //获取活动对用户要扣的点 userPointsNum, e := models.GetCygxActivityPointsSetUserNum(activityInfo.ActivityId) if e != nil { err = errors.New("GetCygxActivityPointsSetUserNum, Err: " + e.Error()) return } // 获取用户所在公司剩余的点 companyPointsNum, e := models.GetCompanyPoints(wxUser.CompanyId) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetCompanyPoints, Err: " + e.Error()) return } activtyPayTotal := GetCygxOrderVirtualAssetdCountTotal(wxUser.Mobile, activityInfo.ActivityId) // 判断用户是否购买单场活动 if companyPointsNum-userPointsNum < 0 && activtyPayTotal == 0 { checkPoints = false var popupPriceMsg string if utils.IS_SHOW_WX_PAY { goodsList := GetGoodsInfoByActivity(activityInfo) //单场活动信息 for _, v := range goodsList { popupPriceMsg = v.PopupPriceMsg //价格弹窗信息 } popupMsg = "