Browse Source

lottery

master
黄梓健 5 years ago
parent
commit
bfb4011ef4
  1. 7
      controllers/base.go
  2. 57
      controllers/client/lottery.go
  3. 4
      controllers/pc/bully_screen.go
  4. 6
      controllers/pc/login.go
  5. 2
      controllers/pc/lottery_draw.go
  6. 2
      controllers/pc/order_draw.go
  7. 6
      controllers/pc/reward.go
  8. 2
      controllers/pc/sign.go
  9. 4
      controllers/pc/vote.go
  10. 14
      models/lottery_draw_record.go
  11. 5
      models/user_prize.go
  12. 1
      utils/code/code.go

7
controllers/base.go

@ -189,10 +189,6 @@ func (t *BaseCtl) DefaultFloat(key string, def float32) float32 {
return def
}
func (t *BaseCtl) JSON(m interface{}) {
t.DisplayByData(m)
}
func (t BaseCtl) XML(data []byte) {
t.OriginResponseWriter.Header().Add("Content-Type", "application/xml; charset=utf-8")
t.OriginResponseWriter.Write(data)
@ -214,7 +210,8 @@ func (t *BaseCtl) SUCCESS(str string) {
func (t *BaseCtl) STRING(str string) {
t.Display(nil, str, 0)
}
func (t *BaseCtl) RAW(data interface{}) {
func (t *BaseCtl) JSON(data interface{}) {
t.DisplayByData(data)
}

57
controllers/client/lottery.go

@ -27,22 +27,22 @@ func (t *LotteryCtl) UserLotteries() {
}
func (t *LotteryCtl) CashLottery() {
uid := t.MustGetUID()
prizeId := t.MustGetInt64("prize_id")
name := t.MustGet("name")
phone := t.MustGet("phone")
wxNo := t.MustGet("wx_no")
address := t.MustGet("address")
prize := new(models.UserPrize)
prize.Id = prizeId
prize.UserId = uid
prize.Name = name
prize.Phone = phone
prize.WxNo = wxNo
prize.Address = address
prize.Status = 1
err := prize.Update("name", "phone", "wx_no", "address", "status")
record := new(models.LotteryDrawRecord)
exist, err := record.GetByUserPrizeId(prizeId)
t.CheckErr(err)
t.Assert(exist, code.MSG_LOTTERY_DRAW_RECORD_NOT_EXIST, "中奖记录不存在")
record.Name = name
record.Phone = phone
record.WxNo = wxNo
record.Address = address
record.Status = 1
_, err = record.Update(record.Id, "name", "phone", "wx_no", "address", "status")
t.CheckErr(err)
t.SUCCESS("兑奖成功")
}
@ -51,20 +51,28 @@ func (t *LotteryCtl) CheckLottery() {
uid := t.MustGetUID()
ladderId := t.MustGetInt64("lottery_draw_ladder_id")
ladder := new(models.LotteryDrawRuleLadder)
exist, err := models.GetById(ladder, ladderId)
t.CheckErr(err)
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)
t.CheckErr(err)
t.Assert(exist, code.MSG_LOTTERY_DRAW_NOT_HIT, "没有中奖")
t.JSON(record)
t.JSON(map[string]interface{}{
"record": record,
"ladder": ladder,
})
}
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"`
}
//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() {
@ -81,16 +89,17 @@ func (t *LotteryCtl) Winners() {
t.CheckErr(err)
t.Assert(exist, code.MSG_LOTTERY_RULE_NOT_EXIST, "抽奖规则不存在")
result := make([]*WinnersResult, 0)
err = core.GetXormAuto().Table("ox_lottery_draw_record").Alias("record").
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_id=? and record.rehearsal_id=?", ladder.LotteryDrawRuleId,
Where("record.is_delete=0 and record.lottery_draw_rule_ladder_id=? and record.rehearsal_id=?", ladderId,
activity.RehearsalId).
Find(&result)
t.CheckErr(err)
t.JSON(map[string]interface{}{
"total": len(result),
"list": result,
"total": len(result),
"ladder": ladder,
"list": result,
})
}

4
controllers/pc/bully_screen.go

@ -178,7 +178,7 @@ func (t *BullyScreenCtl) Latest() {
result, err := bully_reward_service.GetBullyScreenLatest(bullyScreenServer.Id, activity.RehearsalId)
t.CheckErr(err)
if result == nil || result.Id == 0 {
t.RAW(result)
t.JSON(result)
}
//根据主活动得id获取所有得模块列表
@ -199,7 +199,7 @@ func (t *BullyScreenCtl) Latest() {
t.CheckErr(models.Save(map[string]interface{}{
"id =": result.BullyScreenHistory.Id,
}, &result.BullyScreenHistory, "status", "updated_at"))
t.RAW(result)
t.JSON(result)
}
// 霸屏服务器开关

6
controllers/pc/login.go

@ -48,7 +48,7 @@ func (t *UserCtl) Login() {
pid = customer.Id
}
customer.Tag = "activity"
t.RAW(customer)
t.JSON(customer)
}
//检查是否已经登陆
@ -102,7 +102,7 @@ func (t *UserCtl) WXLogin() {
activities, err := activity_service.GetActivitiesByCustomerId(customer.Id)
t.CheckErr(err)
customer.Activities = activities
t.RAW(customer)
t.JSON(customer)
}
// 手机验证码登陆
@ -122,7 +122,7 @@ func (t *UserCtl) QQLogin() {
activities, err := activity_service.GetActivitiesByCustomerId(customer.Id)
t.CheckErr(err)
customer.Activities = activities
t.RAW(customer)
t.JSON(customer)
}
func (t *UserCtl) QQCodeUrl() {

2
controllers/pc/lottery_draw.go

@ -463,7 +463,7 @@ func (t *LotteryDrawCtl) Lottery() {
"desc": "抽奖结果",
})
t.RAW(winners)
t.JSON(winners)
}
type WinnersResult struct {

2
controllers/pc/order_draw.go

@ -388,7 +388,7 @@ func (t *OrderDrawCtl) Draw() {
_, err = core.GetXormAuto().InsertOne(record)
t.CheckErr(err)
}
t.RAW(winners)
t.JSON(winners)
}
type WinnerResult struct {

6
controllers/pc/reward.go

@ -33,7 +33,7 @@ func (t *RewardCtl) Latest() {
result, err := bully_reward_service.GetRewardLatest(server.Id, rehearsalId)
t.CheckErr(err)
if result == nil || result.Id == 0 {
t.RAW(result)
t.JSON(result)
}
result.User.Openid = ""
@ -45,7 +45,7 @@ func (t *RewardCtl) Latest() {
Status: 3,
UpdatedAt: time.Now(),
}, "status", "update_at"))
t.RAW(result)
t.JSON(result)
}
//获取待审核列表
@ -149,7 +149,7 @@ func (t *RewardCtl) Review() {
}
}
// 发送审核的信息
t.RAW("审核成功")
t.JSON("审核成功")
}
//获取打赏得总金额

