yidong.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "hongze/hongze_open_api/models/request/yidong"
  6. "hongze/hongze_open_api/models/tables/company_product"
  7. cygxActivity "hongze/hongze_open_api/models/tables/cygx_activity"
  8. "hongze/hongze_open_api/services/alarm_msg"
  9. servicesYidong "hongze/hongze_open_api/services/yidong"
  10. "hongze/hongze_open_api/utils"
  11. "math"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. // 易董
  17. type YiDongController struct {
  18. BaseCommon
  19. }
  20. // YiDongController
  21. // @Title 易董提交报名用户审核接口
  22. // @Description 易董提交报名用户审核接口
  23. // @Param request body yidong.ActivityExamineReq true "type json string"
  24. // @Success 200 创建成功
  25. // @router /activity/examine/signup [post]
  26. func (c *YiDongController) ActivityExamine() {
  27. var req yidong.ActivityExamineReq
  28. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  29. if err != nil {
  30. c.FailWithMessage("参数解析异常")
  31. return
  32. }
  33. activityIdYiDong := req.ActivityId
  34. timeInt := req.Time
  35. list := req.List
  36. appid := req.Appid
  37. timeUnix := time.Now().Unix() //当前格林威治时间,int64类型
  38. timestamp := int64(timeInt)
  39. if math.Abs(float64(timeUnix-timestamp)) > 600 {
  40. c.FailWithMessage("当前时间异常,请调整设备时间与北京时间一致:" + strconv.Itoa(timeInt))
  41. return
  42. }
  43. //校验 APPID 与ip白名单
  44. ip := c.Ctx.Input.IP()
  45. err = servicesYidong.CheckAppidAndIp(appid, ip)
  46. if err != nil {
  47. c.FailWithMessage(err.Error())
  48. return
  49. }
  50. //校验 签名
  51. signStr := servicesYidong.GetSign(activityIdYiDong, timeInt)
  52. ownSign := req.Sign
  53. if ownSign != signStr {
  54. c.FailWithMessage("签名错误!")
  55. return
  56. }
  57. activityInfo, err := cygxActivity.GetAddActivityInfoById(activityIdYiDong)
  58. if err != nil {
  59. c.FailWithMessage("会议id异常:" + activityIdYiDong)
  60. return
  61. }
  62. activityId := activityInfo.ActivityId
  63. var examineMobile string
  64. var delMyMobile string //审核不通过需要删除日程的手机号
  65. var delSignupMobile string //取消活动需要删除报名信息的手机号
  66. var itemsLog []*cygxActivity.CygxYidongActivityExamineStatus
  67. for _, v := range list {
  68. var dateTxt = []byte(v.Mobile)
  69. resultDe := utils.DesBase64Decrypt(dateTxt)
  70. deMobile := string(resultDe)
  71. if deMobile == "" {
  72. go alarm_msg.SendAlarmMsg("加密手机号解密失败:"+v.Mobile, 3)
  73. c.FailWithMessage("加密手机号解密失败:" + v.Mobile)
  74. return
  75. }
  76. examineMobile += "'" + deMobile + "'" + ","
  77. itemlog := new(cygxActivity.CygxYidongActivityExamineStatus)
  78. //记录日志
  79. itemlog.ActivityId = activityId
  80. itemlog.YidongActivityId = activityIdYiDong
  81. itemlog.CreateTime = time.Now()
  82. itemlog.ExamineTime = v.CreateTime
  83. itemlog.Mobile = deMobile
  84. itemlog.YidongExamineStatus = v.ExamineStatus
  85. itemsLog = append(itemsLog, itemlog)
  86. }
  87. //记录日志
  88. err = cygxActivity.AddActivityItemsLogNumMulti(itemsLog)
  89. if err != nil {
  90. c.FailWithMessage("修改活动审核状态失败:" + activityIdYiDong)
  91. go alarm_msg.SendAlarmMsg("修改活动审核状态失败AddActivityItemsLogNumMulti:"+err.Error()+"活动ID"+activityIdYiDong, 3)
  92. return
  93. }
  94. //以下处理传过来的逻辑
  95. // 获取已经报名了的用户列表
  96. signupList, err := cygxActivity.GetActivitySignupListByActivity(activityId)
  97. if err != nil {
  98. c.FailWithMessage("会议id异常:" + activityIdYiDong)
  99. return
  100. }
  101. mapSignUp := make(map[string]string)
  102. for _, v := range signupList {
  103. mapSignUp[v.Mobile] = v.Mobile
  104. }
  105. // 获取我的日程列表
  106. myScheduleList, err := cygxActivity.GetCygxMyScheduleList(activityId)
  107. if err != nil {
  108. c.FailWithMessage("会议id异常:" + activityIdYiDong)
  109. return
  110. }
  111. mapMyScheduleList := make(map[string]string)
  112. for _, v := range myScheduleList {
  113. mapMyScheduleList[v.Mobile] = v.Mobile
  114. }
  115. examineMobile = strings.TrimRight(examineMobile, ",")
  116. userList, err := cygxActivity.GetUserListByMobile(examineMobile)
  117. if err != nil {
  118. c.FailWithMessage("操作失败,用户信息不存在")
  119. return
  120. }
  121. mapUserinfo := make(map[string]*cygxActivity.CygxActivitySignup)
  122. mapMySchedule := make(map[string]*cygxActivity.CygxMySchedule)
  123. for _, v := range userList {
  124. item := new(cygxActivity.CygxActivitySignup)
  125. item.UserId = v.UserId
  126. item.RealName = v.RealName
  127. item.SellerName = v.SellerName
  128. item.ActivityId = activityId
  129. item.CreateTime = time.Now()
  130. item.Mobile = v.Mobile
  131. item.Email = v.Email
  132. item.CompanyId = v.CompanyId
  133. item.CompanyName = v.CompanyName
  134. item.Source = 3
  135. //优先绑定用户修改过的外呼手机号
  136. if v.OutboundMobile != "" {
  137. item.OutboundMobile = v.OutboundMobile
  138. if v.OutboundCountryCode == "" {
  139. item.CountryCode = "86"
  140. } else {
  141. item.CountryCode = v.OutboundCountryCode
  142. }
  143. } else {
  144. item.OutboundMobile = v.Mobile
  145. if v.CountryCode == "" {
  146. item.CountryCode = "86"
  147. } else {
  148. item.CountryCode = v.CountryCode
  149. }
  150. }
  151. item.SignupType = 1
  152. mapUserinfo[v.Mobile] = item
  153. //添加我的日程
  154. itemMySchedule := new(cygxActivity.CygxMySchedule)
  155. itemMySchedule.UserId = v.UserId
  156. itemMySchedule.ActivityId = activityId
  157. itemMySchedule.CreateTime = time.Now()
  158. itemMySchedule.Mobile = v.Mobile
  159. itemMySchedule.Email = v.Email
  160. itemMySchedule.CompanyId = v.CompanyId
  161. itemMySchedule.CompanyName = v.CompanyName
  162. mapMySchedule[v.Mobile] = itemMySchedule
  163. }
  164. var items []*cygxActivity.ExamineStatusReq
  165. var itemsAdd []*cygxActivity.CygxActivitySignup
  166. var itemsMyAdd []*cygxActivity.CygxMySchedule
  167. for _, v := range list {
  168. item := new(cygxActivity.ExamineStatusReq)
  169. var dateTxt = []byte(v.Mobile)
  170. resultDe := utils.DesBase64Decrypt(dateTxt)
  171. deMobile := string(resultDe)
  172. if mapSignUp[deMobile] != "" {
  173. item.ActivityId = activityId
  174. item.Mobile = deMobile
  175. item.ExamineStatus = v.ExamineStatus
  176. items = append(items, item)
  177. } else {
  178. if mapUserinfo[deMobile] != nil {
  179. mapUserinfo[deMobile].YidongExamineStatus = v.ExamineStatus
  180. if v.ExamineStatus != 3 {
  181. itemsAdd = append(itemsAdd, mapUserinfo[deMobile])
  182. }
  183. }
  184. }
  185. //处理我的日程
  186. if mapMyScheduleList[deMobile] != "" {
  187. if v.ExamineStatus != 1 {
  188. delMyMobile += "'" + deMobile + "'" + ","
  189. }
  190. if v.ExamineStatus == 3 {
  191. delSignupMobile += "'" + deMobile + "'" + ","
  192. }
  193. } else {
  194. if mapMySchedule[deMobile] != nil {
  195. if v.ExamineStatus == 1 {
  196. itemsMyAdd = append(itemsMyAdd, mapMySchedule[deMobile])
  197. }
  198. }
  199. }
  200. }
  201. //fmt.Println(delSignupMobile)
  202. //return
  203. //处理要删除的日程
  204. delMyMobile = strings.TrimRight(delMyMobile, ",")
  205. if delMyMobile != "" {
  206. fmt.Println("删除日程")
  207. err = cygxActivity.DelCygxMyScheduleList(delMyMobile, activityId)
  208. if err != nil {
  209. go alarm_msg.SendAlarmMsg("处理要删除的日程失败 DelCygxMyScheduleList:"+err.Error()+"活动ID"+activityIdYiDong, 3)
  210. }
  211. }
  212. //处理要删除的报名信息
  213. delSignupMobile = strings.TrimRight(delSignupMobile, ",")
  214. if delSignupMobile != "" {
  215. fmt.Println("处理要删除的报名信息")
  216. err = cygxActivity.DelCygxcActivitySignup(delSignupMobile, activityId)
  217. if err != nil {
  218. go alarm_msg.SendAlarmMsg("处理要删除的报名信息失败 DelCygxMyScheduleList:"+err.Error()+"活动ID"+activityIdYiDong, 3)
  219. }
  220. }
  221. //修改审核状态
  222. err = cygxActivity.UpdateActivitySignupNumMulti(items)
  223. if err != nil {
  224. fmt.Println(err, "UpdateActivitySignupNumMulti")
  225. go alarm_msg.SendAlarmMsg("修改活动审核状态失败:"+err.Error()+"活动ID"+activityIdYiDong, 3)
  226. }
  227. // 批量添加报名信息
  228. err = cygxActivity.AddActivitySignupNumMulti(itemsAdd)
  229. if err != nil {
  230. fmt.Println(err, "AddActivitySignupNumMulti")
  231. go alarm_msg.SendAlarmMsg("修改活动审核状态失败:"+err.Error()+"活动ID"+activityIdYiDong, 3)
  232. }
  233. // 批量添加我的日程
  234. err = cygxActivity.AddCygxMyScheduleLNumMulti(itemsMyAdd)
  235. if err != nil {
  236. fmt.Println(err, "AddCygxMyScheduleLNumMulti")
  237. go alarm_msg.SendAlarmMsg("修改活动审核状态失败:"+err.Error()+"活动ID"+activityIdYiDong, 3)
  238. }
  239. c.OkWithMessage("操作成功")
  240. }
  241. // YiDongController
  242. // @Title 易董提交报名时,获取用户信息接口
  243. // @Description 易董提交报名时,获取用户信息接口
  244. // @Param request body yidong.ActivityExamineReq true "type json string"
  245. // @Success 200 创建成功
  246. // @router /activity/user/signup [post]
  247. func (c *YiDongController) UserSignup() {
  248. var req yidong.ActivitySignUpReq
  249. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  250. if err != nil {
  251. c.FailWithMessage("参数解析异常")
  252. return
  253. }
  254. activityIdYiDong := req.ActivityId
  255. timeInt := req.Time
  256. appid := req.Appid
  257. mobile := req.Mobile
  258. timeUnix := time.Now().Unix() //当前格林威治时间,int64类型
  259. timestamp := int64(timeInt)
  260. if math.Abs(float64(timeUnix-timestamp)) > 600 {
  261. c.FailWithMessage("当前时间异常,请调整设备时间与北京时间一致:" + strconv.Itoa(timeInt))
  262. return
  263. }
  264. //校验 APPID 与ip白名单
  265. ip := c.Ctx.Input.IP()
  266. err = servicesYidong.CheckAppidAndIp(appid, ip)
  267. if err != nil {
  268. c.FailWithMessage(err.Error())
  269. return
  270. }
  271. //校验 签名
  272. signStr := servicesYidong.GetSign(activityIdYiDong, timeInt)
  273. fmt.Println("____")
  274. fmt.Println(signStr)
  275. ownSign := req.Sign
  276. if ownSign != signStr {
  277. c.FailWithMessage("签名错误!")
  278. return
  279. }
  280. activityInfo, err := cygxActivity.GetAddActivityInfoById(activityIdYiDong)
  281. if err != nil {
  282. c.FailWithMessage("会议id异常:" + activityIdYiDong)
  283. return
  284. }
  285. activityId := activityInfo.ActivityId
  286. var dateTxt = []byte(mobile)
  287. resultDe := utils.DesBase64Decrypt(dateTxt)
  288. deMobile := string(resultDe)
  289. if deMobile == "" {
  290. go alarm_msg.SendAlarmMsg("加密手机号解密失败:"+mobile, 3)
  291. c.FailWithMessage("加密手机号解密失败:" + mobile)
  292. return
  293. }
  294. item := new(cygxActivity.CygxYidongActivitySignupLog)
  295. item.ActivityId = activityId
  296. item.YidongActivityId = activityIdYiDong
  297. item.CreateTime = time.Now()
  298. item.Mobile = deMobile
  299. err = cygxActivity.AddCygxYidongActivitySignupLog(item)
  300. if err != nil {
  301. fmt.Println(err)
  302. c.FailWithMessage("获取用户信息失败:" + activityIdYiDong)
  303. go alarm_msg.SendAlarmMsg("修改活动审核状态失败:"+err.Error()+"活动ID"+activityIdYiDong, 3)
  304. return
  305. }
  306. userInfo, err := cygxActivity.GetAddActivityInfoByMobile(deMobile)
  307. if err != nil {
  308. fmt.Println(err)
  309. c.FailWithMessage("获取用户信息失败:" + activityIdYiDong)
  310. go alarm_msg.SendAlarmMsg("修改活动审核状态失败:"+err.Error()+"活动ID"+activityIdYiDong, 3)
  311. return
  312. }
  313. c.OkDetailed(userInfo, "获取成功")
  314. }
  315. // YiDongController
  316. // @Title 校验用户是否有对应权限
  317. // @Description 校验用户是否有对应权限接口
  318. // @Param request body yidong.ActivityExamineReq true "type json string"
  319. // @Success 200 创建成功
  320. // @router /activity/user/check [post]
  321. func (c *YiDongController) UserCheck() {
  322. var req yidong.ActivitySignUpReq
  323. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  324. if err != nil {
  325. c.FailWithMessage("参数解析异常")
  326. return
  327. }
  328. activityIdYiDong := req.ActivityId
  329. timeInt := req.Time
  330. appid := req.Appid
  331. mobile := req.Mobile
  332. timeUnix := time.Now().Unix() //当前格林威治时间,int64类型
  333. timestamp := int64(timeInt)
  334. if math.Abs(float64(timeUnix-timestamp)) > 600 {
  335. c.FailWithMessage("当前时间异常,请调整设备时间与北京时间一致:" + strconv.Itoa(timeInt))
  336. return
  337. }
  338. //校验 APPID 与ip白名单
  339. ip := c.Ctx.Input.IP()
  340. err = servicesYidong.CheckAppidAndIp(appid, ip)
  341. if err != nil {
  342. c.FailWithMessage(err.Error())
  343. return
  344. }
  345. signStr := servicesYidong.GetSign(activityIdYiDong, timeInt)
  346. ownSign := req.Sign
  347. if ownSign != signStr {
  348. c.FailWithMessage("签名错误!")
  349. return
  350. }
  351. _, err = cygxActivity.GetAddActivityInfoById(activityIdYiDong)
  352. if err != nil {
  353. c.FailWithMessage("会议id异常:" + activityIdYiDong)
  354. return
  355. }
  356. var dateTxt = []byte(mobile)
  357. resultDe := utils.DesBase64Decrypt(dateTxt)
  358. deMobile := string(resultDe)
  359. if deMobile == "" {
  360. go alarm_msg.SendAlarmMsg("加密手机号解密失败:"+mobile, 3)
  361. c.FailWithMessage("加密手机号解密失败:" + mobile)
  362. return
  363. }
  364. resp := new(yidong.CheckHaspermissionResp)
  365. total, err := company_product.CheckUserAaiPerssionByMobile(deMobile)
  366. if err != nil {
  367. c.FailWithMessage("校验失败!" + err.Error())
  368. return
  369. }
  370. if total > 0 {
  371. resp.Haspermission = true
  372. }
  373. c.OkDetailed(resp, "获取成功")
  374. }