yidong.go 14 KB

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