45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package logic
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"fonchain-fiee/pkg/service/bundle/common"
|
|
"time"
|
|
|
|
"github.com/360EntSecGroup-Skylar/excelize"
|
|
)
|
|
|
|
func WriteToExcel(dirPath string, orderInfos [][]interface{}) (string, error) {
|
|
headRow := []interface{}{"订单编号", "用户编号", "姓名", "性别", "手机号", "国籍", "套餐名称", "签署时间", "套餐费用", "增值服务视频条数", "增值金额", "总额", "支付状态", "支付时间", "财务确认状态"}
|
|
|
|
xlsx := excelize.NewFile()
|
|
index := "Sheet1"
|
|
|
|
xlsx.MergeCell("Sheet1", "A1", "H1")
|
|
|
|
style, _ := xlsx.NewStyle(`{"alignment":{
|
|
"horizontal":"center"
|
|
}}`)
|
|
|
|
xlsx.SetCellStyle(index, "A1", "A1", style)
|
|
|
|
xlsx.SetSheetRow(index, "A1", &[]interface{}{headRow})
|
|
|
|
rowIndex := 3
|
|
for i := 0; i < len(orderInfos); i++ {
|
|
xlsx.SetCellStyle(index, fmt.Sprintf("A%v", rowIndex), fmt.Sprintf("M%v", rowIndex), style)
|
|
xlsx.SetSheetRow(index, fmt.Sprintf("A%v", rowIndex), &orderInfos[i])
|
|
rowIndex++
|
|
}
|
|
|
|
//path := dirPath + "/" + artShowInfo.ArtistName + "-" + artShowInfo.ShowSeq + "-price" + ".xlsx"
|
|
path := dirPath + "/套餐订单信息" + time.Now().Format("20060102150405") + ".xlsx"
|
|
err := xlsx.SaveAs(path)
|
|
if err != nil {
|
|
fmt.Println("save rows err :", err)
|
|
return "", errors.New(common.ErrorExportOrderInfo)
|
|
}
|
|
|
|
return path, nil
|
|
}
|