activity_sign.go 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. go services.AddCygxActivitySigninLog(item)
  91. if user.Mobile != "" {
  92. resp.IsBindingMobile = true
  93. }
  94. if user.CompanyId == 1 {
  95. detail.IsNewUser = true
  96. }
  97. detail.ActivityId = activityId
  98. detail.ActivityName = activityInfo.ActivityName
  99. detail.Mobile = user.Mobile
  100. detail.RealName = user.RealName
  101. detail.CompanyName = user.CompanyName
  102. resp.Detail = detail
  103. br.Ret = 200
  104. br.Success = true
  105. br.Msg = "获取成功"
  106. br.Data = resp
  107. }
  108. // @Title 活动扫码手动签到
  109. // @Description 活动扫码手动签到接口
  110. // @Param ActivityId query int true "活动ID"
  111. // @Success Ret=200 {object} models.CygxActivityResp
  112. // @router /byHand [post]
  113. func (this *ActivitySignCoAntroller) ByHand() {
  114. br := new(models.BaseResponse).Init()
  115. defer func() {
  116. this.Data["json"] = br
  117. this.ServeJSON()
  118. }()
  119. user := this.User
  120. if user == nil {
  121. br.Msg = "请登录"
  122. br.ErrMsg = "请登录,用户信息为空"
  123. br.Ret = 408
  124. return
  125. }
  126. uid := user.UserId
  127. resp := new(models.CygxActivitySigninDetailResp)
  128. var req models.CygxActivitySigninReq
  129. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  130. if err != nil {
  131. br.Msg = "参数解析异常!"
  132. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  133. return
  134. }
  135. signinType := req.SigninType
  136. activityId := req.ActivityId
  137. CountryCode := req.CountryCode
  138. Mobile := req.Mobile
  139. CompanyName := req.CompanyName
  140. BusinessCard := req.BusinessCard
  141. RealName := req.RealName
  142. if activityId < 1 {
  143. br.Msg = "请输入活动ID"
  144. return
  145. }
  146. user.RealName = RealName
  147. user.CompanyName = CompanyName
  148. activityInfo, err := models.GetAddActivityInfoByIdShow(uid, activityId)
  149. if err != nil && err.Error() != utils.ErrNoRow() {
  150. br.Msg = "获取信息失败"
  151. br.ErrMsg = "获取活动详情信息失败,Err:" + err.Error()
  152. return
  153. }
  154. if activityInfo == nil {
  155. br.Msg = "活动不存在"
  156. br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
  157. return
  158. }
  159. totalMySuccess, err := models.GetActivitySignupCount(uid, activityId)
  160. if err != nil {
  161. br.Msg = "获取失败"
  162. br.ErrMsg = "获取失败,Err:" + err.Error()
  163. return
  164. }
  165. item := new(models.CygxActivitySignin)
  166. var condition string
  167. var pars []interface{}
  168. condition = " AND user_id = ? AND activity_id = ? "
  169. pars = append(pars, uid, activityId)
  170. total, err := models.GetCygxActivitySigninCount(condition, pars)
  171. if err != nil {
  172. br.Msg = "获取失败"
  173. br.ErrMsg = "获取失败,Err:" + err.Error()
  174. return
  175. }
  176. if signinType == 1 {
  177. if req.Mobile == "" {
  178. br.Msg = "参数错误"
  179. br.ErrMsg = "参数错误,手机号为空 为空"
  180. return
  181. }
  182. itemMsgCode, err := models.GetMsgCode(req.Mobile, req.VCode)
  183. if err != nil {
  184. if err.Error() == utils.ErrNoRow() {
  185. br.Msg = "验证码错误,请重新输入"
  186. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  187. return
  188. } else {
  189. br.Msg = "验证码错误,请重新输入"
  190. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  191. return
  192. }
  193. }
  194. if itemMsgCode == nil {
  195. br.Msg = "验证码错误,请重新输入"
  196. return
  197. }
  198. userMobile, err := models.GetWxUserItemByMobile(Mobile)
  199. if err != nil {
  200. br.Msg = "签到失败"
  201. br.ErrMsg = "获取失败,Err:" + err.Error()
  202. return
  203. }
  204. if userMobile != nil {
  205. user = userMobile
  206. }
  207. } else {
  208. if BusinessCard == "" {
  209. br.Msg = "签到失败"
  210. br.ErrMsg = "签到失败名片地址为空,Err:"
  211. return
  212. }
  213. item.BusinessCard = BusinessCard
  214. }
  215. item.ActivityId = activityId
  216. item.UserId = user.UserId
  217. item.Mobile = Mobile
  218. item.CountryCode = CountryCode
  219. item.Email = user.Email
  220. item.CompanyId = user.CompanyId
  221. item.RealName = user.RealName
  222. item.CompanyName = user.CompanyName
  223. item.IsSignup = totalMySuccess
  224. item.BusinessCard = BusinessCard
  225. item.CreateTime = time.Now()
  226. if total == 0 {
  227. err = models.AddCygxActivitySignin(item)
  228. if err != nil {
  229. br.Msg = "签到失败"
  230. br.ErrMsg = "获取失败,Err:" + err.Error()
  231. return
  232. }
  233. }
  234. detail := new(models.CygxActivitySigninResp)
  235. if totalMySuccess > 0 {
  236. detail.IsSignup = true
  237. }
  238. item.RealName = RealName
  239. item.CompanyName = CompanyName
  240. //添加日志记录
  241. go services.AddCygxActivitySigninLog(item)
  242. if user.CompanyId == 1 {
  243. detail.IsNewUser = true
  244. }
  245. detail.ActivityId = activityId
  246. detail.ActivityName = activityInfo.ActivityName
  247. detail.Mobile = Mobile
  248. detail.RealName = user.RealName
  249. detail.CompanyName = user.CompanyName
  250. resp.Detail = detail
  251. br.Ret = 200
  252. br.Success = true
  253. br.Msg = "获取成功"
  254. br.Data = resp
  255. }