Ver código fonte

邀请

master
huangjiajun 10 horas atrás
pai
commit
9e46d86bab
1 arquivos alterados com 43 adições e 38 exclusões
  1. +43
    -38
      app/hdl/hdl_user.go

+ 43
- 38
app/hdl/hdl_user.go Ver arquivo

@@ -3,6 +3,8 @@ package hdl
import (
"applet/app/db"
"applet/app/e"
"applet/app/es/hdl"
md2 "applet/app/es/md"
"applet/app/lib/auth"
"applet/app/md"
"applet/app/svc"
@@ -11,6 +13,7 @@ import (
"applet/app/utils/qrcode"
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
"code.fnuoos.com/EggPlanet/egg_models.git/src/model"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/baidu"
md3 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md"
md4 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
es2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es"
@@ -19,7 +22,9 @@ import (
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"github.com/olivere/elastic/v7"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"strings"
"time"
)
@@ -330,44 +335,44 @@ func InviteUrl(c *gin.Context) {
link = registerViewUrl
}
link += "&inviteCode=" + res.InviteCode
//EggUserShortLink := md2.EggUserShortLink
//boolQueryToItem := elastic.NewBoolQuery() // 创建bool查询
//aggsMatch := elastic.NewMatchQuery("link", link) //设置查询条件
//boolQueryToItem.Must(aggsMatch)
//result, _ := hdl.EsSelectOne(context.Background(), EggUserShortLink, boolQueryToItem, false)
//isHas := 0
//if result != nil && len(result.Hits.Hits) > 0 {
// for _, hit := range result.Hits.Hits {
// if hit == nil {
// continue
// }
// jsonByte, _ := hit.Source.MarshalJSON()
// if gjson.Get(string(jsonByte), "short_link").String() != "" && gjson.Get(string(jsonByte), "date").Int() > time.Now().Unix() {
// isHas = 1
// link = gjson.Get(string(jsonByte), "short_link").String()
// }
// }
//}
//if isHas == 0 {
// url, _ := baidu.BaiduShortenUrl(svc.GetSysCfgStr("baidu_token"), link)
// if url != "" {
// var uniqueId = php2go.Md5(link)
// oldLink := link
// link = url
// tmp := map[string]interface{}{
// "uid": user.Id,
// "link": oldLink,
// "short_link": link,
// "date": time.Now().Unix() + 365*86400,
// }
// doc, _ := es.FirstDoc(EggUserShortLink, uniqueId)
// if doc == nil {
// es.CreateDoc(EggUserShortLink, uniqueId, tmp)
// } else {
// es.UpdateDoc(EggUserShortLink, uniqueId, tmp)
// }
// }
//}
EggUserShortLink := md2.EggUserShortLink
boolQueryToItem := elastic.NewBoolQuery() // 创建bool查询
aggsMatch := elastic.NewMatchQuery("link", link) //设置查询条件
boolQueryToItem.Must(aggsMatch)
result, _ := hdl.EsSelectOne(context.Background(), EggUserShortLink, boolQueryToItem, false)
isHas := 0
if result != nil && len(result.Hits.Hits) > 0 {
for _, hit := range result.Hits.Hits {
if hit == nil {
continue
}
jsonByte, _ := hit.Source.MarshalJSON()
if gjson.Get(string(jsonByte), "short_link").String() != "" && gjson.Get(string(jsonByte), "date").Int() > time.Now().Unix() {
isHas = 1
link = gjson.Get(string(jsonByte), "short_link").String()
}
}
}
if isHas == 0 {
url, _ := baidu.BaiduShortenUrl(svc.GetSysCfgStr("baidu_token"), link)
if url != "" {
var uniqueId = php2go.Md5(link)
oldLink := link
link = url
tmp := map[string]interface{}{
"uid": user.Id,
"link": oldLink,
"short_link": link,
"date": time.Now().Unix() + 365*86400,
}
doc, _ := es.FirstDoc(EggUserShortLink, uniqueId)
if doc == nil {
es.CreateDoc(EggUserShortLink, uniqueId, tmp)
} else {
es.UpdateDoc(EggUserShortLink, uniqueId, tmp)
}
}
}
res.Link = link
QRcode := qrcode.GetPNGBase64(link)
QRcode = strings.ReplaceAll(QRcode, "\u0000", "")


Carregando…
Cancelar
Salvar