yidong.go 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  1. package services
  2. import (
  3. "context"
  4. "encoding/json"
  5. "errors"
  6. "fmt"
  7. "hongze/hongze_cygx/models"
  8. "hongze/hongze_cygx/utils"
  9. "io/ioutil"
  10. "net/http"
  11. "strings"
  12. "time"
  13. )
  14. // GetActivityTypeIdWithYiDong 根据易董同步过来的活动类型,自动匹配行业
  15. func GetActivityTypeIdWithYiDong(industrySwName string) (chartPermissionId int) {
  16. mapIndustrySwName := map[string]int{
  17. "家用电器": utils.XIAO_FEI_ID,
  18. "纺织服饰": utils.XIAO_FEI_ID,
  19. "休闲服务": utils.XIAO_FEI_ID,
  20. "食品饮料": utils.XIAO_FEI_ID,
  21. "美容护理": utils.XIAO_FEI_ID,
  22. //消费
  23. "汽车": utils.ZHI_ZAO_ID,
  24. "机械设备": utils.ZHI_ZAO_ID,
  25. "电力设备": utils.ZHI_ZAO_ID,
  26. //智造
  27. "电子": utils.KE_JI_ID,
  28. "计算机": utils.KE_JI_ID,
  29. "通信": utils.KE_JI_ID,
  30. //科技
  31. "医药生物": utils.YI_YAO_ID,
  32. //医药
  33. "策略": utils.CE_LUE_ID,
  34. //策略
  35. "非银金融": utils.CHART_PERMISSION_ID_YANXUAN,
  36. "建筑装饰": utils.CHART_PERMISSION_ID_YANXUAN,
  37. "基础化工": utils.CHART_PERMISSION_ID_YANXUAN,
  38. "农林牧渔": utils.CHART_PERMISSION_ID_YANXUAN,
  39. "传媒": utils.CHART_PERMISSION_ID_YANXUAN,
  40. "公用事业": utils.CHART_PERMISSION_ID_YANXUAN,
  41. "建筑材料": utils.CHART_PERMISSION_ID_YANXUAN,
  42. "房地产": utils.CHART_PERMISSION_ID_YANXUAN,
  43. "采掘": utils.CHART_PERMISSION_ID_YANXUAN,
  44. "轻工制造": utils.CHART_PERMISSION_ID_YANXUAN,
  45. "钢铁": utils.CHART_PERMISSION_ID_YANXUAN,
  46. "交通运输": utils.CHART_PERMISSION_ID_YANXUAN,
  47. "国防军工": utils.CHART_PERMISSION_ID_YANXUAN,
  48. "银行": utils.CHART_PERMISSION_ID_YANXUAN,
  49. "有色金属": utils.CHART_PERMISSION_ID_YANXUAN,
  50. "综合": utils.CHART_PERMISSION_ID_YANXUAN,
  51. "商业贸易": utils.CHART_PERMISSION_ID_YANXUAN,
  52. "宏观": utils.CHART_PERMISSION_ID_YANXUAN,
  53. "金融工程": utils.CHART_PERMISSION_ID_YANXUAN,
  54. "商贸零售": utils.CHART_PERMISSION_ID_YANXUAN,
  55. "社会服务": utils.CHART_PERMISSION_ID_YANXUAN,
  56. "煤炭": utils.CHART_PERMISSION_ID_YANXUAN,
  57. "石油石化": utils.CHART_PERMISSION_ID_YANXUAN,
  58. "环保": utils.CHART_PERMISSION_ID_YANXUAN,
  59. //研选
  60. }
  61. chartPermissionId = mapIndustrySwName[industrySwName]
  62. return
  63. }
  64. // GetActivityTypeIdWithYiDong 根据易董同步过来的活动类型,自动匹配行业
  65. func GetActivityTypeNameWithYiDong(industrySwName string) (chartPermissionName string) {
  66. mapIndustrySwName := map[string]string{
  67. "家用电器": utils.XIAO_FEI_NAME,
  68. "纺织服饰": utils.XIAO_FEI_NAME,
  69. "休闲服务": utils.XIAO_FEI_NAME,
  70. "食品饮料": utils.XIAO_FEI_NAME,
  71. "美容护理": utils.XIAO_FEI_NAME,
  72. //消费
  73. "汽车": utils.ZHI_ZAO_NAME,
  74. "机械设备": utils.ZHI_ZAO_NAME,
  75. "电力设备": utils.ZHI_ZAO_NAME,
  76. //智造
  77. "电子": utils.KE_JI_NAME,
  78. "计算机": utils.KE_JI_NAME,
  79. "通信": utils.KE_JI_NAME,
  80. //科技
  81. "医药生物": utils.YI_YAO_NAME,
  82. //医药
  83. "策略": utils.CE_LUE_NAME,
  84. //策略
  85. "非银金融": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  86. "建筑装饰": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  87. "基础化工": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  88. "农林牧渔": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  89. "传媒": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  90. "公用事业": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  91. "建筑材料": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  92. "房地产": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  93. "采掘": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  94. "轻工制造": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  95. "钢铁": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  96. "交通运输": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  97. "国防军工": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  98. "银行": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  99. "有色金属": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  100. "综合": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  101. "商业贸易": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  102. "宏观": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  103. "金融工程": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  104. "商贸零售": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  105. "社会服务": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  106. "煤炭": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  107. "石油石化": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  108. "环保": utils.CHART_PERMISSION_NAME_MF_YANXUAN,
  109. //研选
  110. }
  111. chartPermissionName = mapIndustrySwName[industrySwName]
  112. return
  113. }
  114. // 获取易董token
  115. func GetYiDongToken() (token string, err error) {
  116. defer func() {
  117. if err != nil {
  118. fmt.Println(err)
  119. utils.FileLog.Info(err.Error())
  120. }
  121. }()
  122. cacheKey := utils.YI_DONG_ZHENG_TONG_YUN_TOKEN_KEY
  123. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  124. if ttlTime > 0 {
  125. token, _ = utils.Rc.RedisString(cacheKey)
  126. }
  127. if token == "" {
  128. url := utils.YiDongZhengTongYunUrl + "oauth/token?grant_type=client_credentials&response_type=token&client_id=" + utils.YiDongZhengTongYunAppid + "&client_secret=" + utils.YiDongZhengTongYunSecret
  129. method := "GET"
  130. client := &http.Client{}
  131. req, errReq := http.NewRequest(method, url, nil)
  132. if errReq != nil {
  133. err = errReq
  134. return
  135. }
  136. res, errReq := client.Do(req)
  137. if errReq != nil {
  138. err = errReq
  139. return
  140. }
  141. defer res.Body.Close()
  142. type Ydtoklen struct {
  143. Success bool `json:"success"`
  144. ExpiresIn int `json:"expires_in"`
  145. AccessToken string `json:"access_token"`
  146. }
  147. var ydtoklen Ydtoklen
  148. body, errReq := ioutil.ReadAll(res.Body)
  149. if errReq != nil {
  150. err = errReq
  151. return
  152. }
  153. errReq = json.Unmarshal(body, &ydtoklen)
  154. if errReq != nil {
  155. err = errReq
  156. return
  157. }
  158. token = ydtoklen.AccessToken
  159. utils.Rc.Put(cacheKey, ydtoklen.AccessToken, time.Second*7000)
  160. }
  161. return
  162. }
  163. // 获取易董活动列表
  164. func GetYiDongActivity(cont context.Context) (err error) {
  165. //func GetYiDongActivity() (err error) {
  166. defer func() {
  167. if err != nil {
  168. fmt.Println(err)
  169. go utils.SendAlarmMsg("获取易董活动列表失败:"+err.Error(), 2)
  170. utils.FileLog.Info(err.Error())
  171. }
  172. }()
  173. var token string
  174. token, _ = GetYiDongToken()
  175. url := utils.YiDongZhengTongYunUrl + "interact/activityManageApi/getRoadshowList?access_token=" + token
  176. method := "POST"
  177. payload := strings.NewReader(`{
  178. "meetingStatus": "0"
  179. }`)
  180. client := &http.Client{}
  181. req, err := http.NewRequest(method, url, payload)
  182. if err != nil {
  183. fmt.Println(err)
  184. utils.FileLog.Info(err.Error())
  185. return
  186. }
  187. req.Header.Add("Content-Type", "application/json")
  188. res, err := client.Do(req)
  189. if err != nil {
  190. fmt.Println(err)
  191. utils.FileLog.Info(err.Error())
  192. return
  193. }
  194. defer res.Body.Close()
  195. var ApifoxModal *models.ApifoxModal
  196. body, err := ioutil.ReadAll(res.Body)
  197. if err != nil {
  198. fmt.Println(err)
  199. utils.FileLog.Info(err.Error())
  200. return
  201. }
  202. //添加请求日志记录
  203. itemApiLog := new(models.CygxThreeApiLog)
  204. itemApiLog.CreateTime = time.Now()
  205. itemApiLog.Source = 1
  206. itemApiLog.Url = url
  207. itemApiLog.Body = utils.ReplaceSpaceAndWrap(fmt.Sprint(payload))
  208. itemApiLog.Result = string(body)
  209. go models.AddCygxThreeApiLog(itemApiLog)
  210. err = json.Unmarshal(body, &ApifoxModal)
  211. if err != nil {
  212. fmt.Println("Getres.PublicGetDate Err:", err.Error())
  213. utils.FileLog.Info(err.Error())
  214. return
  215. }
  216. OldActYIdongList, err := models.GetActivityListByYiDong()
  217. if err != nil {
  218. fmt.Println(err)
  219. utils.FileLog.Info(string(err.Error()))
  220. return
  221. }
  222. mapOldYiDong := make(map[string]string)
  223. mapOldYiDongBody := make(map[string]string)
  224. for _, v := range OldActYIdongList {
  225. mapOldYiDong[v.YidongActivityId] = v.YidongActivityId
  226. mapOldYiDongBody[v.YidongActivityId] = fmt.Sprint(v.ActivityName, v.Label, v.ChartPermissionId, v.ActivityTime, v.YidongActivityEndTime, v.DistinguishedGuest)
  227. }
  228. // 通过查研观向观向建会的易董活动
  229. yiDongByCygxList, err := models.GetActivityListByYiDongByCygx()
  230. if err != nil {
  231. fmt.Println(err)
  232. utils.FileLog.Info(string(err.Error()))
  233. return
  234. }
  235. yiDongByCygxMap := make(map[string]string)
  236. for _, v := range yiDongByCygxList {
  237. yiDongByCygxMap[v.YidongActivityIdByCygx] = v.YidongActivityIdByCygx
  238. }
  239. var itemsAdd []*models.CygxActivity
  240. if len(ApifoxModal.Result) > 0 {
  241. actList := ApifoxModal.Result
  242. for _, v := range actList {
  243. //同步有效性 1有效,0失效
  244. if v.SyncFlag == "0" {
  245. continue
  246. }
  247. //如果是通过查研观向观向建会的易董活动,就不进行更新的操作
  248. if _, ok := yiDongByCygxMap[v.ID]; ok {
  249. continue
  250. }
  251. var item = new(models.CygxActivity)
  252. item.YidongActivityId = v.ID
  253. item.ActivityTypeId = 3
  254. item.ActivityTypeName = "公司调研电话会"
  255. sliceCompanyInfo := strings.Split(v.CompanyInfo, "(")
  256. sliceActivityTitle := strings.Split(v.CompanyInfo, ")")
  257. companyInfo := sliceCompanyInfo[0]
  258. if len(sliceActivityTitle) > 1 {
  259. item.ActivityName = companyInfo + v.Title
  260. } else {
  261. item.ActivityName = v.Title
  262. }
  263. //fmt.Println(item.ActivityName)
  264. //return err
  265. item.LastUpdatedTime = time.Now()
  266. item.Label = companyInfo
  267. item.TemporaryLabel = companyInfo
  268. item.ChartPermissionId = utils.CHART_PERMISSION_ID_YANXUAN
  269. item.ChartPermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
  270. item.ChartPermissionIdDeputy = GetActivityTypeIdWithYiDong(v.IndustrySwName)
  271. item.ChartPermissionNameDeputy = GetActivityTypeNameWithYiDong(v.IndustrySwName)
  272. item.ChartPermissionNames = item.ChartPermissionName
  273. //if item.ChartPermissionId != item.ChartPermissionIdDeputy {
  274. item.IsShowHz = 1 //默认弘则活动也展示 11.0
  275. //}
  276. item.ActivityTime = v.Start
  277. item.YidongActivityEndTime = v.End
  278. item.YidongSignUpStart = v.SignUpStart
  279. item.YidongSignUpEnd = v.SignUpEnd
  280. item.YidongActivityEndTime = v.End
  281. item.ActivityTimeText = GetActivityTextTime(v.Start)
  282. item.YidongActivityUrl = v.URL
  283. item.ActivityJoinType = v.ActivityJoinType
  284. item.IsExternalLabel = 1
  285. detailYidng, err := GetYiDongActivityDetail(v.ID)
  286. if err != nil {
  287. return err
  288. }
  289. detailList := detailYidng.Resultdetail.GuestPersonList
  290. for _, vdetail := range detailList {
  291. item.DistinguishedGuest += vdetail.PersonName + " " + vdetail.JobName + ","
  292. }
  293. item.DistinguishedGuest = strings.TrimRight(item.DistinguishedGuest, ",")
  294. item.Body = "<p>" + "【" + item.ActivityName + "】" + "<p>时间:" + item.ActivityTimeText + "</p>嘉宾:" + item.DistinguishedGuest + "</p>"
  295. //fmt.Println(item.Body)
  296. //return err
  297. if mapOldYiDong[v.ID] == "" {
  298. itemsAdd = append(itemsAdd, item)
  299. newId, err := models.AddCygxActivity(item)
  300. if err != nil {
  301. fmt.Println(err)
  302. utils.FileLog.Info(string(err.Error()))
  303. return err
  304. }
  305. //把公司名称当做标的 对活动进行产业标的的关联
  306. YidongActivityGroup(companyInfo, int(newId))
  307. } else {
  308. //如果内容主体有做变更,就修改内容
  309. if mapOldYiDongBody[v.ID] != fmt.Sprint(item.ActivityName+"12", item.Label, item.ChartPermissionId, item.ActivityTime, item.YidongActivityEndTime, item.DistinguishedGuest) {
  310. updateParams := make(map[string]interface{})
  311. updateParams["ActivityName"] = item.ActivityName
  312. updateParams["Body"] = item.Body
  313. updateParams["Label"] = item.Label
  314. //updateParams["TemporaryLabel"] = item.TemporaryLabel
  315. updateParams["DistinguishedGuest"] = item.DistinguishedGuest
  316. updateParams["ChartPermissionId"] = item.ChartPermissionId
  317. updateParams["ChartPermissionName"] = item.ChartPermissionName
  318. updateParams["ChartPermissionNames"] = item.ChartPermissionNames
  319. updateParams["ActivityTime"] = item.ActivityTime
  320. updateParams["YidongActivityEndTime"] = item.YidongActivityEndTime
  321. updateParams["ActivityTimeText"] = item.ActivityTimeText
  322. updateParams["YidongActivityUrl"] = item.YidongActivityUrl
  323. updateParams["ActivityJoinType"] = item.ActivityJoinType
  324. updateParams["YidongSignUpStart"] = item.YidongSignUpStart
  325. updateParams["YidongSignUpEnd"] = item.YidongSignUpEnd
  326. updateParams["ChartPermissionIdDeputy"] = item.ChartPermissionIdDeputy
  327. updateParams["ChartPermissionNameDeputy"] = item.ChartPermissionNameDeputy
  328. updateParams["IsShowHz"] = item.IsShowHz
  329. updateParams["IsExternalLabel"] = 1
  330. updateParams["LastUpdatedTime"] = time.Now()
  331. whereParam := map[string]interface{}{"yidong_activity_id": item.YidongActivityId}
  332. err = models.UpdateByExpr(models.CygxActivity{}, whereParam, updateParams)
  333. if err != nil {
  334. return err
  335. }
  336. }
  337. }
  338. }
  339. }
  340. return
  341. }
  342. // 获取易董活动详情
  343. func GetYiDongActivityDetail(activityId string) (detail *models.ApifoxModaldetail, err error) {
  344. defer func() {
  345. if err != nil {
  346. go utils.SendAlarmMsg("获取易董活动详情失败:"+err.Error(), 2)
  347. }
  348. }()
  349. var token string
  350. token, _ = GetYiDongToken()
  351. url := utils.YiDongZhengTongYunUrl + "interact/activityManageApi/getRoadshowDetail?access_token=" + token
  352. method := "POST"
  353. payload := strings.NewReader(`{"activityId":"` + activityId + `"}`)
  354. client := &http.Client{}
  355. req, err := http.NewRequest(method, url, payload)
  356. if err != nil {
  357. fmt.Println(err)
  358. utils.FileLog.Info(err.Error())
  359. return
  360. }
  361. req.Header.Add("Content-Type", "application/json")
  362. res, err := client.Do(req)
  363. if err != nil {
  364. fmt.Println(err)
  365. utils.FileLog.Info(err.Error())
  366. return
  367. }
  368. defer res.Body.Close()
  369. var ApifoxModal *models.ApifoxModaldetail
  370. body, err := ioutil.ReadAll(res.Body)
  371. if err != nil {
  372. fmt.Println(err)
  373. utils.FileLog.Info(err.Error())
  374. return
  375. }
  376. //添加请求日志记录
  377. itemApiLog := new(models.CygxThreeApiLog)
  378. itemApiLog.CreateTime = time.Now()
  379. itemApiLog.Source = 1
  380. itemApiLog.Url = url
  381. itemApiLog.Body = utils.ReplaceSpaceAndWrap(fmt.Sprint(payload))
  382. itemApiLog.Result = string(body)
  383. go models.AddCygxThreeApiLog(itemApiLog)
  384. err = json.Unmarshal(body, &ApifoxModal)
  385. if err != nil {
  386. fmt.Println("Getres.PublicGetDate Err:", err.Error())
  387. utils.FileLog.Info(err.Error())
  388. return
  389. }
  390. detail = ApifoxModal
  391. return
  392. }
  393. // 生成用户相关信息接口 获取用户tgc
  394. func GetYiDongCreateUserInfo(user *models.WxUserItem) (userTgc string, err error) {
  395. defer func() {
  396. if err != nil {
  397. fmt.Println(err)
  398. go utils.SendAlarmMsg("生成用户相关信息接口 获取用户tgc失败:"+err.Error(), 2)
  399. utils.FileLog.Info(err.Error())
  400. }
  401. }()
  402. url := utils.YiDongHuaWeiYunUrl + "app/hz/createUserInfo"
  403. method := "POST"
  404. payload := strings.NewReader(`{
  405. "phone": "` + user.Mobile + `",
  406. "personName": "` + user.RealName + `",
  407. "companyName": "` + user.CompanyName + `",
  408. "jobName": "` + user.Position + `",
  409. "mobileCountryCode": "+` + user.CountryCode + `",
  410. "sourceFrom": "01"
  411. }`)
  412. client := &http.Client{}
  413. req, err := http.NewRequest(method, url, payload)
  414. if err != nil {
  415. fmt.Println(err)
  416. utils.FileLog.Info(err.Error())
  417. return
  418. }
  419. req.Header.Add("Content-Type", "application/json")
  420. res, err := client.Do(req)
  421. if err != nil {
  422. fmt.Println(err)
  423. utils.FileLog.Info(err.Error())
  424. return
  425. }
  426. defer res.Body.Close()
  427. var ApifoxModal *models.ApifoxModalUserTgc
  428. body, err := ioutil.ReadAll(res.Body)
  429. if err != nil {
  430. fmt.Println(err)
  431. utils.FileLog.Info(err.Error())
  432. return
  433. }
  434. err = json.Unmarshal(body, &ApifoxModal)
  435. if err != nil {
  436. fmt.Println("Getres.PublicGetDate Err:", err.Error())
  437. utils.FileLog.Info(err.Error())
  438. return
  439. }
  440. userTgc = ApifoxModal.Result.Tgc
  441. return
  442. }
  443. // GetYiDongOriginalLink 将易懂的短连接转为长链接
  444. func GetYiDongOriginalLink(item *models.ActivityDetail) (yidongLongLink string, err error) {
  445. defer func() {
  446. if err != nil {
  447. fmt.Println(err)
  448. go utils.SendAlarmMsg("将易懂的短连接转为长链接 失败:"+err.Error(), 2)
  449. utils.FileLog.Info(err.Error())
  450. }
  451. }()
  452. sliceYidongActivityUrl := strings.Split(item.YidongActivityUrl, "/")
  453. var shortLink string
  454. if len(sliceYidongActivityUrl) > 1 {
  455. shortLink = sliceYidongActivityUrl[len(sliceYidongActivityUrl)-1]
  456. }
  457. var token string
  458. token, err = GetYiDongToken()
  459. if err != nil {
  460. fmt.Println(err)
  461. return
  462. }
  463. url := utils.YiDonggetOriginalLink + shortLink + "&access_token=" + token
  464. fmt.Println(url)
  465. method := "GET"
  466. client := &http.Client{}
  467. req, err := http.NewRequest(method, url, nil)
  468. if err != nil {
  469. fmt.Println(err)
  470. return
  471. }
  472. res, err := client.Do(req)
  473. if err != nil {
  474. fmt.Println(err)
  475. return
  476. }
  477. defer res.Body.Close()
  478. var ApifoxModal *models.ApifoxgetOriginalLink
  479. body, err := ioutil.ReadAll(res.Body)
  480. if err != nil {
  481. fmt.Println(err)
  482. utils.FileLog.Info(err.Error())
  483. return
  484. }
  485. err = json.Unmarshal(body, &ApifoxModal)
  486. if err != nil {
  487. fmt.Println("Getres.PublicGetDate Err:", err.Error())
  488. utils.FileLog.Info(err.Error())
  489. return
  490. }
  491. lingLink := ApifoxModal.Result
  492. //fmt.Println(lingLink)
  493. //
  494. //slicelingLink := strings.Split(lingLink, "redirect_uri=")
  495. ////var shortLink string
  496. //if len(slicelingLink) > 1 {
  497. // lingLink = slicelingLink[len(slicelingLink)-1]
  498. //}
  499. yidongLongLink = lingLink
  500. return
  501. }
  502. // 处理易董这边过来的时间格式
  503. func GetActivityTextTime(timeYidong string) (timeText string) {
  504. strTime := timeYidong
  505. startTime := utils.StrTimeToTime(strTime)
  506. week := utils.StrDateTimeToWeek(strTime)
  507. timeStrYmd := startTime.Format(utils.FormatDate)
  508. timeStrHmm := startTime.Format(utils.FormatTime)
  509. timeYmd := utils.StrTimeToTime(timeStrYmd + " 12:00:00") //拼接当天中午12点的时间
  510. var amOrPm string
  511. if startTime.After(timeYmd) {
  512. amOrPm = " PM"
  513. } else {
  514. amOrPm = " AM"
  515. }
  516. timeText = timeStrYmd + "(" + week + ")" + timeStrHmm + amOrPm
  517. return
  518. }
  519. //func init() {
  520. // GetYiDongActivityMeeting()
  521. //}
  522. // GetYiDongActivityMeeting获取易董到会详情
  523. func GetYiDongActivityMeeting(cont context.Context) (err error) {
  524. //func GetYiDongActivityMeeting() (err error) {
  525. var condition string
  526. startDate := time.Now().AddDate(0, 0, -1).Format(utils.FormatDateTime)
  527. endDate := time.Now().Add(-time.Minute * 120).Format(utils.FormatDateTime)
  528. condition += ` AND activity_time > ` + "'" + startDate + "'"
  529. condition += ` AND activity_time < ` + "'" + endDate + "'"
  530. //fmt.Println(startDate)
  531. artivityListYidong, err := models.GetActivityListByYidong(condition)
  532. if err != nil {
  533. fmt.Println("GetActivityListByYidong Err:", err.Error())
  534. return err
  535. }
  536. //fmt.Println(artivityListYidong)
  537. //return
  538. //fmt.Println("artivityListYidong", artivityListYidong)
  539. //return err
  540. if len(artivityListYidong) == 0 {
  541. return err
  542. }
  543. var token string
  544. token, _ = GetYiDongToken()
  545. for _, v := range artivityListYidong {
  546. defer func() {
  547. if err != nil {
  548. go utils.SendAlarmMsg("获取易董到会详情失败:"+err.Error(), 2)
  549. }
  550. }()
  551. var yidongActivityId string
  552. if v.YidongActivityId != "" {
  553. yidongActivityId = v.YidongActivityId
  554. } else if v.YidongActivityIdByCygx != "" {
  555. yidongActivityId = v.YidongActivityIdByCygx
  556. }
  557. url := utils.YiDongZhengTongYunUrl + "interact/activityManageApi/getAttendPersonList?access_token=" + token
  558. method := "POST"
  559. payload := strings.NewReader(`{"activityId":"` + yidongActivityId + `"}`)
  560. client := &http.Client{}
  561. req, err := http.NewRequest(method, url, payload)
  562. if err != nil {
  563. fmt.Println(err)
  564. utils.FileLog.Info(err.Error())
  565. return err
  566. }
  567. req.Header.Add("Content-Type", "application/json")
  568. res, err := client.Do(req)
  569. if err != nil {
  570. fmt.Println(err)
  571. utils.FileLog.Info(err.Error())
  572. return err
  573. }
  574. defer res.Body.Close()
  575. var ApifoxModal *models.ApifoxModaluser
  576. body, err := ioutil.ReadAll(res.Body)
  577. if err != nil {
  578. fmt.Println(err)
  579. utils.FileLog.Info(err.Error())
  580. return err
  581. }
  582. //utils.FileLog.Info(string(body))
  583. //fmt.Println(string(body))
  584. err = json.Unmarshal(body, &ApifoxModal)
  585. if err != nil {
  586. fmt.Println("Getres.PublicGetDate Err:", err.Error())
  587. utils.FileLog.Info(err.Error())
  588. return err
  589. }
  590. //跟易董返回的用户状态修改活动以提交到会状态
  591. err = models.UpdateCygxActivitySubmitMeetingByYidong(yidongActivityId)
  592. if err != nil {
  593. fmt.Println("UpdateCygxActivitySubmitMeetingByYidong Err:", err.Error())
  594. return err
  595. }
  596. var mobiles []string
  597. var mobileStr string
  598. var mobileStrMeet string
  599. mapActivityAttendanceDetail := make(map[string]*models.CygxActivityAttendanceDetail)
  600. if len(ApifoxModal.Result) > 0 {
  601. itemlog := new(models.CygxYidongActivityMeetingApiLog)
  602. itemlog.YidongActivityId = yidongActivityId
  603. itemlog.Data = string(body)
  604. itemlog.CreateTime = time.Now()
  605. err = models.AddCygxYidongActivityMeetingApiLog(itemlog)
  606. if err != nil {
  607. fmt.Println("AddCygxYidongActivityMeetingApiLog Err:", err.Error())
  608. return err
  609. }
  610. var itemsUpdate []*models.CygxActivitySignupDetail
  611. needAddAttendanc := make([]*models.CygxActivityAttendanceDetail, 0)
  612. for _, vresult := range ApifoxModal.Result {
  613. if vresult.PersonTelephone == "" {
  614. continue
  615. }
  616. if vresult.Duration != "" || vresult.DurationReview != "" {
  617. mobiles = append(mobiles, vresult.PersonTelephone)
  618. //err = models.UpdateCygxActivitySignupisMeet(v.ActivityId, vresult.PersonTelephone)
  619. //if err != nil {
  620. // fmt.Println("UpdateCygxActivitySignupisMeet Err:", err.Error())
  621. // return err
  622. //}
  623. var itemDetail = new(models.CygxActivitySignupDetail)
  624. if vresult.Duration != "" {
  625. itemDetail.FirstMeetingTime = vresult.StartTime
  626. itemDetail.LastMeetingTime = vresult.EndTime
  627. itemDetail.Duration = vresult.Duration
  628. itemDetail.MeetingStatusStr = "直播"
  629. } else if vresult.DurationReview != "" {
  630. itemDetail.FirstMeetingTime = vresult.StartTimeReview
  631. itemDetail.LastMeetingTime = vresult.EndTimeReview
  632. itemDetail.Duration = vresult.DurationReview
  633. itemDetail.MeetingStatusStr = "回放"
  634. }
  635. itemDetail.Position = vresult.JobName
  636. itemDetail.RealName = vresult.PersonName
  637. itemDetail.Mobile = vresult.PersonTelephone
  638. itemDetail.OutboundMobile = vresult.PersonTelephone
  639. itemDetail.IsMeeting = 1
  640. itemDetail.ActivityId = v.ActivityId
  641. mapActivityAttendanceDetail[vresult.PersonTelephone] = new(models.CygxActivityAttendanceDetail)
  642. mapActivityAttendanceDetail[vresult.PersonTelephone].FirstMeetingTime = vresult.StartTime
  643. mapActivityAttendanceDetail[vresult.PersonTelephone].LastMeetingTime = vresult.EndTime
  644. mapActivityAttendanceDetail[vresult.PersonTelephone].Duration = utils.GetAttendanceDetailSecondsByYiDong(vresult.Duration)
  645. itemsUpdate = append(itemsUpdate, itemDetail)
  646. }
  647. item := new(models.CygxActivityAttendanceDetail)
  648. item.ActivityId = v.ActivityId
  649. item.Mobile = vresult.PersonTelephone
  650. if vresult.Duration != "" {
  651. if vresult.Duration != "" {
  652. item.FirstMeetingTime = vresult.StartTime
  653. item.LastMeetingTime = vresult.EndTime
  654. item.Duration = vresult.Duration
  655. item.MeetingStatusStr = "直播"
  656. } else if vresult.DurationReview != "" {
  657. item.FirstMeetingTime = vresult.StartTimeReview
  658. item.LastMeetingTime = vresult.EndTimeReview
  659. item.Duration = vresult.DurationReview
  660. item.MeetingStatusStr = "回放"
  661. }
  662. item.Position = vresult.JobName
  663. item.RealName = vresult.PersonName
  664. item.FirstMeetingTime = vresult.StartTime
  665. item.LastMeetingTime = vresult.EndTime
  666. item.Duration = vresult.Duration
  667. item.IsMeetingStr = 1
  668. mobileStrMeet += "'" + vresult.PersonTelephone + "'" + ","
  669. item.CreateTime = time.Now()
  670. needAddAttendanc = append(needAddAttendanc, item)
  671. }
  672. mobileStr += "'" + vresult.PersonTelephone + "'" + ","
  673. }
  674. lenmobiles := len(mobiles)
  675. if lenmobiles > 0 {
  676. var parsYd []interface{}
  677. var conditionYd string
  678. conditionYd = ` AND mobile IN (` + utils.GetOrmInReplace(lenmobiles) + `) AND activity_id=? `
  679. parsYd = append(parsYd, mobiles, v.ActivityId)
  680. err = models.UpdateCygxActivitySignupisMeetList(conditionYd, parsYd)
  681. if err != nil {
  682. fmt.Println("UpdateCygxActivitySignupisMeetList Err:", err.Error())
  683. return err
  684. }
  685. err = models.UpdateActivitySignupDetailMultiByYiDong(itemsUpdate)
  686. if err != nil {
  687. fmt.Println("UpdateActivitySignupDetailMultiByYiDong Err:", err.Error())
  688. return err
  689. }
  690. }
  691. mobileStr = strings.TrimRight(mobileStr, ",")
  692. if mobileStr == "" {
  693. mobileStr = "1"
  694. }
  695. mobileStrMeet = strings.TrimRight(mobileStrMeet, ",")
  696. if mobileStrMeet == "" {
  697. mobileStrMeet = "1"
  698. }
  699. listUser, err := models.GetWxUserOutboundMobile(mobileStr)
  700. if err != nil {
  701. fmt.Println("GetWxUserOutboundMobile Err:", err.Error())
  702. return err
  703. }
  704. for kAdd, vAdd := range needAddAttendanc {
  705. for _, v2 := range listUser {
  706. if v2.OutboundMobile == vAdd.Mobile || v2.Mobile == vAdd.Mobile {
  707. if needAddAttendanc[kAdd].CompanyId <= 1 {
  708. needAddAttendanc[kAdd].CompanyId = v2.CompanyId
  709. needAddAttendanc[kAdd].SellerName = v2.SellerName
  710. needAddAttendanc[kAdd].CompanyName = v2.CompanyName
  711. //needAddAttendanc[k].IsMeetingStr = 1
  712. }
  713. }
  714. }
  715. }
  716. //参会记录
  717. err = models.AddAttendancDetail(needAddAttendanc, v.ActivityId, mobileStrMeet)
  718. if err != nil {
  719. fmt.Println("AddAttendancDetail Err:", err.Error())
  720. return err
  721. }
  722. ////处理是否限制报名
  723. err = AddCygxActivityRestrictSignupByAdmin(v.ActivityId)
  724. if err != nil {
  725. fmt.Println("AddCygxActivityRestrictSignupByAdmin Err:", err.Error())
  726. return err
  727. }
  728. AddctivitySignupDetailByJmcj(needAddAttendanc, v.ActivityId)
  729. }
  730. }
  731. return
  732. }
  733. // YidongActivityGroup 添加活动与产业标的的关联
  734. func YidongActivityGroup(subjectName string, activityId int) (err error) {
  735. subjectList, err := models.GetCygxIndustrialSubjectList(subjectName)
  736. if err != nil {
  737. fmt.Println(err)
  738. return err
  739. }
  740. if len(subjectList) == 0 {
  741. return err
  742. }
  743. fmt.Println("去掉临时标签的活动", activityId)
  744. err = models.UpdateActivityshowSubject(activityId)
  745. if err != nil {
  746. go utils.SendAlarmMsg("UpdateActivityshowSubject :根据易董推过来的匹配信息,判断临时标签是否展示失败"+err.Error(), 2)
  747. }
  748. var industrialActivityItems []*models.CygxIndustrialActivityGroupManagement
  749. var subjectActivityItems []*models.CygxIndustrialActivityGroupSubject
  750. mapSubjectName := make(map[string]string)
  751. for _, v := range subjectList {
  752. industrialActivityItem := new(models.CygxIndustrialActivityGroupManagement)
  753. subjectActivityItem := new(models.CygxIndustrialActivityGroupSubject)
  754. industrialActivityItem.ActivityId = activityId
  755. industrialActivityItem.IndustrialManagementId = v.IndustrialManagementId
  756. industrialActivityItem.Source = 1
  757. industrialActivityItem.CreateTime = time.Now()
  758. industrialActivityItems = append(industrialActivityItems, industrialActivityItem)
  759. subjectActivityItem.ActivityId = activityId
  760. subjectActivityItem.IndustrialSubjectId = v.IndustrialSubjectId
  761. subjectActivityItem.Source = 1
  762. subjectActivityItem.CreateTime = time.Now()
  763. if mapSubjectName[v.SubjectName] == "" {
  764. subjectActivityItems = append(subjectActivityItems, subjectActivityItem)
  765. mapSubjectName[v.SubjectName] = v.SubjectName
  766. }
  767. }
  768. err = models.AddCygxActiuvityGroupMulti(industrialActivityItems, subjectActivityItems)
  769. if err != nil {
  770. go utils.SendAlarmMsg("AddCygxActiuvityGroupMulti :批量添加易董活动关联的活动标签失败"+err.Error(), 2)
  771. }
  772. return
  773. }
  774. // 会前一小时将,报名信息同步到易董
  775. func YiDongSignAppointmentsForThird(cont context.Context) (err error) {
  776. //func YiDongSignAppointmentsForThird() (err error) {
  777. defer func() {
  778. if err != nil {
  779. fmt.Println(err)
  780. go utils.SendAlarmMsg("会前一小时将,报名信息同步到易董,同步失败"+err.Error(), 2)
  781. }
  782. }()
  783. var pars []interface{}
  784. var condition string
  785. startDate := time.Now().Add(+time.Minute * 45).Format(utils.FormatDateTime)
  786. endDate := time.Now().Add(+time.Minute * 60).Format(utils.FormatDateTime)
  787. condition = " AND is_yidong_sign_up = 0 AND yidong_activity_id_by_cygx != '' AND activity_time BETWEEN ? AND ? "
  788. pars = append(pars, startDate, endDate)
  789. activityList, err := models.GetActivityListByCondition(condition, pars)
  790. if err != nil {
  791. return
  792. }
  793. if len(activityList) == 0 {
  794. return
  795. }
  796. listEmail, e := models.GetAskEmail()
  797. if e != nil {
  798. err = errors.New("GetAskEmail, Err: " + e.Error())
  799. return
  800. }
  801. //获取某一个活动下面不需要推送的主讲人手机号
  802. idAndMobileNoSendMap := make(map[string]bool)
  803. for _, v := range activityList {
  804. for _, vName := range listEmail {
  805. if strings.Contains(v.Speaker, vName.Name) {
  806. idAndMobileNoSendMap[fmt.Sprint("Id_", v.ActivityId, "Mobile_", vName.Mobile)] = true
  807. }
  808. }
  809. }
  810. url := utils.YiDongHuaWeiYunUrl + "app/hz/signAppointmentsForThird"
  811. var outCallStatus string
  812. for _, v := range activityList {
  813. go UpdateIsSendYidongSignUp(v.ActivityId)
  814. var parsSignUp []interface{}
  815. var conditionSignUp string
  816. conditionSignUp += ` AND activity_id = ?`
  817. parsSignUp = append(parsSignUp, v.ActivityId)
  818. conditionSignUp += ` AND do_fail_type = 0 `
  819. listSignUp, e := models.GetActivitySignuListByUser(conditionSignUp, parsSignUp)
  820. if e != nil {
  821. err = errors.New("GetActivitySignuListByUser, Err: " + e.Error())
  822. return
  823. }
  824. if len(listSignUp) == 0 {
  825. continue
  826. }
  827. var companyIds []int
  828. for _, vS := range listSignUp {
  829. companyIds = append(companyIds, vS.CompanyId)
  830. }
  831. sellNameMap := GetSellNameMapByCompanyIds(companyIds)
  832. for _, vS := range listSignUp {
  833. if idAndMobileNoSendMap[fmt.Sprint("Id_", vS.ActivityId, "Mobile_", vS.Mobile)] {
  834. continue //如果这个活动对应的是主讲人的手机号,那么就不做推送
  835. }
  836. if vS.SignupType == 1 {
  837. outCallStatus = "1"
  838. } else {
  839. outCallStatus = "0"
  840. }
  841. params := SignAppointmentsForThirdParam{
  842. ActivityId: v.YidongActivityIdByCygx,
  843. MobileCountryCode: "+" + vS.CountryCode,
  844. PersonTelephone: vS.OutboundMobile,
  845. ThirdPartySource: "01",
  846. InvestorType: "0",
  847. PersonName: vS.RealName,
  848. JoinRole: "2",
  849. CompanyName: vS.CompanyName,
  850. Extend1: sellNameMap[vS.CompanyId],
  851. OutCallStatus: outCallStatus,
  852. }
  853. postData, e := json.Marshal(params)
  854. if e != nil {
  855. err = e
  856. fmt.Println("PostData json.Marshal Err:" + err.Error())
  857. utils.FileLog.Info("PostData json.Marshal Err:" + err.Error())
  858. return
  859. }
  860. method := "POST"
  861. client := &http.Client{}
  862. req, e := http.NewRequest(method, url, strings.NewReader(string(postData)))
  863. if e != nil {
  864. err = e
  865. fmt.Println(err)
  866. return
  867. }
  868. req.Header.Add("Content-Type", "application/json")
  869. res, e := client.Do(req)
  870. if e != nil {
  871. err = e
  872. return
  873. }
  874. defer res.Body.Close()
  875. body, e := ioutil.ReadAll(res.Body)
  876. if e != nil {
  877. err = e
  878. return
  879. }
  880. itemApiLog := new(models.CygxThreeApiLog)
  881. itemApiLog.CreateTime = time.Now()
  882. itemApiLog.Source = 1
  883. itemApiLog.Url = url
  884. itemApiLog.Body = string(postData)
  885. itemApiLog.Result = string(body)
  886. go models.AddCygxThreeApiLog(itemApiLog)
  887. var yidongResp *YiDongSignAppointmentsForThirdResp
  888. err = json.Unmarshal(body, &yidongResp)
  889. if err != nil {
  890. return
  891. }
  892. if !yidongResp.Success {
  893. err = errors.New(" 会前一小时将,报名信息同步到易董,同步失败," + yidongResp.ErrorCode + yidongResp.ErrorMsg)
  894. return
  895. }
  896. }
  897. }
  898. return
  899. }
  900. type SignAppointmentsForThirdParam struct {
  901. ActivityId string `description:"易董活动ID" json:"activityId"`
  902. MobileCountryCode string `description:"国际区号注意要带前面+号 " json:"mobileCountryCode"`
  903. PersonTelephone string `description:"手机号" json:"personTelephone"`
  904. ThirdPartySource string `description:"第三方来源;弘则固定:01" json:"thirdPartySource"`
  905. InvestorType string `description:"投资者类型 0个人1机构" json:"investorType"`
  906. PersonName string `description:"姓名" json:"personName"`
  907. CompanyName string `description:"公司名" json:"companyName"`
  908. JoinRole string `description:"1:嘉宾, 2:普通参会人员, 3:会议助理。不传默认取值2" json:"joinRole"`
  909. OutCallStatus string `description:"1:需要,0:不需要。不传取默认值0" json:"outCallStatus"`
  910. Extend1 string `description:"对口销售" json:"extend1"`
  911. }
  912. type YiDongSignAppointmentsForThirdResp struct {
  913. ErrorCode string `json:"errorCode"` // 错误码,001:活动不存在;002:该活动不支持此渠道报名;003:该手机号或邮箱已经被其他账号提交报名;004:不在报名时间;005:报名人数已满
  914. ErrorMsg string `json:"errorMsg"` // 错误信息
  915. Success bool `json:"success"` // 成功标识,true:成功;false:失败。可作为判断报名是否成功的标识
  916. Timestamp float64 `json:"timestamp"` // 时间戳
  917. }