activity_sign.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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 user.Mobile == "" {
  238. if signinType == 1 {
  239. if req.Mobile == "" {
  240. br.Msg = "参数错误"
  241. br.ErrMsg = "参数错误,手机号为空 为空"
  242. return
  243. }
  244. itemMsgCode, err := models.GetMsgCode(req.Mobile, req.VCode)
  245. if err != nil {
  246. if err.Error() == utils.ErrNoRow() {
  247. br.Msg = "验证码错误,请重新输入"
  248. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  249. return
  250. } else {
  251. br.Msg = "验证码错误,请重新输入"
  252. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  253. return
  254. }
  255. }
  256. if itemMsgCode == nil {
  257. br.Msg = "验证码错误,请重新输入"
  258. return
  259. }
  260. userMobile, err := models.GetWxUserItemByMobile(Mobile)
  261. if err != nil && err.Error() != utils.ErrNoRow() {
  262. br.Msg = "签到失败"
  263. br.ErrMsg = "获取失败,Err:" + err.Error()
  264. return
  265. }
  266. if userMobile != nil {
  267. user = userMobile
  268. }
  269. } else {
  270. if BusinessCard == "" {
  271. br.Msg = "签到失败"
  272. br.ErrMsg = "签到失败名片地址为空,Err:"
  273. return
  274. }
  275. item.BusinessCard = BusinessCard
  276. }
  277. } else {
  278. if CompanyName == "" {
  279. br.Msg = "请输入公司名称"
  280. return
  281. }
  282. if RealName == "" {
  283. br.Msg = "请输入姓名"
  284. return
  285. }
  286. }
  287. item.ActivityId = activityId
  288. item.UserId = user.UserId
  289. item.Mobile = Mobile
  290. item.CountryCode = CountryCode
  291. item.Email = user.Email
  292. item.CompanyId = user.CompanyId
  293. item.RealName = user.RealName
  294. item.CompanyName = user.CompanyName
  295. item.IsSignup = totalMySuccess
  296. item.BusinessCard = BusinessCard
  297. item.OpenId = user.OpenId
  298. item.CreateTime = time.Now()
  299. if total == 0 {
  300. err = models.AddCygxActivitySignin(item)
  301. if err != nil {
  302. br.Msg = "签到失败"
  303. br.ErrMsg = "获取失败,Err:" + err.Error()
  304. return
  305. }
  306. } else {
  307. pars = make([]interface{}, 0)
  308. condition = " AND open_id = ? AND activity_id = ? "
  309. pars = append(pars, user.OpenId, activityId)
  310. signinDetail, err := models.GetCygxActivitySigninDetail(condition, pars)
  311. if err != nil {
  312. br.Msg = "签到失败"
  313. br.ErrMsg = "获取失败GetCygxActivitySigninDetail,Err:" + err.Error()
  314. return
  315. }
  316. item.Id = signinDetail.Id
  317. err = models.UpdateCygxActivitySignin(item)
  318. if err != nil {
  319. br.Msg = "签到失败"
  320. br.ErrMsg = "获取失败,UpdateCygxActivitySignin,Err:" + err.Error()
  321. return
  322. }
  323. }
  324. detail := new(models.CygxActivitySigninResp)
  325. if totalMySuccess > 0 {
  326. detail.IsSignup = true
  327. }
  328. //添加日志记录
  329. go services.AddCygxActivitySigninLog(item)
  330. if user.CompanyId <= 1 {
  331. detail.IsNewUser = true
  332. }
  333. if user.UserId == 0 {
  334. detail.IsNewUser = true
  335. }
  336. detail.ActivityId = activityId
  337. detail.ActivityName = activityInfo.ActivityName
  338. detail.Mobile = Mobile
  339. detail.RealName = RealName
  340. detail.CompanyName = CompanyName
  341. resp.Detail = detail
  342. resp.IsBindingMobile = true
  343. br.Ret = 200
  344. br.Success = true
  345. br.Msg = "获取成功"
  346. br.Data = resp
  347. }
  348. // @Title 活动签到到会详情
  349. // @Description 活动签到到会详情接口
  350. // @Param ActivityId query int true "活动ID"
  351. // @Success Ret=200 {object} models.CygxActivityResp
  352. // @router /signup/detail [get]
  353. func (this *ActivitySignCoAntroller) SignupDetail() {
  354. br := new(models.BaseResponse).Init()
  355. defer func() {
  356. this.Data["json"] = br
  357. this.ServeJSON()
  358. }()
  359. user := this.User
  360. if user == nil {
  361. br.Msg = "请登录"
  362. br.ErrMsg = "请登录,用户信息为空"
  363. br.Ret = 408
  364. return
  365. }
  366. activityId, _ := this.GetInt("ActivityId")
  367. if activityId < 1 {
  368. br.Msg = "请输入活动ID"
  369. return
  370. }
  371. resp := new(models.CygxActivityOfflineMeetingDetailResp)
  372. activityInfo, err := models.GetAddActivityInfoById(activityId)
  373. if err != nil {
  374. br.Msg = "获取信息失败"
  375. br.ErrMsg = "获取活动详情信息失败,Err:" + err.Error()
  376. return
  377. }
  378. if !services.GetBelongingRai(user.Mobile) {
  379. br.Msg = "你暂无查看权限"
  380. br.ErrMsg = "你暂无查看权限,UserId:" + strconv.Itoa(user.UserId)
  381. return
  382. }
  383. var condition string
  384. var pars []interface{}
  385. condition = ` AND activity_id = ? `
  386. pars = append(pars, activityId)
  387. listOfflineMeeting, err := models.GetOfflineMeetingListWithUser(condition, pars)
  388. UserMobileMap, err := services.GetAdminCheckUserMobileMap(user)
  389. if err != nil {
  390. br.Msg = "你暂无查看权限"
  391. br.ErrMsg = "你暂无查看权限,UserId:" + strconv.Itoa(user.UserId)
  392. return
  393. }
  394. for _, v := range listOfflineMeeting {
  395. if _, ok := UserMobileMap[v.Mobile]; !ok {
  396. item := new(models.CygxActivitySignupResp)
  397. item.RealName = v.RealName
  398. item.CompanyName = v.CompanyName
  399. item.IsMeeting = v.IsMeeting
  400. if v.IsMeeting == 1 {
  401. item.SigninTime = v.SigninTime
  402. }
  403. resp.List = append(resp.List, item)
  404. }
  405. }
  406. if len(resp.List) == 0 {
  407. resp.List = make([]*models.CygxActivitySignupResp, 0)
  408. }
  409. resp.ActivityId = activityId
  410. resp.ActivityName = activityInfo.ActivityName
  411. br.Ret = 200
  412. br.Success = true
  413. br.Msg = "获取成功"
  414. br.Data = resp
  415. }