Prechádzať zdrojové kódy

到款统计列表,套餐显示列调整

xiexiaoyuan 2 rokov pred
rodič
commit
96cb1e6a9d

+ 12 - 6
controller/census/invoice_payment.go

@@ -10,6 +10,7 @@ import (
 	"hongze/fms_api/global"
 	"hongze/fms_api/models/base"
 	"hongze/fms_api/models/fms"
+	fmsService "hongze/fms_api/services/fms"
 	"hongze/fms_api/utils"
 	"net/http"
 	"strconv"
@@ -562,7 +563,7 @@ func (ct *InvoicePaymentController) List(c *gin.Context) {
 			}
 
 			// 合同套餐
-			contractServiceCond := `contract_register_id IN ?`
+			/*contractServiceCond := `contract_register_id IN ?`
 			contractServicePars := make([]interface{}, 0)
 			contractServicePars = append(contractServicePars, queryRegisterIds)
 			contractServiceOB := new(fms.ContractService)
@@ -580,7 +581,12 @@ func (ct *InvoicePaymentController) List(c *gin.Context) {
 				contractServiceMap[contractServiceList[i].ContractRegisterId] = append(contractServiceMap[contractServiceList[i].ContractRegisterId], contractServiceList[i])
 				servicesNameMap[contractServiceList[i].ContractRegisterId] = append(servicesNameMap[contractServiceList[i].ContractRegisterId], contractServiceList[i].Title)
 			}
-
+*/
+			servicesNameMap, serviceFormatMap, e := fmsService.GetContractServiceNameFormat(registerIds)
+			if e != nil {
+				listErr = fmt.Errorf("获取合同套餐列表失败, Err: %s", e.Error())
+				return
+			}
 			// 到款套餐分配
 			serviceAmountMap := make(map[int][]*fms.ContractPaymentServiceAmount, 0)
 			if len(paymentIds) > 0 {
@@ -631,12 +637,13 @@ func (ct *InvoicePaymentController) List(c *gin.Context) {
 					}
 				}
 				// 合同对应的所有套餐
-				svList := contractServiceMap[summaryList[i].RegisterId]
+				svList := serviceFormatMap[summaryList[i].RegisterId]
 				if svList != nil {
 					for ii := range svList {
 						vv := new(fms.ContractPaymentServiceAmountItem)
 						vv.ServiceTemplateId = svList[ii].ServiceTemplateId
-						vv.ServiceTemplateName = svList[ii].Title
+						vv.ServiceTemplateName = svList[ii].FormatTitle
+						vv.ServiceTemplatePid = svList[ii].ServiceTemplatePid
 						k2 := fmt.Sprintf("%d-%d", summaryList[i].PaymentId, svList[ii].ServiceTemplateId)
 						a := amountMap[k2]
 						if a != nil {
@@ -660,8 +667,7 @@ func (ct *InvoicePaymentController) List(c *gin.Context) {
 				v.NewCompany = registerList[i].NewCompany
 				v.StartDate = utils.TimeTransferString(utils.FormatDate, registerList[i].StartDate)
 				v.EndDate = utils.TimeTransferString(utils.FormatDate, registerList[i].EndDate)
-				svList := servicesNameMap[registerList[i].ContractRegisterId]
-				v.ServicesName = strings.Join(svList, ",")
+				v.ServicesName = servicesNameMap[registerList[i].ContractRegisterId]
 				v.InvoicePaymentList = summaryMap[registerList[i].ContractRegisterId]
 				respList = append(respList, v)
 			}

+ 6 - 0
controller/contract/payment.go

@@ -73,6 +73,11 @@ func (ct *PaymentController) DistributePaymentServiceAmount(c *gin.Context) {
 	}
 
 	addList := make([]*fms.ContractPaymentServiceAmount, 0)
+	// todo 判断是否符合均分金额的条件
+	/*templateIds := make([]int)
+	for i := range req.List {
+
+	}*/
 	for i := range req.List {
 		if req.List[i].Amount <= 0 {
 			continue
@@ -84,6 +89,7 @@ func (ct *PaymentController) DistributePaymentServiceAmount(c *gin.Context) {
 		v := &fms.ContractPaymentServiceAmount{
 			ContractRegisterId: req.ContractRegisterId,
 			ContractPaymentId:  req.ContractPaymentId,
+			ServiceTemplatePid: req.List[i].ServiceTemplatePid,
 			ServiceTemplateId:  req.List[i].ServiceTemplateId,
 			Amount:             req.List[i].Amount,
 		}

+ 4 - 1
controller/contract/register.go

@@ -110,7 +110,7 @@ func (rg *RegisterController) List(c *gin.Context) {
 	paymentMap := make(map[int][]*fms.ContractInvoiceItem, 0)
 	if len(registerIds) > 0 {
 		// 获取所有的服务套餐
-		serviceMap, e = fmsService.GetContractServiceNameFormat(registerIds)
+		serviceMap, _, e = fmsService.GetContractServiceNameFormat(registerIds)
 		if e != nil {
 			resp.FailMsg("获取失败", e.Error(), c)
 			return
@@ -905,6 +905,9 @@ func (rg *RegisterController) Invoice(c *gin.Context) {
 			})
 		}
 	}
+
+	// todo 判断是否符合均分金额的条件,如果符合,需要生成金额分配记录表
+
 	// 新增的记录
 	if len(newInvoice) > 0 {
 		newAmount := decimal.NewFromFloat(0).Round(2)

+ 3 - 0
models/fms/contract_payment_service_amount.go

@@ -11,6 +11,7 @@ type ContractPaymentServiceAmount struct {
 	ContractRegisterId             int     `gorm:"column:contract_register_id" json:"contract_register_id" description:"合同登记ID"`
 	ContractPaymentId              int     `gorm:"column:contract_payment_id" json:"contract_payment_id" description:"到款登记ID"`
 	ServiceTemplateId              int     `gorm:"column:service_template_id" json:"service_template_id" description:"套餐ID"`
+	ServiceTemplatePid             int     `gorm:"column:service_template_pid" json:"service_template_pid" description:"套餐父级ID"`
 	Amount                         float64 `gorm:"column:amount" json:"amount" description:"分配金额"`
 	IsDeleted                      int     `gorm:"column:is_deleted" json:"is_deleted" description:"是否已删除: 0-正常; 1-已删除"`
 	base.TimeBase
@@ -49,6 +50,7 @@ type ContractPaymentServiceAmountItem struct {
 	ContractPaymentServiceAmountId int     `json:"contract_payment_service_amount_id"`
 	ContractPaymentId              int     `json:"contract_payment_id" description:"到款登记ID"`
 	ServiceTemplateId              int     `json:"service_template_id" description:"套餐ID"`
+	ServiceTemplatePid             int     `json:"service_template_pid" description:"套餐父级ID"`
 	ServiceTemplateName            string  `json:"service_template_name"`
 	Amount                         float64 `json:"amount" description:"分配金额"`
 }
@@ -64,6 +66,7 @@ type DistributePaymentServiceAmountReq struct {
 type DistributePaymentServiceAmountItem struct {
 	ContractPaymentServiceAmountId int     `json:"contract_payment_service_amount_id"`
 	ServiceTemplateId              int     `json:"service_template_id" description:"套餐ID"`
+	ServiceTemplatePid             int     `json:"service_template_pid" description:"套餐父级ID"`
 	Amount                         float64 `json:"amount" description:"分配金额"`
 }
 

+ 21 - 0
models/fms/contract_service_template.go

@@ -114,6 +114,27 @@ type ContractServiceTemplateFullName struct {
 	ParentTitle string
 }
 
+
+type ContractServiceTemplateFormat struct {
+	FormatTitle        string
+	ServiceTemplateId  int
+	ServiceTemplatePid int
+}
+
+type ContractServiceTemplateFormatList []ContractServiceTemplateFormat
+
+func (c ContractServiceTemplateFormatList) Len() int {
+	return len(c)
+}
+
+func (c ContractServiceTemplateFormatList) Less(i, j int) bool {
+	return c[i].ServiceTemplateId < c[j].ServiceTemplateId
+}
+
+func (c ContractServiceTemplateFormatList) Swap(i, j int) {
+	c[i], c[j] = c[j], c[i]
+}
+
 func GetContractServiceTemplateFullName() (items []*ContractServiceTemplateFullName, err error) {
 	err = global.DEFAULT_MYSQL.Table("contract_service_template as t1").
 		Select("t1.*, t2.title as parent_title").

+ 42 - 11
services/fms/contract_register.go

@@ -13,6 +13,7 @@ import (
 	"hongze/fms_api/utils"
 	"os"
 	"regexp"
+	"sort"
 	"strings"
 	"time"
 )
@@ -303,12 +304,14 @@ func FixContractSummaryData() {
 	return
 }
 
-func GetContractServiceNameFormat(registerIds []int) (serviceNameMap map[int]string, err error) {
+
+func GetContractServiceNameFormat(registerIds []int) (serviceNameMap map[int]string, serviceFormatMap map[int][]fms.ContractServiceTemplateFormat, err error) {
 	serviceNameMap = make(map[int]string)
 	serviceMap := make(map[int][]string, 0)
+	serviceFormatMap = make(map[int][]fms.ContractServiceTemplateFormat, 0)
 	serviceIndustryStr := "医药,消费,科技,智造"
 	serviceIdMap := make(map[int]*fms.ContractServiceTemplateFullName, 0)
-	serviceIndustryMap := make(map[int]map[string][]string, 0)
+	serviceIndustryMap := make(map[int]map[string][]*fms.ContractServiceTemplateFullName, 0)
 	allServiceList, e := fms.GetContractServiceTemplateFullName()
 	if e != nil {
 		err = fmt.Errorf("获取所有套餐失败, Err: "+e.Error())
@@ -335,35 +338,63 @@ func GetContractServiceNameFormat(registerIds []int) (serviceNameMap map[int]str
 			if fullItem.ParentTitle != "" {
 				if strings.Contains(serviceIndustryStr, fullItem.ParentTitle) {
 					if _, ok1 := serviceIndustryMap[item.ContractRegisterId]; !ok1 {
-						serviceIndustryMap[item.ContractRegisterId] = make(map[string][]string)
+						serviceIndustryMap[item.ContractRegisterId] = make(map[string][]*fms.ContractServiceTemplateFullName)
 					}
-					serviceIndustryMap[item.ContractRegisterId][fullItem.ParentTitle] = append(serviceIndustryMap[item.ContractRegisterId][fullItem.ParentTitle], item.Title)
+					serviceIndustryMap[item.ContractRegisterId][fullItem.ParentTitle] = append(serviceIndustryMap[item.ContractRegisterId][fullItem.ParentTitle], fullItem)
 				} else {
+					formatTitle := ""
 					if fullItem.ParentTitle == "策略" {
-						serviceMap[item.ContractRegisterId] = append(serviceMap[item.ContractRegisterId], fullItem.Title)
+						formatTitle = fullItem.Title
 					}else{
-						serviceMap[item.ContractRegisterId] = append(serviceMap[item.ContractRegisterId], fullItem.ParentTitle+"("+fullItem.Title+")")
+						formatTitle = fullItem.ParentTitle+"("+fullItem.Title+")"
 					}
-
+					serviceMap[item.ContractRegisterId] = append(serviceMap[item.ContractRegisterId], formatTitle)
+					tmp := fms.ContractServiceTemplateFormat{
+						FormatTitle:        formatTitle,
+						ServiceTemplateId:  fullItem.ServiceTemplateId,
+						ServiceTemplatePid: fullItem.Pid,
+					}
+					serviceFormatMap[item.ContractRegisterId] = append(serviceFormatMap[item.ContractRegisterId], tmp)
 				}
 			}else{
 				serviceMap[item.ContractRegisterId] = append(serviceMap[item.ContractRegisterId], fullItem.Title)
+				tmp := fms.ContractServiceTemplateFormat{
+					FormatTitle:        fullItem.Title,
+					ServiceTemplateId:  fullItem.ServiceTemplateId,
+					ServiceTemplatePid: fullItem.Pid,
+				}
+				serviceFormatMap[item.ContractRegisterId] = append(serviceFormatMap[item.ContractRegisterId], tmp)
 			}
 		}
 	}
 	for k, v := range serviceIndustryMap {
 		for sk, sv := range v {
+			formatTitle := ""
+			templateId := 0
+			pid := 0
 			if len(sv) >= 2 {
-				serviceMap[k] = append(serviceMap[k], sk)
+				formatTitle = sk
+				templateId = sv[0].Pid
 			}else{
-				serviceMap[k] = append(serviceMap[k], sk+"("+sv[0]+")")
+				formatTitle = sk+"("+sv[0].Title+")"
+				templateId = sv[0].ServiceTemplateId
+				pid = sv[0].Pid
+			}
+			serviceMap[k] = append(serviceMap[k], formatTitle)
+			tmp := fms.ContractServiceTemplateFormat{
+				FormatTitle:       formatTitle,
+				ServiceTemplateId: templateId,
+				ServiceTemplatePid: pid,
 			}
+			serviceFormatMap[k] = append(serviceFormatMap[k], tmp)
 		}
 	}
 
-	for k, v := range serviceMap {
+	// 给套餐内容排序
+	for k, v := range serviceFormatMap {
+		sort.Sort(fms.ContractServiceTemplateFormatList(v))
 		for _, sv := range v {
-			serviceNameMap[k] += sv+","
+			serviceNameMap[k] += sv.FormatTitle+","
 		}
 		serviceNameMap[k] = strings.Trim(serviceNameMap[k], ",")
 	}