123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- package services
- import (
- "context"
- "errors"
- "fmt"
- "hongze/hongze_cygx/models"
- "hongze/hongze_cygx/utils"
- )
- // AddctivitySignupDetail 获取当天已结束的活动的报名信息。添加到到会详情
- func AddctivitySignupDetail(cont context.Context) (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- go utils.SendAlarmMsg(" 获取当天已结束的活动的报名信息。添加到到会详情失败, ErrMsg:"+err.Error(), 2)
- }
- }()
- actList, err := models.GetActivitySattusToComplete()
- if err != nil && err.Error() != utils.ErrNoRow() {
- return err
- }
- if len(actList) == 0 {
- return err
- }
- activityIds := make([]int, 0)
- for _, v := range actList {
- activityIds = append(activityIds, v.ActivityId)
- }
- actLen := len(activityIds)
- var condition string
- var pars []interface{}
- if actLen > 0 {
- condition += ` AND activity_id IN (` + utils.GetOrmInReplace(actLen) + `)`
- pars = append(pars, activityIds)
- } else {
- return err
- }
- //condition = ""
- //获取当天已经结束了 活动的报名人数
- signUpList, err := models.GetSignupDetailBySignup(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- return err
- }
- 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
- }
- }
- var items []*models.CygxActivitySignupDetail
- if len(signUpList) > 0 {
- for _, v := range signUpList {
- if _, ok := mapsignUpDetai[fmt.Sprint("ActivityId", v.ActivityId, "Mobile", v.Mobile)]; !ok {
- item := new(models.CygxActivitySignupDetail)
- item.UserId = v.UserId
- item.RealName = v.RealName
- item.SellerName = v.SellerName
- item.ActivityId = v.ActivityId
- item.CreateTime = v.CreateTime
- item.Mobile = v.Mobile
- item.OutboundMobile = v.OutboundMobile
- item.Email = v.Email
- item.CompanyId = v.CompanyId
- item.CompanyName = v.CompanyName
- item.SignupType = v.SignupType
- item.FailType = v.FailType
- item.DoFailType = v.DoFailType
- items = append(items, item)
- if len(items)%2000 == 0 {
- err = models.AddCygxActivitySignupDetail(items)
- if err != nil {
- return
- }
- items = make([]*models.CygxActivitySignupDetail, 0)
- }
- }
- }
- }
- if len(items) > 0 {
- err = models.AddCygxActivitySignupDetail(items)
- if err != nil {
- return
- }
- }
- return err
- }
- // AddctivitySignupDetailByJmcjNew 通过进门财经添加用户参数信息
- 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
- }
- //func init() {
- // var err error
- // defer func() {
- // if err != nil {
- // fmt.Println(err)
- // }
- // }()
- // var condition string
- // var pars []interface{}
- // condition = " AND user_id = 0 AND company_id > 1 AND mobile != '' "
- // signUpDetailList, e := models.GetSignupDetailList(condition, pars)
- // if e != nil && e.Error() != utils.ErrNoRow() {
- // err = errors.New("GetSignupDetailList, Err: " + e.Error())
- // return
- // }
- // var mobiles []string
- // mobileMap := make(map[string]bool)
- // for _, v := range signUpDetailList {
- // 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
- // }
- //
- // var itemsUpdate []*models.CygxActivitySignupDetail
- // for _, v := range listUser {
- // item := new(models.CygxActivitySignupDetail)
- // item.UserId = v.UserId
- // item.Mobile = v.Mobile
- // itemsUpdate = append(itemsUpdate, item)
- // }
- // fmt.Println(len(itemsUpdate))
- // err = models.UpdateActivitySignupDetailMultiMobileAndUserId(itemsUpdate)
- //}
|