Browse Source

Merge branch 'crm/crm_16.7' of http://8.136.199.33:3000/hongze/hz_crm_api

zhangchuanxing 2 weeks ago
parent
commit
1b8ac218c3

+ 3 - 0
controllers/company_apply_v2.go

@@ -257,6 +257,7 @@ func (this *CompanyApplyController) ApplyServiceUpdate() {
 			br.ErrMsg = "新增合同失败,Err:" + err.Error()
 			return
 		}
+		go services.UpdateCompanyContractInheritEndDate(int(newId))
 		permissionArr := strings.Split(req.PermissionIds, ",")
 		permissionMap := make(map[int]int) //权限id的map集合,用来避免重复添加权限校验
 
@@ -746,6 +747,7 @@ func (this *CompanyApplyController) ApplyTurnPositive() {
 			br.ErrMsg = "新增合同失败,Err:" + err.Error()
 			return
 		}
+		go services.UpdateCompanyContractInheritEndDate(int(newId))
 		permissionArr := strings.Split(req.PermissionIds, ",")
 		permissionMap := make(map[int]int) //权限id的map集合,用来避免重复添加权限校验
 		permissionItems := make([]*company.CompanyContractPermission, 0)
@@ -1257,6 +1259,7 @@ func (this *CompanyApplyController) ApplyBySystemContract() {
 			br.ErrMsg = "新增合同失败,Err:" + err.Error()
 			return
 		}
