activity_sign.go 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_cygx/models"
  5. "hongze/hongze_cygx/services"
  6. "hongze/hongze_cygx/utils"
  7. "strconv"
  8. "time"
  9. )
  10. // 活动
  11. type ActivitySignCoAntroller struct {
  12. BaseAuthController
  13. }
  14. // @Title 活动扫码自动签到
  15. // @Description 活动扫码签到接口
  16. // @Param ActivityId query int true "活动ID"
  17. // @Success Ret=200 {object} models.CygxActivityResp
  18. // @router /detail [get]
  19. func (this *ActivitySignCoAntroller) Detail() {
  20. br := new(models.BaseResponse).Init()
  21. defer func() {
  22. this.Data["json"] = br
  23. this.ServeJSON()
  24. }()
  25. user := this.User
  26. if user == nil {
  27. br.Msg = "请登录"
  28. br.ErrMsg = "请登录,用户信息为空"
  29. br.Ret = 408
  30. return
  31. }
  32. uid := user.UserId
  33. activityId, _ := this.GetInt("ActivityId")
  34. if activityId < 1 {
  35. br.Msg = "请输入活动ID"
  36. return
  37. }
  38. resp := new(models.CygxActivitySigninDetailResp)
  39. activityInfo, err := models.GetAddActivityInfoByIdShow(uid, activityId)
  40. if err != nil && err.Error() != utils.ErrNoRow() {
  41. br.Msg = "获取信息失败"
  42. br.ErrMsg = "获取活动详情信息失败,Err:" + err.Error()
  43. return
  44. }
  45. if activityInfo == nil {
  46. br.Msg = "活动不存在"
  47. br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
  48. return
  49. }
  50. totalMySuccess, err := models.GetActivitySignupCount(uid, activityId)
  51. if err != nil {
  52. br.Msg = "获取失败"
  53. br.ErrMsg = "获取失败,Err:" + err.Error()
  54. return
  55. }
  56. detail := new(models.CygxActivitySigninResp)
  57. if totalMySuccess > 0 {
  58. detail.IsSignup = true
  59. }
  60. var condition string
  61. var pars []interface{}
  62. condition = " AND user_id = ? AND activity_id = ? "
  63. pars = append(pars, uid, activityId)
  64. total, err := models.GetCygxActivitySigninCount(condition, pars)
  65. if err != nil {
  66. br.Msg = "获取失败"
  67. br.ErrMsg = "获取失败,Err:" + err.Error()
  68. return
  69. }
  70. item := new(models.CygxActivitySignin)
  71. item.ActivityId = activityId
  72. item.UserId = user.UserId
  73. item.Mobile = user.Mobile
  74. item.Email = user.Email
  75. item.CompanyId = user.CompanyId
  76. item.RealName = user.RealName
  77. item.CompanyName = user.CompanyName
  78. item.IsSignup = totalMySuccess
  79. item.CountryCode = user.CountryCode
  80. item.CreateTime = time.Now()
  81. if total == 0 && user.Mobile != "" {
  82. err = models.AddCygxActivitySignin(item)
  83. if err != nil {
  84. br.Msg = "签到失败"
  85. br.ErrMsg = "获取失败,Err:" + err.Error()
  86. return
  87. }
  88. }
  89. //记录签到信息到用户到会表
  90. if user.CompanyId > 1 {
  91. totalOfflineMeeting, err := models.GetCygxActivityOfflineMeetingDetailCount(condition, pars)
  92. if err != nil {
  93. br.Msg = "获取失败"
  94. br.ErrMsg = "获取失败,Err:" + err.Error()
  95. return
  96. }
  97. if totalOfflineMeeting == 0 {
  98. itemOfflineMeeting := new(models.CygxActivityOfflineMeetingDetail)
  99. itemOfflineMeeting.UserId = user.UserId
  100. itemOfflineMeeting.ActivityId = activityId
  101. itemOfflineMeeting.CreateTime = time.Now()
  102. itemOfflineMeeting.Mobile = user.Mobile
  103. itemOfflineMeeting.CompanyId = user.CompanyId
  104. itemOfflineMeeting.CompanyName = user.CompanyName
  105. itemOfflineMeeting.IsMeeting = 1
  106. err = models.AddCygxActivityOfflineMeetingDetail(itemOfflineMeeting)
  107. if err != nil {
  108. br.Msg = "签到失败"
  109. br.ErrMsg = "获取失败AddCygxActivityOfflineMeetingDetail,Err:" + err.Error()
  110. return
  111. }
  112. }
  113. }
  114. //添加日志记录
  115. go services.AddCygxActivitySigninLog(item)
  116. //把报名信息写入签到到会表
  117. go services.AddCygxActivityOfflineMeetingDetail(activityId)
  118. if user.Mobile != "" {
  119. resp.IsBindingMobile = true
  120. }
  121. if user.CompanyId == 1 {
  122. detail.IsNewUser = true
  123. }
  124. detail.ActivityId = activityId
  125. detail.ActivityName = activityInfo.ActivityName
  126. detail.Mobile = user.Mobile
  127. detail.RealName = user.RealName
  128. detail.CompanyName = user.CompanyName
  129. resp.Detail = detail
  130. br.Ret = 200
  131. br.Success = true
  132. br.Msg = "获取成功"
  133. br.Data = resp
  134. }
  135. // @Title 活动扫码手动签到
  136. // @Description 活动扫码手动签到接口
  137. // @Param ActivityId query int true "活动ID"
  138. // @Success Ret=200 {object} models.CygxActivityResp
  139. // @router /byHand [post]
  140. func (this *ActivitySignCoAntroller) ByHand() {
  141. br := new(models.BaseResponse).Init()
  142. defer func() {
  143. this.Data["json"] = br
  144. this.ServeJSON()
  145. }()
  146. user := this.User
  147. if user == nil {
  148. br.Msg = "请登录"
  149. br.ErrMsg = "请登录,用户信息为空"
  150. br.Ret = 408
  151. return
  152. }
  153. uid := user.UserId
  154. resp := new(models.CygxActivitySigninDetailResp)
  155. var req models.CygxActivitySigninReq
  156. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  157. if err != nil {
  158. br.Msg = "参数解析异常!"
  159. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  160. return
  161. }
  162. signinType := req.SigninType
  163. activityId := req.ActivityId
  164. CountryCode := req.CountryCode
  165. Mobile := req.Mobile
  166. CompanyName := req.CompanyName
  167. BusinessCard := req.BusinessCard
  168. RealName := req.RealName
  169. if activityId < 1 {
  170. br.Msg = "请输入活动ID"
  171. return
  172. }
  173. user.RealName = RealName
  174. user.CompanyName = CompanyName
  175. activityInfo, err := models.GetAddActivityInfoByIdShow(uid, activityId)
  176. if err != nil && err.Error() != utils.ErrNoRow() {
  177. br.Msg = "获取信息失败"
  178. br.ErrMsg = "获取活动详情信息失败,Err:" + err.Error()
  179. return
  180. }
  181. if activityInfo == nil {
  182. br.Msg = "活动不存在"
  183. br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
  184. return
  185. }
  186. totalMySuccess, err := models.GetActivitySignupCount(uid, activityId)
  187. if err != nil {
  188. br.Msg = "获取失败"
  189. br.ErrMsg = "获取失败,Err:" + err.Error()
  190. return
  191. }
  192. item := new(models.CygxActivitySignin)
  193. var condition string
  194. var pars []interface{}
  195. condition = " AND user_id = ? AND activity_id = ? "
  196. pars = append(pars, uid, activityId)
  197. total, err := models.GetCygxActivitySigninCount(condition, pars)
  198. if err != nil {
  199. br.Msg = "获取失败"
  200. br.ErrMsg = "获取失败,Err:" + err.Error()
  201. return
  202. }
  203. if signinType == 1 {
  204. if req.Mobile == "" {
  205. br.Msg = "参数错误"
  206. br.ErrMsg = "参数错误,手机号为空 为空"
  207. return
  208. }
  209. itemMsgCode, err := models.GetMsgCode(req.Mobile, req.VCode)
  210. if err != nil {
  211. if err.Error() == utils.ErrNoRow() {
  212. br.Msg = "验证码错误,请重新输入"
  213. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  214. return
  215. } else {
  216. br.Msg = "验证码错误,请重新输入"
  217. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  218. return
  219. }
  220. }
  221. if itemMsgCode == nil {
  222. br.Msg = "验证码错误,请重新输入"
  223. return
  224. }
  225. userMobile, err := models.GetWxUserItemByMobile(Mobile)
  226. if err != nil && err.Error() != utils.ErrNoRow() {
  227. br.Msg = "签到失败"
  228. br.ErrMsg = "获取失败,Err:" + err.Error()
  229. return
  230. }
  231. if userMobile != nil {
  232. user = userMobile
  233. }
  234. } else {
  235. if BusinessCard == "" {
  236. br.Msg = "签到失败"
  237. br.ErrMsg = "签到失败名片地址为空,Err:"
  238. return
  239. }
  240. item.BusinessCard = BusinessCard
  241. }
  242. item.ActivityId = activityId
  243. item.UserId = user.UserId
  244. item.Mobile = Mobile
  245. item.CountryCode = CountryCode
  246. item.Email = user.Email
  247. item.CompanyId = user.CompanyId
  248. item.RealName = user.RealName
  249. item.CompanyName = user.CompanyName
  250. item.IsSignup = totalMySuccess
  251. item.BusinessCard = BusinessCard
  252. item.CreateTime = time.Now()
  253. if total == 0 {
  254. err = models.AddCygxActivitySignin(item)
  255. if err != nil {
  256. br.Msg = "签到失败"
  257. br.ErrMsg = "获取失败,Err:" + err.Error()
  258. return
  259. }
  260. }
  261. detail := new(models.CygxActivitySigninResp)
  262. if totalMySuccess > 0 {
  263. detail.IsSignup = true
  264. }
  265. item.RealName = RealName
  266. item.CompanyName = CompanyName
  267. //添加日志记录
  268. go services.AddCygxActivitySigninLog(item)
  269. if user.CompanyId <= 1 {
  270. detail.IsNewUser = true
  271. }
  272. detail.ActivityId = activityId
  273. detail.ActivityName = activityInfo.ActivityName
  274. detail.Mobile = Mobile
  275. detail.RealName = user.RealName
  276. detail.CompanyName = user.CompanyName
  277. resp.Detail = detail
  278. br.Ret = 200
  279. br.Success = true
  280. br.Msg = "获取成功"
  281. br.Data = resp
  282. }