|
@@ -2087,6 +2087,8 @@ func IncomeListExport(this *StatisticReportController, resp response.IncomeListR
|
|
|
// @Param DataType query string false "报表类型,枚举值:`新签客户`,`续约客户`,`未续约客户`"
|
|
|
// @Param TryOutType query string false " '试用', '非试用' 非试用即为冻结/流失"
|
|
|
// @Param IsExport query bool false "是否导出excel,默认是false"
|
|
|
+// @Param IsConfirm query int false "是否确认续约: -1-默认全部; 0-待确认; 1-已确认"
|
|
|
+// @Param CompanyAscribeId query int false "归因ID"
|
|
|
// @Success 200 {object} response.StackCompanyListResp
|
|
|
// @router /stack_company_list [get]
|
|
|
func (this *StatisticReportController) StackCompanyList() {
|
|
@@ -2122,6 +2124,10 @@ func (this *StatisticReportController) StackCompanyList() {
|
|
|
keyword := this.GetString("Keyword")
|
|
|
|
|
|
date := this.GetString("Date")
|
|
|
+
|
|
|
+ isConfirm, _ := this.GetInt("IsConfirm", -1) // CRM 13.9
|
|
|
+ companyAscribeId, _ := this.GetInt("CompanyAscribeId", -1) // CRM 13.9
|
|
|
+
|
|
|
if date == "" {
|
|
|
br.Msg = "获取失败,请选择日期"
|
|
|
br.ErrMsg = "获取失败,请选择日期"
|
|
@@ -2144,7 +2150,7 @@ func (this *StatisticReportController) StackCompanyList() {
|
|
|
var resp response.StackCompanyListResp
|
|
|
//历史统计数据
|
|
|
if dateTime < todayTimeNumber {
|
|
|
- tmpResp, err := getHistoryStackCompanyList(sysUser, currentIndex, pageSize, adminId, regionType, companyType, dataType, tryOutType, date, keyword)
|
|
|
+ tmpResp, err := getHistoryStackCompanyList(sysUser, currentIndex, pageSize, isConfirm, companyAscribeId, adminId, regionType, companyType, dataType, tryOutType, date, keyword)
|
|
|
if err != nil {
|
|
|
br.Msg = "获取失败"
|
|
|
br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
@@ -2153,7 +2159,7 @@ func (this *StatisticReportController) StackCompanyList() {
|
|
|
resp = tmpResp
|
|
|
} else {
|
|
|
//获取实时统计数据(今天数据)
|
|
|
- tmpResp, err := getTodayStackCompanyListV2(sysUser, currentIndex, pageSize, adminId, regionType, companyType, dataType, tryOutType, keyword)
|
|
|
+ tmpResp, err := getTodayStackCompanyListV2(sysUser, currentIndex, pageSize, isConfirm, companyAscribeId, adminId, regionType, companyType, dataType, tryOutType, keyword)
|
|
|
if err != nil {
|
|
|
br.Msg = "获取失败"
|
|
|
br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
@@ -2313,7 +2319,7 @@ func StackCompanyListExport(this *StatisticReportController, dataType string, re
|
|
|
}
|
|
|
|
|
|
// 获取历史的数据
|
|
|
-func getHistoryStackCompanyList(sysUser *system.Admin, currentIndex, pageSize int, adminId, regionType, companyType, dataType, tryOutType, date, keyword string) (returnData response.StackCompanyListResp, err error) {
|
|
|
+func getHistoryStackCompanyList(sysUser *system.Admin, currentIndex, pageSize, isConfirm, companyAscribeId int, adminId, regionType, companyType, dataType, tryOutType, date, keyword string) (returnData response.StackCompanyListResp, err error) {
|
|
|
if date == "" {
|
|
|
err = errors.New("请选择日期")
|
|
|
return
|
|
@@ -2335,6 +2341,55 @@ func getHistoryStackCompanyList(sysUser *system.Admin, currentIndex, pageSize in
|
|
|
condition += ` AND date = ? `
|
|
|
pars = append(pars, date)
|
|
|
|
|
|
+ //是否确认续约 CRM 13.9
|
|
|
+ if isConfirm != -1 {
|
|
|
+ var conditionConfirm string
|
|
|
+ var parsConfirm []interface{}
|
|
|
+
|
|
|
+ companyConfirmList, e := company.GetCompanyNoRenewedAscribeList(conditionConfirm, parsConfirm, 0, 0)
|
|
|
+ if e != nil && e.Error() != utils.ErrNoRow() {
|
|
|
+ err = errors.New("GetCompanyNoRenewedAscribeList" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var companyIds []int
|
|
|
+ if len(companyConfirmList) == 0 {
|
|
|
+ companyIds = append(companyIds, 0) // 给一个不存在的ID
|
|
|
+ } else {
|
|
|
+ for _, v := range companyConfirmList {
|
|
|
+ companyIds = append(companyIds, v.CompanyId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if isConfirm == 0 {
|
|
|
+ condition += ` AND c.company_id NOT IN (` + utils.GetOrmInReplace(len(companyIds)) + `)` // 待确认
|
|
|
+ } else {
|
|
|
+ condition += ` AND c.company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `)` // 已确认
|
|
|
+ }
|
|
|
+ pars = append(pars, companyIds)
|
|
|
+ }
|
|
|
+
|
|
|
+ //归因ID CRM 13.9
|
|
|
+ if companyAscribeId > 0 {
|
|
|
+ var conditionAscribe string
|
|
|
+ var parsAscribe []interface{}
|
|
|
+ conditionAscribe = " AND company_ascribe_id = ? "
|
|
|
+ parsAscribe = append(parsAscribe, companyAscribeId)
|
|
|
+ companyNoRenewedAscribeList, e := company.GetCompanyNoRenewedAscribeList(conditionAscribe, parsAscribe, 0, 0)
|
|
|
+ if e != nil && e.Error() != utils.ErrNoRow() {
|
|
|
+ err = errors.New("GetCompanyNoRenewedAscribeList" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var companyIds []int
|
|
|
+ if len(companyNoRenewedAscribeList) == 0 {
|
|
|
+ companyIds = append(companyIds, 0) // 给一个不存在的ID
|
|
|
+ } else {
|
|
|
+ for _, v := range companyNoRenewedAscribeList {
|
|
|
+ companyIds = append(companyIds, v.CompanyId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ condition += ` AND c.company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `)`
|
|
|
+ pars = append(pars, companyIds)
|
|
|
+ }
|
|
|
+
|
|
|
if adminId != "" {
|
|
|
condition += ` AND a.seller_id in (` + adminId + `) `
|
|
|
//pars = append(pars, adminId)
|
|
@@ -2493,12 +2548,17 @@ func getHistoryStackCompanyList(sysUser *system.Admin, currentIndex, pageSize in
|
|
|
//moreListMap := make(map[int][]*models.StackCompanyStatisticList)
|
|
|
if dataType == "续约客户" {
|
|
|
var ids []string
|
|
|
+ var ascribecompanyIds []int
|
|
|
oldCompanyMap := make(map[int]*models.IncrementalList)
|
|
|
oldMoneyMap := make(map[int]float64)
|
|
|
countMap := make(map[int]int)
|
|
|
for _, item := range list {
|
|
|
ids = append(ids, strconv.Itoa(item.CompanyId))
|
|
|
+ ascribecompanyIds = append(ascribecompanyIds, item.CompanyId)
|
|
|
}
|
|
|
+ //归因标签
|
|
|
+ mapGetCompanyAscribeContent := services.GetCompanyAscribeContentMap(ascribecompanyIds)
|
|
|
+ mapNoRenewedNote := services.GetCompanyNoRenewedNoteMap(ascribecompanyIds)
|
|
|
if len(ids) > 0 {
|
|
|
idStr := strings.Join(ids, ",")
|
|
|
lists, contractErr := models.GetLastContractMoney(idStr)
|
|
@@ -2531,6 +2591,8 @@ func getHistoryStackCompanyList(sysUser *system.Admin, currentIndex, pageSize in
|
|
|
item.PackageDifference = "维持套餐"
|
|
|
}
|
|
|
}
|
|
|
+ item.AscribeContent = mapGetCompanyAscribeContent[fmt.Sprint("CID_", item.CompanyId, "PID_", item.ProductId)]
|
|
|
+ item.IsShowNoRenewedNote = mapNoRenewedNote[fmt.Sprint("CID_", item.CompanyId, "PID_", item.ProductId)]
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -2847,7 +2909,7 @@ func getTodayStackCompanyList(sysUser *system.Admin, currentIndex, pageSize int,
|
|
|
return resp, err
|
|
|
}
|
|
|
|
|
|
-func getTodayStackCompanyListV2(sysUser *system.Admin, currentIndex, pageSize int, adminId, regionType, companyType, dataType, tryOutType, keyword string) (returnData response.StackCompanyListResp, err error) {
|
|
|
+func getTodayStackCompanyListV2(sysUser *system.Admin, currentIndex, pageSize, isConfirm, companyAscribeId int, adminId, regionType, companyType, dataType, tryOutType, keyword string) (returnData response.StackCompanyListResp, err error) {
|
|
|
var startSize int
|
|
|
if pageSize <= 0 {
|
|
|
pageSize = utils.PageSize20
|
|
@@ -2863,6 +2925,55 @@ func getTodayStackCompanyListV2(sysUser *system.Admin, currentIndex, pageSize in
|
|
|
today := utils.GetToday(utils.FormatDate)
|
|
|
//条件
|
|
|
|
|
|
+ //是否确认续约 CRM 13.9
|
|
|
+ if isConfirm != -1 {
|
|
|
+ var conditionConfirm string
|
|
|
+ var parsConfirm []interface{}
|
|
|
+
|
|
|
+ companyConfirmList, e := company.GetCompanyNoRenewedAscribeList(conditionConfirm, parsConfirm, 0, 0)
|
|
|
+ if e != nil && e.Error() != utils.ErrNoRow() {
|
|
|
+ err = errors.New("GetCompanyNoRenewedAscribeList" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var companyIds []int
|
|
|
+ if len(companyConfirmList) == 0 {
|
|
|
+ companyIds = append(companyIds, 0) // 给一个不存在的ID
|
|
|
+ } else {
|
|
|
+ for _, v := range companyConfirmList {
|
|
|
+ companyIds = append(companyIds, v.CompanyId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if isConfirm == 0 {
|
|
|
+ condition += ` AND c.company_id NOT IN (` + utils.GetOrmInReplace(len(companyIds)) + `)` // 待确认
|
|
|
+ } else {
|
|
|
+ condition += ` AND c.company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `)` // 已确认
|
|
|
+ }
|
|
|
+ pars = append(pars, companyIds)
|
|
|
+ }
|
|
|
+
|
|
|
+ //归因ID CRM 13.9
|
|
|
+ if companyAscribeId > 0 {
|
|
|
+ var conditionAscribe string
|
|
|
+ var parsAscribe []interface{}
|
|
|
+ conditionAscribe = " AND company_ascribe_id = ? "
|
|
|
+ parsAscribe = append(parsAscribe, companyAscribeId)
|
|
|
+ companyNoRenewedAscribeList, e := company.GetCompanyNoRenewedAscribeList(conditionAscribe, parsAscribe, 0, 0)
|
|
|
+ if e != nil && e.Error() != utils.ErrNoRow() {
|
|
|
+ err = errors.New("GetCompanyNoRenewedAscribeList" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var companyIds []int
|
|
|
+ if len(companyNoRenewedAscribeList) == 0 {
|
|
|
+ companyIds = append(companyIds, 0) // 给一个不存在的ID
|
|
|
+ } else {
|
|
|
+ for _, v := range companyNoRenewedAscribeList {
|
|
|
+ companyIds = append(companyIds, v.CompanyId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ condition += ` AND c.company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `)`
|
|
|
+ pars = append(pars, companyIds)
|
|
|
+ }
|
|
|
+
|
|
|
if adminId != "" {
|
|
|
condition += ` AND c.seller_id in (` + adminId + `) `
|
|
|
//pars = append(pars, adminId)
|
|
@@ -2879,6 +2990,7 @@ func getTodayStackCompanyListV2(sysUser *system.Admin, currentIndex, pageSize in
|
|
|
if keyword != "" {
|
|
|
condition += ` and b.company_name like "%` + keyword + `%" `
|
|
|
}
|
|
|
+
|
|
|
switch companyType {
|
|
|
case "ficc":
|
|
|
condition += ` AND a.product_id = ? `
|
|
@@ -3081,6 +3193,7 @@ func getTodayStackCompanyListV2(sysUser *system.Admin, currentIndex, pageSize in
|
|
|
oldCompanyMap[item.CompanyId] = item
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
//给list赋值
|
|
|
for _, item := range list {
|
|
|
if item.ProductName == "权益" {
|
|
@@ -3097,6 +3210,19 @@ func getTodayStackCompanyListV2(sysUser *system.Admin, currentIndex, pageSize in
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ var ascribecompanyIds []int
|
|
|
+ for _, item := range list {
|
|
|
+ ascribecompanyIds = append(ascribecompanyIds, item.CompanyId)
|
|
|
+ }
|
|
|
+ //归因标签
|
|
|
+ mapGetCompanyAscribeContent := services.GetCompanyAscribeContentMap(ascribecompanyIds)
|
|
|
+ mapNoRenewedNote := services.GetCompanyNoRenewedNoteMap(ascribecompanyIds)
|
|
|
+ for _, item := range list {
|
|
|
+ item.AscribeContent = mapGetCompanyAscribeContent[fmt.Sprint("CID_", item.CompanyId, "PID_", item.ProductId)]
|
|
|
+ item.IsShowNoRenewedNote = mapNoRenewedNote[fmt.Sprint("CID_", item.CompanyId, "PID_", item.ProductId)]
|
|
|
+ }
|
|
|
+
|
|
|
listLen := len(list)
|
|
|
for i := 0; i < listLen; i++ {
|
|
|
item := list[i]
|
|
@@ -3134,12 +3260,14 @@ func getTodayStackCompanyListV2(sysUser *system.Admin, currentIndex, pageSize in
|
|
|
EndDate: v.EndDate,
|
|
|
RegionType: v.RegionType,
|
|
|
//CreateTime :v.CreateTime,
|
|
|
- CreateTimeStr: v.CreateTime,
|
|
|
- ExpireDay: v.ExpireDay,
|
|
|
- RenewalReason: v.RenewalReason,
|
|
|
- RenewalTodo: v.RenewalTodo,
|
|
|
- Status: v.Status,
|
|
|
- PackageDifference: v.PackageDifference,
|
|
|
+ CreateTimeStr: v.CreateTime,
|
|
|
+ ExpireDay: v.ExpireDay,
|
|
|
+ RenewalReason: v.RenewalReason,
|
|
|
+ RenewalTodo: v.RenewalTodo,
|
|
|
+ Status: v.Status,
|
|
|
+ PackageDifference: v.PackageDifference,
|
|
|
+ AscribeContent: v.AscribeContent,
|
|
|
+ IsShowNoRenewedNote: v.IsShowNoRenewedNote,
|
|
|
}
|
|
|
stackCompanyStatisticList = append(stackCompanyStatisticList, &stackCompanyStatistic)
|
|
|
}
|
|
@@ -3170,6 +3298,8 @@ func getTodayStackCompanyListV2(sysUser *system.Admin, currentIndex, pageSize in
|
|
|
// @Param DataType query string false "报表类型,枚举值:`新增试用`,`新签客户`,`续约客户`,`未续约客户`"
|
|
|
// @Param TryOutType query string false " '试用', '非试用' 非试用即为冻结/流失"
|
|
|
// @Param IsExport query bool false "是否导出excel,默认是false"
|
|
|
+// @Param IsConfirm query int false "是否确认续约: -1-默认全部; 0-待确认; 1-已确认"
|
|
|
+// @Param CompanyAscribeId query int false "归因ID"
|
|
|
// @Success 200 {object} response.IncrementalCompanyListResp
|
|
|
// @router /incremental_company_list [get]
|
|
|
func (this *StatisticReportController) IncrementalCompanyList() {
|
|
@@ -3199,6 +3329,9 @@ func (this *StatisticReportController) IncrementalCompanyList() {
|
|
|
|
|
|
startDate := this.GetString("StartDate")
|
|
|
endDate := this.GetString("EndDate")
|
|
|
+
|
|
|
+ isConfirm, _ := this.GetInt("IsConfirm", -1) // CRM 13.9
|
|
|
+ companyAscribeId, _ := this.GetInt("CompanyAscribeId", -1) // CRM 13.9
|
|
|
//if startDate == "" || endDate == "" {
|
|
|
// br.Msg = "获取失败,开始日期或结束日期未传"
|
|
|
// br.ErrMsg = "获取失败,开始日期或结束日期未传"
|
|
@@ -3248,6 +3381,57 @@ func (this *StatisticReportController) IncrementalCompanyList() {
|
|
|
if keyword != "" {
|
|
|
condition += ` and b.company_name like "%` + keyword + `%" `
|
|
|
}
|
|
|
+
|
|
|
+ //是否确认续约 CRM 13.9
|
|
|
+ if isConfirm != -1 {
|
|
|
+ var conditionConfirm string
|
|
|
+ var parsConfirm []interface{}
|
|
|
+
|
|
|
+ companyConfirmList, err := company.GetCompanyNoRenewedAscribeList(conditionConfirm, parsConfirm, 0, 0)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,GetCompanyNoRenewedAscribeList Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var companyIds []int
|
|
|
+ if len(companyConfirmList) == 0 {
|
|
|
+ companyIds = append(companyIds, 0) // 给一个不存在的ID
|
|
|
+ } else {
|
|
|
+ for _, v := range companyConfirmList {
|
|
|
+ companyIds = append(companyIds, v.CompanyId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if isConfirm == 0 {
|
|
|
+ condition += ` AND c.company_id NOT IN (` + utils.GetOrmInReplace(len(companyIds)) + `)` // 待确认
|
|
|
+ } else {
|
|
|
+ condition += ` AND c.company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `)` // 已确认
|
|
|
+ }
|
|
|
+ pars = append(pars, companyIds)
|
|
|
+ }
|
|
|
+
|
|
|
+ //归因ID CRM 13.9
|
|
|
+ if companyAscribeId > 0 {
|
|
|
+ var conditionAscribe string
|
|
|
+ var parsAscribe []interface{}
|
|
|
+ conditionAscribe = " AND company_ascribe_id = ? "
|
|
|
+ parsAscribe = append(parsAscribe, companyAscribeId)
|
|
|
+ companyNoRenewedAscribeList, err := company.GetCompanyNoRenewedAscribeList(conditionAscribe, parsAscribe, 0, 0)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,GetCompanyNoRenewedAscribeList Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var companyIds []int
|
|
|
+ if len(companyNoRenewedAscribeList) == 0 {
|
|
|
+ companyIds = append(companyIds, 0) // 给一个不存在的ID
|
|
|
+ } else {
|
|
|
+ for _, v := range companyNoRenewedAscribeList {
|
|
|
+ companyIds = append(companyIds, v.CompanyId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ condition += ` AND c.company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `)`
|
|
|
+ pars = append(pars, companyIds)
|
|
|
+ }
|
|
|
switch companyType {
|
|
|
case "ficc":
|
|
|
condition += ` AND c.product_id = ? `
|
|
@@ -3553,9 +3737,20 @@ func (this *StatisticReportController) IncrementalCompanyList() {
|
|
|
br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+ var ascribecompanyIds []int
|
|
|
for _, item := range tmpList {
|
|
|
endDateTime, _ := time.Parse(utils.FormatDateTime, item.CreateTime)
|
|
|
item.EndDate = endDateTime.Format(utils.FormatDate)
|
|
|
+ ascribecompanyIds = append(ascribecompanyIds, item.CompanyId)
|
|
|
+ }
|
|
|
+ //归因标签
|
|
|
+ mapGetCompanyAscribeContent := services.GetCompanyAscribeContentMap(ascribecompanyIds)
|
|
|
+ mapNoRenewedNote := services.GetCompanyNoRenewedNoteMap(ascribecompanyIds)
|
|
|
+
|
|
|
+ for _, item := range tmpList {
|
|
|
+ item.AscribeContent = mapGetCompanyAscribeContent[fmt.Sprint("CID_", item.CompanyId, "PID_", item.ProductId)]
|
|
|
+ item.IsShowNoRenewedNote = mapNoRenewedNote[fmt.Sprint("CID_", item.CompanyId, "PID_", item.ProductId)]
|
|
|
}
|
|
|
list = tmpList
|
|
|
dataTotal = total
|
|
@@ -3588,6 +3783,9 @@ func (this *StatisticReportController) IncrementalCompanyList() {
|
|
|
|
|
|
listLen := len(list)
|
|
|
|
|
|
+ if listLen == 0 {
|
|
|
+ list = make([]*models.IncrementalList, 0)
|
|
|
+ }
|
|
|
for i := 0; i < listLen; i++ {
|
|
|
item := list[i]
|
|
|
|