package services import ( "errors" "fmt" "hongze/hongze_mfyx/models" "hongze/hongze_mfyx/utils" ) // AddctivitySignupDetailByJmcj 通过进门财经添加用户参数信息 func AddctivitySignupDetailByJmcjNew(itemsDetail []*models.CygxActivityAttendanceDetail, activityIds []int) (err error) { defer func() { if err != nil { fmt.Println(err) go utils.SendAlarmMsg("通过进门财经添加用户参数信息失败 ErrMsg:"+err.Error(), 2) } }() actLen := len(activityIds) var condition string var pars []interface{} if actLen > 0 { condition += ` AND activity_id IN (` + utils.GetOrmInReplace(actLen) + `)` pars = append(pars, activityIds) } signUpDetailList, err := models.GetSignupDetailList(condition, pars) if err != nil && err.Error() != utils.ErrNoRow() { return err } mapsignUpDetai := make(map[string]string) if len(signUpDetailList) > 0 { for _, v := range signUpDetailList { mapsignUpDetai[fmt.Sprint("ActivityId", v.ActivityId, "Mobile", v.Mobile)] = v.Mobile } } //获取当天已经结束了 活动的报名人数 signUpList, err := models.GetSignupDetailBySignup(condition, pars) if err != nil && err.Error() != utils.ErrNoRow() { return err } //建立外呼号与手机号的绑定 mapsignUp := make(map[string]string) if len(signUpList) > 0 { for _, v := range signUpList { mapsignUp[fmt.Sprint(v.OutboundMobile)] = v.Mobile } } var itemsAdd []*models.CygxActivitySignupDetail var itemsUpdate []*models.CygxActivitySignupDetail var mobiles []string mobileMap := make(map[string]bool) mobileUserMap := make(map[string]int) for _, v := range itemsDetail { if !mobileMap[v.Mobile] { mobiles = append(mobiles, v.Mobile) } mobileMap[v.Mobile] = true } //mobiles = make([]string, 0) //mobiles = append(mobiles, "13054631616") //根据手机号获取这些用户的信息 listUser, e := models.GetWxUserByOutboundMobiles(mobiles) if e != nil { err = errors.New("GetWxUserOutboundMobiles, Err: " + e.Error()) return } for _, v := range listUser { mobileUserMap[v.Mobile] = v.UserId } for _, v := range itemsDetail { var item = new(models.CygxActivitySignupDetail) item.ActivityId = v.ActivityId item.RealName = v.RealName //如果手机号存在那么就是报名的,不存在就是直接参与的 if _, ok := mapsignUp[v.Mobile]; ok { item.Mobile = mapsignUp[v.Mobile] } else { item.Mobile = v.Mobile } item.OutboundMobile = v.Mobile item.CompanyName = v.CompanyName item.CompanyId = v.CompanyId item.SellerName = v.SellerName item.FirstMeetingTime = v.FirstMeetingTime item.LastMeetingTime = v.LastMeetingTime item.Duration = v.Duration item.MeetingTypeStr = v.MeetingTypeStr item.MeetingAuthentication = v.MeetingAuthentication item.MeetingStatusStr = v.MeetingStatusStr item.CreateTime = v.CreateTime item.Position = v.Position item.IsMeeting = 1 item.UseridEntity = v.UseridEntity item.ActivityTime = v.ActivityTime item.CrmCompanyMapStatusId = v.CrmCompanyMapStatusId item.UserId = mobileUserMap[v.Mobile] if _, ok := mapsignUpDetai[fmt.Sprint("ActivityId", v.ActivityId, "Mobile", item.Mobile)]; !ok { itemsAdd = append(itemsAdd, item) } else { itemsUpdate = append(itemsUpdate, item) } } if len(itemsAdd) > 0 { err = models.AddCygxActivitySignupDetail(itemsAdd) if err != nil { return } } if len(itemsUpdate) > 0 { err = models.UpdateActivitySignupDetailMulti(itemsUpdate) if err != nil { return } } //获取所有研选扣点的活动,如果是就行扣点流水处理 mapActivityPoints, _ := GetActivityPointsAll() for _, v := range activityIds { if mapActivityPoints[v] { YanXuanActivityPointsBillSubmitMeeting(v, 0) } } return err }