From ac18b7038e4bacc2063f7bd00ccda27a86075b05 Mon Sep 17 00:00:00 2001 From: tommy <3405129587@qq.com> Date: Wed, 20 May 2020 16:03:52 +0800 Subject: [PATCH] rm core --- controllers/base.go | 15 ++--------- controllers/client/auction.go | 13 +++++----- controllers/client/barrage.go | 6 ++--- controllers/client/bully_screen.go | 10 ++----- controllers/client/calorie.go | 26 ++----------------- controllers/client/good.go | 3 +-- controllers/client/invite_envelope.go | 5 ++-- controllers/client/login.go | 9 +++---- controllers/client/lottery.go | 49 +++++++++++------------------------ controllers/client/order_entry.go | 2 +- controllers/pc/auction.go | 4 +-- controllers/pc/upper_wall.go | 2 +- controllers/pc/vote.go | 4 +-- controllers/pc/ws.go | 2 +- models/CalorieUser.go | 12 +++++++++ models/auction_history.go | 5 ---- models/auction_result_record.go | 4 +++ models/base.go | 21 ++++++++++++--- models/lottery_draw_record.go | 14 ++++++++++ models/order_entry_person.go | 5 ++-- models/sign_history.go | 13 ++++++++++ models/user_prize.go | 8 ++++++ services/pay/handle.go | 2 +- 23 files changed, 116 insertions(+), 118 deletions(-) diff --git a/controllers/base.go b/controllers/base.go index 5b271ca..d9493b5 100644 --- a/controllers/base.go +++ b/controllers/base.go @@ -20,7 +20,6 @@ type BaseCtl struct { } func (t *BaseCtl) Prepare() { - //t.OriginResponseWriter.Header().Set("Access-Control-Allow-Origin", "*") t.OriginResponseWriter.Header().Set("Access-Control-Allow-Origin", "*") t.OriginResponseWriter.Header().Set("Access-Control-Allow-Credentials", "true") t.OriginResponseWriter.Header().Set("Access-Control-Allow-Methods", "*") @@ -43,8 +42,6 @@ func (t *BaseCtl) Prepare() { } } -type M map[string]interface{} - func (t *BaseCtl) Bind(obj interface{}) error { return t.RequestToStruct(obj) } @@ -199,15 +196,7 @@ func (t *BaseCtl) ERROR(errStr string, code int, data ...string) { t.DisplayByError(errStr, code, data...) } -func (t *BaseCtl) CheckInSuccess(str string) { - t.DisplayByError(str, 1) -} - func (t *BaseCtl) SUCCESS(str string) { - t.DisplayByError(str, 0) -} - -func (t *BaseCtl) STRING(str string) { t.Display(nil, str, 0) } @@ -223,9 +212,9 @@ func (t *BaseCtl) CheckErr(err error) { } // false -func (t *BaseCtl) Assert(b bool, errcode int, errmsg string) { +func (t *BaseCtl) Assert(b bool, code int, msg string) { if !b { - t.ERROR(errmsg, errcode) + t.ERROR(msg, code) } return } diff --git a/controllers/client/auction.go b/controllers/client/auction.go index a864dab..e228257 100644 --- a/controllers/client/auction.go +++ b/controllers/client/auction.go @@ -8,8 +8,6 @@ import ( ws_send_service "hudongzhuanjia/services/ws_send" "hudongzhuanjia/utils/code" "time" - - "github.com/ouxuanserver/osmanthuswine/src/core" ) type AuctionCtl struct { @@ -70,7 +68,7 @@ func (t *AuctionCtl) Auction() { history.IsDelete = false history.CreatedAt = time.Now() history.UpdatedAt = time.Now() - _, err = core.GetXormAuto().InsertOne(history) + _, err = models.Add(history) t.CheckErr(err) if auction.AuctionModel == "加价竞拍" { @@ -78,7 +76,8 @@ func (t *AuctionCtl) Auction() { exist, err := maxHistory.GetHighestMoney(activity.RehearsalId, auction.Id) t.CheckErr(err) if exist && (history.Money < maxHistory.Money || history.UserId != maxHistory.UserId) { - _, err = history.SoftDelete() + history.IsDelete = true + _, err = models.Update(history.Id, history, "is_delete") t.CheckErr(err) t.ERROR("加价失败, 价格低于当前最高价", code.MSG_ERR) return @@ -122,7 +121,7 @@ func (t *AuctionCtl) Auction() { record.UpdatedAt = time.Now() record.CreatedAt = time.Now() record.IsDelete = false - _, err = core.GetXormAuto().InsertOne(record) + _, err = models.Add(record) t.CheckErr(err) go ws_send_service.SendAuction(fmt.Sprintf("%d", activity.Id), @@ -140,7 +139,7 @@ func (t *AuctionCtl) Auction() { }) } // 加价 - t.STRING("加价成功") + t.SUCCESS("加价成功") } func (t *AuctionCtl) ExistRecord() { @@ -158,7 +157,7 @@ func (t *AuctionCtl) ExistRecord() { t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") record := new(models.AuctionResultRecord) - exist, err = core.GetXormAuto().Where("is_delete=0 and user_id=? and auction_activity_id=? and rehearsal_id=?", uid, auctionId, activity.RehearsalId).Get(record) + exist, err = record.GetByUserIdAndAuctionId(uid, auctionId, activity.RehearsalId) t.CheckErr(err) t.JSON(map[string]interface{}{ "show": exist, diff --git a/controllers/client/barrage.go b/controllers/client/barrage.go index 716153e..1d4857b 100644 --- a/controllers/client/barrage.go +++ b/controllers/client/barrage.go @@ -2,7 +2,6 @@ package client import ( "fmt" - "github.com/ouxuanserver/osmanthuswine/src/core" "hudongzhuanjia/controllers" "hudongzhuanjia/libs/filter" "hudongzhuanjia/models" @@ -42,13 +41,14 @@ func (t *BarrageCtl) Send() { t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在") //插入弹幕消息 - _, err = core.GetXormAuto().InsertOne(&models.BarrageHistory{ + history := models.BarrageHistory{ ActivityId: activityId, UserId: uid, Content: content, CreateAt: time.Now(), UpdateAt: time.Now(), - }) + } + _, err = models.Add(&history) t.CheckErr(err) customer := new(models.Customer) diff --git a/controllers/client/bully_screen.go b/controllers/client/bully_screen.go index d3c8ae5..bde67b4 100644 --- a/controllers/client/bully_screen.go +++ b/controllers/client/bully_screen.go @@ -8,8 +8,6 @@ import ( "hudongzhuanjia/services/pay" "hudongzhuanjia/utils/code" "time" - - "github.com/ouxuanserver/osmanthuswine/src/core" ) //霸屏 @@ -48,11 +46,7 @@ func (t *BullyScreenCtl) PaScreen() { t.CheckErr(err) t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在") - //扣除用户的金额 - // todo:微信直接付款 - // 调用微信统一下单接口 amount := bullyScreenServer.Price * second - var res = make(map[string]interface{}, 0) res["out_trade_no"] = "" if activity.RehearsalId == 0 { @@ -60,7 +54,7 @@ func (t *BullyScreenCtl) PaScreen() { t.CheckErr(err) } - history := &models.BullyScreenHistory{ + history := models.BullyScreenHistory{ OutTradeNo: res["out_trade_no"].(string), BullyScreenServerId: bullyScreenServer.Id, ActivityId: activityId, @@ -81,7 +75,7 @@ func (t *BullyScreenCtl) PaScreen() { if activity.RehearsalId != 0 { history.Status = 0 } - _, err = core.GetXormAuto().InsertOne(history) + _, err = models.Add(&history) t.CheckErr(err) t.JSON(res) } diff --git a/controllers/client/calorie.go b/controllers/client/calorie.go index e337b9e..276af47 100644 --- a/controllers/client/calorie.go +++ b/controllers/client/calorie.go @@ -1,7 +1,6 @@ package client import ( - "github.com/ouxuanserver/osmanthuswine/src/core" "hudongzhuanjia/controllers" "hudongzhuanjia/models" "hudongzhuanjia/utils/code" @@ -41,12 +40,10 @@ func (t *CalorieCtl) Shake() { calorieUser.Score += int64(score) // 增加 } - count, err := core.GetXormAuto().Where("is_delete=0 and calorie_id=? and rehearsal_id=?", calorie.Id, activity.RehearsalId).Count(new(models.CalorieUser)) + count, err := calorieUser.CountByCalorieId(calorie.Id, activity.RehearsalId) t.CheckErr(err) - users := make([]*models.CalorieUser, 0) - err = core.GetXormAuto().Where("is_delete=0 and calorie_id=? and rehearsal_id=? and score<=?", - calorie.Id, activity.RehearsalId, calorieUser.Score).Desc("score").Asc("join_time").Find(&users) + users, err := models.GetCalorieUsersByCalorieIdAndScore(calorie.Id, activity.RehearsalId, calorieUser.Score) t.CheckErr(err) var rank int @@ -57,27 +54,8 @@ func (t *CalorieCtl) Shake() { } } - // 活动时长 - //duration := calorie.GameDuration - (time.Now().Unix() - calorie.StartTime) + 6 // 加上倒计时的6s - //if calorie.StartTime == 0 { - // duration = calorie.GameDuration - //} - // 3s 倒计时 - //var countDown float64 = 0 - //if duration-calorie.GameDuration > 0 { - // countDown = math.Ceil(float64(duration-calorie.GameDuration) / 2.0) - //} - - //// 活动结束 - //if calorie.Status == define.StatusEnding || duration <= 0 { - // duration = 0 - //} - t.JSON(map[string]interface{}{ "rank": rank, "score": calorieUser.Score, // 分数 - //"time": duration - 2*int64(countDown), //时长 - //"count_down": countDown, // 倒计时 - //"status": calorie.Status, // 状态 }) } diff --git a/controllers/client/good.go b/controllers/client/good.go index dfc6bfe..1f9ff27 100644 --- a/controllers/client/good.go +++ b/controllers/client/good.go @@ -28,7 +28,6 @@ func (t *GoodCtl) GoodDetail() { func (t *GoodCtl) GoodOption() { activityId := t.MustGetInt64("activity_id") - //areaId := t.MustGetInt64("area_id") option := new(models.CustomerOrderOption) exist, err := option.GetByActivityId(activityId) @@ -37,7 +36,6 @@ func (t *GoodCtl) GoodOption() { t.JSON([]interface{}{}) return } - //t.Assert(exist, code.MSG_ORDER_NOT_EXIST, "订单活动不存在") t.JSON(option) } @@ -94,6 +92,7 @@ func (t *GoodCtl) ListOrder() { for _, order := range orders { orderNos = append(orderNos, order.OrderNo) } + subs, err := models.GetCustomerOrderSubsByOrderNos(orderNos...) t.CheckErr(err) for index, order := range orders { diff --git a/controllers/client/invite_envelope.go b/controllers/client/invite_envelope.go index 8c4b96b..9d9ebcc 100644 --- a/controllers/client/invite_envelope.go +++ b/controllers/client/invite_envelope.go @@ -1,7 +1,6 @@ package client import ( - "github.com/ouxuanserver/osmanthuswine/src/core" "hudongzhuanjia/controllers" "hudongzhuanjia/models" "hudongzhuanjia/utils/code" @@ -36,10 +35,10 @@ func (t *InvitationLetterCtl) Invite() { letter.IsDelete = false letter.CreatedAt = time.Now() letter.UpdatedAt = time.Now() - _, err = core.GetXormAuto().InsertOne(letter) + _, err = models.Add(letter) t.CheckErr(err) - t.STRING("success") + t.SUCCESS("success") } func (t *InvitationLetterCtl) Setting() { diff --git a/controllers/client/login.go b/controllers/client/login.go index b4c655d..1e6548f 100644 --- a/controllers/client/login.go +++ b/controllers/client/login.go @@ -12,8 +12,6 @@ import ( "hudongzhuanjia/utils/code" "hudongzhuanjia/utils/define" "time" - - "github.com/ouxuanserver/osmanthuswine/src/core" ) //用户 @@ -28,8 +26,7 @@ func (t *UserCtl) EntryLogin() { activityId := t.MustGetInt64("activity_id") // 需要获取 entryPeople := new(models.OrderEntryPerson) - exist, err := core.GetXormAuto().Where("is_delete=0 and account = ? and password = ? and activity_id = ?", - account, password, activityId).Get(entryPeople) + exist, err := entryPeople.Auth(account, password, activityId) t.CheckErr(err) t.Assert(exist, code.MSG_ENTRYPEOPLE_NOT_EXIST, "录入人员不存在") @@ -113,7 +110,7 @@ func (t *UserCtl) WxLogin() { user.CreatedAt = time.Now() user.UpdatedAt = time.Now() if !exist { - _, err = core.GetXormAuto().Insert(user) + _, err = models.Add(user) } else { _, err = user.SaveUserInfo(user.Id) } @@ -162,7 +159,7 @@ func (t *UserCtl) Login() { exist, err := user.GetUserByOpenid(user.Openid) t.CheckErr(err) if !exist { - _, err = core.GetXormAuto().Insert(user) + _, err = models.Add(user) t.CheckErr(err) } diff --git a/controllers/client/lottery.go b/controllers/client/lottery.go index 1712347..1c74a20 100644 --- a/controllers/client/lottery.go +++ b/controllers/client/lottery.go @@ -1,7 +1,6 @@ package client import ( - "github.com/ouxuanserver/osmanthuswine/src/core" "hudongzhuanjia/controllers" "hudongzhuanjia/models" activity_service "hudongzhuanjia/services/activity" @@ -14,16 +13,20 @@ type LotteryCtl struct { } func (t *LotteryCtl) UserLotteries() { - uid := t.MustGetUID() + userId := t.MustGetUID() + activityId := t.MustGetInt64("activity_id") - userPrizes := make([]*models.UserPrize, 0) - err := core.GetXormAuto().Where("is_delete=0 and user_id=? ", uid). - Desc("created_at").Find(&userPrizes) + activity := new(models.Activity) + exist, err := models.Get(activity, activityId) + t.CheckErr(err) + t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") + + prizes, err := models.GetUserPrizesByUserIdAndActivityId(userId, activityId, activity.RehearsalId) t.CheckErr(err) t.JSON(map[string]interface{}{ - "list": userPrizes, - "total": len(userPrizes), + "list": prizes, + "total": len(prizes), }) } @@ -67,7 +70,6 @@ func (t *LotteryCtl) CheckLottery() { record := new(models.LotteryDrawRecord) exist, err = record.GetByUserIdAndLadderId(uid, ladderId) t.CheckErr(err) - //t.Assert(exist, code.MSG_LOTTERY_DRAW_NOT_HIT, "没有中奖") t.JSON(map[string]interface{}{ "record": record, "ladder": ladder, @@ -75,14 +77,6 @@ func (t *LotteryCtl) CheckLottery() { }) } -//type WinnersResult struct { -// UserId int64 `json:"user_id"` -// UserName string `json:"user_name"` -// UserPhone string `json:"user_phone"` -// Avatar string `json:"avatar"` -// PrizeName string `json:"prize_name"` -//} - //获取中奖名单 func (t *LotteryCtl) Winners() { activityId := t.MustGetInt64("activity_id") @@ -99,11 +93,7 @@ func (t *LotteryCtl) Winners() { t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在") result := make([]*LotteryUsersResult, 0) - err = core.GetXormAuto().Table(new(models.LotteryDrawRecord)).Alias("record"). - Join("LEFT", new(models.User).Alias("user"), "user.id=record.user_id and user.is_delete=0"). - Where("record.is_delete=0 and record.lottery_draw_rule_ladder_id=? and record.rehearsal_id=?", ladderId, - activity.RehearsalId). - Find(&result) + err = models.GetLotteryUsersResultByLotteryDrawRecord(result, ladderId, activity.RehearsalId) t.CheckErr(err) t.JSON(map[string]interface{}{ "total": len(result), @@ -134,28 +124,19 @@ func (t *LotteryCtl) Users() { t.CheckErr(err) t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在") - result := make([]*LotteryUsersResult, 0) - session := core.GetXormAuto().Table(new(models.SignHistory)).Alias("h"). - Select("h.user_id, u.nickname as username, u.avatar").Distinct("h.user_id"). - Join("LEFT", new(models.User).Alias("u"), "h.user_id=u.id and u.is_delete = 0"). - Where("h.is_delete=0 and h.area_id=? and h.activity_id=? and h.rehearsal_id=?", - areaId, activityId, activity.RehearsalId) - moduleService, exist, err := activity_service.GetModuleService(define.MODULE_LOTTERY, activityId) t.CheckErr(err) t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "活动模块不存在") + recordIds := make([]int64, 0) if moduleService.BesideRepeat == define.MODULE_BESIDE_REPEAT { // 去重标志 - recordIds := make([]int64, 0) - err = core.GetXormAuto().Table(new(models.LotteryDrawRecord)).Select("user_id"). - Where("lottery_draw_rule_id=? and rehearsal_id=? and area_id=? and is_delete=0", - ladder.LotteryDrawRuleId, activity.RehearsalId, areaId).Find(&recordIds) + err = models.GetUserIdsByLotteryDrawRuleId(recordIds, ladder.LotteryDrawRuleId, activity.RehearsalId, areaId) t.CheckErr(err) - session = session.NotIn("h.user_id", recordIds) } - err = session.Find(&result) + result := make([]*LotteryUsersResult, 0) + err = models.GetLotteryUsersResultBySignHistory(result, areaId, activity.Id, activity.RehearsalId, recordIds) t.CheckErr(err) t.JSON(map[string]interface{}{ diff --git a/controllers/client/order_entry.go b/controllers/client/order_entry.go index b514f82..8cc970e 100644 --- a/controllers/client/order_entry.go +++ b/controllers/client/order_entry.go @@ -171,7 +171,7 @@ func (t *OrderEntryCtl) EntryOrders() { activityId := t.MustGetInt64("activity_id") entry := new(models.OrderEntryPerson) - exist, err := entry.GetById(uid) + exist, err := models.Get(entry, uid) t.CheckErr(err) t.Assert(exist, code.MSG_ENTRYPEOPLE_NOT_EXIST, "录入人员不存在") diff --git a/controllers/pc/auction.go b/controllers/pc/auction.go index 6170d9a..f7c9698 100644 --- a/controllers/pc/auction.go +++ b/controllers/pc/auction.go @@ -55,7 +55,7 @@ func (t *AuctionCtl) StartAuction() { Cols("status", "auction_end_time", "updated_at").Update(auction) t.CheckErr(err) - t.STRING("操作成功") + t.SUCCESS("操作成功") } func (t *AuctionCtl) StopAuction() { @@ -139,7 +139,7 @@ func (t *AuctionCtl) StopAuction() { }) } - t.STRING("操作成功") + t.SUCCESS("操作成功") } // 增加数据 diff --git a/controllers/pc/upper_wall.go b/controllers/pc/upper_wall.go index ce6dbc7..9117485 100644 --- a/controllers/pc/upper_wall.go +++ b/controllers/pc/upper_wall.go @@ -112,7 +112,7 @@ func (t *UpperWallCtl) Review() { "total": len(result)}, }) } - t.STRING("审核成功") + t.SUCCESS("审核成功") } //获取黑名单列表 diff --git a/controllers/pc/vote.go b/controllers/pc/vote.go index b2d9cf3..14f6ea4 100644 --- a/controllers/pc/vote.go +++ b/controllers/pc/vote.go @@ -93,7 +93,7 @@ func (t *VoteCtl) StartVote() { _, err = core.GetXormAuto().Where("is_delete=0 and id=?", voteId). Cols("vote_status", "vote_end_time", "updated_at").Update(vote) t.CheckErr(err) - t.STRING("操作成功") + t.SUCCESS("操作成功") } //停止投票 @@ -116,7 +116,7 @@ func (t *VoteCtl) StopVote() { Cols("vote_status", "updated_at", "vote_end_time").Update(vote) t.CheckErr(err) - t.STRING("操作成功") + t.SUCCESS("操作成功") } //获取参与人数 diff --git a/controllers/pc/ws.go b/controllers/pc/ws.go index 70f0b2c..41135a7 100644 --- a/controllers/pc/ws.go +++ b/controllers/pc/ws.go @@ -59,5 +59,5 @@ func (t *WsCtl) SaveOp() { logger.Error("save customer_operation出现错误") t.ERROR("customer operation格式错误", code.MSG_ERR) } - t.STRING("success") + t.SUCCESS("success") } diff --git a/models/CalorieUser.go b/models/CalorieUser.go index d5fc068..cc84ced 100644 --- a/models/CalorieUser.go +++ b/models/CalorieUser.go @@ -34,3 +34,15 @@ func (t *CalorieUser) IncrScore(score int) (int64, error) { t.JoinTime = time.Now().UnixNano() return core.GetXormAuto().Where("is_delete=0 and id=?", t.Id).Cols("score", "join_time").Incr("score", score).Update(t) } + +func (t *CalorieUser) CountByCalorieId(calorieId, rehearsalId interface{}) (int64, error) { + return core.GetXormAuto().Where("is_delete=0 and calorie_id=? and rehearsal_id=?", + calorieId, rehearsalId).Count(t) +} + +func GetCalorieUsersByCalorieIdAndScore(calorieId, rehearsalId, score interface{}) ([]*CalorieUser, error) { + users := make([]*CalorieUser, 0) + err := core.GetXormAuto().Where("is_delete=0 and calorie_id=? and rehearsal_id=? and score<=?", + calorieId, rehearsalId, score).Desc("score").Asc("join_time").Find(&users) + return users, err +} diff --git a/models/auction_history.go b/models/auction_history.go index 9199d1a..3b219fc 100644 --- a/models/auction_history.go +++ b/models/auction_history.go @@ -56,8 +56,3 @@ func GetAuctionHistoriesByAuctionIds(ids []int64, rid int64, orderBy string) ([] In("auction_activity_id", ids).OrderBy(orderBy).Find(&histories) return histories, err } - -func (t *AuctionHistory) SoftDelete() (int64, error) { - t.IsDelete = true - return core.GetXormAuto().ID(t.Id).Cols("is_delete").Update(t) -} diff --git a/models/auction_result_record.go b/models/auction_result_record.go index 69dec79..c09a214 100644 --- a/models/auction_result_record.go +++ b/models/auction_result_record.go @@ -40,3 +40,7 @@ func GetAuctionRecordsByAuctionId(id, rid int64, orderBy string) ([]*AuctionResu OrderBy(orderBy).Find(&records) return records, err } + +func (t *AuctionResultRecord) GetByUserIdAndAuctionId(userId, auctionId, rehearsalId interface{}) (bool, error) { + return core.GetXormAuto().Where("is_delete=0 and user_id=? and auction_activity_id=? and rehearsal_id=?", userId, auctionId, rehearsalId).Get(t) +} diff --git a/models/base.go b/models/base.go index 1a05cfd..e3ce636 100644 --- a/models/base.go +++ b/models/base.go @@ -147,10 +147,25 @@ func Add(bean interface{}) (int64, error) { return core.GetXormAuto().InsertOne(bean) } -func Update(bean interface{}, field ...string) (int64, error) { +func Update(id, bean interface{}, field ...string) (int64, error) { if len(field) > 0 { - return core.GetXormAuto().Cols(field...).Update(bean) + return core.GetXormAuto().ID(id).Cols(field...).Update(bean) } else { - return core.GetXormAuto().Update(bean) + return core.GetXormAuto().ID(id).Update(bean) } } + +func Commit(f func(s *xorm.Session) error) error { + session := core.GetXormAuto().NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + return err + } + err = f(session) + if err != nil { + session.Rollback() + return err + } + return session.Commit() +} diff --git a/models/lottery_draw_record.go b/models/lottery_draw_record.go index f8f9cfc..6674cec 100644 --- a/models/lottery_draw_record.go +++ b/models/lottery_draw_record.go @@ -49,3 +49,17 @@ func (t *LotteryDrawRecord) Update(id interface{}, field ...string) (int64, erro t.Id = 0 return core.GetXormAuto().Where("id=?", id).Update(t) } + +func GetLotteryUsersResultByLotteryDrawRecord(obj, ladderId, rehearsalId interface{}) error { + err := 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 +} + +func GetUserIdsByLotteryDrawRuleId(obj, ruleId, rehearsalId, areaId interface{}) error { + return core.GetXormAuto().Table(new(LotteryDrawRecord)).Select("user_id"). + Where("lottery_draw_rule_id=? and rehearsal_id=? and area_id=? and is_delete=0", + ruleId, rehearsalId, areaId).Find(&obj) +} diff --git a/models/order_entry_person.go b/models/order_entry_person.go index 3d0dd4c..7b94371 100644 --- a/models/order_entry_person.go +++ b/models/order_entry_person.go @@ -27,6 +27,7 @@ func (t *OrderEntryPerson) TableName() string { return OrderEntryPersonTableName } -func (t *OrderEntryPerson) GetById(id interface{}) (bool, error) { - return core.GetXormAuto().Where("is_delete=0 and id=?", id).Get(t) +func (t *OrderEntryPerson) Auth(account, password, activityId interface{}) (bool, error) { + return core.GetXormAuto().Where("is_delete=0 and account = ? and password = ? and activity_id = ?", + account, password, activityId).Get(t) } diff --git a/models/sign_history.go b/models/sign_history.go index f7b0aeb..d9b5d26 100644 --- a/models/sign_history.go +++ b/models/sign_history.go @@ -34,3 +34,16 @@ func (t *SignHistory) Count(id, aid, rid 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) } + +func GetLotteryUsersResultBySignHistory(obj, areaId, activityId, rehearsalId interface{}, ids []int64) error { + session := core.GetXormAuto().Table(new(SignHistory)).Alias("h"). + Select("h.user_id, u.nickname as username, u.avatar").Distinct("h.user_id"). + Join("LEFT", new(User).Alias("u"), "h.user_id=u.id and u.is_delete = 0"). + Where("h.is_delete=0 and h.area_id=? and h.activity_id=? and h.rehearsal_id=?", + areaId, activityId, rehearsalId) + defer session.Close() + if len(ids) > 0 { + session = session.NotIn("h.user_id", ids) + } + return session.Find(&obj) +} diff --git a/models/user_prize.go b/models/user_prize.go index 1d67c94..12caefc 100644 --- a/models/user_prize.go +++ b/models/user_prize.go @@ -39,3 +39,11 @@ func (t *UserPrize) Update(fields ...string) error { _, err := core.GetXormAuto().Where("is_delete=0 and id = ? and user_id =?", t.Id, t.UserId).Cols(fields...).Update(t) return err } + +func GetUserPrizesByUserIdAndActivityId(userId, activityId, rehearsalId interface{}) ([]*UserPrize, error) { + prizes := make([]*UserPrize, 0) + err := core.GetXormAuto().Where("is_delete=0 and user_id=? and activity_id=? and rehearsal_id=?", + userId, activityId, rehearsalId). + Desc("created_at").Find(&prizes) + return prizes, err +} diff --git a/services/pay/handle.go b/services/pay/handle.go index 078cbdf..33a4d00 100644 --- a/services/pay/handle.go +++ b/services/pay/handle.go @@ -96,7 +96,7 @@ func HandleSuccess(param *OrderDelayQueueParam) error { } customerOrder.UserPrizeId = prize.Id - _, err = models.Update(customerOrder, "user_prize_id") + _, err = models.Update(customerOrder.Id, customerOrder, "user_prize_id") if err != nil { err = fmt.Errorf("奖品记录添加失败: err-> %v, out_trade_no-> %v, prize_id->%v", err, param.Order.OutTradeNo, prize.Id) logger.Error(err)