caipin 4 éve
szülő
commit
9cdd47669d

+ 67 - 1
dao/contract_dao.go

@@ -126,7 +126,7 @@ func (d *ContractDao) Add(contractData *models.CmContracts) error {
 	return nil
 }
 
-// 更新合同
+// 更新收入合同
 func (d *ContractDao) Update(contractsCm *models.CmContracts, columns []string, projectId int, bidsectionId int, treeId int) error {
 	session := d.engine.NewSession()
 	defer session.Close()
@@ -192,6 +192,72 @@ func (d *ContractDao) Update(contractsCm *models.CmContracts, columns []string,
 	return nil
 }
 
+// 更新收入合同
+func (d *ContractDao) UpdateExpenditure(contractsCm *models.CmContracts, columns []string, projectId int, bidsectionId int, treeId int) error {
+	session := d.engine.NewSession()
+	defer session.Close()
+	err := session.Begin()
+	if err != nil {
+		return errors.New("session出错-db")
+	}
+
+	// 1.更新合同表
+	// successNum 是否有值更新的数量 为0,表示没有更新
+	// successNum, err := session.Id(contractsCm.Id).MustCols(columns...).Update(contractsCm)
+	_, err = session.Id(contractsCm.Id).MustCols(columns...).Update(contractsCm)
+	if err != nil {
+		session.Rollback()
+		return errors.New("更新失败")
+	}
+
+	// 3.更新合同状态,合同金额和回款金额比对
+	// 3-1获得支出总金额
+	datalist := make([]models.CmContractsPaid, 0)
+	err = d.engine.Where(" project_id =? and bidsection_id = ? and contracts_id =? ", projectId, bidsectionId, contractsCm.Id).Find(&datalist)
+	if err != nil {
+		session.Rollback()
+		return errors.New("编辑合同出错-项目节更新失败")
+	}
+	contractsPrice := 0.00
+	for _, item := range datalist {
+		price, _ := strconv.ParseFloat(item.Price, 64)
+		if item.ContractsId == contractsCm.Id {
+			contractsPrice = contractsPrice + price
+		}
+	}
+	contractsPrice, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", contractsPrice), 64)
+	// 合同状态判定
+	contractsDetailPrice, _ := strconv.ParseFloat(contractsCm.Price, 64)
+	// 总回款大于等于合同金额 待关闭
+	contractStatus := 0
+	if contractsPrice >= contractsDetailPrice {
+		contractStatus = 1
+	}
+	// 更新合同表状态
+	_, err = session.Exec("UPDATE  cm_contracts SET  status = ? where id = ? ", contractStatus, contractsCm.Id)
+	if err != nil {
+		session.Rollback()
+		return errors.New("合同状态更新失败")
+	}
+
+	// 2.更新项目节表
+	_, err = session.Exec("UPDATE  cm_tree_contracts SET `contract_name` = ?,`contract_price` = ? , contract_status = ? "+
+		"where tree_id = ? and project_id = ? and bidsection_id = ? ",
+		contractsCm.Name, contractsCm.Price, contractStatus,
+		treeId, projectId, bidsectionId)
+	if err != nil {
+		session.Rollback()
+		return errors.New("编辑合同出错-项目节更新失败")
+	}
+
+	err = session.Commit()
+	if err != nil {
+		session.Rollback()
+		return errors.New("session出错-db")
+	}
+	return nil
+}
+
 // 删除合同
 func (d *ContractDao) Delete(projectId int, bidsectionId int, treeId int, id int) error {
 

+ 1 - 1
services/contract_expenditure_service.go

@@ -114,7 +114,7 @@ func (s *contractService) UpdateExpenditure(contractData *viewmodels.Contracts,
 	contractsCm.Remarks = contractData.Remarks
 
 	columns := []string{"Content", "Name", "Price", "PartyA", "PartyASigner", "PartyB", "PartyBSigner"}
-	err = s.contractDao.Update(contractsCm, columns, projectId, bidsectionId, treeId)
+	err = s.contractDao.UpdateExpenditure(contractsCm, columns, projectId, bidsectionId, treeId)
 	if err != nil {
 		return err
 	}

+ 22 - 18
services/contract_section_tree_service.go

@@ -235,10 +235,10 @@ func (s *contractService) SectionSave(sectionData *viewmodels.TreeSectionContrac
 		return nil
 	}
 
-	// 1-1 深度为>=2才能新增项目节
-	// if section.Depth < 2 {
-	// 	return errors.New("请在项目节第三层开始编辑")
-	// }
+	// 1-1 深度为>=1才能新增项目节
+	if section.Depth == 0 {
+		return errors.New("请在项目节第二层开始编辑")
+	}
 
 	// 2.保存
 	sectionCM := &models.CmTreeContracts{}
@@ -268,10 +268,10 @@ func (s *contractService) UpdateSerial(sectionData *viewmodels.TreeSectionContra
 		return nil
 	}
 
-	// 1-1 深度为>=2才能新增项目节
-	// if section.Depth < 2 {
-	// 	return errors.New("请在项目节第三层开始编辑")
-	// }
+	// 1-1 深度为>=1才能新增项目节
+	if section.Depth == 0 {
+		return errors.New("请在项目节第二层开始编辑")
+	}
 
 	err = s.treeContractDao.UpdateSerial(section, sectionData.Serial, treeType)
 	if err != nil {
@@ -289,8 +289,8 @@ func (s *contractService) SectionDelete(treeId int, bidsectionId int, projectId
 	}
 
 	// 1-1 深度为>=1才能新增项目节
-	if section.Depth < 1 {
-		return errors.New("请在项目节第层开始编辑")
+	if section.Depth == 0 {
+		return errors.New("请在项目节第层开始编辑")
 	}
 	// 1-2 有合同的不能编辑(包含孩子节点)
 	contractList := s.treeContractDao.GetAttributionContract(section, treeType)
@@ -316,10 +316,12 @@ func (s *contractService) MoveDepth(sectionData *viewmodels.TreeSectionContract,
 	if section.Id == 0 {
 		return errors.New("未找到合同项目节")
 	}
-	// 1-1 深度为>=2才能新增项目节
-	// if section.Depth < 2 {
-	// 	return errors.New("请在项目节第三层开始编辑")
-	// }
+
+	// 1-1 深度为>=1才能新增项目节
+	if section.Depth == 0 {
+		return errors.New("请在项目节第二层开始编辑")
+	}
+
 	// 1-2 有合同的不能编辑(包含孩子节点)
 	contractList := s.GetSectionTreeContract(section.Attribution, section.BidsectionId, section.ProjectId, treeType)
 	if len(contractList) != 0 {
@@ -373,10 +375,12 @@ func (s *contractService) MoveSerial(sectionData *viewmodels.TreeSectionContract
 	if section.Id == 0 {
 		return errors.New("未找到合同项目节")
 	}
-	// 1-1 深度为>=2才能新增项目节
-	// if section.Depth < 2 {
-	// 	return errors.New("请在项目节第三层开始编辑")
-	// }
+
+	// 1-1 深度为>=1才能新增项目节
+	if section.Depth == 0 {
+		return errors.New("请在项目节第二层开始编辑")
+	}
+
 	// 1-2 有合同的不能编辑(包含孩子节点)
 	contractList := s.GetSectionTreeContract(section.Attribution, section.BidsectionId, section.ProjectId, treeType)
 	if len(contractList) != 0 {