瀏覽代碼

update

master
dengbiao 6 月之前
父節點
當前提交
885d97f8fd
共有 4 個檔案被更改,包括 158 行新增64 行删除
  1. +149
    -56
      app/admin/svc/order/svc_order_list.go
  2. +6
    -5
      app/db/db_order_list.go
  3. +3
    -3
      etc/cfg.yml
  4. 二進制
     

+ 149
- 56
app/admin/svc/order/svc_order_list.go 查看文件

@@ -7,6 +7,7 @@ import (
"applet/app/e"
"applet/app/svc"
"applet/app/utils"
"applet/app/utils/logx"
"encoding/json"
"fmt"
"github.com/360EntSecGroup-Skylar/excelize"
@@ -83,49 +84,92 @@ func OrderExport(c *gin.Context) {
}
eg := db.Db
list, _ := db.GetOrderListExport(eg, args)
xlsx, _ := excelize.OpenFile("./static/template/商品销售明细表.xlsx")

titleList := []string{"订单编号", "金额", "手机号", "企业名称", "学校名称", "状态", "送达时间", "订单时间"}
xlsx := excelize.NewFile()
xlsx.SetSheetRow("Sheet1", "A1", &titleList)
style, err := xlsx.NewStyle(`{"fill":{"type":"pattern","color":["FFFF00"],"pattern":1}, "alignment":{"horizontal":"center"}}`)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}
xlsx.SetCellStyle("Sheet1", "A1", "M1", style)
xlsx.SetColWidth("Sheet1", "A", "A", 35)
xlsx.SetColWidth("Sheet1", "B", "B", 30)
xlsx.SetColWidth("Sheet1", "C", "E", 15)
xlsx.SetColWidth("Sheet1", "F", "I", 10)
xlsx.SetColWidth("Sheet1", "J", "J", 20)
xlsx.SetColWidth("Sheet1", "K", "K", 10)
xlsx.SetColWidth("Sheet1", "L", "L", 25)
xlsx.SetColWidth("Sheet1", "M", "M", 15)
//表头被第一行用了,只能从第二行开始
j := 2

var data = map[string]map[int64]map[string]string{}
if list != nil {
stateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"}
enterpriseIds := make([]int, 0)
for _, v := range *list {
enterpriseIds = append(enterpriseIds, v.EnterpriseId)
}
enterpriseMap := db.GetEnterpriseMore(eg, enterpriseIds)

for _, v := range *list {
v1 := JudgePackageOrdOrdState(&v)
enterpriseName := ""
enterpriseName := "-"
_, ok := enterpriseMap[v.EnterpriseId]
if ok {
enterpriseName = enterpriseMap[v.EnterpriseId].Name
}
if data[enterpriseName] == nil {
data[enterpriseName] = make(map[int64]map[string]string)
}
if data[enterpriseName][v.Oid] == nil {
data[enterpriseName][v.Oid] = make(map[string]string)
}
//TODO:: 查找 `order_goods`
var orderGoods []model.OrderGoods
err := eg.Where("oid = ?", v.Oid).Find(&orderGoods)
if err != nil {
e.OutErr(c, e.ERR_DB_ORM, err)
return
}
for _, vv := range orderGoods {
data[enterpriseName][v.Oid]["date"] = v.CreateAt.Format("2006-01-02")
data[enterpriseName][v.Oid]["goods_name"] = vv.GoodsTitle
skuData := make([]md.Sku, 0)
json.Unmarshal([]byte(vv.Sku), &skuData)
skuStr := ""
for _, v1 := range skuData {
if skuStr != "" {
skuStr += ";"
}
skuStr += v1.Value
}
data[enterpriseName][v.Oid]["sku_str"] = skuStr
data[enterpriseName][v.Oid]["num"] = utils.IntToStr(vv.Num)
}
}
}

sheetIndex := 2 //第一个表是模板表
xlsx.NewSheet("Sheet1") //新建表格
xlsx.CopySheet(1, sheetIndex)
xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(2), &[]interface{}{
"日期:" + utils.TimeParseStd(args["start_at"]).Format("2006-01-02") + " ~ " + utils.TimeParseStd(args["end_at"]).Format("2006-01-02"),
})

