diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index b8584c785..b48c0fa6c 100755 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -536,8 +536,10 @@ form.name_reserved = The username '%s' is reserved. form.name_pattern_not_allowed = The pattern '%s' is not allowed in a username. form.name_chars_not_allowed = User name '%s' contains invalid characters. -user.static.invitationNum=User Invitation Count +static.invitationdetailsheetname=User Invitation Detail +static.invitationNum=User Invitation Count static.invitationsheetname=User Invitation +static.srcUserId=Recommended User ID static.sheetname=User Analysis static.id=ID static.name=User Name diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index 51f150cee..434a73986 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -541,8 +541,10 @@ form.name_reserved='%s' 用户名被保留。 form.name_pattern_not_allowed=用户名中不允许使用 "%s"。 form.name_chars_not_allowed=用户名 '%s' 包含无效字符。 -user.static.invitationNum=邀请用户数 +static.invitationdetailsheetname=用户邀请详细数据 +static.invitationNum=邀请用户数 static.sheetname=用户分析 +static.srcUserId=推荐用户ID static.invitationsheetname=用户邀请分析 static.id=ID static.name=用户名 diff --git a/routers/repo/user_invitation.go b/routers/repo/user_invitation.go index 1a63ec1bc..47eb1a3e7 100644 --- a/routers/repo/user_invitation.go +++ b/routers/repo/user_invitation.go @@ -43,6 +43,25 @@ func getInvitationExcelHeader(ctx *context.Context) map[string]string { return excelHeaderMap } +func getInvitationDetailExcelHeader(ctx *context.Context) map[string]string { + excelHeader := make([]string, 0) + excelHeader = append(excelHeader, ctx.Tr("user.static.id")) + excelHeader = append(excelHeader, ctx.Tr("user.static.name")) + excelHeader = append(excelHeader, ctx.Tr("user.static.srcUserId")) + excelHeader = append(excelHeader, ctx.Tr("user.static.phone")) + excelHeader = append(excelHeader, ctx.Tr("user.static.registdate")) + + excelHeaderMap := make(map[string]string, 0) + var i byte + i = 0 + for _, value := range excelHeader { + excelColumn := getColumn(i) + fmt.Sprint(1) + excelHeaderMap[excelColumn] = value + i++ + } + return excelHeaderMap +} + func writeInvitationExcel(row int, xlsx *excelize.File, sheetName string, userRecord *models.UserBusinessAnalysisAll) { rows := fmt.Sprint(row) var tmp byte @@ -63,8 +82,61 @@ func writeInvitationExcel(row int, xlsx *excelize.File, sheetName string, userRe } +func writeInvitationDetailExcel(row int, xlsx *excelize.File, sheetName string, userRecord *models.Invitation) { + rows := fmt.Sprint(row) + var tmp byte + tmp = 0 + xlsx.SetCellValue(sheetName, getColumn(tmp)+rows, userRecord.ID) + tmp = tmp + 1 + xlsx.SetCellValue(sheetName, getColumn(tmp)+rows, userRecord.Name) + tmp = tmp + 1 + + xlsx.SetCellValue(sheetName, getColumn(tmp)+rows, userRecord.SrcUserID) + tmp = tmp + 1 + + xlsx.SetCellValue(sheetName, getColumn(tmp)+rows, userRecord.Phone) + tmp = tmp + 1 + + formatTime := userRecord.CreatedUnix.Format("2006-01-02 15:04:05") + xlsx.SetCellValue(sheetName, getColumn(tmp)+rows, formatTime[0:len(formatTime)-3]) + +} + func DownloadInvitationDetail(ctx *context.Context) { + xlsx := excelize.NewFile() + sheetName := ctx.Tr("user.static.invitationdetailsheetname") + index := xlsx.NewSheet(sheetName) + xlsx.DeleteSheet("Sheet1") + excelHeader := getInvitationDetailExcelHeader(ctx) + for k, v := range excelHeader { + //设置单元格的值 + xlsx.SetCellValue(sheetName, k, v) + } + _, count := models.QueryInvitaionPage(1, 1) + var indexTotal int64 + indexTotal = 0 + row := 1 + for { + re, _ := models.QueryInvitaionPage(int(indexTotal), PAGE_SIZE) + log.Info("return count=" + fmt.Sprint(count)) + for _, userRecord := range re { + row++ + writeInvitationDetailExcel(row, xlsx, sheetName, userRecord) + } + indexTotal += PAGE_SIZE + if indexTotal >= count { + break + } + } + //设置默认打开的表单 + xlsx.SetActiveSheet(index) + filename := sheetName + ".xlsx" + ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+url.QueryEscape(filename)) + ctx.Resp.Header().Set("Content-Type", "application/octet-stream") + if _, err := xlsx.WriteTo(ctx.Resp); err != nil { + log.Info("writer exel error." + err.Error()) + } } func queryDataFromStaticTable(ctx *context.Context, tableName string, queryObj interface{}) { @@ -198,14 +270,14 @@ func QueryInvitationAll(ctx *context.Context) { queryDataFromStaticTable(ctx, "public.user_business_analysis_all", new(models.UserBusinessAnalysisAll)) } -func queryData(ctx *context.Context, startTime int64, endTime int64) { - page, pageSize := getPageInfo(ctx) - result, count := models.QueryInvitaionPage(startTime, endTime, (page-1)*pageSize, pageSize) - mapInterface := make(map[string]interface{}) - mapInterface["data"] = result - mapInterface["count"] = count - ctx.JSON(http.StatusOK, mapInterface) -} +// func queryData(ctx *context.Context, startTime int64, endTime int64) { +// page, pageSize := getPageInfo(ctx) +// result, count := models.QueryInvitaionPage(startTime, endTime, (page-1)*pageSize, pageSize) +// mapInterface := make(map[string]interface{}) +// mapInterface["data"] = result +// mapInterface["count"] = count +// ctx.JSON(http.StatusOK, mapInterface) +// } func getPageInfo(ctx *context.Context) (int, int) { page := ctx.QueryInt("page")