|
@@ -0,0 +1,260 @@
|
|
|
+package controllers
|
|
|
+
|
|
|
+import (
|
|
|
+ "encoding/json"
|
|
|
+ "hongze/hongze_cygx/models"
|
|
|
+ "hongze/hongze_cygx/services"
|
|
|
+ "hongze/hongze_cygx/utils"
|
|
|
+ "strconv"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+// 活动
|
|
|
+type ActivitySignCoAntroller struct {
|
|
|
+ BaseAuthController
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 活动扫码自动签到
|
|
|
+// @Description 活动扫码签到接口
|
|
|
+// @Param ActivityId query int true "活动ID"
|
|
|
+// @Success Ret=200 {object} models.CygxActivityResp
|
|
|
+// @router /detail [get]
|
|
|
+func (this *ActivitySignCoAntroller) Detail() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ user := this.User
|
|
|
+ if user == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,用户信息为空"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+ uid := user.UserId
|
|
|
+ activityId, _ := this.GetInt("ActivityId")
|
|
|
+ if activityId < 1 {
|
|
|
+ br.Msg = "请输入活动ID"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resp := new(models.CygxActivitySigninDetailResp)
|
|
|
+ activityInfo, err := models.GetAddActivityInfoByIdShow(uid, activityId)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取信息失败"
|
|
|
+ br.ErrMsg = "获取活动详情信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if activityInfo == nil {
|
|
|
+ br.Msg = "活动不存在"
|
|
|
+ br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ totalMySuccess, err := models.GetActivitySignupCount(uid, activityId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ detail := new(models.CygxActivitySigninResp)
|
|
|
+ if totalMySuccess > 0 {
|
|
|
+ detail.IsSignup = true
|
|
|
+ }
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+ condition = " AND user_id = ? AND activity_id = ? "
|
|
|
+ pars = append(pars, uid, activityId)
|
|
|
+ total, err := models.GetCygxActivitySigninCount(condition, pars)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ item := new(models.CygxActivitySignin)
|
|
|
+ item.ActivityId = activityId
|
|
|
+ item.UserId = user.UserId
|
|
|
+ item.Mobile = user.Mobile
|
|
|
+ item.Email = user.Email
|
|
|
+ item.CompanyId = user.CompanyId
|
|
|
+ item.RealName = user.RealName
|
|
|
+ item.CompanyName = user.CompanyName
|
|
|
+ item.IsSignup = totalMySuccess
|
|
|
+ item.CountryCode = user.CountryCode
|
|
|
+ item.CreateTime = time.Now()
|
|
|
+ if total == 0 && user.Mobile != "" {
|
|
|
+ err = models.AddCygxActivitySignin(item)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "签到失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //添加日志记录
|
|
|
+ go services.AddCygxActivitySigninLog(item)
|
|
|
+ if user.Mobile != "" {
|
|
|
+ resp.IsBindingMobile = true
|
|
|
+ }
|
|
|
+ if user.CompanyId == 1 {
|
|
|
+ detail.IsNewUser = true
|
|
|
+ }
|
|
|
+ detail.ActivityId = activityId
|
|
|
+ detail.ActivityName = activityInfo.ActivityName
|
|
|
+ detail.Mobile = user.Mobile
|
|
|
+ detail.RealName = user.RealName
|
|
|
+ detail.CompanyName = user.CompanyName
|
|
|
+ resp.Detail = detail
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+ br.Data = resp
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 活动扫码手动签到
|
|
|
+// @Description 活动扫码手动签到接口
|
|
|
+// @Param ActivityId query int true "活动ID"
|
|
|
+// @Success Ret=200 {object} models.CygxActivityResp
|
|
|
+// @router /byHand [post]
|
|
|
+func (this *ActivitySignCoAntroller) ByHand() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ user := this.User
|
|
|
+ if user == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,用户信息为空"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+ uid := user.UserId
|
|
|
+ resp := new(models.CygxActivitySigninDetailResp)
|
|
|
+ var req models.CygxActivitySigninReq
|
|
|
+ err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ signinType := req.SigninType
|
|
|
+ activityId := req.ActivityId
|
|
|
+ CountryCode := req.CountryCode
|
|
|
+ Mobile := req.Mobile
|
|
|
+ CompanyName := req.CompanyName
|
|
|
+ BusinessCard := req.BusinessCard
|
|
|
+ RealName := req.RealName
|
|
|
+ if activityId < 1 {
|
|
|
+ br.Msg = "请输入活动ID"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ user.RealName = RealName
|
|
|
+ user.CompanyName = CompanyName
|
|
|
+ activityInfo, err := models.GetAddActivityInfoByIdShow(uid, activityId)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取信息失败"
|
|
|
+ br.ErrMsg = "获取活动详情信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if activityInfo == nil {
|
|
|
+ br.Msg = "活动不存在"
|
|
|
+ br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ totalMySuccess, err := models.GetActivitySignupCount(uid, activityId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ item := new(models.CygxActivitySignin)
|
|
|
+
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+ condition = " AND user_id = ? AND activity_id = ? "
|
|
|
+ pars = append(pars, uid, activityId)
|
|
|
+ total, err := models.GetCygxActivitySigninCount(condition, pars)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if signinType == 1 {
|
|
|
+ if req.Mobile == "" {
|
|
|
+ br.Msg = "参数错误"
|
|
|
+ br.ErrMsg = "参数错误,手机号为空 为空"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ itemMsgCode, err := models.GetMsgCode(req.Mobile, req.VCode)
|
|
|
+ if err != nil {
|
|
|
+ if err.Error() == utils.ErrNoRow() {
|
|
|
+ br.Msg = "验证码错误,请重新输入"
|
|
|
+ br.ErrMsg = "校验验证码失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ br.Msg = "验证码错误,请重新输入"
|
|
|
+ br.ErrMsg = "校验验证码失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if itemMsgCode == nil {
|
|
|
+ br.Msg = "验证码错误,请重新输入"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ userMobile, err := models.GetWxUserItemByMobile(Mobile)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "签到失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if userMobile != nil {
|
|
|
+ user = userMobile
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if BusinessCard == "" {
|
|
|
+ br.Msg = "签到失败"
|
|
|
+ br.ErrMsg = "签到失败名片地址为空,Err:"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ item.BusinessCard = BusinessCard
|
|
|
+ }
|
|
|
+ item.ActivityId = activityId
|
|
|
+ item.UserId = user.UserId
|
|
|
+ item.Mobile = Mobile
|
|
|
+ item.CountryCode = CountryCode
|
|
|
+ item.Email = user.Email
|
|
|
+ item.CompanyId = user.CompanyId
|
|
|
+ item.RealName = user.RealName
|
|
|
+ item.CompanyName = user.CompanyName
|
|
|
+ item.IsSignup = totalMySuccess
|
|
|
+ item.BusinessCard = BusinessCard
|
|
|
+ item.CreateTime = time.Now()
|
|
|
+ if total == 0 {
|
|
|
+ err = models.AddCygxActivitySignin(item)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "签到失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ detail := new(models.CygxActivitySigninResp)
|
|
|
+ if totalMySuccess > 0 {
|
|
|
+ detail.IsSignup = true
|
|
|
+ }
|
|
|
+ item.RealName = RealName
|
|
|
+ item.CompanyName = CompanyName
|
|
|
+ //添加日志记录
|
|
|
+ go services.AddCygxActivitySigninLog(item)
|
|
|
+ if user.CompanyId == 1 {
|
|
|
+ detail.IsNewUser = true
|
|
|
+ }
|
|
|
+ detail.ActivityId = activityId
|
|
|
+ detail.ActivityName = activityInfo.ActivityName
|
|
|
+ detail.Mobile = Mobile
|
|
|
+ detail.RealName = user.RealName
|
|
|
+ detail.CompanyName = user.CompanyName
|
|
|
+ resp.Detail = detail
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+ br.Data = resp
|
|
|
+}
|