From cff1123c823ef49250d6079249e9e5eee951abd2 Mon Sep 17 00:00:00 2001 From: tommy <3405129587@qq.com> Date: Wed, 1 Apr 2020 11:03:21 +0800 Subject: [PATCH] sign history --- controllers/author.go | 4 ---- controllers/client/order_entry.go | 9 +++++++-- controllers/client/sign.go | 11 +++++++++-- controllers/pc/login.go | 4 ++-- controllers/pc/sign.go | 4 +--- models/order_entry_person.go | 7 ++++--- models/real_sign_history.go | 7 +++++++ models/sign_history.go | 14 +++++++------- models/user.go | 4 ++++ 9 files changed, 41 insertions(+), 23 deletions(-) diff --git a/controllers/author.go b/controllers/author.go index d5caa0b..8c8e508 100644 --- a/controllers/author.go +++ b/controllers/author.go @@ -46,10 +46,6 @@ func (t *AuthorCtl) MustGetActivityId() int64 { return t.MustGetInt64("activity_id") } -func (t *AuthorCtl) MustGetName() string { - return t.claims.Username -} - func (t *AuthorCtl) MustGetCustomerId() int64 { return t.claims.CustomerId } diff --git a/controllers/client/order_entry.go b/controllers/client/order_entry.go index 4553131..6857f3d 100644 --- a/controllers/client/order_entry.go +++ b/controllers/client/order_entry.go @@ -154,8 +154,13 @@ func (t *OrderEntryCtl) EntryOrders() { uid := t.MustGetUID() activityId := t.MustGetInt64("activity_id") + entry := new(models.OrderEntryPerson) + exist, err := entry.GetById(uid) + t.CheckErr(err) + t.Assert(exist, code.MSG_ENTRYPEOPLE_NOT_EXIST, "录入人员不存在") + activity := new(models.Activity) - exist, err := models.GetById(activity, activityId) + exist, err = models.GetById(activity, activityId) t.CheckErr(err) t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") @@ -178,7 +183,7 @@ func (t *OrderEntryCtl) EntryOrders() { data, err := invitation_service.GetOptionValue(optionItems, list[i].ExtraData) t.CheckErr(err) list[i].Extra = data - list[i].EntryName = t.MustGetName() + list[i].EntryName = entry.Name } t.JSON(map[string]interface{}{ diff --git a/controllers/client/sign.go b/controllers/client/sign.go index 438da0a..54225a3 100644 --- a/controllers/client/sign.go +++ b/controllers/client/sign.go @@ -23,6 +23,7 @@ func (t *SignCtl) Sign() { uid := t.MustGetUID() activityId := t.MustGetInt64("activity_id") customerId := t.MustGetInt64("customer_id") + kind, _ := t.GetInt("kind") //根据activity_id查找主活动的信息 activity := new(models.Activity) @@ -73,6 +74,7 @@ func (t *SignCtl) Sign() { } signHistory = new(models.SignHistory) + signHistory.Type = kind signHistory.UserId = uid signHistory.RehearsalId = activity.RehearsalId signHistory.ActivityId = activityId @@ -102,8 +104,13 @@ func (t *SignCtl) RealSign() { uid := t.MustGetUID() rid := t.MustGetInt64("rehearsal_id") + user := new(models.User) + exist, err := user.GetById(uid) + t.CheckErr(err) + t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在") + sign := new(models.SignUp) - exist, err := sign.GetByActivityId(aid) + exist, err = sign.GetByActivityId(aid) t.CheckErr(err) t.Assert(exist, code.MSG_SIGN_UP_NOT_EXIST, "签到活动不存在") @@ -132,7 +139,7 @@ func (t *SignCtl) RealSign() { history.ActivityId = aid history.UserId = uid - history.Nickname = t.MustGetName() + history.Nickname = user.Nickname history.RehearsalId = rid history.Content = string(body) if exist { // 存在 直接通过 diff --git a/controllers/pc/login.go b/controllers/pc/login.go index eeb17cc..c8b547e 100644 --- a/controllers/pc/login.go +++ b/controllers/pc/login.go @@ -38,7 +38,7 @@ func (t *UserCtl) Login() { t.CheckErr(err) // 主账号无法确定 - token, err := jwt.GenJwtToken("customer", customer.Id, customer.Id, customer.Pid, customer.AreaId, customer.ActivityId, customer.Username) + token, err := jwt.GenJwtToken("customer", customer.Id, customer.Id, customer.Pid, customer.AreaId, customer.ActivityId) t.CheckErr(err) t.SetSession(define.TOKEN, token) customer.Token = token @@ -68,7 +68,7 @@ func (t *UserCtl) DebugLogin() { t.CheckErr(err) t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在") - token, err := jwt.GenJwtToken("customer", customer.Id, customer.Id, customer.Pid, customer.AreaId, customer.ActivityId, customer.Username) + token, err := jwt.GenJwtToken("customer", customer.Id, customer.Id, customer.Pid, customer.AreaId, customer.ActivityId) t.CheckErr(err) t.SetSession(define.TOKEN, token) t.JSON(map[string]interface{}{ diff --git a/controllers/pc/sign.go b/controllers/pc/sign.go index a6a7eb9..057c802 100644 --- a/controllers/pc/sign.go +++ b/controllers/pc/sign.go @@ -92,9 +92,7 @@ func (t *SignCtl) SignInfo() { func (t *SignCtl) RealSignInfo() { aid := t.MustGetActivityId() rid := t.MustGetInt64("rehearsal_id") - results := make([]*models.RealSignHistory, 0) - err := core.GetXormAuto().Where("is_delete=0 and activity_id=? and rehearsal_id=? and status=0", - aid, rid).Asc("updated_at").Find(&results) + results, err := models.GetRealSignHistories(aid, rid) t.CheckErr(err) t.JSON(map[string]interface{}{ "result": results, diff --git a/models/order_entry_person.go b/models/order_entry_person.go index 5cf65f3..3d0dd4c 100644 --- a/models/order_entry_person.go +++ b/models/order_entry_person.go @@ -1,6 +1,7 @@ package models import ( + "github.com/ouxuanserver/osmanthuswine/src/core" "time" ) @@ -26,6 +27,6 @@ func (t *OrderEntryPerson) TableName() string { return OrderEntryPersonTableName } -//func (t *OrderEntryPerson) GetById(eid int64) (bool, error) { -// return core.GetXormAuto().Where("is_delete=0 and id=?", eid).Get(t) -//} +func (t *OrderEntryPerson) GetById(id interface{}) (bool, error) { + return core.GetXormAuto().Where("is_delete=0 and id=?", id).Get(t) +} diff --git a/models/real_sign_history.go b/models/real_sign_history.go index bbd7f9d..925fab0 100644 --- a/models/real_sign_history.go +++ b/models/real_sign_history.go @@ -47,3 +47,10 @@ func (t *RealSignHistory) Insert() error { _, err := core.GetXormAuto().InsertOne(t) return err } + +func GetRealSignHistories(aid interface{}, rid interface{}) ([]*RealSignHistory, error) { + results := make([]*RealSignHistory, 0) + err := core.GetXormAuto().Where("is_delete=0 and activity_id=? and rehearsal_id=? and status=0", + aid, rid).Asc("updated_at").Find(&results) + return results, err +} diff --git a/models/sign_history.go b/models/sign_history.go index 6744517..2661787 100644 --- a/models/sign_history.go +++ b/models/sign_history.go @@ -9,13 +9,13 @@ const SignHistoryTN = TableNamePrefix + "sign_history" //签到历史表 type SignHistory struct { - Id int64 `json:"id" xorm:"pk autoincr comment('主键') BIGINT(20)"` - AreaId int64 `json:"area_id" xorm:"not null default 0 comment('地区id') BIGINT(20)"` - ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('主活动id') BIGINT(20)"` - RehearsalId int64 `json:"rehearsal_id" xorm:"not null default 0 comment('彩排id/ 0正式') BIGINT(20)"` - SignRuleId int64 `json:"sign_rule_id" xorm:"not null default 0 comment('sign_up表id') BIGINT(20)"` - UserId int64 `json:"user_id" xorm:"not null default 0 comment('用户表id') BIGINT(20)"` - User *User `json:"user" xorm:"-" description:"用户得信息"` + Id int64 `json:"id" xorm:"pk autoincr comment('主键') INT(11)"` + AreaId int64 `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"` + ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('主活动id') INT(11)"` + RehearsalId int64 `json:"rehearsal_id" xorm:"not null default 0 comment('彩排id/ 0正式') INT(11)"` + SignRuleId int64 `json:"sign_rule_id" xorm:"not null default 0 comment('sign_up表id') INT(11)"` + Type int `json:"type" xorm:"not null default 0 comment('普通签到') INT(2)"` + UserId int64 `json:"user_id" xorm:"not null default 0 comment('用户表id') INT(11)"` IsDelete bool `json:"is_delete" xorm:"not null default(0) comment('删除') TINYINT(1)"` CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"` UpdatedAt time.Time `json:"updated_at" xorm:"not null updated comment('更新时间') DATETIME"` diff --git a/models/user.go b/models/user.go index 014b6da..94b52b5 100644 --- a/models/user.go +++ b/models/user.go @@ -43,6 +43,10 @@ func (t *User) GetUserByOpenid(openId string) (bool, error) { return core.GetXormAuto().Where("openid=?", openId).Get(t) } +func (t *User) GetById(id interface{}) (bool, error) { + return core.GetXormAuto().Where("is_delete=0 and id=?", id).Get(t) +} + func (t *User) SaveAndUpdateWithOpenId() error { exist, err := core.GetXormAuto().Table(UserTN).Where("openid=?", t.Openid).Exist() if err != nil {