activity_sign.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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.Mobile != "" && (applyCount > 0 || user.CompanyId > 1) {
  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. //1,没有签到记录不为潜在客户
  134. //2,没有签到记录,手机号不为空,没有申请记录
  135. //3,已经有签到记录的
  136. if total == 0 && user.CompanyId > 1 || (user.Mobile != "" && applyCount > 0) || total > 0 {
  137. resp.IsBindingMobile = true
  138. }
  139. if user.CompanyId == 1 {
  140. detail.IsNewUser = true
  141. }
  142. //潜在客户提交过申请的显示提交时候的公司
  143. if applyCount > 0 && user.Mobile != "" && user.CompanyId == 1 {
  144. detail, err := models.GetCygxApplyRecordByMobile(user.Mobile)
  145. if err != nil {
  146. br.Msg = "签到失败"
  147. br.ErrMsg = "GetCygxApplyRecordByMobile,Err:" + err.Error()
  148. return
  149. }
  150. user.CompanyName = detail.CompanyName
  151. }
  152. detail.ActivityId = activityId
  153. detail.ActivityName = activityInfo.ActivityName
  154. detail.Mobile = user.Mobile
  155. detail.RealName = user.RealName
  156. detail.CompanyName = user.CompanyName
  157. //用于前端二次回显
  158. if user.Mobile == "" {
  159. pars = make([]interface{}, 0)
  160. condition = " AND open_id = ? AND activity_id = ? "
  161. pars = append(pars, user.OpenId, activityId)
  162. signinDetail, err := models.GetCygxActivitySigninDetail(condition, pars)
  163. if err != nil && err.Error() != utils.ErrNoRow() {
  164. br.Msg = "签到失败"
  165. br.ErrMsg = "获取失败GetCygxActivitySigninDetail,Err:" + err.Error()
  166. return
  167. }
  168. if signinDetail != nil {
  169. detail.BusinessCard = signinDetail.BusinessCard
  170. detail.Mobile = signinDetail.Mobile
  171. detail.RealName = signinDetail.RealName
  172. detail.CompanyName = signinDetail.CompanyName
  173. detail.IsNewUser = true
  174. }
  175. }
  176. resp.Detail = detail
  177. br.Ret = 200
  178. br.Success = true
  179. br.Msg = "获取成功"
  180. br.Data = resp
  181. }
  182. // @Title 活动扫码手动签到
  183. // @Description 活动扫码手动签到接口
  184. // @Param ActivityId query int true "活动ID"
  185. // @Success Ret=200 {object} models.CygxActivityResp
  186. // @router /byHand [post]
  187. func (this *ActivitySignCoAntroller) ByHand() {
  188. br := new(models.BaseResponse).Init()
  189. defer func() {
  190. this.Data["json"] = br
  191. this.ServeJSON()
  192. }()
  193. user := this.User
  194. if user == nil {
  195. br.Msg = "请登录"
  196. br.ErrMsg = "请登录,用户信息为空"
  197. br.Ret = 408
  198. return
  199. }
  200. uid := user.UserId
  201. resp := new(models.CygxActivitySigninDetailResp)
  202. var req models.CygxActivitySigninReq
  203. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  204. if err != nil {
  205. br.Msg = "参数解析异常!"
  206. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  207. return
  208. }
  209. signinType := req.SigninType
  210. activityId := req.ActivityId
  211. CountryCode := req.CountryCode
  212. Mobile := req.Mobile
  213. CompanyName := req.CompanyName
  214. BusinessCard := req.BusinessCard
  215. RealName := req.RealName
  216. if activityId < 1 {
  217. br.Msg = "请输入活动ID"
  218. return
  219. }
  220. user.RealName = RealName
  221. user.CompanyName = CompanyName
  222. activityInfo, err := models.GetAddActivityInfoByIdShow(uid, activityId)
  223. if err != nil && err.Error() != utils.ErrNoRow() {
  224. br.Msg = "获取信息失败"
  225. br.ErrMsg = "获取活动详情信息失败,Err:" + err.Error()
  226. return
  227. }
  228. if activityInfo == nil {
  229. br.Msg = "活动不存在"
  230. br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
  231. return
  232. }
  233. totalMySuccess, err := models.GetActivitySignupCount(uid, activityId)
  234. if err != nil {
  235. br.Msg = "获取失败"
  236. br.ErrMsg = "获取失败,Err:" + err.Error()
  237. return
  238. }
  239. item := new(models.CygxActivitySignin)
  240. var condition string
  241. var pars []interface{}
  242. condition = " AND open_id = ? AND activity_id = ? "
  243. pars = append(pars, user.OpenId, activityId)
  244. total, err := models.GetCygxActivitySigninCount(condition, pars)
  245. if err != nil {
  246. br.Msg = "获取失败"
  247. br.ErrMsg = "获取失败,Err:" + err.Error()
  248. return
  249. }
  250. if user.Mobile == "" {
  251. if signinType == 1 {
  252. if req.Mobile == "" {
  253. br.Msg = "参数错误"
  254. br.ErrMsg = "参数错误,手机号为空 为空"
  255. return
  256. }
  257. itemMsgCode, err := models.GetMsgCode(req.Mobile, req.VCode)
  258. if err != nil {
  259. if err.Error() == utils.ErrNoRow() {
  260. br.Msg = "验证码错误,请重新输入"
  261. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  262. return
  263. } else {
  264. br.Msg = "验证码错误,请重新输入"
  265. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  266. return
  267. }
  268. }
  269. if itemMsgCode == nil {
  270. br.Msg = "验证码错误,请重新输入"
  271. return
  272. }
  273. userMobile, err := models.GetWxUserItemByMobile(Mobile)
  274. if err != nil && err.Error() != utils.ErrNoRow() {
  275. br.Msg = "签到失败"
  276. br.ErrMsg = "获取失败,Err:" + err.Error()
  277. return
  278. }
  279. if userMobile != nil {
  280. user = userMobile
  281. }
  282. } else {
  283. if BusinessCard == "" {
  284. br.Msg = "签到失败"
  285. br.ErrMsg = "签到失败名片地址为空,Err:"
  286. return
  287. }
  288. item.BusinessCard = BusinessCard
  289. }
  290. } else {
  291. if signinType == 1 {
  292. if CompanyName == "" {
  293. br.Msg = "请输入公司名称"
  294. return
  295. }
  296. if RealName == "" {
  297. br.Msg = "请输入姓名"
  298. return
  299. }
  300. }
  301. }
  302. item.ActivityId = activityId
  303. item.UserId = user.UserId
  304. item.Mobile = Mobile
  305. item.CountryCode = CountryCode
  306. item.Email = user.Email
  307. item.CompanyId = user.CompanyId
  308. item.RealName = user.RealName
  309. item.CompanyName = user.CompanyName
  310. item.IsSignup = totalMySuccess
  311. item.BusinessCard = BusinessCard
  312. item.OpenId = user.OpenId
  313. item.CreateTime = time.Now()
  314. if total == 0 {
  315. err = models.AddCygxActivitySignin(item)
  316. if err != nil {
  317. br.Msg = "签到失败"
  318. br.ErrMsg = "获取失败,Err:" + err.Error()
  319. return
  320. }
  321. } else {
  322. pars = make([]interface{}, 0)
  323. condition = " AND open_id = ? AND activity_id = ? "
  324. pars = append(pars, user.OpenId, activityId)
  325. signinDetail, err := models.GetCygxActivitySigninDetail(condition, pars)
  326. if err != nil {
  327. br.Msg = "签到失败"
  328. br.ErrMsg = "获取失败GetCygxActivitySigninDetail,Err:" + err.Error()
  329. return
  330. }
  331. item.Id = signinDetail.Id
  332. err = models.UpdateCygxActivitySignin(item)
  333. if err != nil {
  334. br.Msg = "签到失败"
  335. br.ErrMsg = "获取失败,UpdateCygxActivitySignin,Err:" + err.Error()
  336. return
  337. }
  338. }
  339. detail := new(models.CygxActivitySigninResp)
  340. if totalMySuccess > 0 {
  341. detail.IsSignup = true
  342. }
  343. //添加日志记录
  344. go services.AddCygxActivitySigninLog(item)
  345. if user.CompanyId <= 1 {
  346. detail.IsNewUser = true
  347. }
  348. if user.UserId == 0 {
  349. detail.IsNewUser = true
  350. }
  351. detail.ActivityId = activityId
  352. detail.ActivityName = activityInfo.ActivityName
  353. detail.Mobile = Mobile
  354. detail.RealName = RealName
  355. detail.CompanyName = CompanyName
  356. resp.Detail = detail
  357. resp.IsBindingMobile = true
  358. br.Ret = 200
  359. br.Success = true
  360. br.Msg = "获取成功"
  361. br.Data = resp
  362. }
  363. // @Title 活动签到到会详情
  364. // @Description 活动签到到会详情接口
  365. // @Param ActivityId query int true "活动ID"
  366. // @Success Ret=200 {object} models.CygxActivityResp
  367. // @router /signup/detail [get]
  368. func (this *ActivitySignCoAntroller) SignupDetail() {
  369. br := new(models.BaseResponse).Init()
  370. defer func() {
  371. this.Data["json"] = br
  372. this.ServeJSON()
  373. }()
  374. user := this.User
  375. if user == nil {
  376. br.Msg = "请登录"
  377. br.ErrMsg = "请登录,用户信息为空"
  378. br.Ret = 408
  379. return
  380. }
  381. activityId, _ := this.GetInt("ActivityId")
  382. if activityId < 1 {
  383. br.Msg = "请输入活动ID"
  384. return
  385. }
  386. resp := new(models.CygxActivityOfflineMeetingDetailResp)
  387. activityInfo, err := models.GetAddActivityInfoById(activityId)
  388. if err != nil {
  389. br.Msg = "获取信息失败"
  390. br.ErrMsg = "获取活动详情信息失败,Err:" + err.Error()
  391. return
  392. }
  393. if !services.GetBelongingRai(user.Mobile) {
  394. br.Msg = "你暂无查看权限"
  395. br.ErrMsg = "你暂无查看权限,UserId:" + strconv.Itoa(user.UserId)
  396. return
  397. }
  398. var condition string
  399. var pars []interface{}
  400. condition = ` AND do_fail_type = 0 AND activity_id = ?`
  401. pars = append(pars, activityId)
  402. listSignup, err := models.GetActivitySignupList(condition, pars)
  403. if err != nil && err.Error() != utils.ErrNoRow() {
  404. br.Msg = "获取信息失败"
  405. br.ErrMsg = "GetOfflineMeetingListWithUser,UserId:" + strconv.Itoa(user.UserId)
  406. return
  407. }
  408. //获取对应销售所能查看的用户手机号
  409. UserMobileMap, err := services.GetAdminCheckUserMobileMap(user)
  410. if err != nil {
  411. br.Msg = "获取信息失败"
  412. br.ErrMsg = "GetAdminCheckUserMobileMap,UserId:" + strconv.Itoa(user.UserId)
  413. return
  414. }
  415. //获取用户的签到时间
  416. SigninTimeMap, err := services.GetUserActivitySigninTimeMap(activityId)
  417. if err != nil {
  418. br.Msg = "获取信息失败"
  419. br.ErrMsg = "GetUserActivitySigninTimeMap,activityId:" + strconv.Itoa(activityId)
  420. return
  421. }
  422. for _, v := range listSignup {
  423. if _, ok := UserMobileMap[v.Mobile]; ok {
  424. item := new(models.CygxActivitySignupResp)
  425. item.RealName = v.RealName
  426. item.CompanyName = v.CompanyName
  427. if _, ok := SigninTimeMap[v.UserId]; ok {
  428. item.IsMeeting = 1
  429. item.SigninTime = SigninTimeMap[v.UserId]
  430. }
  431. resp.List = append(resp.List, item)
  432. }
  433. }
  434. if len(resp.List) == 0 {
  435. resp.List = make([]*models.CygxActivitySignupResp, 0)
  436. }
  437. resp.ActivityId = activityId
  438. resp.ActivityName = activityInfo.ActivityName
  439. br.Ret = 200
  440. br.Success = true
  441. br.Msg = "获取成功"
  442. br.Data = resp
  443. }