diff --git a/call/share.go b/call/share.go index 9ae5cb5..0195597 100644 --- a/call/share.go +++ b/call/share.go @@ -32,8 +32,22 @@ func ShareBind(share string, isOld bool, uid, cid int) { if share == "" || isOld { return } - // 一级 - upInfo := &common.ShareInfo{Share: share} + now := time.Now().Unix() + codeInfo := &common.ShareActivityCode{ShareCode: share} + upInfo := &common.ShareInfo{} + db.Mysql().Get(codeInfo) + if codeInfo.Id > 0 { + upInfo.UID = codeInfo.UID + // 判断是否过期 + if now < codeInfo.ExpireAt { + util.Go(func() { + SendShareReward(uid, codeInfo.ActivityId) + }) + } + } else { + // 一级 + upInfo = &common.ShareInfo{Share: share} + } db.Mysql().Get(upInfo) if upInfo.ID <= 0 { return @@ -154,3 +168,37 @@ func GetUserShareRechargeAmount(uid, level int) (count int64) { } return } + +// GetActivityShareCode 根据actid获取share code +func GetActivityShareCode(uid, actId int) (code string, err error) { + now := time.Now() + ret := make([]*common.ShareActivityCode, 0, 1) + _, err = db.Mysql().QueryList(0, 1, fmt.Sprintf("uid = %d and activity_id = %d and expire_at < %d", uid, actId, now.Unix()), "id", &common.ShareActivityCode{}, &ret) + if err != nil { + log.Error("GetActivityShareCode err:%v", err) + return + } + if len(ret) == 0 { + expireTime := util.GetZeroTime(now.AddDate(0, 0, 1)) + code = util.GetShareCode(-uid - actId) + err = db.Mysql().Create(&common.ShareActivityCode{ + UID: uid, + ShareCode: code, + ActivityId: actId, + ExpireAt: expireTime.Unix(), + CreateAt: now.Unix(), + }) + if err != nil { + log.Error("GetActivityShareCode err:%v", err) + return + } + } else { + code = ret[0].ShareCode + } + return +} + +func SendShareReward(uid, actId int) { + switch actId { + } +} diff --git a/common/activity.go b/common/activity.go index 54ea59d..9f46e71 100644 --- a/common/activity.go +++ b/common/activity.go @@ -68,6 +68,8 @@ type ConfigActivity struct { Type int `gorm:"column:type;type:int(11);default:1;comment:类型" json:"Type" web:"type"` Pic string `gorm:"column:pic;type:varchar(255);comment:活动图片" json:"Pic" web:"pic"` Data string `gorm:"column:data;type:varchar(255);comment:跳转数据" json:"Data" web:"data"` + Content string `gorm:"column:content;type:varchar(255);comment:文案内容" json:"Content" web:"content"` + Text string `gorm:"column:text;type:varchar(255);comment:按钮内容" json:"Text" web:"text"` } func (a *ConfigActivity) TableName() string { diff --git a/common/share.go b/common/share.go index 072504c..90f86c1 100644 --- a/common/share.go +++ b/common/share.go @@ -78,6 +78,20 @@ func (a *ShareInfo) TableName() string { return "share_info" } +type ShareActivityCode struct { + Id int `gorm:"column:id;type:int(11) AUTO_INCREMENT;primary_key;" json:"id"` + UID int `gorm:"column:uid;type:int(11);index:idx_share;comment:玩家ID" json:"uid"` + ShareCode string `gorm:"column:share_code;type:varchar(255);index:idx_share;comment:分享码" json:"share_code"` + ActivityId int `gorm:"column:activity_id;type:int(11);index:idx_share;comment:关联活动ID" json:"activity_id"` + Reward string `gorm:"column:reward;type:varchar(255);index:idx_share;comment:分享码" json:"reward"` + CreateAt int64 `gorm:"column:create_at;type:bigint(20);comment:创建时间" json:"create_at"` + ExpireAt int64 `gorm:"column:expire_at;type:bigint(20);comment:过期时间" json:"expire_at"` +} + +func (m *ShareActivityCode) TableName() string { + return "share_act_code" +} + type ShareOrder struct { ID int `gorm:"primarykey"` UID int `gorm:"column:uid;not null;type:int(11)"` diff --git a/modules/backend/migrate.go b/modules/backend/migrate.go index 8e9fed6..c31743a 100644 --- a/modules/backend/migrate.go +++ b/modules/backend/migrate.go @@ -109,6 +109,7 @@ func MigrateDB() { new(common.ActivitySevenDayBoxData), new(common.ConfigActivitySuper), new(common.ActivitySuperData), + new(common.ShareActivityCode), ) if err != nil { panic("Migrate db fail") diff --git a/modules/web/handler/share.go b/modules/web/handler/share.go index a4367af..6f5c743 100644 --- a/modules/web/handler/share.go +++ b/modules/web/handler/share.go @@ -108,6 +108,40 @@ func ShareInfo(c *gin.Context) { } } +func GetActivityCode(c *gin.Context) { + a := app.NewApp(c) + defer func() { + a.Response() + }() + req := new(values.GetActivityCodeReq) + if !a.S(req) { + return + } + resp := &values.GetActivityCodeResp{} + a.Data = resp + channel := call.GetChannelByID(a.Channel) + if channel != nil { + resp.ShareLink += channel.URL + "?code=" + "xxxxxx" + } + a.GetUID() + if a.UID <= 0 { + return + } + code, err := call.GetActivityShareCode(a.UID, req.ActivityId) + if err != nil { + a.Code = values.CodeRetry + return + } + if channel != nil { + resp.ShareLink = channel.URL + "?code=" + code + if a.Prefix != "" { + resp.ShareLink = a.Prefix + "." + resp.ShareLink + } else { + resp.ShareLink = "www." + resp.ShareLink + } + } +} + func SharePlatformInfo(c *gin.Context) { a := app.NewApp(c) defer func() { diff --git a/modules/web/routers/routers_share.go b/modules/web/routers/routers_share.go index 728bb05..245bfcb 100644 --- a/modules/web/routers/routers_share.go +++ b/modules/web/routers/routers_share.go @@ -10,6 +10,7 @@ func share(e *gin.RouterGroup) { e.POST("/share/info", handler.ShareInfo) e.POST("/share/platform", handler.SharePlatformInfo) e.POST("/share/withdraw", handler.ShareWithdraw) + e.POST("/share/activity_code", handler.GetActivityCode) // e.POST("/share/reference", handler.ShareReference) // e.POST("/share/report", handler.ShareReport) // e.POST("/share/transfer", handler.ShareTransfer) diff --git a/modules/web/values/share.go b/modules/web/values/share.go index 3f31238..a32ac56 100644 --- a/modules/web/values/share.go +++ b/modules/web/values/share.go @@ -193,3 +193,11 @@ type OnePddRecord struct { type ActivityPddWithdrawResp struct { ExpireTime int64 } + +type GetActivityCodeReq struct { + ActivityId int +} + +type GetActivityCodeResp struct { + ShareLink string +}