j := 4 //表头前三行被占用了,只能从第四行开始
for k, v := range data {
var total = 0
for kk, vv := range v {
xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{
utils.Int64ToStr(v1.Oid), v1.Amount, v1.BuyPhone, enterpriseName, stateArr[v1.State],
gjson.Get(v1.BuyInfo, "date").String() + " " + gjson.Get(v1.BuyInfo, "time").String(), v1.CreateAt.Format("2006-01-02 15:04:05"),
vv["date"],
utils.Int64ToStr(kk),
k,
vv["goods_name"],
vv["sku_str"],
vv["num"],
})
xlsx.SetRowHeight("Sheet1", j, 18)
total += utils.StrToInt(vv["num"])
j++
}
}

style, err := xlsx.NewStyle(`{"fill":{"type":"pattern","color":["FFFFCC"],"pattern":1}, "alignment":{"horizontal":"center", "vertical": "center"}}`)
if err != nil {
logx.Error(err)
println("<<<<SelfSupportForSchoolDataStatisticsExport4>>>>>Error:::", err.Error())
panic(err)
}
xlsx.MergeCell("Sheet1", "A"+strconv.Itoa(j), "F"+strconv.Itoa(j)) //合并单元格
xlsx.SetCellStyle("Sheet1", "A"+strconv.Itoa(j), "F"+strconv.Itoa(j), style)
xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{
k + " 汇总: " + utils.IntToStr(total),
})
xlsx.SetRowHeight("Sheet1", j, 20)
j++
}
xlsx.DeleteSheet("template") //删除模板表

c.Header("Content-Type", "application/octet-stream")
c.Header("Content-Disposition", "attachment; filename="+"订单记录"+".xlsx")
@@ -417,49 +461,98 @@ func OrderOutput(c *gin.Context) {
}
eg := db.Db
list := db.GetOrderListOutput(eg, args)
xlsx, _ := excelize.OpenFile("./static/template/商品销售明细表.xlsx")

name := "订单_" + args["page"]
//写入数据
data := map[string]string{
"A1": "购买人手机号",
"B1": "学校名称",
"C1": "订单编号",
"D1": "总金额",
"E1": "订单状态",
"F1": "送达时间",
"G1": "下单时间",
}
var data = map[string]map[int64]map[string]string{}
if list != nil {
stateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"}
enterpriseIds := make([]int, 0)
for _, v := range *list {
enterpriseIds = append(enterpriseIds, v.EnterpriseId)
}
enterpriseMap := db.GetEnterpriseMore(eg, enterpriseIds)
for k, v := range *list {
v1 := v
enterpriseName := ""

for _, v := range *list {
enterpriseName := "-"
_, ok := enterpriseMap[v.EnterpriseId]
if ok {
enterpriseName = enterpriseMap[v.EnterpriseId].Name
}
i := utils.IntToStr(k + 2)
data["A"+i] = v1.BuyPhone
data["B"+i] = enterpriseName
data["C"+i] = utils.Int64ToStr(v1.Oid)
data["D"+i] = v1.Amount
data["E"+i] = stateArr[v1.State]
data["F"+i] = gjson.Get(v1.BuyInfo, "date").String() + " " + gjson.Get(v1.BuyInfo, "time").String()
data["G"+i] = v1.CreateAt.Format("2006-01-02 15:04:05")
if data[enterpriseName] == nil {
data[enterpriseName] = make(map[int64]map[string]string)
}
if data[enterpriseName][v.Oid] == nil {
data[enterpriseName][v.Oid] = make(map[string]string)
}
//TODO:: 查找 `order_goods`
var orderGoods []model.OrderGoods
err := eg.Where("oid = ?", v.Oid).Find(&orderGoods)
if err != nil {
e.OutErr(c, e.ERR_DB_ORM, err)
return
}
for _, vv := range orderGoods {
data[enterpriseName][v.Oid]["date"] = v.CreateAt.Format("2006-01-02")
data[enterpriseName][v.Oid]["goods_name"] = vv.GoodsTitle
skuData := make([]md.Sku, 0)
json.Unmarshal([]byte(vv.Sku), &skuData)
skuStr := ""
for _, v1 := range skuData {
if skuStr != "" {
skuStr += ";"
}
skuStr += v1.Value
}
data[enterpriseName][v.Oid]["sku_str"] = skuStr
data[enterpriseName][v.Oid]["num"] = utils.IntToStr(vv.Num)
}
}
}
file := utils.Output(c, name, data)
filename := name + ".xlsx"
r := map[string]string{
"file": file,
"filename": filename,
}
e.OutSuc(c, r, nil)

sheetIndex := 2 //第一个表是模板表
xlsx.NewSheet("Sheet1") //新建表格
xlsx.CopySheet(1, sheetIndex)
xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(2), &[]interface{}{
"日期:" + utils.TimeParseStd(args["start_at"]).Format("2006-01-02") + " ~ " + utils.TimeParseStd(args["end_at"]).Format("2006-01-02"),
})

