|
@@ -591,6 +591,199 @@ func YanXuanActivityPointsBillActivityPublishAndCancelReduce(log models.YanXuanA
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// 5:活动到会研选扣点处理
|
|
|
+func YanXuanActivityPointsBillSubmitMeetingReduce(log models.YanXuanActivityPointsRedis) (err error) {
|
|
|
+ //func YanXuanActivityPointsBillSubmitMeetingReduce(activityId int) (err error) {
|
|
|
+ //defer func() {
|
|
|
+ // if err != nil {
|
|
|
+ // fmt.Println(err)
|
|
|
+ // go utils.SendAlarmMsg("活动到会研选扣点,处理Redis队列消息失败:"+err.Error()+fmt.Sprint("ActivityId", log.ActivityId, "adminId", log.AdminId), 2)
|
|
|
+ // }
|
|
|
+ //}()
|
|
|
+
|
|
|
+ activityId := log.ActivityId
|
|
|
+ publishStatus := log.PublishStatus
|
|
|
+ //comapnyId := log.ComapnyId
|
|
|
+
|
|
|
+ //获取活动是否扣点以及扣点规则明细
|
|
|
+ activityPointsSetDetail, e := models.GetCygxActivityPointsSetDetail(activityId)
|
|
|
+ if e != nil && e.Error() != utils.ErrNoRow() {
|
|
|
+ err = errors.New("GetCygxActivityPointsSetDetail" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if activityPointsSetDetail == nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if activityPointsSetDetail.PointsType != 2 {
|
|
|
+ return // 如果不是到会即扣点,的这种形式,那么就不做任何处理
|
|
|
+ }
|
|
|
+
|
|
|
+ activityInfo, e := models.GetAddActivityInfoByActivityId(activityId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetAddActivityInfoByActivityId" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ comapnyId := activityPointsSetDetail.CompanyId
|
|
|
+ var items []*models.CygxActivityPointsBill
|
|
|
+
|
|
|
+ var itemCompanys []*models.CygxActivityPointsCompany
|
|
|
+
|
|
|
+ if publishStatus == 1 {
|
|
|
+ fmt.Println("//活动发布")
|
|
|
+ if comapnyId > 0 {
|
|
|
+ comapny, e := models.GetCompanyById(comapnyId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetCompanyById" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 获取用户所在公司剩余的点
|
|
|
+ companyPointsNum, e := models.GetCompanyPoints(comapny.CompanyId)
|
|
|
+ if e != nil && e.Error() != utils.ErrNoRow() {
|
|
|
+ err = errors.New("GetCompanyPoints, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ item := new(models.CygxActivityPointsBill)
|
|
|
+ item.ActivityId = activityId
|
|
|
+ item.CreateTime = time.Now()
|
|
|
+ //item.Mobile = user.Mobile
|
|
|
+ //item.Email = user.Email
|
|
|
+ item.CompanyId = comapny.CompanyId
|
|
|
+ item.CompanyName = comapny.CompanyName
|
|
|
+ //item.RealName = user.RealName
|
|
|
+ item.BillDetailed = -activityPointsSetDetail.CompanyPointsNum
|
|
|
+ item.RegisterPlatform = log.RegisterPlatform
|
|
|
+ item.AdminId = log.AdminId
|
|
|
+ item.Source = log.Source
|
|
|
+ item.ChartPermissionId = activityInfo.ChartPermissionId
|
|
|
+ item.DoType = 1
|
|
|
+ item.Content = activityInfo.ActivityName + "--办会"
|
|
|
+ item.Points = companyPointsNum - activityPointsSetDetail.CompanyPointsNum
|
|
|
+ items = append(items, item)
|
|
|
+
|
|
|
+ //更新对应机构的剩余点数
|
|
|
+ itemCompany := new(models.CygxActivityPointsCompany)
|
|
|
+ itemCompany.CompanyId = comapny.CompanyId
|
|
|
+ itemCompany.Points = item.Points
|
|
|
+ itemCompany.ModifyTime = time.Now()
|
|
|
+ itemCompanys = append(itemCompanys, itemCompany)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ fmt.Println("//活动取消发布")
|
|
|
+ //活动取消发布
|
|
|
+ mapCompanyPoints := make(map[int]float64) //一组公司的剩余点数
|
|
|
+ if comapnyId > 0 {
|
|
|
+ comapny, e := models.GetCompanyById(comapnyId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetCompanyById" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 获取用户所在公司剩余的点
|
|
|
+ companyPointsNum, e := models.GetCompanyPoints(comapny.CompanyId)
|
|
|
+ if e != nil && e.Error() != utils.ErrNoRow() {
|
|
|
+ err = errors.New("GetCompanyPoints, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ item := new(models.CygxActivityPointsBill)
|
|
|
+ item.ActivityId = activityId
|
|
|
+ item.CreateTime = time.Now()
|
|
|
+ //item.Mobile = user.Mobile
|
|
|
+ //item.Email = user.Email
|
|
|
+ item.CompanyId = comapny.CompanyId
|
|
|
+ item.CompanyName = comapny.CompanyName
|
|
|
+ //item.RealName = user.RealName
|
|
|
+ item.BillDetailed = activityPointsSetDetail.CompanyPointsNum
|
|
|
+ item.RegisterPlatform = log.RegisterPlatform
|
|
|
+ item.AdminId = log.AdminId
|
|
|
+ item.Source = log.Source
|
|
|
+ item.ChartPermissionId = activityInfo.ChartPermissionId
|
|
|
+ item.DoType = 2
|
|
|
+ item.Content = activityInfo.ActivityName + "--取消办会"
|
|
|
+ item.Points = companyPointsNum + activityPointsSetDetail.CompanyPointsNum
|
|
|
+ items = append(items, item)
|
|
|
+ //更新对应机构的剩余点数
|
|
|
+ itemCompany := new(models.CygxActivityPointsCompany)
|
|
|
+ itemCompany.CompanyId = comapny.CompanyId
|
|
|
+ itemCompany.Points = item.Points
|
|
|
+ itemCompany.ModifyTime = time.Now()
|
|
|
+ itemCompanys = append(itemCompanys, itemCompany)
|
|
|
+ mapCompanyPoints[comapnyId] = item.Points
|
|
|
+ }
|
|
|
+
|
|
|
+ if activityPointsSetDetail.UserPointsNum > 0 && activityPointsSetDetail.PointsType == 1 {
|
|
|
+ //如果扣点形式选的是报名即扣点,那么就对已经报名的用户所在机构进行返点
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+ condition = ` AND do_fail_type = 0 AND activity_id = ?`
|
|
|
+ pars = append(pars, activityId)
|
|
|
+
|
|
|
+ listSignup, e := models.GetActivitySignupList(condition, pars)
|
|
|
+ if e != nil && e.Error() != utils.ErrNoRow() {
|
|
|
+ err = errors.New("GetActivitySignupList, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var companyIds []int
|
|
|
+ if len(listSignup) > 0 {
|
|
|
+ for _, v := range listSignup {
|
|
|
+ companyIds = append(companyIds, v.CompanyId)
|
|
|
+ }
|
|
|
+ pars = make([]interface{}, 0)
|
|
|
+ condition = ` AND company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `)`
|
|
|
+ pars = append(pars, companyIds)
|
|
|
+
|
|
|
+ //获取这些公司剩余的点数
|
|
|
+ conpanyList, e := models.GetCygxActivityPointsCompanyList(condition, pars)
|
|
|
+ if e != nil && e.Error() != utils.ErrNoRow() {
|
|
|
+ err = errors.New("GetCygxActivityPointsCompanyList, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range conpanyList {
|
|
|
+ if mapCompanyPoints[comapnyId] != 0 {
|
|
|
+ mapCompanyPoints[comapnyId] = v.Points
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, user := range listSignup {
|
|
|
+ item := new(models.CygxActivityPointsBill)
|
|
|
+ item.ActivityId = activityId
|
|
|
+ item.CreateTime = time.Now()
|
|
|
+ item.Mobile = user.Mobile
|
|
|
+ item.Email = user.Email
|
|
|
+ item.CompanyId = user.CompanyId
|
|
|
+ item.CompanyName = user.CompanyName
|
|
|
+ item.RealName = user.RealName
|
|
|
+ item.BillDetailed = activityPointsSetDetail.UserPointsNum
|
|
|
+ item.RegisterPlatform = log.RegisterPlatform
|
|
|
+ item.AdminId = log.AdminId
|
|
|
+ item.Source = log.Source
|
|
|
+ item.ChartPermissionId = activityInfo.ChartPermissionId
|
|
|
+ item.DoType = 2
|
|
|
+ item.Content = activityInfo.ActivityName + "--取消活动"
|
|
|
+ mapCompanyPoints[comapnyId] += activityPointsSetDetail.UserPointsNum //通过map处理机构剩余点数
|
|
|
+ item.Points = mapCompanyPoints[comapnyId]
|
|
|
+ items = append(items, item)
|
|
|
+
|
|
|
+ //更新对应机构的剩余点数
|
|
|
+ itemCompany := new(models.CygxActivityPointsCompany)
|
|
|
+ itemCompany.CompanyId = user.CompanyId
|
|
|
+ itemCompany.Points = item.Points
|
|
|
+ itemCompany.ModifyTime = time.Now()
|
|
|
+ itemCompanys = append(itemCompanys, itemCompany)
|
|
|
+ mapCompanyPoints[comapnyId] = item.Points
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ e = models.AddCygxActivityPointsBillMulti(items, itemCompanys)
|
|
|
+ if e != nil && e.Error() != utils.ErrNoRow() {
|
|
|
+ err = errors.New("AddCygxActivityPointsBillMulti, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// 6:研选审批通过的时候研选扣点更新
|
|
|
func YanXuanCompanyApprovalReduce(log models.YanXuanActivityPointsRedis) (err error) {
|
|
|
defer func() {
|