|
@@ -106,6 +106,13 @@ func (d *ContractReturnDao) UpdateTotalPrice(projectId int, bidsectionId int, co
|
|
|
return errors.New("session出错-db")
|
|
|
}
|
|
|
|
|
|
+ // 0.获得合同金额
|
|
|
+ contractsDetail := &models.CmContracts{}
|
|
|
+ _, err = d.engine.Where(" id = ? ", contractsId).Get(contractsDetail)
|
|
|
+ if err != nil {
|
|
|
+ return errors.New("未找到合同")
|
|
|
+ }
|
|
|
+
|
|
|
// 1.获得合同回款总金额
|
|
|
datalist := make([]models.CmContractsReturn, 0)
|
|
|
err = d.engine.Where(" project_id =? and bidsection_id = ? ", projectId, bidsectionId).Find(&datalist)
|
|
@@ -125,15 +132,23 @@ func (d *ContractReturnDao) UpdateTotalPrice(projectId int, bidsectionId int, co
|
|
|
priceTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", priceTotal), 64)
|
|
|
contractsPrice, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", contractsPrice), 64)
|
|
|
|
|
|
+ // 1-1合同状态的判定
|
|
|
+ contractsDetailPrice, _ := strconv.ParseFloat(contractsDetail.Price, 64)
|
|
|
+ // 总回款大于等于合同金额 待关闭
|
|
|
+ contractStatus := 0
|
|
|
+ if contractsPrice >= contractsDetailPrice {
|
|
|
+ contractStatus = 1
|
|
|
+ }
|
|
|
+
|
|
|
// 2.更新合同表 合同下回款总金额
|
|
|
- _, err = session.Exec("UPDATE cm_contracts SET `returned` = ? where id = ? ", contractsPrice, contractsId)
|
|
|
+ _, err = session.Exec("UPDATE cm_contracts SET `returned` = ? and status = ? where id = ? ", contractsPrice, contractStatus, contractsId)
|
|
|
if err != nil {
|
|
|
session.Rollback()
|
|
|
return errors.New("金额更新失败")
|
|
|
}
|
|
|
// 3.更新项目节 合同下回款总金额
|
|
|
- _, err = session.Exec("UPDATE cm_tree_contracts SET `contract_returned` = ? where project_id = ? and bidsection_id=? and contract_id=? ",
|
|
|
- contractsPrice, projectId, bidsectionId, contractsId)
|
|
|
+ _, err = session.Exec("UPDATE cm_tree_contracts SET `contract_returned` = ? and contract_status = ? where project_id = ? and bidsection_id=? and contract_id=? ",
|
|
|
+ contractsPrice, contractStatus, projectId, bidsectionId, contractsId)
|
|
|
if err != nil {
|
|
|
session.Rollback()
|
|
|
return errors.New("金额更新失败")
|