|
@@ -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},
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
// 创建供应商
|