animeic 2 年之前
父节点
当前提交
307dad651e
共有 2 个文件被更改,包括 42 次插入2 次删除
  1. 21 1
      boxcost/api/bill-produce.go
  2. 21 1
      boxcost/api/bill.go

+ 21 - 1
boxcost/api/bill-produce.go

@@ -42,6 +42,10 @@ func BillProduce(r *GinRouter) {
 // 审核单据
 func ProduceReview(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	_id := c.Param("id")
+	id, err := primitive.ObjectIDFromHex(_id)
+	if err != nil {
+		return nil, errors.New("id错误")
+	}
 	userId, err := primitive.ObjectIDFromHex(apictx.User.Parent)
 	if err != nil {
 		return nil, errors.New("用户异常")
@@ -53,8 +57,24 @@ func ProduceReview(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	if !isManager(user.Roles) {
 		return nil, errors.New("该用户没有权限")
 	}
-	// 更改状态为已审核 并签字
+	// 查询单据获取已有的签字
+	bill := model.ProduceBill{}
+	repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+		CollectName: repo.CollectionBillProduce,
+		Query:       repo.Map{"_id": id, "reviewed": 1},
+	}, &bill)
 	signs := make([]primitive.ObjectID, 0)
+	if len(bill.SignUsers) > 0 {
+		// 如果自己已存在该集合中了
+		for _, signUser := range bill.SignUsers {
+			if signUser == userId {
+				return nil, errors.New("该单据您已审核过了")
+			}
+		}
+		signs = bill.SignUsers
+	}
+
+	// 更改状态为已审核 并签字
 	signs = append(signs, userId)
 	produce := model.ProduceBill{
 		Reviewed:   1,

+ 21 - 1
boxcost/api/bill.go

@@ -42,6 +42,10 @@ func Bill(r *GinRouter) {
 // 审核单据
 func PurchaseReview(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	_id := c.Param("id")
+	id, err := primitive.ObjectIDFromHex(_id)
+	if err != nil {
+		return nil, errors.New("id错误")
+	}
 	userId, err := primitive.ObjectIDFromHex(apictx.User.Parent)
 	if err != nil {
 		return nil, errors.New("用户异常")
@@ -53,8 +57,24 @@ func PurchaseReview(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	if !isManager(user.Roles) {
 		return nil, errors.New("该用户没有权限")
 	}
-	// 更改状态为已审核 并签字
+	// 查询单据获取已有的签字
+	bill := model.PurchaseBill{}
+	repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
+		CollectName: repo.CollectionBillPurchase,
+		Query:       repo.Map{"_id": id, "reviewed": 1},
+	}, &bill)
 	signs := make([]primitive.ObjectID, 0)
+	if len(bill.SignUsers) > 0 {
+		// 如果自己已存在该集合中了
+		for _, signUser := range bill.SignUsers {
+			if signUser == userId {
+				return nil, errors.New("该单据您已审核过了")
+			}
+		}
+		signs = bill.SignUsers
+	}
+
+	// 更改状态为已审核 并签字
 	signs = append(signs, userId)
 	purchase := model.PurchaseBill{
 		Reviewed:   1,