@@ -9,9 +9,11 @@ import ( | |||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/md" | |||
svc3 "code.fnuoos.com/EggPlanet/egg_system_rules.git/svc" | |||
"code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" | |||
"context" | |||
"encoding/json" | |||
"fmt" | |||
"github.com/gin-gonic/gin" | |||
"github.com/olivere/elastic/v7" | |||
"time" | |||
) | |||
@@ -43,7 +45,7 @@ func IsCanComment(c *gin.Context) { | |||
// @param Authorization header string true "验证参数Bearer和token空格拼接" | |||
// @Success 200 {string} "许可链接" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/v1/circleFriends/comment [Get] | |||
// @Router /api/v1/circleFriends/comment [POST] | |||
func Comment(c *gin.Context) { | |||
var req friend_circles.CommentReq | |||
if err1 := c.ShouldBindJSON(&req); err1 != nil { | |||
@@ -79,8 +81,9 @@ func Comment(c *gin.Context) { | |||
//查找评论记录 | |||
var comment md.EggFriendCircleCommentEs | |||
commentIndex := svc3.GetEggFriendCircleCommentEsIndex(circle.Uid) | |||
if req.CommentIndexId != "" { | |||
doc1, err1 := es.FirstDoc(md.EggFriendCircleCommentEsAlias, req.CircleIndexId) | |||
doc1, err1 := es.FirstDoc(commentIndex, req.CommentIndexId) | |||
if err1 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err1.Error()) | |||
return | |||
@@ -106,11 +109,15 @@ func Comment(c *gin.Context) { | |||
} | |||
var commentId, replyCommentId string | |||
var commentImUid, replyCommentImUid int64 | |||
if &comment != nil { | |||
if req.CommentIndexId != "" { | |||
if comment.CommentId != "" { | |||
// 为二级评论赋值 | |||
commentId = comment.CommentId | |||
commentImUid = comment.CommentImUid | |||
replyCommentId = req.CommentIndexId | |||
commentImUid = comment.ImUid | |||
replyCommentImUid = comment.ImUid | |||
} else { | |||
// 不存在二级评论 就将本条当做二级评论 | |||
commentId = req.CommentIndexId | |||
commentImUid = comment.ImUid | |||
} | |||
@@ -147,8 +154,8 @@ func Comment(c *gin.Context) { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
if &comment != nil { | |||
_, err = es.UpdateDoc(md.EggFriendCircleCommentEsAlias, req.CommentIndexId, map[string]interface{}{ | |||
if req.CommentIndexId != "" { | |||
_, err = es.UpdateDoc(commentIndex, req.CommentIndexId, map[string]interface{}{ | |||
"comment_nums": comment.CommentNums + 1, | |||
}) | |||
if err != nil { | |||
@@ -172,18 +179,36 @@ func Comment(c *gin.Context) { | |||
// @Router /api/v1/circleFriends/CommentDelete/{$comment_index_id} [DELETE] | |||
func CommentDelete(c *gin.Context) { | |||
commentIndexId := c.Param("comment_index_id") | |||
doc1, err := es.FirstDoc(md.EggFriendCircleCommentEsAlias, commentIndexId) | |||
//查找评论记录 | |||
boolQuery := elastic.NewBoolQuery() | |||
boolQuery.Must(elastic.NewTermQuery("_id", commentIndexId)) | |||
searchResult, err := es.EsClient.Search(). | |||
Index(md.EggFriendCircleCommentEsAlias). | |||
Query(boolQuery). | |||
Size(1). | |||
Pretty(true). | |||
Do(context.Background()) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
if !doc1.Found { // 表示没找到数据 | |||
var doc1 md.EggFriendCircleCommentEs | |||
// 检查是否有结果 | |||
var index string | |||
if searchResult.Hits.TotalHits.Value != 0 { | |||
index = searchResult.Hits.Hits[0].Index | |||
err = json.Unmarshal(searchResult.Hits.Hits[0].Source, &doc1) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
} else { | |||
e.OutErr(c, e.ERR_NOT_FAN, "评论文档记录不存在") | |||
return | |||
} | |||
//1、删除es数据 | |||
_, err = es.DeleteDoc(md.EggFriendCircleCommentEsAlias, commentIndexId) | |||
_, err = es.DeleteDoc(index, commentIndexId) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
@@ -206,22 +231,33 @@ func CommentDelete(c *gin.Context) { | |||
// @Param comment_index_id query string true "评论文档记录" | |||
// @Success 200 {string} "success" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/v1/circleFriends/CommentLike [Get] | |||
// @Router /api/v1/circleFriends/commentLike [Get] | |||
func CommentLike(c *gin.Context) { | |||
commentIndexId := c.DefaultQuery("comment_index_id", "") | |||
doc, err := es.FirstDoc(md.EggFriendCircleCommentEsAlias, commentIndexId) | |||
boolQuery := elastic.NewBoolQuery() | |||
boolQuery.Must(elastic.NewTermQuery("_id", commentIndexId)) | |||
searchResult, err := es.EsClient.Search(). | |||
Index(md.EggFriendCircleCommentEsAlias). | |||
Query(boolQuery). | |||
Size(1). | |||
Pretty(true). | |||
Do(context.Background()) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if !doc.Found { // 表示没找到数据 | |||
e.OutErr(c, e.ERR_NOT_FAN, "评论文档记录不存在") | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
var comment md.EggFriendCircleCommentEs | |||
err = json.Unmarshal(doc.Source, &comment) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
var index string | |||
// 检查是否有结果 | |||
if searchResult.Hits.TotalHits.Value != 0 { | |||
index = searchResult.Hits.Hits[0].Index | |||
err = json.Unmarshal(searchResult.Hits.Hits[0].Source, &comment) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
} else { | |||
e.OutErr(c, e.ERR_NOT_FAN, "评论文档记录不存在") | |||
return | |||
} | |||
@@ -238,8 +274,8 @@ func CommentLike(c *gin.Context) { | |||
} | |||
//2、修改es数据 | |||
_, err = es.UpdateDoc(md.EggFriendCircleCommentEsAlias, commentIndexId, map[string]interface{}{ | |||
"like_nums": comment.CommentNums + 1, | |||
_, err = es.UpdateDoc(index, commentIndexId, map[string]interface{}{ | |||
"likes_nums": comment.CommentNums + 1, | |||
}) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
@@ -274,29 +310,40 @@ func CommentLike(c *gin.Context) { | |||
// @Param comment_index_id query string true "评论文档记录" | |||
// @Success 200 {string} "success" | |||
// @Failure 400 {object} md.Response "具体错误" | |||
// @Router /api/v1/circleFriends/CommentLike [Get] | |||
// @Router /api/v1/circleFriends/commentCancelLike [Get] | |||
func CommentCancelLike(c *gin.Context) { | |||
commentIndexId := c.DefaultQuery("comment_index_id", "") | |||
doc, err := es.FirstDoc(md.EggFriendCircleCommentEsAlias, commentIndexId) | |||
boolQuery := elastic.NewBoolQuery() | |||
boolQuery.Must(elastic.NewTermQuery("_id", commentIndexId)) | |||
searchResult, err := es.EsClient.Search(). | |||
Index(md.EggFriendCircleCommentEsAlias). | |||
Query(boolQuery). | |||
Size(1). | |||
Pretty(true). | |||
Do(context.Background()) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if !doc.Found { // 表示没找到数据 | |||
e.OutErr(c, e.ERR_NOT_FAN, "评论文档记录不存在") | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
var comment md.EggFriendCircleCommentEs | |||
err = json.Unmarshal(doc.Source, &comment) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
var index string | |||
// 检查是否有结果 | |||
if searchResult.Hits.TotalHits.Value != 0 { | |||
index = searchResult.Hits.Hits[0].Index | |||
err = json.Unmarshal(searchResult.Hits.Hits[0].Source, &comment) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
} else { | |||
e.OutErr(c, e.ERR_NOT_FAN, "评论文档记录不存在") | |||
return | |||
} | |||
//1、修改es数据 | |||
_, err = es.UpdateDoc(md.EggFriendCircleCommentEsAlias, commentIndexId, map[string]interface{}{ | |||
"like_nums": comment.CommentNums - 1, | |||
_, err = es.UpdateDoc(index, commentIndexId, map[string]interface{}{ | |||
"likes_nums": comment.LikesNums - 1, | |||
}) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
@@ -0,0 +1,57 @@ | |||
package friend_circle | |||
import ( | |||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/md" | |||
"code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" | |||
"fmt" | |||
"testing" | |||
) | |||
func TestCreateFriendCircleIndex(t *testing.T) { | |||
es.Init("http://123.57.140.192:9200", "elastic", "fnuo123") | |||
err := es.CreateIndexIfNotExists(md.EggFriendCircleEsIndex, md.EggFriendCircleEsMapping) | |||
if err != nil { | |||
fmt.Println(err) | |||
} | |||
fmt.Println("success") | |||
} | |||
func TestCreateFriendCircleCommentLikeIndex(t *testing.T) { | |||
es.Init("http://123.57.140.192:9200", "elastic", "fnuo123") | |||
for i := 0; i < 10; i++ { | |||
index := fmt.Sprintf("%s%d", md.EggFriendCircleLikeEsIndex, i) | |||
err := es.CreateIndexIfNotExists(index, md.EggFriendCircleLikeEsMapping) | |||
if err != nil { | |||
fmt.Println(err) | |||
} | |||
} | |||
fmt.Println("success") | |||
} | |||
func TestCreateFriendCircleCommentIndex(t *testing.T) { | |||
es.Init("http://123.57.140.192:9200", "elastic", "fnuo123") | |||
for i := 0; i < 10; i++ { | |||
index := fmt.Sprintf("%s%d", md.EggFriendCircleCommentEsIndex, i) | |||
err := es.CreateIndexIfNotExists(index, md.EggFriendCircleCommentEsMapping) | |||
if err != nil { | |||
fmt.Println(err) | |||
} | |||
} | |||
fmt.Println("success") | |||
} | |||
func TestDeleteIndex(t *testing.T) { | |||
es.Init("http://123.57.140.192:9200", "elastic", "fnuo123") | |||
for i := 0; i < 10; i++ { | |||
index := fmt.Sprintf("%s%d", md.EggFriendCircleCommentEsIndex, i) | |||
_, err := es.DeleteIndex(index) | |||
if err != nil { | |||
fmt.Println(err) | |||
return | |||
} | |||
} | |||
fmt.Println("success") | |||
} |
@@ -1,6 +1,8 @@ | |||
package friend_circle | |||
import ( | |||
"applet/app/db" | |||
"applet/app/db/im/model" | |||
"applet/app/e" | |||
"applet/app/md/friend_circles" | |||
"applet/app/svc" | |||
@@ -11,6 +13,7 @@ import ( | |||
es2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es" | |||
"code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" | |||
"context" | |||
"encoding/json" | |||
"errors" | |||
"fmt" | |||
"github.com/gin-gonic/gin" | |||
@@ -95,11 +98,19 @@ func Publish(c *gin.Context) { | |||
return | |||
} | |||
//插入es记录 | |||
user := svc.GetUser(c) | |||
var imUser model.User | |||
_, err = db.DbIm.Where("phone_number = ?", user.Phone).Get(&imUser) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
//插入es记录 | |||
now := time.Now() | |||
createDocRet, err := es.CreateDoc(md.EggFriendCircleEsIndex, strconv.FormatInt(user.Id, 10)+"_"+utils.Int64ToStr(now.Unix()), md.EggFriendCircleEs{ | |||
Uid: user.Id, | |||
ImUid: imUser.Id, | |||
Kind: 1, | |||
Content: req.Content, | |||
Image: utils.SerializeStr(req.ImageList), | |||
@@ -120,16 +131,35 @@ func Publish(c *gin.Context) { | |||
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()) | |||
id := fmt.Sprintf("%d%d_%d", year, week, user.Id) | |||
_, err = es.FirstDoc(index, id) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
if err.Error() != "elastic: Error 404 (Not Found)" { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} else { | |||
m := md.EggEnergyUserEggScoreEs{ | |||
Uid: user.Id, | |||
SendCircleOfFriendNums: 1, | |||
} | |||
newCreateDoc, err := es.CreateDoc(index, id, &m) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
fmt.Printf("newCreateDoc ==> %+v \n\n", newCreateDoc) | |||
} | |||
} else { | |||
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) | |||
} | |||
@@ -218,12 +248,26 @@ func CommentDetail(c *gin.Context) { | |||
} | |||
//查找评论记录 | |||
doc1, err1 := es.FirstDoc(md.EggFriendCircleCommentEsAlias, req.CommentIndexId) | |||
if err1 != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err1.Error()) | |||
boolQuery := elastic.NewBoolQuery() | |||
boolQuery.Must(elastic.NewTermQuery("_id", req.CommentIndexId)) | |||
searchResult, err := es.EsClient.Search(). | |||
Index(md.EggFriendCircleCommentEsAlias). | |||
Query(boolQuery). | |||
Pretty(true). | |||
Do(context.Background()) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
if !doc1.Found { // 表示没找到数据 | |||
var doc md.EggFriendCircleCommentEs | |||
// 检查是否有结果 | |||
if searchResult.Hits.TotalHits.Value != 0 { | |||
err = json.Unmarshal(searchResult.Hits.Hits[0].Source, &doc) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
} else { | |||
e.OutErr(c, e.ERR_NOT_FAN, "评论文档记录不存在") | |||
return | |||
} | |||
@@ -233,6 +277,7 @@ func CommentDetail(c *gin.Context) { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
resp.CircleIndexId = doc.CircleId | |||
e.OutSuc(c, resp, nil) | |||
} | |||
@@ -269,7 +314,9 @@ func Delete(c *gin.Context) { | |||
e.OutErr(c, e.ERR_NOT_FAN, "朋友圈文档记录不存在") | |||
return | |||
} | |||
if doc.Uid != utils.Int64ToStr(user.Id) { | |||
var docInfo md.EggFriendCircleEs | |||
utils.Unserialize(doc.Source, &docInfo) | |||
if docInfo.Uid != user.Id { | |||
e.OutErr(c, e.ERR, errors.New("不允许删除别人的朋友圈")) | |||
return | |||
} | |||
@@ -368,11 +415,18 @@ func Like(c *gin.Context) { | |||
return | |||
} | |||
var imUser model.User | |||
_, err = db.DbIm.Where("phone_number = ?", user.Phone).Get(&imUser) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
// 新增点赞信息 | |||
now := time.Now() | |||
m := md.EggFriendCircleLikeEs{ | |||
Uid: user.Id, | |||
ImUid: 0, | |||
ImUid: imUser.Id, | |||
CircleId: req.CircleIndexId, | |||
CreatedAt: now.Format("2006-01-02 15:04:05"), | |||
UpdatedAt: now.Format("2006-01-02 15:04:05"), | |||
@@ -427,6 +481,10 @@ func CancelLike(c *gin.Context) { | |||
likeId := svc3.GetEggFriendCircleLikeEsIndexId(user.Id, req.CircleIndexId) | |||
deleteDocRet, err := es.DeleteDoc(likeEsIndex, likeId) | |||
if err != nil { | |||
if err.Error() == "elastic: Error 404 (Not Found)" { | |||
e.OutErr(c, e.ERR_BAD_REQUEST, errors.New("点赞已取消,请勿重复请求").Error()) | |||
return | |||
} | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
@@ -106,7 +106,7 @@ func EggEnergyDetails(c *gin.Context) { | |||
list = append(list, tmp) | |||
} | |||
//3、获取当前用户 蛋蛋能量(可用+结算)、 预估总价值 | |||
//3、获取当前用户 蛋蛋能量(可用+结算+预估)、 预估总价值 | |||
virtualAmountDb := implement.NewUserVirtualAmountDb(db.Db) | |||
personEggEnergy, err := virtualAmountDb.GetUserVirtualWalletBySession(user.Id, eggEnergyBasicSetting.PersonEggEnergyCoinId) | |||
if err != nil { | |||
@@ -124,7 +124,40 @@ func EggEnergyDetails(c *gin.Context) { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
totalEggEnergy := utils.StrToFloat64(personEggEnergy.Amount) + utils.StrToFloat64(teamEggEnergy.Amount) | |||
now := time.Now() | |||
signInDb := implement.NewEggSignInDb(db.Db) | |||
nowStr := now.Format("2006-01-02 15:04:05") | |||
has, signIn, err := signInDb.EggSignINGetOneByTimeAndUid("", nowStr, user.Id, 0) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
var estimatePersonEggEnergyValue decimal.Decimal | |||
var estimateTeamEggEnergyValue decimal.Decimal | |||
if has && utils.TimeParseStd(signIn.EndTime).After(now) { | |||
//获取预估每秒获得蛋蛋能量数 | |||
estimatePerSecondPersonEggEnergyValue, err1 := decimal.NewFromString(signIn.EstimatePerSecondPersonEggEnergyValue) | |||
if err1 != nil { | |||
e.OutErr(c, e.ERR, err1.Error()) | |||
return | |||
} | |||
estimatePerSecondTeamEggEnergyValue, err1 := decimal.NewFromString(signIn.EstimatePerSecondTeamEggEnergyValue) | |||
if err1 != nil { | |||
e.OutErr(c, e.ERR, err1.Error()) | |||
return | |||
} | |||
//3.2.2 计算预估获得的蛋蛋能量数 | |||
estimateTimeSec := now.Unix() - utils.TimeParseStd(signIn.StartTime).Unix() | |||
estimatePersonEggEnergyValue = decimal.NewFromInt(estimateTimeSec).Mul(estimatePerSecondPersonEggEnergyValue) | |||
estimateTeamEggEnergyValue = decimal.NewFromInt(estimateTimeSec).Mul(estimatePerSecondTeamEggEnergyValue) | |||
} | |||
personEggEnergyValue, _ := decimal.NewFromString(personEggEnergy.Amount) | |||
teamEggEnergyValue, _ := decimal.NewFromString(teamEggEnergy.Amount) | |||
totalEggEnergy, _ := personEggEnergyValue.Add(teamEggEnergyValue).Add(estimatePersonEggEnergyValue).Add(estimateTeamEggEnergyValue).Float64() | |||
totalEggEnergyPrice := totalEggEnergy * utils.StrToFloat64(coreData.NowPrice) | |||
transferTypeList := md.TransferTypeList{ | |||
@@ -377,21 +410,6 @@ func BasalRate(c *gin.Context) { | |||
e.OutErr(c, e.ERR_USER_CHECK_ERR, nil) | |||
return | |||
} | |||
energyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db) | |||
eggEnergyBasicSetting, err := energyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{ | |||
"key": "is_open", | |||
"value": 1, | |||
}) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
coinID := eggEnergyBasicSetting.PersonEggEnergyCoinId | |||
coinDb := implement.NewVirtualCoinDb(db.Db) | |||
coin, err := coinDb.VirtualCoinGetOneByParams(map[string]interface{}{ | |||
"key": "id", | |||
"value": coinID, | |||
}) | |||
now := time.Now() | |||
nowStr := now.Format("2006-01-02 15:04:05") | |||
signInDb := implement.NewEggSignInDb(db.Db) | |||
@@ -415,11 +433,6 @@ func BasalRate(c *gin.Context) { | |||
e.OutSuc(c, resp, nil) | |||
return | |||
} | |||
ratio, err := decimal.NewFromString(coin.ExchangeRatio) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_UNMARSHAL, err.Error()) | |||
return | |||
} | |||
estimatePerSecondEggEnergyValue, err := decimal.NewFromString(eggSignIn.EstimatePerSecondPersonEggEnergyValue) | |||
if err != nil { | |||
@@ -430,16 +443,14 @@ func BasalRate(c *gin.Context) { | |||
consumedTimeSec := now.Unix() - utils.TimeParseStd(eggSignIn.StartTime).Unix() | |||
consumedTime := decimal.NewFromInt(consumedTimeSec).Div(decimal.NewFromInt(60 * 60)) | |||
consumedEggEnergy := decimal.NewFromInt(consumedTimeSec).Mul(estimatePerSecondEggEnergyValue) | |||
consumedAmount := consumedEggEnergy.Div(ratio) | |||
// 剩余时间、待收益 | |||
remainingTimeSec := utils.TimeParseStd(eggSignIn.EndTime).Unix() - now.Unix() | |||
remainingTime := decimal.NewFromInt(remainingTimeSec).Div(decimal.NewFromInt(60 * 60)) | |||
remainingEggEnergy := decimal.NewFromInt(remainingTimeSec).Mul(estimatePerSecondEggEnergyValue) | |||
remainingAmount := remainingEggEnergy.Div(ratio) | |||
// 预估收益 | |||
estimatedRevenue := consumedAmount.Add(remainingAmount) | |||
estimatedRevenue := consumedEggEnergy.Add(remainingEggEnergy) | |||
// 基础速率 / 每小时 | |||
basalRateDecimal, err := decimal.NewFromString(eggSignIn.EstimatePerSecondPersonEggEnergyValue) | |||
if err != nil { | |||
@@ -109,11 +109,10 @@ func HomePage(c *gin.Context) { | |||
e.OutErr(c, e.ERR_DB_ORM, nil) | |||
return | |||
} | |||
signEggEnergyValue, _ := decimal.NewFromString(signPersonalEggEnergy) | |||
personEggEnergyValue, _ := decimal.NewFromString(personEggEnergy.Amount) | |||
teamEggEnergyValue, _ := decimal.NewFromString(teamEggEnergy.Amount) | |||
totalEggEnergy, _ = signEggEnergyValue.Add(personEggEnergyValue).Add(teamEggEnergyValue).Float64() | |||
totalEggEnergy, _ = personEggEnergyValue.Add(teamEggEnergyValue).Float64() | |||
//4、活跃积分(个人+团队) | |||
var totalActivePoints float64 | |||
@@ -268,6 +267,7 @@ func HomePageWatchAdRule(c *gin.Context) { | |||
"nextWatchAdDate": nextWatchAdDate, | |||
"next_watch_ad_times": nextWatchAdTimes, | |||
"uid": utils.Int64ToStr(user.Id), | |||
"roundRemainingSecs": roundRemainingSecs, | |||
"time": time.Now().Format("2006-01-02 15:04:05.000"), | |||
})) | |||
@@ -378,39 +378,55 @@ func IsCanSignIn(c *gin.Context) { | |||
return | |||
} | |||
//1、查找 `OneCirclesPublicPlatoonBasicSetting` 基础设置 | |||
energyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db) | |||
eggEnergyBasicSetting, err := energyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{ | |||
"key": "is_open", | |||
"value": 1, | |||
}) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
var videoRewardSystem *md2.VideoRewardSystemStruct | |||
err = json.Unmarshal([]byte(eggEnergyBasicSetting.VideoRewardSystem), &videoRewardSystem) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
rewardTotalNum := utils.StrToInt(videoRewardSystem.RewardTotalNum) | |||
//2、查询当前用户观看视屏记录 | |||
watchRecordsDb := implement.NewEggEnergyUserWatchRecordsDb(db.Db) | |||
userWatchRecords, err := watchRecordsDb.EggEnergyUserWatchRecordsGetOneByParams(map[string]interface{}{ | |||
"key": "uid", | |||
"value": user.Id, | |||
}) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
var isCan bool | |||
now := time.Now() | |||
if userWatchRecords != nil && userWatchRecords.ResidueWatchAdNum == rewardTotalNum && userWatchRecords.NextWatchAdDate.After(now) { | |||
isCan = true | |||
cacheKey := fmt.Sprintf("IsCanSignIn:%d", user.Id) | |||
var isCan bool | |||
if cache.Exists(cacheKey) { | |||
isCan = false | |||
} else { | |||
signInDb := implement.NewEggSignInDb(db.Db) | |||
nowStr := now.Format("2006-01-02 15:04:05") | |||
has, _, err := signInDb.EggSignINGetOneByTimeAndUid("", nowStr, user.Id, 0) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if has { | |||
isCan = false | |||
} else { | |||
//1、查找 `OneCirclesPublicPlatoonBasicSetting` 基础设置 | |||
energyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db) | |||
eggEnergyBasicSetting, err := energyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{ | |||
"key": "is_open", | |||
"value": 1, | |||
}) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
var videoRewardSystem *md2.VideoRewardSystemStruct | |||
err = json.Unmarshal([]byte(eggEnergyBasicSetting.VideoRewardSystem), &videoRewardSystem) | |||
if err != nil { | |||
e.OutErr(c, e.ERR, err.Error()) | |||
return | |||
} | |||
rewardTotalNum := utils.StrToInt(videoRewardSystem.RewardTotalNum) | |||
//2、查询当前用户观看视屏记录 | |||
watchRecordsDb := implement.NewEggEnergyUserWatchRecordsDb(db.Db) | |||
userWatchRecords, err := watchRecordsDb.EggEnergyUserWatchRecordsGetOneByParams(map[string]interface{}{ | |||
"key": "uid", | |||
"value": user.Id, | |||
}) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
if userWatchRecords != nil && userWatchRecords.ResidueWatchAdNum == rewardTotalNum && userWatchRecords.NextWatchAdDate.After(now) { | |||
isCan = true | |||
} | |||
} | |||
} | |||
utils.FilePutContents("HomePageIsCanSignIn", utils.SerializeStr(map[string]interface{}{ | |||
@@ -422,6 +438,8 @@ func IsCanSignIn(c *gin.Context) { | |||
resp := md.IsCanSignInResp{ | |||
IsCan: isCan, | |||
} | |||
cache.SetEx(cacheKey, "run", 30) | |||
e.OutSuc(c, resp, nil) | |||
return | |||
} | |||
@@ -9,7 +9,7 @@ type HomePageResp struct { | |||
NowBasalRate string `json:"now_basal_rate"` // 当前基础速率/小时 | |||
NowTeamRate string `json:"now_team_rate"` // 当前团队速率/小时 | |||
NickName string `json:"nick_name"` // 用户名称 | |||
LeaveTimer string `json:"leave_timer"` //可签到剩余时间 秒 | |||
LeaveTimer string `json:"leave_timer"` // 可签到剩余时间 秒 | |||
} | |||
type HomePageWatchAdRuleResp struct { | |||
@@ -227,7 +227,7 @@ func rCircleFriends(r *gin.RouterGroup) { | |||
r.DELETE("/commentDelete/:comment_index_id", friend_circle.CommentDelete) // 删除评论 | |||
r.GET("/commentLike", friend_circle.CommentLike) // 点赞评论 | |||
r.POST("/commentCancelLike", friend_circle.CommentCancelLike) // 取消点赞评论 | |||
r.GET("/commentCancelLike", friend_circle.CommentCancelLike) // 取消点赞评论 | |||
} | |||
func rComm(r *gin.RouterGroup) { | |||
@@ -57,9 +57,10 @@ func IsCanComment(c *gin.Context) (isCan bool, err error) { | |||
} | |||
total := searchResult.TotalHits() | |||
if int(total) >= eggFriendCircleBasic.CommentNumsEveryDay { | |||
err = errors.New("今日朋友圈发布数量已达上限~") | |||
err = errors.New("今日评论发布数量已达上限~") | |||
return | |||
} | |||
isCan = true | |||
return | |||
} | |||
@@ -3,6 +3,7 @@ package svc | |||
import ( | |||
"applet/app/db" | |||
"applet/app/db/im/model" | |||
"applet/app/e" | |||
"applet/app/md/friend_circles" | |||
"applet/app/svc" | |||
"applet/app/utils/logx" | |||
@@ -65,6 +66,7 @@ func IsCanPublish(c *gin.Context) (isCan bool, err error) { | |||
err = errors.New("今日朋友圈发布数量已达上限~") | |||
return | |||
} | |||
isCan = true | |||
return | |||
} | |||
@@ -75,12 +77,20 @@ func MySelfList(c *gin.Context, req friend_circles.MySelfListReq) (resp friend_c | |||
var friends []*model.Friend | |||
err = db.DbIm.Where("`user_id`=?", user.Id).Limit(5000).Find(&friends) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
var friendIDs []interface{} | |||
for _, v := range friends { | |||
friendIDs = append(friendIDs, v.FriendId) | |||
} | |||
var imUser model.User | |||
_, err = db.DbIm.Where("phone_number = ?", user.Phone).Get(&imUser) | |||
if err != nil { | |||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | |||
return | |||
} | |||
friendIDs = append(friendIDs, imUser.Id) | |||
// 分页参数 | |||
from := (req.Page - 1) * req.PageSize | |||
@@ -98,7 +108,6 @@ func MySelfList(c *gin.Context, req friend_circles.MySelfListReq) (resp friend_c | |||
Pretty(true). | |||
Do(context.Background()) | |||
if err != nil { | |||
logx.Fatalf("Error searching for documents: %v", err) | |||
return | |||
} | |||
@@ -115,9 +124,10 @@ func MySelfList(c *gin.Context, req friend_circles.MySelfListReq) (resp friend_c | |||
return | |||
} | |||
doc.CircleIndexId = hit.Id | |||
likeId := svc3.GetEggFriendCircleLikeEsIndexId(user.Id, hit.Index) | |||
likeDoc, _ := es.FirstDoc(md.EggFriendCircleLikeEsAlias, likeId) | |||
if likeDoc.Found { // 表示已点赞 | |||
likeEsIndex := svc3.GetEggFriendCircleLikeEsIndex(user.Id) | |||
likeId := svc3.GetEggFriendCircleLikeEsIndexId(user.Id, hit.Id) | |||
likeDoc, _ := es.FirstDoc(likeEsIndex, likeId) | |||
if likeDoc != nil && likeDoc.Found { // 表示已点赞 | |||
doc.IsLike = true | |||
} | |||
resp.List = append(resp.List, doc) | |||
@@ -179,9 +189,9 @@ func CommentList(req friend_circles.CommentListReq) (resp friend_circles.Comment | |||
searchResult, err := es.EsClient.Search(). | |||
Index(md.EggFriendCircleCommentEsAlias). // 替换为你的索引名称 | |||
Query(query). | |||
Sort("create_at", false). // 按时间倒排 | |||
From(from). | |||
Size(req.PageSize). | |||
Sort("created_at", false). // 按时间倒排 | |||
Pretty(true). | |||
Do(context.Background()) | |||
if err != nil { | |||
@@ -229,7 +239,7 @@ func CommentDetail(req friend_circles.CommentDetailReq) (resp friend_circles.Com | |||
searchResult, err := es.EsClient.Search(). | |||
Index(md.EggFriendCircleCommentEsAlias). // 替换为你的索引名称 | |||
Query(query). | |||
Sort("create_at", false). // 按时间倒排 | |||
Sort("created_at", false). // 按时间倒排 | |||
From(from). | |||
Size(req.PageSize). | |||
Pretty(true). | |||
@@ -293,7 +303,7 @@ func DelFriendCircleComment(circleId string) (err error) { | |||
searchResult, err = es.EsClient.Search(). | |||
Index(md.EggFriendCircleCommentEsAlias). // 替换为你的索引名称 | |||
Query(query). | |||
Sort("create_at", true). | |||
Sort("created_at", true). | |||
From(from). | |||
Size(limit). | |||
Pretty(true). | |||
@@ -47,28 +47,28 @@ db_back: | |||
show_log: true | |||
path: 'tmp/%s.log' | |||
#im_db: | |||
# host: '119.23.182.117:3306' | |||
# name: 'egg-im' | |||
# user: 'root' | |||
# psw: 'Fnuo123com@' | |||
# show_log: true | |||
# max_lifetime: 30 | |||
# max_open_conns: 100 | |||
# max_idle_conns: 100 | |||
# path: 'tmp/%s.log' | |||
im_db: | |||
host: 'advertisement-db.rwlb.rds.aliyuncs.com:3306' | |||
host: '119.23.182.117:3306' | |||
name: 'egg-im' | |||
user: 'canal' | |||
psw: 'DengBiao@1997' | |||
user: 'root' | |||
psw: 'Fnuo123com@' | |||
show_log: true | |||
max_lifetime: 30 | |||
max_open_conns: 100 | |||
max_idle_conns: 100 | |||
path: 'tmp/%s.log' | |||
#im_db: | |||
# host: 'advertisement-db.rwlb.rds.aliyuncs.com:3306' | |||
# name: 'egg-im' | |||
# user: 'canal' | |||
# psw: 'DengBiao@1997' | |||
# show_log: true | |||
# max_lifetime: 30 | |||
# max_open_conns: 100 | |||
# max_idle_conns: 100 | |||
# path: 'tmp/%s.log' | |||
# 日志 | |||
log: | |||
app_name: 'applet' | |||
@@ -34,7 +34,7 @@ require ( | |||
require ( | |||
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241217110120-62a0f203ce90 | |||
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241217121546-d895a4983b84 | |||
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241218083435-34181bb6bcbc | |||
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 | |||
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible | |||