caipin 4 年之前
父節點
當前提交
7b71436d5b

+ 2 - 8
dao/contract_paid_dao.go

@@ -62,20 +62,14 @@ func (d *ContractPaidDao) Add(contractsPaid *models.CmContractsPaid) error {
 
 // 更新已支付
 func (d *ContractPaidDao) Update(contractsReturn *models.CmContractsPaid, contracts_id int, bidsectionId int) error {
-	is, err := d.engine.Where("id = ? and contracts_id = ? and bidsection_id=? ", contractsReturn.Id, contracts_id, bidsectionId).Update(contractsReturn)
-	if is == 0 {
-		return errors.New("未找到已支付信息")
-	}
+	_, err := d.engine.Where("id = ? and contracts_id = ? and bidsection_id=? ", contractsReturn.Id, contracts_id, bidsectionId).Update(contractsReturn)
 	return err
 }
 
 // 删除回款
 func (d *ContractPaidDao) Delete(id int, contractsId int, bidsectionId int, projectId int) error {
 	data := &models.CmContractsPaid{}
-	is, err := d.engine.Where("id = ? and contracts_id = ? and project_id =? and bidsection_id = ? ", id, contractsId, projectId, bidsectionId).Delete(data)
-	if is == 0 {
-		return errors.New("未找到已支付信息")
-	}
+	_, err := d.engine.Where("id = ? and contracts_id = ? and project_id =? and bidsection_id = ? ", id, contractsId, projectId, bidsectionId).Delete(data)
 	return err
 }
 

+ 10 - 5
services/contract_paid_service.go

@@ -35,7 +35,7 @@ func (s *contractService) PaidAll(projectId int, bidsectionId int, contractsId i
 	return contractsReturnVM
 }
 
-// 创建回款信息
+// 创建已支付信息
 func (s *contractService) PaidCreate(returnData *viewmodels.ContractsPaid, projectId int, bidsectionId int, contractsId int, projectAccountId int) error {
 	// 1.合同存在
 	contract := s.contractDao.GetInProjectAndBidsection(contractsId, projectId, bidsectionId)
@@ -46,6 +46,15 @@ func (s *contractService) PaidCreate(returnData *viewmodels.ContractsPaid, proje
 	if contract.Status == 2 {
 		return errors.New("合同已关闭")
 	}
+	// 1-3已支付的中金额不能超过 合同金额
+	price, err := strconv.ParseFloat(returnData.Price, 64)
+	if err != nil {
+		return errors.New("金额填写有误")
+	}
+	paidPrice, _ := strconv.ParseFloat(contract.Paid, 64)
+	if price > paidPrice {
+		return errors.New("支付金额不能超过合同金额")
+	}
 
 	// 2.已支付信息
 	contractsReturnCm := &models.CmContractsPaid{}
@@ -66,10 +75,6 @@ func (s *contractService) PaidCreate(returnData *viewmodels.ContractsPaid, proje
 	contractsReturnCm.CreateUser = returnData.CreateUser
 	contractsReturnCm.AccountId = projectAccountId
 
-	_, err = strconv.ParseFloat(returnData.Price, 64)
-	if err != nil {
-		return errors.New("金额填写有误")
-	}
 	contractsReturnCm.Price = returnData.Price
 
 	// 3.新增回款

+ 10 - 4
services/contract_return_service.go

@@ -132,6 +132,16 @@ func (s *contractService) ReturnCreate(returnData *viewmodels.ContractsReturn, p
 		return errors.New("合同已关闭")
 	}
 
+	// 1-3已支付的中金额不能超过 合同金额
+	price, err := strconv.ParseFloat(returnData.Price, 64)
+	if err != nil {
+		return errors.New("金额填写有误")
+	}
+	returnedPrice, _ := strconv.ParseFloat(contract.Returned, 64)
+	if price > returnedPrice {
+		return errors.New("回款金额不能超过合同金额")
+	}
+
 	// 2.回款信息
 	contractsReturnCm := &models.CmContractsReturn{}
 	contractsReturnCm.ContractsId = contractsId
@@ -151,10 +161,6 @@ func (s *contractService) ReturnCreate(returnData *viewmodels.ContractsReturn, p
 	contractsReturnCm.CreateUser = returnData.CreateUser
 	contractsReturnCm.AccountId = projectAccountId
 
-	_, err = strconv.ParseFloat(returnData.Price, 64)
-	if err != nil {
-		return errors.New("金额填写有误")
-	}
 	contractsReturnCm.Price = returnData.Price
 
 	// 3.新增回款

+ 6 - 6
services/contract_service.go

@@ -63,8 +63,8 @@ type ContractService interface {
 	Add(contractData *viewmodels.Contracts, projectId int, bidsectionId int, treeId int) error
 	Update(contractData *viewmodels.Contracts, projectId int, bidsectionId int, treeId int) error
 	Delete(projectId int, bidsectionId int, treeId int, id int) error
-	Close(projectId int, bidsectionId int, treeId int, id int) error
-	Unlock(projectId int, bidsectionId int, treeId int, id int) error
+	Close(projectId int, bidsectionId int, treeId int, id int, treeType int) error
+	Unlock(projectId int, bidsectionId int, treeId int, id int, treeType int) error
 	GetSurvey(bidsectionId int, projectId int, contractsType int) map[string]interface{}
 
 	ReturnCreate(returnData *viewmodels.ContractsReturn, projectId int, bidsectionId int, contractsId int, projectAccountId int) error
@@ -490,9 +490,9 @@ func (s *contractService) Delete(projectId int, bidsectionId int, treeId int, id
 }
 
 // 关闭合同
-func (s *contractService) Close(projectId int, bidsectionId int, treeId int, id int) error {
+func (s *contractService) Close(projectId int, bidsectionId int, treeId int, id int, treeType int) error {
 	// 1. 项目节存在
-	contractsTree := s.treeContractDao.Get(treeId, bidsectionId, projectId, 0)
+	contractsTree := s.treeContractDao.Get(treeId, bidsectionId, projectId, treeType)
 	if contractsTree.Id == 0 {
 		return errors.New("未找到项目节")
 	}
@@ -516,9 +516,9 @@ func (s *contractService) Close(projectId int, bidsectionId int, treeId int, id
 }
 
 // 解锁合同
-func (s *contractService) Unlock(projectId int, bidsectionId int, treeId int, id int) error {
+func (s *contractService) Unlock(projectId int, bidsectionId int, treeId int, id int, treeType int) error {
 	// 1. 项目节存在
-	contractsTree := s.treeContractDao.Get(treeId, bidsectionId, projectId, 0)
+	contractsTree := s.treeContractDao.Get(treeId, bidsectionId, projectId, treeType)
 	if contractsTree.Id == 0 {
 		return errors.New("未找到项目节")
 	}

+ 2 - 2
web/api/contract_api.go

@@ -441,7 +441,7 @@ func (c *ContractApi) PostClose() {
 		return
 	}
 
-	err = c.ServiceContract.Close(projectIdInt, bidsectionId, treeId, id)
+	err = c.ServiceContract.Close(projectIdInt, bidsectionId, treeId, id, contractData.TreeType)
 	if err != nil {
 		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
 		return
@@ -495,7 +495,7 @@ func (c *ContractApi) PostUnlock() {
 		return
 	}
 
-	err = c.ServiceContract.Unlock(projectIdInt, bidsectionId, treeId, id)
+	err = c.ServiceContract.Unlock(projectIdInt, bidsectionId, treeId, id, contractData.TreeType)
 	if err != nil {
 		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
 		return

+ 3 - 3
web/api/contract_paid_api.go

@@ -104,7 +104,7 @@ func (c *ContractApi) PostPaidCreate() {
 	}
 
 	account := c.Ctx.Values().Get("account").(*models.CmProjectAccount)
-	returnData.CreateUser = account.Account
+	returnData.CreateUser = account.Name
 
 	err = c.ServiceContract.PaidCreate(returnData, projectId, bidsectionId, contractsId, projectAccountId)
 	contractData := c.ServiceContract.GetContract(contractsId)
@@ -157,10 +157,10 @@ func (c *ContractApi) PostPaidUpdate() {
 		return
 	}
 	if returnData.Id == "" {
-		c.Ctx.JSON(iris.Map{"code": -1, "msg": "回款ID不能为空"})
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "已支付ID不能为空"})
 		return
 	}
-	// 回款ID
+	// 已支付ID
 	id, err := utils.GetDecryptId(returnData.Id)
 	if err != nil {
 		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})