Browse Source

添加供应商自己的订单列表

animeic 2 years ago
parent
commit
81398d75b1

+ 3 - 0
boxcost/api/bill-produce.go

@@ -214,6 +214,9 @@ func UpdateProduceBill(c *gin.Context, apictx *ApiSession) (interface{}, error)
 
 		}
 	}
+	if bill.IsSend {
+		bill.SendTime = time.Now()
+	}
 	// 计算结算价格
 	if bill.Status == "complete" {
 		bill.CompleteTime = time.Now()

+ 3 - 0
boxcost/api/bill-product.go

@@ -214,6 +214,9 @@ func UpdateProductBill(c *gin.Context, apictx *ApiSession) (interface{}, error)
 
 		}
 	}
+	if bill.IsSend {
+		bill.SendTime = time.Now()
+	}
 
 	// 计算结算价格
 	if bill.Status == "complete" {

+ 3 - 0
boxcost/api/bill.go

@@ -311,6 +311,9 @@ func UpdateBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 		}
 	}
+	if bill.IsSend {
+		bill.SendTime = time.Now()
+	}
 
 	if bill.Status == "complete" {
 		bill.CompleteTime = time.Now()

+ 62 - 0
boxcost/api/plan.go

@@ -49,6 +49,68 @@ func ProductPlan(r *GinRouter) {
 	// 生产成本表
 	r.GET("/plan/cost/download", DownLoadPlanCost)
 
+	// 单据批量分配给供应商
+	r.GET("/plan/alloc/batch", PlanAllocBatch)
+
+}
+
+// 把某个计划的订单批量分配给供应商
+// id 为计划id
+// /plan/alloc/batch?id=xxx
+func PlanAllocBatch(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	_planId := c.Query("id")
+	planId, err := primitive.ObjectIDFromHex(_planId)
+	if err != nil {
+		return nil, errors.New("planId错误")
+	}
+	plan := model.ProductPlan{}
+	found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+		CollectName: repo.CollectionProductPlan,
+		Query:       repo.Map{"_id": planId},
+	}, &plan)
+	if !found || err != nil {
+		return nil, errors.New("数据未找到")
+	}
+	// 获取所有stages单据id
+	billIds := make([]string, 0)
+	for _, comp := range plan.Pack.Components {
+		if comp.Id == "" || len(comp.Stages) == 0 {
+			continue
+		}
+		for _, stage := range comp.Stages {
+			billId, _ := primitive.ObjectIDFromHex(stage.BillId)
+			if !billId.IsZero() {
+				billIds = append(billIds, fmt.Sprintf("%d_%s", stage.BillType, stage.BillId))
+			}
+		}
+
+	}
+	// 去重单据号
+	typeBillIds := removeDuplicationSort(billIds)
+	if len(typeBillIds) < 1 {
+		return nil, errors.New("未找到单据信息")
+	}
+
+	for _, tId := range typeBillIds {
+		tidArr := strings.Split(tId, "_")
+		// 采购
+		billId, _ := primitive.ObjectIDFromHex(tidArr[1])
+		if tidArr[0] == "1" {
+			repo.RepoUpdateSetDocProps(apictx.CreateRepoCtx(), repo.CollectionBillPurchase, billId.Hex(), &model.PurchaseBill{IsSend: true, SendTime: time.Now()})
+		}
+		// 工艺
+		if tidArr[0] == "2" {
+			repo.RepoUpdateSetDocProps(apictx.CreateRepoCtx(), repo.CollectionBillProduce, billId.Hex(), &model.ProduceBill{IsSend: true, SendTime: time.Now()})
+		}
+		// 成品采购
+		if tidArr[0] == "3" {
+			repo.RepoUpdateSetDocProps(apictx.CreateRepoCtx(), repo.CollectionBillProduct, billId.Hex(), &model.ProductBill{IsSend: true, SendTime: time.Now()})
+		}
+
+	}
+
+	return true, nil
+
 }
 
 type SupplierPlanCost struct {

+ 85 - 0
boxcost/api/supplier.go

@@ -34,6 +34,91 @@ func Supplier(r *GinRouter) {
 
 	// 获取供应商列表
 	r.GET("/plan/supplier/list", GetPlanSuppliers)
+
+	// 供应商获取自己的单据列表
+	r.GETJWT("/supplier/bill/list", SupplierBillList)
+
+	// 单据分配给供应商
+	r.GET("/supplier/bill/alloc", SupplierBillAlloc)
+
+}
+
+// 把订单分配给供应商
+// purchase produce product
+// /supplier/bill/list?id=xxx&type=purchase
+func SupplierBillAlloc(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	billId, _ := primitive.ObjectIDFromHex(c.Query("id"))
+	if billId.IsZero() {
+		return nil, errors.New("订单id不正确")
+	}
+	billType := c.Query("type")
+	billTypes := []string{"purchase", "produce", "product"}
+	flagType := false
+	for _, bt := range billTypes {
+		if bt == billType {
+			flagType = true
+			break
+		}
+	}
+	if !flagType {
+		return nil, errors.New("订单类型错误")
+	}
+
+	switch billType {
+	case "purchase":
+		return repo.RepoUpdateSetDocProps(apictx.CreateRepoCtx(), repo.CollectionBillPurchase, billId.Hex(), &model.PurchaseBill{IsSend: true, SendTime: time.Now()})
+	case "produce":
+		return repo.RepoUpdateSetDocProps(apictx.CreateRepoCtx(), repo.CollectionBillProduce, billId.Hex(), &model.ProduceBill{IsSend: true, SendTime: time.Now()})
+	case "product":
+		return repo.RepoUpdateSetDocProps(apictx.CreateRepoCtx(), repo.CollectionBillProduct, billId.Hex(), &model.ProductBill{IsSend: true, SendTime: time.Now()})
+	default:
+		return true, nil
+	}
+}
+
+// 供应商-订单列表
+// purchase produce product
+// /supplier/bill/list?type=purchase&query={"status":"created"}
+func SupplierBillList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	userId, _ := primitive.ObjectIDFromHex(apictx.User.Parent)
+	billType := c.Query("type")
+	page, size, query := UtilQueryPageSize(c)
+	if userId.IsZero() {
+		return nil, errors.New("非法用户")
+	}
+	// purchase produce product
+	billTypes := []string{"purchase", "produce", "product"}
+	flagType := false
+	for _, bt := range billTypes {
+		if bt == billType {
+			flagType = true
+			break
+		}
+	}
+	if !flagType {
+		return nil, errors.New("订单类型错误")
+	}
+	query["supplierId"] = userId
+	query["isSend"] = true
+
+	collectName := ""
+	switch billType {
+	case "purchase":
+		collectName = repo.CollectionBillPurchase
+	case "produce":
+		collectName = repo.CollectionBillProduce
+	case "product":
+		collectName = repo.CollectionBillProduct
+	default:
+		return []map[string]interface{}{}, nil
+	}
+	return repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
+		CollectName: collectName,
+		Page:        page,
+		Size:        size,
+		Query:       query,
+		Sort:        repo.Map{"sendTime": 1},
+	})
 }
 
 // 创建供应商

+ 12 - 0
boxcost/db/model/bill.go

@@ -77,6 +77,10 @@ type PurchaseBill struct {
 
 	// 单据类型
 	BillType string `bson:"billType,omitempty" json:"billType"`
+
+	// 发送给供应商
+	IsSend   bool      `bson:"isSend,omitempty" json:"isSend"`
+	SendTime time.Time `bson:"sendTime,omitempty" json:"sendTime"`
 }
 
 // 工艺生产数据
@@ -159,6 +163,10 @@ type ProduceBill struct {
 
 	// 单据类型
 	BillType string `bson:"billType,omitempty" json:"billType"`
+
+	// 发送给供应商
+	IsSend   bool      `bson:"isSend,omitempty" json:"isSend"`
+	SendTime time.Time `bson:"sendTime,omitempty" json:"sendTime"`
 }
 
 // 成品采购单据
@@ -201,6 +209,10 @@ type ProductBill struct {
 
 	// 单据类型
 	BillType string `bson:"billType,omitempty" json:"billType"`
+
+	// 发送给供应商
+	IsSend   bool      `bson:"isSend,omitempty" json:"isSend"`
+	SendTime time.Time `bson:"sendTime,omitempty" json:"sendTime"`
 }
 
 // 工艺生产数据