123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754 |
- 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"`
- }
- // 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
- }
|