|
@@ -6,8 +6,10 @@ import (
|
|
|
"hongze/hz_crm_api/controllers"
|
|
|
"hongze/hz_crm_api/models"
|
|
|
"hongze/hz_crm_api/models/company"
|
|
|
+ "hongze/hz_crm_api/models/fms"
|
|
|
"hongze/hz_crm_api/models/statistic_report"
|
|
|
"hongze/hz_crm_api/models/system"
|
|
|
+ cygxService "hongze/hz_crm_api/services/cygx"
|
|
|
"hongze/hz_crm_api/utils"
|
|
|
"strconv"
|
|
|
"strings"
|
|
@@ -125,17 +127,21 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
|
|
|
mapNoRenewedcompanyContractIds[v.CompanyContractId] = true
|
|
|
}
|
|
|
|
|
|
- mapAddTrialNum := make(map[string]float64) // 新增试用-(数据)
|
|
|
- mapNewContractMoney := make(map[string]float64) // 新签合同(金额)
|
|
|
- mapNewContractNum := make(map[string]int) // 新签合同(数量)
|
|
|
- mapExpiredContractMoney := make(map[string]float64) // 到期合同(金额)
|
|
|
- mapExpiredContractNum := make(map[string]int) // 到期合同(数量)
|
|
|
- mapRenewedContractMoney := make(map[string]float64) // 续约合同(金额)
|
|
|
- mapRenewedContractNum := make(map[string]int) // 续约合同(数量)
|
|
|
- confirmedNoRenewalContractMoney := make(map[string]float64) // 确认不续约合同(金额)
|
|
|
- confirmedNoRenewalContractNum := make(map[string]int) // 确认不续约合同(数量)
|
|
|
- mapSignedClientNum := make(map[string]int) // 签约客户(数量)
|
|
|
- mapSignedClientMoney := make(map[string]float64) // 签约客户(金额)
|
|
|
+ mapAddTrialNum := make(map[string]float64) // 新增试用-(数据)
|
|
|
+ mapNewContractMoney := make(map[string]float64) // 新签合同(金额)
|
|
|
+ mapNewContractNum := make(map[string]int) // 新签合同(数量)
|
|
|
+ mapExpiredContractMoney := make(map[string]float64) // 到期合同(金额)
|
|
|
+ mapExpiredContractNum := make(map[string]int) // 到期合同(数量)
|
|
|
+ mapRenewedContractMoney := make(map[string]float64) // 续约合同(金额)
|
|
|
+ mapRenewedContractNum := make(map[string]int) // 续约合同(数量)
|
|
|
+ confirmedNoRenewalContractMoney := make(map[string]float64) // 确认不续约合同(金额)
|
|
|
+ confirmedNoRenewalContractNum := make(map[string]int) // 确认不续约合同(数量)
|
|
|
+ mapSignedClientNum := make(map[string]int) // 签约客户(数量)
|
|
|
+ mapSignedClientMoney := make(map[string]float64) // 签约客户(金额)
|
|
|
+ mapInvoiceAmountMoney := make(map[string]float64) // 财务系统开票金额(金额)
|
|
|
+ mapPaymentAmountMoney := make(map[string]float64) // 财务系统到款金额(金额)
|
|
|
+ mapNewCustomerInvoicingMoney := make(map[string]float64) // 财务系统新客开票金额(金额)
|
|
|
+ mapNewCustomerPaymentsReceivedMoney := make(map[string]float64) // 财务系统新客到款金额(金额)
|
|
|
|
|
|
for _, v := range listRaiData {
|
|
|
startDateTime := utils.StrDateToDate(v.StartDate)
|
|
@@ -178,11 +184,49 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
|
|
|
confirmedNoRenewalContractMoney[keyMap] += v.Money
|
|
|
confirmedNoRenewalContractNum[keyMap]++
|
|
|
}
|
|
|
-
|
|
|
mapSignedClientMoney[keyMap] += v.Money
|
|
|
mapSignedClientNum[keyMap]++
|
|
|
}
|
|
|
|
|
|
+ listFmsData, err := fms.GetContractRegisterListByStartDate(startDate)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取数据信息失败"
|
|
|
+ br.ErrMsg = "获取财务系统数据信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range listFmsData {
|
|
|
+ startDateTime := v.StartDate
|
|
|
+ monthNum := startDateTime.Month()
|
|
|
+ yearStr := strconv.Itoa(startDateTime.Year())
|
|
|
+ if dataType == "季度" {
|
|
|
+ if monthNum < 4 {
|
|
|
+ yearStr += "Q1"
|
|
|
+ } else if monthNum > 3 && monthNum < 7 {
|
|
|
+ yearStr += "Q2"
|
|
|
+ } else if monthNum > 6 && monthNum < 10 {
|
|
|
+ yearStr += "Q3"
|
|
|
+ } else if monthNum > 9 {
|
|
|
+ yearStr += "Q4"
|
|
|
+ }
|
|
|
+ } else if dataType == "半年度" {
|
|
|
+ if monthNum < 7 {
|
|
|
+ yearStr += "H1"
|
|
|
+ } else {
|
|
|
+ yearStr += "H2"
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ keyMap := fmt.Sprint(yearStr, "_", v.RaiSellerId)
|
|
|
+ mapInvoiceAmountMoney[keyMap] += v.InvoicedAmount
|
|
|
+ mapPaymentAmountMoney[keyMap] += v.PaymentAmount
|
|
|
+
|
|
|
+ if v.ContractType == 1 {
|
|
|
+ mapNewCustomerInvoicingMoney[keyMap] += v.InvoicedAmount
|
|
|
+ mapNewCustomerPaymentsReceivedMoney[keyMap] += v.PaymentAmount
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
conditionTry := ` AND a.create_time >= ? AND a.create_time <= ? AND a.operation in ( "add","receive","apply_receive" ) AND a.sys_user_id IN ( SELECT admin_id FROM admin WHERE role_type_code IN ( 'rai_seller', 'rai_group' , 'rai_admin') ) `
|
|
|
var parsTry []interface{}
|
|
|
parsTry = append(parsTry, startDate, endDate)
|
|
@@ -289,13 +333,18 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
|
|
|
sellerItem.AverageRevenueCount = utils.SubFloatToString(mapSignedClientMoney[keyMap]/float64(mapSignedClientNum[keyMap]), 2) //客单价
|
|
|
}
|
|
|
|
|
|
- sellerItem.InvoiceAmountCount = "开票金额-(数据)"
|
|
|
- sellerItem.PaymentReceivedCount = "到款金额-(数据)"
|
|
|
- sellerItem.UnpaidRatioCount = "未到款比例-(数据)"
|
|
|
- sellerItem.NewCustomerInvoicingCount = "新客开票-(数据)"
|
|
|
- sellerItem.NewCustomerPaymentsReceivedCount = "新客到款-(数据)"
|
|
|
+ sellerItem.InvoiceAmountCount = utils.SubFloatToString(mapInvoiceAmountMoney[keyMap], 2) //"开票金额-(数据)"
|
|
|
+ sellerItem.PaymentReceivedCount = utils.SubFloatToString(mapPaymentAmountMoney[keyMap], 2) //"开票金额-(数据)"
|
|
|
+ if mapInvoiceAmountMoney[keyMap] == 0 || mapPaymentAmountMoney[keyMap] == 0 {
|
|
|
+ sellerItem.UnpaidRatioCount = "0%"
|
|
|
+ } else {
|
|
|
+ sellerItem.UnpaidRatioCount = utils.SubFloatToString((mapInvoiceAmountMoney[keyMap]-mapPaymentAmountMoney[keyMap])/mapInvoiceAmountMoney[keyMap]*100, 2) + "%" //"未到款比例-(数据)"
|
|
|
+ }
|
|
|
+ sellerItem.NewCustomerInvoicingCount = utils.SubFloatToString(mapNewCustomerInvoicingMoney[keyMap], 2) // "新客开票-(数据)"
|
|
|
+ sellerItem.NewCustomerPaymentsReceivedCount = utils.SubFloatToString(mapNewCustomerPaymentsReceivedMoney[keyMap], 2) // "新客到款-(数据)"
|
|
|
item.DataList = append(item.DataList, sellerItem)
|
|
|
}
|
|
|
+
|
|
|
if len(sellerDevelop) > 0 {
|
|
|
sellerItem := new(statistic_report.RaiDataSummaryDetail)
|
|
|
sellerItem.SellerName = "开拓组合计"
|
|
@@ -406,6 +455,9 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
|
|
|
resp := new(statistic_report.RaiDataSummaryPopupTypeResp)
|
|
|
var listResp []*statistic_report.RaiDataSummaryDetailResp
|
|
|
var trialTotal int
|
|
|
+
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
switch popupType {
|
|
|
case "新增试用":
|
|
|
var parsTry []interface{}
|
|
@@ -447,6 +499,56 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
|
|
|
listResp = append(listResp, item)
|
|
|
}
|
|
|
}
|
|
|
+ case "新签合同":
|
|
|
+
|
|
|
+ if sellerId > 0 {
|
|
|
+ condition += ` AND a.seller_id_init = ? `
|
|
|
+ pars = append(pars, sellerId)
|
|
|
+ }
|
|
|
+
|
|
|
+ condition += ` AND a.status = 1 AND a.start_date >= ? AND a.start_date <= ? `
|
|
|
+ pars = append(pars, startDate, endDate)
|
|
|
+ condition += ` AND a.rai_contract_type = ? `
|
|
|
+ pars = append(pars, "新签合同")
|
|
|
+
|
|
|
+ total, err := company.GetIncrementalNewCompanyProductMergeCount(condition, pars)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ trialTotal = total
|
|
|
+ //列表页数据
|
|
|
+ tmpList, err := models.GetIncrementalCompanyMergeList(condition, pars, startSize, pageSize)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(tmpList) > 0 {
|
|
|
+ var companyContractIds []int
|
|
|
+ for _, v := range tmpList {
|
|
|
+ companyContractIds = append(companyContractIds, v.CompanyContractId)
|
|
|
+ }
|
|
|
+
|
|
|
+ //合并合同所对应的权限
|
|
|
+ mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range tmpList {
|
|
|
+ item := new(statistic_report.RaiDataSummaryDetailResp)
|
|
|
+ item.CompanyName = v.CompanyName
|
|
|
+ item.SellerName = v.SellerNameInit
|
|
|
+ item.StartDate = v.StartDate
|
|
|
+ item.EndDate = v.EndDate
|
|
|
+ item.Money = v.Money
|
|
|
+ item.PermissionName = mappermissionName[v.CompanyContractId]
|
|
|
+ listResp = append(listResp, item)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if len(listResp) == 0 {
|