附近小店
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

svc_domain_info.go 5.5 KiB

pirms 2 mēnešiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/db/model"
  5. "applet/app/db/offical"
  6. "applet/app/md"
  7. "applet/app/utils"
  8. "applet/app/utils/logx"
  9. "github.com/gin-gonic/gin"
  10. "github.com/tidwall/gjson"
  11. "strings"
  12. )
  13. // 获取指定类型的域名:admin、wap、api
  14. func GetWebSiteDomainInfo(c *gin.Context, domainType string) string {
  15. if domainType == "" {
  16. domainType = "wap"
  17. }
  18. domainSetting := SysCfgGet(c, "domain_setting")
  19. domainTypePath := domainType + ".type"
  20. domainSslPath := domainType + ".isOpenHttps"
  21. domainPath := domainType + ".domain"
  22. domainTypeValue := gjson.Get(domainSetting, domainTypePath).String()
  23. domainSslValue := gjson.Get(domainSetting, domainSslPath).String()
  24. domain := gjson.Get(domainSetting, domainPath).String()
  25. scheme := "http://"
  26. if domainSslValue == "1" {
  27. scheme = "https://"
  28. }
  29. // 有自定义域名 返回自定义的
  30. if domainTypeValue == "own" && domain != "" {
  31. return scheme + domain
  32. }
  33. // 否则返回官方的
  34. official, err := db.GetOfficialDomainInfoByType(db.Db, c.GetString("mid"), domainType)
  35. if err != nil {
  36. _ = logx.Errorf("Get Official Domain Fail! %s", err)
  37. return ""
  38. }
  39. if strings.Contains(official, "http") {
  40. return official
  41. }
  42. return scheme + official
  43. }
  44. func GetWebSiteDomainInfoToAgent(c *gin.Context, domainType string) string {
  45. if domainType == "" {
  46. domainType = "wap"
  47. }
  48. domainSetting := SysCfgGet(c, "domain_setting")
  49. domainTypePath := domainType + ".type"
  50. domainSslPath := domainType + ".isOpenHttps"
  51. domainPath := domainType + ".domain"
  52. domainTypeValue := gjson.Get(domainSetting, domainTypePath).String()
  53. domainSslValue := gjson.Get(domainSetting, domainSslPath).String()
  54. domain := gjson.Get(domainSetting, domainPath).String()
  55. scheme := "http://"
  56. if domainSslValue == "1" {
  57. scheme = "https://"
  58. }
  59. // 有自定义域名 返回自定义的
  60. if domainTypeValue == "own" && domain != "" {
  61. return scheme + domain
  62. }
  63. // 否则返回官方的
  64. puid := AppUserListPuid(c)
  65. var official = ""
  66. var err error
  67. if puid != "" && puid != "0" {
  68. official, err = db.GetOfficialDomainInfoByTypeToAgent(db.Db, c.GetString("mid"), puid, domainType)
  69. if err != nil {
  70. _ = logx.Errorf("Get Official Domain Fail! %s", err)
  71. return ""
  72. }
  73. } else {
  74. official, err = db.GetOfficialDomainInfoByType(db.Db, c.GetString("mid"), domainType)
  75. if err != nil {
  76. _ = logx.Errorf("Get Official Domain Fail! %s", err)
  77. return ""
  78. }
  79. }
  80. if strings.Contains(official, "http") {
  81. return official
  82. }
  83. return scheme + official
  84. }
  85. func GetWebSiteDomainInfoOfficial(c *gin.Context, domainType string) string {
  86. if domainType == "" {
  87. domainType = "wap"
  88. }
  89. domainSetting := SysCfgGet(c, "domain_setting")
  90. domainSslPath := domainType + ".isOpenHttps"
  91. domainSslValue := gjson.Get(domainSetting, domainSslPath).String()
  92. scheme := "http://"
  93. if domainSslValue == "1" {
  94. scheme = "https://"
  95. }
  96. // 有自定义域名 返回自定义的
  97. // 否则返回官方的
  98. official, err := db.GetOfficialDomainInfoByType(db.Db, c.GetString("mid"), domainType)
  99. if err != nil {
  100. _ = logx.Errorf("Get Official Domain Fail! %s", err)
  101. return ""
  102. }
  103. if strings.Contains(official, "http") {
  104. return official
  105. }
  106. return scheme + official
  107. }
  108. // 获取指定类型的域名对应的masterId:admin、wap、api
  109. func GetWebSiteDomainMasterId(domainType string, host string) string {
  110. obj := new(model.UserAppDomain)
  111. has, err := db.Db.Where("domain=? and type=?", host, domainType).Get(obj)
  112. if err != nil || !has {
  113. return ""
  114. }
  115. return utils.AnyToString(obj.Uuid)
  116. }
  117. func GetWebSiteAppSmsPlatform(mid string) string {
  118. obj := new(model.UserAppList)
  119. has, err := db.Db.Where("uuid=? ", mid).Asc("id").Get(obj)
  120. if err != nil || !has {
  121. return ""
  122. }
  123. return utils.AnyToString(obj.SmsPlatform)
  124. }
  125. // 获取指定类型的域名:admin、wap、api
  126. func GetWebSiteLiveBroadcastDomainInfo(c *gin.Context, domainType, mid string) string {
  127. if domainType == "" {
  128. domainType = "wap"
  129. }
  130. domainSetting := SysCfgGet(c, "domain_setting")
  131. domainSslPath := domainType + ".isOpenHttps"
  132. domainSslValue := gjson.Get(domainSetting, domainSslPath).String()
  133. //masterid.izhyin.cn
  134. domain := mid + ".izhim.net"
  135. scheme := "http://"
  136. if domainSslValue == "1" {
  137. scheme = "https://"
  138. }
  139. if c.GetHeader("platform") == md.PLATFORM_WX_APPLET { //小程序需要https
  140. scheme = "https://"
  141. }
  142. return scheme + domain
  143. }
  144. func GetWebSiteDomainInfoSecond(c *gin.Context, domainType string) string {
  145. if domainType == "" {
  146. domainType = "wap"
  147. }
  148. domainSetting := SysCfgGet(c, "domain_setting")
  149. domainSslPath := domainType + ".isOpenHttps"
  150. domainSslValue := gjson.Get(domainSetting, domainSslPath).String()
  151. domain := c.GetString("mid") + ".izhim.net"
  152. domainTypePath := domainType + ".type"
  153. domainTypeValue := gjson.Get(domainSetting, domainTypePath).String()
  154. scheme := "http://"
  155. if domainSslValue == "1" {
  156. scheme = "https://"
  157. }
  158. if c.GetHeader("platform") == md.PLATFORM_WX_APPLET { //小程序需要https
  159. scheme = "https://"
  160. }
  161. // 有自定义域名 返回自定义的
  162. if domainTypeValue == "own" {
  163. domainPath := domainType + ".domain"
  164. domain = gjson.Get(domainSetting, domainPath).String()
  165. }
  166. return scheme + domain
  167. }
  168. func AppUserListPuid(c *gin.Context) string {
  169. appList := offical.GetUserAppList(c.GetString("mid"))
  170. uid := "0"
  171. if appList != nil && appList.Puid > 0 {
  172. uid = utils.IntToStr(appList.Puid)
  173. }
  174. return uid
  175. }
  176. func AppUserListPuidWithDb(dbName string) string {
  177. appList := offical.GetUserAppList(dbName)
  178. uid := "0"
  179. if appList != nil && appList.Puid > 0 {
  180. uid = utils.IntToStr(appList.Puid)
  181. }
  182. return uid
  183. }