+		go services.UpdateCompanyContractInheritEndDate(int(newId))
 		upgradeMap := make(map[int]int)
 		if utils.RunMode == "release" {
 			upgradeMap = map[int]int{22: 39, 21: 38, 20: 37, 19: 36}

+ 108 - 3
controllers/company_seller.go

@@ -191,7 +191,7 @@ func (this *CompanySellerController) CheckListV2() {
 	getAllUser, _ := this.GetBool("AllUser", false)
 	status, _ := this.GetInt("Status", 0)
 	getAllEnabled, _ := this.GetBool("AllEnabled", false)
-	enabled := -1       //默认只获取正常状态的用户
+	enabled := -1      //默认只获取正常状态的用户
 	if getAllEnabled { //获取所有状态的用户
 		enabled = -1
 	}
@@ -5572,7 +5572,7 @@ func (this *CompanySellerController) InvoicePaymentCheckList() {
 	getAllUser, _ := this.GetBool("AllUser", false)
 	status, _ := this.GetInt("Status", 0)
 	//getAllEnabled, _ := this.GetBool("AllEnabled", false)
-	enabled := -1       //默认只获取正常状态的用户
+	enabled := -1 //默认只获取正常状态的用户
 	//if getAllEnabled { //获取所有状态的用户
 	//	enabled = -1
 	//}
@@ -7485,4 +7485,109 @@ func (this *CompanySellerController) InvoicePaymentCheckList() {
 	br.Data = company.DepartmentGroupSellersResp{
 		List: list,
 	}
-}
+}
+
+// CheckListV2
+// @Title 获取权益开拓组或者服务组下面的销售
+// @Description 获取权益开拓组或者服务组下面的销售接口
+// @Success 200 {object} company.DepartmentGroupSellersResp
+// @router /seller/check/list_rai/server_type [get]
+func (this *CompanySellerController) CheckListRaiServerType() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	//serverType := this.GetString("ServerType", "开拓")
+	list := make([]company.DepartmentGroupSellers, 0)
+	listServer := make([]company.DepartmentGroupSellers, 0)
+
+	condition := " AND role_type_code IN ('rai_seller','rai_group') AND enabled = 1 AND  rai_enabled = 1 "
+	var pars []interface{}
+	//名字带6 的属于服务组
+	//if serverType == "开拓" {
+	//	condition += " AND  real_name  NOT LIKE '%6%' "
+	//} else {
+	//	condition += " AND  real_name LIKE '%6%' "
+	//}
+	sellerList, err := system.GetSysUserItemsOrderByCreated(condition, pars)
+	if err != nil {
+		br.Msg = "获取管理账号失败"
+		br.ErrMsg = "获取管理账号失败,Err:" + err.Error()
+		return
+	}
+	//部门管理员看小组、销售
+	departmentId := 5
+	groupList, err := system.GetSysGroupByDepartmentId(departmentId)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取分组失败,Err:" + err.Error()
+		return
+	}
+	for _, group := range groupList {
+		groupSellerList := make([]company.DepartmentGroupSellers, 0)
+		groupItem := company.DepartmentGroupSellers{
+			AdminId: fmt.Sprint("group_", group.DepartmentId),
+			//AdminName string `description:"系统用户名称"`
+			RealName:     group.GroupName,
+			ChildrenList: groupSellerList,
+		}
+		for _, seller := range sellerList {
+			if seller.GroupId != group.GroupId || strings.Contains(seller.RealName, "6") {
+				continue
+			}
+			sellerItem := company.DepartmentGroupSellers{
+				AdminId:      fmt.Sprint(seller.AdminId),
+				RealName:     seller.RealName,
+				Authority:    seller.Authority,
+				RoleTypeCode: seller.RoleTypeCode,
+			}
+			groupSellerList = append(groupSellerList, sellerItem)
+		}
+		groupItem.ChildrenList = groupSellerList
+		if len(groupSellerList) > 0 {
+			list = append(list, groupItem)
+		}
+	}
+
+	for _, group := range groupList {
+		groupSellerList := make([]company.DepartmentGroupSellers, 0)
+		groupItem := company.DepartmentGroupSellers{
+			AdminId: fmt.Sprint("group_", group.DepartmentId),
+			//AdminName string `description:"系统用户名称"`
+			RealName:     group.GroupName,
+			ChildrenList: groupSellerList,
+		}
+		for _, seller := range sellerList {
+			if seller.GroupId != group.GroupId || !strings.Contains(seller.RealName, "6") {
+				continue
+			}
+			sellerItem := company.DepartmentGroupSellers{
+				AdminId:      fmt.Sprint(seller.AdminId),
+				RealName:     seller.RealName,
+				Authority:    seller.Authority,
+				RoleTypeCode: seller.RoleTypeCode,
+			}
+			groupSellerList = append(groupSellerList, sellerItem)
+		}
+		groupItem.ChildrenList = groupSellerList
+		if len(groupSellerList) > 0 {
+			listServer = append(listServer, groupItem)
+		}
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = company.DepartmentGroupSellersServerResp{
+		List:       list,
+		ListServer: listServer,
+	}
+}

+ 1 - 0
controllers/cygx/activity.go

@@ -32,6 +32,7 @@ func (this *ActivityCoAntroller) List() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
+
 	isZxdy, _ := this.GetBool("IsZxdy", false)
 	sysUser := this.SysUser
 	if sysUser == nil {

+ 1593 - 0
controllers/statistic/rai_data_summary.go

@@ -0,0 +1,1593 @@
+package statistic
+
+import (
+	"fmt"
+	"github.com/rdlucklib/rdluck_tools/paging"
+	"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"
+	"hongze/hz_crm_api/services"
+	cygxService "hongze/hz_crm_api/services/cygx"
+	"hongze/hz_crm_api/utils"
+	"strconv"
+	"strings"
+	"time"
+)
+
+// 权益数据汇总
+// StatisticRaiDataSummaryController 权益数据汇总基类
+type StatisticRaiDataSummaryController struct {
+	controllers.BaseAuthController
+}
+
+// MergeCompanyList
+// @Title 权益数据汇总
+// @Description 权益数据汇总统计列表接口
+// @Param   AdminId   query   string  true       "开拓组销售id,多个用英文逗号隔开,空字符串为全部"
+// @Param   ServiceAdminId   query   string  true       "服务组销售id,多个用英文逗号隔开,空字符串为全部"
+// @Param   StartYear   query   int	  false       "开始日期(年份)"
+// @Param   EndYear   query   int  false       "结束日期(年份)"
+// @Param   DataType   query   string  false       "报表类型,枚举值:`季度`,`年度`,`半年度`"
+// @Param   DevelopButton   query   int	  false       "开拓组开关,枚举值:1:开启,0:关闭 ,默认关闭"
+// @Param   ServerButton   query   int	  false       "服务组开关,枚举值:1:开启,0:关闭 ,默认关闭"
+// @Param   ContractButtonType   query   string	  false       "开关类型,:`新签`,`续约`,`收入` 多个用英文逗号隔开, "
+// @Param   IsExport   query   bool  false       "是否导出excel,默认是false"
+// @Success 200 {object} statistic_report.RaiDataSummaryListResp
+// @router /rai_data_summary/list [get]
+func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+
+	dataType := this.GetString("DataType")
+	adminId := this.GetString("AdminId")
+	serviceAdminId := this.GetString("ServiceAdminId")
+	startYear, _ := this.GetInt("StartYear")
+	endYear, _ := this.GetInt("EndYear")
+	developButton, _ := this.GetBool("DevelopButton")
+	serverButton, _ := this.GetBool("ServerButton")
+
+	dataTypeArr := []string{}
+	if dataType == "季度" {
+		dataTypeArr = []string{"Q1", "Q2", "Q3", "Q4"}
+	} else if dataType == "半年度" {
+		dataTypeArr = []string{"H1", "H2"}
+	} else {
+		dataTypeArr = []string{""}
+	}
+
+	condition := " AND role_type_code IN ('rai_seller','rai_group') AND enabled = 1 AND  rai_enabled = 1  "
+	var pars []interface{}
+	if adminId != "" {
+		serviceAdminId = ""
+		condition += " AND  admin_id IN (" + adminId + ") "
+	}
+	if serviceAdminId != "" {
+		condition += " AND  admin_id IN (" + serviceAdminId + ") "
+	}
+
+	if developButton && !serverButton && adminId == "" && serviceAdminId == "" { //开拓组筛选条件
+		condition += " AND  real_name   NOT LIKE '%6%' "
+	}
+
+	if !developButton && serverButton && adminId == "" && serviceAdminId == "" { //服务组筛选条件
+		condition += " AND  real_name   LIKE '%6%' "
+	}
+
+	sellerList, err := system.GetSysUserItemsOrderByCreated(condition, pars)
+	if err != nil {
+		br.Msg = "获取管理账号失败"
+		br.ErrMsg = "获取管理账号失败,Err:" + err.Error()
+		return
+	}
+	var sellerDevelop []*system.AdminItem     // 开拓组销售
+	var sellerService []*system.AdminItem     // 服务组销售
+	var sellerDevelopIds = make(map[int]bool) // 开拓组销售的map
+	mapsellerId := make(map[int]bool)         // 权益销售map
+	for _, v := range sellerList {
+		if strings.Contains(v.RealName, "6") {
+			sellerService = append(sellerService, v)
+		} else {
+			sellerDevelop = append(sellerDevelop, v)
+			sellerDevelopIds[v.AdminId] = true
+		}
+		mapsellerId[v.AdminId] = true
+	}
+
+	//拼接起始时间查询
+	startDate := fmt.Sprintf("%d-01-01", startYear)
+	endDate := fmt.Sprintf("%d-12-31", endYear)
+
+	//新签部分的数据
+	var conditionRai string
+	var parsRai []interface{}
+	conditionRai = " AND  a.product_id = 2  AND  a.status = 1  AND  a.start_date >= ?  AND  a.start_date <= ? AND a.rai_contract_type = '新签合同'  "
+	parsRai = append(parsRai, startDate, endDate)
+	listRaiData, err := statistic_report.GetRaiDataSummaryList(conditionRai, parsRai)
+	if err != nil {
+		br.Msg = "获取数据信息失败"
+		br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+		return
+	}
+	var companyIds []int
+	for _, v := range listRaiData {
+		companyIds = append(companyIds, v.CompanyId)
+	}
+	companyIds = append(companyIds, 0)
+
+	//续约部分的数据
+	var conditionInherit string
+	var parsInherit []interface{}
+	conditionInherit = ` AND  a.product_id = 2  AND  a.status = 1  AND  a.inherit_end_date >= ?  AND  a.inherit_end_date <= ?  AND a.rai_contract_type = '续约合同'   AND  a.company_id NOT IN (` + utils.GetOrmInReplace(len(companyIds)) + `) `
+	parsInherit = append(parsInherit, startDate, endDate, companyIds)
+	listInheritData, err := statistic_report.GetRaiDataSummaryInheritList(conditionInherit, parsInherit)
+	if err != nil {
+		br.Msg = "获取数据信息失败"
+		br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+		return
+	}
+
+	//确认不续约、到期合同部分的数据
+	var conditionEnd string
+	var parsEnd []interface{}
+	conditionEnd = " AND  a.product_id = 2  AND  a.status = 1  AND  a.end_date >= ?  AND  a.end_date <= ? AND  a.end_date <= ? "
+	parsEnd = append(parsEnd, startDate, endDate, time.Now().Format(utils.FormatDate))
+	listEndData, err := statistic_report.GetRaiDataSummaryList(conditionEnd, parsEnd)
+	if err != nil {
+		br.Msg = "获取数据信息失败"
+		br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+		return
+	}
+
+	var conditionConfirm string
+	var parsConfirm []interface{}
+	mapNoRenewedcompanyContractIds := make(map[int]bool) //已经确定未续约的合同ID
+	conditionConfirm = " AND company_ascribe_id != 9  "
+	companyConfirmList, err := company.GetCompanyContractNoRenewedAscribeList(conditionConfirm, parsConfirm, 0, 0)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,GetCompanyNoRenewedAscribeList Err:" + err.Error()
+		return
+	}
+	for _, v := range companyConfirmList {
+		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)                   // 到期合同(数量)
+	mapExpiredContractCompanyNum := make(map[string]int)            // 到期公司(数量)
+	mapRenewedContractMoney := make(map[string]float64)             // 续约合同(金额)
+	mapRenewedContractNum := make(map[string]int)                   // 续约合同(数量)
+	mapRenewedContractCompanyNum := make(map[string]int)            // 续约公司(数量)
+	confirmedNoRenewalContractMoney := make(map[string]float64)     // 确认不续约合同(金额)
+	confirmedNoRenewalContractNum := make(map[string]int)           // 确认不续约合同(数量)
+	confirmedNoRenewalContractCompanyNum := 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) // 财务系统新客到款金额(金额)
+
+	var keyMap string
+	var keyMapTtoal string
+	var keyMapTtoalServer string
+	var keyMapCompany string
+	var keyMapCompanyNo string
+	var keySigned string
+
+	mapCompanyData := make(map[string]bool)
+	//新签部分的数据
+	for _, v := range listRaiData {
+		if !mapsellerId[v.SellerIdLast] {
+			continue
+		}
+		startDateTime := utils.StrDateToDate(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.SellerIdLast)
+		keySigned = fmt.Sprint(yearStr, "_", "_CID_", v.CompanyId, "_SID_", v.SellerIdLast)
+
+		if sellerDevelopIds[v.SellerIdLast] == true {
+			keyMapTtoal = fmt.Sprint(yearStr, "_Develop")
+		} else {
+			keyMapTtoal = fmt.Sprint(yearStr, "_Service")
+		}
+
+		if v.RaiContractType == "新签合同" {
+			mapNewContractMoney[keyMap] += v.Money
+			mapNewContractNum[keyMap]++
+
+			mapNewContractMoney[keyMapTtoal] += v.Money
+			mapNewContractNum[keyMapTtoal]++
+		}
+
+		mapSignedClientMoney[keyMap] += v.Money
+		mapSignedClientMoney[keyMapTtoal] += v.Money
+
+		if !mapCompanyData[keySigned] && v.RaiContractType == "新签合同" {
+			mapSignedClientNum[keyMap]++
+			mapSignedClientNum[keyMapTtoal]++
+			mapCompanyData[keySigned] = true
+		}
+	}
+
+	//续约部分的数据
+	mapKeyMapCompanyData := make(map[string]bool)
+	for _, v := range listInheritData {
+		if !mapsellerId[v.SellerIdLast] {
+			continue
+		}
+		startDateTime := utils.StrDateToDate(v.InheritEndDate)
+		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.SellerIdLast)
+		keyMapCompany = fmt.Sprint(yearStr, "_", v.SellerIdLast, "_CID_", v.CompanyId)
+		if sellerDevelopIds[v.SellerIdLast] == true {
+			keyMapTtoal = fmt.Sprint(yearStr, "_Develop")
+		} else {
+			keyMapTtoal = fmt.Sprint(yearStr, "_Service")
+		}
+
+		//续约合同 数据
+		mapRenewedContractMoney[keyMap] += v.Money
+
+		mapRenewedContractMoney[keyMapTtoal] += v.Money
+
+		//一家公司同一个时间纬度,只统计一次
+		//if !mapKeyMapCompanyData[keyMapCompany] {
+		mapRenewedContractNum[keyMap]++
+		mapRenewedContractNum[keyMapTtoal]++
+		//mapKeyMapCompanyData[keyMapCompany] = true
+		//}
+		if !mapKeyMapCompanyData[keyMapCompany] {
+			mapRenewedContractCompanyNum[keyMap]++
+			mapRenewedContractCompanyNum[keyMapTtoal]++
+			mapKeyMapCompanyData[keyMapCompany] = true
+		}
+		if !mapCompanyData[keySigned] && v.RaiContractType == "续约合同" {
+			mapSignedClientNum[keyMap]++
+			mapSignedClientNum[keyMapTtoal]++
+			mapCompanyData[keySigned] = true
+		}
+	}
+
+	//确认不续约、到期合同部分的数据
+	mapKeyMapCompanyEndData := make(map[string]bool)
+	mapKeyMapCompanyNoData := make(map[string]bool)
+	for _, v := range listEndData {
+		if !mapsellerId[v.SellerIdLast] {
+			continue
+		}
+		startDateTime := utils.StrDateToDate(v.EndDate)
+		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.SellerIdLast)
+		keyMapCompany = fmt.Sprint(yearStr, "_", v.SellerIdLast, "_CID_", v.CompanyId)
+		keyMapCompanyNo = fmt.Sprint(yearStr, "_", v.SellerIdLast, "_CID_NO", v.CompanyId)
+		if sellerDevelopIds[v.SellerIdLast] == true {
+			keyMapTtoal = fmt.Sprint(yearStr, "_Develop")
+		} else {
+			keyMapTtoal = fmt.Sprint(yearStr, "_Service")
+		}
+
+		//到期合同数据
+		mapExpiredContractMoney[keyMap] += v.Money
+		mapExpiredContractMoney[keyMapTtoal] += v.Money
+
+		//一家公司同一个时间纬度,只统计一次
+		//if !mapKeyMapCompanyEndData[keyMapCompany] {
+		mapExpiredContractNum[keyMap]++
+		mapExpiredContractNum[keyMapTtoal]++
+		//mapKeyMapCompanyEndData[keyMapCompany] = true
+		//}
+
+		//一家公司同一个时间纬度,只统计一次
+		if !mapKeyMapCompanyEndData[keyMapCompany] {
+			mapExpiredContractCompanyNum[keyMap]++
+			mapExpiredContractCompanyNum[keyMapTtoal]++
+			mapKeyMapCompanyEndData[keyMapCompany] = true
+		}
+
+		if mapNoRenewedcompanyContractIds[v.CompanyContractId] { // 确认不续约合同
+			confirmedNoRenewalContractMoney[keyMap] += v.Money
+
+			confirmedNoRenewalContractMoney[keyMapTtoal] += v.Money
+
+			//一家公司同一个时间纬度,只统计一次
+			//if !mapKeyMapCompanyNoData[keyMapCompanyNo] {
+			confirmedNoRenewalContractNum[keyMap]++
+			confirmedNoRenewalContractNum[keyMapTtoal]++
+			//mapKeyMapCompanyNoData[keyMapCompanyNo] = true
+			//}
+
+			if !mapKeyMapCompanyNoData[keyMapCompanyNo] {
+				confirmedNoRenewalContractCompanyNum[keyMap]++
+				confirmedNoRenewalContractCompanyNum[keyMapTtoal]++
+				mapKeyMapCompanyNoData[keyMapCompanyNo] = true
+			}
+
+		}
+	}
+
+	listFmsData, err := fms.GetContractRegisterListByStartDate(startDate, endDate)
+	if err != nil {
+		br.Msg = "获取数据信息失败"
+		br.ErrMsg = "获取财务系统数据信息失败,Err:" + err.Error()
+		return
+	}
+
+	for _, v := range listFmsData {
+		if !mapsellerId[v.RaiSellerId] {
+			continue
+		}
+		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)
+
+		if sellerDevelopIds[v.RaiSellerId] == true {
+			keyMapTtoal = fmt.Sprint(yearStr, "_Develop")
+		} else {
+			keyMapTtoal = fmt.Sprint(yearStr, "_Service")
+		}
+
+		mapInvoiceAmountMoney[keyMap] += v.InvoicedAmount
+		mapPaymentAmountMoney[keyMap] += v.PaymentAmount
+
+		mapInvoiceAmountMoney[keyMapTtoal] += v.InvoicedAmount
+		mapPaymentAmountMoney[keyMapTtoal] += v.PaymentAmount
+
+		if v.ContractType == 1 {
+			mapNewCustomerInvoicingMoney[keyMap] += v.InvoicedAmount
+			mapNewCustomerPaymentsReceivedMoney[keyMap] += v.PaymentAmount
+			mapNewCustomerInvoicingMoney[keyMapTtoal] += v.InvoicedAmount
+			mapNewCustomerPaymentsReceivedMoney[keyMapTtoal] += 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)
+	//列表页数据
+	tryList, err := models.GetIncrementalCompanyListByOperationRecordRai(conditionTry, parsTry, 0, 9999)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+	for _, v := range tryList {
+		startDateTime := utils.StrTimeToTime(v.CreateTime)
+		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.SysUserId)
+		mapAddTrialNum[keyMap]++
+
+		//var keyMapTtoal string
+		sysUserId, _ := strconv.Atoi(v.SysUserId)
+		if sellerDevelopIds[sysUserId] == true {
+			keyMapTtoal = fmt.Sprint(yearStr, "_Develop")
+		} else {
+			keyMapTtoal = fmt.Sprint(yearStr, "_Service")
+		}
+		mapAddTrialNum[keyMapTtoal]++
+	}
+
+	resp := new(statistic_report.RaiDataSummaryListResp)
+	var items []*statistic_report.RaiDataSummaryResp
+	for i := startYear; i <= endYear; i++ {
+		//if len(dataTypeArr) > 0 {
+		for _, Dv := range dataTypeArr {
+			item := new(statistic_report.RaiDataSummaryResp)
+			item.DataType = fmt.Sprint(i, Dv)
+			keyMapTtoal = fmt.Sprint(item.DataType, "_Develop")
+			keyMapTtoalServer = fmt.Sprint(item.DataType, "_Server")
+			var sellerIds []string
+			var sellerServiceIds []string
+			for _, vS := range sellerDevelop {
+				keyMap = fmt.Sprint(item.DataType, "_", vS.AdminId)
+				sellerItem := new(statistic_report.RaiDataSummaryDetail)
+				sellerItem.SellerId = strconv.Itoa(vS.AdminId)
+				sellerIds = append(sellerIds, sellerItem.SellerId)
+				sellerItem.SellerName = vS.RealName
+				sellerItem.AddTrialCount = fmt.Sprint(mapAddTrialNum[keyMap])
+				sellerItem.NewContractData = fmt.Sprint(utils.SubFloatToString(mapNewContractMoney[keyMap], 2), " / ", mapNewContractNum[keyMap])             // 新签合同(金额/数量)-(数据)
+				sellerItem.ExpiredContractData = fmt.Sprint(utils.SubFloatToString(mapExpiredContractMoney[keyMap], 2), " / ", mapExpiredContractNum[keyMap]) //"到期合同(金额/数量)-(数据)"
+				sellerItem.RenewedContractData = fmt.Sprint(utils.SubFloatToString(mapRenewedContractMoney[keyMap], 2), " / ", mapRenewedContractNum[keyMap]) // "续约合同(金额/数量)-(数据)"
+				var renewalRateMoey string
+				var renewalRateNum string
+				if mapRenewedContractMoney[keyMap] == 0 || mapExpiredContractMoney[keyMap] == 0 {
+					renewalRateMoey = "0%"
+				} else {
+					renewalRateMoey = utils.SubFloatToString(mapRenewedContractMoney[keyMap]/mapExpiredContractMoney[keyMap]*100, 2) + "%"
+				}
+				if mapRenewedContractCompanyNum[keyMap] == 0 || mapExpiredContractCompanyNum[keyMap] == 0 {
+					renewalRateNum = "0%"
+				} else {
+					renewalRateNum = utils.SubFloatToString(float64(mapRenewedContractCompanyNum[keyMap])/float64(mapExpiredContractCompanyNum[keyMap])*100, 2) + "%"
+				}
+				sellerItem.RenewalRateData = fmt.Sprint(renewalRateMoey, " / ", renewalRateNum)                                                                                          //"续约率(金额/数量)-(数据)"
+				sellerItem.ConfirmedNoRenewalContractData = fmt.Sprint(utils.SubFloatToString(confirmedNoRenewalContractMoney[keyMap], 2), " / ", confirmedNoRenewalContractNum[keyMap]) //"确认不续约合同(金额/数量)-(数据)"
+
+				var confirmNonRenewalRateMoey string
+				var confirmNonRenewalRateNum string
+				if confirmedNoRenewalContractMoney[keyMap] == 0 || mapExpiredContractMoney[keyMap] == 0 {
+					confirmNonRenewalRateMoey = "0%"
+				} else {
+					confirmNonRenewalRateMoey = utils.SubFloatToString(confirmedNoRenewalContractMoney[keyMap]/mapExpiredContractMoney[keyMap]*100, 2) + "%"
+				}
+				if confirmedNoRenewalContractCompanyNum[keyMap] == 0 || mapExpiredContractCompanyNum[keyMap] == 0 {
+					confirmNonRenewalRateNum = "0%"
+				} else {
+					confirmNonRenewalRateNum = utils.SubFloatToString(float64(confirmedNoRenewalContractCompanyNum[keyMap])/float64(mapExpiredContractCompanyNum[keyMap])*100, 2) + "%"
+				}
+				sellerItem.ConfirmNonRenewalRateData = fmt.Sprint(confirmNonRenewalRateMoey, " / ", confirmNonRenewalRateNum) //确认不续约率(金额/数量)-(数据)"
+
+				sellerItem.SignedClientCount = fmt.Sprint(mapSignedClientNum[keyMap]) // 签约客户数量
+				if mapSignedClientNum[keyMap] == 0 || mapSignedClientMoney[keyMap] == 0 {
+					sellerItem.AverageRevenueCount = "0"
+				} else {
+					sellerItem.AverageRevenueCount = utils.SubFloatToString(mapSignedClientMoney[keyMap]/float64(mapSignedClientNum[keyMap]), 2) //客单价
+				}
+
+				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) // "新客到款-(数据)"
+				if developButton || serverButton || adminId != "" {
+					item.DataList = append(item.DataList, sellerItem)
+				}
+			}
+
+			if len(sellerDevelop) > 0 {
+				sellerItem := new(statistic_report.RaiDataSummaryDetail)
+				sellerItem.SellerId = strings.Join(sellerIds, ",")
+				sellerItem.SellerName = "开拓组合计"
+				sellerItem.AddTrialCount = fmt.Sprint(mapAddTrialNum[keyMapTtoal])
+				sellerItem.NewContractData = fmt.Sprint(utils.SubFloatToString(mapNewContractMoney[keyMapTtoal], 2), " / ", mapNewContractNum[keyMapTtoal])             // 新签合同(金额/数量)-(数据)
+				sellerItem.ExpiredContractData = fmt.Sprint(utils.SubFloatToString(mapExpiredContractMoney[keyMapTtoal], 2), " / ", mapExpiredContractNum[keyMapTtoal]) //"到期合同(金额/数量)-(数据)"
+				sellerItem.RenewedContractData = fmt.Sprint(utils.SubFloatToString(mapRenewedContractMoney[keyMapTtoal], 2), " / ", mapRenewedContractNum[keyMapTtoal]) // "续约合同(金额/数量)-(数据)"
+				var renewalRateMoey string
+				var renewalRateNum string
+				if mapRenewedContractMoney[keyMapTtoal] == 0 || mapExpiredContractMoney[keyMapTtoal] == 0 {
+					renewalRateMoey = "0%"
+				} else {
+					renewalRateMoey = utils.SubFloatToString(mapRenewedContractMoney[keyMapTtoal]/mapExpiredContractMoney[keyMapTtoal]*100, 2) + "%"
+				}
+				if mapRenewedContractCompanyNum[keyMapTtoal] == 0 || mapExpiredContractCompanyNum[keyMapTtoal] == 0 {
+					renewalRateNum = "0%"
+				} else {
+					renewalRateNum = utils.SubFloatToString(float64(mapRenewedContractCompanyNum[keyMapTtoal])/float64(mapExpiredContractCompanyNum[keyMapTtoal])*100, 2) + "%"
+				}
+				sellerItem.RenewalRateData = fmt.Sprint(renewalRateMoey, " / ", renewalRateNum)                                                                                                    //"续约率(金额/数量)-(数据)"
+				sellerItem.ConfirmedNoRenewalContractData = fmt.Sprint(utils.SubFloatToString(confirmedNoRenewalContractMoney[keyMapTtoal], 2), " / ", confirmedNoRenewalContractNum[keyMapTtoal]) //"确认不续约合同(金额/数量)-(数据)"
+
+				var confirmNonRenewalRateMoey string
+				var confirmNonRenewalRateNum string
+				if confirmedNoRenewalContractMoney[keyMapTtoal] == 0 || mapExpiredContractMoney[keyMapTtoal] == 0 {
+					confirmNonRenewalRateMoey = "0%"
+				} else {
+					confirmNonRenewalRateMoey = utils.SubFloatToString(confirmedNoRenewalContractMoney[keyMapTtoal]/mapExpiredContractMoney[keyMapTtoal]*100, 2) + "%"
+				}
+				if confirmedNoRenewalContractCompanyNum[keyMapTtoal] == 0 || mapExpiredContractCompanyNum[keyMapTtoal] == 0 {
+					confirmNonRenewalRateNum = "0%"
+				} else {
+					confirmNonRenewalRateNum = utils.SubFloatToString(float64(confirmedNoRenewalContractCompanyNum[keyMapTtoal])/float64(mapExpiredContractCompanyNum[keyMapTtoal])*100, 2) + "%"
+				}
+				sellerItem.ConfirmNonRenewalRateData = fmt.Sprint(confirmNonRenewalRateMoey, " / ", confirmNonRenewalRateNum) //确认不续约率(金额/数量)-(数据)"
+
+				sellerItem.SignedClientCount = fmt.Sprint(mapSignedClientNum[keyMapTtoal]) // 签约客户数量
+				if mapSignedClientNum[keyMapTtoal] == 0 || mapSignedClientMoney[keyMapTtoal] == 0 {
+					sellerItem.AverageRevenueCount = "0"
+				} else {
+					sellerItem.AverageRevenueCount = utils.SubFloatToString(mapSignedClientMoney[keyMapTtoal]/float64(mapSignedClientNum[keyMapTtoal]), 2) //客单价
+				}
+
+				sellerItem.InvoiceAmountCount = utils.SubFloatToString(mapInvoiceAmountMoney[keyMapTtoal], 2)   //"开票金额-(数据)"
+				sellerItem.PaymentReceivedCount = utils.SubFloatToString(mapPaymentAmountMoney[keyMapTtoal], 2) //"开票金额-(数据)"
+				if mapInvoiceAmountMoney[keyMapTtoal] == 0 || mapPaymentAmountMoney[keyMapTtoal] == 0 {
+					sellerItem.UnpaidRatioCount = "0%"
+				} else {
+					sellerItem.UnpaidRatioCount = utils.SubFloatToString((mapInvoiceAmountMoney[keyMapTtoal]-mapPaymentAmountMoney[keyMapTtoal])/mapInvoiceAmountMoney[keyMapTtoal]*100, 2) + "%" //"未到款比例-(数据)"
+				}
+				sellerItem.NewCustomerInvoicingCount = utils.SubFloatToString(mapNewCustomerInvoicingMoney[keyMapTtoal], 2)               // "新客开票-(数据)"
+				sellerItem.NewCustomerPaymentsReceivedCount = utils.SubFloatToString(mapNewCustomerPaymentsReceivedMoney[keyMapTtoal], 2) // "新客到款-(数据)"
+				item.DataList = append(item.DataList, sellerItem)
+			}
+
+			for _, vS := range sellerService {
+				sellerItem := new(statistic_report.RaiDataSummaryDetail)
+				sellerItem.SellerId = strconv.Itoa(vS.AdminId)
+				sellerServiceIds = append(sellerServiceIds, sellerItem.SellerId)
+				sellerItem.SellerName = vS.RealName
+				sellerItem.AddTrialCount = fmt.Sprint(mapAddTrialNum[keyMap])
+				sellerItem.NewContractData = fmt.Sprint(utils.SubFloatToString(mapNewContractMoney[keyMap], 2), " / ", mapNewContractNum[keyMap])             // 新签合同(金额/数量)-(数据)
+				sellerItem.ExpiredContractData = fmt.Sprint(utils.SubFloatToString(mapExpiredContractMoney[keyMap], 2), " / ", mapExpiredContractNum[keyMap]) //"到期合同(金额/数量)-(数据)"
+				sellerItem.RenewedContractData = fmt.Sprint(utils.SubFloatToString(mapRenewedContractMoney[keyMap], 2), " / ", mapRenewedContractNum[keyMap]) // "续约合同(金额/数量)-(数据)"
+				var renewalRateMoey string
+				var renewalRateNum string
+				if mapRenewedContractMoney[keyMap] == 0 || mapExpiredContractMoney[keyMap] == 0 {
+					renewalRateMoey = "0%"
+				} else {
+					renewalRateMoey = utils.SubFloatToString(mapRenewedContractMoney[keyMap]/mapExpiredContractMoney[keyMap]*100, 2) + "%"
+				}
+				if mapRenewedContractCompanyNum[keyMap] == 0 || mapExpiredContractCompanyNum[keyMap] == 0 {
+					renewalRateNum = "0%"
+				} else {
+					renewalRateNum = utils.SubFloatToString(float64(mapRenewedContractCompanyNum[keyMap])/float64(mapExpiredContractCompanyNum[keyMap])*100, 2) + "%"
+				}
+				sellerItem.RenewalRateData = fmt.Sprint(renewalRateMoey, " / ", renewalRateNum)                                                                                          //"续约率(金额/数量)-(数据)"
+				sellerItem.ConfirmedNoRenewalContractData = fmt.Sprint(utils.SubFloatToString(confirmedNoRenewalContractMoney[keyMap], 2), " / ", confirmedNoRenewalContractNum[keyMap]) //"确认不续约合同(金额/数量)-(数据)"
+
+				var confirmNonRenewalRateMoey string
+				var confirmNonRenewalRateNum string
+				if confirmedNoRenewalContractMoney[keyMap] == 0 || mapExpiredContractMoney[keyMap] == 0 {
+					confirmNonRenewalRateMoey = "0%"
+				} else {
+					confirmNonRenewalRateMoey = utils.SubFloatToString(confirmedNoRenewalContractMoney[keyMap]/mapExpiredContractMoney[keyMap]*100, 2) + "%"
+				}
+				if confirmedNoRenewalContractCompanyNum[keyMap] == 0 || mapExpiredContractCompanyNum[keyMap] == 0 {
+					confirmNonRenewalRateNum = "0%"
+				} else {
+					confirmNonRenewalRateNum = utils.SubFloatToString(float64(confirmedNoRenewalContractCompanyNum[keyMap])/float64(mapExpiredContractCompanyNum[keyMap])*100, 2) + "%"
+				}
+				sellerItem.ConfirmNonRenewalRateData = fmt.Sprint(confirmNonRenewalRateMoey, " / ", confirmNonRenewalRateNum) //确认不续约率(金额/数量)-(数据)"
+
+				sellerItem.SignedClientCount = fmt.Sprint(mapSignedClientNum[keyMap]) // 签约客户数量
+				if mapSignedClientNum[keyMap] == 0 || mapSignedClientMoney[keyMap] == 0 {
+					sellerItem.AverageRevenueCount = "0"
+				} else {
+					sellerItem.AverageRevenueCount = utils.SubFloatToString(mapSignedClientMoney[keyMap]/float64(mapSignedClientNum[keyMap]), 2) //客单价
+				}
+
+				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) // "新客到款-(数据)"
+				if developButton || serverButton || serviceAdminId != "" {
+					item.DataList = append(item.DataList, sellerItem)
+				}
+			}
+			if len(sellerService) > 0 {
+				sellerItem := new(statistic_report.RaiDataSummaryDetail)
+				sellerItem.SellerId = strings.Join(sellerServiceIds, ",")
+				sellerItem.SellerName = "服务组合计"
+				sellerItem.AddTrialCount = fmt.Sprint(mapAddTrialNum[keyMapTtoalServer])
+				sellerItem.NewContractData = fmt.Sprint(utils.SubFloatToString(mapNewContractMoney[keyMapTtoalServer], 2), " / ", mapNewContractNum[keyMapTtoalServer])             // 新签合同(金额/数量)-(数据)
+				sellerItem.ExpiredContractData = fmt.Sprint(utils.SubFloatToString(mapExpiredContractMoney[keyMapTtoalServer], 2), " / ", mapExpiredContractNum[keyMapTtoalServer]) //"到期合同(金额/数量)-(数据)"
+				sellerItem.RenewedContractData = fmt.Sprint(utils.SubFloatToString(mapRenewedContractMoney[keyMapTtoalServer], 2), " / ", mapRenewedContractNum[keyMapTtoalServer]) // "续约合同(金额/数量)-(数据)"
+				var renewalRateMoey string
+				var renewalRateNum string
+				if mapRenewedContractMoney[keyMapTtoalServer] == 0 || mapExpiredContractMoney[keyMapTtoalServer] == 0 {
+					renewalRateMoey = "0%"
+				} else {
+					renewalRateMoey = utils.SubFloatToString(mapRenewedContractMoney[keyMapTtoalServer]/mapExpiredContractMoney[keyMapTtoalServer]*100, 2) + "%"
+				}
+				if mapRenewedContractCompanyNum[keyMapTtoalServer] == 0 || mapExpiredContractCompanyNum[keyMapTtoalServer] == 0 {
+					renewalRateNum = "0%"
+				} else {
+					renewalRateNum = utils.SubFloatToString(float64(mapRenewedContractCompanyNum[keyMapTtoalServer])/float64(mapExpiredContractCompanyNum[keyMapTtoalServer])*100, 2) + "%"
+				}
+				sellerItem.RenewalRateData = fmt.Sprint(renewalRateMoey, " / ", renewalRateNum)                                                                                                                //"续约率(金额/数量)-(数据)"
+				sellerItem.ConfirmedNoRenewalContractData = fmt.Sprint(utils.SubFloatToString(confirmedNoRenewalContractMoney[keyMapTtoalServer], 2), " / ", confirmedNoRenewalContractNum[keyMapTtoalServer]) //"确认不续约合同(金额/数量)-(数据)"
+
+				var confirmNonRenewalRateMoey string
+				var confirmNonRenewalRateNum string
+				if confirmedNoRenewalContractMoney[keyMapTtoalServer] == 0 || mapExpiredContractMoney[keyMapTtoalServer] == 0 {
+					confirmNonRenewalRateMoey = "0%"
+				} else {
+					confirmNonRenewalRateMoey = utils.SubFloatToString(confirmedNoRenewalContractMoney[keyMapTtoalServer]/mapExpiredContractMoney[keyMapTtoalServer]*100, 2) + "%"
+				}
+				if confirmedNoRenewalContractCompanyNum[keyMapTtoalServer] == 0 || mapExpiredContractCompanyNum[keyMapTtoalServer] == 0 {
+					confirmNonRenewalRateNum = "0%"
+				} else {
+					confirmNonRenewalRateNum = utils.SubFloatToString(float64(confirmedNoRenewalContractCompanyNum[keyMapTtoalServer])/float64(mapExpiredContractCompanyNum[keyMapTtoalServer])*100, 2) + "%"
+				}
+				sellerItem.ConfirmNonRenewalRateData = fmt.Sprint(confirmNonRenewalRateMoey, " / ", confirmNonRenewalRateNum) //确认不续约率(金额/数量)-(数据)"
+
+				sellerItem.SignedClientCount = fmt.Sprint(mapSignedClientNum[keyMapTtoalServer]) // 签约客户数量
+				if mapSignedClientNum[keyMapTtoalServer] == 0 || mapSignedClientMoney[keyMapTtoalServer] == 0 {
+					sellerItem.AverageRevenueCount = "0"
+				} else {
+					sellerItem.AverageRevenueCount = utils.SubFloatToString(mapSignedClientMoney[keyMapTtoalServer]/float64(mapSignedClientNum[keyMapTtoalServer]), 2) //客单价
+				}
+
+				sellerItem.InvoiceAmountCount = utils.SubFloatToString(mapInvoiceAmountMoney[keyMapTtoalServer], 2)   //"开票金额-(数据)"
+				sellerItem.PaymentReceivedCount = utils.SubFloatToString(mapPaymentAmountMoney[keyMapTtoalServer], 2) //"开票金额-(数据)"
+				if mapInvoiceAmountMoney[keyMapTtoalServer] == 0 || mapPaymentAmountMoney[keyMapTtoalServer] == 0 {
+					sellerItem.UnpaidRatioCount = "0%"
+				} else {
+					sellerItem.UnpaidRatioCount = utils.SubFloatToString((mapInvoiceAmountMoney[keyMapTtoalServer]-mapPaymentAmountMoney[keyMapTtoalServer])/mapInvoiceAmountMoney[keyMapTtoalServer]*100, 2) + "%" //"未到款比例-(数据)"
+				}
+				sellerItem.NewCustomerInvoicingCount = utils.SubFloatToString(mapNewCustomerInvoicingMoney[keyMapTtoalServer], 2)               // "新客开票-(数据)"
+				sellerItem.NewCustomerPaymentsReceivedCount = utils.SubFloatToString(mapNewCustomerPaymentsReceivedMoney[keyMapTtoalServer], 2) // "新客到款-(数据)"
+				item.DataList = append(item.DataList, sellerItem)
+			}
+			items = append(items, item)
+		}
+	}
+	resp.List = items
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// MergeCompanyList
+// @Title 权益数据汇总弹窗详情
+// @Description 权益数据汇总弹窗详情接口
+// @Param   SellerId   query   int  true       "销售ID"
+// @Param   DataType   query   string  false       "报表类型,枚举值:`季度`,`年度`,`半年度`"
+// @Param   PopupType   query   string	  false       "弹窗数据类型,枚举值:"
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Success 200 {object} statistic_report.RaiDataSummaryPopupTypeResp
+// @router /rai_data_summary/detail [get]
+func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	dataType := this.GetString("DataType")
+	sellerId := this.GetString("SellerId")
+	popupType := this.GetString("PopupType")
+
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = utils.StartIndex(currentIndex, pageSize)
+
+	var startDate string
+	var endDate string
+	year := (dataType[:4])
+	if strings.Contains(dataType, "Q1") {
+		startDate = year + "-01-01"
+		endDate = year + "-03-31"
+	} else if strings.Contains(dataType, "Q2") {
+		startDate = year + "-04-01"
+		endDate = year + "-06-30"
+	} else if strings.Contains(dataType, "Q3") {
+		startDate = year + "-07-01"
+		endDate = year + "-09-30"
+	} else if strings.Contains(dataType, "Q4") {
+		startDate = year + "-10-01"
+		endDate = year + "-12-31"
+	} else if strings.Contains(dataType, "H1") {
+		startDate = year + "-01-01"
+		endDate = year + "-06-31"
+	} else if strings.Contains(dataType, "H2") {
+		startDate = year + "-07-01"
+		endDate = year + "-12-31"
+	} else {
+		startDate = year + "-01-01"
+		endDate = year + "-12-31"
+	}
+
+	resp := new(statistic_report.RaiDataSummaryPopupTypeResp)
+	var listResp []*statistic_report.RaiDataSummaryDetailResp
+	var listGroup []*models.CompanyContractGroupList
+	var trialTotal int
+
+	var condition string
+	var pars []interface{}
+
+	//新签合同的客户ID
+	var companyIdsNew []int
+	{
+		var conditionNew string
+		var parsNew []interface{}
+		if sellerId != "" {
+			conditionNew += ` AND a.sys_user_id IN (` + sellerId + `) `
+		}
+		conditionNew = " AND  a.product_id = 2  AND  a.status = 1  AND  a.start_date >= ?  AND  a.start_date <= ? AND a.rai_contract_type = '新签合同'  "
+		parsNew = append(parsNew, startDate, endDate)
+		listNewData, err := statistic_report.GetRaiDataSummaryList(conditionNew, parsNew)
+		if err != nil {
+			br.Msg = "获取数据信息失败"
+			br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+			return
+		}
+		for _, v := range listNewData {
+			companyIdsNew = append(companyIdsNew, v.CompanyId)
+		}
+	}
+	companyIdsNew = append(companyIdsNew, 0)
+	lenArrCompany := len(companyIdsNew)
+
+	switch popupType {
+	case "新增试用":
+		var parsTry []interface{}
+		var conditionTry string
+		if sellerId != "" {
+			conditionTry += ` AND a.sys_user_id IN (` + sellerId + `) `
+		}
+		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') ) `
+
+		parsTry = append(parsTry, startDate, endDate)
+		total, err := models.GetIncrementalCompanyCountByOperationRecordRai(conditionTry, parsTry)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取新增试用客户数量失败,Err:" + err.Error()
+			return
+		}
+		trialTotal = total
+
+		//列表页数据
+		tryList, err := models.GetIncrementalCompanyListByOperationRecordRai(conditionTry, parsTry, startSize, pageSize)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取失败,Err:" + err.Error()
+			return
+		}
+		if len(tryList) > 0 {
+			for _, v := range tryList {
+				item := new(statistic_report.RaiDataSummaryDetailResp)
+				v.SellerName = v.SysRealName
+				if v.Operation == "add" {
+					item.AddType = "新建"
+				} else if v.Operation == "receive" || v.Operation == "apply_receive" {
+					item.AddType = "领取"
+				}
+				item.CompanyName = v.CompanyName
+				item.SellerName = v.SellerName
+				item.CreateTime = v.CreateTime
+				listResp = append(listResp, item)
+			}
+		}
+
+	case "新签合同":
+		if sellerId != "" {
+			condition += ` AND a.seller_id_init IN (` + 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)
+			}
+
+			listGroup, err = models.GetCompanyContractGroupList(condition, pars)
+			if err != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取失败,Err:" + err.Error()
+				return
+			}
+
+		}
+
+	case "到期合同":
+
+		if sellerId != "" {
+			condition += ` AND a.seller_id_last  IN (` + sellerId + `) `
+		}
+
+		condition += ` AND  a.status = 1  AND a.end_date >= ?  AND a.end_date <= ?   AND a.end_date < ? `
+		pars = append(pars, startDate, endDate, time.Now().Format(utils.FormatDate))
+
+		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.SellerNameLast
+				item.StartDate = v.StartDate
+				item.EndDate = v.EndDate
+				item.Money = v.Money
+				item.PermissionName = mappermissionName[v.CompanyContractId]
+				listResp = append(listResp, item)
+			}
+			listGroup, err = models.GetCompanyContractGroupList(condition, pars)
+			if err != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取失败,Err:" + err.Error()
+				return
+			}
+		}
+
+	case "续约合同":
+		if sellerId != "" {
+			condition += ` AND a.seller_id_last  IN (` + sellerId + `) `
+		}
+
+		condition += ` AND  a.status = 1  AND a.inherit_end_date >= ?  AND a.inherit_end_date <= ?  AND  a.inherit_company_contract_id > 0  AND a.rai_contract_type = '续约合同'  AND a.company_id NOT  IN (` + utils.GetOrmInReplace(lenArrCompany) + `)  `
+		pars = append(pars, startDate, endDate, companyIdsNew)
+
+		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.SellerNameLast
+				item.StartDate = v.StartDate
+				item.EndDate = v.EndDate
+				item.Money = v.Money
+				item.PermissionName = mappermissionName[v.CompanyContractId]
+				listResp = append(listResp, item)
+			}
+			listGroup, err = models.GetCompanyContractGroupList(condition, pars)
+			if err != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取失败,Err:" + err.Error()
+				return
+			}
+		}
+
+	case "续约率":
+		var conditionEnd string
+		var parsEnd []interface{}
+		if sellerId != "" {
+			condition += ` AND a.seller_id_last IN (` + sellerId + `) `
+
+			conditionEnd += ` AND a.seller_id_last  IN (` + sellerId + `) `
+		}
+
+		condition += ` AND  a.status = 1  AND a.inherit_end_date >= ?  AND a.inherit_end_date <= ?  AND  inherit_company_contract_id > 0    AND a.rai_contract_type = '续约合同' AND a.company_id NOT  IN (` + utils.GetOrmInReplace(lenArrCompany) + `)  `
+		pars = append(pars, startDate, endDate, companyIdsNew)
+		listRaiData, err := statistic_report.GetRaiDataSummaryList(condition, pars)
+		if err != nil {
+			br.Msg = "获取数据信息失败"
+			br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+			return
+		}
+
+		//到期合同数据
+		conditionEnd += ` AND  a.status = 1  AND a.end_date >= ?  AND a.end_date <= ?   AND a.end_date < ? `
+		parsEnd = append(parsEnd, startDate, endDate, time.Now().Format(utils.FormatDate))
+		listEndData, err := statistic_report.GetRaiDataSummaryList(conditionEnd, parsEnd)
+		if err != nil {
+			br.Msg = "获取数据信息失败"
+			br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+			return
+		}
+
+		var renewedContractMoney float64   // 续约金额
+		var renewedContractCompany float64 // 续约客户数
+		maprenewedContractCompany := make(map[int]bool)
+
+		var expiredContractMoney float64   //到期金额
+		var expiredContractCompany float64 // 到期客户数
+		mapexpiredContractCompany := make(map[int]bool)
+
+		for _, v := range listRaiData {
+			renewedContractMoney += v.Money
+			if !maprenewedContractCompany[v.CompanyId] {
+				renewedContractCompany++
+				maprenewedContractCompany[v.CompanyId] = true
+			}
+			//startDateTime := utils.StrDateToDate(v.StartDate)
+			//if startDateTime.Before(time.Now().AddDate(0, 0, -1)) { //到期合同数据
+			//	expiredContractMoney += v.Money
+			//	if !mapexpiredContractCompany[v.CompanyId] {
+			//		expiredContractCompany++
+			//		mapexpiredContractCompany[v.CompanyId] = true
+			//	}
+			//}
+		}
+
+		for _, v := range listEndData {
+			expiredContractMoney += v.Money
+			if !mapexpiredContractCompany[v.CompanyId] {
+				expiredContractCompany++
+				mapexpiredContractCompany[v.CompanyId] = true
+			}
+		}
+
+		item := new(statistic_report.RaiDataSummaryDetailResp)
+		item.TbaleNameAText = "金额续约率"
+		item.RenewedContractMoney = fmt.Sprint(utils.SubFloatToString(renewedContractMoney, 2))
+		item.ExpiredContractMoney = fmt.Sprint(utils.SubFloatToString(expiredContractMoney, 2))
+		if renewedContractMoney == 0 || expiredContractMoney == 0 {
+			item.RenewalRate = "0%"
+		} else {
+			item.RenewalRate = fmt.Sprint(utils.SubFloatToString(renewedContractMoney/expiredContractMoney*100, 2), "%")
+		}
+
+		listResp = append(listResp, item)
+
+		item2 := new(statistic_report.RaiDataSummaryDetailResp)
+		item2.TbaleNameAText = "客户续约率"
+		item2.RenewedContractMoney = fmt.Sprint(renewedContractCompany)
+		item2.ExpiredContractMoney = fmt.Sprint(expiredContractCompany)
+		if renewedContractCompany == 0 || expiredContractCompany == 0 {
+			item2.RenewalRate = "0%"
+		} else {
+			item2.RenewalRate = fmt.Sprint(utils.SubFloatToString(renewedContractCompany/expiredContractCompany*100, 2), "%")
+		}
+
+		listResp = append(listResp, item2)
+
+	case "确认不续约合同":
+		noRenewedcompanyContractIds := services.GetCompanyContractNoRenewedAscribeListArr()
+		condition += ` AND  a.company_contract_id IN (` + utils.GetOrmInReplace(len(noRenewedcompanyContractIds)) + `)  ` // 已确认
+		pars = append(pars, noRenewedcompanyContractIds)
+		if sellerId != "" {
+			condition += ` AND a.seller_id_last  IN (` + sellerId + `) `
+		}
+		condition += ` AND  a.product_id = 2  AND  a.status = 1  AND a.end_date >= ?  AND a.end_date <= ?  AND a.end_date <= ?  `
+		pars = append(pars, startDate, endDate, time.Now().Format(utils.FormatDate))
+
+		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)
+			}
+
+			listGroup, err = models.GetCompanyContractGroupList(condition, pars)
+			if err != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取失败,Err:" + err.Error()
+				return
+			}
+
+		}
+
+	case "确认不续约率":
+		noRenewedcompanyContractIdsMap := services.GetCompanyContractNoRenewedAscribeListMap()
+		var conditionEnd string
+		var parsEnd []interface{}
+		if sellerId != "" {
+			condition += ` AND a.seller_id_last  IN (` + sellerId + `) `
+
+			conditionEnd += ` AND a.seller_id_last  IN (` + sellerId + `) `
+		}
+
+		condition += ` AND  a.product_id = 2  AND  a.status = 1  AND  a.end_date >= ?  AND  a.end_date <= ? AND a.end_date <= ?  `
+		pars = append(pars, startDate, endDate, time.Now().Format(utils.FormatDate))
+		listRaiData, err := statistic_report.GetRaiDataSummaryList(condition, pars)
+		if err != nil {
+			br.Msg = "获取数据信息失败"
+			br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+			return
+		}
+
+		conditionEnd += `  AND  a.product_id = 2  AND  a.status = 1  AND a.end_date >= ?  AND a.end_date <= ?   AND a.end_date < ? `
+		parsEnd = append(parsEnd, startDate, endDate, time.Now().Format(utils.FormatDate))
+
+		listEndData, err := statistic_report.GetRaiDataSummaryList(conditionEnd, parsEnd)
+		if err != nil {
+			br.Msg = "获取数据信息失败"
+			br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+			return
+		}
+
+		var norenewedContractMoney float64   // 不续约金额
+		var norenewedContractCompany float64 // 不续约客户数
+		mapnorenewedContractCompany := make(map[int]bool)
+
+		var expiredContractMoney float64   //到期金额
+		var expiredContractCompany float64 // 到期客户数
+		mapexpiredContractCompany := make(map[int]bool)
+
+		for _, v := range listRaiData {
+			if noRenewedcompanyContractIdsMap[v.CompanyContractId] {
+				norenewedContractMoney += v.Money
+				if !mapnorenewedContractCompany[v.CompanyId] {
+					norenewedContractCompany++
+					mapnorenewedContractCompany[v.CompanyId] = true
+				}
+			}
+		}
+
+		for _, v := range listEndData {
+			expiredContractMoney += v.Money
+			if !mapexpiredContractCompany[v.CompanyId] {
+				expiredContractCompany++
+				mapexpiredContractCompany[v.CompanyId] = true
+			}
+		}
+
+		item := new(statistic_report.RaiDataSummaryDetailResp)
+		item.TbaleNameAText = "金额不续约率"
+		item.RenewedContractMoney = fmt.Sprint(utils.SubFloatToString(norenewedContractMoney, 2))
+		item.ExpiredContractMoney = fmt.Sprint(utils.SubFloatToString(expiredContractMoney, 2))
+		if norenewedContractMoney == 0 || expiredContractMoney == 0 {
+			item.RenewalRate = "0%"
+		} else {
+			item.RenewalRate = fmt.Sprint(utils.SubFloatToString(norenewedContractMoney/expiredContractMoney*100, 2), "%")
+		}
+		listResp = append(listResp, item)
+
+		item2 := new(statistic_report.RaiDataSummaryDetailResp)
+		item2.TbaleNameAText = "客户不续约率"
+		item2.RenewedContractMoney = fmt.Sprint(norenewedContractCompany)
+		item2.ExpiredContractMoney = fmt.Sprint(expiredContractCompany)
+		if norenewedContractCompany == 0 || expiredContractCompany == 0 {
+			item2.RenewalRate = "0%"
+		} else {
+			item2.RenewalRate = fmt.Sprint(utils.SubFloatToString(norenewedContractCompany/expiredContractCompany*100, 2), "%")
+		}
+		listResp = append(listResp, item2)
+
+	case "签约客户数量":
+		var conditionInherit string
+		var parsInherit []interface{}
+		if sellerId != "" {
+			condition += ` AND a.seller_id_last IN (` + sellerId + `) `
+
+			conditionInherit += ` AND a.seller_id_last  IN (` + sellerId + `) `
+		}
+		condition += " AND  a.product_id = 2  AND  a.status = 1  AND  a.start_date >= ?  AND  a.start_date <= ?  AND a.rai_contract_type = '新签合同' "
+		pars = append(pars, startDate, endDate)
+		listRaiData, err := statistic_report.GetRaiDataSummaryList(condition, pars)
+		if err != nil {
+			br.Msg = "获取数据信息失败"
+			br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+			return
+		}
+
+		//续约部分的数据
+		conditionInherit += ` AND  a.product_id = 2  AND  a.status = 1  AND  a.inherit_end_date >= ?  AND  a.inherit_end_date <= ? AND  a.inherit_company_contract_id > 0  AND a.rai_contract_type = '续约合同'  AND a.company_id NOT  IN (` + utils.GetOrmInReplace(lenArrCompany) + `)  `
+		parsInherit = append(parsInherit, startDate, endDate, companyIdsNew)
+		listInheritData, err := statistic_report.GetRaiDataSummaryInheritList(conditionInherit, parsInherit)
+		if err != nil {
+			br.Msg = "获取数据信息失败"
+			br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+			return
+		}
+
+		var renewedContractCompany int // 续约客户数
+		var renewedContract int        // 续约合同数
+		maprenewedContractCompany := make(map[int]bool)
+
+		var newContractCompany int // 新签客户数
+		var newContract int        // 新签合同数
+		mapenewContractCompany := make(map[int]bool)
+		for _, v := range listRaiData {
+			if v.RaiContractType == "新签合同" {
+				newContract++
+				if !mapenewContractCompany[v.CompanyId] {
+					newContractCompany++
+					mapenewContractCompany[v.CompanyId] = true
+				}
+			}
+			//else if v.RaiContractType == "续约合同" {
+			//	renewedContract++
+			//	if !maprenewedContractCompany[v.CompanyId] {
+			//		renewedContractCompany++
+			//		maprenewedContractCompany[v.CompanyId] = true
+			//	}
+			//}
+		}
+
+		for _, v := range listInheritData {
+			renewedContract++
+			if !maprenewedContractCompany[v.CompanyId] {
+				renewedContractCompany++
+				maprenewedContractCompany[v.CompanyId] = true
+			}
+
+		}
+
+		item := new(statistic_report.RaiDataSummaryDetailResp)
+		item.RenewedContractCompany = renewedContractCompany
+		item.RenewedContract = renewedContract
+		item.NewContractCompany = newContractCompany
+		item.NewContract = newContract
+		listResp = append(listResp, item)
+
+	case "客单价":
+		//续约部分的数据
+		var conditionInherit string
+		var parsInherit []interface{}
+		if sellerId != "" {
+			condition += ` AND a.seller_id_last  IN (` + sellerId + `) `
+			conditionInherit += ` AND a.seller_id_last  IN (` + sellerId + `) `
+		}
+		condition += " AND  a.product_id = 2  AND  a.status = 1  AND  a.start_date >= ?  AND  a.start_date <= ? AND a.rai_contract_type = '新签合同'  "
+		pars = append(pars, startDate, endDate)
+		listRaiData, err := statistic_report.GetRaiDataSummaryList(condition, pars)
+		if err != nil {
+			br.Msg = "获取数据信息失败"
+			br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+			return
+		}
+
+		var ontractMoney float64 // 签约总金额
+		var contractNum int      // 签约客户数
+		mapCompany := make(map[int]bool)
+
+		for _, v := range listRaiData {
+			if v.RaiContractType != "新签合同" {
+				continue
+			}
+			ontractMoney += v.Money
+			if !mapCompany[v.CompanyId] {
+				contractNum++
+				mapCompany[v.CompanyId] = true
+			}
+		}
+		conditionInherit += ` AND  a.product_id = 2  AND  a.status = 1  AND  a.inherit_end_date >= ?  AND  a.inherit_end_date <= ?  AND a.rai_contract_type = '续约合同'   AND a.company_id NOT  IN (` + utils.GetOrmInReplace(lenArrCompany) + `)  `
+		parsInherit = append(parsInherit, startDate, endDate, companyIdsNew)
+		listInheritData, err := statistic_report.GetRaiDataSummaryInheritList(conditionInherit, parsInherit)
+		if err != nil {
+			br.Msg = "获取数据信息失败"
+			br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+			return
+		}
+
+		for _, v := range listInheritData {
+			ontractMoney += v.Money
+			if !mapCompany[v.CompanyId] && v.RaiContractType == "续约合同" {
+				contractNum++
+				mapCompany[v.CompanyId] = true
+			}
+		}
+
+		item := new(statistic_report.RaiDataSummaryDetailResp)
+		item.ContractMoney = fmt.Sprint(utils.SubFloatToString(ontractMoney, 2))
+		item.ContractNum = contractNum
+		listResp = append(listResp, item)
+
+	case "开票金额":
+		if sellerId != "" {
+			condition += ` AND a.rai_seller_id  IN (` + sellerId + `) `
+		}
+		condition += " AND  a.is_deleted = 0    AND  a.start_date >= ?  AND  a.start_date <= ?  AND  invoiced_amount > 0   AND product_ids LIKE '%2%' "
+		pars = append(pars, startDate, endDate)
+		listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
+		if err != nil {
+			br.Msg = "获取数据信息失败"
+			br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+			return
+		}
+		if len(listFmsData) > 0 {
+			var contractRegisterId []int
+			for _, v := range listFmsData {
+				contractRegisterId = append(contractRegisterId, v.ContractRegisterId)
+			}
+			lenArr := len(contractRegisterId)
+			var conditionFms string
+			var parsFms []interface{}
+			conditionFms += ` AND  contract_register_id IN  (` + utils.GetOrmInReplace(lenArr) + `)  GROUP BY contract_register_id  `
+			parsFms = append(parsFms, contractRegisterId)
+			listInvoiceData, err := fms.GetContractInvoiceList(conditionFms, parsFms, 0, lenArr)
+			if err != nil {
+				br.Msg = "获取数据信息失败"
+				br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+				return
+			}
+
+			mapInvoiceTime := make(map[int]string)
+			for _, v := range listInvoiceData {
+				mapInvoiceTime[v.ContractRegisterId] = v.InvoiceTime.Format(utils.FormatDate)
+			}
+
+			for _, v := range listFmsData {
+				item := new(statistic_report.RaiDataSummaryDetailResp)
+				item.CompanyName = v.CompanyName
+				item.SellerName = v.RaiSellerName
+				item.ContractCode = v.ContractCode
+				item.InvoicedAmount = v.InvoicedAmount
+				item.CreateTime = mapInvoiceTime[v.ContractRegisterId]
+				listResp = append(listResp, item)
+			}
+		}
+
+	case "到款金额":
+		if sellerId != "" {
+			condition += ` AND a.rai_seller_id  IN (` + sellerId + `) `
+		}
+		condition += " AND  a.is_deleted = 0    AND  a.start_date >= ?  AND  a.start_date <= ?  AND  payment_amount > 0   AND product_ids LIKE '%2%' "
+		pars = append(pars, startDate, endDate)
+		listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
+		if err != nil {
+			br.Msg = "获取数据信息失败"
+			br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+			return
+		}
+
+		if len(listFmsData) > 0 {
+			var contractRegisterId []int
+			for _, v := range listFmsData {
+				contractRegisterId = append(contractRegisterId, v.ContractRegisterId)
+			}
+			lenArr := len(contractRegisterId)
+			var conditionFms string
+			var parsFms []interface{}
+			conditionFms += ` AND  contract_register_id IN  (` + utils.GetOrmInReplace(lenArr) + `)  GROUP BY contract_register_id  `
+			parsFms = append(parsFms, contractRegisterId)
+			listInvoiceData, err := fms.GetContractInvoiceList(conditionFms, parsFms, 0, lenArr)
+			if err != nil {
+				br.Msg = "获取数据信息失败"
+				br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+				return
+			}
+
+			mapInvoiceTime := make(map[int]string)
+			for _, v := range listInvoiceData {
+				mapInvoiceTime[v.ContractRegisterId] = v.InvoiceTime.Format(utils.FormatDate)
+			}
+
+			for _, v := range listFmsData {
+				item := new(statistic_report.RaiDataSummaryDetailResp)
+				item.CompanyName = v.CompanyName
+				item.SellerName = v.RaiSellerName
+				item.ContractCode = v.ContractCode
+				item.PaymentAmount = v.PaymentAmount
+				item.CreateTime = v.CreateTime.Format(utils.FormatDate)
+				listResp = append(listResp, item)
+			}
+		}
+
+	case "未到款比例":
+		if sellerId != "" {
+			condition += ` AND a.rai_seller_id  IN (` + sellerId + `) `
+		}
+		condition += " AND  a.is_deleted = 0   AND  a.start_date >= ?  AND  a.start_date <= ?    AND product_ids LIKE '%2%' "
+		pars = append(pars, startDate, endDate)
+		listFmsData, err := fms.GetContractRegisterAmountList(condition, pars)
+		if err != nil {
+			br.Msg = "获取数据信息失败"
+			br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+			return
+		}
+
+		for _, v := range listFmsData {
+			item := new(statistic_report.RaiDataSummaryDetailResp)
+			item.InvoicedAmount = v.InvoicedAmount
+			item.PaymentAmount = v.PaymentAmount
+			item.NotReceivedtAmount = v.InvoicedAmount - v.PaymentAmount
+			item.CreateTime = v.CreateTime.Format(utils.FormatDate)
+			listResp = append(listResp, item)
+		}
+
+	case "新客开票":
+		if sellerId != "" {
+			condition += ` AND a.rai_seller_id  IN (` + sellerId + `) `
+		}
+		condition += " AND  a.is_deleted = 0  AND contract_type = 1   AND  a.start_date >= ?  AND  a.start_date <= ?   AND product_ids LIKE '%2%' "
+		pars = append(pars, startDate, endDate)
+		listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
+		if err != nil {
+			br.Msg = "获取数据信息失败"
+			br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+			return
+		}
+		if len(listFmsData) > 0 {
+			var contractRegisterId []int
+			for _, v := range listFmsData {
+				contractRegisterId = append(contractRegisterId, v.ContractRegisterId)
+			}
+			lenArr := len(contractRegisterId)
+			var conditionFms string
+			var parsFms []interface{}
+			conditionFms += ` AND  contract_register_id IN  (` + utils.GetOrmInReplace(lenArr) + `)  GROUP BY contract_register_id  `
+			parsFms = append(parsFms, contractRegisterId)
+			listInvoiceData, err := fms.GetContractInvoiceList(conditionFms, parsFms, 0, lenArr)
+			if err != nil {
+				br.Msg = "获取数据信息失败"
+				br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+				return
+			}
+
+			mapInvoiceTime := make(map[int]string)
+			for _, v := range listInvoiceData {
+				mapInvoiceTime[v.ContractRegisterId] = v.InvoiceTime.Format(utils.FormatDate)
+			}
+
+			for _, v := range listFmsData {
+				item := new(statistic_report.RaiDataSummaryDetailResp)
+				item.CompanyName = v.CompanyName
+				item.SellerName = v.RaiSellerName
+				item.ContractCode = v.ContractCode
+				item.InvoicedAmount = v.InvoicedAmount
+				item.CreateTime = mapInvoiceTime[v.ContractRegisterId]
+				listResp = append(listResp, item)
+			}
+		}
+
+	case "新客到款":
+		if sellerId != "" {
+			condition += ` AND a.rai_seller_id  IN (` + sellerId + `) `
+		}
+		condition += " AND  a.is_deleted = 0    AND contract_type = 1   AND  a.start_date >= ?  AND  a.start_date <= ?  AND  payment_amount > 0   AND product_ids LIKE '%2%' "
+		pars = append(pars, startDate, endDate)
+		listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
+		if err != nil {
+			br.Msg = "获取数据信息失败"
+			br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+			return
+		}
+		if len(listFmsData) > 0 {
+			var contractRegisterId []int
+			for _, v := range listFmsData {
+				contractRegisterId = append(contractRegisterId, v.ContractRegisterId)
+			}
+			lenArr := len(contractRegisterId)
+			var conditionFms string
+			var parsFms []interface{}
+			conditionFms += ` AND  contract_register_id IN  (` + utils.GetOrmInReplace(lenArr) + `)  GROUP BY contract_register_id  `
+			parsFms = append(parsFms, contractRegisterId)
+			listInvoiceData, err := fms.GetContractInvoiceList(conditionFms, parsFms, 0, lenArr)
+			if err != nil {
+				br.Msg = "获取数据信息失败"
+				br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+				return
+			}
+
+			mapInvoiceTime := make(map[int]string)
+			for _, v := range listInvoiceData {
+				mapInvoiceTime[v.ContractRegisterId] = v.InvoiceTime.Format(utils.FormatDate)
+			}
+
+			for _, v := range listFmsData {
+				item := new(statistic_report.RaiDataSummaryDetailResp)
+				item.CompanyName = v.CompanyName
+				item.SellerName = v.RaiSellerName
+				item.ContractCode = v.ContractCode
+				item.PaymentAmount = v.PaymentAmount
+				item.CreateTime = mapInvoiceTime[v.ContractRegisterId]
+				listResp = append(listResp, item)
+			}
+		}
+
+	}
+
+	if len(listResp) == 0 {
+		listResp = make([]*statistic_report.RaiDataSummaryDetailResp, 0)
+	}
+	if len(listGroup) > 0 {
+		for _, v := range listGroup {
+			if v.CompanyCount > 1 {
+				resp.CompanyMultiple++
+			}
+		}
+		resp.CompanyNum = len(listGroup)
+	}
+	resp.List = listResp
+	page := paging.GetPaging(currentIndex, pageSize, trialTotal)
+	resp.Paging = page
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 8 - 0
models/company/company_contract.go

