yidong.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "hongze/hz_crm_api/models/cygx"
  7. "hongze/hz_crm_api/services/alarm_msg"
  8. "hongze/hz_crm_api/utils"
  9. "io/ioutil"
  10. "net/http"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. type ApifoxModalSingUpClass struct {
  16. ErrorCode *string `json:"errorCode"` // 错误码,001:活动不存在;002:该活动不支持此渠道报名;003:该手机号或邮箱已经被其他账号提交报名;004:不在报名时间;005:报名人数已满
  17. ErrorMsg *string `json:"errorMsg"` // 错误信息
  18. Result SingUpMap `json:"result"` // 结果Map,成功
  19. Success bool `json:"success"` // 成功标识,true:成功;false:失败。可作为判断报名是否成功的标识
  20. Timestamp float64 `json:"timestamp"` // 时间戳
  21. }
  22. type SingUpMap struct {
  23. Msg string `json:"msg"` // 请求信息,成功信息
  24. }
  25. type GetYidongTokenResp struct {
  26. Success bool `json:"success"` // 请求信息,成功信息
  27. AccessToken string `json:"access_token"` // token
  28. ExpiresIn int `json:"expires_in"` // 过期时间
  29. }
  30. // 易董建会成功返回的结构体
  31. type YiDongSaveRoadshowDetailResp struct {
  32. ErrorCode string `json:"errorCode"` // 错误码
  33. ErrorMsg string `json:"errorMsg"` // 错误信息
  34. Success bool `json:"success"` // 请求信息,成功信息
  35. Result YiDongSaveRoadshowDetailIdResp `json:"result"` // 返回信息
  36. }
  37. type YiDongSaveRoadshowDetailIdResp struct {
  38. ActivityId string `json:"activityId"` //易董返回的活动ID
  39. }
  40. type YiDongUpdateActivityPublishResp struct {
  41. Id string `description:"易董活动ID,为空时新增,非空时修改" json:"id"`
  42. PublishFlag string `description:"发布状态,1发布 0 取消发布" json:"publishFlag"`
  43. }
  44. // 获取路演详细信息(2.0)结构体
  45. type YiDongGetRoadshowDetailResp struct {
  46. ErrorCode string `json:"errorCode"` // 错误码
  47. ErrorMsg string `json:"errorMsg"` // 错误信息
  48. Success bool `json:"success"` // 请求信息,成功信息
  49. Result YiDongGetRoadshowDetailRespResult `json:"result"` // 返回信息
  50. }
  51. type YiDongGetRoadshowDetailRespResult struct {
  52. MeetingCode string `json:"meetingCode"` //腾讯会议号
  53. }
  54. // 获取创建人信息列表(新)结构体
  55. type YiDongGetCreateUserListResp struct {
  56. ErrorCode string `json:"errorCode"` // 错误码
  57. ErrorMsg string `json:"errorMsg"` // 错误信息
  58. Success bool `json:"success"` // 请求信息,成功信息
  59. Result YiDongGetCreateUserListResult `json:"result"` // 返回信息
  60. }
  61. type YiDongGetCreateUserListResult struct {
  62. PersonList []*PersonUser
  63. }
  64. type PersonUser struct {
  65. Id string `description:"人员id" json:"id"`
  66. PersonName string `description:"姓名" json:"personName"`
  67. JobName string `description:"职务" json:"jobName"`
  68. UserId string `description:"用户id" json:"userId"`
  69. UserName string `description:"用户账号" json:"userName"`
  70. IdentityType string `description:"身份类型:0 不可用,1可用" json:"identityType"`
  71. Lock bool `description:"锁定状态:true 锁定 false 未锁定" json:"lock"`
  72. CreatePersonName string `description:"创建人姓名:创建时必填" json:"createPersonName"`
  73. }
  74. // CheckYidongActivitySignupTime 校验易董的活动是否可以 添加报名
  75. func CheckYidongActivitySignupTime(activityInfo *cygx.ActivityDetail) (errstr string) {
  76. if activityInfo.YidongSignUpEnd == "0000-00-00 00:00:00" {
  77. return
  78. }
  79. timeStart := activityInfo.YidongSignUpStart
  80. timeEnd := activityInfo.YidongSignUpEnd
  81. resultTimeStart := utils.StrTimeToTime(timeStart) //时间字符串格式转时间格式
  82. resStart := time.Now().Before(resultTimeStart)
  83. if resStart {
  84. errstr = "当前时间不可报名!"
  85. }
  86. resultTimeEnd := utils.StrTimeToTime(timeEnd) //时间字符串格式转时间格式
  87. resend := time.Now().After(resultTimeEnd)
  88. if resend {
  89. errstr = "当前时间不可报名!"
  90. }
  91. return
  92. }
  93. // YidongActivityUserSingnUp 易董的活动添加报名
  94. func YidongActivityUserSingnUp(items []*cygx.YidongActivitySignup) (err error) {
  95. url := utils.YiDongHuaWeiYunUrl + "app/hz/signAppointmentsForThird"
  96. method := "POST"
  97. for _, v := range items {
  98. defer func() {
  99. if err != nil {
  100. go alarm_msg.SendAlarmMsg("易董的活动添加报名消息失败,Err:"+err.Error(), 3)
  101. }
  102. }()
  103. payload := strings.NewReader(`{
  104. "activityId": "` + v.YidongActivityId + `",
  105. "personTelephone":"` + v.Mobile + `",
  106. "personName": "` + v.RealName + `",
  107. "companyName": "` + v.CompanyName + `",
  108. "mobileCountryCode": "+` + v.CountryCode + `",
  109. "thirdPartySource": "01"
  110. }`)
  111. client := &http.Client{}
  112. req, err := http.NewRequest(method, url, payload)
  113. if err != nil {
  114. fmt.Println(err)
  115. utils.FileLog.Info(err.Error())
  116. return err
  117. }
  118. req.Header.Add("Content-Type", "application/json")
  119. res, err := client.Do(req)
  120. if err != nil {
  121. fmt.Println(err)
  122. utils.FileLog.Info(err.Error())
  123. return err
  124. }
  125. defer res.Body.Close()
  126. var ApifoxModal *ApifoxModalSingUpClass
  127. body, err := ioutil.ReadAll(res.Body)
  128. if err != nil {
  129. fmt.Println(err)
  130. utils.FileLog.Info(err.Error())
  131. return err
  132. }
  133. itemApiLog := new(cygx.CygxThreeApiLog)
  134. itemApiLog.CreateTime = time.Now()
  135. itemApiLog.Source = 1
  136. itemApiLog.Url = url
  137. itemApiLog.Body = utils.ReplaceSpaceAndWrap(fmt.Sprint(payload))
  138. itemApiLog.Result = string(body)
  139. go cygx.AddCygxThreeApiLog(itemApiLog)
  140. err = json.Unmarshal(body, &ApifoxModal)
  141. }
  142. return
  143. }
  144. // GetYidongToken 获取易董证通云接口的token
  145. func GetYidongToken() (token string, err error) {
  146. defer func() {
  147. if err != nil {
  148. go alarm_msg.SendAlarmMsg("获取易董证通云接口的token失败;err:"+err.Error(), 3)
  149. }
  150. }()
  151. cacheKey := utils.YI_DONG_ZHENG_TONG_YUN_TOKEN_KEY
  152. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  153. if ttlTime > 0 {
  154. token, _ = utils.Rc.RedisString(cacheKey)
  155. if token != "" {
  156. return
  157. }
  158. }
  159. url := utils.YiDongZhengTongYunUrl + "oauth/token?grant_type=client_credentials&response_type=token&client_id=" + utils.YiDongZhengTongYunClientId + "&client_secret=" + utils.YiDongZhengTongYunClientSecret
  160. method := "GET"
  161. client := &http.Client{}
  162. req, err := http.NewRequest(method, url, nil)
  163. if err != nil {
  164. return
  165. }
  166. res, err := client.Do(req)
  167. if err != nil {
  168. return
  169. }
  170. defer res.Body.Close()
  171. body, err := ioutil.ReadAll(res.Body)
  172. if err != nil {
  173. return
  174. }
  175. itemApiLog := new(cygx.CygxThreeApiLog)
  176. itemApiLog.CreateTime = time.Now()
  177. itemApiLog.Source = 1
  178. itemApiLog.Url = url
  179. itemApiLog.Body = ""
  180. itemApiLog.Result = string(body)
  181. go cygx.AddCygxThreeApiLog(itemApiLog)
  182. var yidongTokenResp *GetYidongTokenResp
  183. err = json.Unmarshal(body, &yidongTokenResp)
  184. if err != nil {
  185. return
  186. }
  187. token = yidongTokenResp.AccessToken
  188. err = utils.Rc.Put(cacheKey, token, time.Second*7000)
  189. if err != nil {
  190. return
  191. }
  192. return
  193. }
  194. // 易董创建/更新路演活动结构体
  195. type SaveRoadshowDetaiParam struct {
  196. Id string `description:"易董活动ID,为空时新增,非空时修改" json:"id"`
  197. PublishFlag string `description:"发布状态,1发布 0 取消发布" json:"publishFlag"`
  198. Title string `description:"主题" json:"title"`
  199. Type string `description:"类型:投资策略、深度解读、行业分析、公司分析、自定义活动" json:"type"`
  200. Start string `description:"开始时间:开始时间与结束时间,日期必须相同" json:"start"`
  201. End string `description:"结束时间:开始时间与结束时间,日期必须相同" json:"end"`
  202. CreateUserId string `description:"创建人userId:创建时必填" json:"createUserId"`
  203. CreatePersonName string `description:"创建人姓名:创建时必填" json:"createPersonName"`
  204. }
  205. // 获取创建人信息列表(新)
  206. func YiDongGetCreateUserList() (userId string) {
  207. var err error
  208. defer func() {
  209. if err != nil {
  210. fmt.Println(err)
  211. go alarm_msg.SendAlarmMsg("获取创建人信息列表(新)失败;err:"+err.Error(), 3)
  212. }
  213. }()
  214. token, _ := GetYidongToken()
  215. if token == "" {
  216. return
  217. }
  218. url := utils.YiDongZhengTongYunUrl + "interact/activityThirdApi/getCreateUserList" + "?access_token=" + token
  219. method := "POST"
  220. client := &http.Client{}
  221. req, err := http.NewRequest(method, url, strings.NewReader(""))
  222. if err != nil {
  223. fmt.Println(err)
  224. return
  225. }
  226. req.Header.Add("Content-Type", "application/json")
  227. res, err := client.Do(req)
  228. if err != nil {
  229. fmt.Println(err)
  230. return
  231. }
  232. defer res.Body.Close()
  233. body, err := ioutil.ReadAll(res.Body)
  234. if err != nil {
  235. fmt.Println(err)
  236. return
  237. }
  238. itemApiLog := new(cygx.CygxThreeApiLog)
  239. itemApiLog.CreateTime = time.Now()
  240. itemApiLog.Source = 1
  241. itemApiLog.Url = url
  242. itemApiLog.Body = ""
  243. itemApiLog.Result = string(body)
  244. go cygx.AddCygxThreeApiLog(itemApiLog)
  245. var yidongResp *YiDongGetCreateUserListResp
  246. err = json.Unmarshal(body, &yidongResp)
  247. if err != nil {
  248. return
  249. }
  250. if !yidongResp.Success {
  251. err = errors.New("获取创建人信息列表(新) 接口失败," + yidongResp.ErrorCode + yidongResp.ErrorMsg)
  252. return
  253. }
  254. if len(yidongResp.Result.PersonList) > 0 {
  255. for _, v := range yidongResp.Result.PersonList {
  256. if v.PersonName == "高亦文" {
  257. userId = v.UserId
  258. }
  259. }
  260. }
  261. if userId == "" {
  262. err = errors.New("获取创建人信息列表(新) 接口失败," + yidongResp.ErrorCode + yidongResp.ErrorMsg + string(body))
  263. return
  264. }
  265. return
  266. }
  267. //func init() {
  268. // YiDongUpdateActivityPublish(2149)
  269. //}
  270. // YiDongSaveRoadshowDetail 创建/更新路演活动(新)
  271. func YiDongSaveRoadshowDetail(activityId int) {
  272. var err error
  273. defer func() {
  274. if err != nil {
  275. fmt.Println(err)
  276. go alarm_msg.SendAlarmMsg("活动同步到易董失败;err:"+err.Error(), 3)
  277. }
  278. }()
  279. activityInfo, err := cygx.GetAddActivityInfoById(activityId)
  280. if err != nil {
  281. fmt.Println(err)
  282. return
  283. }
  284. if activityInfo == nil {
  285. return
  286. }
  287. if activityInfo.IsYidongConduct == 0 {
  288. return
  289. }
  290. token, _ := GetYidongToken()
  291. if token == "" {
  292. return
  293. }
  294. //C类分析师电话会 不对外发布
  295. if activityInfo.ActivityTypeId == 7 || activityInfo.IsBClass == 1 {
  296. activityInfo.PublishStatus = 0
  297. }
  298. //if activityInfo.PublishStatus == 0 {
  299. // return
  300. //}
  301. //获取高亦文在易董的用户ID
  302. var createUserId string
  303. createUserId = YiDongGetCreateUserList()
  304. url := utils.YiDongZhengTongYunUrl + "interact/activityThirdApi/saveRoadshowDetail" + "?access_token=" + token
  305. startTime := activityInfo.ActivityTime
  306. endTime := utils.StrTimeToTime(startTime).Add(time.Minute * 60).Format(utils.FormatDateTime) // 30分钟后为结束时间
  307. params := SaveRoadshowDetaiParam{
  308. Id: activityInfo.YidongActivityIdByCygx,
  309. PublishFlag: strconv.Itoa(activityInfo.PublishStatus),
  310. Title: activityInfo.ActivityName,
  311. Type: "行业分析",
  312. Start: startTime,
  313. End: endTime,
  314. CreateUserId: createUserId,
  315. CreatePersonName: "高亦文",
  316. }
  317. postData, err := json.Marshal(params)
  318. if err != nil {
  319. fmt.Println("PostData json.Marshal Err:" + err.Error())
  320. utils.FileLogCygx.Info("PostData json.Marshal Err:" + err.Error())
  321. return
  322. }
  323. method := "POST"
  324. client := &http.Client{}
  325. req, err := http.NewRequest(method, url, strings.NewReader(string(postData)))
  326. if err != nil {
  327. fmt.Println(err)
  328. return
  329. }
  330. req.Header.Add("Content-Type", "application/json")
  331. res, err := client.Do(req)
  332. if err != nil {
  333. fmt.Println(err)
  334. return
  335. }
  336. defer res.Body.Close()
  337. body, err := ioutil.ReadAll(res.Body)
  338. if err != nil {
  339. fmt.Println(err)
  340. return
  341. }
  342. itemApiLog := new(cygx.CygxThreeApiLog)
  343. itemApiLog.CreateTime = time.Now()
  344. itemApiLog.Source = 1
  345. itemApiLog.Url = url
  346. itemApiLog.Body = string(postData)
  347. itemApiLog.Result = string(body)
  348. go cygx.AddCygxThreeApiLog(itemApiLog)
  349. var yidongResp *YiDongSaveRoadshowDetailResp
  350. err = json.Unmarshal(body, &yidongResp)
  351. if err != nil {
  352. return
  353. }
  354. if !yidongResp.Success {
  355. err = errors.New("更新易董建会接口失败," + yidongResp.ErrorCode + yidongResp.ErrorMsg)
  356. return
  357. }
  358. yidongActivityIdByCygx := yidongResp.Result.ActivityId
  359. YiDongGetRoadshowDetail(activityId, yidongActivityIdByCygx) //获取易董创建的腾讯会议详情,并写入到我们自己的小程序
  360. YiDongSignAppointmentsForThirdSpeaker(activityId) // 根据填入的主讲人姓名 以嘉宾的身份自动报名
  361. }
  362. // YiDongGetRoadshowDetail 获取易董创建的腾讯会议详情,并写入到我们自己的小程序
  363. func YiDongGetRoadshowDetail(activityId int, yidongActivityIdByCygx string) {
  364. var err error
  365. defer func() {
  366. if err != nil {
  367. fmt.Println(err)
  368. go alarm_msg.SendAlarmMsg("易董获取路演详细信息(2.0);err:"+err.Error(), 3)
  369. }
  370. }()
  371. activityInfo, err := cygx.GetAddActivityInfoById(activityId)
  372. if err != nil {
  373. fmt.Println(err)
  374. return
  375. }
  376. if activityInfo == nil {
  377. return
  378. }
  379. token, _ := GetYidongToken()
  380. if token == "" {
  381. return
  382. }
  383. activityInfo.YidongActivityIdByCygx = yidongActivityIdByCygx
  384. url := utils.YiDongZhengTongYunUrl + "interact/activityManageApi/getRoadshowDetail" + "?access_token=" + token
  385. if activityInfo.IsYidongConduct == 0 {
  386. return
  387. }
  388. params := YiDongSaveRoadshowDetailIdResp{
  389. ActivityId: yidongActivityIdByCygx,
  390. }
  391. postData, err := json.Marshal(params)
  392. if err != nil {
  393. fmt.Println("PostData json.Marshal Err:" + err.Error())
  394. utils.FileLogCygx.Info("PostData json.Marshal Err:" + err.Error())
  395. return
  396. }
  397. method := "POST"
  398. client := &http.Client{}
  399. req, err := http.NewRequest(method, url, strings.NewReader(string(postData)))
  400. if err != nil {
  401. fmt.Println(err)
  402. return
  403. }
  404. req.Header.Add("Content-Type", "application/json")
  405. res, err := client.Do(req)
  406. if err != nil {
  407. fmt.Println(err)
  408. return
  409. }
  410. defer res.Body.Close()
  411. body, err := ioutil.ReadAll(res.Body)
  412. if err != nil {
  413. fmt.Println(err)
  414. return
  415. }
  416. itemApiLog := new(cygx.CygxThreeApiLog)
  417. itemApiLog.CreateTime = time.Now()
  418. itemApiLog.Source = 1
  419. itemApiLog.Url = url
  420. itemApiLog.Body = string(postData)
  421. itemApiLog.Result = string(body)
  422. go cygx.AddCygxThreeApiLog(itemApiLog)
  423. var yidongResp *YiDongGetRoadshowDetailResp
  424. err = json.Unmarshal(body, &yidongResp)
  425. if err != nil {
  426. return
  427. }
  428. if !yidongResp.Success {
  429. err = errors.New("易董获取路演详细信息(2.0)接口失败," + yidongResp.ErrorCode + yidongResp.ErrorMsg)
  430. return
  431. }
  432. MeetingCode := yidongResp.Result.MeetingCode
  433. if activityInfo.TencentConferenceNumber != "" {
  434. activityInfo.Body = strings.Replace(activityInfo.Body, activityInfo.TencentConferenceNumber, MeetingCode, -1)
  435. } else {
  436. activityInfo.Body += "<p>腾讯会议号:" + MeetingCode + "</p>"
  437. }
  438. activityInfo.TencentConferenceNumber = MeetingCode
  439. err = cygx.UpdateCygxActivityTencentConferenceNumber(activityInfo)
  440. return
  441. }
  442. // 发布路演到活动广场(新)
  443. func YiDongUpdateActivityPublish(activityId int) {
  444. var err error
  445. defer func() {
  446. if err != nil {
  447. fmt.Println(err)
  448. go alarm_msg.SendAlarmMsg("发布路演到活动广场(新);err:"+err.Error(), 3)
  449. }
  450. }()
  451. activityInfo, err := cygx.GetAddActivityInfoById(activityId)
  452. if err != nil {
  453. fmt.Println(err)
  454. return
  455. }
  456. if activityInfo == nil {
  457. return
  458. }
  459. //C类分析师电话会 不对外发布
  460. if activityInfo.ActivityTypeId == 7 {
  461. activityInfo.PublishStatus = 0
  462. }
  463. token, _ := GetYidongToken()
  464. if token == "" {
  465. return
  466. }
  467. url := utils.YiDongZhengTongYunUrl + "interact/activityThirdApi/updateActivityPublish" + "?access_token=" + token
  468. if activityInfo.IsYidongConduct == 0 || activityInfo.YidongActivityIdByCygx == "" {
  469. return
  470. }
  471. params := YiDongUpdateActivityPublishResp{
  472. Id: activityInfo.YidongActivityIdByCygx,
  473. PublishFlag: strconv.Itoa(activityInfo.PublishStatus),
  474. }
  475. postData, err := json.Marshal(params)
  476. if err != nil {
  477. fmt.Println("PostData json.Marshal Err:" + err.Error())
  478. utils.FileLogCygx.Info("PostData json.Marshal Err:" + err.Error())
  479. return
  480. }
  481. method := "POST"
  482. client := &http.Client{}
  483. req, err := http.NewRequest(method, url, strings.NewReader(string(postData)))
  484. if err != nil {
  485. fmt.Println(err)
  486. return
  487. }
  488. req.Header.Add("Content-Type", "application/json")
  489. res, err := client.Do(req)
  490. if err != nil {
  491. fmt.Println(err)
  492. return
  493. }
  494. defer res.Body.Close()
  495. body, err := ioutil.ReadAll(res.Body)
  496. if err != nil {
  497. fmt.Println(err)
  498. return
  499. }
  500. itemApiLog := new(cygx.CygxThreeApiLog)
  501. itemApiLog.CreateTime = time.Now()
  502. itemApiLog.Source = 1
  503. itemApiLog.Url = url
  504. itemApiLog.Body = string(postData)
  505. itemApiLog.Result = string(body)
  506. go cygx.AddCygxThreeApiLog(itemApiLog)
  507. var yidongResp *YiDongGetRoadshowDetailResp
  508. err = json.Unmarshal(body, &yidongResp)
  509. if err != nil {
  510. return
  511. }
  512. if !yidongResp.Success {
  513. err = errors.New("发布路演到活动广场(新) 接口失败," + yidongResp.ErrorCode + yidongResp.ErrorMsg)
  514. return
  515. }
  516. if activityInfo.PublishStatus == 0 {
  517. YiDongUpdateActivityStatus(activityId)
  518. }
  519. return
  520. }
  521. // 易董创建/更新路演活动结构体
  522. type SignAppointmentsForThirdParam struct {
  523. ActivityId string `description:"易董活动ID" json:"activityId"`
  524. MobileCountryCode string `description:"国际区号注意要带前面+号 " json:"mobileCountryCode"`
  525. PersonTelephone string `description:"手机号" json:"personTelephone"`
  526. ThirdPartySource string `description:"第三方来源;弘则固定:01" json:"thirdPartySource"`
  527. InvestorType string `description:"投资者类型 0个人1机构" json:"investorType"`
  528. PersonName string `description:"姓名" json:"personName"`
  529. CompanyName string `description:"公司名" json:"companyName"`
  530. JoinRole string `description:"1:嘉宾, 2:普通参会人员, 3:会议助理。不传默认取值2" json:"joinRole"`
  531. OutCallStatus string `description:"1:需要,0:不需要。不传取默认值0" json:"outCallStatus"`
  532. }
  533. type YiDongSignAppointmentsForThirdResp struct {
  534. ErrorCode string `json:"errorCode"` // 错误码,001:活动不存在;002:该活动不支持此渠道报名;003:该手机号或邮箱已经被其他账号提交报名;004:不在报名时间;005:报名人数已满
  535. ErrorMsg string `json:"errorMsg"` // 错误信息
  536. Success bool `json:"success"` // 成功标识,true:成功;false:失败。可作为判断报名是否成功的标识
  537. Timestamp float64 `json:"timestamp"` // 时间戳
  538. }
  539. // 根据填入的主讲人姓名 以嘉宾的身份自动报名
  540. func YiDongSignAppointmentsForThirdSpeaker(activityId int) {
  541. var err error
  542. defer func() {
  543. if err != nil {
  544. fmt.Println(err)
  545. go alarm_msg.SendAlarmMsg("易董获取路演详细信息(2.0);err:"+err.Error(), 3)
  546. }
  547. }()
  548. activityInfo, err := cygx.GetAddActivityInfoById(activityId)
  549. if err != nil {
  550. fmt.Println(err)
  551. return
  552. }
  553. if activityInfo == nil {
  554. return
  555. }
  556. speaker := activityInfo.Speaker
  557. if speaker == "" {
  558. return
  559. }
  560. // 获取admin列表-匹配联系人是否为admin用户
  561. sysUserList, err := cygx.GetAskEmail()
  562. var personNameites []*cygx.AskEmailRep
  563. if err != nil {
  564. return
  565. }
  566. //var personName string
  567. //var personTelephone string
  568. for _, v := range sysUserList {
  569. if strings.Contains(speaker, v.Name) && v.Mobile != "" {
  570. personNameites = append(personNameites, &cygx.AskEmailRep{
  571. Name: v.Name,
  572. Mobile: v.Mobile,
  573. })
  574. }
  575. }
  576. if activityInfo.IsYidongConduct == 0 || len(personNameites) == 0 {
  577. return
  578. }
  579. url := utils.YiDongHuaWeiYunUrl + "app/hz/signAppointmentsForThird"
  580. for _, v := range personNameites {
  581. params := SignAppointmentsForThirdParam{
  582. ActivityId: activityInfo.YidongActivityIdByCygx,
  583. MobileCountryCode: "+86",
  584. PersonTelephone: v.Mobile,
  585. ThirdPartySource: "01",
  586. InvestorType: "0",
  587. PersonName: v.Name,
  588. JoinRole: "1",
  589. CompanyName: "弘则研究",
  590. OutCallStatus: "0",
  591. }
  592. postData, err := json.Marshal(params)
  593. if err != nil {
  594. fmt.Println("PostData json.Marshal Err:" + err.Error())
  595. utils.FileLogCygx.Info("PostData json.Marshal Err:" + err.Error())
  596. return
  597. }
  598. method := "POST"
  599. client := &http.Client{}
  600. req, err := http.NewRequest(method, url, strings.NewReader(string(postData)))
  601. if err != nil {
  602. fmt.Println(err)
  603. return
  604. }
  605. req.Header.Add("Content-Type", "application/json")
  606. res, err := client.Do(req)
  607. if err != nil {
  608. fmt.Println(err)
  609. return
  610. }
  611. defer res.Body.Close()
  612. body, err := ioutil.ReadAll(res.Body)
  613. if err != nil {
  614. fmt.Println(err)
  615. return
  616. }
  617. itemApiLog := new(cygx.CygxThreeApiLog)
  618. itemApiLog.CreateTime = time.Now()
  619. itemApiLog.Source = 1
  620. itemApiLog.Url = url
  621. itemApiLog.Body = string(postData)
  622. itemApiLog.Result = string(body)
  623. go cygx.AddCygxThreeApiLog(itemApiLog)
  624. var yidongResp *YiDongSignAppointmentsForThirdResp
  625. err = json.Unmarshal(body, &yidongResp)
  626. if err != nil {
  627. return
  628. }
  629. if !yidongResp.Success {
  630. err = errors.New(" 根据填入的主讲人姓名 以嘉宾的身份自动报名 接口失败," + yidongResp.ErrorCode + yidongResp.ErrorMsg)
  631. return
  632. }
  633. }
  634. return
  635. }
  636. //func init() {
  637. // YiDongUpdateActivityStatus(2180)
  638. //}
  639. // 删除路演活动(新)
  640. func YiDongUpdateActivityStatus(activityId int) {
  641. var err error
  642. defer func() {
  643. if err != nil {
  644. fmt.Println(err)
  645. go alarm_msg.SendAlarmMsg(" 删除路演活动(新);err:"+err.Error(), 3)
  646. }
  647. }()
  648. activityInfo, err := cygx.GetAddActivityInfoById(activityId)
  649. if err != nil {
  650. fmt.Println(err)
  651. return
  652. }
  653. if activityInfo == nil {
  654. return
  655. }
  656. //C类分析师电话会 不对外发布
  657. if activityInfo.ActivityTypeId == 7 {
  658. activityInfo.PublishStatus = 0
  659. }
  660. //如果关联的易董活动ID为空,那么不做处理
  661. if activityInfo.YidongActivityIdByCygx == "" {
  662. return
  663. }
  664. //如果状态是已发布,而且是易董办会那么就不做处理
  665. if activityInfo.IsYidongConduct == 1 && activityInfo.PublishStatus == 1 {
  666. return
  667. }
  668. token, _ := GetYidongToken()
  669. if token == "" {
  670. return
  671. }
  672. url := utils.YiDongZhengTongYunUrl + "interact/activityThirdApi/updateActivityStatus" + "?access_token=" + token
  673. //if activityInfo.IsYidongConduct == 0 || activityInfo.YidongActivityIdByCygx == "" {
  674. // return
  675. //}
  676. params := YiDongUpdateActivityPublishResp{
  677. Id: activityInfo.YidongActivityIdByCygx,
  678. }
  679. postData, err := json.Marshal(params)
  680. if err != nil {
  681. fmt.Println("PostData json.Marshal Err:" + err.Error())
  682. utils.FileLogCygx.Info("PostData json.Marshal Err:" + err.Error())
  683. return
  684. }
  685. method := "POST"
  686. client := &http.Client{}
  687. req, err := http.NewRequest(method, url, strings.NewReader(string(postData)))
  688. if err != nil {
  689. fmt.Println(err)
  690. return
  691. }
  692. req.Header.Add("Content-Type", "application/json")
  693. res, err := client.Do(req)
  694. if err != nil {
  695. fmt.Println(err)
  696. return
  697. }
  698. defer res.Body.Close()
  699. body, err := ioutil.ReadAll(res.Body)
  700. if err != nil {
  701. fmt.Println(err)
  702. return
  703. }
  704. itemApiLog := new(cygx.CygxThreeApiLog)
  705. itemApiLog.CreateTime = time.Now()
  706. itemApiLog.Source = 1
  707. itemApiLog.Url = url
  708. itemApiLog.Body = string(postData)
  709. itemApiLog.Result = string(body)
  710. go cygx.AddCygxThreeApiLog(itemApiLog)
  711. var yidongResp *YiDongGetRoadshowDetailResp
  712. err = json.Unmarshal(body, &yidongResp)
  713. if err != nil {
  714. return
  715. }
  716. if !yidongResp.Success {
  717. err = errors.New("删除路演活动 接口失败," + yidongResp.ErrorCode + yidongResp.ErrorMsg)
  718. return
  719. }
  720. activityInfo.Body = strings.Replace(activityInfo.Body, "腾讯会议号:"+activityInfo.TencentConferenceNumber, "", -1)
  721. activityInfo.Body = strings.Replace(activityInfo.Body, "<p></p>", "", -1)
  722. activityInfo.YidongActivityIdByCygx = ""
  723. activityInfo.TencentConferenceNumber = ""
  724. err = cygx.UpdateCygxActivityTencentConferenceNumber(activityInfo)
  725. return
  726. }