yidong.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "hongze/hongze_open_api/models/request/yidong"
  6. cygxActivity "hongze/hongze_open_api/models/tables/cygx_activity"
  7. "hongze/hongze_open_api/services/alarm_msg"
  8. servicesYidong "hongze/hongze_open_api/services/yidong"
  9. "hongze/hongze_open_api/utils"
  10. "math"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. // 易董
  16. type YiDongController struct {
  17. BaseCommon
  18. }
  19. // YiDongController
  20. // @Title 易董提交报名用户审核接口
  21. // @Description 易董提交报名用户审核接口
  22. // @Param request body yidong.ActivityExamineReq true "type json string"
  23. // @Success 200 创建成功
  24. // @router /activity/examine/signup [post]
  25. func (c *YiDongController) ActivityExamine() {
  26. var req yidong.ActivityExamineReq
  27. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  28. if err != nil {
  29. c.FailWithMessage("参数解析异常")
  30. return
  31. }
  32. activityIdYiDong := req.ActivityId
  33. timeInt := req.Time
  34. list := req.List
  35. appid := req.Appid
  36. timeUnix := time.Now().Unix() //当前格林威治时间,int64类型
  37. timestamp := int64(timeInt)
  38. if math.Abs(float64(timeUnix-timestamp)) > 600 {
  39. c.FailWithMessage("当前时间异常,请调整设备时间与北京时间一致:" + strconv.Itoa(timeInt))
  40. return
  41. }
  42. //校验 APPID 与ip白名单
  43. ip := c.Ctx.Input.IP()
  44. err = servicesYidong.CheckAppidAndIp(appid, ip)
  45. if err != nil {
  46. c.FailWithMessage(err.Error())
  47. return
  48. }
  49. //校验 签名
  50. paramStr := fmt.Sprintf(`activity_id=%stime=%s`, activityIdYiDong, strconv.Itoa(timeInt))
  51. signStr := servicesYidong.GetSign(paramStr)
  52. fmt.Println("____")
  53. fmt.Println(signStr)
  54. ownSign := req.Sign
  55. if ownSign != signStr {
  56. c.FailWithMessage("签名错误!")
  57. return
  58. }
  59. activityInfo, err := cygxActivity.GetAddActivityInfoById(activityIdYiDong)
  60. if err != nil {
  61. c.FailWithMessage("会议id异常:" + activityIdYiDong)
  62. return
  63. }
  64. activityId := activityInfo.ActivityId
  65. signupList, err := cygxActivity.GetActivitySignupListByActivity(activityId)
  66. if err != nil {
  67. c.FailWithMessage("会议id异常:" + activityIdYiDong)
  68. return
  69. }
  70. mapSignUp := make(map[string]string)
  71. for _, v := range signupList {
  72. mapSignUp[v.Mobile] = v.Mobile
  73. }
  74. var examineMobile string
  75. for _, v := range list {
  76. var dateTxt = []byte(v.Mobile)
  77. resultDe := utils.DesBase64Decrypt(dateTxt)
  78. deMobile := string(resultDe)
  79. if deMobile == "" {
  80. go alarm_msg.SendAlarmMsg("加密手机号解密失败:"+v.Mobile, 3)
  81. c.FailWithMessage("加密手机号解密失败:" + v.Mobile)
  82. return
  83. }
  84. examineMobile += "'" + deMobile + "'" + ","
  85. }
  86. examineMobile = strings.TrimRight(examineMobile, ",")
  87. userList, err := cygxActivity.GetUserListByMobile(examineMobile)
  88. if err != nil {
  89. c.FailWithMessage("操作失败,用户信息不存在")
  90. return
  91. }
  92. mapUserinfo := make(map[string]*cygxActivity.CygxActivitySignup)
  93. for _, v := range userList {
  94. item := new(cygxActivity.CygxActivitySignup)
  95. item.UserId = v.UserId
  96. item.RealName = v.RealName
  97. item.SellerName = v.SellerName
  98. item.ActivityId = activityId
  99. item.CreateTime = time.Now()
  100. item.Mobile = v.Mobile
  101. item.Email = v.Email
  102. item.CompanyId = v.CompanyId
  103. item.CompanyName = v.CompanyName
  104. item.Source = 3
  105. //优先绑定用户修改过的外呼手机号
  106. if v.OutboundMobile != "" {
  107. item.OutboundMobile = v.OutboundMobile
  108. if v.OutboundCountryCode == "" {
  109. item.CountryCode = "86"
  110. } else {
  111. item.CountryCode = v.OutboundCountryCode
  112. }
  113. } else {
  114. item.OutboundMobile = v.Mobile
  115. if v.CountryCode == "" {
  116. item.CountryCode = "86"
  117. } else {
  118. item.CountryCode = v.CountryCode
  119. }
  120. }
  121. item.SignupType = 1
  122. mapUserinfo[v.Mobile] = item
  123. }
  124. var items []*cygxActivity.ExamineStatusReq
  125. var itemsAdd []*cygxActivity.CygxActivitySignup
  126. for _, v := range list {
  127. item := new(cygxActivity.ExamineStatusReq)
  128. //encryptMobile := string(utils.DesBase64Encrypt([]byte(v.Mobile)))
  129. //fmt.Println(encryptMobile)
  130. //continue
  131. //encryptMobile := string(utils.DesBase64Encrypt([]byte(v.Mobile)))
  132. var dateTxt = []byte(v.Mobile)
  133. resultDe := utils.DesBase64Decrypt(dateTxt)
  134. deMobile := string(resultDe)
  135. if deMobile == "" {
  136. c.FailWithMessage("加密手机号解密失败:" + v.Mobile)
  137. go alarm_msg.SendAlarmMsg("加密手机号解密失败:"+v.Mobile, 3)
  138. return
  139. }
  140. if mapSignUp[deMobile] != "" {
  141. item.ActivityId = activityId
  142. item.Mobile = deMobile
  143. item.ExamineStatus = v.ExamineStatus
  144. items = append(items, item)
  145. } else {
  146. if mapUserinfo[deMobile] != nil {
  147. mapUserinfo[deMobile].YidongExamineStatus = v.ExamineStatus
  148. itemsAdd = append(itemsAdd, mapUserinfo[deMobile])
  149. }
  150. }
  151. }
  152. err = cygxActivity.UpdateActivitySignupNumMulti(items)
  153. if err != nil {
  154. c.FailWithMessage("修改活动审核状态失败:" + activityIdYiDong)
  155. go alarm_msg.SendAlarmMsg("修改活动审核状态失败:"+err.Error()+"活动ID"+activityIdYiDong, 3)
  156. return
  157. }
  158. err = cygxActivity.AddActivitySignupNumMulti(itemsAdd)
  159. if err != nil {
  160. c.FailWithMessage("修改活动审核状态失败:" + activityIdYiDong)
  161. go alarm_msg.SendAlarmMsg("修改活动审核状态失败:"+err.Error()+"活动ID"+activityIdYiDong, 3)
  162. return
  163. }
  164. c.OkWithMessage("操作成功")
  165. }