Sfoglia il codice sorgente

获取身份证接口bug修复

maker 2 anni fa
parent
commit
c97aac5e62
1 ha cambiato i file con 12 aggiunte e 10 eliminazioni
  1. 12 10
      service/card/id_card.go

+ 12 - 10
service/card/id_card.go

@@ -31,18 +31,20 @@ func (s *IdCardService) GetIdCard(idCard cardReq.IdCardRequest) (list []card.IdC
 	db = db.Joins("left JOIN shuyou_id_card_usage as b on b.id_idCard = a.id")
 	db.Count(&total)
 
-	//将total转化为int
-	strInt64 := strconv.FormatInt(total, 10)
-	countInt ,_ := strconv.Atoi(strInt64)
-	//生成1个0-total之间的随机数
-	randomOffset := rand.Intn(countInt)
+	if total > 0 {
+		//将total转化为int
+		strInt64 := strconv.FormatInt(total, 10)
+		countInt, _ := strconv.Atoi(strInt64)
+		//生成1个0-total之间的随机数
+		randomOffset := rand.Intn(countInt)
 
-	db = db.Order("use_count").Limit(limit).Offset(randomOffset)
-	err = db.Find(&unionIdCardList).Error
-	if err != nil {
-		return nil, err
+		db = db.Order("use_count").Limit(limit).Offset(randomOffset)
+		err = db.Find(&unionIdCardList).Error
+		if err != nil {
+			return nil, err
+		}
+		fmt.Println(unionIdCardList)
 	}
-	fmt.Println(unionIdCardList)
 	//没有非这个渠道的记录
 	if total == 0 {
 		dbFail := global.GVA_DB.Table("shuyou_id_card as a")