vip当日购买信息导出excel

This commit is contained in:
zhoupengwei 2022-05-10 19:45:00 +08:00
parent 3d1a1670cc
commit d7a49bf56d
2 changed files with 87 additions and 0 deletions

44
example/app/func.go Normal file
View File

@ -0,0 +1,44 @@
package app
import (
"bytes"
"code.hoteas.com/golang/hotime/common"
"fmt"
"github.com/tealeg/xlsx"
"net/http"
"time"
)
func DataToExcel(w http.ResponseWriter, r *http.Request, titleList []string, dataList []common.Map, fileName string) {
// 生成一个新的文件
file := xlsx.NewFile()
// 添加sheet页
sheet, _ := file.AddSheet("Sheet1")
// 插入表头
titleRow := sheet.AddRow()
for _, v := range titleList {
cell := titleRow.AddCell()
cell.Value = v
cell.GetStyle().Font.Color = "00FF0000"
}
for _, v1 := range dataList {
row := sheet.AddRow()
// 插入内容
for _, v := range titleList {
cell := row.AddCell()
cell.SetValue(v1.Get(v))
}
}
file.Save("D:\\temp\\vip_excel")
fileName = fmt.Sprintf("%s.xlsx", fileName)
//_ = file.Save(fileName)
w.Header().Add("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, fileName))
w.Header().Add("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
var buffer bytes.Buffer
_ = file.Write(&buffer)
content := bytes.NewReader(buffer.Bytes())
http.ServeContent(w, r, fileName, time.Now(), content)
}

View File

@ -157,4 +157,47 @@ var VipOrderCtr = Ctr{
return return
}, },
"export": func(that *Context) {
if that.Session("user_id").Data == nil {
that.Display(2, "没有登录")
return
}
buy_date := ObjToStr(that.Req.FormValue("buy_date"))
if buy_date == "" {
that.Display(3, "请求参数异常")
return
}
data := that.Db.Query("SELECT vo.sn 订单号, vo.`name` 订单名, vo.user_id 购买用户ID,usr.`name` 购买用户名, usr.phone 购买用户电话, cp.id 企业ID, cp.`name` 企业名,\nvo.expiration_time 过期时间, vo.old_expiration_time 订购前到期时间, vo.amount `订单金额_单位(分)`,\nvo.salesman_id 业务员ID,sm.`name` 业务员名, sm.phone 业务员电话, pv.`name` 服务商名 \nFROM vip_order vo\nLEFT JOIN salesman sm ON sm.id = vo.salesman_id\nLEFT JOIN provider pv ON pv.id = vo.provider_id\nLEFT JOIN `user` usr ON usr.id = vo.user_id\nLEFT JOIN company cp ON cp.id = vo.company_id\nWHERE vo.`status` = 1 AND vo.create_time >= '" + buy_date + "' \nORDER BY vo.create_time")
if len(data) == 0 {
that.Display(0, "今日没有vip购买信息数据")
return
}
var titleList []string
if data != nil {
m := data[0]
for k, _ := range m {
titleList = append(titleList, k)
}
}
var dataList []Map
for _, v := range data {
dataList = append(dataList, v)
}
//打印最后一次sql语句
//that.Db.LastQuery
//请求的数据
//that.Db.LastData
//that.Db.LastErr
//appIns.Db.Select("company",common.Map{"[<>]user":"company.id=user.company_id"},"company.id as id",common.Map{"AND":common.Map{"id[!]":nil},"ORDER":"id DESC"})
//appIns.Db.Query("select * from user where id = ? and name = ?",common.Slice{1,"nn"})
//titleList:= []string{"aaaa", "vvvvv", "dddd", "eeeee", "gfgggg"}
DataToExcel(that.Resp, that.Req, titleList, dataList, buy_date+"vip购买信息分析数据")
},
} }