活动分享码

pull/1/head
mofangmin 1 year ago
parent fe972dd0c1
commit 37d968698b
  1. 52
      call/share.go
  2. 2
      common/activity.go
  3. 14
      common/share.go
  4. 1
      modules/backend/migrate.go
  5. 34
      modules/web/handler/share.go
  6. 1
      modules/web/routers/routers_share.go
  7. 8
      modules/web/values/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 {
}
}

@ -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 {

@ -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)"`

@ -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")

@ -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() {

@ -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)

@ -193,3 +193,11 @@ type OnePddRecord struct {
type ActivityPddWithdrawResp struct {
ExpireTime int64
}
type GetActivityCodeReq struct {
ActivityId int
}
type GetActivityCodeResp struct {
ShareLink string
}

Loading…
Cancel
Save