@@ -484,3 +484,11 @@ func UpdateCompanyContracthide(companyContractId []string) (err error) {
 	_, err = o.Raw(sql).Exec()
 	return
 }
+
+// 更新合同类型
+func UpdateCompanyContractInheritEndDate(inheritEndDate string, inheritCompanyContracId, companyContractId int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE company_contract SET inherit_end_date = ? , inherit_company_contract_id = ?   WHERE company_contract_id=? `
+	_, err = o.Raw(sql, inheritEndDate, inheritCompanyContracId, companyContractId).Exec()
+	return
+}

+ 6 - 0
models/company/company_seller.go

@@ -29,6 +29,12 @@ type DepartmentGroupSellersResp struct {
 	List []DepartmentGroupSellers
 }
 
+// DepartmentGroupSellersResp 销售列表(根据部门、分组来)
+type DepartmentGroupSellersServerResp struct {
+	List       []DepartmentGroupSellers
+	ListServer []DepartmentGroupSellers //服务组销售
+}
+
 type DepartmentGroupSellers struct {
 	AdminId string `description:"系统用户id"`
 	//AdminName string `description:"系统用户名称"`

+ 1 - 0
models/fms/contract_invoice.go

@@ -16,6 +16,7 @@ type ContractInvoice struct {
 	CurrencyUnit       string    `gorm:"column:currency_unit" json:"currency_unit" description:"货币国际代码"`
 	InvoiceType        int       `gorm:"column:invoice_type" json:"invoice_type" description:"类型: 1-开票登记; 2-到款登记"`
 	InvoiceDate        time.Time `gorm:"column:invoice_time" json:"invoice_time" description:"开票日期/到款月"`
+	InvoiceTime        time.Time `description:"开票日期/到款月"`
 	SellerId           int       `gorm:"column:seller_id" json:"seller_id" description:"销售ID"`
 	SellerName         string    `gorm:"column:seller_name" json:"seller_name" description:"销售名称"`
 	SellerGroupId      int       `gorm:"column:seller_group_id" json:"seller_group_id" description:"销售分组ID"`

+ 61 - 14
models/fms/invoice_payment_summary.go

@@ -17,13 +17,11 @@ type InvoicePaymentSummary struct {
 	ModifyTime       time.Time `gorm:"autoUpdateTime:milli;column:modify_time" json:"modify_time" description:"最后更新时间"`
 }
 
-
 type ContractRegisterSummary struct {
 	SummaryId int `json:"summary_id" description:"汇总ID"`
 	ContractRegister
 }
 
-
 // GetInvoicePaymentCensusPageList 获取商品到款统计列表-总数
 func GetInvoicePaymentCensusPageList(condition string, pars []interface{}, order string, startSize, pageSize int) (results []*ContractRegisterSummary, total int64, err error) {
 	o := orm.NewOrmUsingDB("fms")
@@ -35,7 +33,7 @@ func GetInvoicePaymentCensusPageList(condition string, pars []interface{}, order
 	if condition != "" {
 		sql += condition
 	}
-	totalSQl := `SELECT COUNT(1) total FROM (`+sql+`) as a`
+	totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) as a`
 	if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
 		return
 	}
