From 21dd4a5a38d5a0a3da1b4f04ccfdd720fa09b220 Mon Sep 17 00:00:00 2001 From: tommy <3405129587@qq.com> Date: Thu, 14 May 2020 14:47:07 +0800 Subject: [PATCH] cash_lottery --- controllers/client/lottery.go | 21 +++++++++++++++++++++ models/user_prize.go | 10 ++++++++++ 2 files changed, 31 insertions(+) diff --git a/controllers/client/lottery.go b/controllers/client/lottery.go index d810138..c6a9650 100644 --- a/controllers/client/lottery.go +++ b/controllers/client/lottery.go @@ -22,3 +22,24 @@ func (t *LotteryCtl) UserLotteries() { "total": len(userPrizes), }) } + +func (t *LotteryCtl) CashLotteries() { + 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") + t.CheckErr(err) + t.SUCCESS("兑奖成功") +} diff --git a/models/user_prize.go b/models/user_prize.go index efa9d0d..22b4702 100644 --- a/models/user_prize.go +++ b/models/user_prize.go @@ -16,6 +16,11 @@ 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"` @@ -33,3 +38,8 @@ func (t *UserPrize) SoftDeleteById(id int64) (int64, error) { func (t *UserPrize) Add() (int64, error) { return core.GetXormAuto().InsertOne(t) } + +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 +}