2
controllers/pc/sign.go

@ -46,7 +46,7 @@ func (t *SignCtl) Mode() {
t.CheckErr(err)
t.Assert(exist, code.MSG_SIGN_UP_NOT_EXIST, "签到规则不存在")
t.RAW(signUp.MaxModel)
t.JSON(signUp.MaxModel)
}
func (t *SignCtl) List() {

4
controllers/pc/vote.go

@ -116,7 +116,7 @@ func (t *VoteCtl) JoinTotal() {
total, err := core.GetXormAuto().Distinct("user_id").Where("vote_activity_id=? and rehearsal_id=? and is_delete=0",
voteActivityId, rehearsalId).Count(new(models.NewVoteActivityHistory))
t.CheckErr(err)
t.RAW(total)
t.JSON(total)
}
//获取所有的投票活动
@ -160,5 +160,5 @@ func (t *VoteCtl) History() {
err := core.GetXormAuto().Where("is_delete=0 and vote_activity_id=?", voteActivityId).
Desc("total_number").Asc("updated_at").Limit(total).Find(&ladders)
t.CheckErr(err)
t.RAW(ladders)
t.JSON(ladders)
}

14
models/lottery_draw_record.go

@ -23,6 +23,11 @@ type LotteryDrawRecord struct {
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"`
@ -35,3 +40,12 @@ func (t *LotteryDrawRecord) TableName() string {
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) GetByUserPrizeId(upId int64) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and user_prize_id=?", upId).Get(t)
}
func (t *LotteryDrawRecord) Update(id interface{}, field ...string) (int64, error) {
t.Id = 0
return core.GetXormAuto().Where("id=?", id).Update(t)
}

5
models/user_prize.go

@ -16,11 +16,6 @@ type UserPrize struct {
PrizeName string `json:"prize_name" xorm:"not null default('') comment('奖品名字') VARCHAR(128)"`
PrizeImg string `json:"prize_img" xorm:"not null default('') comment('奖品图片') VARCHAR(255)"`
PrizeType int `json:"prize_type" xorm:"not null default(0) comment('订单来源1普通抽奖2订单抽奖3订单送礼4直播下单') INT(11)"`
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:"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"`

1
utils/code/code.go

@ -35,6 +35,7 @@ const (
MSG_CUSTOMER_ORDER_SEND = 4009 // 订单已发货
MSG_LOTTERY_DRAW_NOT_HIT = 4010 // 没有抽中奖
MSG_LOTTERY_DRAW_LADDER_NOT_EXIST = 4011 // 中奖阶梯规则不存在
MSG_LOTTERY_DRAW_RECORD_NOT_EXIST = 4012 // 中奖记录不存在
MSG_ORDER_NOT_EXIST = 5000 // 订单活动不存在
MSG_CUSTOMER_ORDER_ERROR = 5001 // 订单已完成
MSG_SIGN_UP_NOT_EXIST = 5000 // 签到规则不存在

Loading…
Cancel
Save