附近小店
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

156 líneas
5.0 KiB

  1. package mw
  2. import (
  3. "applet/app/svc"
  4. "applet/app/utils"
  5. "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/mw"
  6. "errors"
  7. "fmt"
  8. "github.com/gin-gonic/gin"
  9. "strings"
  10. "applet/app/db"
  11. "applet/app/e"
  12. "applet/app/md"
  13. )
  14. // DB is 中间件 用来检查master_id是否有对应的数据库engine
  15. func DB(c *gin.Context) {
  16. fmt.Println(c.Request.Header)
  17. masterID := mw.GetMasterId(db.Db, c)
  18. if masterID == "" {
  19. masterID = svc.GetWebSiteDomainMasterId("userStoreAgent", c.Request.Host)
  20. }
  21. if masterID == "" {
  22. masterID = svc.GetWebSiteDomainMasterId("userStoreStore", c.Request.Host)
  23. }
  24. _, ok := db.DBs[masterID]
  25. if !ok {
  26. e.OutErr(c, e.ERR_MASTER_ID, errors.New("not found master_id in DBs"))
  27. return
  28. }
  29. fmt.Println("master_id", masterID)
  30. c.Set("mid", masterID)
  31. //判断应用是不是过期了
  32. isOverTime := svc.SysCfgGet(c, "is_over_time")
  33. if isOverTime == "1" {
  34. str := "应用已过期"
  35. overTimeStr := svc.SysCfgGet(c, "over_time_str")
  36. if overTimeStr != "" {
  37. str = overTimeStr
  38. }
  39. e.OutErr(c, 400, e.NewErr(400, str))
  40. return
  41. }
  42. closeStation := svc.SysCfgGet(c, "close_station")
  43. closeAppVersion := svc.SysCfgGet(c, "close_app_version")
  44. platform := c.GetHeader("Platform")
  45. if strings.Contains(closeStation, platform) && closeStation != "" && utils.StrToInt64(c.GetHeader("app_version")) <= utils.StrToInt64(closeAppVersion) {
  46. str := "应用关闭"
  47. overTimeStr := svc.SysCfgGet(c, "over_time_str")
  48. if overTimeStr != "" {
  49. str = overTimeStr
  50. }
  51. e.OutErr(c, 400, e.NewErr(400, str))
  52. return
  53. }
  54. //判断是否有独立域名
  55. domainWapBase := svc.GetWebSiteDomainInfo(c, "wap")
  56. httpStr := "http://"
  57. if c.GetHeader("Platform") == md.PLATFORM_WX_APPLET || c.GetHeader("Platform") == md.PLATFORM_ALIPAY_APPLET || c.GetHeader("Platform") == md.PLATFORM_BAIDU_APPLET || c.GetHeader("Platform") == md.PLATFORM_TOUTIAO_APPLET || c.GetHeader("Platform") == md.PLATFORM_TIKTOK_APPLET {
  58. httpStr = "https://"
  59. domainWapBase = strings.Replace(domainWapBase, "http://", httpStr, 1)
  60. }
  61. c.Set("domain_wap_base", domainWapBase)
  62. c.Set("domain_wap_base_new", svc.GetWebSiteLiveBroadcastDomainInfo(c, "wap", masterID))
  63. c.Set("domain_wap_base_second", svc.GetWebSiteDomainInfoSecond(c, "wap"))
  64. c.Set("http_host", httpStr)
  65. c.Set("h5_api_secret_key", svc.SysCfgGet(c, "h5_api_secret_key"))
  66. c.Set("app_api_secret_key", svc.SysCfgGet(c, "app_api_secret_key"))
  67. c.Set("applet_api_secret_key", svc.SysCfgGet(c, "applet_api_secret_key"))
  68. c.Set("integral_prec", svc.SysCfgGet(c, "integral_prec"))
  69. fanOrderCommissionPrec := svc.SysCfgGet(c, "fan_order_commission_prec")
  70. if fanOrderCommissionPrec == "" {
  71. fanOrderCommissionPrec = "2"
  72. }
  73. c.Set("fan_order_commission_prec", fanOrderCommissionPrec)
  74. areaOrderCommissionPrec := svc.SysCfgGet(c, "area_order_commission_prec")
  75. if areaOrderCommissionPrec == "" {
  76. areaOrderCommissionPrec = "2"
  77. }
  78. c.Set("area_order_commission_prec", areaOrderCommissionPrec)
  79. commissionPrec := svc.SysCfgGet(c, "commission_prec")
  80. c.Set("commission_prec", commissionPrec)
  81. pricePrec := svc.SysCfgGet(c, "price_prec")
  82. if pricePrec == "" {
  83. pricePrec = commissionPrec
  84. }
  85. dsChcek := svc.SysCfgGet(c, "ds_check")
  86. if dsChcek == "1" {
  87. pricePrec = commissionPrec
  88. }
  89. c.Set("price_prec", pricePrec)
  90. c.Set("is_show_point", svc.SysCfgGet(c, "is_show_point"))
  91. c.Set("appUserDefaultAvatar", svc.SysCfgGet(c, "app_user_default_avatar"))
  92. translateOpen := ""
  93. if strings.Contains(c.GetHeader("locale"), "zh_Hant_") {
  94. translateOpen = "zh_Hant_"
  95. }
  96. if strings.Contains(c.GetHeader("locale"), "ug_CN") {
  97. translateOpen = "ug_CN"
  98. }
  99. c.Set("translate_open", translateOpen)
  100. orderVirtualCoinType := db.SysCfgGet(c, "order_virtual_coin_type")
  101. c.Set("order_virtual_coin_type", orderVirtualCoinType)
  102. orderVirtualCoinName := db.SysCfgGet(c, "order_virtual_coin_name")
  103. if orderVirtualCoinName == "" {
  104. orderVirtualCoinName = "收益:¥"
  105. }
  106. c.Set("orderVirtualCoinName", orderVirtualCoinName)
  107. h5AppletMustSign := svc.SysCfgGet(c, "h5_applet_must_sign")
  108. c.Set("h5_applet_must_sign", h5AppletMustSign)
  109. androidMustSign := svc.SysCfgGet(c, "android_must_sign")
  110. c.Set("android_must_sign", androidMustSign)
  111. iosMustSign := svc.SysCfgGet(c, "ios_must_sign")
  112. c.Set("ios_must_sign", iosMustSign)
  113. c.Set("is_not_change_url", "0")
  114. smsType := svc.SysCfgGet(c, "sms_type")
  115. c.Set("sms_type", smsType)
  116. if utils.StrToInt64(c.GetHeader("app_version")) > 1678445020 {
  117. // || utils.StrToInt64(c.GetHeader("BuildVersion")) > 1678676004
  118. c.Set("is_not_change_url", "1")
  119. }
  120. if utils.InArr(c.GetHeader("platform"), []string{md.PLATFORM_ANDROID, md.PLATFORM_IOS}) == false {
  121. c.Set("is_not_change_url", "1")
  122. }
  123. GetHeaderParam(c)
  124. c.Next()
  125. }
  126. func GetHeaderParam(c *gin.Context) {
  127. var appTypeList = []string{"app_type", "App_type", "AppType"}
  128. appType := ""
  129. for _, v := range appTypeList {
  130. val := c.GetHeader(v)
  131. if val != "" {
  132. appType = val
  133. }
  134. }
  135. c.Set("app_type", appType)
  136. var storeIdList = []string{"store_id", "Store_id", "StoreId"}
  137. storeId := ""
  138. for _, v := range storeIdList {
  139. val := c.GetHeader(v)
  140. if val != "" {
  141. storeId = val
  142. }
  143. }
  144. c.Set("store_id", storeId)
  145. }