|
|
|
|
package call
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"server/common"
|
|
|
|
|
"server/config"
|
|
|
|
|
"server/db"
|
|
|
|
|
"server/pb"
|
|
|
|
|
"server/util"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/liangdas/mqant/log"
|
|
|
|
|
"github.com/olivere/elastic/v7"
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func IsActivityValid(actID int) bool {
|
|
|
|
|
act := GetConfigActivityByID(actID)
|
|
|
|
|
if act == nil {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
return act.IsValid()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NotifyActivityItem 通知客户端获得活动物品
|
|
|
|
|
func NotifyActivityItem(uid, activityID int, items []*pb.ActivityItem) {
|
|
|
|
|
activityNotify := &pb.ActivityResp{
|
|
|
|
|
ActivityID: int64(activityID),
|
|
|
|
|
ActivityItems: items,
|
|
|
|
|
}
|
|
|
|
|
SendNR(uid, int(pb.ServerCommonResp_CommonActivityItemResp), activityNotify, "common")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetAcitivityPddData(uid int) *common.PddData {
|
|
|
|
|
pddData := &common.PddData{UID: uid}
|
|
|
|
|
db.Mysql().Get(pddData)
|
|
|
|
|
con := GetConfigActivityPdd()
|
|
|
|
|
if con == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
now := time.Now().Unix()
|
|
|
|
|
if now-pddData.Time < con.Expire*60 {
|
|
|
|
|
// 每天有一次免费旋转
|
|
|
|
|
if !util.IsSameDayTimeStamp(now, pddData.FreeSpinTime) {
|
|
|
|
|
pddData.Spin++
|
|
|
|
|
}
|
|
|
|
|
return pddData
|
|
|
|
|
}
|
|
|
|
|
resetSpinCount := 1
|
|
|
|
|
if !config.GetBase().Release {
|
|
|
|
|
resetSpinCount = 100
|
|
|
|
|
}
|
|
|
|
|
if pddData.ID == 0 {
|
|
|
|
|
pddData.Time = now
|
|
|
|
|
pddData.Spin = resetSpinCount
|
|
|
|
|
db.Mysql().Create(pddData)
|
|
|
|
|
} else {
|
|
|
|
|
db.Mysql().Update(&common.PddData{UID: pddData.UID, Time: pddData.Time},
|
|
|
|
|
map[string]interface{}{"amount": 0, "time": now, "Spin": resetSpinCount, "free_spin_time": 0, "new_record_time": 0})
|
|
|
|
|
pddData.Amount = 0
|
|
|
|
|
pddData.Time = now
|
|
|
|
|
pddData.Spin = resetSpinCount
|
|
|
|
|
pddData.FreeSpinTime = 0
|
|
|
|
|
pddData.NewRecordTime = 0
|
|
|
|
|
}
|
|
|
|
|
return pddData
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 是否有新邀请
|
|
|
|
|
func HasNewAcitivityPddShare(uid int) bool {
|
|
|
|
|
if !IsActivityValid(common.ActivityIDPDD) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
pddData := GetAcitivityPddData(uid)
|
|
|
|
|
if pddData.NewRecordTime <= 0 {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
q := elastic.NewBoolQuery()
|
|
|
|
|
q.Filter(elastic.NewTermQuery("Referer", uid))
|
|
|
|
|
q.Filter(elastic.NewRangeQuery("Time").Gte(pddData.NewRecordTime))
|
|
|
|
|
return db.ES().Count(common.ESIndexBackPddRecord, q) > 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetUserFreeSpinData(uid int) *common.ActivityFreeSpinData {
|
|
|
|
|
data := &common.ActivityFreeSpinData{UID: uid}
|
|
|
|
|
db.Mysql().Get(data)
|
|
|
|
|
return data
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetUserFirstRechargeBackData(uid int) *common.ActivityFirstRechargeBackData {
|
|
|
|
|
data := &common.ActivityFirstRechargeBackData{UID: uid}
|
|
|
|
|
db.Mysql().Get(data)
|
|
|
|
|
return data
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ShouldShowActivityFirstRechargeBack(uid int) bool {
|
|
|
|
|
if !IsActivityValid(common.ActivityIDFirstRechargeBack) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
if uid == 0 {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
data := GetUserFirstRechargeBackData(uid)
|
|
|
|
|
return data.RewardTime == 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func UploadActivityData(uid, activityID, t int, amount int64) {
|
|
|
|
|
db.ES().InsertToESGO(common.ESIndexBackActivity, &common.ESActivity{
|
|
|
|
|
ActivityID: activityID,
|
|
|
|
|
UID: uid,
|
|
|
|
|
Time: time.Now().Unix(),
|
|
|
|
|
Type: t,
|
|
|
|
|
Amount: amount,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ShouldShowActivitySign(uid int) bool {
|
|
|
|
|
if !IsActivityValid(common.ActivityIDSign) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
if uid == 0 {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
p, _ := GetUserXInfo(uid, "birth")
|
|
|
|
|
now := util.GetZeroTime(time.Now()).Unix()
|
|
|
|
|
birth := util.GetZeroTime(time.Unix(p.Birth, 0)).Unix()
|
|
|
|
|
return now-birth <= 6*common.OneDay
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetUserWeekCard(uid int) *common.ActivityWeekCardData {
|
|
|
|
|
data := &common.ActivityWeekCardData{UID: uid}
|
|
|
|
|
db.Mysql().Get(data)
|
|
|
|
|
return data
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ShouldShowActivityWeekCard(uid int) bool {
|
|
|
|
|
if !IsActivityValid(common.ActivityIDWeekCard) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
if uid == 0 {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetUserActivitySlotsData(uid int) *common.ActivitySlotsData {
|
|
|
|
|
data := &common.ActivitySlotsData{UID: uid}
|
|
|
|
|
db.Mysql().Get(data)
|
|
|
|
|
now := time.Now().Unix()
|
|
|
|
|
isSingle := IsActivitySingleDay(common.ActivityIDSlots)
|
|
|
|
|
t := data.Time2
|
|
|
|
|
if isSingle {
|
|
|
|
|
t = data.Time1
|
|
|
|
|
}
|
|
|
|
|
if !util.IsSameDayTimeStamp(now, t) {
|
|
|
|
|
data.Spin = 0
|
|
|
|
|
}
|
|
|
|
|
if data.ID == 0 {
|
|
|
|
|
if isSingle {
|
|
|
|
|
data.Time1 = now
|
|
|
|
|
} else {
|
|
|
|
|
data.Time2 = now
|
|
|
|
|
}
|
|
|
|
|
p, _ := GetUserXInfo(uid, "mobile", "avatar")
|
|
|
|
|
data.Avatar = p.Avatar
|
|
|
|
|
data.Nick = p.Nick
|
|
|
|
|
db.Mysql().Create(data)
|
|
|
|
|
}
|
|
|
|
|
return data
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func UpdateUserActivitySlotsData(uid int, count int) {
|
|
|
|
|
data := &common.ActivitySlotsData{UID: uid}
|
|
|
|
|
db.Mysql().Get(data)
|
|
|
|
|
now := time.Now().Unix()
|
|
|
|
|
isSingle := IsActivitySingleDay(common.ActivityIDSlots)
|
|
|
|
|
if data.ID == 0 {
|
|
|
|
|
if isSingle {
|
|
|
|
|
data.Time1 = now
|
|
|
|
|
} else {
|
|
|
|
|
data.Time2 = now
|
|
|
|
|
}
|
|
|
|
|
data.Spin = count
|
|
|
|
|
db.Mysql().Create(data)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
update := map[string]interface{}{}
|
|
|
|
|
t := data.Time2
|
|
|
|
|
str := "time2"
|
|
|
|
|
if isSingle {
|
|
|
|
|
t = data.Time1
|
|
|
|
|
str = "time1"
|
|
|
|
|
}
|
|
|
|
|
if !util.IsSameDayTimeStamp(now, t) {
|
|
|
|
|
update["spin"] = count
|
|
|
|
|
update[str] = now
|
|
|
|
|
} else {
|
|
|
|
|
update["spin"] = gorm.Expr("spin + ?", count)
|
|
|
|
|
}
|
|
|
|
|
log.Debug("UpdateUserActivitySlotsData uid:%v,count:%v,isSingle:%v,update:%v", uid, count, isSingle, update)
|
|
|
|
|
db.Mysql().Update(&common.ActivitySlotsData{UID: uid}, update)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ShouldShowActivityLuckShop(uid int) bool {
|
|
|
|
|
if !IsActivityValid(common.ActivityIDLuckyShop) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
if uid == 0 {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return GetShowActivityLuckShopData(uid) != nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetShowActivityLuckShopData(uid int) *common.ActivityLuckyShopData {
|
|
|
|
|
if uid == 0 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
re := GetRechargeInfo(uid)
|
|
|
|
|
if re.TotalRecharge == 0 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
datas := []*common.ActivityLuckyShopData{}
|
|
|
|
|
db.Mysql().QueryAll(fmt.Sprintf("uid = %d", uid), "type asc", &common.ActivityLuckyShopData{}, &datas)
|
|
|
|
|
now := time.Now().Unix()
|
|
|
|
|
// 先判断首充礼包,两种礼包互斥,弹了其中一种,另一种不会弹了
|
|
|
|
|
var rechargeData *common.ActivityLuckyShopData
|
|
|
|
|
for i, v := range datas {
|
|
|
|
|
if v.Type == common.ActivityLuckyShopTypeRechargeLess || v.Type == common.ActivityLuckyShopTypeRechargeMore {
|
|
|
|
|
rechargeData = datas[i]
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if rechargeData != nil && rechargeData.IsValid() {
|
|
|
|
|
return rechargeData
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for i := common.ActivityLuckyShopType + 1; i < common.ActivityLuckyShopTypeAll; i++ {
|
|
|
|
|
// 如果已有首充礼包,那么直接跳过后续判断
|
|
|
|
|
if rechargeData != nil {
|
|
|
|
|
if i == common.ActivityLuckyShopTypeRechargeLess || i == common.ActivityLuckyShopTypeRechargeMore {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
con := GetConfigActivityLuckShop(i)
|
|
|
|
|
var tmp *common.ActivityLuckyShopData
|
|
|
|
|
for i, v := range datas {
|
|
|
|
|
if con.Type == v.Type {
|
|
|
|
|
tmp = datas[i]
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if tmp == nil {
|
|
|
|
|
if con.Type == common.ActivityLuckyShopTypeRechargeLess {
|
|
|
|
|
if re.TotalRecharge < con.Recharge {
|
|
|
|
|
return &common.ActivityLuckyShopData{UID: uid, Type: con.Type, Push: now, ProductID: con.ProductID}
|
|
|
|
|
}
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if con.Type == common.ActivityLuckyShopTypeRechargeMore {
|
|
|
|
|
if re.TotalRecharge >= con.Recharge {
|
|
|
|
|
return &common.ActivityLuckyShopData{UID: uid, Type: con.Type, Push: now, ProductID: con.ProductID}
|
|
|
|
|
}
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
p, _ := GetUserXInfo(uid, "birth")
|
|
|
|
|
tmp := p.Birth + 3*24*3600
|
|
|
|
|
if util.IsSameDayTimeStamp(now, tmp) || now > tmp {
|
|
|
|
|
return &common.ActivityLuckyShopData{UID: uid, Type: con.Type, Push: now, ProductID: con.ProductID}
|
|
|
|
|
}
|
|
|
|
|
} else if tmp.IsValid() {
|
|
|
|
|
return tmp
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IsActivitySingleDay 返回活动是否是单数天
|
|
|
|
|
func IsActivitySingleDay(id int) bool {
|
|
|
|
|
act := GetConfigActivityByID(id)
|
|
|
|
|
if act == nil || !act.IsValid() {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
// if config.GetBase().Release {
|
|
|
|
|
diff := int((util.GetZeroTime(time.Now()).Unix() - util.GetZeroTime(time.Unix(act.Start, 0)).Unix()) / (24 * 60 * 60))
|
|
|
|
|
return util.IsSingle(diff)
|
|
|
|
|
// }
|
|
|
|
|
// now := time.Now()
|
|
|
|
|
// _, m, _ := now.Clock()
|
|
|
|
|
// return util.IsSingle(m / 5)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetUserActivitySuperData(uid int) *common.ActivitySuperData {
|
|
|
|
|
p, _ := GetUserXInfo(uid, "birth")
|
|
|
|
|
data := &common.ActivitySuperData{UID: uid}
|
|
|
|
|
db.Mysql().Get(data)
|
|
|
|
|
if util.GetZeroTime(time.Now()).Unix()-util.GetZeroTime(time.Unix(p.Birth, 0)).Unix() < 5*common.OneDay {
|
|
|
|
|
data.Type = 1
|
|
|
|
|
} else {
|
|
|
|
|
data.Type = 2
|
|
|
|
|
}
|
|
|
|
|
data.CanBuy = !util.IsSameDayTimeStamp(time.Now().Unix(), data.Time)
|
|
|
|
|
if data.ID == 0 {
|
|
|
|
|
db.Mysql().Create(data)
|
|
|
|
|
}
|
|
|
|
|
return data
|
|
|
|
|
}
|