|
@@ -42,14 +42,14 @@ type MatBillReq struct {
|
|
|
// 创建单据
|
|
|
func CreateBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
|
|
|
- req := &MatBillReq{}
|
|
|
+ req := &model.PurchaseBill{}
|
|
|
err := c.ShouldBindJSON(req)
|
|
|
- if err != nil || req.Bill == nil || req.CompIndex == nil || req.MatIndex == nil {
|
|
|
+ if err != nil {
|
|
|
fmt.Println(err)
|
|
|
- return nil, errors.New("参数错误!compIndex, matIndex 不能为空")
|
|
|
+ return nil, errors.New("参数错误")
|
|
|
}
|
|
|
ctx := apictx.CreateRepoCtx()
|
|
|
- bill := req.Bill
|
|
|
+ bill := req
|
|
|
|
|
|
if bill.PackId.Hex() == "" {
|
|
|
return nil, errors.New("包装产品id为空")
|
|
@@ -65,19 +65,7 @@ func CreateBill(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
bill.CreateTime = time.Now()
|
|
|
bill.UpdateTime = time.Now()
|
|
|
|
|
|
- result, err := repo.RepoAddDoc(ctx, repo.CollectionBillPurchase, &bill)
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
- updat := bson.M{}
|
|
|
- matkey := fmt.Sprintf("pack.components.%d.mats.%d.billId", *req.CompIndex, *req.MatIndex)
|
|
|
- updat[matkey] = result
|
|
|
- ret, err := repo.RepoUpdateSetDocProps(apictx.CreateRepoCtx(), repo.CollectionProductPlan, bill.PlanId.Hex(), bson.M{"$set": updat})
|
|
|
- if ret.ModifiedCount == 1 && err == nil {
|
|
|
- return result, nil
|
|
|
- }
|
|
|
- return nil, fmt.Errorf("创建失败")
|
|
|
+ return repo.RepoAddDoc(ctx, repo.CollectionBillPurchase, &bill)
|
|
|
}
|
|
|
|
|
|
// 获取单据信息
|