activity.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  1. package yb
  2. import (
  3. "errors"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "hongze/hz_crm_api/models"
  7. "hongze/hz_crm_api/models/company"
  8. "hongze/hz_crm_api/models/yb"
  9. "hongze/hz_crm_api/models/yb/request"
  10. "hongze/hz_crm_api/services"
  11. "hongze/hz_crm_api/services/alarm_msg"
  12. "hongze/hz_crm_api/services/quanshi"
  13. "hongze/hz_crm_api/utils"
  14. "strconv"
  15. "strings"
  16. "time"
  17. )
  18. // AddActivity 添加活动
  19. func AddActivity(req request.AddActivityReq, userId int) (activityInfo *yb.Activity, err error) {
  20. startTime, err := time.ParseInLocation(utils.FormatDateTime, req.StartTime, time.Local)
  21. if err != nil {
  22. err = errors.New(fmt.Sprint("活动开始日期转换失败:", err))
  23. return
  24. }
  25. endTime, err := time.ParseInLocation(utils.FormatDateTime, req.EndTime, time.Local)
  26. if err != nil {
  27. err = errors.New(fmt.Sprint("活动结束日期转换失败:", err))
  28. return
  29. }
  30. //是否限制人数
  31. var isLimitPeople int8
  32. if req.LimitPeopleNum > 0 {
  33. isLimitPeople = 1
  34. }
  35. // 查询分类详情
  36. activityType, err := yb.GetActivityTypeListById(req.ActivityTypeId)
  37. if err != nil {
  38. return
  39. }
  40. firstActivityType, err := yb.GetActivityTypeListById(activityType.Pid)
  41. if err != nil {
  42. return
  43. }
  44. //活动
  45. activityInfo = &yb.Activity{
  46. FirstActivityTypeId: firstActivityType.ActivityTypeId,
  47. FirstActivityTypeName: firstActivityType.ActivityTypeName,
  48. ActivityTypeId: req.ActivityTypeId,
  49. ActivityTypeName: req.ActivityTypeName,
  50. //ChartPermissionId int `description:"对应的权限id,表chart_permission中id"`
  51. //ChartPermissionName string `description:"对应的权限名称,表chart_permission中name"`
  52. ActivityName: utils.TrimStr(req.ActivityName),
  53. StartTime: startTime,
  54. EndTime: endTime,
  55. Speaker: req.Speaker,
  56. SpeakerHeadPic: req.SpeakerHeadPic,
  57. SpeakerBackgroundPic: getBackgroundPic(firstActivityType.ActivityTypeId),
  58. MainlandTel: req.MainlandTel,
  59. HongKongTel: req.HongKongTel,
  60. TaiwanTel: req.TaiwanTel,
  61. AmericaTel: req.AmericaTel,
  62. SingaporeTel: req.SingaporeTel,
  63. ParticipationCode: req.ParticipationCode,
  64. LinkParticipants: req.LinkParticipants,
  65. IsLimitPeople: isLimitPeople,
  66. LimitPeopleNum: req.LimitPeopleNum,
  67. ReportId: req.ReportId,
  68. ReportLink: req.ReportLink,
  69. ReportName: utils.TrimStr(req.ReportName),
  70. City: req.City,
  71. Address: req.Address,
  72. //VoiceUrl :req.Vi
  73. //Remarks :req.Remarks,
  74. UserId: userId,
  75. PublishStatus: req.PublishStatus,
  76. //ActiveStatus int8 `description:"活动进行状态 未开始:1、进行中2、已结束3"`
  77. IsSendWxMsg: 0,
  78. IsSendSalonWxMsg: 0,
  79. //ArticleId int `description:"报告链接所关联的文章ID"`
  80. ModifyTime: time.Now(),
  81. CreateTime: time.Now(),
  82. IsNewReport: req.IsNewReport,
  83. }
  84. //活动海报
  85. activityPosterList := make([]*yb.ActivityPoster, 0)
  86. for _, v := range req.PosterList {
  87. tmpPoster := &yb.ActivityPoster{
  88. //ActivityId: activityInfo.ActivityId,
  89. Url: v.Url,
  90. Name: v.Name,
  91. CreateTime: time.Now(),
  92. }
  93. activityPosterList = append(activityPosterList, tmpPoster)
  94. }
  95. // 权限列表
  96. activityPermissionList := make([]*yb.ActivityPermission, 0)
  97. permissionIdList := make([]int, 0)
  98. if activityInfo.FirstActivityTypeId == 1 { //电话会这种,直接从数据库里面读取权限配置
  99. activityType, tmpErr := yb.GetActivityTypeListById(activityInfo.ActivityTypeId)
  100. if tmpErr != nil {
  101. err = fmt.Errorf("查询分类权限失败,Err:", tmpErr)
  102. return
  103. }
  104. if activityType.ChartPermissionId != "" {
  105. permissionIds := strings.Split(activityType.ChartPermissionId, ",")
  106. for _, val := range permissionIds {
  107. permissionId, _ := strconv.Atoi(val)
  108. permissionIdList = append(permissionIdList, permissionId)
  109. }
  110. }
  111. } else {
  112. permissionIdList = req.PermissionIdList
  113. }
  114. if len(permissionIdList) > 0 {
  115. permissionList, tmpErr := company.GetChartPermissionListByIds(permissionIdList)
  116. if tmpErr != nil {
  117. err = fmt.Errorf("查询权限失败,Err:", tmpErr)
  118. return
  119. }
  120. for _, v := range permissionList {
  121. tmpPermission := &yb.ActivityPermission{
  122. PermissionId: v.ChartPermissionId,
  123. PermissionName: v.PermissionName,
  124. CreateTime: time.Now(),
  125. }
  126. activityPermissionList = append(activityPermissionList, tmpPermission)
  127. }
  128. }
  129. //新增活动
  130. err = yb.AddNewActivity(activityInfo, activityPosterList, activityPermissionList)
  131. //推送报告给同花顺
  132. //if activityInfo.ReportLink != `` && activityInfo.PublishStatus == 1 {
  133. // go services.SendActivityToThs(activityInfo)
  134. //}
  135. return
  136. }
  137. // EditActivity 编辑活动
  138. func EditActivity(req request.EditActivityReq) (activityInfo *yb.Activity, err error, errMsg string) {
  139. startTime, err := time.ParseInLocation(utils.FormatDateTime, req.StartTime, time.Local)
  140. if err != nil {
  141. err = errors.New(fmt.Sprint("活动开始日期转换失败:", err))
  142. return
  143. }
  144. endTime, err := time.ParseInLocation(utils.FormatDateTime, req.EndTime, time.Local)
  145. if err != nil {
  146. err = errors.New(fmt.Sprint("活动结束日期转换失败:", err))
  147. return
  148. }
  149. activityInfo, err = yb.GetById(req.ActivityId)
  150. if err != nil {
  151. if err.Error() == utils.ErrNoRow() {
  152. errMsg = "找不到该活动"
  153. }
  154. return
  155. }
  156. oldActivityInfo := *activityInfo //修改前的数据
  157. // 活动已结束去除所有时间限制
  158. now := time.Now()
  159. if oldActivityInfo.EndTime.After(now) {
  160. /*if now.After(startTime) {
  161. err = errors.New(fmt.Sprint("活动时间不允许小于当前时间!", err))
  162. errMsg = "活动时间不允许小于当前时间!"
  163. return
  164. }*/
  165. if startTime.After(endTime) {
  166. err = errors.New(fmt.Sprint("活动结束时间不允许小于开始时间!", err))
  167. errMsg = "活动结束时间不允许小于开始时间!"
  168. return
  169. }
  170. allowEndTime := startTime.Add(30 * time.Minute)
  171. if allowEndTime.After(endTime) {
  172. err = errors.New(fmt.Sprint("活动结束时间至少要在开始时间半个小时之后!", err))
  173. errMsg = "活动结束时间至少要在开始时间半个小时之后!"
  174. return
  175. }
  176. }
  177. //是否限制人数
  178. var isLimitPeople int8
  179. if req.LimitPeopleNum > 0 {
  180. isLimitPeople = 1
  181. }
  182. req.ReportLink = utils.TrimStr(req.ReportLink)
  183. updateCols := make([]string, 0)
  184. activityInfo.ActivityName = utils.TrimStr(req.ActivityName)
  185. activityInfo.StartTime = startTime
  186. activityInfo.EndTime = endTime
  187. activityInfo.Speaker = req.Speaker
  188. activityInfo.SpeakerHeadPic = req.SpeakerHeadPic
  189. activityInfo.SpeakerBackgroundPic = getBackgroundPic(activityInfo.FirstActivityTypeId)
  190. activityInfo.MainlandTel = req.MainlandTel
  191. activityInfo.HongKongTel = req.HongKongTel
  192. activityInfo.TaiwanTel = req.TaiwanTel
  193. activityInfo.AmericaTel = req.AmericaTel
  194. activityInfo.SingaporeTel = req.SingaporeTel
  195. activityInfo.ParticipationCode = req.ParticipationCode
  196. activityInfo.LinkParticipants = req.LinkParticipants
  197. activityInfo.IsLimitPeople = isLimitPeople
  198. activityInfo.ReportId = req.ReportId
  199. activityInfo.LimitPeopleNum = req.LimitPeopleNum
  200. activityInfo.ReportLink = req.ReportLink
  201. activityInfo.ReportName = utils.TrimStr(req.ReportName)
  202. activityInfo.City = req.City
  203. activityInfo.Address = req.Address
  204. ////VoiceUrl :req.Vi
  205. activityInfo.Remarks = req.Remarks
  206. activityInfo.IsNewReport = req.IsNewReport
  207. //发布
  208. if req.PublishStatus >= 1 {
  209. activityInfo.PublishStatus = req.PublishStatus
  210. updateCols = append(updateCols, "PublishStatus")
  211. }
  212. activityInfo.ModifyTime = time.Now()
  213. ////ActiveStatus int8 `description:"活动进行状态 未开始:1、进行中2、已结束3"`
  214. ////ArticleId int `description:"报告链接所关联的文章ID"`
  215. //更新
  216. updateCols = append(updateCols, "ActivityName", "StartTime", "EndTime", "Speaker", "SpeakerHeadPic", "SpeakerBackgroundPic", "MainlandTel", "HongKongTel", "TaiwanTel", "AmericaTel", "SingaporeTel", "ParticipationCode", "LinkParticipants", "IsLimitPeople", "LimitPeopleNum", "ReportLink", "ReportName", "ReportId", "City", "Address", "Remarks", "ModifyTime", "IsNewReport")
  217. //插入新的海报文件
  218. activityPosterList := make([]*yb.ActivityPoster, 0)
  219. for _, v := range req.PosterList {
  220. tmpPoster := &yb.ActivityPoster{
  221. ActivityId: activityInfo.ActivityId,
  222. Url: v.Url,
  223. Name: v.Name,
  224. CreateTime: time.Now(),
  225. }
  226. activityPosterList = append(activityPosterList, tmpPoster)
  227. }
  228. //插入新的音频文件
  229. activityVoiceList := make([]*yb.ActivityVoice, 0)
  230. for _, v := range req.VoiceList {
  231. tmpVoice := &yb.ActivityVoice{
  232. ActivityId: activityInfo.ActivityId,
  233. VoiceUrl: v.Url,
  234. VoiceName: v.Name,
  235. VoicePlaySeconds: v.PlaySeconds,
  236. CreateTime: time.Now(),
  237. }
  238. activityVoiceList = append(activityVoiceList, tmpVoice)
  239. }
  240. // 权限列表
  241. activityPermissionList := make([]*yb.ActivityPermission, 0)
  242. permissionIdList := make([]int, 0)
  243. if activityInfo.FirstActivityTypeId == 1 { //电话会这种,直接从数据库里面读取权限配置
  244. activityType, tmpErr := yb.GetActivityTypeListById(activityInfo.ActivityTypeId)
  245. if tmpErr != nil {
  246. err = fmt.Errorf("查询分类权限失败,Err:", tmpErr)
  247. return
  248. }
  249. if activityType.ChartPermissionId != "" {
  250. permissionIds := strings.Split(activityType.ChartPermissionId, ",")
  251. for _, val := range permissionIds {
  252. permissionId, _ := strconv.Atoi(val)
  253. permissionIdList = append(permissionIdList, permissionId)
  254. }
  255. }
  256. } else {
  257. permissionIdList = req.PermissionIdList
  258. }
  259. if len(permissionIdList) > 0 {
  260. permissionList, tmpErr := company.GetChartPermissionListByIds(permissionIdList)
  261. if tmpErr != nil {
  262. err = fmt.Errorf("查询权限失败,Err:", tmpErr)
  263. return
  264. }
  265. for _, v := range permissionList {
  266. tmpPermission := &yb.ActivityPermission{
  267. ActivityId: activityInfo.ActivityId,
  268. PermissionId: v.ChartPermissionId,
  269. PermissionName: v.PermissionName,
  270. CreateTime: time.Now(),
  271. }
  272. activityPermissionList = append(activityPermissionList, tmpPermission)
  273. }
  274. }
  275. err = activityInfo.UpdateActivity(updateCols, activityPosterList, activityVoiceList, activityPermissionList)
  276. if err != nil {
  277. return
  278. }
  279. //变更提醒(活动已经发布了)
  280. if oldActivityInfo.PublishStatus >= 1 {
  281. go sendWxMsg(oldActivityInfo, activityInfo)
  282. }
  283. //推送报告给同花顺
  284. //if activityInfo.ReportLink != `` && activityInfo.PublishStatus == 1 {
  285. // go services.SendActivityToThs(activityInfo)
  286. //}
  287. // 如果开始时间/活动标题有过变更,那么需要去修改全时会议
  288. if !oldActivityInfo.StartTime.Equal(activityInfo.StartTime) || oldActivityInfo.ActivityName != activityInfo.ActivityName {
  289. go updateQsEvent(activityInfo)
  290. }
  291. return
  292. }
  293. // PublishActivity 发布活动
  294. func PublishActivity(activityId int) (activityInfo *yb.Activity, err error, errMsg string) {
  295. activityInfo, err = yb.GetById(activityId)
  296. if err != nil {
  297. if err.Error() == utils.ErrNoRow() {
  298. errMsg = "找不到该活动"
  299. }
  300. return
  301. }
  302. if activityInfo.PublishStatus == 1 {
  303. err = errors.New("该活动已发布")
  304. errMsg = "该活动已发布"
  305. return
  306. }
  307. updateCols := make([]string, 0)
  308. //发布
  309. activityInfo.PublishStatus = 1
  310. activityInfo.ModifyTime = time.Now()
  311. //更新
  312. updateCols = append(updateCols, "PublishStatus", "ModifyTime")
  313. err = activityInfo.Update(updateCols)
  314. //推送同花顺报告
  315. //if activityInfo.ReportLink != `` && activityInfo.PublishStatus == 1 {
  316. // go services.SendActivityToThs(activityInfo)
  317. //}
  318. return
  319. }
  320. // UnPublishActivity 取消发布活动
  321. func UnPublishActivity(activityId int) (activityInfo *yb.Activity, err error, errMsg string) {
  322. activityInfo, err = yb.GetById(activityId)
  323. if err != nil {
  324. if err.Error() == utils.ErrNoRow() {
  325. errMsg = "找不到该活动"
  326. }
  327. return
  328. }
  329. if activityInfo.PublishStatus == 0 {
  330. err = errors.New("该活动未发布")
  331. errMsg = "该活动未发布"
  332. return
  333. }
  334. oldActivityInfo := *activityInfo
  335. o := orm.NewOrm()
  336. to, err := o.Begin()
  337. if err != nil {
  338. return
  339. }
  340. defer func() {
  341. if err != nil {
  342. _ = to.Rollback()
  343. } else {
  344. _ = to.Commit()
  345. }
  346. }()
  347. // 1.取消发布活动
  348. activityInfo.PublishStatus = 0
  349. activityInfo.ModifyTime = time.Now()
  350. updateCols := make([]string, 0)
  351. updateCols = append(updateCols, "PublishStatus", "ModifyTime")
  352. err = activityInfo.Update(updateCols)
  353. if err != nil {
  354. err = errors.New("取消发布失败")
  355. errMsg = "取消发布失败"
  356. return
  357. }
  358. // 2.更新该活动所有报名为取消报名
  359. err = yb.CancelActivityRegisters(activityId)
  360. if err != nil {
  361. err = errors.New("取消报名信息失败")
  362. errMsg = "取消报名信息失败"
  363. return
  364. }
  365. // 3.清除所有活动提醒
  366. err = yb.DelActivityReminds(activityId)
  367. if err != nil {
  368. err = errors.New("清除活动提醒失败")
  369. errMsg = "清除活动提醒失败"
  370. return
  371. }
  372. // 4.变更提醒
  373. go sendWxMsg(oldActivityInfo, activityInfo)
  374. // 取消全时会议
  375. go cancelQsEvent(activityInfo)
  376. return
  377. }
  378. // DelActivity 删除活动
  379. func DelActivity(activityId int) (activityInfo *yb.Activity, err error, errMsg string) {
  380. activityInfo, err = yb.GetById(activityId)
  381. if err != nil {
  382. if err.Error() == utils.ErrNoRow() {
  383. errMsg = "找不到该活动"
  384. }
  385. return
  386. }
  387. if activityInfo.IsDelete == 1 {
  388. err = errors.New("该活动不存在")
  389. errMsg = "该活动不存在"
  390. return
  391. }
  392. updateCols := make([]string, 0)
  393. //发布
  394. activityInfo.IsDelete = 1
  395. activityInfo.ModifyTime = time.Now()
  396. //更新
  397. updateCols = append(updateCols, "IsDelete", "ModifyTime")
  398. err = activityInfo.Update(updateCols)
  399. return
  400. }
  401. // sendWxMsg 发送微信消息
  402. func sendWxMsg(oldActivityInfo yb.Activity, activityInfo *yb.Activity) (err error) {
  403. defer func() {
  404. if err != nil {
  405. fmt.Println(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "发送电话会提醒失败 ErrMsg:"+err.Error())
  406. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "发送电话会提醒失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  407. }
  408. }()
  409. // 如果活动结束时间小于现在,那么也不提醒
  410. if activityInfo.EndTime.Before(time.Now()) {
  411. return
  412. }
  413. //不是我们主持的会议或者沙龙,那么就不通知
  414. if activityInfo.FirstActivityTypeId != 1 && activityInfo.FirstActivityTypeId != 3 {
  415. return
  416. }
  417. var isUpdateTime, isUpdateAddress, isCancel bool //是否更改时间,是否更改地址
  418. if activityInfo.StartTime != oldActivityInfo.StartTime || activityInfo.EndTime != oldActivityInfo.EndTime {
  419. isUpdateTime = true
  420. }
  421. if activityInfo.Address != oldActivityInfo.Address {
  422. isUpdateAddress = true
  423. }
  424. //活动取消
  425. if activityInfo.PublishStatus != oldActivityInfo.PublishStatus && activityInfo.PublishStatus == 0 {
  426. isCancel = true
  427. }
  428. //您有一场【橡胶双周报】发生了时间变更
  429. firstUpdateStr := ""
  430. detailUpdateStr := ``
  431. if isUpdateTime && isUpdateAddress {
  432. firstUpdateStr = `发生了时间变更、活动地址变更`
  433. detailUpdateStr = `原定时间【` + formatActivityTimeStr(oldActivityInfo.StartTime, oldActivityInfo.EndTime) + `】变更为【` + formatActivityTimeStr(activityInfo.StartTime, activityInfo.EndTime) + `】,原定活动地址【` + oldActivityInfo.Address + `】变更为【` + activityInfo.Address + `】`
  434. } else if isUpdateTime {
  435. firstUpdateStr = `发生了时间变更`
  436. detailUpdateStr = `原定时间【` + formatActivityTimeStr(oldActivityInfo.StartTime, oldActivityInfo.EndTime) + `】变更为【` + formatActivityTimeStr(activityInfo.StartTime, activityInfo.EndTime) + `】`
  437. } else if isUpdateAddress {
  438. firstUpdateStr = `发生了活动地址变更`
  439. detailUpdateStr = `原定活动地址【` + oldActivityInfo.Address + `】变更为【` + activityInfo.Address + `】`
  440. } else if isCancel {
  441. firstUpdateStr = `已取消`
  442. detailUpdateStr = `已取消`
  443. } else {
  444. return
  445. }
  446. //您有一场【橡胶双周报】将在15分钟后开始
  447. userIdList := make([]string, 0) //提醒用户列表
  448. //电话会
  449. if activityInfo.FirstActivityTypeId == 1 {
  450. list, tmpErr := yb.GetAllActivityRemindListByActivityId(activityInfo.ActivityId)
  451. if tmpErr != nil {
  452. err = tmpErr
  453. return
  454. }
  455. for _, v := range list {
  456. userIdList = append(userIdList, fmt.Sprint(v.UserId))
  457. }
  458. } else { //沙龙
  459. //提醒
  460. list, tmpErr := yb.GetAllActivityRemindListByActivityId(activityInfo.ActivityId)
  461. if tmpErr != nil {
  462. err = tmpErr
  463. return
  464. }
  465. for _, v := range list {
  466. userIdList = append(userIdList, fmt.Sprint(v.UserId))
  467. }
  468. //线下报名
  469. list2, tmpErr := yb.GetAllActivityRegisterListByActivityId(activityInfo.ActivityId)
  470. if tmpErr != nil {
  471. err = tmpErr
  472. return
  473. }
  474. for _, v := range list2 {
  475. userIdList = append(userIdList, fmt.Sprint(v.UserId))
  476. }
  477. }
  478. if len(userIdList) <= 0 {
  479. return
  480. }
  481. first := `您有一场【` + activityInfo.ActivityTypeName + `】` + firstUpdateStr
  482. keyword1 := activityInfo.ActivityName
  483. keyword2 := detailUpdateStr
  484. remark := ``
  485. //小程序跳转地址
  486. wxAppPath := ``
  487. //如果不是已取消,那么需要让他跳转到详情
  488. if !isCancel {
  489. wxAppPath = `pages-activity/detail?id=` + fmt.Sprint(activityInfo.ActivityId)
  490. remark = `点击查看活动详情`
  491. }
  492. //由于测试环境小程序没有发布,模板消息设置了小程序跳转地址,会导致模板消息发送失败
  493. if utils.RunMode == `debug` {
  494. wxAppPath = ``
  495. }
  496. //获取所有用户的openid列表
  497. openidList, err := models.GetUserOpenidListByUserIds(userIdList)
  498. if err != nil {
  499. return
  500. }
  501. err = services.SendWxMsgWithActivityAppointmentRemind(first, keyword1, keyword2, remark, wxAppPath, openidList)
  502. return
  503. }
  504. // formatActivityTimeStr 格式化活动的开始结束时间
  505. func formatActivityTimeStr(startTime, endTime time.Time) string {
  506. startStr := startTime.Format("2006-01-02 15:04")
  507. endStr := endTime.Format("15:04")
  508. weekStr := ``
  509. weekInt := startTime.Weekday()
  510. switch weekInt {
  511. case 0:
  512. weekStr = `星期日`
  513. case 1:
  514. weekStr = `星期一`
  515. case 2:
  516. weekStr = `星期二`
  517. case 3:
  518. weekStr = `星期三`
  519. case 4:
  520. weekStr = `星期四`
  521. case 5:
  522. weekStr = `星期五`
  523. case 6:
  524. weekStr = `星期六`
  525. }
  526. return startStr + `-` + endStr + ` ` + weekStr
  527. }
  528. // getBackgroundPic 获取活动背景图
  529. func getBackgroundPic(typeId int) (pic string) {
  530. if typeId <= 2 {
  531. //电话会议
  532. pic = `https://hongze.oss-accelerate.aliyuncs.com/static/images/202112/20211214/nNSTxmH6lxlT0PAp7xcfJJTGX9Gu.png`
  533. } else {
  534. //线下沙龙
  535. pic = `https://hongze.oss-accelerate.aliyuncs.com/static/images/202112/20211214/k77gDxvFvuAnYUhF6PU1FOVDHI8O.png`
  536. }
  537. return
  538. }
  539. // CreateQsEvent 创建全时会议
  540. func CreateQsEvent(req request.CreateQsReq) (err error, errMsg string) {
  541. activityInfo, err := yb.GetById(req.ActivityId)
  542. if err != nil {
  543. if err.Error() == utils.ErrNoRow() {
  544. errMsg = "活动信息不存在"
  545. } else {
  546. errMsg = "活动详情获取失败"
  547. }
  548. return
  549. }
  550. //获取最近一条全时会议信息
  551. qsEventInfo, err := yb.GetLastQsEventByActivityId(req.ActivityId)
  552. if err != nil && err.Error() != utils.ErrNoRow() {
  553. errMsg = "获取全时信息异常!"
  554. return
  555. }
  556. if qsEventInfo != nil {
  557. if qsEventInfo.Status == 1 {
  558. errMsg = "全时会议已创建,请勿重复创建!"
  559. return
  560. } else if qsEventInfo.Status == 2 {
  561. qsEventInfo = nil
  562. }
  563. }
  564. //创建全时会议
  565. startTime := activityInfo.StartTime
  566. if startTime.Before(time.Now()) { //如果开始时间早于现在,那么就以现在的时间往后推迟10s作为会议开始时间
  567. startTime = time.Now().Add(10 * time.Second)
  568. }
  569. paramStr := fmt.Sprintf(`activity_id=%d&time=%d`, activityInfo.ActivityId, time.Now().Unix())
  570. signStr := quanshi.GetSign(paramStr)
  571. paramStr += `&sign=` + signStr
  572. callbackUrl := `http://8.136.199.33:8608/api/quanshi/callback?` + paramStr
  573. if utils.RunMode == "release" {
  574. callbackUrl = `https://openapi.hzinsights.com/api/quanshi/callback?` + paramStr
  575. }
  576. qsResp, err := quanshi.QsEventCreate(activityInfo.ActivityName, req.Time, 1, startTime, callbackUrl)
  577. if err != nil {
  578. errMsg = "请求全时接口异常"
  579. return
  580. }
  581. if qsEventInfo != nil {
  582. qsEventInfo.QsEventId = int(qsResp.EventID)
  583. qsEventInfo.StartTime = startTime
  584. qsEventInfo.EndTime = startTime.Add(time.Duration(req.Time*60) * time.Second)
  585. qsEventInfo.ModifyTime = time.Now()
  586. qsEventInfo.Status = 1
  587. err = qsEventInfo.Update([]string{"QsEventId", "StartTime", "EndTime", "ModifyTime", "Status"})
  588. } else {
  589. qsEventInfo = &yb.QsEvent{
  590. YbActivityId: req.ActivityId,
  591. QsEventId: int(qsResp.EventID),
  592. StartTime: startTime,
  593. EndTime: startTime.Add(time.Duration(req.Time*60) * time.Second),
  594. Time: req.Time,
  595. Status: 1,
  596. ModifyTime: time.Now(),
  597. CreateTime: time.Now(),
  598. }
  599. err = yb.AddQsEvent(qsEventInfo)
  600. }
  601. if err != nil {
  602. go alarm_msg.SendAlarmMsg("全时会议创建成功,变更全时记录表信息失败;ERR:"+err.Error(), 3)
  603. errMsg = "保存活动失败!"
  604. return
  605. }
  606. //变更参会信息
  607. activityInfo.HostCode = qsResp.Pcode1
  608. activityInfo.ParticipationCode = qsResp.Pcode2
  609. activityInfo.LinkParticipants = qsResp.AttendeeJoinURL
  610. activityInfo.QsId = qsEventInfo.QsId
  611. err = activityInfo.Update([]string{"HostCode", "ParticipationCode", "LinkParticipants", "QsId"})
  612. if err != nil {
  613. go alarm_msg.SendAlarmMsg("全时会议创建成功,变更参会信息失败;ERR:"+err.Error(), 3)
  614. }
  615. return
  616. }
  617. // CancelQsEvent 取消全时会议
  618. func CancelQsEvent(activityId int) (err error, errMsg string) {
  619. activityInfo, err := yb.GetById(activityId)
  620. if err != nil {
  621. if err.Error() == utils.ErrNoRow() {
  622. errMsg = "找不到该活动!"
  623. } else {
  624. errMsg = "获取活动信息异常!"
  625. }
  626. return
  627. }
  628. err, errMsg = cancelQsEvent(activityInfo)
  629. return
  630. }
  631. // cancelQsEvent 取消全时会议
  632. func cancelQsEvent(activityInfo *yb.Activity) (err error, errMsg string) {
  633. qsEventInfo, err := yb.GetQsEventByActivityId(activityInfo.ActivityId)
  634. if err != nil {
  635. errMsg = "获取全时信息异常!"
  636. return
  637. }
  638. //取消全时会议
  639. err = quanshi.QsEventCancel(qsEventInfo.QsEventId)
  640. if err != nil {
  641. errMsg = "取消全时会议失败!"
  642. return
  643. }
  644. //变更全时会议同步状态
  645. qsEventInfo.Status = 2
  646. err = qsEventInfo.Update([]string{"Status"})
  647. if err != nil {
  648. errMsg = "取消会议失败!"
  649. return
  650. }
  651. //变更活动关联关系id
  652. activityInfo.QsId = 0
  653. activityInfo.HostCode = ""
  654. activityInfo.ParticipationCode = ""
  655. activityInfo.LinkParticipants = ""
  656. err = activityInfo.Update([]string{"QsId", "HostCode", "ParticipationCode", "LinkParticipants"})
  657. if err != nil {
  658. errMsg = "取消会议失败!"
  659. return
  660. }
  661. return
  662. }
  663. // updateQsEvent 修改全时会议
  664. func updateQsEvent(activityInfo *yb.Activity) (err error, errMsg string) {
  665. //获取最近一条全时会议信息
  666. qsEventInfo, err := yb.GetLastQsEventByActivityId(activityInfo.ActivityId)
  667. if err != nil && err.Error() != utils.ErrNoRow() {
  668. errMsg = "获取全时信息异常!"
  669. return
  670. }
  671. if qsEventInfo == nil {
  672. errMsg = "没有创建全时会议!"
  673. err = errors.New("没有创建全时会议")
  674. return
  675. }
  676. //变更全时会议信息
  677. startTime := activityInfo.StartTime
  678. if startTime.Before(time.Now()) { //如果开始时间早于现在,那么就以现在的时间往后推迟10s作为会议开始时间
  679. startTime = time.Now().Add(10)
  680. }
  681. _, err = quanshi.QsEventUpdate(qsEventInfo.QsEventId, qsEventInfo.Time, activityInfo.ActivityName, startTime)
  682. if err != nil {
  683. errMsg = "请求全时接口异常"
  684. return
  685. }
  686. return
  687. }
  688. func SyncUser(qsEventId int) {
  689. //qsEventId := 6631607
  690. qsEventInfo, err := yb.GetQsEventByQsEventId(qsEventId)
  691. if err != nil {
  692. return
  693. }
  694. if qsEventInfo.IsSync == 1 {
  695. return
  696. }
  697. //获取全时的参会人员信息
  698. qsData, err := quanshi.QsEventReportSummary(qsEventId)
  699. if err != nil {
  700. fmt.Println(err)
  701. return
  702. }
  703. fmt.Println(qsData)
  704. //获取全时录制的流媒体信息
  705. qsVideoData, err := quanshi.QsEventReportQueryVideo(int64(qsEventId))
  706. if err != nil {
  707. fmt.Println(err)
  708. return
  709. }
  710. fmt.Println(qsData)
  711. if qsData.Summary != nil && len(qsData.Summary) > 0 {
  712. for _, v := range qsData.Summary {
  713. fmt.Println(v)
  714. mobile := v.Mobile
  715. trimMobile := mobile
  716. countryCode := "86"
  717. var companyProductInfo *company.CompanyProduct
  718. var wxUserInfo *models.WxUser
  719. if mobile != "" {
  720. trimMobileSlice := strings.Split(v.Mobile, "-")
  721. lenTrimMobileSlice := len(trimMobileSlice)
  722. if lenTrimMobileSlice > 1 {
  723. trimMobile = trimMobileSlice[1]
  724. countryCode = strings.Replace(trimMobileSlice[0], "+", "", -1)
  725. }
  726. fmt.Println(trimMobile)
  727. fmt.Println(countryCode)
  728. wxUserInfo, _ = models.GetWxUserByMobileCountryCode(trimMobile, countryCode)
  729. if wxUserInfo != nil {
  730. companyProductInfo, _ = company.GetCompanyProductByCompanyIdAndProductId(wxUserInfo.CompanyId, 1)
  731. }
  732. }
  733. qsEventUserInfo := &yb.QsEventUser{
  734. QsId: qsEventInfo.QsId,
  735. UserId: 0,
  736. Mobile: v.Mobile,
  737. Email: v.Email,
  738. Name: v.Name,
  739. //RegisterTime: time.Time{},
  740. ViewTotal: 0,
  741. //LastViewTime: time.Time{},
  742. CompanyId: 0,
  743. ProductId: 0,
  744. CompanyName: "",
  745. Status: "",
  746. SellerId: 0,
  747. SellerName: "",
  748. CompanyViewTotal: 0,
  749. CompanyRoadTotal: 0,
  750. CreateTime: time.Now(),
  751. }
  752. //这个时候是系统用户了,美滋滋
  753. if companyProductInfo != nil {
  754. qsEventUserInfo.RegisterTime = wxUserInfo.RegisterTime
  755. userViewStatisticsInfo, _ := models.GetUserViewStatisticsByMobile(trimMobile) //用户阅读信息
  756. if userViewStatisticsInfo != nil {
  757. qsEventUserInfo.ViewTotal = userViewStatisticsInfo.Total
  758. qsEventUserInfo.LastViewTime = userViewStatisticsInfo.LastViewTime
  759. }
  760. qsEventUserInfo.CompanyId = companyProductInfo.CompanyId
  761. qsEventUserInfo.ProductId = companyProductInfo.ProductId
  762. qsEventUserInfo.CompanyName = companyProductInfo.ProductName
  763. qsEventUserInfo.Status = companyProductInfo.Status
  764. qsEventUserInfo.SellerId = companyProductInfo.SellerId
  765. qsEventUserInfo.SellerName = companyProductInfo.SellerName
  766. qsEventUserInfo.CompanyViewTotal = companyProductInfo.ViewTotal
  767. qsEventUserInfo.CompanyRoadTotal = companyProductInfo.RoadShowTotal
  768. }
  769. _ = yb.AddQsEventUser(qsEventUserInfo)
  770. }
  771. }
  772. videoUrl := ``
  773. for k, v := range qsVideoData.Records {
  774. if k == strconv.Itoa(qsEventId) {
  775. videoUrl = v.VideoURL
  776. }
  777. }
  778. qsEventInfo.VideoUrl = videoUrl
  779. qsEventInfo.IsSync = 1
  780. qsEventInfo.QsStatus = 2
  781. err = qsEventInfo.Update([]string{"VideoUrl", "IsSync"})
  782. }