@@ -0,0 +1,124 @@
|
||||
package statctrl
|
||||
|
||||
import (
|
||||
"91porn-server/common"
|
||||
"91porn-server/common/stderr"
|
||||
"91porn-server/web/service/statser"
|
||||
"bytes"
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func DataStat(ctx *gin.Context) {
|
||||
var args struct {
|
||||
Start time.Time `form:"startTime" json:"startTime" binding:"required"`
|
||||
End time.Time `form:"endTime" json:"endTime" binding:"required"`
|
||||
}
|
||||
if err := ctx.ShouldBind(&args); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, "stat RchSucRate arg error "+err.Error())
|
||||
return
|
||||
}
|
||||
res, err, titles := statser.DataStat(args.Start, args.End)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.Failure, "DataStat DataStat error: "+err.Error())
|
||||
return
|
||||
}
|
||||
var (
|
||||
headList []string
|
||||
dataBytes = new(bytes.Buffer)
|
||||
)
|
||||
headList = []string{"时间", "楼凤", "vip充值", "金币充值", "新增用户"}
|
||||
for i := range titles {
|
||||
headList = append(headList, titles[i]+"金额", titles[i]+"-数量")
|
||||
}
|
||||
headList = append(headList, titles...)
|
||||
//设置编码格式
|
||||
dataBytes.WriteString("\xEF\xBB\xBF")
|
||||
wr := csv.NewWriter(dataBytes)
|
||||
wr.Write(headList)
|
||||
for _, v := range res {
|
||||
bodyList := []string{
|
||||
v.SumData,
|
||||
strconv.FormatInt(v.LoufengTrade, 10),
|
||||
strconv.FormatInt(v.VIPRecharge, 10),
|
||||
strconv.FormatInt(v.CoinRecharge, 10),
|
||||
strconv.FormatInt(v.NewUser, 10),
|
||||
}
|
||||
vipTrans := make([]string, 0)
|
||||
for i := range titles {
|
||||
if len(v.VipTrande) < 1 {
|
||||
vipTrans = append(vipTrans, "0", "0")
|
||||
} else if vipTrande, ok := v.VipTrande[titles[i]]; ok {
|
||||
vipTrans = append(vipTrans, fmt.Sprintf("%d", vipTrande.Amount), fmt.Sprintf("%d", vipTrande.Count))
|
||||
} else {
|
||||
vipTrans = append(vipTrans, "0", "0")
|
||||
}
|
||||
}
|
||||
bodyList = append(bodyList, vipTrans...)
|
||||
wr.Write(bodyList)
|
||||
}
|
||||
//清空
|
||||
wr.Flush()
|
||||
ctx.Writer.Header().Set("Content-type", "application/octet-stream")
|
||||
//c.Writer.Header().Set("Content-Type", "text/csv")
|
||||
ctx.Writer.Header().Set("Content-Disposition", fmt.Sprintf("attachment;filename=%s", "companys.csv"))
|
||||
ctx.String(200, dataBytes.String())
|
||||
return
|
||||
}
|
||||
func VidStat(ctx *gin.Context) {
|
||||
var args struct {
|
||||
Start time.Time `form:"startTime" json:"startTime" binding:"required"`
|
||||
End time.Time `form:"endTime" json:"endTime" binding:"required"`
|
||||
}
|
||||
if err := ctx.ShouldBind(&args); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, "stat RchSucRate arg error "+err.Error())
|
||||
return
|
||||
}
|
||||
var (
|
||||
headList []string
|
||||
dataBytes = new(bytes.Buffer)
|
||||
)
|
||||
headList = []string{"时间", "短视频销售额", "短视频数量", "长视频销售额", "长视频数量"}
|
||||
//设置编码格式
|
||||
dataBytes.WriteString("\xEF\xBB\xBF")
|
||||
wr := csv.NewWriter(dataBytes)
|
||||
wr.Write(headList)
|
||||
start := args.Start
|
||||
end := args.End
|
||||
|
||||
for start.Before(end) {
|
||||
head := start
|
||||
tail := head.Add(time.Hour * 24 * 15)
|
||||
if tail.After(end) {
|
||||
tail = end
|
||||
}
|
||||
res, err := statser.PayVidStat(head, tail)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.Failure, "statser PayVidStat error: "+err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
for _, v := range res {
|
||||
bodyList := []string{
|
||||
v.SumData,
|
||||
strconv.FormatInt(v.ShortVidAmount, 10),
|
||||
strconv.FormatInt(v.ShortVidCount, 10),
|
||||
strconv.FormatInt(v.LongVidAmount, 10),
|
||||
strconv.FormatInt(v.LongVidCount, 10),
|
||||
}
|
||||
wr.Write(bodyList)
|
||||
}
|
||||
start = tail
|
||||
}
|
||||
|
||||
//清空
|
||||
wr.Flush()
|
||||
ctx.Writer.Header().Set("Content-type", "application/octet-stream")
|
||||
ctx.Writer.Header().Set("Content-Disposition", fmt.Sprintf("attachment;filename=%s", "videoSales.csv"))
|
||||
ctx.String(200, dataBytes.String())
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user