|
@@ -6,6 +6,7 @@ import (
|
|
|
"box-cost/log"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
+ "strconv"
|
|
|
"time"
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
@@ -365,69 +366,52 @@ func UpdateBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
bill.SupplierRemark = " "
|
|
|
}
|
|
|
|
|
|
- // 获取当前订单提交数
|
|
|
- // 对比提交数量是否变化,变化了就同步计划中的提交数
|
|
|
- currPurchase := &model.PurchaseBill{}
|
|
|
- currConfirmCountMap := map[string]int{}
|
|
|
- repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
|
|
|
- CollectName: repo.CollectionBillPurchase,
|
|
|
- Query: repo.Map{"_id": bill.Id},
|
|
|
- Project: []string{"papers"},
|
|
|
- }, currPurchase)
|
|
|
- if len(currPurchase.Paper) > 0 {
|
|
|
- for _, cp := range currPurchase.Paper {
|
|
|
- currConfirmCountMap[cp.Id] = cp.ConfirmCount
|
|
|
- }
|
|
|
- }
|
|
|
- isSyncConfirm := false
|
|
|
-
|
|
|
- // 更新供应商确定数量与plan中stage项的同步
|
|
|
+ // 修改单据信息需要同步plan中stage项
|
|
|
if len(bill.Paper) > 0 {
|
|
|
- idCounts := map[string]int{}
|
|
|
+ // 获取当前订单供应商id
|
|
|
+ // 对比供应商是否变化,变化了就同步计划中的供应商
|
|
|
+ currPurchase := &model.PurchaseBill{}
|
|
|
+ repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
|
|
|
+ CollectName: repo.CollectionBillPurchase,
|
|
|
+ Query: repo.Map{"_id": bill.Id},
|
|
|
+ Project: []string{"supplierId"},
|
|
|
+ }, currPurchase)
|
|
|
+ var supplierInfo *model.Supplier
|
|
|
+ if currPurchase.SupplierId != bill.SupplierId {
|
|
|
+ // 查询更改后的supplierInfo
|
|
|
+ supplierInfo = &model.Supplier{}
|
|
|
+ repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
|
|
|
+ CollectName: repo.CollectionSupplier,
|
|
|
+ }, supplierInfo)
|
|
|
+ }
|
|
|
+ idStatges := make(map[string]*UpdateBilltoStageReq)
|
|
|
for _, paper := range bill.Paper {
|
|
|
if len(paper.Id) == 0 {
|
|
|
continue
|
|
|
}
|
|
|
- // 对比提交数量不一致时
|
|
|
- if v, ok := currConfirmCountMap[paper.Id]; ok {
|
|
|
- if v != paper.ConfirmCount {
|
|
|
- isSyncConfirm = true
|
|
|
- idCounts[paper.Id] = paper.ConfirmCount
|
|
|
- }
|
|
|
+ width, _ := strconv.Atoi(paper.Width)
|
|
|
+ Height, _ := strconv.Atoi(paper.Height)
|
|
|
+ idStatges[paper.Id] = &UpdateBilltoStageReq{
|
|
|
+ BillType: "purchase",
|
|
|
+ SupplierInfo: supplierInfo,
|
|
|
+ Norm: paper.Norm,
|
|
|
+ Width: width,
|
|
|
+ Height: Height,
|
|
|
+ Price2: paper.Price2,
|
|
|
+ OrderCount: paper.OrderCount,
|
|
|
+ OrderPrice: paper.OrderPrice,
|
|
|
+ Remark: paper.Remark,
|
|
|
+ ConfirmCount: paper.ConfirmCount,
|
|
|
+ DeliveryTime: paper.DeliveryTime,
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
- fmt.Println("单据变化的提交数量:", idCounts)
|
|
|
-
|
|
|
- if isSyncConfirm {
|
|
|
- result, err := updateStageCount(c, bill.PlanId, idCounts, apictx)
|
|
|
- if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
- log.Error(err)
|
|
|
- }
|
|
|
- fmt.Println(result)
|
|
|
-
|
|
|
+ _, err := updateBilltoStage(c, bill.PlanId, idStatges, apictx)
|
|
|
+ if err != nil {
|
|
|
+ return nil, errors.New("该单据改动同步到产品失败")
|
|
|
}
|
|
|
+ fmt.Println("单据同步到产品,planId:", bill.PlanId)
|
|
|
}
|
|
|
|
|
|
- // // 更新供应商确定数量与plan中stage项的同步
|
|
|
- // if len(bill.Paper) > 0 {
|
|
|
- // idCounts := map[string]int{}
|
|
|
- // for _, paper := range bill.Paper {
|
|
|
- // if len(paper.Id) == 0 {
|
|
|
- // continue
|
|
|
- // }
|
|
|
- // idCounts[paper.Id] = paper.ConfirmCount
|
|
|
- // }
|
|
|
- // fmt.Println(idCounts)
|
|
|
- // result, err := updateStageCount(c, bill.PlanId, idCounts, apictx)
|
|
|
- // if err != nil {
|
|
|
- // fmt.Println(err)
|
|
|
- // log.Error(err)
|
|
|
- // }
|
|
|
- // fmt.Println(result)
|
|
|
- // }
|
|
|
-
|
|
|
bill.UpdateTime = time.Now()
|
|
|
// return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionBillPurchase, bill.Id.Hex(), &bill)
|
|
|
return repo.RepoUpdateSetDoc1(apictx.CreateRepoCtx(), repo.CollectionBillPurchase, bill.Id.Hex(), &bill, &repo.RecordLogReq{
|