123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734 |
- /*
- * @description: 合同数据相关操作
- * @Author: CP
- * @Date: 2020-10-27 11:28:24
- * @FilePath: \construction_management\services\contract_service.go
- */
- package services
- import (
- "errors"
- "fmt"
- "html"
- "log"
- "strconv"
- "time"
- "github.com/kataras/iris/v12"
- "github.com/shopspring/decimal"
- "go.mod/comm"
- "go.mod/conf"
- "go.mod/dao"
- "go.mod/datasource"
- "go.mod/models"
- "go.mod/web/viewmodels"
- )
- // 定义项目用户Service接口
- type ContractService interface {
- ValidRuleDepth(ctx iris.Context) (*viewmodels.TreeSectionContract, error)
- ValidRuleTemplate(ctx iris.Context) (*viewmodels.TreeSectionContract, error)
- ValidRuleSectionAdd(ctx iris.Context) (*viewmodels.TreeSectionContract, error)
- ValidRuleSectionDelete(ctx iris.Context) (*viewmodels.TreeSectionContract, error)
- ValidRuleSectionNot(ctx iris.Context) (*viewmodels.TreeSectionContract, error)
- ValidRuleGet(ctx iris.Context) (*viewmodels.TreeSectionContract, error)
- ValidRuleSerial(ctx iris.Context) (*viewmodels.TreeSectionContract, error)
- ValidRuleContractAdd(ctx iris.Context) (*viewmodels.Contracts, error)
- ValidRuleContractEdi(ctx iris.Context) (*viewmodels.Contracts, error)
- ValidRuleContractDel(ctx iris.Context) (*viewmodels.Contracts, error)
- ValidRuleContractClose(ctx iris.Context) (*viewmodels.Contracts, error)
- ValidRuleContractRetrunAdd(ctx iris.Context) (*viewmodels.ContractsReturn, error)
- ValidRuleContractRetrun(ctx iris.Context) (*viewmodels.ContractsReturn, error)
- ValidRuleContractRetrunDel(ctx iris.Context) (*viewmodels.ContractsReturn, error)
- ValidRuleContractPaidAdd(ctx iris.Context) (*viewmodels.ContractsPaid, error)
- ValidRuleContractPaid(ctx iris.Context) (*viewmodels.ContractsPaid, error)
- ValidRuleContractPaidDel(ctx iris.Context) (*viewmodels.ContractsPaid, error)
- // 项目节
- Get(treeId int, bidsectionId int, projectId int, treeType int) *viewmodels.TreeSectionContract
- 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) (*models.CmTreeContracts, error)
- ContractSectionAdd(sectionData *viewmodels.TreeSectionContract, bidsectionId int, projectId int, treeType int) (*models.CmTreeContracts, 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
- GetSecionTreeNotContract(bidsectionId int, projectId int, treeType int) *viewmodels.TreeSectionContract
- GetContract(contractId int) *viewmodels.Contracts
- 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, treeType int, settlementCode string) 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
- 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
- // 已支付
- PaidAll(projectId int, bidsectionId int, contractsId int, page int) []*viewmodels.ContractsPaid
- PaidCreate(returnData *viewmodels.ContractsPaid, projectId int, bidsectionId int, contractsId int, projectAccountId int) error
- PaidUpdate(returnData *viewmodels.ContractsPaid, projectId int, bidsectionId int, contractsId int, id int) error
- PaidDelete(projectId int, bidsectionId int, contractsId int, id int) error
- }
- // 返回service操作类
- type contractService struct {
- treeContractDao *dao.TreeContractDao
- contractDao *dao.ContractDao
- contractReturnDao *dao.ContractReturnDao
- contractPaidDao *dao.ContractPaidDao
- treeDao *dao.TreeDao
- annexDao *dao.AnnexDao
- }
- // 创建项目用户service
- func NewContractService() ContractService {
- return &contractService{
- treeContractDao: dao.NewTreeContractDao(datasource.InstanceDbMaster()),
- contractDao: dao.NewContractDao(datasource.InstanceDbMaster()),
- contractReturnDao: dao.NewContractReturnDao(datasource.InstanceDbMaster()),
- contractPaidDao: dao.NewContractPaidDao(datasource.InstanceDbMaster()),
- treeDao: dao.NewTreeDao(datasource.InstanceDbMaster()),
- annexDao: dao.NewAnnexDao(datasource.InstanceDbMaster()),
- }
- }
- // 升级降级规则验证
- func (s *contractService) ValidRuleDepth(ctx iris.Context) (*viewmodels.TreeSectionContract, error) {
- treeSectionVaild := &viewmodels.TreeSectionContract{}
- err := ctx.ReadJSON(treeSectionVaild)
- if err != nil {
- log.Println("folder-ValidRule-ReadForm转换异常, error=", err)
- return treeSectionVaild, err
- }
- err = treeSectionVaild.ValidateDepth()
- if err != nil {
- log.Println("参数验证错误, error=", err)
- return treeSectionVaild, err
- }
- return treeSectionVaild, nil
- }
- // 模板规则验证
- func (s *contractService) ValidRuleTemplate(ctx iris.Context) (*viewmodels.TreeSectionContract, error) {
- treeSectionVaild := &viewmodels.TreeSectionContract{}
- err := ctx.ReadJSON(treeSectionVaild)
- if err != nil {
- log.Println("folder-ValidRule-ReadForm转换异常, error=", err)
- return treeSectionVaild, err
- }
- err = treeSectionVaild.ValidateTemplate()
- if err != nil {
- log.Println("参数验证错误, error=", err)
- return treeSectionVaild, err
- }
- return treeSectionVaild, nil
- }
- // 模板规则新增项目节
- func (s *contractService) ValidRuleSectionAdd(ctx iris.Context) (*viewmodels.TreeSectionContract, error) {
- treeSectionVaild := &viewmodels.TreeSectionContract{}
- err := ctx.ReadJSON(treeSectionVaild)
- if err != nil {
- log.Println("folder-ValidRule-ReadForm转换异常, error=", err)
- return treeSectionVaild, err
- }
- err = treeSectionVaild.ValidateSectionAdd()
- if err != nil {
- log.Println("参数验证错误, error=", err)
- return treeSectionVaild, err
- }
- return treeSectionVaild, nil
- }
- // 模板规则新增项目节
- func (s *contractService) ValidRuleSectionDelete(ctx iris.Context) (*viewmodels.TreeSectionContract, error) {
- treeSectionVaild := &viewmodels.TreeSectionContract{}
- err := ctx.ReadForm(treeSectionVaild)
- if err != nil {
- log.Println("folder-ValidRule-ReadForm转换异常, error=", err)
- return treeSectionVaild, err
- }
- err = treeSectionVaild.ValidateSectionDelete()
- if err != nil {
- log.Println("参数验证错误, error=", err)
- return treeSectionVaild, err
- }
- return treeSectionVaild, nil
- }
- func (s *contractService) ValidRuleSectionNot(ctx iris.Context) (*viewmodels.TreeSectionContract, error) {
- treeSectionVaild := &viewmodels.TreeSectionContract{}
- err := ctx.ReadForm(treeSectionVaild)
- if err != nil {
- log.Println("folder-ValidRule-ReadForm转换异常, error=", err)
- return treeSectionVaild, err
- }
- err = treeSectionVaild.ValidateSectionNot()
- if err != nil {
- log.Println("参数验证错误, error=", err)
- return treeSectionVaild, err
- }
- return treeSectionVaild, nil
- }
- func (s *contractService) ValidRuleGet(ctx iris.Context) (*viewmodels.TreeSectionContract, error) {
- treeSectionVaild := &viewmodels.TreeSectionContract{}
- err := ctx.ReadForm(treeSectionVaild)
- if err != nil {
- log.Println("folder-ValidRule-ReadForm转换异常, error=", err)
- return treeSectionVaild, err
- }
- err = treeSectionVaild.ValidateSectionDelete()
- if err != nil {
- log.Println("参数验证错误, error=", err)
- return treeSectionVaild, err
- }
- return treeSectionVaild, nil
- }
- // 验证序号相关
- func (s *contractService) ValidRuleSerial(ctx iris.Context) (*viewmodels.TreeSectionContract, error) {
- treeSectionVaild := &viewmodels.TreeSectionContract{}
- err := ctx.ReadJSON(treeSectionVaild)
- if err != nil {
- log.Println("folder-ValidRule-ReadForm转换异常, error=", err)
- return treeSectionVaild, err
- }
- err = treeSectionVaild.ValidateSectionSerial()
- if err != nil {
- log.Println("参数验证错误, error=", err)
- return treeSectionVaild, err
- }
- return treeSectionVaild, nil
- }
- // 新增合同参数验证
- func (s *contractService) ValidRuleContractAdd(ctx iris.Context) (*viewmodels.Contracts, error) {
- // 创建一个存放前端传过来参数
- contractsVaild := &viewmodels.Contracts{}
- // 存放raw的值,放入到contractsVaild
- err := ctx.ReadJSON(contractsVaild)
- if err != nil {
- log.Println("folder-ValidRule-ReadForm转换异常, error=", err)
- return contractsVaild, err
- }
- // 验证合同传参
- err = contractsVaild.ValidateAdd()
- if err != nil {
- log.Println("参数验证错误, error=", err)
- return contractsVaild, err
- }
- // xss
- contractsVaild.Code = html.EscapeString(contractsVaild.Code)
- contractsVaild.Name = html.EscapeString(contractsVaild.Name)
- // contractsVaild.Price = html.EscapeString(contractsVaild.Price)
- return contractsVaild, nil
- }
- // 校验编辑接口
- func (s *contractService) ValidRuleContractEdi(ctx iris.Context) (*viewmodels.Contracts, error) {
- // 创建一个存放前端传过来参数
- contractsVaild := &viewmodels.Contracts{}
- // 存放raw的值,放入到contractsVaild
- err := ctx.ReadJSON(contractsVaild)
- if err != nil {
- log.Println("folder-ValidRule-ReadForm转换异常, error=", err)
- return contractsVaild, err
- }
- // 验证合同传参
- err = contractsVaild.ValidateEdi()
- if err != nil {
- log.Println("参数验证错误, error=", err)
- return contractsVaild, err
- }
- contractsVaild.Content = html.EscapeString(contractsVaild.Content)
- contractsVaild.Name = html.EscapeString(contractsVaild.Name)
- // contractsVaild.Price = html.EscapeString(contractsVaild.Price)
- contractsVaild.PartyA = html.EscapeString(contractsVaild.PartyA)
- contractsVaild.PartyASigner = html.EscapeString(contractsVaild.PartyASigner)
- contractsVaild.PartyB = html.EscapeString(contractsVaild.PartyB)
- contractsVaild.PartyBSigner = html.EscapeString(contractsVaild.PartyBSigner)
- return contractsVaild, nil
- }
- // 校验删除合同参数
- func (s *contractService) ValidRuleContractDel(ctx iris.Context) (*viewmodels.Contracts, error) {
- // 创建一个存放前端传过来参数
- contractsVaild := &viewmodels.Contracts{}
- // 存放raw的值,放入到contractsVaild
- err := ctx.ReadForm(contractsVaild)
- if err != nil {
- log.Println("folder-ValidRule-ReadForm转换异常, error=", err)
- return contractsVaild, err
- }
- // 验证合同传参
- err = contractsVaild.ValidateDel()
- if err != nil {
- log.Println("参数验证错误, error=", err)
- return contractsVaild, err
- }
- return contractsVaild, nil
- }
- // 校验关闭合同参数
- func (s *contractService) ValidRuleContractClose(ctx iris.Context) (*viewmodels.Contracts, error) {
- // 创建一个存放前端传过来参数
- contractsVaild := &viewmodels.Contracts{}
- // 存放raw的值,放入到contractsVaild
- err := ctx.ReadJSON(contractsVaild)
- if err != nil {
- log.Println("folder-ValidRule-ReadForm转换异常, error=", err)
- return contractsVaild, err
- }
- // 验证合同传参
- err = contractsVaild.ValidateDel()
- if err != nil {
- log.Println("参数验证错误, error=", err)
- return contractsVaild, err
- }
- return contractsVaild, nil
- }
- // ------------------------------------------------------------
- // 获得项目节
- func (s *contractService) Get(treeId int, bidsectionId int, projectId int, treeType int) *viewmodels.TreeSectionContract {
- // 1.获得项目节
- section := s.treeContractDao.Get(treeId, bidsectionId, projectId, treeType)
- // 2.构造数据
- sectionVM := s.makeSectionView(section)
- // 3.更新 上移和下一的限制
- youngerBrotherList := s.treeContractDao.GetYoungerBrother(section.Serial, section.Depth, section.ParentId, bidsectionId, projectId, treeType)
- if len(youngerBrotherList) == 0 {
- sectionVM.IsEnd = true
- }
- sectionVM.ElderBrother = true
- elderBrotherList := s.treeContractDao.GetElderBrother(section.Serial, section.Depth, section.ParentId, bidsectionId, projectId, treeType)
- if len(elderBrotherList) == 0 {
- sectionVM.ElderBrother = false
- }
- return sectionVM
- }
- // 获得合同详情
- func (s *contractService) GetContract(contractId int) *viewmodels.Contracts {
- contract := s.contractDao.Get(contractId)
- contractsVM := s.makeContractVM(contract)
- return &contractsVM
- }
- // 新增合同
- func (s *contractService) Add(contractData *viewmodels.Contracts, projectId int, bidsectionId int, treeId int) error {
- // 1. 项目节存在
- contracts := s.treeContractDao.Get(treeId, bidsectionId, projectId, 0)
- if contracts.Id == 0 {
- return errors.New("未找到项目节")
- }
- // 2.项目节是没有合同
- if contracts.ContractId != 0 {
- return errors.New("该项目节上已经存在合同")
- }
- // 2-1.查找合同编号是否存在
- codeData := s.contractDao.GetByCode(projectId, bidsectionId, contractData.Code, 1)
- if len(codeData) != 0 {
- return errors.New("该合同编号已经存在")
- }
- // 3.新增合同 --合计标段上的金额
- contractsCm := &models.CmContracts{}
- contractsCm.Code = contractData.Code
- contractsCm.Name = contractData.Name
- contractsCm.ContractsType = 1
- contractsCm.Price = fmt.Sprintf("%.2f", contractData.Price)
- // 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, 0)
- // 更新标段目录上合同金额和总数
- err = s.treeDao.UpdateContractsAndIncomePrice(projectId, bidsectionId, contractTotal, priceTotal)
- if err != nil {
- return err
- }
- return nil
- }
- // 更新合同
- func (s *contractService) Update(contractData *viewmodels.Contracts, projectId int, bidsectionId int, treeId int) error {
- // 1. 项目节存在
- contractsTree := s.treeContractDao.Get(treeId, bidsectionId, projectId, 0)
- if contractsTree.Id == 0 {
- return errors.New("未找到项目节")
- }
- // 2.项目节是没有合同
- if contractsTree.ContractId == 0 {
- return errors.New("该项目节上没有找到合同")
- }
- // 3.合同锁定 不能删除
- if contractsTree.ContractLocking == 1 {
- return errors.New("该合同已锁定")
- }
- // 4.合同金额不能小于回款金额
- returnedPrice, _ := decimal.NewFromString(contractsTree.ContractReturned)
- price := decimal.NewFromFloat(contractData.Price)
- // price, err := decimal.NewFromString(contractData.Price)
- // if err != nil {
- // return errors.New("金额填写有误")
- // }
- if returnedPrice.GreaterThan(price) {
- return errors.New(fmt.Sprintf("合同金额不能低于%s", contractsTree.ContractReturned))
- }
- contractsCm := &models.CmContracts{}
- contractsCm.Id = contractsTree.ContractId
- contractsCm.Content = contractData.Content
- contractsCm.Name = contractData.Name
- contractsCm.Price = fmt.Sprintf("%.2f", contractData.Price)
- // strconv.FormatFloat(contractData.Price, 'f', 1, 64)
- // 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, 0)
- // 更新标段目录上合同金额和总数
- err = s.treeDao.UpdateContractsAndIncomePrice(projectId, bidsectionId, contractTotal, priceTotal)
- if err != nil {
- return err
- }
- return nil
- }
- // 删除合同
- func (s *contractService) Delete(projectId int, bidsectionId int, treeId int, id int) error {
- // 1. 项目节存在
- contractsTree := s.treeContractDao.Get(treeId, bidsectionId, projectId, 0)
- 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.Delete(projectId, bidsectionId, treeId, id)
- if err != nil {
- return err
- }
- // 3.获得该标段下合同总数 - 总收入金额
- contractTotal, priceTotal := s.getContractTotalAndPrice(bidsectionId, projectId, 0)
- // 更新标段目录上合同金额和总数
- err = s.treeDao.UpdateContractsAndIncomePrice(projectId, bidsectionId, contractTotal, priceTotal)
- if err != nil {
- return err
- }
- // 4.更新回款总金额
- err = s.contractReturnDao.UpdateTotalPrice(projectId, bidsectionId, id)
- if err != nil {
- return err
- }
- return nil
- }
- // 关闭合同
- func (s *contractService) Close(projectId int, bidsectionId int, treeId int, id int, treeType int, settlementCode string) error {
- // 1. 项目节存在
- contractsTree := s.treeContractDao.Get(treeId, bidsectionId, projectId, treeType)
- 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.Close(projectId, bidsectionId, treeId, id, settlementCode)
- if err != nil {
- return err
- }
- return nil
- }
- // 解锁合同
- func (s *contractService) Unlock(projectId int, bidsectionId int, treeId int, id int, treeType int) error {
- // 1. 项目节存在
- contractsTree := s.treeContractDao.Get(treeId, bidsectionId, projectId, treeType)
- if contractsTree.Id == 0 {
- return errors.New("未找到项目节")
- }
- // 2.项目节是没有合同
- if contractsTree.ContractId == 0 {
- return errors.New("该项目节上没有找到合同")
- }
- // 解锁合同
- err := s.contractDao.Unlock(projectId, bidsectionId, treeId, id)
- if err != nil {
- return err
- }
- return nil
- }
- // 获得合同收入概况
- func (s *contractService) GetSurvey(bidsectionId int, projectId int, contractsType int) map[string]interface{} {
- // 1.获得收入合同
- year := time.Now().Year()
- incomeList := s.contractDao.GetTypeYear(bidsectionId, projectId, contractsType, year)
- // 2.初始化
- totalContractPrice := 0.00
- totalTypePrice := 0.00
- performNumber := 0
- closeNumber := 0
- uncloseNumber := 0
- // 3.当年数据初始化
- returnDate := map[string]float64{
- fmt.Sprintf("%d-01", year): 0.00,
- fmt.Sprintf("%d-02", year): 0.00,
- fmt.Sprintf("%d-03", year): 0.00,
- fmt.Sprintf("%d-04", year): 0.00,
- fmt.Sprintf("%d-05", year): 0.00,
- fmt.Sprintf("%d-06", year): 0.00,
- fmt.Sprintf("%d-07", year): 0.00,
- fmt.Sprintf("%d-08", year): 0.00,
- fmt.Sprintf("%d-09", year): 0.00,
- fmt.Sprintf("%d-10", year): 0.00,
- fmt.Sprintf("%d-11", year): 0.00,
- fmt.Sprintf("%d-12", year): 0.00,
- }
- contractIds := []int{}
- for _, item := range incomeList {
- contractPrice, _ := strconv.ParseFloat(item.Price, 64)
- totalContractPrice = totalContractPrice + contractPrice
- // 回款金额或已支付金额合计
- contractIds = append(contractIds, item.Id)
- // typePrice := 0.00
- // if contractsType == 1 {
- // typePrice, _ = strconv.ParseFloat(item.Returned, 64)
- // totalTypePrice = totalTypePrice + typePrice
- // } else {
- // typePrice, _ = strconv.ParseFloat(item.Paid, 64)
- // totalTypePrice = totalTypePrice + typePrice
- // }
- if item.Status == 0 {
- performNumber = performNumber + 1
- } else if item.Status == 1 {
- uncloseNumber = uncloseNumber + 1
- } else if item.Status == 2 {
- closeNumber = closeNumber + 1
- }
- // returnDate[item.CreateTime.Format(conf.SysTimeformMonth)] = returnDate[item.CreateTime.Format(conf.SysTimeformMonth)] + typePrice
- }
- fmt.Println(contractIds)
- // contractInId := strings.Join(contractIds, ",")
- if contractsType == 1 {
- list := s.contractReturnDao.GetInContractsIds(contractIds)
- for _, item := range list {
- typePrice := 0.00
- typePrice, _ = strconv.ParseFloat(item.Price, 64)
- totalTypePrice = totalTypePrice + typePrice
- fmt.Println(item)
- // :=decimal.NewFromFloat(typePrice)
- returnDate[item.Time.Format(conf.SysTimeformMonth)], _ = decimal.NewFromFloat(returnDate[item.Time.Format(conf.SysTimeformMonth)]).Add(decimal.NewFromFloat(typePrice)).Float64()
- }
- } else {
- list := s.contractPaidDao.GetInContractsIds(contractIds)
- for _, item := range list {
- typePrice := 0.00
- typePrice, _ = strconv.ParseFloat(item.Price, 64)
- totalTypePrice = totalTypePrice + typePrice
- returnDate[item.Time.Format(conf.SysTimeformMonth)], _ = decimal.NewFromFloat(returnDate[item.Time.Format(conf.SysTimeformMonth)]).Add(decimal.NewFromFloat(typePrice)).Float64()
- }
- }
- totalContractPrice, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", totalContractPrice), 64)
- totalTypePrice, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", totalTypePrice), 64)
- // ac := accounting.Accounting{Symbol: "", Precision: 2}
- surveryData := map[string]interface{}{
- "totalContractPrice": totalContractPrice,
- "totalContractPriceShow": totalContractPrice,
- // "totalReturnPrice": ac.FormatMoney(totalReturnPrice),
- "performNumber": performNumber,
- "closeNumber": closeNumber,
- "uncloseNumber": uncloseNumber,
- "returnDate": returnDate,
- }
- if contractsType == 1 {
- surveryData["totalReturnPriceShow"] = totalTypePrice
- } else {
- surveryData["totalPaidPriceShow"] = totalTypePrice
- }
- return surveryData
- }
- // 获得合同总数量和总金额
- 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)
- priceTotal = priceTotal + contractPrice
- }
- // 合同总数
- // contractTotal = len(contractList) + 1
- contractTotal = len(contractListAll)
- // 合同收入总金额
- // price, _ := strconv.ParseFloat(priceString, 64)
- // priceTotal = priceTotal + price
- // 保留2位小数
- priceTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", priceTotal), 64)
- return contractTotal, priceTotal
- }
- // 构建合同详情视图
- func (s *contractService) makeContractVM(contract *models.CmContracts) viewmodels.Contracts {
- contractsVM := viewmodels.Contracts{}
- if contract.Id == 0 {
- return contractsVM
- }
- id, _ := comm.AesEncrypt(strconv.Itoa(contract.Id), conf.SignSecret)
- treeId, _ := comm.AesEncrypt(strconv.Itoa(contract.TreeId), conf.SignSecret)
- bidsectionId, _ := comm.AesEncrypt(strconv.Itoa(contract.BidsectionId), conf.SignSecret)
- contractsVM.Id = id
- contractsVM.TreeId = treeId
- contractsVM.ContractsType = contract.ContractsType
- contractsVM.BidsectionId = bidsectionId
- contractsVM.Name = contract.Name
- contractsVM.Content = contract.Content
- contractsVM.Code = contract.Code
- contractsVM.PartyA = contract.PartyA
- contractsVM.PartyASigner = contract.PartyASigner
- contractsVM.PartyB = contract.PartyB
- contractsVM.PartyBSigner = contract.PartyBSigner
- contractsVM.Remarks = contract.Remarks
- // price, _ := strconv.ParseFloat(contract.Price, 64)
- // returned, _ := strconv.ParseFloat(contract.Returned, 64)
- // paid, _ := strconv.ParseFloat(contract.Paid, 64)
- price, _ := strconv.ParseFloat(contract.Price, 64)
- // contractsVM.PriceFloat = price
- contractsVM.Price = price
- contractsVM.Returned = contract.Returned
- contractsVM.Paid = contract.Paid
- contractsVM.Status = contract.Status
- contractsVM.Locking = contract.Locking
- contractsVM.ContractDeductionTotal = contract.ContractDeductionTotal
- contractsVM.CreateTime = contract.CreateTime.Format(conf.SysTimeform)
- contractsVM.UpdateTime = contract.UpdateTime.Format(conf.SysTimeform)
- // nilTime := time.Time{}
- // contract.SignerTime != nilTime
- if !contract.SignerTime.IsZero() {
- contractsVM.SignerTime = contract.SignerTime.Format(conf.SysTimeform)
- }
- return contractsVM
- }
|