Browse Source

update

master
shenjiachi 15 hours ago
parent
commit
2a746025cb
3 changed files with 117 additions and 2 deletions
  1. +107
    -0
      app/task/svc/svc_team_assistance_count.go
  2. +7
    -0
      app/utils/cache/redis.go
  3. +3
    -2
      go.mod

+ 107
- 0
app/task/svc/svc_team_assistance_count.go View File

@@ -0,0 +1,107 @@
package svc

import (
"applet/app/db"
"applet/app/utils"
"applet/app/utils/cache"
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
"code.fnuoos.com/EggPlanet/egg_models.git/src/model"
"fmt"
"time"
)

func AutoCountTeamAssistance() {

// 1.查签到表,统计今天0点后开始签到的用户
now := time.Now()
nowStr := now.Format("2006-01-02 15:04:05")
date := now.Format("2006-01-02")
todayStr := fmt.Sprintf("%s %s", date, "00:00:00")
var signIns []model.EggSignIn
err := db.Db.Where("start_time > ?", todayStr).Find(&signIns)
if err != nil {
fmt.Println(err)
return
}
var teamAssistance []model.EggEnergyTeamAssistance
// 2. 查询这些用户的下级
for _, signIn := range signIns {
relateDb := implement.NewUserRelateDb(db.Db)
relates, err := relateDb.FindUserRelateByParentUid(signIn.Uid, 0)
if err != nil {
fmt.Println(err)
return
}
// 3. 判断这些下级助力次数
var uids []int64
for _, relate := range *relates {
uids = append(uids, relate.Uid)
}
typePrefix := "incentive_eggSmash"
types := fmt.Sprintf("type LIKE '%s'", typePrefix+"%")
assistedNum, err := db.Db.Where("create_at > ?", signIn.CreateAt).
And(types).In("uid", uids).
GroupBy("uid").Count(&model.AdvertisingCallback{})
if err != nil {
fmt.Println(err)
return
}
if assistedNum > 0 {
// 保存助力信息 数据库
var assistedUsers []model.AdvertisingCallback
err := db.Db.Select("uid").Where("create_at > ?", signIn.CreateAt).
And(types).In("uid", uids).
GroupBy("uid").Find(&assistedUsers)
assistedUserDetails := make([]model.EggEnergyAssistanceDetail, len(assistedUsers))
for i, assistedUser := range assistedUsers {
m := model.EggEnergyAssistanceDetail{
Uid: signIn.Uid,
AssistedUid: int64(assistedUser.Uid),
SignId: signIn.Id,
CreatedAt: nowStr,
UpdatedAt: nowStr,
}
assistedUserDetails[i] = m
}
// 保存助力信息到 redis
cacheKey := fmt.Sprintf("EggEnergyTeamAssistance:%d", signIn.Uid)
targetTime, err1 := time.Parse("2006-01-02 15:04:05", signIn.EndTime)
if err1 != nil {
fmt.Println("解析时间错误:", err1)
return
}
diff := targetTime.Sub(time.Now()).Seconds()
_, err = cache.SetEx(cacheKey, nil, int(diff))
if err != nil {
return
}
for _, assistedUser := range assistedUsers {
cache.SetBit(cacheKey, int64(assistedUser.Uid), 1)
}

assistedTimes, err := db.Db.Where("create_at > ?", signIn.CreateAt).
And(types).In("uid", uids).Count(&model.AdvertisingCallback{})
if err != nil {
fmt.Println(err)
return
}
m := model.EggEnergyTeamAssistance{
Uid: signIn.Uid,
AssistedNum: int(assistedNum),
AssistedTimes: int(assistedTimes),
RewardScore: utils.Float64ToStr(float64(assistedTimes) * 187.5),
SignId: signIn.Id,
Date: date,
CreateAt: nowStr,
UpdateAt: nowStr,
}
teamAssistance = append(teamAssistance, m)
}
}
insert, err := db.Db.Insert(&teamAssistance)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("insert ", insert)
}

+ 7
- 0
app/utils/cache/redis.go View File

@@ -410,3 +410,10 @@ func LPushMax(key string, data ...interface{}) (interface{}, error) {
func SelectDb(db int) (interface{}, error) {
return Do("SELECT", db)
}

func GetBit(key string, offset int64) (int64, error) {
return redigo.Int64(Do("GETBIT", key, offset))
}
func SetBit(key string, offset int64, value int) (interface{}, error) {
return Do("SETBIT", key, offset, value)
}

+ 3
- 2
go.mod View File

@@ -16,7 +16,7 @@ require (
github.com/go-playground/universal-translator v0.18.1
github.com/go-playground/validator/v10 v10.20.0
github.com/go-redis/redis v6.15.9+incompatible
github.com/gomodule/redigo v1.9.2
github.com/gomodule/redigo v2.0.0+incompatible
github.com/jinzhu/copier v0.4.0
github.com/makiuchi-d/gozxing v0.0.0-20210324052758-57132e828831
github.com/qiniu/api.v7/v7 v7.8.2
@@ -33,7 +33,7 @@ require (
)

require (
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241220110855-5eeb26f6c25b
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241224014721-42a6059f0dfa
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241223150004-6bb07a3d2934
code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5
@@ -44,6 +44,7 @@ require (
github.com/alibabacloud-go/tea v1.2.2
github.com/alibabacloud-go/tea-utils/v2 v2.0.6
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
github.com/gin-contrib/sessions v1.0.1
github.com/go-pay/gopay v1.5.98
github.com/go-sql-driver/mysql v1.8.1
github.com/gocolly/colly v1.2.0


Loading…
Cancel
Save