liwei 2 years ago
parent
commit
9f3665a4f6

+ 2 - 2
boxcost/api/setting.go

@@ -38,7 +38,7 @@ func Setting(router *GinRouter) {
 			return &model.Category{}
 		},
 		JWT:           true,
-		SearchProject: []string{"name", "createTime"},
+		SearchProject: []string{"name", "createTime", "letterName"},
 	})
 
 	CreateCRUD(router, "/info", &CRUDOption{
@@ -53,7 +53,7 @@ func Setting(router *GinRouter) {
 			return &model.Setting{}
 		},
 		JWT:           true,
-		SearchProject: []string{"companyName", "updateTime", "address"},
+		SearchProject: []string{"companyName", "updateTime", "address", "phone"},
 	})
 
 	//计价策略

+ 47 - 9
boxcost/api/supplier-price.go

@@ -29,13 +29,32 @@ func SupplierPrice(r *GinRouter) {
 	// r.POST("/supplier/mat/delete/:id", DelSupplierPrice)
 
 	//材料供应
+	SupplierMatTable := "supplier-mats"
 	CreateCRUD(r, "/supplier/mat", &CRUDOption{
-		Collection: "supplier-mats",
+		Collection: SupplierMatTable,
 		NewModel: func(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 			entity := &model.SupplierPrice{}
 			c.ShouldBindJSON(entity)
+			if entity.ProductId == primitive.NilObjectID || entity.SupplierId == primitive.NilObjectID {
+				return nil, fmt.Errorf("产品ID或供应商Id不能为空")
+			}
+
+			curr := &model.SupplierPrice{}
+			ok, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+				CollectName: SupplierMatTable,
+				Query:       repo.Map{"productId": entity.ProductId, "supplierId": entity.SupplierId},
+				Project:     []string{"_id"},
+			}, curr)
+			if err != nil {
+				return nil, err
+			}
+			if ok {
+				return nil, fmt.Errorf("该材料已经在供应列表里面了")
+			}
+
 			entity.CreateTime = time.Now()
 			entity.UpdateTime = time.Now()
+
 			return entity, nil
 		},
 		EmtyModel: func(c *gin.Context, apictx *ApiSession) interface{} {
@@ -56,7 +75,7 @@ func SupplierPrice(r *GinRouter) {
 		SearchPostProcess: func(page *repo.PageResult, c *gin.Context, apictx *ApiSession, query map[string]interface{}) (interface{}, error) {
 			//查询材料对应的材料信息
 			for _, mat := range page.List {
-				_id, _ := mat["_id"].(primitive.ObjectID)
+				_id, _ := mat["productId"].(primitive.ObjectID)
 
 				matInfo := &model.Material{}
 				repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
@@ -68,14 +87,33 @@ func SupplierPrice(r *GinRouter) {
 			return page, nil
 		},
 
-		SearchProject: []string{"price", "supplierId", "updateTime", "_id"},
+		SearchProject: []string{"price", "supplierId", "productId", "updateTime", "_id"},
 	})
 
+	SupplierCraftTable := "supplier-crafts"
 	CreateCRUD(r, "/supplier/craft", &CRUDOption{
-		Collection: "supplier-crafts",
+		Collection: SupplierCraftTable,
 		NewModel: func(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 			entity := &model.SupplierPrice{}
 			c.ShouldBindJSON(entity)
+
+			if entity.ProductId == primitive.NilObjectID || entity.SupplierId == primitive.NilObjectID {
+				return nil, fmt.Errorf("产品ID或供应商Id不能为空")
+			}
+
+			curr := &model.SupplierPrice{}
+			ok, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+				CollectName: SupplierCraftTable,
+				Query:       repo.Map{"productId": entity.ProductId, "supplierId": entity.SupplierId},
+				Project:     []string{"_id"},
+			}, curr)
+			if err != nil {
+				return nil, err
+			}
+			if ok {
+				return nil, fmt.Errorf("该工艺已经在供应列表里面了")
+			}
+
 			entity.CreateTime = time.Now()
 			entity.UpdateTime = time.Now()
 			return entity, nil
@@ -97,18 +135,18 @@ func SupplierPrice(r *GinRouter) {
 		SearchPostProcess: func(page *repo.PageResult, c *gin.Context, apictx *ApiSession, query map[string]interface{}) (interface{}, error) {
 			//查询材料对应的材料信息
 			for _, mat := range page.List {
-				_id, _ := mat["_id"].(primitive.ObjectID)
+				_id, _ := mat["productId"].(primitive.ObjectID)
 
-				matInfo := &model.Material{}
+				craft := &model.Craft{}
 				repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
 					CollectName: repo.CollectionCraft,
 					Query:       repo.Map{"_id": _id},
-				}, matInfo)
-				mat["craftInfo"] = matInfo
+				}, craft)
+				mat["craftInfo"] = craft
 			}
 			return page, nil
 		},
-		SearchProject: []string{"price", "supplierId", "updateTime", "_id"},
+		SearchProject: []string{"price", "supplierId", "productId", "updateTime", "_id"},
 	})
 
 	//添加计价方案

+ 6 - 3
boxcost/db/model/material.go

@@ -15,9 +15,12 @@ type Unit struct {
 
 // 分类
 type Category struct {
-	Id         primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
-	Name       string             `bson:"name,omitempty" json:"name"`
-	CreateTime time.Time          `bson:"createTime,omitempty" json:"createTime"`
+	Id   primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
+	Name string             `bson:"name,omitempty" json:"name"`
+
+	//字母缩写
+	LetterName string    `bson:"letterName,omitempty" json:"letterName"`
+	CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
 }
 
 // 材料只能添加,不能修改

+ 1 - 0
boxcost/db/model/setting.go

@@ -11,4 +11,5 @@ type Setting struct {
 	UpdateTime  time.Time          `bson:"updateTime,omitempty" json:"updateTime"`
 	Address     string             `bson:"address,omitempty" json:"address"`
 	CompanyName string             `bson:"companyName,omitempty" json:"companyName"`
+	Phone       string             `bson:"phone,omitempty" json:"phone"`
 }

+ 3 - 0
boxcost/db/model/supplier-price.go

@@ -10,6 +10,9 @@ import (
 type SupplierPrice struct {
 	Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"` //商品Id
 
+	//商品Id
+	ProductId primitive.ObjectID `bson:"productId,omitempty" json:"productId"`
+
 	SupplierId primitive.ObjectID `bson:"supplierId,omitempty" json:"supplierId"`
 
 	Price float64 `bson:"price,omitempty" json:"price"` //价格