Bladeren bron

支出合同相关

caipin 4 jaren geleden
bovenliggende
commit
0015c411e4

+ 51 - 2
dao/contract_dao.go

@@ -182,7 +182,7 @@ func (d *ContractDao) Delete(projectId int, bidsectionId int, treeId int, id int
 
 	// 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 "+
-		"where tree_id = ? and project_id = ? and bidsection_id = ? ",
+		",contract_locking=0 where tree_id = ? and project_id = ? and bidsection_id = ? ",
 		treeId, projectId, bidsectionId)
 	if err != nil {
 		session.Rollback()
@@ -207,7 +207,56 @@ func (d *ContractDao) Delete(projectId int, bidsectionId int, treeId int, id int
 	return nil
 }
 
-// 删除合同
+// 删除支出合同
+func (d *ContractDao) DeleteExpenditure(projectId int, bidsectionId int, treeId int, id int) error {
+
+	contractsCm := models.CmContracts{}
+
+	session := d.engine.NewSession()
+	defer session.Close()
+	err := session.Begin()
+	if err != nil {
+		return errors.New("session出错-db")
+	}
+	// 1.删除合同
+	successNum, err := session.Where("id = ? and tree_id=? and bidsection_id= ? and project_id=? ", id, treeId, bidsectionId, projectId).Delete(contractsCm)
+	if err != nil {
+		session.Rollback()
+		return errors.New("删除失败")
+	}
+	if successNum == 0 {
+		session.Rollback()
+		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 = ? ",
+		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("编辑合同出错-项目节更新失败")
+	}
+
+	// 4.删除附件-TODO
+
+	err = session.Commit()
+	if err != nil {
+		session.Rollback()
+		return errors.New("session出错-db")
+	}
+	return nil
+}
+
+// 关闭合同
 func (d *ContractDao) Close(projectId int, bidsectionId int, treeId int, id int) error {
 
 	session := d.engine.NewSession()

+ 71 - 0
dao/contract_return_dao.go

@@ -167,3 +167,74 @@ func (d *ContractReturnDao) UpdateTotalPrice(projectId int, bidsectionId int, co
 	}
 	return nil
 }
+
+// 更新已支付总金额
+func (d *ContractReturnDao) UpdatePaidTotalPrice(projectId int, bidsectionId int, contractsId int) error {
+	session := d.engine.NewSession()
+	defer session.Close()
+	err := session.Begin()
+	if err != nil {
+		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.CmContractsPaid, 0)
+	err = d.engine.Where(" project_id =? and bidsection_id = ? ", projectId, bidsectionId).Find(&datalist)
+	if err != nil {
+		session.Rollback()
+		return errors.New("编辑合同出错-项目节更新失败")
+	}
+	priceTotal := 0.00
+	contractsPrice := 0.00
+	for _, item := range datalist {
+		price, _ := strconv.ParseFloat(item.Price, 64)
+		priceTotal = priceTotal + price
+		if item.ContractsId == contractsId {
+			contractsPrice = contractsPrice + price
+		}
+	}
+	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 `paid` = ? , status = ? where id = ? ", contractsPrice, contractStatus, contractsId)
+	if err != nil {
+		session.Rollback()
+		return errors.New("金额更新失败")
+	}
+	// 3.更新项目节 合同下回款总金额
+	_, err = session.Exec("UPDATE  cm_tree_contracts SET `contracts_paid` = ? , contract_status = ? where project_id = ? and bidsection_id=? and contract_id=? ",
+		contractsPrice, contractStatus, projectId, bidsectionId, contractsId)
+	if err != nil {
+		session.Rollback()
+		return errors.New("金额更新失败")
+	}
+	// 4.更新标段树 整个标段下回款总金额
+	_, err = session.Exec("UPDATE  cm_tree SET `contracts_paid` = ? where project_id = ? and bidsection_id=? ", priceTotal, 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
+}

+ 14 - 0
dao/tree_contract_dao.go

@@ -56,6 +56,20 @@ func (d *TreeContractDao) GetAll(bidsectionId int, projectId int, treeType int)
 	}
 }
 
