wangchuanjin 2 年 前
コミット
a22dc50334
1 ファイル変更44 行追加21 行削除
  1. 44 21
      compatible/compatible.go

+ 44 - 21
compatible/compatible.go

@@ -80,29 +80,53 @@ func (c *Compatible) selectDo(id string, identity *pb.Identity, fd interface{})
 			}
 		}
 		if identity.EntUserId > 0 {
-			if (*field)["o_entniche"] != nil || (*field)["o_vipjy"] != nil || (*field)["o_member_jy"] != nil || (*field)["o_jy"] != nil {
-				entniche_rule, ok := c.Mgo.Find("entniche_rule", map[string]interface{}{
+			fms := []string{}
+			fmp := map[int]map[string]interface{}{}
+			for k, v := range *field {
+				if util.IntAll(v) <= 0 {
+					continue
+				}
+				if k == "o_entniche" || strings.HasPrefix(k, "o_entniche.") {
+					if fmp[0] == nil {
+						fmp[0] = map[string]interface{}{"_id": 0}
+					}
+					fmp[0][k] = 1
+				} else if k == "o_vipjy" || strings.HasPrefix(k, "o_vipjy.") {
+					if fmp[1] == nil {
+						fmp[1] = map[string]interface{}{"_id": 0}
+					}
+					fms = append(fms, "o_vipjy")
+					fmp[1][strings.ReplaceAll(k, "o_vipjy", "o_entniche")] = 1
+				} else if k == "o_member_jy" || strings.HasPrefix(k, "o_member_jy.") {
+					if fmp[1] == nil {
+						fmp[1] = map[string]interface{}{"_id": 0}
+					}
+					fms = append(fms, "o_member_jy")
+					fmp[1][strings.ReplaceAll(k, "o_member_jy", "o_entniche")] = 1
+				} else if k == "o_jy" || strings.HasPrefix(k, "o_jy.") {
+					if fmp[2] == nil {
+						fmp[2] = map[string]interface{}{"_id": 0}
+					}
+					fmp[2][strings.ReplaceAll(k, "o_jy", "o_entniche")] = 1
+				} else {
+					continue
+				}
+			}
+			for k, v := range fmp {
+				entniche_rule, ok := c.Mgo.FindOneByField("entniche_rule", map[string]interface{}{
 					"i_userid": identity.EntUserId,
-				}, nil, `{"_id":0,"o_entniche":1,"i_type":1}`, false, -1, -1)
+					"i_type":   k,
+				}, v)
+				log.Println(entniche_rule)
 				if ok && entniche_rule != nil && len(*entniche_rule) > 0 {
-					for _, v := range *entniche_rule {
-						i_type := util.IntAll(v["i_type"])
-						if i_type == 0 {
-							if (*field)["o_entniche"] != nil {
-								user["o_entniche"] = v["o_entniche"]
-							}
-						} else if i_type == 1 {
-							if (*field)["o_vipjy"] != nil {
-								user["o_vipjy"] = v["o_entniche"]
-							}
-							if (*field)["o_member_jy"] != nil {
-								user["o_member_jy"] = v["o_entniche"]
-							}
-						} else if i_type == 2 {
-							if (*field)["o_jy"] != nil {
-								user["o_jy"] = v["o_entniche"]
-							}
+					if k == 0 {
+						user["o_entniche"] = (*entniche_rule)["o_entniche"]
+					} else if k == 1 {
+						for _, vv := range fms {
+							user[vv] = (*entniche_rule)["o_entniche"]
 						}
+					} else if k == 2 {
+						user["o_jy"] = (*entniche_rule)["o_entniche"]
 					}
 				}
 			}
@@ -199,7 +223,6 @@ func (c *Compatible) updateDo(id string, identity *pb.Identity, update map[strin
 			}, up1, true, false)
 		}
 		if len(up2) > 0 {
-			log.Println("update----", up2)
 			ok2 = c.Mgo.Update("entniche_rule", map[string]interface{}{
 				"i_entid":  identity.EntId,
 				"i_userid": identity.EntUserId,