Browse Source

update pc menu json

zou.yingbin 3 years ago
parent
commit
462b7bea53
2 changed files with 44 additions and 8 deletions
  1. 20 8
      controllers/user/user.go
  2. 24 0
      models/market.go

+ 20 - 8
controllers/user/user.go

@@ -323,21 +323,33 @@ func LoginQuery(c *gin.Context) {
 		}
 		}
 		rsp.Goodsgroups = goodsgroups
 		rsp.Goodsgroups = goodsgroups
 	}
 	}
+
 	// 外部交易所
 	// 外部交易所
 	rsp.ExternalExchanges = make([]models.Externalexchange, 0)
 	rsp.ExternalExchanges = make([]models.Externalexchange, 0)
 	if len(rsp.Goodsgroups) > 0 {
 	if len(rsp.Goodsgroups) > 0 {
 		exchangeIDs := make([]int, 0)
 		exchangeIDs := make([]int, 0)
+
+		// 过滤掉没有关联商品的交易所
+		id := models.GetAvalidExchangeId(rsp.UserAccount.Rootuserid)
+
 		for _, v := range rsp.Goodsgroups {
 		for _, v := range rsp.Goodsgroups {
-			exchangeIDs = append(exchangeIDs, int(v.Exexchangeid))
+			for i := range id {
+				if id[i] == v.Exexchangeid {
+					exchangeIDs = append(exchangeIDs, int(v.Exexchangeid))
+				}
+			}
 		}
 		}
-		exExchanges, err := models.GetExExchangeByIDs(exchangeIDs)
-		if err != nil {
-			// 查询失败
-			logger.GetLogger().Errorf("LoginQuery failed: %s", err.Error())
-			appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
-			return
+
+		if len(exchangeIDs) > 0 {
+			exExchanges, err := models.GetExExchangeByIDs(exchangeIDs)
+			if err != nil {
+				// 查询失败
+				logger.GetLogger().Errorf("LoginQuery failed: %s", err.Error())
+				appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+				return
+			}
+			rsp.ExternalExchanges = exExchanges
 		}
 		}
-		rsp.ExternalExchanges = exExchanges
 	}
 	}
 	// 系统参数
 	// 系统参数
 	systemParams, err := models.GetSystemParams()
 	systemParams, err := models.GetSystemParams()

+ 24 - 0
models/market.go

@@ -1,6 +1,7 @@
 package models
 package models
 
 
 import (
 import (
+	"fmt"
 	"mtp2_if/db"
 	"mtp2_if/db"
 	"strconv"
 	"strconv"
 	"time"
 	"time"
@@ -474,3 +475,26 @@ func GetAllExExchanges() ([]Externalexchange, error) {
 
 
 	return exExchanges, nil
 	return exExchanges, nil
 }
 }
+
+//GetAvalidExchangeId 风管云平台获取有关联商品的交易所id
+func GetAvalidExchangeId(userId int64) []int64 {
+	e := db.GetEngine()
+	sqlId := `
+	select g.exexchangeid
+	  from erms_middlegoods t
+	  left join goodsgroup g
+		on t.goodsgroupid = g.goodsgroupid
+	 where t.areauserid = %v
+`
+	sqlId = fmt.Sprintf(sqlId, userId)
+	type ExchangeId struct {
+		EXEXCHANGEID int64 `json:"AutoId"  xorm:"'exexchangeid'"`
+	}
+	sData := make([]ExchangeId, 0)
+	_ = e.SQL(sqlId).Find(&sData)
+	var sId []int64
+	for _, v := range sData {
+		sId = append(sId, v.EXEXCHANGEID)
+	}
+	return sId
+}