Przeglądaj źródła

Merge remote-tracking branch 'origin/main'

wkyuer 5 miesięcy temu
rodzic
commit
22bbe1d3c8
2 zmienionych plików z 21 dodań i 6 usunięć
  1. 1 0
      internal/model/orderParams.go
  2. 20 6
      utility/user.go

+ 1 - 0
internal/model/orderParams.go

@@ -60,6 +60,7 @@ type (
 		OrderCode          string   `json:"orderCode"`
 		ControlsType       int      `json:"controlsType"` //操作 保存 or 更新
 		UserId             string   `json:"userId"`
+		MgoId              string   `json:"mgoId"`
 		ProductType        string   `json:"productType,omitempty"`                  //产品类型
 		BuySubject         string   `form:"buySubject" json:"buySubject"`           //购买主体  1 个人, 2公司
 		BillingMode        string   `json:"billingMode"`                            //策略 购买 赠送

+ 20 - 6
utility/user.go

@@ -17,8 +17,9 @@ var (
 	ctx = context.Background()
 )
 
-// GetCreateUserData 查询用户 不存在注册用户
-func GetCreateUserData(phone string) map[string]interface{} {
+// GetCreateUserData 查询用户 不存在注册用户 isEntSign 是否需要注册企业信息(避免校验调用) 如entId不为0代办已注册企业信息
+func GetCreateUserData(phone, companyName, orderCode string, entId int, isEntSign bool) map[string]interface{} {
+	data := make(map[string]interface{})
 	userData, ok := MG.DB().FindOne("user", map[string]interface{}{
 		"$or": []map[string]interface{}{
 			{"s_phone": phone},
@@ -26,7 +27,7 @@ func GetCreateUserData(phone string) map[string]interface{} {
 		},
 	})
 	if ok && userData != nil && len(*userData) > 0 {
-		return *userData
+		data = *userData
 	} else {
 		id := MG.DB().Save("user", map[string]interface{}{
 			"i_appid":       2,
@@ -51,11 +52,24 @@ func GetCreateUserData(phone string) map[string]interface{} {
 			ck := &http.Cookie{}
 			usercenter.AddBaseUser(*MG.DB(), g.Cfg().MustGet(ctx, "userCenterUrl").String(), id, formdata, ck)
 			SaveUserLog(id, phone)
-			data, _ := MG.DB().FindById("user", id, "")
-			return *data
+			uData, _ := MG.DB().FindById("user", id, "")
+			data = *uData
 		}
 	}
-	return nil
+	var userPositionId string
+	//查找baseUserId
+	baseUserId := common.Int64All(data["base_user_id"])
+	positionData, _ := g.DB().Ctx(ctx).GetOne(ctx, fmt.Sprintf(`SELECT s_name FROM base_position WHERE type=1 and user_id='%d' and ent_id=%d`, baseUserId, entId))
+	if !positionData.IsEmpty() {
+		userPositionId = gconv.String(positionData.Map()["id"])
+	}
+	//校验企业用户是否创建
+	if entId == 0 && isEntSign {
+		entId, _, userPositionId = AutomaticallyCreatingEnt(companyName, phone, orderCode, common.InterfaceToStr(data["_id"]))
+	}
+	data["entId"] = entId
+	data["userPositionId"] = userPositionId
+	return data
 }
 
 // 用户注册日志保存