activity_sign.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_mfyx/models"
  5. "hongze/hongze_mfyx/services"
  6. "hongze/hongze_mfyx/utils"
  7. "strconv"
  8. "strings"
  9. "time"
  10. )
  11. // 活动
  12. type ActivitySignCoAntroller struct {
  13. BaseAuthController
  14. }
  15. // @Title 活动扫码自动签到
  16. // @Description 活动扫码签到接口
  17. // @Param ActivityId query int true "活动ID"
  18. // @Success Ret=200 {object} models.CygxActivityResp
  19. // @router /detail [get]
  20. func (this *ActivitySignCoAntroller) Detail() {
  21. br := new(models.BaseResponse).Init()
  22. defer func() {
  23. this.Data["json"] = br
  24. this.ServeJSON()
  25. }()
  26. user := this.User
  27. if user == nil {
  28. br.Msg = "请登录"
  29. br.ErrMsg = "请登录,用户信息为空"
  30. br.Ret = 408
  31. return
  32. }
  33. uid := user.UserId
  34. activityId, _ := this.GetInt("ActivityId")
  35. if activityId < 1 {
  36. br.Msg = "请输入活动ID"
  37. return
  38. }
  39. resp := new(models.CygxActivitySigninDetailResp)
  40. activityInfo, err := models.GetAddActivityInfoByIdShow(uid, activityId)
  41. if err != nil && err.Error() != utils.ErrNoRow() {
  42. br.Msg = "获取信息失败"
  43. br.ErrMsg = "获取活动详情信息失败,Err:" + err.Error()
  44. return
  45. }
  46. if activityInfo == nil {
  47. br.Msg = "活动不存在"
  48. br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
  49. return
  50. }
  51. totalMySuccess, err := models.GetActivitySignupCount(uid, activityId)
  52. if err != nil {
  53. br.Msg = "获取失败"
  54. br.ErrMsg = "获取失败,Err:" + err.Error()
  55. return
  56. }
  57. detail := new(models.CygxActivitySigninResp)
  58. if totalMySuccess > 0 {
  59. detail.IsSignup = true
  60. }
  61. var condition string
  62. var pars []interface{}
  63. condition = " AND open_id = ? AND activity_id = ? "
  64. pars = append(pars, user.OpenId, activityId)
  65. total, err := models.GetCygxActivitySigninCount(condition, pars)
  66. if err != nil {
  67. br.Msg = "获取失败"
  68. br.ErrMsg = "获取失败,Err:" + err.Error()
  69. return
  70. }
  71. //判断是否已经申请过
  72. applyCount, err := models.GetApplyRecordCount(uid)
  73. if err != nil && err.Error() != utils.ErrNoRow() {
  74. br.Msg = "获取信息失败"
  75. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  76. return
  77. }
  78. item := new(models.CygxActivitySignin)
  79. item.ActivityId = activityId
  80. item.UserId = user.UserId
  81. item.Mobile = user.Mobile
  82. item.Email = user.Email
  83. item.CompanyId = user.CompanyId
  84. item.RealName = user.RealName
  85. item.CompanyName = user.CompanyName
  86. item.IsSignup = totalMySuccess
  87. item.CountryCode = user.CountryCode
  88. item.OpenId = user.OpenId
  89. item.CreateTime = time.Now()
  90. if total == 0 && (user.Mobile != "" || user.Email != "") && (applyCount > 0 || user.CompanyId > 1) {
  91. err = models.AddCygxActivitySignin(item)
  92. if err != nil {
  93. br.Msg = "签到失败"
  94. br.ErrMsg = "获取失败,Err:" + err.Error()
  95. return
  96. }
  97. }
  98. //记录签到信息到用户到会表
  99. if user.CompanyId > 1 {
  100. pars = make([]interface{}, 0)
  101. condition = " AND user_id = ? AND activity_id = ? "
  102. pars = append(pars, user.UserId, activityId)
  103. totalOfflineMeeting, err := models.GetCygxActivityOfflineMeetingDetailCount(condition, pars)
  104. if err != nil {
  105. br.Msg = "获取失败"
  106. br.ErrMsg = "获取失败,Err:" + err.Error()
  107. return
  108. }
  109. if totalOfflineMeeting == 0 {
  110. itemOfflineMeeting := new(models.CygxActivityOfflineMeetingDetail)
  111. itemOfflineMeeting.UserId = user.UserId
  112. itemOfflineMeeting.ActivityId = activityId
  113. itemOfflineMeeting.CreateTime = time.Now()
  114. itemOfflineMeeting.Mobile = user.Mobile
  115. itemOfflineMeeting.CompanyId = user.CompanyId
  116. itemOfflineMeeting.CompanyName = user.CompanyName
  117. itemOfflineMeeting.IsMeeting = 1
  118. err = models.AddCygxActivityOfflineMeetingDetail(itemOfflineMeeting)
  119. if err != nil {
  120. br.Msg = "签到失败"
  121. br.ErrMsg = "获取失败AddCygxActivityOfflineMeetingDetail,Err:" + err.Error()
  122. return
  123. }
  124. }
  125. //添加日志记录
  126. services.AddCygxActivitySigninLog(item)
  127. //把报名信息写入签到到会表
  128. services.AddCygxActivityOfflineMeetingDetail(activityId, user.UserId)
  129. //后期扫码签到,处理是否爽约限制
  130. services.CygxActivityRestrictSignupByuid(user.UserId, activityId)
  131. //线下调研活动扫码签到给对应销售发模版消息
  132. services.SendActivitieSignTemplateMsg(user, activityInfo)
  133. services.SendActivitieSignCategoryTemplateMsg(user, activityInfo)
  134. //处理用户标签
  135. services.ActivityUserLabelLogAdd(activityId, []string{user.Mobile})
  136. {
  137. //用做后台联系人列表查询
  138. itemD := new(models.CygxActivityAttendanceDetail)
  139. itemD.ActivityId = activityId
  140. itemD.RealName = user.RealName
  141. itemD.Mobile = user.Mobile
  142. itemD.CompanyName = user.CompanyName
  143. itemD.IsMeetingStr = 1
  144. itemD.CreateTime = time.Now()
  145. var itemDs []*models.CygxActivityAttendanceDetail
  146. itemDs = append(itemDs, itemD)
  147. services.AddctivitySignupDetailByJmcjNew(itemDs, []int{activityId})
  148. }
  149. }
  150. //1,没有签到记录不为潜在客户
  151. //2,没有签到记录,手机号不为空,没有申请记录
  152. //3,已经有签到记录的
  153. if total == 0 && user.CompanyId > 1 || ((user.Mobile != "" || user.Email != "") && applyCount > 0) || total > 0 {
  154. resp.IsBindingMobile = true
  155. }
  156. if user.CompanyId == 1 {
  157. detail.IsNewUser = true
  158. }
  159. //潜在客户提交过申请的显示提交时候的公司
  160. if applyCount > 0 && (user.Mobile != "" || user.Email != "") && user.CompanyId == 1 {
  161. detail, err := models.GetCygxApplyRecordByMobile(user.Mobile)
  162. if err != nil {
  163. br.Msg = "签到失败"
  164. br.ErrMsg = "GetCygxApplyRecordByMobile,Err:" + err.Error()
  165. return
  166. }
  167. user.CompanyName = detail.CompanyName
  168. }
  169. detail.ActivityId = activityId
  170. detail.ActivityName = activityInfo.ActivityName
  171. detail.Mobile = user.Mobile
  172. if user.Mobile == "" {
  173. detail.Mobile = user.Email
  174. }
  175. detail.RealName = user.RealName
  176. detail.CompanyName = user.CompanyName
  177. //用于前端二次回显
  178. if user.Mobile == "" {
  179. pars = make([]interface{}, 0)
  180. condition = " AND open_id = ? AND activity_id = ? "
  181. pars = append(pars, user.OpenId, activityId)
  182. signinDetail, err := models.GetCygxActivitySigninDetail(condition, pars)
  183. if err != nil && err.Error() != utils.ErrNoRow() {
  184. br.Msg = "签到失败"
  185. br.ErrMsg = "获取失败GetCygxActivitySigninDetail,Err:" + err.Error()
  186. return
  187. }
  188. if signinDetail != nil {
  189. detail.BusinessCard = signinDetail.BusinessCard
  190. detail.Mobile = signinDetail.Mobile
  191. if signinDetail.Mobile == "" {
  192. detail.Mobile = signinDetail.Email
  193. }
  194. detail.RealName = signinDetail.RealName
  195. detail.CompanyName = signinDetail.CompanyName
  196. detail.IsNewUser = true
  197. }
  198. }
  199. resp.Detail = detail
  200. br.Ret = 200
  201. br.Success = true
  202. br.Msg = "获取成功"
  203. br.Data = resp
  204. }
  205. // @Title 活动扫码手动签到
  206. // @Description 活动扫码手动签到接口
  207. // @Param ActivityId query int true "活动ID"
  208. // @Success Ret=200 {object} models.CygxActivityResp
  209. // @router /byHand [post]
  210. func (this *ActivitySignCoAntroller) ByHand() {
  211. br := new(models.BaseResponse).Init()
  212. defer func() {
  213. this.Data["json"] = br
  214. this.ServeJSON()
  215. }()
  216. user := this.User
  217. if user == nil {
  218. br.Msg = "请登录"
  219. br.ErrMsg = "请登录,用户信息为空"
  220. br.Ret = 408
  221. return
  222. }
  223. uid := user.UserId
  224. resp := new(models.CygxActivitySigninDetailResp)
  225. var req models.CygxActivitySigninReq
  226. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  227. if err != nil {
  228. br.Msg = "参数解析异常!"
  229. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  230. return
  231. }
  232. signinType := req.SigninType
  233. activityId := req.ActivityId
  234. CountryCode := req.CountryCode
  235. Mobile := req.Mobile
  236. CompanyName := req.CompanyName
  237. BusinessCard := req.BusinessCard
  238. RealName := req.RealName
  239. if activityId < 1 {
  240. br.Msg = "请输入活动ID"
  241. return
  242. }
  243. user.RealName = RealName
  244. user.CompanyName = CompanyName
  245. activityInfo, err := models.GetAddActivityInfoByIdShow(uid, activityId)
  246. if err != nil && err.Error() != utils.ErrNoRow() {
  247. br.Msg = "获取信息失败"
  248. br.ErrMsg = "获取活动详情信息失败,Err:" + err.Error()
  249. return
  250. }
  251. if activityInfo == nil {
  252. br.Msg = "活动不存在"
  253. br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
  254. return
  255. }
  256. totalMySuccess, err := models.GetActivitySignupCount(uid, activityId)
  257. if err != nil {
  258. br.Msg = "获取失败"
  259. br.ErrMsg = "获取失败,Err:" + err.Error()
  260. return
  261. }
  262. item := new(models.CygxActivitySignin)
  263. var condition string
  264. var pars []interface{}
  265. condition = " AND open_id = ? AND activity_id = ? "
  266. pars = append(pars, user.OpenId, activityId)
  267. total, err := models.GetCygxActivitySigninCount(condition, pars)
  268. if err != nil {
  269. br.Msg = "获取失败"
  270. br.ErrMsg = "获取失败,Err:" + err.Error()
  271. return
  272. }
  273. if user.Mobile == "" && user.Email == "" {
  274. if signinType == 1 {
  275. if req.Mobile == "" {
  276. br.Msg = "参数错误"
  277. br.ErrMsg = "参数错误,手机号为空 为空"
  278. return
  279. }
  280. itemMsgCode, err := models.GetMsgCode(req.Mobile, req.VCode)
  281. if err != nil {
  282. if err.Error() == utils.ErrNoRow() {
  283. br.Msg = "验证码错误,请重新输入"
  284. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  285. return
  286. } else {
  287. br.Msg = "验证码错误,请重新输入"
  288. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  289. return
  290. }
  291. }
  292. if itemMsgCode == nil {
  293. br.Msg = "验证码错误,请重新输入"
  294. return
  295. }
  296. userMobile, err := models.GetWxUserItemByMobile(Mobile)
  297. if err != nil && err.Error() != utils.ErrNoRow() {
  298. br.Msg = "签到失败"
  299. br.ErrMsg = "获取失败,Err:" + err.Error()
  300. return
  301. }
  302. if userMobile != nil {
  303. user = userMobile
  304. }
  305. } else {
  306. if BusinessCard == "" {
  307. br.Msg = "签到失败"
  308. br.ErrMsg = "签到失败名片地址为空,Err:"
  309. return
  310. }
  311. item.BusinessCard = BusinessCard
  312. }
  313. } else {
  314. if signinType == 1 {
  315. if CompanyName == "" {
  316. br.Msg = "请输入公司名称"
  317. return
  318. }
  319. if RealName == "" {
  320. br.Msg = "请输入姓名"
  321. return
  322. }
  323. }
  324. }
  325. //如果是用邮箱登录的,就把手机号置空
  326. if strings.Contains(Mobile, "@") {
  327. Mobile = ""
  328. }
  329. item.ActivityId = activityId
  330. item.UserId = user.UserId
  331. item.Mobile = Mobile
  332. item.CountryCode = CountryCode
  333. item.Email = user.Email
  334. item.CompanyId = user.CompanyId
  335. item.RealName = user.RealName
  336. item.CompanyName = user.CompanyName
  337. item.IsSignup = totalMySuccess
  338. item.BusinessCard = BusinessCard
  339. item.OpenId = user.OpenId
  340. item.CreateTime = time.Now()
  341. if total == 0 {
  342. err = models.AddCygxActivitySignin(item)
  343. if err != nil {
  344. br.Msg = "签到失败"
  345. br.ErrMsg = "获取失败,Err:" + err.Error()
  346. return
  347. }
  348. } else {
  349. pars = make([]interface{}, 0)
  350. condition = " AND open_id = ? AND activity_id = ? "
  351. pars = append(pars, user.OpenId, activityId)
  352. signinDetail, err := models.GetCygxActivitySigninDetail(condition, pars)
  353. if err != nil {
  354. br.Msg = "签到失败"
  355. br.ErrMsg = "获取失败GetCygxActivitySigninDetail,Err:" + err.Error()
  356. return
  357. }
  358. item.Id = signinDetail.Id
  359. err = models.UpdateCygxActivitySignin(item)
  360. if err != nil {
  361. br.Msg = "签到失败"
  362. br.ErrMsg = "获取失败,UpdateCygxActivitySignin,Err:" + err.Error()
  363. return
  364. }
  365. }
  366. detail := new(models.CygxActivitySigninResp)
  367. if totalMySuccess > 0 {
  368. detail.IsSignup = true
  369. }
  370. //添加日志记录
  371. go services.AddCygxActivitySigninLog(item)
  372. if user.CompanyId <= 1 {
  373. detail.IsNewUser = true
  374. }
  375. if user.UserId == 0 {
  376. detail.IsNewUser = true
  377. }
  378. detail.ActivityId = activityId
  379. detail.ActivityName = activityInfo.ActivityName
  380. detail.Mobile = Mobile
  381. detail.RealName = RealName
  382. detail.CompanyName = CompanyName
  383. resp.Detail = detail
  384. resp.IsBindingMobile = true
  385. br.Ret = 200
  386. br.Success = true
  387. br.Msg = "获取成功"
  388. br.Data = resp
  389. }
  390. // @Title 活动签到到会详情
  391. // @Description 活动签到到会详情接口
  392. // @Param ActivityId query int true "活动ID"
  393. // @Success Ret=200 {object} models.CygxActivityResp
  394. // @router /signup/detail [get]
  395. func (this *ActivitySignCoAntroller) SignupDetail() {
  396. br := new(models.BaseResponse).Init()
  397. defer func() {
  398. this.Data["json"] = br
  399. this.ServeJSON()
  400. }()
  401. user := this.User
  402. if user == nil {
  403. br.Msg = "请登录"
  404. br.ErrMsg = "请登录,用户信息为空"
  405. br.Ret = 408
  406. return
  407. }
  408. activityId, _ := this.GetInt("ActivityId")
  409. if activityId < 1 {
  410. br.Msg = "请输入活动ID"
  411. return
  412. }
  413. resp := new(models.CygxActivityOfflineMeetingDetailResp)
  414. activityInfo, err := models.GetAddActivityInfoById(activityId)
  415. if err != nil {
  416. br.Msg = "获取信息失败"
  417. br.ErrMsg = "获取活动详情信息失败,Err:" + err.Error()
  418. return
  419. }
  420. if !services.GetBelongingRai(user.Mobile) {
  421. br.Msg = "你暂无查看权限"
  422. br.ErrMsg = "你暂无查看权限,UserId:" + strconv.Itoa(user.UserId)
  423. return
  424. }
  425. var condition string
  426. var pars []interface{}
  427. condition = ` AND do_fail_type = 0 AND activity_id = ?`
  428. pars = append(pars, activityId)
  429. listSignup, err := models.GetActivitySignupList(condition, pars)
  430. if err != nil && err.Error() != utils.ErrNoRow() {
  431. br.Msg = "获取信息失败"
  432. br.ErrMsg = "GetOfflineMeetingListWithUser,UserId:" + strconv.Itoa(user.UserId)
  433. return
  434. }
  435. //获取对应销售所能查看的用户手机号
  436. UserMobileMap, err := services.GetAdminCheckUserMobileMap(user)
  437. if err != nil {
  438. br.Msg = "获取信息失败"
  439. br.ErrMsg = "GetAdminCheckUserMobileMap,UserId:" + strconv.Itoa(user.UserId)
  440. return
  441. }
  442. //获取用户的签到时间
  443. SigninTimeMap, err := services.GetUserActivitySigninTimeMap(activityId)
  444. if err != nil {
  445. br.Msg = "获取信息失败"
  446. br.ErrMsg = "GetUserActivitySigninTimeMap,activityId:" + strconv.Itoa(activityId)
  447. return
  448. }
  449. for _, v := range listSignup {
  450. if _, ok := UserMobileMap[v.Mobile]; ok {
  451. item := new(models.CygxActivitySignupResp)
  452. item.RealName = v.RealName
  453. item.CompanyName = v.CompanyName
  454. if _, ok := SigninTimeMap[v.UserId]; ok {
  455. item.IsMeeting = 1
  456. item.SigninTime = SigninTimeMap[v.UserId]
  457. }
  458. resp.List = append(resp.List, item)
  459. }
  460. }
  461. if len(resp.List) == 0 {
  462. resp.List = make([]*models.CygxActivitySignupResp, 0)
  463. }
  464. resp.ActivityId = activityId
  465. resp.ActivityName = activityInfo.ActivityName
  466. br.Ret = 200
  467. br.Success = true
  468. br.Msg = "获取成功"
  469. br.Data = resp
  470. }