xingzai 1 éve
szülő
commit
d5f9016277
5 módosított fájl, 199 hozzáadás és 0 törlés
  1. 113 0
      controllers/activity_sign.go
  2. 70 0
      models/activity_signin.go
  3. 2 0
      models/db.go
  4. 9 0
      routers/commentsRouter.go
  5. 5 0
      routers/router.go

+ 113 - 0
controllers/activity_sign.go

@@ -0,0 +1,113 @@
+package controllers
+
+import (
+	"hongze/hongze_cygx/models"
+	"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.CygxActivitySigninResp)
+	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
+	}
+	if totalMySuccess > 0 {
+		resp.IsSignup = true
+	}
+	var condition string
+	var pars []interface{}
+	total, err := models.GetCygxActivitySigninCount(condition, pars)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+
+	if total == 0 {
+		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.CreateTime = time.Now()
+		err = models.AddCygxActivitySignin(item)
+		if err != nil {
+			br.Msg = "签到失败"
+			br.ErrMsg = "获取失败,Err:" + err.Error()
+			return
+		}
+	}
+	//添加日志记录
+	itemLog := new(models.CygxActivitySigninLog)
+	itemLog.ActivityId = activityId
+	itemLog.UserId = user.UserId
+	itemLog.Mobile = user.Mobile
+	itemLog.Email = user.Email
+	itemLog.CompanyId = user.CompanyId
+	itemLog.RealName = user.RealName
+	itemLog.CompanyName = user.CompanyName
+	itemLog.IsSignup = totalMySuccess
+	itemLog.CreateTime = time.Now()
+	err = models.AddCygxActivitySigninLog(itemLog)
+	if err != nil {
+		br.Msg = "签到失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+	resp.ActivityId = activityId
+	resp.ActivityName = activityInfo.ActivityName
+	resp.Mobile = user.Mobile
+	resp.RealName = user.RealName
+	resp.CompanyName = user.CompanyName
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 70 - 0
models/activity_signin.go

@@ -0,0 +1,70 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxActivitySignin struct {
+	Id           int       `orm:"column(id);pk"`
+	ActivityId   int       `description:"活动ID"`
+	UserId       int       `description:"用户ID"`
+	CreateTime   time.Time `description:"创建时间"`
+	Mobile       string    `description:"手机号"`
+	Email        string    `description:"邮箱"`
+	CompanyId    int       `description:"公司id"`
+	CompanyName  string    `description:"公司名称"`
+	BusinessCard string    `description:"名片"`
+	RealName     string    `description:"用户实际名称"`
+	IsSignup     int       `description:"是否报名了"`
+}
+
+type CygxActivitySigninLog struct {
+	Id           int       `orm:"column(id);pk"`
+	ActivityId   int       `description:"活动ID"`
+	UserId       int       `description:"用户ID"`
+	CreateTime   time.Time `description:"创建时间"`
+	Mobile       string    `description:"手机号"`
+	Email        string    `description:"邮箱"`
+	CompanyId    int       `description:"公司id"`
+	CompanyName  string    `description:"公司名称"`
+	BusinessCard string    `description:"名片"`
+	RealName     string    `description:"用户实际名称"`
+	IsSignup     int       `description:"是否报名了"`
+}
+
+type CygxActivitySigninResp struct {
+	ActivityId   int    `description:"活动ID"`
+	ActivityName string `description:"活动名称"`
+	RealName     string `description:"用户实际名称"`
+	Mobile       string `description:"手机号"`
+	CompanyName  string `description:"公司名称"`
+	BusinessCard string `description:"名片"`
+	IsNewUser    bool   `description:"是否属于新客户"`
+	IsSignup     bool   `description:"是否报名了"`
+}
+
+// 获取数量
+func GetCygxActivitySigninCount(condition string, pars []interface{}) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_activity_signin as art WHERE 1= 1  `
+	if condition != "" {
+		sqlCount += condition
+	}
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, pars).QueryRow(&count)
+	return
+}
+
+// 添加
+func AddCygxActivitySignin(item *CygxActivitySignin) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(item)
+	return
+}
+
+// 添加日志
+func AddCygxActivitySigninLog(item *CygxActivitySigninLog) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(item)
+	return
+}

+ 2 - 0
models/db.go

@@ -135,6 +135,8 @@ func init() {
 		new(CygxXzsChooseCategory),
 		new(CygxReportSelectionSubjectHistory),
 		new(CygxTacticsTimeLineHistory),
+		new(CygxActivitySignin),
+		new(CygxActivitySigninLog),
 	)
 	// 记录ORM查询日志
 	orm.Debug = true

+ 9 - 0
routers/commentsRouter.go

@@ -232,6 +232,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ActivitySignCoAntroller"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ActivitySignCoAntroller"],
+        beego.ControllerComments{
+            Method: "Detail",
+            Router: `/detail`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ActivitySpecialCoAntroller"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ActivitySpecialCoAntroller"],
         beego.ControllerComments{
             Method: "SpecialTripAdd",

+ 5 - 0
routers/router.go

@@ -139,6 +139,11 @@ func init() {
 				&controllers.ReportSelectionController{},
 			),
 		),
+		web.NSNamespace("/activity_signin",
+			web.NSInclude(
+				&controllers.ActivitySignCoAntroller{},
+			),
+		),
 	)
 	web.AddNamespace(ns)
 }