浏览代码

Merge branch 'fms_2.7' into debug

ziwen 1 年之前
父节点
当前提交
4b8dfb5ac3
共有 3 个文件被更改,包括 110 次插入18 次删除
  1. 93 16
      controller/contract/register.go
  2. 9 2
      models/fms/contract_invoice.go
  3. 8 0
      models/fms/contract_register.go

+ 93 - 16
controller/contract/register.go

@@ -21,6 +21,7 @@ import (
 	"net/http"
 	"os"
 	"path"
+	"sort"
 	"strconv"
 	"strings"
 	"time"
@@ -427,8 +428,25 @@ func (rg *RegisterController) Add(c *gin.Context) {
 			err = fmt.Errorf("获取开票到款列表失败, Err: %s", e.Error())
 			return
 		}
+		templateIds := make([]int, 0)
+		for _, detail := range serviceList {
+			templateIds = append(templateIds, detail.ServiceTemplateId)
+		}
+		sort.Ints(templateIds)
+		ids := make([]string, 0)
+		for _, id := range templateIds {
+			ids = append(ids, strconv.Itoa(id))
+		}
+		templateIdStr := strings.Join(ids, ",")
+		nDupList := make([]*fms.DupInvoice, 0)
+		for _, dup := range dupList {
+			if templateIdStr == dup.TemplateIds {
+				nDupList = append(nDupList, dup)
+			}
+		}
+
 		//先遍历一遍拿到开票销售信息
-		for _, ppItem := range dupList {
+		for _, ppItem := range nDupList {
 			if ppItem.ContractRegisterId != req.ContractRegisterId {
 				j := 0
 				if ppItem.InvoiceType == 3 {
@@ -533,7 +551,7 @@ func (rg *RegisterController) Add(c *gin.Context) {
 			}
 		}
 
-		for _, ppItem := range dupList {
+		for _, ppItem := range nDupList {
 			if ppItem.ContractRegisterId != req.ContractRegisterId {
 				j := 0
 				v := &fms.ContractInvoice{
@@ -680,8 +698,24 @@ func (rg *RegisterController) Add(c *gin.Context) {
 			err = fmt.Errorf("获取开票到款列表失败, Err: %s", e.Error())
 			return
 		}
+		templateIds := make([]int, 0)
+		for _, detail := range serviceList {
+			templateIds = append(templateIds, detail.ServiceTemplateId)
+		}
+		sort.Ints(templateIds)
+		ids := make([]string, 0)
+		for _, id := range templateIds {
+			ids = append(ids, strconv.Itoa(id))
+		}
+		templateIdStr := strings.Join(ids, ",")
+		nDupList := make([]*fms.DupInvoice, 0)
+		for _, dup := range dupList {
+			if templateIdStr == dup.TemplateIds {
+				nDupList = append(nDupList, dup)
+			}
+		}
 		//先遍历一遍拿到开票销售信息
-		for _, ppItem := range dupList {
+		for _, ppItem := range nDupList {
 			j := 0
 			if ppItem.ContractRegisterId != req.ContractRegisterId {
 				if ppItem.InvoiceType == 3 {
@@ -697,7 +731,7 @@ func (rg *RegisterController) Add(c *gin.Context) {
 				j++
 			}
 		}
-		for _, ppItem := range dupList {
+		for _, ppItem := range nDupList {
 			j := 0
 			if ppItem.ContractRegisterId != req.ContractRegisterId {
 				v := &fms.ContractInvoice{
@@ -3485,6 +3519,22 @@ func (rg *RegisterController) Import(c *gin.Context) {
 					err = fmt.Errorf("获取开票到款列表失败, Err: %s", e.Error())
 					return
 				}
+				templateIds := make([]int, 0)
+				for _, detail := range rowServices {
+					templateIds = append(templateIds, detail.ServiceTemplateId)
+				}
+				sort.Ints(templateIds)
+				ids := make([]string, 0)
+				for _, id := range templateIds {
+					ids = append(ids, strconv.Itoa(id))
+				}
+				templateIdStr := strings.Join(ids, ",")
+				nDupList := make([]*fms.DupInvoice, 0)
+				for _, dup := range dupList {
+					if templateIdStr == dup.TemplateIds {
+						nDupList = append(nDupList, dup)
+					}
+				}
 				//先遍历一遍拿到开票销售信息
 				for _, ppItem := range dupList {
 					j := 0
@@ -3774,19 +3824,14 @@ func (rg *RegisterController) CheckContractDuplicate(c *gin.Context) {
 
 		existPars = append(existPars, startDate, endDate)
 	}
-	if len(req.Services) > 0 {
-		//serviceList, e := fmsService.HandleContractServiceAndDetail(req.Services, true, serviceAmountMap)
-		//if e != nil {
-		//	resp.FailMsg("操作失败", "获取合同套餐详情失败, Err: "+e.Error(), c)
-		//	return
-		//}
-
-	}
 
 	if existCond == "" {
 		resp.Fail("请输入合同名称或者合同有效期", c)
 		return
 	}
+	data := fms.CheckContractDuplicateResp{
+		Exist: 0,
+	}
 
 	// 是否存在相同合同名称的登记
 	list, e := fms.CheckContractDuplicate(existCond, existPars)
@@ -3794,12 +3839,44 @@ func (rg *RegisterController) CheckContractDuplicate(c *gin.Context) {
 		resp.FailMsg("操作失败", "查询重复合同失败, Err: "+e.Error(), c)
 		return
 	}
-	data := fms.CheckContractDuplicateResp{
-		Exist: 0,
+
+	registerIds := make([]int, 0)
+	for i := range list {
+		registerIds = append(registerIds, list[i].ContractRegisterId)
 	}
-	if len(list) > 0 {
-		data.Exist = 1
+
+	idlist, e := fms.CheckContractServiceDuplicate(registerIds)
+	if e != nil {
+		resp.FailMsg("操作失败", "查询重复合同套餐失败, Err: "+e.Error(), c)
+		return
+	}
+
+	//校验套餐
+	if len(req.Services) > 0 {
+		serviceAmountMap := make(map[int]float64)
+		serviceList, e := fmsService.HandleContractServiceAndDetail(req.Services, true, serviceAmountMap)
+		if e != nil {
+			resp.FailMsg("操作失败", "获取合同套餐详情失败, Err: "+e.Error(), c)
+			return
+		}
+		templateIds := make([]int, 0)
+		for _, detail := range serviceList {
+			templateIds = append(templateIds, detail.ServiceTemplateId)
+		}
+		sort.Ints(templateIds)
+		ids := make([]string, 0)
+		for _, id := range templateIds {
+			ids = append(ids, strconv.Itoa(id))
+		}
+		templateIdStr := strings.Join(ids, ",")
+
+		for _, s := range idlist {
+			if templateIdStr == *s {
+				data.Exist = 1
+			}
+		}
 	}
+
 	resp.OkData("查询成功", data, c)
 	return
 }

+ 9 - 2
models/fms/contract_invoice.go

@@ -625,12 +625,19 @@ func GetContractInvoiceByRegisterIdAndType(registerId int) (items *ContractInvoi
 	return
 }
 
+type DupInvoice struct {
+	ContractInvoice
+	TemplateIds string
+}
+
 // GetDuplicateContractInvoiceDetailItemList 预登记列表详情用-获取开票到款列表
-func GetDuplicateContractInvoiceDetailItemList(companyName, startDate, endDate string) (list []*ContractInvoice, err error) {
+func GetDuplicateContractInvoiceDetailItemList(companyName, startDate, endDate string) (list []*DupInvoice, err error) {
 	err = global.DEFAULT_MYSQL.Table("contract_invoice as a ").
-		Select(" a.* ").
+		Select(" a.*,GROUP_CONCAT(c.service_template_id ORDER BY c.service_template_id ) AS template_ids ").
 		Joins(" JOIN contract_register as b ON a.contract_register_id = b.contract_register_id ").
+		Joins("JOIN contract_service AS c ON a.contract_register_id = c.contract_register_id").
 		Where(fmt.Sprintf("a.is_deleted = 0 AND b.company_name = '%s' AND b.start_date= '%s' AND b.end_date= '%s' AND b.is_deleted=0 AND (a.invoice_type=3 OR a.invoice_type=4) ",companyName, startDate, endDate)).
+		Group("a.contract_register_id").
 		Order("a.contract_invoice_id ASC").
 		Find(&list).Error
 	if err != nil {

+ 8 - 0
models/fms/contract_register.go

@@ -930,4 +930,12 @@ func CheckContractDuplicate(condition string, pars []interface{}) (list []*Contr
 
 type CheckContractDuplicateResp struct {
 	Exist int `json:"exist" description:"是否存在重复的合同:0不存在,1存在"`
+}
+
+func CheckContractServiceDuplicate(registerIds []int) (ids []*string, err error) {
+	err = global.DEFAULT_MYSQL.Table("contract_service").
+		Select("GROUP_CONCAT(service_template_id ORDER BY service_template_id)  AS ids ").
+		Where("contract_register_id IN (?)", registerIds).
+		Group("contract_register_id").Scan(&ids).Error
+	return
 }