@@ -3,12 +3,15 @@ package comm | |||||
import ( | import ( | ||||
"applet/app/db" | "applet/app/db" | ||||
"applet/app/e" | "applet/app/e" | ||||
"applet/app/md" | |||||
"applet/app/md/comm" | "applet/app/md/comm" | ||||
"applet/app/svc" | "applet/app/svc" | ||||
"applet/app/utils" | |||||
"applet/app/utils/cache" | "applet/app/utils/cache" | ||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | ||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" | "code.fnuoos.com/EggPlanet/egg_models.git/src/model" | ||||
enum2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" | enum2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" | ||||
"fmt" | |||||
"github.com/aliyun/aliyun-oss-go-sdk/oss" | "github.com/aliyun/aliyun-oss-go-sdk/oss" | ||||
"github.com/gin-gonic/gin" | "github.com/gin-gonic/gin" | ||||
"time" | "time" | ||||
@@ -103,24 +106,42 @@ func AccessRecords(c *gin.Context) { | |||||
user := svc.GetUser(c) | user := svc.GetUser(c) | ||||
date := time.Now().Format("2006-01-02") | date := time.Now().Format("2006-01-02") | ||||
recordsDb := implement.NewEggAccessRecordsDb(db.Db) | |||||
exist, err := recordsDb.EggAccessRecordsExist(user.Id, date, req.Index) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, nil) | |||||
} | |||||
if exist { | |||||
e.OutSuc(c, "data exist", nil) | |||||
return | |||||
} | |||||
m := model.EggAccessRecords{ | |||||
Uid: user.Id, | |||||
PageIndex: req.Index, | |||||
Date: date, | |||||
} | |||||
_, err = recordsDb.EggAccessRecordsInsert(&m) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, nil) | |||||
cacheKey := fmt.Sprintf(md.UserAccessRecordsKey, user.Id, date, req.Index) | |||||
get, err1 := cache.GetString(cacheKey) | |||||
if err1 != nil || get == "" { | |||||
recordsDb := implement.NewEggAccessRecordsDb(db.Db) | |||||
exist, err := recordsDb.EggAccessRecordsExist(user.Id, date, req.Index) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, nil) | |||||
} | |||||
if exist { | |||||
e.OutSuc(c, "success", nil) | |||||
return | |||||
} | |||||
m := model.EggAccessRecords{ | |||||
Uid: user.Id, | |||||
PageIndex: req.Index, | |||||
Date: date, | |||||
} | |||||
_, err = recordsDb.EggAccessRecordsInsert(&m) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR_DB_ORM, nil) | |||||
return | |||||
} | |||||
ttl := 3 * 60 * 60 // 记录保存三小时 | |||||
_, err = cache.SetEx(cacheKey, "1", ttl) | |||||
if err != nil { | |||||
fmt.Println("AccessRecordsRedis_ERR:::::", err.Error()) | |||||
utils.FilePutContents("AccessRecordsRedis_ERR", utils.SerializeStr(map[string]interface{}{ | |||||
"cacheKey": cacheKey, | |||||
"err": err.Error(), | |||||
})) | |||||
} | |||||
} else { | |||||
e.OutSuc(c, "success", nil) | |||||
return | return | ||||
} | } | ||||
@@ -8,6 +8,7 @@ import ( | |||||
"applet/app/utils" | "applet/app/utils" | ||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/md" | "code.fnuoos.com/EggPlanet/egg_system_rules.git/md" | ||||
svc3 "code.fnuoos.com/EggPlanet/egg_system_rules.git/svc" | svc3 "code.fnuoos.com/EggPlanet/egg_system_rules.git/svc" | ||||
es2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es" | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" | "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" | ||||
"context" | "context" | ||||
"errors" | "errors" | ||||
@@ -112,6 +113,22 @@ func Publish(c *gin.Context) { | |||||
}) | }) | ||||
fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet) | fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet) | ||||
// 更新发朋友圈次数 | |||||
year, week := time.Now().ISOWeek() | |||||
yearStr := utils.IntToStr(year) | |||||
weekStr := utils.IntToStr(week) | |||||
index := es2.GetAppointIndexFromAlias(yearStr, weekStr) | |||||
id := fmt.Sprintf("%d%d-%d", year, week, user.Id) | |||||
script := elastic.NewScript("ctx._source.send_circle_of_friend_nums += params.inc").Param("inc", 1) | |||||
_, err = es.EsClient.Update(). | |||||
Index(index). | |||||
Id(id). | |||||
Script(script). | |||||
Do(context.Background()) | |||||
if err != nil { | |||||
e.OutErr(c, e.ERR, err.Error()) | |||||
return | |||||
} | |||||
e.OutSuc(c, "success", nil) | e.OutSuc(c, "success", nil) | ||||
} | } | ||||
@@ -227,6 +227,9 @@ func SendRedPackage(c *gin.Context) { | |||||
RedPackageId: redPackageId, | RedPackageId: redPackageId, | ||||
} | } | ||||
// 处理统计发红包数 推到 mq 处理 | |||||
go svc.AddSendRedPackageTimesPushToMQ(user.Id) | |||||
e.OutSuc(c, resp, nil) | e.OutSuc(c, resp, nil) | ||||
return | return | ||||
} | } |
@@ -6,4 +6,5 @@ const ( | |||||
DealAppLimiterRequestIdPrefix = "%s:egg_app_limiter_request_id:%s" | DealAppLimiterRequestIdPrefix = "%s:egg_app_limiter_request_id:%s" | ||||
AppLimiterLock = "%s:egg_app_limiter_lock:%s" // 限流器锁 | AppLimiterLock = "%s:egg_app_limiter_lock:%s" // 限流器锁 | ||||
CfgCacheTime = 86400 | CfgCacheTime = 86400 | ||||
UserAccessRecordsKey = "AccessRecords:%d:%s:%s" // 用户访问记录 uid index | |||||
) | ) |
@@ -14,7 +14,9 @@ import ( | |||||
enum2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" | enum2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" | ||||
md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md" | md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md" | ||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/rule" | "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule" | ||||
md3 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" | |||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/svc" | "code.fnuoos.com/EggPlanet/egg_system_rules.git/svc" | ||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" | |||||
"errors" | "errors" | ||||
"github.com/google/uuid" | "github.com/google/uuid" | ||||
"github.com/shopspring/decimal" | "github.com/shopspring/decimal" | ||||
@@ -377,3 +379,16 @@ func GetImUser(userId int64, phone string) (user *pb.User, err error) { | |||||
} | } | ||||
return resp.User, nil | return resp.User, nil | ||||
} | } | ||||
func AddSendRedPackageTimesPushToMQ(uid int64) { | |||||
ch, err := rabbit.Cfg.Pool.GetChannel() | |||||
if err != nil { | |||||
return | |||||
} | |||||
defer ch.Release() | |||||
ch.Publish(md3.IMEggEnergyExchange, md3.IMEggEnergyStructForSendRedPackageData{ | |||||
Uid: uid, | |||||
}, md3.IMEggEnergyRoutKeyForSendRedPackage) | |||||
} |
@@ -33,7 +33,7 @@ require ( | |||||
require ( | require ( | ||||
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241206115326-8cbc93c7c64d | code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241206115326-8cbc93c7c64d | ||||
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241205061938-91f42710d6cd | |||||
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241207095445-64c8aa0b486e | |||||
code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be | 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 | code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 | ||||
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible | github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible | ||||