Browse Source

fix productAdd supplyId form userId

animeic 2 years ago
parent
commit
66a7e23f6d
3 changed files with 8 additions and 11 deletions
  1. BIN
      3dshow-supplier/__debug_bin
  2. 2 3
      3dshow-supplier/api/order.go
  3. 6 8
      3dshow-supplier/api/product.go

BIN
3dshow-supplier/__debug_bin


+ 2 - 3
3dshow-supplier/api/order.go

@@ -19,9 +19,8 @@ func Order(r *GinRouter) {
 // 订单列表
 func OrderList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	page, size, query := UtilQueryPageSize(c)
-	// _userId := apictx.User.ID
-	// userId, _ := primitive.ObjectIDFromHex(_userId)
-	userId, _ := primitive.ObjectIDFromHex("636c66874fa01c203c478ba9")
+	_userId := apictx.User.ID
+	userId, _ := primitive.ObjectIDFromHex(_userId)
 	// 供应商的订单列表
 	query["supplyId"] = userId
 	result, err := repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{

+ 6 - 8
3dshow-supplier/api/product.go

@@ -29,10 +29,10 @@ func ProductAdd(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	if err != nil {
 		return nil, errors.New("参数错误!")
 	}
-	ctx := apictx.CreateRepoCtx()
-	if form.SupplyId.Hex() == "" {
-		return nil, errors.New("供应链id不能为空")
-	}
+	_userId := apictx.User.ID
+	userId, _ := primitive.ObjectIDFromHex(_userId)
+	// 供应链端 供应id就算当前用户id
+	form.SupplyId = userId
 	if form.Name == "" {
 		return nil, errors.New("产品名不能为空")
 	}
@@ -42,7 +42,7 @@ func ProductAdd(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 		form.Status = -1
 	}
 
-	result, err := repo.RepoAddDoc(ctx, repo.CollectionProduct, &form)
+	result, err := repo.RepoAddDoc(apictx.CreateRepoCtx(), repo.CollectionProduct, &form)
 	return result, err
 
 }
@@ -66,10 +66,8 @@ func ProductUpdate(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 		return nil, errors.New("该商品不存在")
 	}
 
-	_userId := apictx.User.ID
-	userId, _ := primitive.ObjectIDFromHex(_userId)
 	// 不是自己的商品
-	if product.SupplyId != userId {
+	if product.SupplyId.Hex() != apictx.User.ID {
 		return nil, errors.New("非法操作")
 	}
 	form.UpdateTime = time.Now()