|
@@ -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"},
|
|
|
})
|
|
|
|
|
|
//添加计价方案
|