@@ -81,14 +79,14 @@ func GetInvoicePaymentCensusSummaryData(condition string, pars []interface{}) (r
 		"IF(c.seller_group_name = '' OR c.seller_group_name IS NULL, d.seller_group_name, c.seller_group_name) AS seller_group_name", "d.origin_amount AS payment_amount", "d.invoice_time AS payment_date", "d.pay_type",
 	}
 	o := orm.NewOrmUsingDB("fms")
-	sql := `SELECT `+strings.Join(fields, ",")+ ` FROM invoice_payment_summary AS a 
+	sql := `SELECT ` + strings.Join(fields, ",") + ` FROM invoice_payment_summary AS a 
 			JOIN contract_register AS b ON a.register_id = b.contract_register_id AND b.is_deleted = 0
 			LEFT JOIN contract_invoice AS c ON a.invoice_id = c.contract_invoice_id AND c.is_deleted = 0
 			LEFT JOIN contract_invoice AS d ON a.payment_id = d.contract_invoice_id AND d.is_deleted = 0
 	WHERE `
 	sql += condition
 
-	_,err = o.Raw(sql, pars).QueryRows(&results)
+	_, err = o.Raw(sql, pars).QueryRows(&results)
 
 	return
 }
@@ -102,8 +100,7 @@ func GetInvoicePaymentCensusSummaryDataIds(condition string, pars []interface{})
 			LEFT JOIN contract_invoice AS d ON a.payment_id = d.contract_invoice_id AND d.is_deleted = 0
 	WHERE `
 	sql += condition
