|
@@ -148,6 +148,64 @@ func SupplierPrice(r *GinRouter) {
|
|
|
SearchProject: []string{"price", "supplierId", "productId", "updateTime", "_id"},
|
|
|
})
|
|
|
|
|
|
+ CreateCRUD(r, "/supplier/process", &CRUDOption{
|
|
|
+ Collection: repo.CollectionSupplierCraftprice,
|
|
|
+ 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: repo.CollectionSupplierProcessprice,
|
|
|
+ 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{} {
|
|
|
+ return &model.SupplierPrice{}
|
|
|
+ },
|
|
|
+ JWT: true,
|
|
|
+ OnUpdate: func(c *gin.Context, apictx *ApiSession, entity interface{}) {
|
|
|
+ calc := entity.(*model.SupplierPrice)
|
|
|
+ calc.UpdateTime = time.Now()
|
|
|
+ },
|
|
|
+ SearchFilter: func(c *gin.Context, apictx *ApiSession, query map[string]interface{}) map[string]interface{} {
|
|
|
+ if query["supplierId"] != nil {
|
|
|
+ query["supplierId"], _ = primitive.ObjectIDFromHex(query["supplierId"].(string))
|
|
|
+ }
|
|
|
+ return query
|
|
|
+ },
|
|
|
+ SearchPostProcess: func(page *repo.PageResult, c *gin.Context, apictx *ApiSession, query map[string]interface{}) (interface{}, error) {
|
|
|
+ //查询材料对应的材料信息
|
|
|
+ for _, ps := range page.List {
|
|
|
+ _id, _ := ps["productId"].(primitive.ObjectID)
|
|
|
+
|
|
|
+ process := &model.Process{}
|
|
|
+ repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
|
|
|
+ CollectName: repo.CollectionProcess,
|
|
|
+ Query: repo.Map{"_id": _id},
|
|
|
+ }, process)
|
|
|
+ ps["processInfo"] = process
|
|
|
+ }
|
|
|
+ return page, nil
|
|
|
+ },
|
|
|
+ SearchProject: []string{"price", "supplierId", "productId", "updateTime", "_id"},
|
|
|
+ })
|
|
|
+
|
|
|
//添加计价方案
|
|
|
SupplierCalcPriceColl := "supplier-calcprice"
|
|
|
CreateCRUD(r, "/supplier/calc", &CRUDOption{
|