liwei 2 years ago
parent
commit
22ff928db9
3 changed files with 35 additions and 17 deletions
  1. 5 17
      boxcost/api/bill.go
  2. 16 0
      boxcost/api/setting.go
  3. 14 0
      boxcost/db/model/setting.go

+ 5 - 17
boxcost/api/bill.go

@@ -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)
 }
 
 // 获取单据信息

+ 16 - 0
boxcost/api/setting.go

@@ -41,6 +41,21 @@ func Setting(router *GinRouter) {
 		SearchProject: []string{"name", "createTime"},
 	})
 
+	CreateCRUD(router, "/info", &CRUDOption{
+		Collection: "infos",
+		NewModel: func(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+			entity := &model.Setting{}
+			c.ShouldBindJSON(entity)
+			entity.UpdateTime = time.Now()
+			return entity, nil
+		},
+		EmtyModel: func(c *gin.Context, apictx *ApiSession) interface{} {
+			return &model.Setting{}
+		},
+		JWT:           true,
+		SearchProject: []string{"companyName", "updateTime", "address"},
+	})
+
 	//计价策略
 	CreateCRUD(router, "/calc", &CRUDOption{
 		Collection: "calcs",
@@ -54,6 +69,7 @@ func Setting(router *GinRouter) {
 		EmtyModel: func(c *gin.Context, apictx *ApiSession) interface{} {
 			return &model.PriceCalc{}
 		},
+
 		JWT: true,
 		OnUpdate: func(c *gin.Context, apictx *ApiSession, entity interface{}) {
 			calc := entity.(*model.PriceCalc)

+ 14 - 0
boxcost/db/model/setting.go

@@ -0,0 +1,14 @@
+package model
+
+import (
+	"time"
+
+	"go.mongodb.org/mongo-driver/bson/primitive"
+)
+
+type Setting struct {
+	Id          primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
+	UpdateTime  time.Time          `bson:"updateTime,omitempty" json:"updateTime"`
+	Address     string             `bson:"address,omitempty" json:"address"`
+	CompanyName string             `bson:"companyName,omitempty" json:"companyName"`
+}