-	_,err = o.Raw(sql, pars).QueryRows(&summaryIds)
-
+	_, err = o.Raw(sql, pars).QueryRows(&summaryIds)
 
 	return
 }
@@ -115,7 +112,7 @@ func GetContractSummaryInvoicePaymentAmountTotal(condition string, pars []interf
 		joinCond = `a.payment_id = b.contract_invoice_id`
 	}
 	o := orm.NewOrmUsingDB("fms")
-	sql := `SELECT IFNULL(SUM(b.amount),0) FROM invoice_payment_summary AS a JOIN contract_invoice AS b ON `+ joinCond+` AND b.is_deleted = 0 WHERE `
+	sql := `SELECT IFNULL(SUM(b.amount),0) FROM invoice_payment_summary AS a JOIN contract_invoice AS b ON ` + joinCond + ` AND b.is_deleted = 0 WHERE `
 	sql += condition
 	err = o.Raw(sql, pars).QueryRow(&amountTotal)
 
@@ -131,27 +128,25 @@ func GetSummaryListCurrencySum(condition string, pars []interface{}, amountType
 
 	o := orm.NewOrmUsingDB("fms")
 	sql := `SELECT b.currency_unit, b.invoice_type, SUM(b.amount) AS amount_total, SUM(b.origin_amount) AS origin_amount_total
-			FROM invoice_payment_summary AS a JOIN contract_invoice AS b ON `+ joinCond+` AND b.is_deleted = 0 WHERE `
+			FROM invoice_payment_summary AS a JOIN contract_invoice AS b ON ` + joinCond + ` AND b.is_deleted = 0 WHERE `
 	sql += condition
 
 	sql += ` GROUP BY b.currency_unit `
-	_,err = o.Raw(sql, pars).QueryRows(&results)
+	_, err = o.Raw(sql, pars).QueryRows(&results)
 
 	return
 }
 
-
 // GetContractSummaryInvoicePaymentAmount 获取汇总金额合计信息
 func GetContractSummaryInvoicePaymentAmount(condition string, pars []interface{}) (amountTotal float64, err error) {
 	joinCond := ` (a.invoice_id = b.contract_invoice_id OR a.payment_id = b.contract_invoice_id) `
 
 	o := orm.NewOrmUsingDB("fms")
-	sql := `SELECT b.amount FROM invoice_payment_summary AS a JOIN contract_invoice AS b ON `+ joinCond+` AND b.is_deleted = 0 WHERE `
+	sql := `SELECT b.amount FROM invoice_payment_summary AS a JOIN contract_invoice AS b ON ` + joinCond + ` AND b.is_deleted = 0 WHERE `
 	sql += condition
 	sql += ` GROUP BY id `
 
-	nsql := `SELECT IFNULL( SUM( e.amount ), 0 ) FROM (`+sql+`) as e`
-
+	nsql := `SELECT IFNULL( SUM( e.amount ), 0 ) FROM (` + sql + `) as e`
 
 	err = o.Raw(nsql, pars).QueryRow(&amountTotal)
 
@@ -165,3 +160,55 @@ type InvoiceSummary struct {
 	ContractRegister
 }
 
+// GetContractRegisterListByStartDate  根据起始日期的时间段筛选合同登记信息。
+func GetContractRegisterListByStartDate(startDate, endDate string) (results []*ContractRegisterSummary, err error) {
+	o := orm.NewOrmUsingDB("fms")
+	sql := ` SELECT  * FROM contract_register  WHERE start_date > ?  AND start_date <  ?   AND is_deleted = 0  AND product_ids LIKE '%2%'  `
+	_, err = o.Raw(sql, startDate, endDate).QueryRows(&results)
+	return
+}
+
+// 列表
+func GetContractRegisterList(condition string, pars []interface{}, startSize, pageSize int) (items []*ContractRegisterSummary, err error) {
+	o := orm.NewOrmUsingDB("fms")
+	sql := `SELECT * FROM contract_register  as a  WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	if startSize+pageSize > 0 {
+		sql += ` LIMIT ?,?  `
+		_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	} else {
+		_, err = o.Raw(sql, pars).QueryRows(&items)
+	}
+	return
+}
+
+// 获取开票金额与未到账金额的统计
+func GetContractRegisterAmountList(condition string, pars []interface{}) (items []*ContractRegisterSummary, err error) {
+	o := orm.NewOrmUsingDB("fms")
+	sql := `SELECT
+			SUM( invoiced_amount ) AS invoiced_amount,
+			SUM( payment_amount ) AS payment_amount FROM contract_register  as a  WHERE 1= 1  `
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
+// 列表
+func GetContractInvoiceList(condition string, pars []interface{}, startSize, pageSize int) (items []*ContractInvoice, err error) {
+	o := orm.NewOrmUsingDB("fms")
+	sql := `SELECT * FROM contract_invoice  as a  WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	if startSize+pageSize > 0 {
+		sql += ` LIMIT ?,?  `
+		_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	} else {
+		_, err = o.Raw(sql, pars).QueryRows(&items)
+	}
+	return
+}

+ 24 - 1
models/statistic_report.go

@@ -415,6 +415,7 @@ type IncrementalList struct {
 	SellerIdLast    int    `description:"合同到期之前最后所属销售ID"`
 	ShareSellerInit string `description:"共享销售员"`
 	SysRealName     string `description:"操作者名称"`
+	SysUserId       string `description:"操作者Id"`
 	Operation       string `description:"操作"`
 }
 
@@ -845,7 +846,7 @@ func GetIncrementalCompanyListByOperationRecordRai(condition string, pars []inte
 	sql1 += ` GROUP BY a.id `
 
 	//查询真正的数据
-	sql := `SELECT a.id, a.company_id, b.company_name, c.seller_id, c.seller_name, c.seller_name_init, a.product_id, a.product_name, a.create_time, b.region_type, c.renewal_reason, c.renewal_todo, c.status , a.sys_real_name, a.operation FROM company_operation_record a
+	sql := `SELECT a.id, a.company_id, b.company_name, c.seller_id, c.seller_name, c.seller_name_init, a.product_id, a.product_name, a.create_time, b.region_type, c.renewal_reason, c.renewal_todo, c.status , a.sys_real_name, a.operation ,a.sys_user_id  FROM company_operation_record a
 		RIGHT JOIN company b ON a.company_id = b.company_id
 		JOIN company_product c ON b.company_id = c.company_id 
 		AND a.product_id = c.product_id
@@ -955,6 +956,28 @@ func GetIncrementalCompanyMergeList(condition string, pars []interface{}, startS
 	return
 }
 
+// 增量客户统计报表列表数据结构
+type CompanyContractGroupList struct {
+	CompanyId    int `description:"企业客户id"`
+	CompanyCount int `description:"合同数"`
+}
+
+// GetIncrementalNewCompanyList 获取增量客户报表列表数据(根据合同来展示)
+func GetCompanyContractGroupList(condition string, pars []interface{}) (items []*CompanyContractGroupList, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			company_id,
+			COUNT( company_id )  company_count 
+		FROM
+			company_contract AS a  WHERE  product_id = 2  `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` GROUP BY company_id `
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
 // GetIncrementalNewCompanyList 获取到期合同列表数据(根据合同来展示)
 func GetIncrementalCompanyMergeListEnd(condition string, pars []interface{}, startSize, pageSize int) (items []*IncrementalList, err error) {
 	o := orm.NewOrm()

+ 182 - 0
models/statistic_report/rai_data_summary.go

@@ -0,0 +1,182 @@
+package statistic_report
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"github.com/rdlucklib/rdluck_tools/paging"
+	"hongze/hz_crm_api/models/company"
+)
+
+// 时间区间数据结构
+type DateInterval struct {
+	StartDate string `description:"合同开始日期"`
+	EndDate   string `description:"合同结束日期"`
+}
+
+type RaiDataSummaryListResp struct {
+	List []*RaiDataSummaryResp
+}
+
+type RaiDataSummaryResp struct {
+	DataType string `description:"时间区间"`
+	DataList []*RaiDataSummaryDetail
+}
+
+type RaiDataSummaryDetail struct {
+	SellerId                         string `description:"销售id"`
+	SellerName                       string `description:"销售名称"`
+	AddTrialCount                    string `description:"新增试用"`
+	NewContractData                  string `description:"新签合同(金额/数量)"`
+	ExpiredContractData              string `description:"到期合同(金额/数量)"`
+	RenewedContractData              string `description:"续约合同(金额/数量)"`
+	RenewalRateData                  string `description:"续约率(金额/数量)"`
+	ConfirmedNoRenewalContractData   string `description:"确认不续约合同(金额/数量)"`
+	ConfirmNonRenewalRateData        string `description:"确认不续约率(金额/数量)"`
+	SignedClientCount                string `description:"签约客户数量"`
+	AverageRevenueCount              string `description:"客单价"`
+	InvoiceAmountCount               string `description:"开票金额"`
+	PaymentReceivedCount             string `description:"到款金额"`
+	UnpaidRatioCount                 string `description:"未到款比例"`
+	NewCustomerInvoicingCount        string `description:"新客开票"`
+	NewCustomerPaymentsReceivedCount string `description:"新客到款"`
+}
+
+// 增量客户统计报表列表数据结构
+type IncrementalList struct {
+	CompanyContractId    int                                `description:"合同id"`
+	ContractType         string                             `description:"合同类型"`
+	CompanyId            int                                `description:"企业客户id"`
+	CompanyName          string                             `description:"企业客户名称"`
+	ProductId            int                                `description:"产品id"`
+	ProductName          string                             `description:"产品名称"`
+	ProductStatus        string                             `description:"产品名称"`
+	CompanyProductId     int                                `description:"客户购买产品授权id"`
+	ContractCode         string                             `description:"合同编码"`
+	StartDate            string                             `description:"合同开始日期"`
+	EndDate              string                             `description:"合同结束日期"`
+	Money                float64                            `description:"合同金额"`
+	PayMethod            string                             `description:"付款方式"`
+	PayChannel           string                             `description:"付款渠道"`
+	ImgUrl               string                             `description:"合同图片"`
+	CreateTime           string                             `description:"合同创建时间"`
+	ModifyTime           string                             `description:"合同修改时间"`
+	Status               string                             `description:"合同审批状态,0:待审批,1:已审批;默认:1"`
+	RegionType           string                             `description:"企业客户所属区域;可选范围:国内,海外"`
+	SellerId             int                                `description:"归属销售id"`
+	SellerName           string                             `description:"归属销售名称"`
+	SellerNameLast       string                             `description:"合同到期之前最后所属归属销售名称"`
+	ShareSeller          string                             `description:"合同到期之前最后所属共享销售员"`
+	ShareSellerLast      string                             `description:"共享销售员"`
+	ExpireDay            string                             `description:"剩余可用天数"`
+	PermissionList       []*company.CompanyReportPermission `description:"产品权限"`
+	Count                int                                `json:"-" description:"合同数"`
+	RenewalReason        string                             `description:"未续约说明"`
+	RenewalTodo          string                             `description:"未续约说明中的待办事项说明"`
+	PackageDifference    string                             `description:"和上一份合同的区别"`
+	AscribeContent       string                             `description:"归因标签说明"`
+	IsShowNoRenewedNote  bool                               `description:"是否展示未续约备注按钮"`
+	Content              string                             `description:"归因内容说明"`
+	PermissionName       string                             `description:"权限名"`
+	PermissionNameExport string                             `description:"权限名导出时使用"`
+	PermissionNameStatus string                             `description:"权限状态"`
+	CompanyProductStatus string                             `description:"客户状态"`
+	//CompanyContractIdGroup string                             `description:"表company_contract合并的 company_contract_id"`
+	IsUserMaker     int    `description:"近四周之内是否包含决策人互动过 ,0否,1是"`
+	SellerNameInit  string `description:"权益初始化销售"`
+	SellerIdInit    int    `description:"权益初始化销售ID"`
+	SellerIdLast    int    `description:"合同到期之前最后所属销售ID"`
+	ShareSellerInit string `description:"共享销售员"`
+	SysRealName     string `description:"操作者名称"`
+	Operation       string `description:"操作"`
+	RaiContractType string `description:"权益合同类型:枚举值:'新签合同','续约合同','补充协议'"`
+	InheritEndDate  string `description:"所继承上一份合同的结束日期,权益自定义续约合同统计使用"`
+}
+
+// GetRaiDataSummaryList 获取增量客户报表列表数据(根据合同来展示)
+func GetRaiDataSummaryList(condition string, pars []interface{}) (items []*IncrementalList, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT a.start_date,
+			   a.end_date,
+			   a.company_contract_id,
+			   a.money,
+			   a.company_id,
+			   a.rai_contract_type,
+			   a.seller_id_init,
+			   a.seller_name_init,
+			   a.share_seller_init,
+			   a.share_seller_id_init,
+			   a.seller_id_last,
+			   a.seller_name_last, 
+			   a.share_seller_last,
+			   a.share_seller_id_last
+       FROM company_contract a
+	   JOIN company b ON a.company_id = b.company_id
+	   JOIN company_product c ON a.company_id = c.company_id and a.product_id=c.product_id WHERE 1 = 1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` group by a.company_contract_id  order by a.start_date desc,a.company_id desc `
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
+// GetRaiDataSummaryList 获取增量客户报表列表数据(根据合同来展示)
+func GetRaiDataSummaryInheritList(condition string, pars []interface{}) (items []*IncrementalList, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT a.start_date,
+			   a.end_date,
+			   a.inherit_end_date,
+			   a.company_contract_id,
+			   a.money,
+		       a.company_id,
+			   a.rai_contract_type,
+			   a.seller_id_init,
+			   a.seller_name_init,
+			   a.share_seller_init,
+			   a.share_seller_id_init,
+			   a.seller_id_last,
+			   a.seller_name_last, 
+			   a.share_seller_last,
+			   a.share_seller_id_last
+       FROM company_contract a
+	   JOIN company b ON a.company_id = b.company_id
+	   JOIN company_product c ON a.company_id = c.company_id and a.product_id=c.product_id WHERE 1 = 1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` group by a.company_contract_id  order by a.start_date desc,a.company_id desc `
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
+type RaiDataSummaryPopupTypeResp struct {
+	CompanyNum      int                         `description:"企业客户数量"`
+	CompanyMultiple int                         `description:"户有多份合同的企业客户数量"`
+	Paging          *paging.PagingItem          `description:"分页数据"`
+	List            []*RaiDataSummaryDetailResp `description:"列表"`
+}
+
+// 增量客户统计报表列表数据结构
+type RaiDataSummaryDetailResp struct {
+	CompanyName            string  `description:"企业客户名称"`
+	SellerName             string  `description:"归属销售名称"`
+	AddType                string  `description:"新增类型"`
+	CreateTime             string  `description:"创建时间"`
+	StartDate              string  `description:"合同开始日期"`
+	EndDate                string  `description:"合同结束日期"`
+	Money                  float64 `description:"合同金额"`
+	PermissionName         string  `description:"权限名"`
+	RenewedContractMoney   string  `description:"续约金额"`
+	ExpiredContractMoney   string  `description:"到期金额"`
+	RenewalRate            string  `description:"续约率"`
+	RenewedContractCompany int     `description:"续约客户数"`
+	RenewedContract        int     `description:"续约合同数"`
+	NewContractCompany     int     `description:"新签客户数"`
+	NewContract            int     `description:"新签合同数"`
+	ContractMoney          string  `description:"签约总金额"`
+	ContractNum            int     `description:"签约客户数"`
+	ContractCode           string  `description:"合同编号"`
+	InvoicedAmount         float64 ` description:"开票金额"`
+	PaymentAmount          float64 ` description:"到款金额"`
+	NotReceivedtAmount     float64 ` description:"未到账金额"`
+	TbaleNameAText         string  ` description:"表格A列占位符"` //配合前端渲染使用,没有啥实际意义
+}

+ 27 - 0
routers/commentsRouter.go

@@ -8134,6 +8134,24 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/statistic:StatisticRaiDataSummaryController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/statistic:StatisticRaiDataSummaryController"],
+        beego.ControllerComments{
+            Method: "RaiDataSummaryDetail",
+            Router: `/rai_data_summary/detail`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/statistic:StatisticRaiDataSummaryController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/statistic:StatisticRaiDataSummaryController"],
+        beego.ControllerComments{
+            Method: "RaiDataSummaryList",
+            Router: `/rai_data_summary/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/yb:ActivityController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/yb:ActivityController"],
         beego.ControllerComments{
             Method: "Add",
@@ -10204,6 +10222,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:CompanySellerController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:CompanySellerController"],
+        beego.ControllerComments{
+            Method: "CheckListRaiServerType",
+            Router: `/seller/check/list_rai/server_type`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:CompanySellerController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:CompanySellerController"],
         beego.ControllerComments{
             Method: "CheckListForLose",

+ 2 - 0
routers/router.go

@@ -27,6 +27,7 @@ import (
 	"hongze/hz_crm_api/controllers/overseas_custom"
 	"hongze/hz_crm_api/controllers/roadshow"
 	"hongze/hz_crm_api/controllers/seal"
+	"hongze/hz_crm_api/controllers/statistic"
 	"hongze/hz_crm_api/controllers/yb"
 
 	"github.com/beego/beego/v2/server/web"
@@ -72,6 +73,7 @@ func init() {
 				&controllers.StatisticYbLogController{},
 				&controllers.StatisticReportCommonController{},
 				&controllers.StatisticCompanyMergerController{},
+				&statistic.StatisticRaiDataSummaryController{},
 			),
 		),
 		web.NSNamespace("/voice",

+ 52 - 0
services/company_ascribe.go

@@ -98,3 +98,55 @@ func GetCompanyContractAscribeContentMap(companyContractIds []int) (mapResp map[
 	}
 	return
 }
+
+// 获取不续约的合同ID的map映射
+func GetCompanyContractNoRenewedAscribeListMap() (mapCountResp map[int]bool) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println("err:", err)
+			go alarm_msg.SendAlarmMsg(" 处理公司归因展示失败 GetCompanyContractAscribeContentMap,Err:"+err.Error(), 3)
+		}
+	}()
+	var condition string
+	var pars []interface{}
+	condition = ` AND company_ascribe_id != 9 `
+	list, e := company.GetCompanyContractNoRenewedAscribeList(condition, pars, 0, 0)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetCompanyContractNoRenewedAscribeList, Err: " + e.Error())
+		return
+	}
+	mapCountResp = make(map[int]bool, 0)
+	for _, v := range list {
+		mapCountResp[v.CompanyContractId] = true
+	}
+	return
+}
+
+// 获取不续约的合同ID的数组
+func GetCompanyContractNoRenewedAscribeListArr() (companyContractIds []int) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println("err:", err)
+			go alarm_msg.SendAlarmMsg(" 处理公司归因展示失败 GetCompanyContractNoRenewedAscribeListArr,Err:"+err.Error(), 3)
+		}
+	}()
+	var condition string
+	var pars []interface{}
+	condition = ` AND company_ascribe_id != 9 `
+	list, e := company.GetCompanyContractNoRenewedAscribeList(condition, pars, 0, 0)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetCompanyContractNoRenewedAscribeList, Err: " + e.Error())
+		return
+	}
+	companyContractIds = make([]int, 0)
+	if len(list) == 0 {
+		companyContractIds = append(companyContractIds, 0)
+	} else {
+		for _, v := range list {
+			companyContractIds = append(companyContractIds, v.CompanyContractId)
+		}
+	}
+	return
+}

+ 61 - 0
services/company_contract.go

@@ -588,3 +588,64 @@ func UpdateCompanyContracthideBycompanyId(companyId, productId int) {
 
 	return
 }
+
+func init_CRM_16_7() {
+	var condition string
+	var pars []interface{}
+	condition = "  AND  product_id = 2 AND status != 2  ORDER BY start_date ASC   "
+	companyContractList, e := company.GetCompanyContractList(condition, pars)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		fmt.Println(e)
+		return
+	}
+	for k, v := range companyContractList {
+		fmt.Println(k)
+		UpdateCompanyContractInheritEndDate(v.CompanyContractId)
+		time.Sleep(100 * time.Millisecond)
+	}
+	fmt.Println("init_CRM_16_7end")
+}
+
+//func init() {
+//	//UpdateCompanyContractInheritEndDate(211)
+//	init_CRM_16_7()
+//}
+
+// 判断权益合同,是否续约了上一份的合同,并修改对应续约信息
+func UpdateCompanyContractInheritEndDate(companyContractId int) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go alarm_msg.SendAlarmMsg(fmt.Sprint("判断权益合同,是否续约了上一份的合同,并修改对应续约信息失败,UpdateCompanyContractInheritEndDate ", err), 3)
+		}
+	}()
+	contractInfo, e := company.GetCompanyContractDetailByCompanyContractId(companyContractId)
+	if e != nil {
+		err = errors.New("GetCompanyContractDetailByCompanyContractId, Err: " + e.Error())
+		return
+	}
+	startDate := contractInfo.StartDate
+
+	var condition string
+	var pars []interface{}
+	condition = "  AND  product_id = 2 AND status != 2  AND company_id = ? AND end_date <= ? AND DATE_ADD( end_date, INTERVAL 1 YEAR ) >= ?  ORDER BY start_date ASC  LIMIT	 1  "
+	pars = append(pars, contractInfo.CompanyId, startDate, startDate)
+	companyContractList, e := company.GetCompanyContractList(condition, pars)
+	if e != nil {
+		err = errors.New("GetCompanyContractList, Err: " + e.Error())
+		return
+	}
+
+	if len(companyContractList) == 1 {
+		for _, v := range companyContractList {
+			e = company.UpdateCompanyContractInheritEndDate(v.EndDate, v.CompanyContractId, contractInfo.CompanyContractId)
+			if e != nil {
+				err = errors.New("UpdateCompanyContractInheritEndDate, Err: " + e.Error())
+				return
+			}
+		}
+	}
+
+	return
+}