You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.7 KiB
60 lines
1.7 KiB
package call |
|
|
|
import ( |
|
"github.com/liangdas/mqant/log" |
|
"server/common" |
|
"server/db" |
|
"time" |
|
) |
|
|
|
func SetLuckyWheelRecords(uid int, luckType int, award *common.LuckyAward) { |
|
userInfo, _ := GetUserInfo(uid) |
|
err := db.Mysql().C().Model(&common.LuckyWheelReward{}).Create(&common.LuckyWheelReward{ |
|
UID: uid, |
|
Nick: userInfo.Nick, |
|
LuckyType: luckType, |
|
AwardType: award.AwardType, |
|
AwardCount: int(award.Currency.Value), |
|
SpeAwardType: award.WheelType, |
|
SpeAwardCount: award.WheelCount, |
|
UpdatedAt: time.Now().Unix(), |
|
}).Error |
|
if err != nil { |
|
log.Error("create luckyWheel record err, %s", err.Error()) |
|
} |
|
} |
|
|
|
func GetLuckWheelRecords(uid, withoutUid, page, pageSize int) ( |
|
records []common.LuckyWheelReward, total, totalAmount int64, err error) { |
|
mdb := db.Mysql().C().Model(&common.LuckyWheelReward{}) |
|
if uid == 0 { // 查询全部 |
|
mdb = mdb.Where("uid != ?", withoutUid).Order("updated_at desc").Limit(10) |
|
err = mdb.Find(&records).Error |
|
if err != nil { |
|
log.Error("get luckyWheel records err, %s", err.Error()) |
|
return |
|
} |
|
} else { // 查询个人 |
|
mdb = mdb.Where("uid = ?", uid) |
|
mdb = mdb.Order("updated_at desc") |
|
err = mdb.Count(&total).Error |
|
if err != nil { |
|
log.Error("get luckyWheel reward count err, %s", err.Error()) |
|
return |
|
} |
|
if page != 0 && pageSize != 0 { |
|
mdb = mdb.Offset((page - 1) * pageSize).Limit(pageSize) |
|
} |
|
err = mdb.Find(&records).Error |
|
if err != nil { |
|
log.Error("get luckyWheel records err, %s", err.Error()) |
|
return |
|
} |
|
err = mdb.Select("COALESCE(SUM(award_count), 0) as totalAmount").Scan(&totalAmount).Error |
|
if err != nil { |
|
log.Error("get luckyWheel totalAmount err, %s", err.Error()) |
|
return |
|
} |
|
} |
|
return |
|
}
|
|
|