caipin 4 anos atrás
pai
commit
00efb70995
2 arquivos alterados com 27 adições e 10 exclusões
  1. 13 7
      dao/contract_dao.go
  2. 14 3
      web/api/contract_expenditure_api.go

+ 13 - 7
dao/contract_dao.go

@@ -206,8 +206,8 @@ func (d *ContractDao) Delete(projectId int, bidsectionId int, treeId int, id int
 	}
 
 	// 2.删除项目节上合同信息-需求变更-删除项目节
-	_, err = session.Exec("DELETE FROM `cm_tree_contracts` WHERE tree_id=?  ",
-		treeId)
+	_, err = session.Exec("DELETE FROM `cm_tree_contracts` WHERE tree_id=? and project_id = ? and bidsection_id = ? ",
+		treeId, projectId, bidsectionId)
 	if err != nil {
 		session.Rollback()
 		return errors.New("编辑合同出错-项目节删除失败")
@@ -260,21 +260,27 @@ func (d *ContractDao) DeleteExpenditure(projectId int, bidsectionId int, treeId
 		return errors.New("合同数据异常,删除失败")
 	}
 
-	// 2.删除项目节上合同信息
-	_, err = session.Exec("UPDATE  cm_tree_contracts SET `contract_name` = '',`contract_code` = '',`contract_price` = 0,`contract_id` = 0,`contract_returned` = 0,`contracts_paid` = 0,`contract_status` = 0 "+
-		",contract_locking=0 where tree_id = ? and project_id = ? and bidsection_id = ? ",
+	// 2.删除项目节上合同信息--移除项目节需求变更
+	_, err = session.Exec("DELETE FROM `cm_tree_contracts` WHERE tree_id=? and project_id = ? and bidsection_id = ?  ",
 		treeId, projectId, bidsectionId)
 	if err != nil {
 		session.Rollback()
-		return errors.New("删除合同出错-项目节更新失败")
+		return errors.New("编辑合同出错-删除项目节失败")
 	}
+	// _, err = session.Exec("UPDATE  cm_tree_contracts SET `contract_name` = '',`contract_code` = '',`contract_price` = 0,`contract_id` = 0,`contract_returned` = 0,`contracts_paid` = 0,`contract_status` = 0 "+
+	// 	",contract_locking=0 where tree_id = ? and project_id = ? and bidsection_id = ? ",
+	// 	treeId, projectId, bidsectionId)
+	// if err != nil {
+	// 	session.Rollback()
+	// 	return errors.New("删除合同出错-项目节更新失败")
+	// }
 
 	// 3.删除已支付信息
 	_, err = session.Exec("DELETE FROM `cm_contracts_paid` WHERE contracts_id=? and project_id=? and bidsection_id=? ",
 		id, projectId, bidsectionId)
 	if err != nil {
 		session.Rollback()
-		return errors.New("编辑合同出错-项目节更新失败")
+		return errors.New("编辑合同出错-删除已支付失败")
 	}
 
 	// 4.删除附件-TODO

+ 14 - 3
web/api/contract_expenditure_api.go

@@ -187,12 +187,23 @@ func (c *ContractApi) PostExpenditureCreate() {
 		return
 	}
 
-	err = c.ServiceContract.AddExpenditure(contractData, projectIdInt, bidsectionId, treeId)
+	sectionData := &viewmodels.TreeSectionContract{}
+	sectionData.Id = contractData.TreeId
+	sectionData.Name = " "
+	sectionResult, err := c.ServiceContract.SectionAdd(sectionData, bidsectionId, projectIdInt, 1)
 	if err != nil {
 		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
 		return
 	}
 
+	err = c.ServiceContract.AddExpenditure(contractData, projectIdInt, bidsectionId, sectionResult.Id)
+	if err != nil {
+		// 需要删除项目节
+		c.ServiceContract.SectionDelete(sectionResult.Id, bidsectionId, projectIdInt, 0)
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+
 	// 获得项目节
 	sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, 1)
 	// 合同ID
@@ -326,7 +337,7 @@ func (c *ContractApi) DeleteExpenditure() {
 
 	//2.请求当前项目信息
 	// 1.验证项目节ID
-	sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, 1)
+	// sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt, 1)
 
-	c.Ctx.JSON(iris.Map{"code": 0, "msg": "删除成功", "section": sectionDetail})
+	c.Ctx.JSON(iris.Map{"code": 0, "msg": "删除成功", "section": ""})
 }