+// 获得项目节所有合同
+func (d *TreeContractDao) GetContractAll(bidsectionId int, projectId int) []models.CmTreeContracts {
+	datalist := make([]models.CmTreeContracts, 0)
+	err := d.engine.
+		Asc("id").
+		Where("bidsection_id =? and project_id=? and contract_id!=0 ", bidsectionId, projectId).
+		Find(&datalist)
+	if err != nil {
+		return datalist
+	} else {
+		return datalist
+	}
+}
+
 // 获得标段 项目节中已有的合同
 func (d *TreeContractDao) GetContract(bidsectionId int, projectId int, treeType int) []models.CmTreeContracts {
 	datalist := make([]models.CmTreeContracts, 0)

+ 13 - 0
dao/tree_dao.go

@@ -349,6 +349,19 @@ func (d *TreeDao) Update(data *models.CmTree, columns []string) error {
 }
 
 // 更新标段目录上合同金额和总数
+func (d *TreeDao) UpdateContractsAndPayPrice(projectId int, bidsectionId int, contractTotal int, priceTotal float64) error {
+	// 1.更新标段 上的合同总金额
+	_, err := d.engine.Exec("UPDATE  cm_tree SET `contracts` = ?,`contracts_pay` = ? "+
+		"where project_id = ? and bidsection_id = ? ",
+		contractTotal, priceTotal,
+		projectId, bidsectionId)
+	if err != nil {
+		return errors.New("编辑标段目录-金额合计出错")
+	}
+	return nil
+}
+
+// 更新标段目录上合同金额和总数
 func (d *TreeDao) UpdateContractsAndIncomePrice(projectId int, bidsectionId int, contractTotal int, priceTotal float64) error {
 	// 1.更新标段 上的合同总金额
 	_, err := d.engine.Exec("UPDATE  cm_tree SET `contracts` = ?,`contracts_income` = ? "+

+ 2 - 2
models/cm_contracts.go

@@ -7,7 +7,7 @@ import (
 type CmContracts struct {
 	Id            int       `xorm:"not null pk autoincr comment('自增ID') INT(11)"`
 	TreeId        int       `xorm:"not null default 0 comment('树ID') INT(11)"`
-	ContractsType int       `xorm:"not null default 1 comment('合同类型(1收入合同2支出合同)') TINYINT(1)"`
+	ContractsType int       `xorm:"not null default 1 comment('合同类型(1收入2支出)') TINYINT(1)"`
 	ProjectId     int       `xorm:"not null default 0 comment('项目ID') INT(11)"`
 	BidsectionId  int       `xorm:"default 0 comment('标段ID') INT(11)"`
 	Name          string    `xorm:"not null comment('合同名称') VARCHAR(64)"`
@@ -21,7 +21,7 @@ type CmContracts struct {
 	Remarks       string    `xorm:"comment('备注') VARCHAR(1024)"`
 	Price         string    `xorm:"not null default 0.00 comment('合同金额') DECIMAL(12,2)"`
 	Returned      string    `xorm:"not null default 0.00 comment('回款总金额') DECIMAL(12,2)"`
-	Paid          string    `xorm:"not null default 0.00 comment('合同已支付金额 0') DECIMAL(12,2)"`
+	Paid          string    `xorm:"not null default 0.00 comment('合同已支付金额') DECIMAL(12,2)"`
 	Status        int       `xorm:"not null default 0 comment('合同状态(0履行中1待关闭2已关闭)') TINYINT(1)"`
 	Locking       int       `xorm:"not null default 0 comment('锁定(0未锁定1锁定)') TINYINT(1)"`
 	CreateTime    time.Time `xorm:"comment('创建时间') DATETIME"`

+ 22 - 0
models/cm_contracts_paid.go

@@ -0,0 +1,22 @@
+package models
+
+import (
+	"time"
+)
+
+type CmContractsPaid struct {
+	Id           int       `xorm:"not null pk autoincr comment('自增ID') INT(11)"`
+	ContractsId  int       `xorm:"not null default 0 comment('合同ID') INT(11)"`
+	ProjectId    int       `xorm:"not null default 0 comment('项目ID') INT(11)"`
+	BidsectionId int       `xorm:"not null default 0 comment('标段ID') INT(11)"`
+	TreeId       int       `xorm:"not null default 0 comment('项目节ID') INT(11)"`
+	Time         time.Time `xorm:"comment('支付日期') DATETIME"`
+	Price        string    `xorm:"default 0.00 comment('支付金额') DECIMAL(12,2)"`
+	Way          string    `xorm:"comment('支付方式') VARCHAR(32)"`
+	CreateUser   string    `xorm:"comment('创建人') VARCHAR(32)"`
+	AccountId    int       `xorm:"not null default 0 comment('项目用户ID') INT(11)"`
+	Remarks      string    `xorm:"comment('备注') VARCHAR(512)"`
+	Annexes      int       `xorm:"default 0 comment('附件数量') TINYINT(2)"`
+	CreateTime   time.Time `xorm:"comment('创建时间') DATETIME"`
+	UpdateTime   time.Time `xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') TIMESTAMP"`
+}

+ 1 - 1
models/cm_safe.go

@@ -14,7 +14,7 @@ type CmSafe struct {
 	Inspection       string    `xorm:"comment('检查项目') VARCHAR(3072)"`
 	InspectionDetail string    `xorm:"comment('现场检查情况') TEXT"`
 	Demand           string    `xorm:"comment('处理要求') VARCHAR(128)"`
-	Status           int       `xorm:"default 0 comment('状态') INT(11)"`
+	Status           int       `xorm:"default 0 comment('状态(0待审批1通过2退回3关闭)') INT(11)"`
 	Uid              int       `xorm:"not null default 0 comment('创建者id') INT(11)"`
 	Times            int       `xorm:"default 0 comment('审批次数') INT(11)"`
 }

+ 1 - 1
models/cm_safe_audit.go

@@ -11,7 +11,7 @@ type CmSafeAudit struct {
 	Times        int       `xorm:"not null default 0 comment('审核次数') INT(11)"`
 	AuditId      int       `xorm:"not null default 0 comment('审核人id') INT(11)"`
 	AuditOrder   int       `xorm:"not null default 0 comment('审批顺序') INT(11)"`
-	Status       int       `xorm:"default 0 comment('审核状态') INT(11)"`
+	Status       int       `xorm:"default 0 comment('审核状态(0待审批1通过2退回3关闭)') INT(11)"`
 	Progress     int       `xorm:"not null default 0 comment('审批进度(0审批1整改2复查)') TINYINT(1)"`
 	CreateTime   time.Time `xorm:"comment('开始时间') DATETIME"`
 	EndTime      time.Time `xorm:"comment('结束时间') DATETIME"`

+ 150 - 0
services/contract_expenditure_service.go

@@ -0,0 +1,150 @@
+/*
+ * @description: 合同支出业务相关
+ * @Author: CP
+ * @Date: 2020-12-21 15:35:03
+ * @FilePath: \construction_management\services\contract_expenditure_service.go
+ */
+
+package services
+
+import (
+	"errors"
+	"time"
+
+	"go.mod/conf"
+	"go.mod/models"
+	"go.mod/web/viewmodels"
+)
+
+// 新增支出合同
+func (s *contractService) AddExpenditure(contractData *viewmodels.Contracts, projectId int, bidsectionId int, treeId int) error {
+	// 1. 项目节存在
+	contracts := s.treeContractDao.Get(treeId, bidsectionId, projectId, 1)
+	if contracts.Id == 0 {
+		return errors.New("未找到项目节")
+	}
+	// k := int32(projectId)
+	// 2.项目节是没有合同
+	if contracts.ContractId != 0 {
+		return errors.New("该项目节上已经存在合同")
+	}
+
+	// 3.新增合同 --合计标段上的金额
+	contractsCm := &models.CmContracts{}
+	contractsCm.Code = contractData.Code
+	contractsCm.Name = contractData.Name
+	contractsCm.ContractsType = 2
+	contractsCm.Price = contractData.Price
+	contractsCm.Returned = "0"
+	contractsCm.Paid = "0"
+	contractsCm.TreeId = treeId
+	contractsCm.ProjectId = projectId
+	contractsCm.BidsectionId = bidsectionId
+	contractsCm.Status = 0
+	contractsCm.CreateTime = time.Now()
+	contractsCm.UpdateTime = time.Now()
+
+	err := s.contractDao.Add(contractsCm)
+	if err != nil {
+		return err
+	}
+
+	// 3.获得该标段下合同总数 - 总收入金额
+	contractTotal, priceTotal := s.getContractTotalAndPrice(bidsectionId, projectId, 1)
+	// 更新标段目录上合同金额和总数
+	err = s.treeDao.UpdateContractsAndPayPrice(projectId, bidsectionId, contractTotal, priceTotal)
+	if err != nil {
+		return err
+	}
+
+	return nil
+}
+
+// 更新支出合同
+func (s *contractService) UpdateExpenditure(contractData *viewmodels.Contracts, projectId int, bidsectionId int, treeId int) error {
+	// 1. 项目节存在
+	contractsTree := s.treeContractDao.Get(treeId, bidsectionId, projectId, 1)
+	if contractsTree.Id == 0 {
+		return errors.New("未找到项目节")
+	}
+	// 2.项目节是没有合同
+	if contractsTree.ContractId == 0 {
+		return errors.New("该项目节上没有找到合同")
+	}
+
+	// 3.合同锁定 不能删除
+	if contractsTree.ContractLocking == 1 {
+		return errors.New("该合同已锁定")
+	}
+
+	contractsCm := &models.CmContracts{}
+	contractsCm.Id = contractsTree.ContractId
+	contractsCm.Content = contractData.Content
+	contractsCm.Name = contractData.Name
+	contractsCm.Price = contractData.Price
+	contractsCm.PartyA = contractData.PartyA
+	contractsCm.PartyASigner = contractData.PartyASigner
+	contractsCm.PartyB = contractData.PartyB
+	contractsCm.PartyBSigner = contractData.PartyBSigner
+
+	loc, _ := time.LoadLocation("Local")
+	SignerTime, err := time.ParseInLocation(conf.SysTimeform, contractData.SignerTime, loc)
+	if err != nil {
+		return errors.New("签约时间填写异常")
+	}
+	contractsCm.SignerTime = SignerTime
+	contractsCm.Remarks = contractData.Remarks
+
+	columns := []string{"Content", "Name", "Price", "PartyA", "PartyASigner", "PartyB", "PartyBSigner"}
+	err = s.contractDao.Update(contractsCm, columns, projectId, bidsectionId, treeId)
+	if err != nil {
+		return err
+	}
+	// 3.获得该标段下合同总数 - 总收入金额
+	contractTotal, priceTotal := s.getContractTotalAndPrice(bidsectionId, projectId, 1)
+	// 更新标段目录上合同金额和总数
+	err = s.treeDao.UpdateContractsAndPayPrice(projectId, bidsectionId, contractTotal, priceTotal)
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+// 删除支出合同
+func (s *contractService) DeleteExpenditure(projectId int, bidsectionId int, treeId int, id int) error {
+	// 1. 项目节存在
+	contractsTree := s.treeContractDao.Get(treeId, bidsectionId, projectId, 1)
+	if contractsTree.Id == 0 {
+		return errors.New("未找到项目节")
+	}
+	// 2.项目节是没有合同
+	if contractsTree.ContractId == 0 {
+		return errors.New("该项目节上没有找到合同")
+	}
+
+	// 3.合同锁定 不能删除
+	if contractsTree.ContractLocking == 1 {
+		return errors.New("该合同已锁定")
+	}
+
+	// 删除支出合同
+	err := s.contractDao.DeleteExpenditure(projectId, bidsectionId, treeId, id)
+	if err != nil {
+		return err
+	}
+	// 3.获得该标段下合同总数 - 总收入金额
+	contractTotal, priceTotal := s.getContractTotalAndPrice(bidsectionId, projectId, 1)
+	// 更新标段目录上合同金额和总数
+	err = s.treeDao.UpdateContractsAndPayPrice(projectId, bidsectionId, contractTotal, priceTotal)
+	if err != nil {
+		return err
+	}
+
+	// 4.更新回款总金额
+	err = s.contractReturnDao.UpdatePaidTotalPrice(projectId, bidsectionId, id)
+	if err != nil {
+		return err
+	}
+
+	return nil
+}

+ 30 - 28
services/contract_section_tree_service.go

@@ -16,8 +16,8 @@ import (
 )
 
 // 获得合同项目节
-func (s *contractService) GetSecionTree(bidsectionId int, projectId int) *viewmodels.TreeSectionContract {
-	dataList := s.treeContractDao.GetAll(bidsectionId, projectId, 0)
+func (s *contractService) GetSecionTree(bidsectionId int, projectId int, treeType int) *viewmodels.TreeSectionContract {
+	dataList := s.treeContractDao.GetAll(bidsectionId, projectId, treeType)
 	sectionList := s.makeSectionTreeView(dataList)
 
 	// Node := sectionRoot //父节点
@@ -27,13 +27,13 @@ func (s *contractService) GetSecionTree(bidsectionId int, projectId int) *viewmo
 }
 
 // 获得项目节树和孩子们下的合同数据
-func (s *contractService) GetSectionTreeContract(attribution string, bidsectionId int, projectId int) []*viewmodels.Contracts {
-	s.treeContractDao.GetAttribution(attribution, bidsectionId, projectId, 0)
+func (s *contractService) GetSectionTreeContract(attribution string, bidsectionId int, projectId int, treeType int) []*viewmodels.Contracts {
+	s.treeContractDao.GetAttribution(attribution, bidsectionId, projectId, treeType)
 	return nil
 }
 
 // 设置合同项目节初始数据-根据模板导入
-func (s *contractService) SetSection(templateNumber int, bidsectionId int, projectId int) error {
+func (s *contractService) SetSection(templateNumber int, bidsectionId int, projectId int, treeType int) error {
 	// 获得模板数据
 	templateTree := make([]*lib.ItemSectionTemplateTree, 0)
 	if templateNumber == 1 {
@@ -49,6 +49,7 @@ func (s *contractService) SetSection(templateNumber int, bidsectionId int, proje
 	for _, item := range templateTree {
 		section := &models.CmTreeContracts{}
 		section.TreeId = item.Id
+		section.TreeType = treeType
 		section.ParentId = item.ParentId
 		section.ProjectId = projectId
 		section.BidsectionId = bidsectionId
@@ -75,13 +76,13 @@ func (s *contractService) SetSection(templateNumber int, bidsectionId int, proje
 }
 
 // 新增项目节
-func (s *contractService) SectionAdd(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int) error {
+func (s *contractService) SectionAdd(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int, treeType int) error {
 	// 1.验证项目节ID
 	treeId, err := utils.GetDecryptId(sectionData.Id)
 	if err != nil {
 		return err
 	}
-	sectionFather := s.treeContractDao.Get(treeId, bidsectionId, projectId, 0)
+	sectionFather := s.treeContractDao.Get(treeId, bidsectionId, projectId, treeType)
 	if sectionFather.Id == 0 {
 		return errors.New("未找到合同项目节")
 	}
@@ -96,7 +97,7 @@ func (s *contractService) SectionAdd(sectionData *viewmodels.TreeSectionContract
 
 	// 2 获得最大序号
 	// 2-1 孩子节点
-	childrenList := s.treeContractDao.GetChildren(treeId, bidsectionId, projectId, 0)
+	childrenList := s.treeContractDao.GetChildren(treeId, bidsectionId, projectId, treeType)
 	// 2-1 最大序号
 	serial := 1
 	if len(childrenList) != 0 {
@@ -107,6 +108,7 @@ func (s *contractService) SectionAdd(sectionData *viewmodels.TreeSectionContract
 	code := fmt.Sprintf("%s%d", attribution, serial)
 	// 新增项目节
 	sectionCM := &models.CmTreeContracts{}
+	sectionCM.TreeId = treeType
 	sectionCM.ParentId = sectionFather.TreeId
 	sectionCM.Name = sectionData.Name
 	sectionCM.Depth = sectionFather.Depth + 1
@@ -128,13 +130,13 @@ func (s *contractService) SectionAdd(sectionData *viewmodels.TreeSectionContract
 }
 
 // 保存名称
-func (s *contractService) SectionSave(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int) error {
+func (s *contractService) SectionSave(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int, treeType int) error {
 	// 1.验证项目节ID
 	treeId, err := utils.GetDecryptId(sectionData.Id)
 	if err != nil {
 		return err
 	}
-	section := s.treeContractDao.Get(treeId, bidsectionId, projectId, 0)
+	section := s.treeContractDao.Get(treeId, bidsectionId, projectId, treeType)
 	if section.Id == 0 {
 		return errors.New("未找到合同项目节")
 	}
@@ -157,13 +159,13 @@ func (s *contractService) SectionSave(sectionData *viewmodels.TreeSectionContrac
 }
 
 // 更新序号
-func (s *contractService) UpdateSerial(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int) error {
+func (s *contractService) UpdateSerial(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int, treeType int) error {
 	// 1.验证项目节ID
 	treeId, err := utils.GetDecryptId(sectionData.Id)
 	if err != nil {
 		return err
 	}
-	section := s.treeContractDao.Get(treeId, bidsectionId, projectId, 0)
+	section := s.treeContractDao.Get(treeId, bidsectionId, projectId, treeType)
 	if section.Id == 0 {
 		return errors.New("未找到合同项目节")
 	}
@@ -173,7 +175,7 @@ func (s *contractService) UpdateSerial(sectionData *viewmodels.TreeSectionContra
 	// 	return errors.New("请在项目节第三层开始编辑")
 	// }
 
-	err = s.treeContractDao.UpdateSerial(section, sectionData.Serial, 0)
+	err = s.treeContractDao.UpdateSerial(section, sectionData.Serial, treeType)
 	if err != nil {
 		return errors.New("更新失败")
 	}
@@ -181,9 +183,9 @@ func (s *contractService) UpdateSerial(sectionData *viewmodels.TreeSectionContra
 }
 
 // 项目节删除
-func (s *contractService) SectionDelete(treeId int, bidsectionId int, projectId int) error {
+func (s *contractService) SectionDelete(treeId int, bidsectionId int, projectId int, treeType int) error {
 	// 1.验证项目节ID
-	section := s.treeContractDao.Get(treeId, bidsectionId, projectId, 0)
+	section := s.treeContractDao.Get(treeId, bidsectionId, projectId, treeType)
 	if section.Id == 0 {
 		return errors.New("未找到合同项目节")
 	}
@@ -193,9 +195,9 @@ func (s *contractService) SectionDelete(treeId int, bidsectionId int, projectId
 	// 	return errors.New("请在项目节第三层开始编辑")
 	// }
 	// 1-2 有合同的不能编辑(包含孩子节点)
-	contractList := s.GetSectionTreeContract(section.Attribution, section.BidsectionId, section.ProjectId)
+	contractList := s.GetSectionTreeContract(section.Attribution, section.BidsectionId, section.ProjectId, treeType)
 	if len(contractList) != 0 {
-		return errors.New("该项目节存在合同")
+		return errors.New("该项目节存在合同")
 	}
 
 	err := s.treeContractDao.Delete(section)
@@ -206,13 +208,13 @@ func (s *contractService) SectionDelete(treeId int, bidsectionId int, projectId
 }
 
 // 项目节的层级移动
-func (s *contractService) MoveDepth(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int) error {
+func (s *contractService) MoveDepth(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int, treeType int) error {
 	// 1.验证项目节ID
 	treeId, err := utils.GetDecryptId(sectionData.Id)
 	if err != nil {
 		return err
 	}
-	section := s.treeContractDao.Get(treeId, bidsectionId, projectId, 0)
+	section := s.treeContractDao.Get(treeId, bidsectionId, projectId, treeType)
 	if section.Id == 0 {
 		return errors.New("未找到合同项目节")
 	}
@@ -221,7 +223,7 @@ func (s *contractService) MoveDepth(sectionData *viewmodels.TreeSectionContract,
 	// 	return errors.New("请在项目节第三层开始编辑")
 	// }
 	// 1-2 有合同的不能编辑(包含孩子节点)
-	contractList := s.GetSectionTreeContract(section.Attribution, section.BidsectionId, section.ProjectId)
+	contractList := s.GetSectionTreeContract(section.Attribution, section.BidsectionId, section.ProjectId, treeType)
 	if len(contractList) != 0 {
 		return errors.New("该项目节已存在合同")
 	}
@@ -230,7 +232,7 @@ func (s *contractService) MoveDepth(sectionData *viewmodels.TreeSectionContract,
 	elderBrother := &models.CmTreeContracts{}
 	if sectionData.Operation == "downDepth" {
 		// 获得前一个兄弟节点
-		elderBrotherList := s.treeContractDao.GetElderBrother(section.Serial, section.Depth, section.ParentId, bidsectionId, projectId, 0)
+		elderBrotherList := s.treeContractDao.GetElderBrother(section.Serial, section.Depth, section.ParentId, bidsectionId, projectId, treeType)
 		if len(elderBrotherList) == 0 {
 			return errors.New("项目节不能降级")
 		}
@@ -249,7 +251,7 @@ func (s *contractService) MoveDepth(sectionData *viewmodels.TreeSectionContract,
 	}
 
 	// 4.执行升降级
-	err = s.treeContractDao.MoveDepth(section, elderBrother, sectionData.Operation, bidsectionId, projectId, 0)
+	err = s.treeContractDao.MoveDepth(section, elderBrother, sectionData.Operation, bidsectionId, projectId, treeType)
 	if err != nil {
 		return err
 	}
@@ -258,13 +260,13 @@ func (s *contractService) MoveDepth(sectionData *viewmodels.TreeSectionContract,
 }
 
 // 项目节的排序移动
-func (s *contractService) MoveSerial(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int) error {
+func (s *contractService) MoveSerial(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int, treeType int) error {
 	// 1.验证项目节ID
 	treeId, err := utils.GetDecryptId(sectionData.Id)
 	if err != nil {
 		return err
 	}
-	section := s.treeContractDao.Get(treeId, bidsectionId, projectId, 0)
+	section := s.treeContractDao.Get(treeId, bidsectionId, projectId, treeType)
 	if section.Id == 0 {
 		return errors.New("未找到合同项目节")
 	}
@@ -273,7 +275,7 @@ func (s *contractService) MoveSerial(sectionData *viewmodels.TreeSectionContract
 	// 	return errors.New("请在项目节第三层开始编辑")
 	// }
 	// 1-2 有合同的不能编辑(包含孩子节点)
-	contractList := s.GetSectionTreeContract(section.Attribution, section.BidsectionId, section.ProjectId)
+	contractList := s.GetSectionTreeContract(section.Attribution, section.BidsectionId, section.ProjectId, treeType)
 	if len(contractList) != 0 {
 		return errors.New("该项目节已存在合同")
 	}
@@ -282,14 +284,14 @@ func (s *contractService) MoveSerial(sectionData *viewmodels.TreeSectionContract
 	brother := &models.CmTreeContracts{}
 	if sectionData.Operation == "downSerial" {
 		// 获得下一个兄弟
-		youngerBrotherList := s.treeContractDao.GetYoungerBrother(section.Serial, section.Depth, section.ParentId, bidsectionId, projectId, 0)
+		youngerBrotherList := s.treeContractDao.GetYoungerBrother(section.Serial, section.Depth, section.ParentId, bidsectionId, projectId, treeType)
 		if len(youngerBrotherList) == 0 {
 			return errors.New("项目节不能下移")
 		}
 		brother = &youngerBrotherList[0]
 	} else if sectionData.Operation == "upSerial" {
 		// 获得上一个兄弟
-		elderBrotherList := s.treeContractDao.GetElderBrother(section.Serial, section.Depth, section.ParentId, bidsectionId, projectId, 0)
+		elderBrotherList := s.treeContractDao.GetElderBrother(section.Serial, section.Depth, section.ParentId, bidsectionId, projectId, treeType)
 		if len(elderBrotherList) == 0 {
 			return errors.New("项目节不能上移")
 		}
@@ -299,7 +301,7 @@ func (s *contractService) MoveSerial(sectionData *viewmodels.TreeSectionContract
 	}
 
 	// 4.执行升降级
-	err = s.treeContractDao.MoveSerial(section, brother, sectionData.Operation, bidsectionId, projectId, 0)
+	err = s.treeContractDao.MoveSerial(section, brother, sectionData.Operation, bidsectionId, projectId, treeType)
 	if err != nil {
 		return err
 	}

+ 26 - 16
services/contract_service.go

@@ -39,15 +39,15 @@ type ContractService interface {
 	ValidRuleContractRetrunDel(ctx iris.Context) (*viewmodels.ContractsReturn, error)
 
 	Get(treeId int, bidsectionId int, projectId int) *viewmodels.TreeSectionContract
-	GetSectionTreeContract(attribution string, bidsectionId int, projectId int) []*viewmodels.Contracts
-	GetSecionTree(bidsectionId int, projectId int) *viewmodels.TreeSectionContract
-	SetSection(templateNumber int, bidsectionId int, projectIdInt int) error
-	SectionAdd(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int) error
-	SectionSave(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int) error
-	UpdateSerial(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int) error
-	SectionDelete(treeId int, bidsectionId int, projectId int) error
-	MoveDepth(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int) error
-	MoveSerial(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int) error
+	GetSectionTreeContract(attribution string, bidsectionId int, projectId int, treeType int) []*viewmodels.Contracts
+	GetSecionTree(bidsectionId int, projectId int, treeType int) *viewmodels.TreeSectionContract
+	SetSection(templateNumber int, bidsectionId int, projectIdInt int, treeType int) error
+	SectionAdd(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int, treeType int) error
+	SectionSave(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int, treeType int) error
+	UpdateSerial(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int, treeType int) error
+	SectionDelete(treeId int, bidsectionId int, projectId int, treeType int) error
+	MoveDepth(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int, treeType int) error
+	MoveSerial(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int, treeType int) error
 
 	GetContract(contractId int) *viewmodels.Contracts
 	Add(contractData *viewmodels.Contracts, projectId int, bidsectionId int, treeId int) error
@@ -60,6 +60,11 @@ type ContractService interface {
 	ReturnUpdate(returnData *viewmodels.ContractsReturn, projectId int, bidsectionId int, contractsId int, id int) error
 	ReturnAll(projectId int, bidsectionId int, contractsId int, page int) []*viewmodels.ContractsReturn
 	ReturnDelete(projectId int, bidsectionId int, contractsId int, id int) error
+
+	//支出合同
+	AddExpenditure(contractData *viewmodels.Contracts, projectId int, bidsectionId int, treeId int) error
+	UpdateExpenditure(contractData *viewmodels.Contracts, projectId int, bidsectionId int, treeId int) error
+	DeleteExpenditure(projectId int, bidsectionId int, treeId int, id int) error
 }
 
 //返回service操作类
@@ -261,6 +266,7 @@ func (s *contractService) ValidRuleContractDel(ctx iris.Context) (*viewmodels.Co
 	return contractsVaild, nil
 }
 
+//------------------------------------------------------------
 // 获得项目节
 func (s *contractService) Get(treeId int, bidsectionId int, projectId int) *viewmodels.TreeSectionContract {
 	// 1.获得项目节
@@ -332,7 +338,7 @@ func (s *contractService) Add(contractData *viewmodels.Contracts, projectId int,
 	contractsCm := &models.CmContracts{}
 	contractsCm.Code = contractData.Code
 	contractsCm.Name = contractData.Name
-	contractsCm.ContractsType = contractData.ContractsType
+	contractsCm.ContractsType = 1
 	contractsCm.Price = contractData.Price
 	contractsCm.Returned = "0"
 	contractsCm.Paid = "0"
@@ -349,7 +355,7 @@ func (s *contractService) Add(contractData *viewmodels.Contracts, projectId int,
 	}
 
 	// 3.获得该标段下合同总数 - 总收入金额
-	contractTotal, priceTotal := s.getContractTotalAndPrice(bidsectionId, projectId)
+	contractTotal, priceTotal := s.getContractTotalAndPrice(bidsectionId, projectId, 0)
 	// 更新标段目录上合同金额和总数
 	err = s.treeDao.UpdateContractsAndIncomePrice(projectId, bidsectionId, contractTotal, priceTotal)
 	if err != nil {
@@ -400,7 +406,7 @@ func (s *contractService) Update(contractData *viewmodels.Contracts, projectId i
 		return err
 	}
 	// 3.获得该标段下合同总数 - 总收入金额
-	contractTotal, priceTotal := s.getContractTotalAndPrice(bidsectionId, projectId)
+	contractTotal, priceTotal := s.getContractTotalAndPrice(bidsectionId, projectId, 0)
 	// 更新标段目录上合同金额和总数
 	err = s.treeDao.UpdateContractsAndIncomePrice(projectId, bidsectionId, contractTotal, priceTotal)
 	if err != nil {
@@ -432,7 +438,7 @@ func (s *contractService) Delete(projectId int, bidsectionId int, treeId int, id
 		return err
 	}
 	// 3.获得该标段下合同总数 - 总收入金额
-	contractTotal, priceTotal := s.getContractTotalAndPrice(bidsectionId, projectId)
+	contractTotal, priceTotal := s.getContractTotalAndPrice(bidsectionId, projectId, 0)
 	// 更新标段目录上合同金额和总数
 	err = s.treeDao.UpdateContractsAndIncomePrice(projectId, bidsectionId, contractTotal, priceTotal)
 	if err != nil {
@@ -496,8 +502,12 @@ func (s *contractService) Unlock(projectId int, bidsectionId int, treeId int, id
 }
 
 // 获得合同总数量和总金额
-func (s *contractService) getContractTotalAndPrice(bidsectionId int, projectId int) (contractTotal int, priceTotal float64) {
-	contractList := s.treeContractDao.GetContract(bidsectionId, projectId, 0)
+func (s *contractService) getContractTotalAndPrice(bidsectionId int, projectId int, treeType int) (contractTotal int, priceTotal float64) {
+
+	contractListAll := s.treeContractDao.GetContractAll(bidsectionId, projectId)
+
+	// 获得收入合同
+	contractList := s.treeContractDao.GetContract(bidsectionId, projectId, treeType)
 	priceTotal = 0.00
 	for _, item := range contractList {
 		contractPrice, _ := strconv.ParseFloat(item.ContractPrice, 64)
@@ -505,7 +515,7 @@ func (s *contractService) getContractTotalAndPrice(bidsectionId int, projectId i
 	}
 	// 合同总数
 	// contractTotal = len(contractList) + 1
-	contractTotal = len(contractList)
+	contractTotal = len(contractListAll)
 	// 合同收入总金额
 	// price, _ := strconv.ParseFloat(priceString, 64)
 	// priceTotal = priceTotal + price

+ 8 - 8
web/api/contract_api.go

@@ -53,7 +53,7 @@ func (c *ContractApi) GetFolder() {
 }
 
 // @Summary 获得标段收入-项目节信息
-// @Tags 合同管理
+// @Tags 合同管理-收入合同
 // @Description 未设置合同项目节 返回项目节模板信息
 // @Accept  json
 // @Produce  json
@@ -87,7 +87,7 @@ func (c *ContractApi) GetIncomeSectionAll() {
 	}
 
 	//获得合同项目节
-	sectionTree := c.ServiceContract.GetSecionTree(bidsectionId, projectIdInt)
+	sectionTree := c.ServiceContract.GetSecionTree(bidsectionId, projectIdInt, 0)
 
 	// 1.未设置了项目节
 	if len(sectionTree.Children) == 0 {
@@ -117,8 +117,8 @@ func (c *ContractApi) GetIncomeSectionAll() {
 	}
 }
 
-// @Summary 单个合同详情和项目节详情
-// @Tags 合同管理
+// @Summary 单个合同和项目节
+// @Tags 合同管理-收入合同
 // @Description 获得合同详情和项目节详情
 // @Accept  json
 // @Produce  json
@@ -159,7 +159,7 @@ func (c *ContractApi) GetIncome() {
 
 	// 该项目节 子树下是否有合同
 	isContract := true
-	contractList := c.ServiceContract.GetSectionTreeContract(section.Attribution, bidsectionId, projectId)
+	contractList := c.ServiceContract.GetSectionTreeContract(section.Attribution, bidsectionId, projectId, 0)
 	if len(contractList) == 0 {
 		isContract = false
 	}
@@ -179,7 +179,7 @@ func (c *ContractApi) GetIncome() {
 }
 
 // @Summary 新增合同
-// @Tags 合同管理
+// @Tags 合同管理-收入合同
 // @Description 新增合同
 // @Accept  json
 // @Produce  json
@@ -239,7 +239,7 @@ func (c *ContractApi) PostIncomeCreate() {
 }
 
 // @Summary 编辑合同
-// @Tags 合同管理
+// @Tags 合同管理-收入合同
 // @Description 编辑合同
 // @Accept  json
 // @Produce  json
@@ -307,7 +307,7 @@ func (c *ContractApi) PostIncomeUpdate() {
 }
 
 // @Summary 删除合同
-// @Tags 合同管理
+// @Tags 合同管理-收入合同
 // @Description 删除合同
 // @Accept  json
 // @Produce  json

+ 332 - 0
web/api/contract_expenditure_api.go

@@ -0,0 +1,332 @@
+/*
+ * @description: 合同支出相关控制
+ * @Author: CP
+ * @Date: 2020-12-18 16:44:13
+ * @FilePath: \construction_management\web\api\contract_expenditure_api.go
+ */
+package api
+
+import (
+	"fmt"
+
+	"github.com/kataras/iris/v12"
+	"go.mod/lib"
+	"go.mod/web/utils"
+	"go.mod/web/viewmodels"
+)
+
+// @Summary 获得标段支出-项目节信息
+// @Tags 合同管理-支出合同
+// @Description 未设置合同项目节 返回项目节模板信息
+// @Accept  json
+// @Produce  json
+// @Security ApiKeyAuth
+// @Param   bidsectionId     path    string     true        "标段ID"
+// @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,data:viewmodels.TreeSectionContract,msg:错误信息}"
+// @Router /api/contract/paid/section/all [get]
+func (c *ContractApi) GetPaidSectionAll() {
+
+	sectionData := viewmodels.TreeSectionContract{}
+	err := c.Ctx.ReadForm(&sectionData)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
+		return
+	}
+	if sectionData.BidsectionId == "" {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
+		return
+	}
+	bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
+		return
+	}
+
+	// 项目ID
+	projectIdInt, err := utils.GetProjectId(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
+		return
+	}
+
+	//获得合同项目节
+	sectionTree := c.ServiceContract.GetSecionTree(bidsectionId, projectIdInt, 1)
+
+	// 1.未设置了项目节
+	if len(sectionTree.Children) == 0 {
+		// 返回项目节2个基础模板
+		templateTree1 := lib.NewItemSection().TemplateTree1
+		templateTree2 := lib.NewItemSection().TemplateTree2
+
+		c.Ctx.JSON(iris.Map{
+			"code":             0,
+			"msg":              "",
+			"isTemplate":       1,
+			"sectionTemplate1": templateTree1,
+			"sectionTemplate2": templateTree2,
+		})
+		return
+		//2.项目节已设置
+	} else {
+		// 2.已设置项目节
+		c.Ctx.JSON(iris.Map{
+			"code":        0,
+			"msg":         "",
+			"isTemplate":  0,
+			"sectionTree": sectionTree,
+		})
+		return
+		// 返回项目相关所有信息
+	}
+}
+
+// @Summary 单个合同详情和项目节详情
+// @Tags 合同管理-支出合同
+// @Description 获得合同详情和项目节详情
+// @Accept  json
+// @Produce  json
+// @Security ApiKeyAuth
+// @Param   id     path    string     true        "项目节ID"
+// @Param   bidsectionId     path    string     true        "标段ID"
+// @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,isContract:是否有合同(包含孩子们),section:viewmodels.TreeSectionContract,msg:错误信息}"
+// @Router /api/contract/paid [get]
+func (c *ContractApi) GetPaid() {
+	// 1.规则验证
+	sectionData, err := c.ServiceContract.ValidRuleGet(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
+		return
+	}
+
+	// 2.项目ID
+	projectId, err := utils.GetProjectId(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
+		return
+	}
+	// 3.标段ID
+	bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
+		return
+	}
+	// 4.树ID
+	treeId, err := utils.GetDecryptId(sectionData.Id)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
+		return
+	}
+
+	// 获得项目节详情
+	section := c.ServiceContract.Get(treeId, bidsectionId, projectId)
+
+	// 该项目节 子树下是否有合同
+	isContract := true
+	contractList := c.ServiceContract.GetSectionTreeContract(section.Attribution, bidsectionId, projectId, 1)
+	if len(contractList) == 0 {
+		isContract = false
+	}
+	// 获得合同详情
+	contractId, _ := utils.GetDecryptId(section.ContractId)
+	contract := &viewmodels.Contracts{}
+	if contractId != 0 {
+		contract = c.ServiceContract.GetContract(contractId)
+	}
+	c.Ctx.JSON(iris.Map{
+		"code":       0,
+		"msg":        "",
+		"section":    section,
+		"isContract": isContract, //该项目节(包含子孙)下是否有合同
+		"contract":   contract,
+	})
+}
+
+// @Summary 新增合同
+// @Tags 合同管理-支出合同
+// @Description 新增合同
+// @Accept  json
+// @Produce  json
+// @Security ApiKeyAuth
+// @Param   treeId     path    string     true        "项目节ID"
+// @Param   bidsectionId     path    string     true        "标段ID"
+// @Param   code     path    string     true        "合同编号"
+// @Param   name     path    string     true        "合同名称"
+// @Param   contractsType     path    int     true        "合同类型(1)"
+// @Param   price     path    string     true        "合同金额"
+// @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
+// @Router /api/contract/expenditure/create [post]
+func (c *ContractApi) PostExpenditureCreate() {
+	// 验证参数
+	contractData, err := c.ServiceContract.ValidRuleContractAdd(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+
+	// 项目ID
+	projectIdInt, err := utils.GetProjectId(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+	// 标段ID
+	bidsectionId, err := utils.GetDecryptId(contractData.BidsectionId)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+	// 项目节ID
+	treeId, err := utils.GetDecryptId(contractData.TreeId)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+
+	if !(contractData.ContractsType == 0 || contractData.ContractsType == 1) {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同类型只能是0或者1"})
+		return
+	}
+
+	err = c.ServiceContract.AddExpenditure(contractData, projectIdInt, bidsectionId, treeId)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+
+	// 获得项目节
+	sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt)
+	// 合同ID
+	contractId, _ := utils.GetDecryptId(sectionDetail.ContractId)
+	contractDetail := c.ServiceContract.GetContract(contractId)
+
+	c.Ctx.JSON(iris.Map{
+		"code":     0,
+		"msg":      "新增成功",
+		"contract": contractDetail,
+	})
+}
+
+// @Summary 编辑合同
+// @Tags 合同管理-支出合同
+// @Description 编辑合同
+// @Accept  json
+// @Produce  json
+// @Security ApiKeyAuth
+// @Param   id     path    string     true        "合同ID"
+// @Param   treeId     path    string     true        "项目节ID"
+// @Param   bidsectionId     path    string     true        "标段ID"
+// @Param   content     path    string     true        "合同内容"
+// @Param   name     path    string     true        "合同名称"
+// @Param   price     path    string     true        "合同金额"
+// @Param   partyA     path    string     true        "甲方"
+// @Param   partyASigner     path    string     true        "甲方签约人"
+// @Param   partyB     path    string     true        "已方"
+// @Param   partyBSigner     path    string     true        "已方签约人"
+// @Param   signerTime     path    string     true        "签约时间"
+// @Param   remarks     path    string     true        "备注"
+// @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
+// @Router /api/contract/expenditure/update [post]
+func (c *ContractApi) PostExpenditureUpdate() {
+	// 验证参数
+	contractData, err := c.ServiceContract.ValidRuleContractEdi(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+
+	// 项目ID
+	projectIdInt, err := utils.GetProjectId(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+	// 标段ID
+	bidsectionId, err := utils.GetDecryptId(contractData.BidsectionId)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+	// 项目节ID
+	treeId, err := utils.GetDecryptId(contractData.TreeId)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+
+	err = c.ServiceContract.UpdateExpenditure(contractData, projectIdInt, bidsectionId, treeId)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+
+	//2.请求当前项目信息
+	// 1.验证项目节ID
+	sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt)
+	// 合同ID
+	contractId, _ := utils.GetDecryptId(sectionDetail.ContractId)
+	contractDetail := c.ServiceContract.GetContract(contractId)
+
+	c.Ctx.JSON(iris.Map{
+		"code":     0,
+		"msg":      "编辑成功",
+		"section":  sectionDetail,
+		"contract": contractDetail,
+	})
+}
+
+// @Summary 删除合同
+// @Tags 合同管理-支出合同
+// @Description 删除合同
+// @Accept  json
+// @Produce  json
+// @Security ApiKeyAuth
+// @Param   id     path    string     true        "合同ID"
+// @Param   treeId     path    string     true        "项目节ID"
+// @Param   bidsectionId     path    string     true        "标段ID"
+// @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
+// @Router /api/contract/expenditure [delete]
+func (c *ContractApi) DeleteExpenditure() {
+	// 验证参数
+	contractData, err := c.ServiceContract.ValidRuleContractDel(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+
+	// 项目ID
+	projectIdInt, err := utils.GetProjectId(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+	// 标段ID
+	bidsectionId, err := utils.GetDecryptId(contractData.BidsectionId)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+	// 项目节ID
+	treeId, err := utils.GetDecryptId(contractData.TreeId)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+	// 合同ID
+	id, err := utils.GetDecryptId(contractData.Id)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+
+	err = c.ServiceContract.DeleteExpenditure(projectIdInt, bidsectionId, treeId, id)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
+
+	//2.请求当前项目信息
+	// 1.验证项目节ID
+	sectionDetail := c.ServiceContract.Get(treeId, bidsectionId, projectIdInt)
+
+	c.Ctx.JSON(iris.Map{"code": 0, "msg": "删除成功", "section": sectionDetail})
+}

+ 4 - 4
web/api/contract_return_api.go

@@ -34,7 +34,7 @@ func (c *ContractApi) GetReturnWay() {
 }
 
 // @Summary 获得回款列表
-// @Tags 合同管理
+// @Tags 合同管理-收入合同
 // @Description 获得回款列表
 // @Accept  json
 // @Produce  json
@@ -75,7 +75,7 @@ func (c *ContractApi) GetReturnList() {
 }
 
 // @Summary 新增回款内容
-// @Tags 合同管理
+// @Tags 合同管理-收入合同
 // @Description 新增回款内容
 // @Accept  json
 // @Produce  json
@@ -134,7 +134,7 @@ func (c *ContractApi) PostReturnCreate() {
 }
 
 // @Summary 更新回款内容
-// @Tags 合同管理
+// @Tags 合同管理-收入合同
 // @Description 更新回款内容
 // @Accept  json
 // @Produce  json
@@ -194,7 +194,7 @@ func (c *ContractApi) PostReturnUpdate() {
 }
 
 // @Summary 删除回款
-// @Tags 合同管理
+// @Tags 合同管理-收入合同
 // @Description 删除回款
 // @Accept  json
 // @Produce  json

+ 58 - 15
web/api/contract_section_tree_api.go

@@ -14,13 +14,14 @@ import (
 )
 
 // @Summary 升级降级合同项目节
-// @Tags 合同管理
+// @Tags 合同管理-项目节
 // @Description operation{upDepth,downDepth}
 // @Accept  json
 // @Produce  json
 // @Security ApiKeyAuth
 // @Param   id     body    string     true        "项目节ID"
 // @Param   bidsectionId     body    string     true        "标段ID"
+// @Param   treeType     body    string     true        "项目节类型(0合同1支出) 不传为0" default(0)
 // @Param   operation     body    string     true        "操作名称"  default(upDepth)
 // @Success 200 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
 // @Router /api/contract/section/depth [post]
@@ -45,7 +46,12 @@ func (c *ContractApi) PostSectionDepth() {
 		return
 	}
 
-	err = c.ServiceContract.MoveDepth(sectionData, bidsectionId, projectIdInt)
+	if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})
+		return
+	}
+
+	err = c.ServiceContract.MoveDepth(sectionData, bidsectionId, projectIdInt, sectionData.TreeType)
 	if err != nil {
 		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
 		return
@@ -63,13 +69,14 @@ func (c *ContractApi) PostSectionDepth() {
 }
 
 // @Summary 上移下移合同项目节
-// @Tags 合同管理
+// @Tags 合同管理-项目节
 // @Description operation{upSerial,downSerial}
 // @Accept  json
 // @Produce  json
 // @Security ApiKeyAuth
 // @Param   id     body    string     true        "项目节ID"
 // @Param   bidsectionId     body    string     true        "标段ID"
+// @Param   treeType     body    string     true        "项目节类型(0合同1支出) 不传为0" default(0)
 // @Param   operation     body    string     true        "操作名称"  default(upSerial)
 // @Success 200 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
 // @Router /api/contract/section/serial [post]
@@ -92,7 +99,13 @@ func (c *ContractApi) PostSectionSerial() {
 		c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
 		return
 	}
-	err = c.ServiceContract.MoveSerial(sectionData, bidsectionId, projectIdInt)
+
+	if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})
+		return
+	}
+
+	err = c.ServiceContract.MoveSerial(sectionData, bidsectionId, projectIdInt, sectionData.TreeType)
 	if err != nil {
 		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
 		return
@@ -111,13 +124,14 @@ func (c *ContractApi) PostSectionSerial() {
 }
 
 // @Summary 更新合同节序号
-// @Tags 合同管理
+// @Tags 合同管理-项目节
 // @Description
 // @Accept  json
 // @Produce  json
 // @Security ApiKeyAuth
 // @Param   id     body    string     true        "项目节ID"
 // @Param   bidsectionId     body    string     true        "标段ID"
+// @Param   treeType     body    string     true        "项目节类型(0合同1支出) 不传为0" default(0)
 // @Param   serial     body    int     true        "操作名称"
 // @Success 200 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
 // @Router /api/contract/section/serial/update [post]
@@ -140,7 +154,13 @@ func (c *ContractApi) PostSectionSerialUpdate() {
 		c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
 		return
 	}
-	err = c.ServiceContract.UpdateSerial(sectionData, bidsectionId, projectIdInt)
+
+	if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})
+		return
+	}
+
+	err = c.ServiceContract.UpdateSerial(sectionData, bidsectionId, projectIdInt, sectionData.TreeType)
 	if err != nil {
 		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
 		return
@@ -159,13 +179,14 @@ func (c *ContractApi) PostSectionSerialUpdate() {
 }
 
 // @Summary 设置合同项目节模板
-// @Tags 合同管理
+// @Tags 合同管理-项目节
 // @Description 设置合同项目节模板
 // @Accept  json
 // @Produce  json
 // @Security ApiKeyAuth
 // @Param   templateNumber     body    int     true        "模板号" default(1)
 // @Param   bidsectionId     body    string     true        "标段ID"
+// @Param   treeType     body    string     true        "项目节类型(0合同1支出) 不传为0" default(0)
 // @Success 200 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
 // @Router /api/contract/section/template [post]
 func (c *ContractApi) PostSectionTemplate() {
@@ -190,12 +211,17 @@ func (c *ContractApi) PostSectionTemplate() {
 		return
 	}
 
+	if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})
+		return
+	}
+
 	//获得合同项目节
-	sectionTree := c.ServiceContract.GetSecionTree(bidsectionId, projectIdInt)
+	sectionTree := c.ServiceContract.GetSecionTree(bidsectionId, projectIdInt, sectionData.TreeType)
 
 	// 1.未设置了项目节
 	if len(sectionTree.Children) == 0 {
-		err = c.ServiceContract.SetSection(sectionData.TemplateNumber, bidsectionId, projectIdInt)
+		err = c.ServiceContract.SetSection(sectionData.TemplateNumber, bidsectionId, projectIdInt, sectionData.TreeType)
 		if err != nil {
 			c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
 			return
@@ -209,13 +235,14 @@ func (c *ContractApi) PostSectionTemplate() {
 }
 
 // @Summary 新增 合同项目节
-// @Tags 合同管理
+// @Tags 合同管理-项目节
 // @Description 新增 合同项目节
 // @Accept  json
 // @Produce  json
 // @Security ApiKeyAuth
 // @Param   id     body    string     true        "项目节ID"
 // @Param   bidsectionId     body    string     true        "标段ID"
+// @Param   treeType     body    string     true        "项目节类型(0合同1支出) 不传为0" default(0)
 // @Param   name     body    string     true        "项目节名称"
 // @Success 200 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
 // @Router /api/contract/section/add [post]
@@ -240,7 +267,12 @@ func (c *ContractApi) PostSectionAdd() {
 		return
 	}
 
-	err = c.ServiceContract.SectionAdd(sectionData, bidsectionId, projectIdInt)
+	if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})
+		return
+	}
+
+	err = c.ServiceContract.SectionAdd(sectionData, bidsectionId, projectIdInt, sectionData.TreeType)
 	if err != nil {
 		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
 		return
@@ -249,13 +281,14 @@ func (c *ContractApi) PostSectionAdd() {
 }
 
 // @Summary 修改合同项目节 名称
-// @Tags 合同管理
+// @Tags 合同管理-项目节
 // @Description 修改合同项目节 名称
 // @Accept  json
 // @Produce  json
 // @Security ApiKeyAuth
 // @Param   id     body    string     true        "项目节ID"
 // @Param   bidsectionId     body    string     true        "标段ID"
+// @Param   treeType     body    string     true        "项目节类型(0合同1支出) 不传为0" default(0)
 // @Param   name     body    string     true        "项目节名称"
 // @Success 200 {string} string	"{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
 // @Router /api/contract/section/save [post]
@@ -280,7 +313,12 @@ func (c *ContractApi) PostSectionSave() {
 		return
 	}
 
-	err = c.ServiceContract.SectionSave(sectionData, bidsectionId, projectIdInt)
+	if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})
+		return
+	}
+
+	err = c.ServiceContract.SectionSave(sectionData, bidsectionId, projectIdInt, sectionData.TreeType)
 	if err != nil {
 		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
 		return
@@ -295,7 +333,7 @@ func (c *ContractApi) PostSectionSave() {
 }
 
 // @Summary 删除 合同项目节
-// @Tags 合同管理
+// @Tags 合同管理-项目节
 // @Description 删除 合同项目节
 // @Accept  json
 // @Produce  json
@@ -331,7 +369,12 @@ func (c *ContractApi) DeleteSection() {
 		return
 	}
 
-	err = c.ServiceContract.SectionDelete(treeId, bidsectionId, projectIdInt)
+	if !(sectionData.TreeType == 0 || sectionData.TreeType == 1) {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "合同项目节类型只能是0或者1"})
+		return
+	}
+
+	err = c.ServiceContract.SectionDelete(treeId, bidsectionId, projectIdInt, sectionData.TreeType)
 	if err != nil {
 		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
 		return

+ 1 - 1
web/viewmodels/contract.go

@@ -42,7 +42,7 @@ func (l Contracts) ValidateAdd() error {
 		validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),
 		validation.Field(&l.Code, validation.Required.Error("合同编号不能为空")),
 		validation.Field(&l.Name, validation.Required.Error("名称不能为空")),
-		validation.Field(&l.ContractsType, validation.Required.Error("合同类型不能为空"), validation.In(1, 2).Error("未找到相关合同类型")),
+		//validation.Field(&l.ContractsType, validation.Required.Error("合同类型不能为空"), validation.In(1, 2).Error("未找到相关合同类型")),
 		validation.Field(&l.Price, validation.Required.Error("合同金额不能为空")),
 	)
 }

+ 1 - 0
web/viewmodels/tree_section_contract.go

@@ -15,6 +15,7 @@ import (
 
 type TreeSectionContract struct {
 	Id           string `form:"id" json:"id" `
+	TreeType     int    `form:"treeType" json:"treeType"`
 	ParentId     string `form:"parentId" json:"parentId"`
 	Name         string `form:"name" json:"name"`
 	Depth        int    `form:"depth" json:"depth"`