activity_sign.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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 open_id = ? AND activity_id = ? "
  63. pars = append(pars, user.OpenId, 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. //判断是否已经申请过
  71. applyCount, err := models.GetApplyRecordCount(uid)
  72. if err != nil && err.Error() != utils.ErrNoRow() {
  73. br.Msg = "获取信息失败"
  74. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  75. return
  76. }
  77. item := new(models.CygxActivitySignin)
  78. item.ActivityId = activityId
  79. item.UserId = user.UserId
  80. item.Mobile = user.Mobile
  81. item.Email = user.Email
  82. item.CompanyId = user.CompanyId
  83. item.RealName = user.RealName
  84. item.CompanyName = user.CompanyName
  85. item.IsSignup = totalMySuccess
  86. item.CountryCode = user.CountryCode
  87. item.OpenId = user.OpenId
  88. item.CreateTime = time.Now()
  89. if total == 0 && user.CompanyId > 1 || (user.Mobile != "" && applyCount > 0) {
  90. err = models.AddCygxActivitySignin(item)
  91. if err != nil {
  92. br.Msg = "签到失败"
  93. br.ErrMsg = "获取失败,Err:" + err.Error()
  94. return
  95. }
  96. }
  97. //记录签到信息到用户到会表
  98. if user.CompanyId > 1 {
  99. pars = make([]interface{}, 0)
  100. condition = " AND user_id = ? AND activity_id = ? "
  101. pars = append(pars, user.UserId, activityId)
  102. totalOfflineMeeting, err := models.GetCygxActivityOfflineMeetingDetailCount(condition, pars)
  103. if err != nil {
  104. br.Msg = "获取失败"
  105. br.ErrMsg = "获取失败,Err:" + err.Error()
  106. return
  107. }
  108. if totalOfflineMeeting == 0 {
  109. itemOfflineMeeting := new(models.CygxActivityOfflineMeetingDetail)
  110. itemOfflineMeeting.UserId = user.UserId
  111. itemOfflineMeeting.ActivityId = activityId
  112. itemOfflineMeeting.CreateTime = time.Now()
  113. itemOfflineMeeting.Mobile = user.Mobile
  114. itemOfflineMeeting.CompanyId = user.CompanyId
  115. itemOfflineMeeting.CompanyName = user.CompanyName
  116. itemOfflineMeeting.IsMeeting = 1
  117. err = models.AddCygxActivityOfflineMeetingDetail(itemOfflineMeeting)
  118. if err != nil {
  119. br.Msg = "签到失败"
  120. br.ErrMsg = "获取失败AddCygxActivityOfflineMeetingDetail,Err:" + err.Error()
  121. return
  122. }
  123. }
  124. //添加日志记录
  125. services.AddCygxActivitySigninLog(item)
  126. //把报名信息写入签到到会表
  127. services.AddCygxActivityOfflineMeetingDetail(activityId, user.UserId)
  128. //后期扫码签到,处理是否爽约限制
  129. services.CygxActivityRestrictSignupByuid(user.UserId, activityId)
  130. //线下调研活动扫码签到给对应销售发模班消息
  131. services.SendActivitieSignTemplateMsg(user, activityInfo)
  132. }
  133. if total == 0 && user.CompanyId > 1 || (user.Mobile != "" && applyCount > 0) {
  134. resp.IsBindingMobile = true
  135. }
  136. if user.CompanyId == 1 {
  137. detail.IsNewUser = true
  138. }
  139. detail.ActivityId = activityId
  140. detail.ActivityName = activityInfo.ActivityName
  141. detail.Mobile = user.Mobile
  142. detail.RealName = user.RealName
  143. detail.CompanyName = user.CompanyName
  144. //用于前端二次回显
  145. if user.Mobile == "" {
  146. pars = make([]interface{}, 0)
  147. condition = " AND open_id = ? AND activity_id = ? "
  148. pars = append(pars, user.OpenId, activityId)
  149. signinDetail, err := models.GetCygxActivitySigninDetail(condition, pars)
  150. if err != nil && err.Error() != utils.ErrNoRow() {
  151. br.Msg = "签到失败"
  152. br.ErrMsg = "获取失败GetCygxActivitySigninDetail,Err:" + err.Error()
  153. return
  154. }
  155. if signinDetail != nil {
  156. detail.BusinessCard = signinDetail.BusinessCard
  157. detail.Mobile = signinDetail.Mobile
  158. detail.RealName = signinDetail.RealName
  159. detail.CompanyName = signinDetail.CompanyName
  160. detail.IsNewUser = true
  161. }
  162. }
  163. resp.Detail = detail
  164. br.Ret = 200
  165. br.Success = true
  166. br.Msg = "获取成功"
  167. br.Data = resp
  168. }
  169. // @Title 活动扫码手动签到
  170. // @Description 活动扫码手动签到接口
  171. // @Param ActivityId query int true "活动ID"
  172. // @Success Ret=200 {object} models.CygxActivityResp
  173. // @router /byHand [post]
  174. func (this *ActivitySignCoAntroller) ByHand() {
  175. br := new(models.BaseResponse).Init()
  176. defer func() {
  177. this.Data["json"] = br
  178. this.ServeJSON()
  179. }()
  180. user := this.User
  181. if user == nil {
  182. br.Msg = "请登录"
  183. br.ErrMsg = "请登录,用户信息为空"
  184. br.Ret = 408
  185. return
  186. }
  187. uid := user.UserId
  188. resp := new(models.CygxActivitySigninDetailResp)
  189. var req models.CygxActivitySigninReq
  190. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  191. if err != nil {
  192. br.Msg = "参数解析异常!"
  193. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  194. return
  195. }
  196. signinType := req.SigninType
  197. activityId := req.ActivityId
  198. CountryCode := req.CountryCode
  199. Mobile := req.Mobile
  200. CompanyName := req.CompanyName
  201. BusinessCard := req.BusinessCard
  202. RealName := req.RealName
  203. if activityId < 1 {
  204. br.Msg = "请输入活动ID"
  205. return
  206. }
  207. user.RealName = RealName
  208. user.CompanyName = CompanyName
  209. activityInfo, err := models.GetAddActivityInfoByIdShow(uid, activityId)
  210. if err != nil && err.Error() != utils.ErrNoRow() {
  211. br.Msg = "获取信息失败"
  212. br.ErrMsg = "获取活动详情信息失败,Err:" + err.Error()
  213. return
  214. }
  215. if activityInfo == nil {
  216. br.Msg = "活动不存在"
  217. br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
  218. return
  219. }
  220. totalMySuccess, err := models.GetActivitySignupCount(uid, activityId)
  221. if err != nil {
  222. br.Msg = "获取失败"
  223. br.ErrMsg = "获取失败,Err:" + err.Error()
  224. return
  225. }
  226. item := new(models.CygxActivitySignin)
  227. var condition string
  228. var pars []interface{}
  229. condition = " AND open_id = ? AND activity_id = ? "
  230. pars = append(pars, user.OpenId, activityId)
  231. total, err := models.GetCygxActivitySigninCount(condition, pars)
  232. if err != nil {
  233. br.Msg = "获取失败"
  234. br.ErrMsg = "获取失败,Err:" + err.Error()
  235. return
  236. }
  237. if signinType == 1 {
  238. if req.Mobile == "" {
  239. br.Msg = "参数错误"
  240. br.ErrMsg = "参数错误,手机号为空 为空"
  241. return
  242. }
  243. itemMsgCode, err := models.GetMsgCode(req.Mobile, req.VCode)
  244. if err != nil {
  245. if err.Error() == utils.ErrNoRow() {
  246. br.Msg = "验证码错误,请重新输入"
  247. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  248. return
  249. } else {
  250. br.Msg = "验证码错误,请重新输入"
  251. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  252. return
  253. }
  254. }
  255. if itemMsgCode == nil {
  256. br.Msg = "验证码错误,请重新输入"
  257. return
  258. }
  259. userMobile, err := models.GetWxUserItemByMobile(Mobile)
  260. if err != nil && err.Error() != utils.ErrNoRow() {
  261. br.Msg = "签到失败"
  262. br.ErrMsg = "获取失败,Err:" + err.Error()
  263. return
  264. }
  265. if userMobile != nil {
  266. user = userMobile
  267. }
  268. } else {
  269. if BusinessCard == "" {
  270. br.Msg = "签到失败"
  271. br.ErrMsg = "签到失败名片地址为空,Err:"
  272. return
  273. }
  274. item.BusinessCard = BusinessCard
  275. }
  276. item.ActivityId = activityId
  277. item.UserId = user.UserId
  278. item.Mobile = Mobile
  279. item.CountryCode = CountryCode
  280. item.Email = user.Email
  281. item.CompanyId = user.CompanyId
  282. item.RealName = user.RealName
  283. item.CompanyName = user.CompanyName
  284. item.IsSignup = totalMySuccess
  285. item.BusinessCard = BusinessCard
  286. item.OpenId = user.OpenId
  287. item.CreateTime = time.Now()
  288. if total == 0 {
  289. err = models.AddCygxActivitySignin(item)
  290. if err != nil {
  291. br.Msg = "签到失败"
  292. br.ErrMsg = "获取失败,Err:" + err.Error()
  293. return
  294. }
  295. } else {
  296. pars = make([]interface{}, 0)
  297. condition = " AND open_id = ? AND activity_id = ? "
  298. pars = append(pars, user.OpenId, activityId)
  299. signinDetail, err := models.GetCygxActivitySigninDetail(condition, pars)
  300. if err != nil {
  301. br.Msg = "签到失败"
  302. br.ErrMsg = "获取失败GetCygxActivitySigninDetail,Err:" + err.Error()
  303. return
  304. }
  305. item.Id = signinDetail.Id
  306. err = models.UpdateCygxActivitySignin(item)
  307. if err != nil {
  308. br.Msg = "签到失败"
  309. br.ErrMsg = "获取失败,UpdateCygxActivitySignin,Err:" + err.Error()
  310. return
  311. }
  312. }
  313. detail := new(models.CygxActivitySigninResp)
  314. if totalMySuccess > 0 {
  315. detail.IsSignup = true
  316. }
  317. //添加日志记录
  318. go services.AddCygxActivitySigninLog(item)
  319. if user.CompanyId <= 1 {
  320. detail.IsNewUser = true
  321. }
  322. if user.UserId == 0 {
  323. detail.IsNewUser = true
  324. }
  325. detail.ActivityId = activityId
  326. detail.ActivityName = activityInfo.ActivityName
  327. detail.Mobile = Mobile
  328. detail.RealName = RealName
  329. detail.CompanyName = CompanyName
  330. resp.Detail = detail
  331. resp.IsBindingMobile = true
  332. br.Ret = 200
  333. br.Success = true
  334. br.Msg = "获取成功"
  335. br.Data = resp
  336. }
  337. // @Title 活动签到到会详情
  338. // @Description 活动签到到会详情接口
  339. // @Param ActivityId query int true "活动ID"
  340. // @Success Ret=200 {object} models.CygxActivityResp
  341. // @router /signup/detail [get]
  342. func (this *ActivitySignCoAntroller) SignupDetail() {
  343. br := new(models.BaseResponse).Init()
  344. defer func() {
  345. this.Data["json"] = br
  346. this.ServeJSON()
  347. }()
  348. user := this.User
  349. if user == nil {
  350. br.Msg = "请登录"
  351. br.ErrMsg = "请登录,用户信息为空"
  352. br.Ret = 408
  353. return
  354. }
  355. activityId, _ := this.GetInt("ActivityId")
  356. if activityId < 1 {
  357. br.Msg = "请输入活动ID"
  358. return
  359. }
  360. resp := new(models.CygxActivityOfflineMeetingDetailResp)
  361. activityInfo, err := models.GetAddActivityInfoById(activityId)
  362. if err != nil {
  363. br.Msg = "获取信息失败"
  364. br.ErrMsg = "获取活动详情信息失败,Err:" + err.Error()
  365. return
  366. }
  367. if !services.GetBelongingRai(user.Mobile) {
  368. br.Msg = "你暂无查看权限"
  369. br.ErrMsg = "你暂无查看权限,UserId:" + strconv.Itoa(user.UserId)
  370. return
  371. }
  372. var condition string
  373. var pars []interface{}
  374. condition = ` AND activity_id = ? `
  375. pars = append(pars, activityId)
  376. listOfflineMeeting, err := models.GetOfflineMeetingListWithUser(condition, pars)
  377. UserMobileMap, err := services.GetAdminCheckUserMobileMap(user)
  378. if err != nil {
  379. br.Msg = "你暂无查看权限"
  380. br.ErrMsg = "你暂无查看权限,UserId:" + strconv.Itoa(user.UserId)
  381. return
  382. }
  383. for _, v := range listOfflineMeeting {
  384. if _, ok := UserMobileMap[v.Mobile]; !ok {
  385. item := new(models.CygxActivitySignupResp)
  386. item.RealName = v.RealName
  387. item.CompanyName = v.CompanyName
  388. item.IsMeeting = v.IsMeeting
  389. if v.IsMeeting == 1 {
  390. item.SigninTime = v.SigninTime
  391. }
  392. resp.List = append(resp.List, item)
  393. }
  394. }
  395. if len(resp.List) == 0 {
  396. resp.List = make([]*models.CygxActivitySignupResp, 0)
  397. }
  398. resp.ActivityId = activityId
  399. resp.ActivityName = activityInfo.ActivityName
  400. br.Ret = 200
  401. br.Success = true
  402. br.Msg = "获取成功"
  403. br.Data = resp
  404. }