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.
50 lines
1.2 KiB
50 lines
1.2 KiB
|
3 months ago
|
package call
|
||
|
|
|
||
|
|
import (
|
||
|
|
"github.com/liangdas/mqant/log"
|
||
|
|
"server/common"
|
||
|
|
"server/db"
|
||
|
|
"time"
|
||
|
|
)
|
||
|
|
|
||
|
|
func GetPddData(uid int) (result *common.PddDataNew, err error) {
|
||
|
|
pdd := GetConfigPdd()
|
||
|
|
err = db.Mysql().C().Model(&common.PddDataNew{}).Where("uid = ?", uid).Find(&result).Error
|
||
|
|
if err != nil {
|
||
|
|
log.Error("get pdd data err, %s", err.Error())
|
||
|
|
return
|
||
|
|
}
|
||
|
|
now := time.Now()
|
||
|
|
if result.ID == 0 {
|
||
|
|
result = &common.PddDataNew{
|
||
|
|
UID: uid,
|
||
|
|
Time: now.Unix(),
|
||
|
|
Spin: pdd.FreeCount,
|
||
|
|
ExpiredAt: now.AddDate(0, 0, pdd.Cycle).Unix(),
|
||
|
|
FreeSpinAt: now.Unix(),
|
||
|
|
}
|
||
|
|
err = db.Mysql().C().Model(&common.PddDataNew{}).Create(result).Error
|
||
|
|
if err != nil {
|
||
|
|
log.Error("create pdd data err, %s", err.Error())
|
||
|
|
return
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
if result.ExpiredAt < now.Unix() { // 重置
|
||
|
|
updatesValue := map[string]interface{}{
|
||
|
|
"amount": "",
|
||
|
|
"spin": pdd.FreeCount,
|
||
|
|
"expired_at": now.AddDate(0, 0, pdd.Cycle).Unix(),
|
||
|
|
"inviter_amount": 0,
|
||
|
|
"free_spin_at": now.Unix(),
|
||
|
|
}
|
||
|
|
err = db.Mysql().C().Model(&common.PddDataNew{}).Where("id = ?", result.ID).
|
||
|
|
Updates(updatesValue).Error
|
||
|
|
if err != nil {
|
||
|
|
log.Error("update pdd data err, %s", err.Error())
|
||
|
|
return
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return
|
||
|
|
}
|