劲创营---任务项目
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

87 linhas
2.2 KiB

  1. package svc
  2. import (
  3. "applet/app/comm/db"
  4. "applet/app/comm/db/model"
  5. "applet/app/comm/utils"
  6. "applet/app/comm/utils/logx"
  7. "errors"
  8. "github.com/gin-gonic/gin"
  9. "github.com/tidwall/gjson"
  10. "strings"
  11. )
  12. // 获取指定类型的域名:admin、wap、api
  13. func GetWebSiteDomainInfo(c *gin.Context, domainType string) string {
  14. if domainType == "" {
  15. domainType = "wap"
  16. }
  17. domainSetting := SysCfgGet(c, "domain_setting")
  18. domainTypePath := domainType + ".type"
  19. domainSslPath := domainType + ".isOpenHttps"
  20. domainPath := domainType + ".domain"
  21. domainTypeValue := gjson.Get(domainSetting, domainTypePath).String()
  22. domainSslValue := gjson.Get(domainSetting, domainSslPath).String()
  23. domain := gjson.Get(domainSetting, domainPath).String()
  24. scheme := "http://"
  25. if domainSslValue == "1" {
  26. scheme = "https://"
  27. }
  28. // 有自定义域名 返回自定义的
  29. if domainTypeValue == "own" && domain != "" {
  30. return scheme + domain
  31. }
  32. // 否则返回官方的
  33. official, err := db.GetOfficialDomainInfoByType(db.Db, c.GetString("mid"), domainType)
  34. if err != nil {
  35. _ = logx.Warn(errors.New("Get Official Domain Fail!"))
  36. return ""
  37. }
  38. if strings.Contains(official, "http") {
  39. return official
  40. }
  41. return scheme + official
  42. }
  43. func GetWebSiteDomainInfoOfficial(c *gin.Context, domainType string) string {
  44. if domainType == "" {
  45. domainType = "wap"
  46. }
  47. domainSetting := SysCfgGet(c, "domain_setting")
  48. domainSslPath := domainType + ".isOpenHttps"
  49. domainSslValue := gjson.Get(domainSetting, domainSslPath).String()
  50. scheme := "http://"
  51. if domainSslValue == "1" {
  52. scheme = "https://"
  53. }
  54. // 否则返回官方的
  55. official, err := db.GetOfficialDomainInfoByType(db.Db, c.GetString("mid"), domainType)
  56. if err != nil {
  57. _ = logx.Warn(errors.New("Get Official Domain Fail!"))
  58. return ""
  59. }
  60. if strings.Contains(official, "http") {
  61. return official
  62. }
  63. return scheme + official
  64. }
  65. // 获取指定类型的域名对应的masterId:admin、wap、api
  66. func GetWebSiteDomainMasterId(domainType string, host string) string {
  67. obj := new(model.UserAppDomain)
  68. has, err := db.Db.Where("domain=? and type=?", host, domainType).Get(obj)
  69. if err != nil || !has {
  70. return ""
  71. }
  72. return utils.AnyToString(obj.Uuid)
  73. }