附近小店
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.

mw_db.go 4.8 KiB

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