From d9030679ddd97bb4dfb528ecf2d4abb2613bf024 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Sun, 22 Dec 2024 15:28:33 +0800 Subject: [PATCH] =?UTF-8?q?=E9=82=80=E8=AF=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/hdl/hdl_config.go | 11 ++++-- app/hdl/hdl_user.go | 90 +++++++++++++++++++++---------------------- app/md/md_config.go | 24 ++++++------ app/svc/svc_common.go | 42 ++++++++++++++++++++ 4 files changed, 107 insertions(+), 60 deletions(-) diff --git a/app/hdl/hdl_config.go b/app/hdl/hdl_config.go index 45df7fb..43a7bdf 100644 --- a/app/hdl/hdl_config.go +++ b/app/hdl/hdl_config.go @@ -55,9 +55,14 @@ func Config(c *gin.Context) { SeoLogo: svc.GetOssUrl(svc.GetSysCfgStr("seo_logo")), WebLogo: svc.GetOssUrl(svc.GetSysCfgStr("web_logo")), } - link := svc.GetSysCfgStr("kuaizhan_url") - link += "?type=download" - res.DownViewUrl = link + + res.DownViewUrl, res.RegisterViewUrl = svc.DownUrl(c) + if res.DownViewUrl == "" { + link := svc.GetSysCfgStr("kuaizhan_url") + link += "?type=download" + res.DownViewUrl = link + } + res.DownWebOpen = svc.GetSysCfgStr("down_web_open") e.OutSuc(c, res, nil) return } diff --git a/app/hdl/hdl_user.go b/app/hdl/hdl_user.go index 0bfb9bc..2af3c5f 100644 --- a/app/hdl/hdl_user.go +++ b/app/hdl/hdl_user.go @@ -3,8 +3,6 @@ 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" @@ -13,19 +11,15 @@ 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" "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" - "context" "encoding/json" "fmt" "github.com/gin-gonic/gin" - "github.com/olivere/elastic/v7" "github.com/syyongx/php2go" - "github.com/tidwall/gjson" "strings" "time" ) @@ -323,7 +317,7 @@ func UpdatePasscode(c *gin.Context) { func InviteUrl(c *gin.Context) { user := svc.GetUser(c) - link := svc.GetSysCfgStr("kuaizhan_url") + link := svc.GetSysCfgStr("kuaizhan_url") + "?type=" res := md.InviteUrl{ Link: "", InviteCode: user.SystemInviteCode, @@ -331,45 +325,49 @@ func InviteUrl(c *gin.Context) { if user.CustomInviteCode != "" { res.InviteCode = user.CustomInviteCode } - 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) - } - } - } + _, registerViewUrl := svc.DownUrl(c) + if registerViewUrl != "" { + 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) + // } + // } + //} res.Link = link QRcode := qrcode.GetPNGBase64(link) QRcode = strings.ReplaceAll(QRcode, "\u0000", "") diff --git a/app/md/md_config.go b/app/md/md_config.go index ad52d5f..e8aa170 100644 --- a/app/md/md_config.go +++ b/app/md/md_config.go @@ -1,17 +1,19 @@ package md type ConfigResp struct { - Title string `json:"title" example:"软件使用协议标题"` - Content string `json:"content" example:"软件使用协议内容"` - UserTitle string `json:"user_title" example:"用户协议标题"` - UserUrl string `json:"user_url" example:"用户协议链接"` - PrivacyTitle string `json:"privacy_title" example:"隐私协议标题"` - PrivacyUrl string `json:"privacy_url" example:"隐私协议链接"` - OssUrl string `json:"oss_url" example:"阿里云图片链接"` - Guide []Guide `json:"guide"` - DownUrl string `json:"down_url"` - DownViewUrl string `json:"down_view_url"` - Seo Seo `json:"seo"` + Title string `json:"title" example:"软件使用协议标题"` + Content string `json:"content" example:"软件使用协议内容"` + UserTitle string `json:"user_title" example:"用户协议标题"` + UserUrl string `json:"user_url" example:"用户协议链接"` + PrivacyTitle string `json:"privacy_title" example:"隐私协议标题"` + PrivacyUrl string `json:"privacy_url" example:"隐私协议链接"` + OssUrl string `json:"oss_url" example:"阿里云图片链接"` + Guide []Guide `json:"guide"` + DownUrl string `json:"down_url"` + DownViewUrl string `json:"down_view_url"` + RegisterViewUrl string `json:"register_view_url"` + DownWebOpen string `json:"down_web_open"` + Seo Seo `json:"seo"` } type Seo struct { SeoTitle string `json:"seo_title" example:"seo"` diff --git a/app/svc/svc_common.go b/app/svc/svc_common.go index 17bb9a5..70c31f0 100644 --- a/app/svc/svc_common.go +++ b/app/svc/svc_common.go @@ -7,7 +7,10 @@ import ( "applet/app/utils/logx" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + "encoding/json" + "fmt" "github.com/gin-gonic/gin" + "math/rand" "strings" "time" ) @@ -135,3 +138,42 @@ func GetWeekInfo(dateStr string) (string, string, string, string) { weekEnd := weekStart.AddDate(0, 0, 6) return utils.IntToStr(year), utils.IntToStr(week), weekStart.Format("2006-01-02"), weekEnd.Format("2006-01-02") } + +func DownUrl(c *gin.Context) (string, string) { + downDomainStr := GetSysCfgStr("down_web_domain") + registerDomainStr := GetSysCfgStr("down_register_domain") + var downDomainArr = make([]string, 0) + json.Unmarshal([]byte(downDomainStr), &downDomainArr) + downDomain := "" + registerDomain := "" + if len(downDomainArr) > 0 { + rand.Seed(time.Now().UnixNano()) + num := rand.Intn(len(downDomainArr)) + if num == 0 { + num = 1 + } + num-- + downDomain = downDomainArr[num] + } + var registerDomainArr = make([]string, 0) + json.Unmarshal([]byte(registerDomainStr), ®isterDomainArr) + if len(registerDomainArr) > 0 { + rand.Seed(time.Now().UnixNano()) + num := rand.Intn(len(registerDomainArr)) + if num == 0 { + num = 1 + } + num-- + registerDomain = registerDomainArr[num] + } + downUrl := "" + registerUrl := "" + if downDomain != "" { + downUrl = fmt.Sprintf("%s%s%s", "https://", downDomain, "/#/pages/down-page/down-page?type=download") + } + if registerDomain != "" { + registerUrl = fmt.Sprintf("%s%s%s", "https://", registerDomain, "/#/pages/down-page/down-page?type=") + } + + return downUrl, registerUrl +}