From 9a20e1270e8c64bcffd688db89aa4467ed0f7056 Mon Sep 17 00:00:00 2001 From: tommy <3405129587@qq.com> Date: Wed, 20 May 2020 17:37:52 +0800 Subject: [PATCH] rm core --- controllers/client/lottery.go | 4 +-- controllers/client/reward.go | 7 +--- controllers/client/sign.go | 25 +++++-------- controllers/client/tug_war.go | 32 ++--------------- controllers/client/upper_wall.go | 17 ++++----- controllers/client/vote.go | 4 +-- controllers/pc/lottery_draw.go | 24 ++++++++----- models/activity_module_service.go | 10 ++++-- models/bahe_team.go | 14 ++++++++ models/bahe_team_member.go | 5 +++ models/invitation_letter.go | 9 ++--- models/lottery_draw_record.go | 72 ++++++++++++++++++++++---------------- models/lottery_draw_rule_ladder.go | 1 + models/module_service_history.go | 5 +++ models/new_vote_activity.go | 5 +++ models/sign_history.go | 5 +-- models/upper_wall.go | 11 +++++- 17 files changed, 135 insertions(+), 115 deletions(-) diff --git a/controllers/client/lottery.go b/controllers/client/lottery.go index 1c74a20..b4d90cc 100644 --- a/controllers/client/lottery.go +++ b/controllers/client/lottery.go @@ -68,7 +68,7 @@ func (t *LotteryCtl) CheckLottery() { t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在") record := new(models.LotteryDrawRecord) - exist, err = record.GetByUserIdAndLadderId(uid, ladderId) + exist, err = record.GetByUserIdAndLadderId(uid, ladderId, ladder.RollNum) t.CheckErr(err) t.JSON(map[string]interface{}{ "record": record, @@ -93,7 +93,7 @@ func (t *LotteryCtl) Winners() { t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在") result := make([]*LotteryUsersResult, 0) - err = models.GetLotteryUsersResultByLotteryDrawRecord(result, ladderId, activity.RehearsalId) + err = models.GetLotteryUsersResultByLotteryDrawRecord(result, ladderId, activity.RehearsalId, ladder.RollNum) t.CheckErr(err) t.JSON(map[string]interface{}{ "total": len(result), diff --git a/controllers/client/reward.go b/controllers/client/reward.go index e5cf7eb..b1c8b69 100644 --- a/controllers/client/reward.go +++ b/controllers/client/reward.go @@ -9,8 +9,6 @@ import ( "hudongzhuanjia/utils" "hudongzhuanjia/utils/code" "time" - - "github.com/ouxuanserver/osmanthuswine/src/core" ) //打赏 @@ -82,7 +80,7 @@ func (t *RewardCtl) Reward() { history.Status = 0 } - _, err = core.GetXormAuto().InsertOne(history) + _, err = models.Add(history) t.CheckErr(err) res["rehearsal_id"] = activity.RehearsalId @@ -103,9 +101,6 @@ func (t *RewardCtl) List() { t.CheckErr(err) t.Assert(exist, code.MSG_REWARD_NOT_EXIST, "打赏不存在") - ////// todo: 检查订单 - //t.CheckErr(bully_reward_service.CheckRewardStatus(rs.Id)) - list, err := bully_reward_service.GetRewardList(uid, activity.RehearsalId, rs.Id) t.CheckErr(err) t.JSON(map[string]interface{}{ diff --git a/controllers/client/sign.go b/controllers/client/sign.go index b32258c..3f0fe94 100644 --- a/controllers/client/sign.go +++ b/controllers/client/sign.go @@ -3,9 +3,7 @@ package client import ( "encoding/json" "fmt" - "github.com/ouxuanserver/osmanthuswine/src/core" "hudongzhuanjia/controllers" - "hudongzhuanjia/logger" "hudongzhuanjia/models" ws_send_service "hudongzhuanjia/services/ws_send" "hudongzhuanjia/utils/code" @@ -70,15 +68,12 @@ func (t *SignCtl) Setting() { exist, err := service.GetByName(define.MODULE_SIGNIN) t.CheckErr(err) t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "签到模块不存在") - histories := make([]*models.ModuleServiceHistory, 0) - err = core.GetXormAuto().Where("is_delete=0 and service_module_id=? and name=?", service.Id, service.Name).Find(&histories) - t.CheckErr(err) historyIds := make([]int64, 0) - for _, history := range histories { - historyIds = append(historyIds, history.Id) - } + err = models.GetModuleServiceHistoryIdsByIdAndName(&historyIds, service.Id, service.Name) + t.CheckErr(err) + module := new(models.ActivityModuleService) - exist, err = core.GetXormAuto().Where("is_delete=0 and activity_id=?", activityId).In("service_module_history_id", historyIds).Get(module) + exist, err = module.GetByActivityIdAndHistoryIds(activityId, historyIds) t.CheckErr(err) t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "签到模块不存在") @@ -111,9 +106,6 @@ func (t *SignCtl) Sign() { user := new(models.User) exist, err = models.Get(user, uid) - logger.Error("user:===>%+v", user) - logger.Error("token:==>%v", t.MustGet("token")) - logger.Error("user_id:===>%v", uid) t.CheckErr(err) t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在") @@ -132,16 +124,15 @@ func (t *SignCtl) Sign() { } //检查是否已经签到了 signHistory := new(models.SignHistory) - exist, err = signHistory.GetByUserId(activityId, uid, activity.RehearsalId, t.MustGetAreaId()) + exist, err = signHistory.GetByUserId(activityId, uid, activity.RehearsalId, area.Id) t.CheckErr(err) t.Assert(!exist, code.MSG_SIGN_HISTORY_EXIST, "您已经签到过了") // 存在判断 // 签到人数 - signTotal, err := core.GetXormAuto().Where("is_delete=0 and sign_rule_id=? and rehearsal_id=? and activity_id=?", - signUp.Id, activity.RehearsalId, activity.Id).Count(signHistory) + signTotal, err := signHistory.Count(signUp.Id, activity.RehearsalId, activity.Id) t.CheckErr(err) - signUpTotal, err := core.GetXormAuto().Where("is_delete=0 and activity_id=?", activity.Id).Count(new(models.InvitationLetter)) + signUpTotal, err := new(models.InvitationLetter).Count(activity.Id, activity.RehearsalId) t.CheckErr(err) if activity.RehearsalId != 0 && signTotal >= 10 { @@ -158,7 +149,7 @@ func (t *SignCtl) Sign() { signHistory.IsDelete = false signHistory.UpdatedAt = time.Now() signHistory.CreatedAt = time.Now() - _, err = core.GetXormAuto().InsertOne(signHistory) + _, err = models.Add(signHistory) t.CheckErr(err) go ws_send_service.SendSign(fmt.Sprintf("%d", activity.Id), diff --git a/controllers/client/tug_war.go b/controllers/client/tug_war.go index b5b5ce6..4a8bcf1 100644 --- a/controllers/client/tug_war.go +++ b/controllers/client/tug_war.go @@ -7,8 +7,6 @@ import ( "hudongzhuanjia/utils/code" "hudongzhuanjia/utils/define" "time" - - "github.com/ouxuanserver/osmanthuswine/src/core" ) type TugOfWarCtl struct { @@ -74,19 +72,6 @@ func (t *TugOfWarCtl) Status() { }) } -// tug_war doc -// @Summary tug war -// @Description shake bahe activity -// @Tags tug war -// @Accept json -// @Produce json -// @Param bahe_activity_id query int true "Bahe Activity ID" -// @Success 0 {object} models.TugOfWar -// @Success 0 {object} models.BaheTeamMember -// @Success 0 {object} models.BaheTeam -// @Failure 404 {string} string "参数不存在" -// @Failure 405 {object} string "用户不存在" -// @Router /Client/TugOfWarCtl/shake [get] func (t *TugOfWarCtl) Shake() { uid := t.MustGetUID() baheId := t.MustGetInt64("bahe_activity_id") @@ -117,8 +102,7 @@ func (t *TugOfWarCtl) Shake() { // 根据team_id 获取所有成员的分数 members := make([]*models.BaheTeamMember, 0) - err = core.GetXormAuto().Where("is_delete=0 and team_id=? and rehearsal_id=?", - member.TeamId, member.RehearsalId).Desc("score").Asc("sort_time").Find(&members) + err = models.GetBaheMembersByTeamId(members, member.TeamId, member.RehearsalId) t.CheckErr(err) var rank int @@ -172,17 +156,7 @@ func (t *TugOfWarCtl) JoinTeam() { } team := new(JoinTeamResult) - session := core.GetXormAuto().Table(new(models.BaheTeam)).Alias("t"). - Select("t.id as team_id, t.bahe_team_name as team_name, count(m.id) as number"). - Join("LEFT", new(models.BaheTeamMember).Alias("m"), - "m.team_id=t.id and m.is_delete=0 and m.rehearsal_id=?", activity.RehearsalId) - if teamId == 0 { // 人数最少的一队 - session = session.Where("t.is_delete=0 and t.bahe_activity_id=? ", bahe.Id). - GroupBy("t.id").Asc("number") - } else { - session = session.Where("t.is_delete=0 and t.id=?", teamId).GroupBy("t.id") - } - exist, err = session.Get(team) + exist, err = models.GetJoinTeamByBaheId(team, bahe.Id, teamId, activity.RehearsalId) t.CheckErr(err) t.Assert(exist, code.MSG_ERR, "队伍信息错误, 请重新扫码") t.Assert(team.Number < bahe.Number, code.MSG_TUGWAR_TEAM_OVER_LIMIT, "队伍满人,请等待下一轮") @@ -203,7 +177,7 @@ func (t *TugOfWarCtl) JoinTeam() { member.SortTime = time.Now().UnixNano() member.CreatedAt = time.Now() member.UpdatedAt = time.Now() - _, err = core.GetXormAuto().InsertOne(member) + _, err = models.Add(member) t.CheckErr(err) t.JSON(map[string]interface{}{ "member": member, diff --git a/controllers/client/upper_wall.go b/controllers/client/upper_wall.go index fe0f7f4..fe7e291 100644 --- a/controllers/client/upper_wall.go +++ b/controllers/client/upper_wall.go @@ -6,8 +6,6 @@ import ( "hudongzhuanjia/models" "hudongzhuanjia/utils/code" "time" - - "github.com/ouxuanserver/osmanthuswine/src/core" ) type UpperWallCtl struct { @@ -53,12 +51,12 @@ func (t *UpperWallCtl) Send() { uw.Status = 0 uw.CreatedAt = time.Now() uw.UpdatedAt = time.Now() - _, err = core.GetXormAuto().Insert(uw) + _, err = models.Add(uw) t.CheckErr(err) t.SUCCESS("成功") } -type UWListResult struct { +type UpperWallResult struct { Id int64 `json:"id"` Content string `json:"content"` Img string `json:"img"` @@ -68,18 +66,15 @@ type UWListResult struct { func (t *UpperWallCtl) List() { activityId := t.MustGetInt64("activity_id") - uid := t.MustGetUID() + userId := t.MustGetUID() activity := new(models.Activity) exist, err := models.Get(activity, activityId) t.CheckErr(err) t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") - list := make([]*UWListResult, 0) - err = core.GetXormAuto().Table(new(models.UpperWall)). - Select("id, content, img, category, status"). - Where("is_delete=0 and user_id=? and activity_id=? and rehearsal_id=?", - uid, activityId, activity.RehearsalId). - OrderBy("created_at desc").Find(&list) + + list := make([]*UpperWallResult, 0) + err = models.GetUpperWallResultByUserIdAndActivityId(list, userId, activity.Id, activity.RehearsalId) t.CheckErr(err) t.JSON(map[string]interface{}{ "list": list, diff --git a/controllers/client/vote.go b/controllers/client/vote.go index 68ce0fd..9b984e2 100644 --- a/controllers/client/vote.go +++ b/controllers/client/vote.go @@ -61,7 +61,7 @@ func (t *VoteCtl) Vote() { history.IsDelete = false history.CreatedAt = time.Now() history.UpdatedAt = time.Now() - _, err = core.GetXormAuto().InsertOne(history) + _, err = models.Add(history) t.CheckErr(err) // vote ladder total_number + 1 @@ -83,7 +83,7 @@ func (t *VoteCtl) List() { t.CheckRunning(activity.Status) votes := make([]*models.NewVoteActivity, 0) - err = core.GetXormAuto().Where("is_delete=0 and activity_id=?", activityId).Desc("created_at").Find(&votes) + err = models.GetVoteListByActivityId(votes, activity.Id) t.CheckErr(err) t.JSON(map[string]interface{}{ diff --git a/controllers/pc/lottery_draw.go b/controllers/pc/lottery_draw.go index 34c5275..c6e6345 100644 --- a/controllers/pc/lottery_draw.go +++ b/controllers/pc/lottery_draw.go @@ -34,10 +34,9 @@ func (t *LotteryDrawCtl) Start() { } ladder.Status = define.StatusRunning ladder.UpdatedAt = time.Now() - t.CheckErr(models.Save(map[string]interface{}{ - "id=": ladderId, - }, ladder, "status", "updated_at")) - + ladder.RollNum = 0 + _, err = models.Update(ladder.Id, ladder, "status", "roll_num", "updated_at") + t.CheckErr(err) // 通知直播开始抽奖 im_service.SendGroupCustomMessage("admin", activityId, im_service.NoticeLotteryDrawStart, map[string]interface{}{ @@ -62,11 +61,15 @@ func (t *LotteryDrawCtl) StartRoll() { if ladder.Status != define.StatusRunning { t.ERROR(fmt.Sprintf("该活动%s", ladder.Status), code.MSG_ERR) } + ladder.RollNum += 1 + _, err = models.Update(ladder.Id, ladder, "roll_num") + // 通知直播开始抽奖 im_service.SendGroupCustomMessage("admin", activityId, im_service.NoticeLotteryDrawRollStart, map[string]interface{}{ "lottery_draw_ladder_id": ladder.Id, "timestamp": time.Now().Unix(), + "roll_num": ladder.RollNum, "desc": "开始滚动", "number": num, }) @@ -91,6 +94,7 @@ func (t *LotteryDrawCtl) StopRoll() { map[string]interface{}{ "lottery_draw_ladder_id": ladder.Id, "timestamp": time.Now().Unix(), + "roll_num": ladder.RollNum, "desc": "停止滚动", "number": num, }) @@ -113,9 +117,9 @@ func (t *LotteryDrawCtl) Stop() { ladder.Status = define.StatusEnding ladder.UpdatedAt = time.Now() - t.CheckErr(models.Save(map[string]interface{}{ - "id=": ladderId, - }, ladder, "status", "updated_at")) + ladder.RollNum = 0 + _, err = models.Update(ladder.Id, ladder, "status, updated_at, roll_num") + t.CheckErr(err) // 通知直播开始抽奖 im_service.SendGroupCustomMessage("admin", activityId, im_service.NoticeLotteryDrawStop, @@ -431,7 +435,7 @@ func (t *LotteryDrawCtl) Lottery() { userPrize.IsDelete = false userPrize.CreatedAt = time.Now() userPrize.UpdatedAt = time.Now() - _, err = core.GetXormAuto().Insert(userPrize) + _, err = models.Add(userPrize) t.CheckErr(err) record := new(models.LotteryDrawRecord) @@ -447,10 +451,11 @@ func (t *LotteryDrawCtl) Lottery() { record.PrizeName = ladder.PrizeName record.AreaId = area.Id record.AreaName = area.Name + record.RollNum = ladder.RollNum record.IsDelete = false record.CreatedAt = time.Now() record.UpdatedAt = time.Now() - _, err = core.GetXormAuto().InsertOne(record) + _, err = models.Add(record) t.CheckErr(err) } @@ -459,6 +464,7 @@ func (t *LotteryDrawCtl) Lottery() { map[string]interface{}{ "lottery_draw_ladder_id": ladder.Id, "winners": winners, + "roll_num": ladder.RollNum, "timestamp": time.Now().Unix(), "desc": "抽奖结果", }) diff --git a/models/activity_module_service.go b/models/activity_module_service.go index 5473e8f..320285f 100644 --- a/models/activity_module_service.go +++ b/models/activity_module_service.go @@ -45,6 +45,12 @@ func (t *ActivityModuleService) Alias(name string) string { return AliasTableName(t, name) } -func (t *ActivityModuleService) GetByActivityIdAndHistoryId(aid, hid int64) (bool, error) { - return core.GetXormAuto().Where("is_delete=0 and activity_id=? and service_module_history_id=?", aid, hid).Get(t) +// +//func (t *ActivityModuleService) GetByActivityIdAndHistoryId(aid, hid int64) (bool, error) { +// return core.GetXormAuto().Where("is_delete=0 and activity_id=? and service_module_history_id=?", aid, hid).Get(t) +//} + +func (t *ActivityModuleService) GetByActivityIdAndHistoryIds(activityId, historyIds interface{}) (bool, error) { + return core.GetXormAuto().Where("is_delete=0 and activity_id=?", activityId). + In("service_module_history_id", historyIds).Get(t) } diff --git a/models/bahe_team.go b/models/bahe_team.go index a4cb27c..02f7ffc 100644 --- a/models/bahe_team.go +++ b/models/bahe_team.go @@ -29,3 +29,17 @@ func (t *BaheTeam) TableName() string { func (t *BaheTeam) GetOtherTeam(id, bid int64) (bool, error) { return core.GetXormAuto().Where("is_delete=0 and id=? and bahe_activity_id=?", id, bid).Get(t) } + +func GetJoinTeamByBaheId(obj, baheId, teamId, rehearsalId interface{}) (bool, error) { + session := core.GetXormAuto().Table(new(BaheTeam)).Alias("t"). + Select("t.id as team_id, t.bahe_team_name as team_name, count(m.id) as number"). + Join("LEFT", new(BaheTeamMember).Alias("m"), + "m.team_id=t.id and m.is_delete=0 and m.rehearsal_id=?", rehearsalId) + if teamId == 0 { // 人数最少的一队 + session = session.Where("t.is_delete=0 and t.bahe_activity_id=? ", baheId). + GroupBy("t.id").Asc("number") + } else { + session = session.Where("t.is_delete=0 and t.id=?", teamId).GroupBy("t.id") + } + return session.Get(&obj) +} diff --git a/models/bahe_team_member.go b/models/bahe_team_member.go index 985abc3..3f6931e 100644 --- a/models/bahe_team_member.go +++ b/models/bahe_team_member.go @@ -41,3 +41,8 @@ func (t *BaheTeamMember) IncrScoreById(id, score int64) (int64, error) { t.SortTime = time.Now().UnixNano() return core.GetXormAuto().ID(id).Incr("score", score).Cols("score, sort_time").Update(t) } + +func GetBaheMembersByTeamId(obj, teamId, rehearsalId interface{}) error { + return core.GetXormAuto().Where("is_delete=0 and team_id=? and rehearsal_id=?", + teamId, rehearsalId).Desc("score").Asc("sort_time").Find(&obj) +} diff --git a/models/invitation_letter.go b/models/invitation_letter.go index c93ed06..e9075f7 100644 --- a/models/invitation_letter.go +++ b/models/invitation_letter.go @@ -28,10 +28,11 @@ func (t *InvitationLetter) Alias(name string) string { return AliasTableName(t, name) } -func (t *InvitationLetter) Insert() (int64, error) { - return core.GetXormAuto().InsertOne(t) -} - func (t *InvitationLetter) GetByUserIdAndActivityId(uid, aid, rid int64) (bool, error) { return core.GetXormAuto().Where("user_id=? and activity_id=? and rehearsal_id=? and is_delete=0", uid, aid, rid).Get(t) } + +func (t *InvitationLetter) Count(activityId, rehearsalId interface{}) (int64, error) { + return core.GetXormAuto().Where("is_delete=0 and activity_id=? and rehearsal_id=?", activityId, rehearsalId). + Count(t) +} diff --git a/models/lottery_draw_record.go b/models/lottery_draw_record.go index 6674cec..c6aad0d 100644 --- a/models/lottery_draw_record.go +++ b/models/lottery_draw_record.go @@ -8,37 +8,45 @@ import ( const LotteryDrawRecordTableName = TableNamePrefix + "lottery_draw_record" type LotteryDrawRecord struct { - Id int64 `json:"id" xorm:"pk autoincr"` - ActivityId int64 `json:"activity_id" xorm:"not null comment('主活动id')"` - RehearsalId int64 `json:"rehearsal_id" xorm:"not null comment('彩排id/0正式')"` - UserPrizeId int64 `json:"user_prize_id" xorm:"not null comment('用户奖品id') INT(11)"` - LotteryDrawActivityId int64 `json:"lottery_draw_activity_id" xorm:"not null comment('抽奖活动id')"` - LotteryDrawRuleId int64 `json:"lottery_draw_rule_id" xorm:"not null comment('抽奖规则id') BIGINT(20)"` - LotteryDrawRuleLadder *LotteryDrawRuleLadder `json:"lottery_draw_rule_ladder" xorm:"-"` - UserId int64 `json:"user_id" xorm:"not null comment('用户id')"` - User *User `json:"user" xorm:"-"` - UserName string `json:"user_name" description:"用户名" xorm:"not null comment('用户名')"` - UserPhone string `json:"user_phone" description:"电话" xorm:"not null comment('电话号码')"` - LotteryDrawRuleLadderId int64 `json:"lottery_draw_rule_ladder_id" xorm:"not null comment('规则阶梯id')"` - PrizeName string `json:"prize_name" description:"奖品名字" xorm:"not null comment('奖品名字')"` - AreaName string `json:"area_name" description:"名字" xorm:"not null comment('地区名字')"` - AreaId int64 `json:"area_id" xorm:"not null default(0) comment('地区id')"` - Status int `json:"status" xorm:"not null default 0 comment('是否已经兑奖0否1是') TINYINT(1)"` - Name string `json:"name" xorm:"not null default '' comment('姓名') VARCHAR(128)"` - Phone string `json:"phone" xorm:"not null default '' comment('电话号码') VARCHAR(128)"` - WxNo string `json:"wx_no" xorm:"not null default '' comment('微信号') VARCHAR(128)"` - Address string `json:"address" xorm:"not null default '' comment('地址') VARCHAR(128)"` - IsDelete bool `json:"-" xorm:"default(0)"` - CreatedAt time.Time `json:"-" xorm:"created"` - UpdatedAt time.Time `json:"-" xorm:"updated"` + Id int64 `json:"id" xorm:"pk autoincr"` + ActivityId int64 `json:"activity_id" xorm:"not null comment('主活动id')"` + RehearsalId int64 `json:"rehearsal_id" xorm:"not null comment('彩排id/0正式')"` + UserPrizeId int64 `json:"user_prize_id" xorm:"not null comment('用户奖品id') INT(11)"` + LotteryDrawActivityId int64 `json:"lottery_draw_activity_id" xorm:"not null comment('抽奖活动id')"` + LotteryDrawRuleId int64 `json:"lottery_draw_rule_id" xorm:"not null comment('抽奖规则id') BIGINT(20)"` + LotteryDrawRuleLadderId int64 `json:"lottery_draw_rule_ladder_id" xorm:"not null comment('规则阶梯id')"` + UserId int64 `json:"user_id" xorm:"not null comment('用户id')"` + RollNum int `json:"roll_num" xrom:"not null default 0 comment('滚动次数') INT(11)"` + UserName string `json:"user_name" description:"用户名" xorm:"not null comment('用户名')"` + UserPhone string `json:"user_phone" description:"电话" xorm:"not null comment('电话号码')"` + PrizeName string `json:"prize_name" description:"奖品名字" xorm:"not null comment('奖品名字')"` + AreaName string `json:"area_name" description:"名字" xorm:"not null comment('地区名字')"` + AreaId int64 `json:"area_id" xorm:"not null default(0) comment('地区id')"` + Status int `json:"status" xorm:"not null default 0 comment('是否已经兑奖0否1是') TINYINT(1)"` + Name string `json:"name" xorm:"not null default '' comment('姓名') VARCHAR(128)"` + Phone string `json:"phone" xorm:"not null default '' comment('电话号码') VARCHAR(128)"` + WxNo string `json:"wx_no" xorm:"not null default '' comment('微信号') VARCHAR(128)"` + Address string `json:"address" xorm:"not null default '' comment('地址') VARCHAR(128)"` + IsDelete bool `json:"-" xorm:"default(0)"` + CreatedAt time.Time `json:"-" xorm:"created"` + UpdatedAt time.Time `json:"-" xorm:"updated"` + + // 无关变量 + User *User `json:"user" xorm:"-"` + LotteryDrawRuleLadder *LotteryDrawRuleLadder `json:"lottery_draw_rule_ladder" xorm:"-"` } func (t *LotteryDrawRecord) TableName() string { return LotteryDrawRecordTableName } -func (t *LotteryDrawRecord) GetByUserIdAndLadderId(userId, ladderId interface{}) (bool, error) { - return core.GetXormAuto().Where("is_delete=0 and user_id=? and lottery_draw_rule_ladder_id=?", userId, ladderId).Get(t) +func (t *LotteryDrawRecord) GetByUserIdAndLadderId(userId, ladderId interface{}, rollNum int) (bool, error) { + session := core.GetXormAuto().Where("is_delete=0 and user_id=? and lottery_draw_rule_ladder_id=?", userId, ladderId) + defer session.Close() + if rollNum > 0 { + session.Where("roll_num=?", rollNum) + } + return session.Get(t) } func (t *LotteryDrawRecord) GetByUserPrizeId(upId int64) (bool, error) { @@ -50,12 +58,16 @@ func (t *LotteryDrawRecord) Update(id interface{}, field ...string) (int64, erro return core.GetXormAuto().Where("id=?", id).Update(t) } -func GetLotteryUsersResultByLotteryDrawRecord(obj, ladderId, rehearsalId interface{}) error { - err := core.GetXormAuto().Table(new(LotteryDrawRecord)).Alias("r"). +func GetLotteryUsersResultByLotteryDrawRecord(obj, ladderId, rehearsalId interface{}, rollNum int) error { + session := core.GetXormAuto().Table(new(LotteryDrawRecord)).Alias("r"). Join("LEFT", new(User).Alias("u"), "u.id=r.user_id"). - Where("r.is_delete=0 and r.lottery_draw_rule_ladder_id=? and r.rehearsal_id=?", ladderId, rehearsalId). - Find(&obj) - return err + Where("r.is_delete=0 and r.lottery_draw_rule_ladder_id=? and "+ + "r.rehearsal_id=?", ladderId, rehearsalId) + defer session.Close() + if rollNum > 0 { + session = session.Where("roll_num=?", rollNum) + } + return session.Find(&obj) } func GetUserIdsByLotteryDrawRuleId(obj, ruleId, rehearsalId, areaId interface{}) error { diff --git a/models/lottery_draw_rule_ladder.go b/models/lottery_draw_rule_ladder.go index 293aacd..a13fbd9 100644 --- a/models/lottery_draw_rule_ladder.go +++ b/models/lottery_draw_rule_ladder.go @@ -12,6 +12,7 @@ const LotteryDrawRuleLadderTableName = TableNamePrefix + "lottery_draw_rule_ladd type LotteryDrawRuleLadder struct { Id int64 `json:"id"` LotteryDrawRuleId int64 `json:"lottery_draw_rule_id" description:"红包轮次的id"` + RollNum int `json:"roll_num" xorm:"not null default 0 comment('滚动次数') INT(11)"` PrizeName string `json:"prize_name" description:"奖品名字"` PrizeNumber int `json:"prize_number" description:"奖品数量"` Probability float64 `json:"probability" description:"概率"` diff --git a/models/module_service_history.go b/models/module_service_history.go index 8e80821..2366952 100644 --- a/models/module_service_history.go +++ b/models/module_service_history.go @@ -36,3 +36,8 @@ func (t *ModuleServiceHistory) GetByModuleIdAndName(id int64, name string) (bool func (t *ModuleServiceHistory) ExistSignModule(ids []interface{}) (bool, error) { return core.GetXormAuto().Where("is_delete=0 and name=?", "签到").In("id", ids...).Exist(t) } + +func GetModuleServiceHistoryIdsByIdAndName(obj, serviceId, serviceName interface{}) error { + return core.GetXormAuto().Table(new(ModuleServiceHistory)).Select("id"). + Where("is_delete=0 and service_module_id=? and name=?", serviceId, serviceName).Find(&obj) +} diff --git a/models/new_vote_activity.go b/models/new_vote_activity.go index 6ad36e5..7ea1533 100644 --- a/models/new_vote_activity.go +++ b/models/new_vote_activity.go @@ -62,3 +62,8 @@ func UpdateVoteStatusByActiviytId(aid int64) (int64, error) { return core.GetXormAuto().Where("is_delete=0 and activity_id=?", aid). Update(&NewVoteActivity{VoteStatus: define.StatusNotBegin}) } + +func GetVoteListByActivityId(obj, activityId interface{}) error { + return core.GetXormAuto().Where("is_delete=0 and activity_id=?", activityId). + Desc("created_at").Find(&obj) +} diff --git a/models/sign_history.go b/models/sign_history.go index d9b5d26..9ae6959 100644 --- a/models/sign_history.go +++ b/models/sign_history.go @@ -30,9 +30,10 @@ func (t *SignHistory) GetByUserId(aid, uid, rid, arid int64) (bool, error) { "rehearsal_id=? and area_id=?", aid, uid, rid, arid).Get(t) } -func (t *SignHistory) Count(id, aid, rid interface{}) (int64, error) { +func (t *SignHistory) Count(signUpId, activityId, rehearsalId interface{}) (int64, error) { // 签到人数 - return core.GetXormAuto().Where("is_delete=0 and sign_rule_id=? and rehearsal_id=? and activity_id=?", id, aid, rid).Count(t) + return core.GetXormAuto().Where("is_delete=0 and sign_rule_id=? and rehearsal_id=? and activity_id=?", + signUpId, rehearsalId, activityId).Count(t) } func GetLotteryUsersResultBySignHistory(obj, areaId, activityId, rehearsalId interface{}, ids []int64) error { diff --git a/models/upper_wall.go b/models/upper_wall.go index 19236f9..e35367e 100644 --- a/models/upper_wall.go +++ b/models/upper_wall.go @@ -1,6 +1,7 @@ package models import ( + "github.com/ouxuanserver/osmanthuswine/src/core" "time" ) @@ -15,9 +16,17 @@ type UpperWall struct { Content string `json:"content" xorm:"comment('内容') text" ` Img string `json:"img" xorm:"comment('图片') text" description:"图片"` Imgs []string `json:"imgs" xorm:"-" description:"图片数组"` - Status int `json:"status" xorm:"not null default(0) comment('0未审核,1未通过,2已通过,3已推送') INT(11)"` + Status int `json:"status" xorm:"not null default(0) comment('0未审核,1未通过,2已通过,3已推送') INT(11)"` ReviewTime int64 `json:"review_time" xorm:"not null default(0) comment('审核的时间,10位') INT(11)"` IsDelete bool `json:"is_delete" xorm:"default(0)" description:"是否删除"` CreatedAt time.Time `json:"created_at" xorm:"created" description:"创建时间"` UpdatedAt time.Time `json:"updated_at" xorm:"updated" description:"更新时间"` } + +func GetUpperWallResultByUserIdAndActivityId(obj, userId, activityId, rehearsalId interface{}) error { + return core.GetXormAuto().Table(new(UpperWall)). + Select("id, content, img, category, status"). + Where("is_delete=0 and user_id=? and activity_id=? and rehearsal_id=?", + userId, activityId, rehearsalId). + OrderBy("created_at desc").Find(&obj) +}