1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123 |
- package cygx
- import (
- "encoding/json"
- "errors"
- "fmt"
- "hongze/hz_crm_api/models/cygx"
- "hongze/hz_crm_api/services/alarm_msg"
- "hongze/hz_crm_api/utils"
- "io/ioutil"
- "net/http"
- "strconv"
- "strings"
- "time"
- )
- type ApifoxModalSingUpClass struct {
- ErrorCode *string `json:"errorCode"` // 错误码,001:活动不存在;002:该活动不支持此渠道报名;003:该手机号或邮箱已经被其他账号提交报名;004:不在报名时间;005:报名人数已满
- ErrorMsg *string `json:"errorMsg"` // 错误信息
- Result SingUpMap `json:"result"` // 结果Map,成功
- Success bool `json:"success"` // 成功标识,true:成功;false:失败。可作为判断报名是否成功的标识
- Timestamp float64 `json:"timestamp"` // 时间戳
- }
- type SingUpMap struct {
- Msg string `json:"msg"` // 请求信息,成功信息
- }
- type GetYidongTokenResp struct {
- Success bool `json:"success"` // 请求信息,成功信息
- AccessToken string `json:"access_token"` // token
- ExpiresIn int `json:"expires_in"` // 过期时间
- }
- // 易董建会成功返回的结构体
- type YiDongSaveRoadshowDetailResp struct {
- ErrorCode string `json:"errorCode"` // 错误码
- ErrorMsg string `json:"errorMsg"` // 错误信息
- Success bool `json:"success"` // 请求信息,成功信息
- Result YiDongSaveRoadshowDetailIdResp `json:"result"` // 返回信息
- }
- type YiDongSaveRoadshowDetailIdResp struct {
- ActivityId string `json:"activityId"` //易董返回的活动ID
- }
- type YiDongUpdateActivityPublishResp struct {
- Id string `description:"易董活动ID,为空时新增,非空时修改" json:"id"`
- PublishFlag string `description:"发布状态,1发布 0 取消发布" json:"publishFlag"`
- }
- // 获取路演详细信息(2.0)结构体
- type YiDongGetRoadshowDetailResp struct {
- ErrorCode string `json:"errorCode"` // 错误码
- ErrorMsg string `json:"errorMsg"` // 错误信息
- Success bool `json:"success"` // 请求信息,成功信息
- Result YiDongGetRoadshowDetailRespResult `json:"result"` // 返回信息
- }
- type YiDongGetRoadshowDetailRespResult struct {
- MeetingCode string `json:"meetingCode"` //腾讯会议号
- }
- // 获取创建人信息列表(新)结构体
- type YiDongGetCreateUserListResp struct {
- ErrorCode string `json:"errorCode"` // 错误码
- ErrorMsg string `json:"errorMsg"` // 错误信息
- Success bool `json:"success"` // 请求信息,成功信息
- Result YiDongGetCreateUserListResult `json:"result"` // 返回信息
- }
- type YiDongGetCreateUserListResult struct {
- PersonList []*PersonUser
- }
- type PersonUser struct {
- Id string `description:"人员id" json:"id"`
- PersonName string `description:"姓名" json:"personName"`
- JobName string `description:"职务" json:"jobName"`
- UserId string `description:"用户id" json:"userId"`
- UserName string `description:"用户账号" json:"userName"`
- IdentityType string `description:"身份类型:0 不可用,1可用" json:"identityType"`
- Lock bool `description:"锁定状态:true 锁定 false 未锁定" json:"lock"`
- CreatePersonName string `description:"创建人姓名:创建时必填" json:"createPersonName"`
- }
- type YidongActivityResult struct {
- ActivityJoinType string `json:"activityJoinType"` // 活动入会类型,01报名审核后可入会 02预约即可入会 03仅定向邀请人员可入会
- Banner string `json:"banner"` // 宣传图
- BusinessCardOpen string `json:"businessCardOpen"` // 上传名片是否开启,1是 0否
- BusinessCardRequired string `json:"businessCardRequired"` // 上传名片是否必填,1是 0否
- CertificateInformationOpen string `json:"certificateInformationOpen"` // 证件信息是否开启,1是 0否
- CertificateInformationRequired string `json:"certificateInformationRequired"` // 证件信息是否必填,1是 0否
- CompanyCodeOpen string `json:"companyCodeOpen"` // 公司代码是否开启,1是 0否
- CompanyCodeRequired string `json:"companyCodeRequired"` // 公司代码是否必填,1是 0否
- CompanyInfo string `json:"companyInfo"` // 公司名称
- CompanyShortNameOpen string `json:"companyShortNameOpen"` // 公司名称是否开启,1是 0否
- CompanyShortNameRequired string `json:"companyShortNameRequired"` // 公司名称是否必填,1是 0否
- End string `json:"end"` // 活动结束时间
- ID string `json:"id"` // 活动主键id
- IndustrySwName string `json:"industrySwName"` // 行业
- InviteeOpen *string `json:"inviteeOpen"` // 邀请机构是否开启,1是 0否
- InviteeRequired *string `json:"inviteeRequired"` // 邀请机构是否必填,1是 0否
- JobNameOpen string `json:"jobNameOpen"` // 职务是否开启,1是 0否
- JobNameRequired string `json:"jobNameRequired"` // 职务是否必填,1是 0否
- MailOpen string `json:"mailOpen"` // 邮箱是否开启,1是 0否
- MailRequired string `json:"mailRequired"` // 邮箱是否必填,1是 0否
- PersonNameOpen string `json:"personNameOpen"` // 姓名是否开启,1是 0否
- PersonNameRequired string `json:"personNameRequired"` // 姓名是否必填,1是 0否
- PersonTelephoneOpen string `json:"personTelephoneOpen"` // 手机号是否开启,1是 0否
- PersonTelephoneRequired string `json:"personTelephoneRequired"` // 手机号是否必填,1是 0否
- SignUpEnd string `json:"signUpEnd"` // 报名结束时间,适应于报名审核后可入会,为空表示不限制报名时间
- SignUpStart string `json:"signUpStart"` // 报名开始时间,适应于报名审核后可入会,为空表示不限制报名时间
- Start string `json:"start"` // 活动开始时间
- SyncFlag string `json:"syncFlag"` // 同步有效性,同步有效性 1有效,0失效
- Title string `json:"title"` // 活动主题
- Type string `json:"type"` // 路演类型
- URL string `json:"url"` // 活动短链接
- }
- type YidongApifoxModal struct {
- ErrorCode interface{} `json:"errorCode"`
- ErrorMsg interface{} `json:"errorMsg"`
- Result []YidongActivityResult `json:"result"`
- Success bool `json:"success"`
- Timestamp int64 `json:"timestamp"`
- }
- type YidongResultuser struct {
- DeviceType string `json:"deviceType"` // 参会方式,1-PC,2-Mac,3-Android,4-IOS,5-Web,6-iPad,7-Android Pad,8-小程序,0-PSTN
- Duration string `json:"duration"` // 云会议参会时长
- DurationInteract string `json:"durationInteract"` // 互动交流参会时长
- DurationLive string `json:"durationLive"` // 直播参会时长
- DurationReview string `json:"durationReview"` // 回看参会时长
- EndTime string `json:"endTime"` // 云会议最后退会时间
- EndTimeInteract string `json:"endTimeInteract"` // 互动交流最后退会时间
- EndTimeLive string `json:"endTimeLive"` // 直播最后退会时间
- EndTimeReview string `json:"endTimeReview"` // 回看最后退会时间
- ID string `json:"id"` // 主键id
- Mail string `json:"mail" comment:"电子邮件"`
- CompanyName string `json:"company_name" comment:"公司名称"`
- JobName string `json:"jobName"` // 职务
- MobileCountryCode string `json:"mobileCountryCode"` // 手机号国际区号码
- PersonName string `json:"personName"` // 姓名
- PersonTelephone string `json:"personTelephone"` // 用户手机号
- StartTime string `json:"startTime"` // 云会议最早入会时间
- StartTimeInteract string `json:"startTimeInteract"` // 互动交流最早入会时间
- StartTimeLive string `json:"startTimeLive"` // 直播最早入会时间
- StartTimeReview string `json:"startTimeReview"` // 回看最早入会时间
- Status string `json:"status"` // 状态,D表示被删除
- UserID string `json:"userId,omitempty"` // 用户id
- SignUpStatus string `json:"sign_up_status" comment:"报名状态"`
- }
- // CheckYidongActivitySignupTime 校验易董的活动是否可以 添加报名
- func CheckYidongActivitySignupTime(activityInfo *cygx.ActivityDetail) (errstr string) {
- if activityInfo.YidongSignUpEnd == "0000-00-00 00:00:00" {
- return
- }
- timeStart := activityInfo.YidongSignUpStart
- timeEnd := activityInfo.YidongSignUpEnd
- resultTimeStart := utils.StrTimeToTime(timeStart) //时间字符串格式转时间格式
- resStart := time.Now().Before(resultTimeStart)
- if resStart {
- errstr = "当前时间不可报名!"
- }
- resultTimeEnd := utils.StrTimeToTime(timeEnd) //时间字符串格式转时间格式
- resend := time.Now().After(resultTimeEnd)
- if resend {
- errstr = "当前时间不可报名!"
- }
- return
- }
- // YidongActivityUserSingnUp 易董的活动添加报名
- func YidongActivityUserSingnUp(items []*cygx.YidongActivitySignup) (err error) {
- url := utils.YiDongHuaWeiYunUrl + "app/hz/signAppointmentsForThird"
- method := "POST"
- for _, v := range items {
- defer func() {
- if err != nil {
- go alarm_msg.SendAlarmMsg("易董的活动添加报名消息失败,Err:"+err.Error(), 3)
- }
- }()
- payload := strings.NewReader(`{
- "activityId": "` + v.YidongActivityId + `",
- "personTelephone":"` + v.Mobile + `",
- "personName": "` + v.RealName + `",
- "companyName": "` + v.CompanyName + `",
- "mobileCountryCode": "+` + v.CountryCode + `",
- "thirdPartySource": "01"
- }`)
- client := &http.Client{}
- req, err := http.NewRequest(method, url, payload)
- if err != nil {
- fmt.Println(err)
- utils.FileLog.Info(err.Error())
- return err
- }
- req.Header.Add("Content-Type", "application/json")
- res, err := client.Do(req)
- if err != nil {
- fmt.Println(err)
- utils.FileLog.Info(err.Error())
- return err
- }
- defer res.Body.Close()
- var ApifoxModal *ApifoxModalSingUpClass
- body, err := ioutil.ReadAll(res.Body)
- if err != nil {
- fmt.Println(err)
- utils.FileLog.Info(err.Error())
- return err
- }
- itemApiLog := new(cygx.CygxThreeApiLog)
- itemApiLog.CreateTime = time.Now()
- itemApiLog.Source = 1
- itemApiLog.Url = url
- itemApiLog.Body = utils.ReplaceSpaceAndWrap(fmt.Sprint(payload))
- itemApiLog.Result = string(body)
- go cygx.AddCygxThreeApiLog(itemApiLog)
- err = json.Unmarshal(body, &ApifoxModal)
- }
- return
- }
- // GetYidongToken 获取易董证通云接口的token
- func GetYidongToken() (token string, err error) {
- defer func() {
- if err != nil {
- go alarm_msg.SendAlarmMsg("获取易董证通云接口的token失败;err:"+err.Error(), 3)
- }
- }()
- cacheKey := utils.YI_DONG_ZHENG_TONG_YUN_TOKEN_KEY
- ttlTime := utils.Rc.GetRedisTTL(cacheKey)
- if ttlTime > 0 {
- token, _ = utils.Rc.RedisString(cacheKey)
- if token != "" {
- return
- }
- }
- url := utils.YiDongZhengTongYunUrl + "oauth/token?grant_type=client_credentials&response_type=token&client_id=" + utils.YiDongZhengTongYunClientId + "&client_secret=" + utils.YiDongZhengTongYunClientSecret
- method := "GET"
- client := &http.Client{}
- req, err := http.NewRequest(method, url, nil)
- if err != nil {
- return
- }
- res, err := client.Do(req)
- if err != nil {
- return
- }
- defer res.Body.Close()
- body, err := ioutil.ReadAll(res.Body)
- if err != nil {
- return
- }
- itemApiLog := new(cygx.CygxThreeApiLog)
- itemApiLog.CreateTime = time.Now()
- itemApiLog.Source = 1
- itemApiLog.Url = url
- itemApiLog.Body = ""
- itemApiLog.Result = string(body)
- go cygx.AddCygxThreeApiLog(itemApiLog)
- var yidongTokenResp *GetYidongTokenResp
- err = json.Unmarshal(body, &yidongTokenResp)
- if err != nil {
- return
- }
- token = yidongTokenResp.AccessToken
- err = utils.Rc.Put(cacheKey, token, time.Second*7000)
- if err != nil {
- return
- }
- return
- }
- // 易董创建/更新路演活动结构体
- type SaveRoadshowDetaiParam struct {
- Id string `description:"易董活动ID,为空时新增,非空时修改" json:"id"`
- PublishFlag string `description:"发布状态,1发布 0 取消发布" json:"publishFlag"`
- Title string `description:"主题" json:"title"`
- Type string `description:"类型:投资策略、深度解读、行业分析、公司分析、自定义活动" json:"type"`
- Start string `description:"开始时间:开始时间与结束时间,日期必须相同" json:"start"`
- End string `description:"结束时间:开始时间与结束时间,日期必须相同" json:"end"`
- CreateUserId string `description:"创建人userId:创建时必填" json:"createUserId"`
- CreatePersonName string `description:"创建人姓名:创建时必填" json:"createPersonName"`
- }
- // 获取创建人信息列表(新)
- func YiDongGetCreateUserList() (userId string) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go alarm_msg.SendAlarmMsg("获取创建人信息列表(新)失败;err:"+err.Error(), 3)
- }
- }()
- token, _ := GetYidongToken()
- if token == "" {
- return
- }
- url := utils.YiDongZhengTongYunUrl + "interact/activityThirdApi/getCreateUserList" + "?access_token=" + token
- method := "POST"
- client := &http.Client{}
- req, err := http.NewRequest(method, url, strings.NewReader(""))
- if err != nil {
- fmt.Println(err)
- return
- }
- req.Header.Add("Content-Type", "application/json")
- res, err := client.Do(req)
- if err != nil {
- fmt.Println(err)
- return
- }
- defer res.Body.Close()
- body, err := ioutil.ReadAll(res.Body)
- if err != nil {
- fmt.Println(err)
- return
- }
- itemApiLog := new(cygx.CygxThreeApiLog)
- itemApiLog.CreateTime = time.Now()
- itemApiLog.Source = 1
- itemApiLog.Url = url
- itemApiLog.Body = ""
- itemApiLog.Result = string(body)
- go cygx.AddCygxThreeApiLog(itemApiLog)
- var yidongResp *YiDongGetCreateUserListResp
- err = json.Unmarshal(body, &yidongResp)
- if err != nil {
- return
- }
- if !yidongResp.Success {
- err = errors.New("获取创建人信息列表(新) 接口失败," + yidongResp.ErrorCode + yidongResp.ErrorMsg)
- return
- }
- if len(yidongResp.Result.PersonList) > 0 {
- for _, v := range yidongResp.Result.PersonList {
- if v.PersonName == "高亦文" {
- userId = v.UserId
- }
- }
- }
- if userId == "" {
- err = errors.New("获取创建人信息列表(新) 接口失败," + yidongResp.ErrorCode + yidongResp.ErrorMsg + string(body))
- return
- }
- return
- }
- //func init() {
- // YiDongUpdateActivityPublish(2149)
- //}
- // YiDongSaveRoadshowDetail 创建/更新路演活动(新)
- func YiDongSaveRoadshowDetail(activityId int) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go alarm_msg.SendAlarmMsg("活动同步到易董失败;err:"+err.Error(), 3)
- }
- }()
- activityInfo, err := cygx.GetAddActivityInfoById(activityId)
- if err != nil {
- fmt.Println(err)
- return
- }
- if activityInfo == nil {
- return
- }
- if activityInfo.IsYidongConduct == 0 {
- return
- }
- token, _ := GetYidongToken()
- if token == "" {
- return
- }
- //C类分析师电话会 不对外发布
- if activityInfo.ActivityTypeId == 7 || activityInfo.IsBClass == 1 {
- activityInfo.PublishStatus = 0
- }
- //if activityInfo.PublishStatus == 0 {
- // return
- //}
- //获取高亦文在易董的用户ID
- var createUserId string
- createUserId = YiDongGetCreateUserList()
- url := utils.YiDongZhengTongYunUrl + "interact/activityThirdApi/saveRoadshowDetail" + "?access_token=" + token
- startTime := activityInfo.ActivityTime
- endTime := utils.StrTimeToTime(startTime).Add(time.Minute * 60).Format(utils.FormatDateTime) // 30分钟后为结束时间
- params := SaveRoadshowDetaiParam{
- Id: activityInfo.YidongActivityIdByCygx,
- PublishFlag: strconv.Itoa(activityInfo.PublishStatus),
- Title: activityInfo.ActivityName,
- Type: "行业分析",
- Start: startTime,
- End: endTime,
- CreateUserId: createUserId,
- CreatePersonName: "高亦文",
- }
- postData, err := json.Marshal(params)
- if err != nil {
- fmt.Println("PostData json.Marshal Err:" + err.Error())
- utils.FileLogCygx.Info("PostData json.Marshal Err:" + err.Error())
- return
- }
- method := "POST"
- client := &http.Client{}
- req, err := http.NewRequest(method, url, strings.NewReader(string(postData)))
- if err != nil {
- fmt.Println(err)
- return
- }
- req.Header.Add("Content-Type", "application/json")
- res, err := client.Do(req)
- if err != nil {
- fmt.Println(err)
- return
- }
- defer res.Body.Close()
- body, err := ioutil.ReadAll(res.Body)
- if err != nil {
- fmt.Println(err)
- return
- }
- itemApiLog := new(cygx.CygxThreeApiLog)
- itemApiLog.CreateTime = time.Now()
- itemApiLog.Source = 1
- itemApiLog.Url = url
- itemApiLog.Body = string(postData)
- itemApiLog.Result = string(body)
- go cygx.AddCygxThreeApiLog(itemApiLog)
- var yidongResp *YiDongSaveRoadshowDetailResp
- err = json.Unmarshal(body, &yidongResp)
- if err != nil {
- return
- }
- if !yidongResp.Success {
- err = errors.New("更新易董建会接口失败," + yidongResp.ErrorCode + yidongResp.ErrorMsg)
- return
- }
- yidongActivityIdByCygx := yidongResp.Result.ActivityId
- YiDongGetRoadshowDetail(activityId, yidongActivityIdByCygx) //获取易董创建的腾讯会议详情,并写入到我们自己的小程序
- YiDongSignAppointmentsForThirdSpeaker(activityId) // 根据填入的主讲人姓名 以嘉宾的身份自动报名
- }
- // YiDongGetRoadshowDetail 获取易董创建的腾讯会议详情,并写入到我们自己的小程序
- func YiDongGetRoadshowDetail(activityId int, yidongActivityIdByCygx string) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go alarm_msg.SendAlarmMsg("易董获取路演详细信息(2.0);err:"+err.Error(), 3)
- }
- }()
- activityInfo, err := cygx.GetAddActivityInfoById(activityId)
- if err != nil {
- fmt.Println(err)
- return
- }
- if activityInfo == nil {
- return
- }
- token, _ := GetYidongToken()
- if token == "" {
- return
- }
- activityInfo.YidongActivityIdByCygx = yidongActivityIdByCygx
- url := utils.YiDongZhengTongYunUrl + "interact/activityManageApi/getRoadshowDetail" + "?access_token=" + token
- if activityInfo.IsYidongConduct == 0 {
- return
- }
- params := YiDongSaveRoadshowDetailIdResp{
- ActivityId: yidongActivityIdByCygx,
- }
- postData, err := json.Marshal(params)
- if err != nil {
- fmt.Println("PostData json.Marshal Err:" + err.Error())
- utils.FileLogCygx.Info("PostData json.Marshal Err:" + err.Error())
- return
- }
- method := "POST"
- client := &http.Client{}
- req, err := http.NewRequest(method, url, strings.NewReader(string(postData)))
- if err != nil {
- fmt.Println(err)
- return
- }
- req.Header.Add("Content-Type", "application/json")
- res, err := client.Do(req)
- if err != nil {
- fmt.Println(err)
- return
- }
- defer res.Body.Close()
- body, err := ioutil.ReadAll(res.Body)
- if err != nil {
- fmt.Println(err)
- return
- }
- itemApiLog := new(cygx.CygxThreeApiLog)
- itemApiLog.CreateTime = time.Now()
- itemApiLog.Source = 1
- itemApiLog.Url = url
- itemApiLog.Body = string(postData)
- itemApiLog.Result = string(body)
- go cygx.AddCygxThreeApiLog(itemApiLog)
- var yidongResp *YiDongGetRoadshowDetailResp
- err = json.Unmarshal(body, &yidongResp)
- if err != nil {
- return
- }
- if !yidongResp.Success {
- err = errors.New("易董获取路演详细信息(2.0)接口失败," + yidongResp.ErrorCode + yidongResp.ErrorMsg)
- return
- }
- MeetingCode := yidongResp.Result.MeetingCode
- if activityInfo.TencentConferenceNumber != "" {
- activityInfo.Body = strings.Replace(activityInfo.Body, activityInfo.TencentConferenceNumber, MeetingCode, -1)
- } else {
- activityInfo.Body += "<p>腾讯会议号:" + MeetingCode + "</p>"
- }
- activityInfo.TencentConferenceNumber = MeetingCode
- err = cygx.UpdateCygxActivityTencentConferenceNumber(activityInfo)
- return
- }
- // 发布路演到活动广场(新)
- func YiDongUpdateActivityPublish(activityId int) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go alarm_msg.SendAlarmMsg("发布路演到活动广场(新);err:"+err.Error(), 3)
- }
- }()
- activityInfo, err := cygx.GetAddActivityInfoById(activityId)
- if err != nil {
- fmt.Println(err)
- return
- }
- if activityInfo == nil {
- return
- }
- //C类分析师电话会 不对外发布
- if activityInfo.ActivityTypeId == 7 {
- activityInfo.PublishStatus = 0
- }
- token, _ := GetYidongToken()
- if token == "" {
- return
- }
- url := utils.YiDongZhengTongYunUrl + "interact/activityThirdApi/updateActivityPublish" + "?access_token=" + token
- if activityInfo.IsYidongConduct == 0 || activityInfo.YidongActivityIdByCygx == "" {
- return
- }
- params := YiDongUpdateActivityPublishResp{
- Id: activityInfo.YidongActivityIdByCygx,
- PublishFlag: strconv.Itoa(activityInfo.PublishStatus),
- }
- postData, err := json.Marshal(params)
- if err != nil {
- fmt.Println("PostData json.Marshal Err:" + err.Error())
- utils.FileLogCygx.Info("PostData json.Marshal Err:" + err.Error())
- return
- }
- method := "POST"
- client := &http.Client{}
- req, err := http.NewRequest(method, url, strings.NewReader(string(postData)))
- if err != nil {
- fmt.Println(err)
- return
- }
- req.Header.Add("Content-Type", "application/json")
- res, err := client.Do(req)
- if err != nil {
- fmt.Println(err)
- return
- }
- defer res.Body.Close()
- body, err := ioutil.ReadAll(res.Body)
- if err != nil {
- fmt.Println(err)
- return
- }
- itemApiLog := new(cygx.CygxThreeApiLog)
- itemApiLog.CreateTime = time.Now()
- itemApiLog.Source = 1
- itemApiLog.Url = url
- itemApiLog.Body = string(postData)
- itemApiLog.Result = string(body)
- go cygx.AddCygxThreeApiLog(itemApiLog)
- var yidongResp *YiDongGetRoadshowDetailResp
- err = json.Unmarshal(body, &yidongResp)
- if err != nil {
- return
- }
- if !yidongResp.Success {
- err = errors.New("发布路演到活动广场(新) 接口失败," + yidongResp.ErrorCode + yidongResp.ErrorMsg)
- return
- }
- if activityInfo.PublishStatus == 0 {
- YiDongUpdateActivityStatus(activityId)
- }
- return
- }
- // 易董创建/更新路演活动结构体
- type SignAppointmentsForThirdParam struct {
- ActivityId string `description:"易董活动ID" json:"activityId"`
- MobileCountryCode string `description:"国际区号注意要带前面+号 " json:"mobileCountryCode"`
- PersonTelephone string `description:"手机号" json:"personTelephone"`
- ThirdPartySource string `description:"第三方来源;弘则固定:01" json:"thirdPartySource"`
- InvestorType string `description:"投资者类型 0个人1机构" json:"investorType"`
- PersonName string `description:"姓名" json:"personName"`
- CompanyName string `description:"公司名" json:"companyName"`
- JoinRole string `description:"1:嘉宾, 2:普通参会人员, 3:会议助理。不传默认取值2" json:"joinRole"`
- OutCallStatus string `description:"1:需要,0:不需要。不传取默认值0" json:"outCallStatus"`
- }
- type YiDongSignAppointmentsForThirdResp struct {
- ErrorCode string `json:"errorCode"` // 错误码,001:活动不存在;002:该活动不支持此渠道报名;003:该手机号或邮箱已经被其他账号提交报名;004:不在报名时间;005:报名人数已满
- ErrorMsg string `json:"errorMsg"` // 错误信息
- Success bool `json:"success"` // 成功标识,true:成功;false:失败。可作为判断报名是否成功的标识
- Timestamp float64 `json:"timestamp"` // 时间戳
- }
- // 根据填入的主讲人姓名 以嘉宾的身份自动报名
- func YiDongSignAppointmentsForThirdSpeaker(activityId int) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go alarm_msg.SendAlarmMsg("易董获取路演详细信息(2.0);err:"+err.Error(), 3)
- }
- }()
- activityInfo, err := cygx.GetAddActivityInfoById(activityId)
- if err != nil {
- fmt.Println(err)
- return
- }
- if activityInfo == nil {
- return
- }
- speaker := activityInfo.Speaker
- if speaker == "" {
- return
- }
- // 获取admin列表-匹配联系人是否为admin用户
- sysUserList, err := cygx.GetAskEmail()
- var personNameites []*cygx.AskEmailRep
- if err != nil {
- return
- }
- //var personName string
- //var personTelephone string
- for _, v := range sysUserList {
- if strings.Contains(speaker, v.Name) && v.Mobile != "" {
- personNameites = append(personNameites, &cygx.AskEmailRep{
- Name: v.Name,
- Mobile: v.Mobile,
- })
- }
- }
- if activityInfo.IsYidongConduct == 0 || len(personNameites) == 0 {
- return
- }
- url := utils.YiDongHuaWeiYunUrl + "app/hz/signAppointmentsForThird"
- for _, v := range personNameites {
- params := SignAppointmentsForThirdParam{
- ActivityId: activityInfo.YidongActivityIdByCygx,
- MobileCountryCode: "+86",
- PersonTelephone: v.Mobile,
- ThirdPartySource: "01",
- InvestorType: "0",
- PersonName: v.Name,
- JoinRole: "1",
- CompanyName: "弘则研究",
- OutCallStatus: "0",
- }
- postData, err := json.Marshal(params)
- if err != nil {
- fmt.Println("PostData json.Marshal Err:" + err.Error())
- utils.FileLogCygx.Info("PostData json.Marshal Err:" + err.Error())
- return
- }
- method := "POST"
- client := &http.Client{}
- req, err := http.NewRequest(method, url, strings.NewReader(string(postData)))
- if err != nil {
- fmt.Println(err)
- return
- }
- req.Header.Add("Content-Type", "application/json")
- res, err := client.Do(req)
- if err != nil {
- fmt.Println(err)
- return
- }
- defer res.Body.Close()
- body, err := ioutil.ReadAll(res.Body)
- if err != nil {
- fmt.Println(err)
- return
- }
- itemApiLog := new(cygx.CygxThreeApiLog)
- itemApiLog.CreateTime = time.Now()
- itemApiLog.Source = 1
- itemApiLog.Url = url
- itemApiLog.Body = string(postData)
- itemApiLog.Result = string(body)
- go cygx.AddCygxThreeApiLog(itemApiLog)
- var yidongResp *YiDongSignAppointmentsForThirdResp
- err = json.Unmarshal(body, &yidongResp)
- if err != nil {
- return
- }
- if !yidongResp.Success {
- err = errors.New(" 根据填入的主讲人姓名 以嘉宾的身份自动报名 接口失败," + yidongResp.ErrorCode + yidongResp.ErrorMsg)
- return
- }
- }
- return
- }
- //func init() {
- // YiDongUpdateActivityStatus(2180)
- //}
- // 删除路演活动(新)
- func YiDongUpdateActivityStatus(activityId int) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go alarm_msg.SendAlarmMsg(" 删除路演活动(新);err:"+err.Error(), 3)
- }
- }()
- activityInfo, err := cygx.GetAddActivityInfoById(activityId)
- if err != nil {
- fmt.Println(err)
- return
- }
- if activityInfo == nil {
- return
- }
- //C类分析师电话会 不对外发布
- if activityInfo.ActivityTypeId == 7 {
- activityInfo.PublishStatus = 0
- }
- //如果关联的易董活动ID为空,那么不做处理
- if activityInfo.YidongActivityIdByCygx == "" {
- return
- }
- //如果状态是已发布,而且是易董办会那么就不做处理
- if activityInfo.IsYidongConduct == 1 && activityInfo.PublishStatus == 1 {
- return
- }
- token, _ := GetYidongToken()
- if token == "" {
- return
- }
- url := utils.YiDongZhengTongYunUrl + "interact/activityThirdApi/updateActivityStatus" + "?access_token=" + token
- //if activityInfo.IsYidongConduct == 0 || activityInfo.YidongActivityIdByCygx == "" {
- // return
- //}
- params := YiDongUpdateActivityPublishResp{
- Id: activityInfo.YidongActivityIdByCygx,
- }
- postData, err := json.Marshal(params)
- if err != nil {
- fmt.Println("PostData json.Marshal Err:" + err.Error())
- utils.FileLogCygx.Info("PostData json.Marshal Err:" + err.Error())
- return
- }
- method := "POST"
- client := &http.Client{}
- req, err := http.NewRequest(method, url, strings.NewReader(string(postData)))
- if err != nil {
- fmt.Println(err)
- return
- }
- req.Header.Add("Content-Type", "application/json")
- res, err := client.Do(req)
- if err != nil {
- fmt.Println(err)
- return
- }
- defer res.Body.Close()
- body, err := ioutil.ReadAll(res.Body)
- if err != nil {
- fmt.Println(err)
- return
- }
- itemApiLog := new(cygx.CygxThreeApiLog)
- itemApiLog.CreateTime = time.Now()
- itemApiLog.Source = 1
- itemApiLog.Url = url
- itemApiLog.Body = string(postData)
- itemApiLog.Result = string(body)
- go cygx.AddCygxThreeApiLog(itemApiLog)
- var yidongResp *YiDongGetRoadshowDetailResp
- err = json.Unmarshal(body, &yidongResp)
- if err != nil {
- return
- }
- if !yidongResp.Success {
- err = errors.New("删除路演活动 接口失败," + yidongResp.ErrorCode + yidongResp.ErrorMsg)
- return
- }
- activityInfo.Body = strings.Replace(activityInfo.Body, "腾讯会议号:"+activityInfo.TencentConferenceNumber, "", -1)
- activityInfo.Body = strings.Replace(activityInfo.Body, "<p></p>", "", -1)
- activityInfo.YidongActivityIdByCygx = ""
- activityInfo.TencentConferenceNumber = ""
- err = cygx.UpdateCygxActivityTencentConferenceNumber(activityInfo)
- return
- }
- // GetLoginAuthCodeReq 获取登录编码请求体
- type GetYiDongActivityByApiReq struct {
- MeetingStatus string `json:"meetingStatus" description:"会议状态必需(0未开始1进行中2已结束)多个逗号分隔"`
- ConveneStartStr string `json:"conveneStartStr" description:"活动日期范围开始"`
- ConveneEndStr string `json:"conveneEndStr" description:"活动日期范围结束"`
- LastUpdateTime string `json:"lastUpdateTime" description:"上次同步时间(用于筛选更新时间大于同步时间的活动数据)"`
- }
- // 根据条件获取易董建会列表信息
- func GetYiDongActivityListByApi(param *GetYiDongActivityByApiReq) (yiDongResult []YidongActivityResult) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go alarm_msg.SendAlarmMsg(fmt.Sprint("根据条件获取易董建会列表信息 GetYiDongActivityListByApi"+err.Error(), param), 2)
- }
- }()
- var token string
- token, _ = GetYidongToken()
- url := utils.YiDongZhengTongYunUrl + "interact/activityManageApi/getRoadshowList?access_token=" + token
- method := "POST"
- data, e := json.Marshal(param)
- if e != nil {
- err = errors.New("data json marshal err: " + e.Error())
- return
- }
- payload := strings.NewReader(string(data))
- client := &http.Client{}
- req, e := http.NewRequest(method, url, payload)
- if e != nil {
- err = errors.New(" http.NewRequest err: " + e.Error())
- return
- }
- req.Header.Add("Content-Type", "application/json")
- res, e := client.Do(req)
- if e != nil {
- err = errors.New(" client.Do err: " + e.Error())
- return
- }
- defer res.Body.Close()
- var ApifoxModal *YidongApifoxModal
- body, e := ioutil.ReadAll(res.Body)
- if e != nil {
- err = errors.New(" ioutil.ReadAll: " + e.Error())
- return
- }
- //添加请求日志记录
- itemApiLog := new(cygx.CygxThreeApiLog)
- itemApiLog.CreateTime = time.Now()
- itemApiLog.Source = 1
- itemApiLog.Url = url
- itemApiLog.Body = utils.ReplaceSpaceAndWrap(fmt.Sprint(payload))
- itemApiLog.Result = string(body)
- go cygx.AddCygxThreeApiLog(itemApiLog)
- err = json.Unmarshal(body, &ApifoxModal)
- if err != nil {
- fmt.Println("Getres.PublicGetDate Err:", err.Error())
- return
- }
- if len(ApifoxModal.Result) > 0 {
- yiDongResult = ApifoxModal.Result
- } else {
- yiDongResult = make([]YidongActivityResult, 0)
- }
- return
- }
- type GetYiDongActivityMeetByActivityIdReq struct {
- ActivityId string `json:"activityId" description:"活动ID"`
- }
- type YidongApifoxModaluser struct {
- ErrorCode interface{} `json:"errorCode"`
- ErrorMsg interface{} `json:"errorMsg"`
- Result []YidongResultuser `json:"result"`
- Success bool `json:"success"`
- Timestamp int64 `json:"timestamp"`
- }
- // 根据条件获取易董活动ID获取到会信息
- func GetYiDongActivityMeetDataByaAtivityId(ativityId string) (yiDongResult []YidongResultuser) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go alarm_msg.SendAlarmMsg(fmt.Sprint("根据条件获取易董建会列表信息 GetYiDongActivityListByApi"+err.Error(), ativityId), 2)
- }
- }()
- var token string
- token, _ = GetYidongToken()
- url := utils.YiDongZhengTongYunUrl + "interact/activityManageApi/getAttendPersonList?access_token=" + token
- method := "POST"
- param := new(GetYiDongActivityMeetByActivityIdReq)
- param.ActivityId = ativityId
- data, e := json.Marshal(param)
- if e != nil {
- err = errors.New("data json marshal err: " + e.Error())
- return
- }
- payload := strings.NewReader(string(data))
- client := &http.Client{}
- req, e := http.NewRequest(method, url, payload)
- if e != nil {
- err = errors.New(" http.NewRequest err: " + e.Error())
- return
- }
- req.Header.Add("Content-Type", "application/json")
- res, e := client.Do(req)
- if e != nil {
- err = errors.New(" client.Do err: " + e.Error())
- return
- }
- defer res.Body.Close()
- var ApifoxModal *YidongApifoxModaluser
- body, e := ioutil.ReadAll(res.Body)
- if e != nil {
- err = errors.New(" ioutil.ReadAll err: " + e.Error())
- return
- }
- e = json.Unmarshal(body, &ApifoxModal)
- if e != nil {
- err = errors.New(" json.Unmarshal err: " + e.Error())
- return
- }
- //添加请求日志记录
- itemApiLog := new(cygx.CygxThreeApiLog)
- itemApiLog.CreateTime = time.Now()
- itemApiLog.Source = 1
- itemApiLog.Url = url
- itemApiLog.Body = utils.ReplaceSpaceAndWrap(fmt.Sprint(payload))
- itemApiLog.Result = string(body)
- go cygx.AddCygxThreeApiLog(itemApiLog)
- err = json.Unmarshal(body, &ApifoxModal)
- if err != nil {
- fmt.Println("Getres.PublicGetDate Err:", err.Error())
- return
- }
- if len(ApifoxModal.Result) > 0 {
- yiDongResult = ApifoxModal.Result
- } else {
- yiDongResult = make([]YidongResultuser, 0)
- }
- return
- }
- // 根据条件获取易董活动ID获取到会信息
- func GetYiDongActivityMeeting(yidongActivityId string, cygxActivityId int) (yiDongResult []YidongResultuser) {
- var err error
- defer func() {
- if err != nil {
- fmt.Println(err)
- go alarm_msg.SendAlarmMsg(fmt.Sprint("根据条件获取易董建会列表信息 GetYiDongActivityMeeting"+err.Error(), cygxActivityId), 2)
- }
- }()
- //跟易董返回的用户状态修改活动以提交到会状态
- e := cygx.UpdateCygxActivitySubmitMeetingByYidong(yidongActivityId)
- if e != nil {
- err = errors.New("UpdateCygxActivitySubmitMeetingByYidong err: " + e.Error())
- return
- }
- meetDataList := GetYiDongActivityMeetDataByaAtivityId(yidongActivityId)
- var mobiles []string
- var mobileStr string
- var mobileStrMeet string
- mapActivityAttendanceDetail := make(map[string]*cygx.CygxActivityAttendanceDetail)
- if len(meetDataList) > 0 {
- var itemsUpdate []*cygx.CygxActivitySignupDetail
- needAddAttendanc := make([]*cygx.CygxActivityAttendanceDetail, 0)
- for _, vresult := range meetDataList {
- if vresult.PersonTelephone == "" {
- continue
- }
- if vresult.Duration != "" || vresult.DurationReview != "" {
- mobiles = append(mobiles, vresult.PersonTelephone)
- var itemDetail = new(cygx.CygxActivitySignupDetail)
- if vresult.Duration != "" {
- itemDetail.FirstMeetingTime = vresult.StartTime
- itemDetail.LastMeetingTime = vresult.EndTime
- itemDetail.Duration = vresult.Duration
- itemDetail.MeetingStatusStr = "直播"
- } else if vresult.DurationReview != "" {
- itemDetail.FirstMeetingTime = vresult.StartTimeReview
- itemDetail.LastMeetingTime = vresult.EndTimeReview
- itemDetail.Duration = vresult.DurationReview
- itemDetail.MeetingStatusStr = "回放"
- }
- itemDetail.Position = vresult.JobName
- itemDetail.RealName = vresult.PersonName
- itemDetail.Mobile = vresult.PersonTelephone
- itemDetail.OutboundMobile = vresult.PersonTelephone
- itemDetail.IsMeeting = 1
- itemDetail.ActivityId = cygxActivityId
- mapActivityAttendanceDetail[vresult.PersonTelephone] = new(cygx.CygxActivityAttendanceDetail)
- mapActivityAttendanceDetail[vresult.PersonTelephone].FirstMeetingTime = vresult.StartTime
- mapActivityAttendanceDetail[vresult.PersonTelephone].LastMeetingTime = vresult.EndTime
- mapActivityAttendanceDetail[vresult.PersonTelephone].Duration = utils.GetAttendanceDetailSecondsByYiDong(vresult.Duration)
- itemsUpdate = append(itemsUpdate, itemDetail)
- }
- item := new(cygx.CygxActivityAttendanceDetail)
- item.ActivityId = cygxActivityId
- item.Mobile = vresult.PersonTelephone
- if vresult.Duration != "" {
- if vresult.Duration != "" {
- item.FirstMeetingTime = vresult.StartTime
- item.LastMeetingTime = vresult.EndTime
- item.Duration = vresult.Duration
- item.MeetingStatusStr = "直播"
- } else if vresult.DurationReview != "" {
- item.FirstMeetingTime = vresult.StartTimeReview
- item.LastMeetingTime = vresult.EndTimeReview
- item.Duration = vresult.DurationReview
- item.MeetingStatusStr = "回放"
- }
- item.Position = vresult.JobName
- item.RealName = vresult.PersonName
- item.FirstMeetingTime = vresult.StartTime
- item.LastMeetingTime = vresult.EndTime
- item.Duration = vresult.Duration
- item.IsMeetingStr = 1
- mobileStrMeet += "'" + vresult.PersonTelephone + "'" + ","
- item.CreateTime = time.Now()
- needAddAttendanc = append(needAddAttendanc, item)
- }
- mobileStr += "'" + vresult.PersonTelephone + "'" + ","
- }
- lenmobiles := len(mobiles)
- if lenmobiles > 0 {
- var parsYd []interface{}
- var conditionYd string
- conditionYd = ` AND mobile IN (` + utils.GetOrmInReplace(lenmobiles) + `) AND activity_id=? `
- parsYd = append(parsYd, mobiles, cygxActivityId)
- e = cygx.UpdateCygxActivitySignupisMeetList(conditionYd, parsYd)
- if e != nil {
- err = errors.New("UpdateCygxActivitySignupisMeetList err: " + e.Error())
- return
- }
- e = cygx.UpdateActivitySignupDetailMultiByYiDong(itemsUpdate)
- if e != nil {
- err = errors.New("UpdateActivitySignupDetailMultiByYiDong err: " + e.Error())
- return
- }
- }
- mobileStr = strings.TrimRight(mobileStr, ",")
- if mobileStr == "" {
- mobileStr = "1"
- }
- mobileStrMeet = strings.TrimRight(mobileStrMeet, ",")
- if mobileStrMeet == "" {
- mobileStrMeet = "1"
- }
- listUser, e := cygx.GetWxUserOutboundMobile(mobileStr)
- if e != nil {
- err = errors.New("GetWxUserOutboundMobile err: " + e.Error())
- return
- }
- for kAdd, vAdd := range needAddAttendanc {
- for _, v2 := range listUser {
- if v2.OutboundMobile == vAdd.Mobile || v2.Mobile == vAdd.Mobile {
- if needAddAttendanc[kAdd].CompanyId <= 1 {
- needAddAttendanc[kAdd].CompanyId = v2.CompanyId
- needAddAttendanc[kAdd].SellerName = v2.SellerName
- needAddAttendanc[kAdd].CompanyName = v2.CompanyName
- //needAddAttendanc[k].IsMeetingStr = 1
- }
- }
- }
- }
- //参会记录
- e = cygx.AddAttendancDetail(needAddAttendanc, cygxActivityId, mobileStrMeet)
- if e != nil {
- err = errors.New("AddAttendancDetail err: " + e.Error())
- return
- }
- ////处理是否限制报名
- e = AddCygxActivityRestrictSignupByAdmin(cygxActivityId)
- if e != nil {
- err = errors.New("AddCygxActivityRestrictSignupByAdmin err: " + e.Error())
- return
- }
- AddctivitySignupDetailListByHand(needAddAttendanc, cygxActivityId)
- }
- return
- }
|