j := 4 //表头前三行被占用了,只能从第四行开始
for k, v := range data {
var total = 0
for kk, vv := range v {
xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{
vv["date"],
utils.Int64ToStr(kk),
k,
vv["goods_name"],
vv["sku_str"],
vv["num"],
})
xlsx.SetRowHeight("Sheet1", j, 18)
total += utils.StrToInt(vv["num"])
j++
}

style, err := xlsx.NewStyle(`{"fill":{"type":"pattern","color":["FFFFCC"],"pattern":1}, "alignment":{"horizontal":"center", "vertical": "center"}}`)
if err != nil {
logx.Error(err)
println("<<<<SelfSupportForSchoolDataStatisticsExport4>>>>>Error:::", err.Error())
panic(err)
}
xlsx.MergeCell("Sheet1", "A"+strconv.Itoa(j), "F"+strconv.Itoa(j)) //合并单元格
xlsx.SetCellStyle("Sheet1", "A"+strconv.Itoa(j), "F"+strconv.Itoa(j), style)
xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{
k + " 汇总: " + utils.IntToStr(total),
})
xlsx.SetRowHeight("Sheet1", j, 20)
j++
}
xlsx.DeleteSheet("template") //删除模板表

c.Header("Content-Type", "application/octet-stream")
c.Header("Content-Disposition", "attachment; filename="+"订单记录"+".xlsx")
c.Header("Content-Transfer-Encoding", "binary")
//回写到web 流媒体 形成下载
_ = xlsx.Write(c.Writer)
return
}
func OrderEdit(c *gin.Context) {


+ 6
- 5
app/db/db_order_list.go 查看文件

@@ -127,6 +127,12 @@ func GetOrderListOutput(eg *xorm.Engine, param map[string]string) *[]model.Order
if param["ids"] != "" {
sess.In("id", strings.Split(param["ids"], ","))
}
if param["start_at"] != "" {
sess.And("create_at >= ?", param["start_at"])
}
if param["end_at"] != "" {
sess.And("create_at <= ?", param["end_at"])
}
if param["enterprise_name"] != "" {
var enterprise []model.Enterprise
eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise)
@@ -136,11 +142,6 @@ func GetOrderListOutput(eg *xorm.Engine, param map[string]string) *[]model.Order
}
sess.In("enterprise_id", oids)
}
size := 10000
start := (utils.StrToInt(param["page"]) - 1) * size
if param["ids"] == "" {
sess.Limit(size, start)
}
err := sess.OrderBy("id asc").Find(&order)
if err != nil {
return nil


+ 3
- 3
etc/cfg.yml 查看文件

@@ -11,10 +11,10 @@ redis_password: ''

# 连接官网数据库获取db mapping
db:
host: '119.23.182.117:3306'
host: 'zhios123.rwlb.rds.aliyuncs.com:3306'
name: 'bakery'
user: 'root'
psw: 'Fnuo123com@'
user: 'canal'
psw: 'canal'
show_log: true
max_lifetime: 30
max_open_conns: 100


二進制
查看文件


Loading…
取消
儲存