@@ -314,6 +314,57 @@ func OrderDetail(c *gin.Context) { | |||||
} | } | ||||
func OrderOutput(c *gin.Context) { | func OrderOutput(c *gin.Context) { | ||||
var args map[string]string | |||||
if err := c.ShouldBindJSON(&args); err != nil { | |||||
e.OutErr(c, e.ERR_INVALID_ARGS, err) | |||||
return | |||||
} | |||||
eg := db.Db | |||||
list := db.GetOrderListOutput(eg, args) | |||||
name := "订单_" + args["page"] | |||||
//写入数据 | |||||
data := map[string]string{ | |||||
"A1": "购买人手机号", | |||||
"B1": "学校名称", | |||||
"C1": "订单编号", | |||||
"D1": "总金额", | |||||
"E1": "订单状态", | |||||
"F1": "送达时间", | |||||
"G1": "下单时间", | |||||
} | |||||
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 := "" | |||||
_, 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") | |||||
} | |||||
} | |||||
file := utils.Output(c, name, data) | |||||
filename := name + ".xlsx" | |||||
r := map[string]string{ | |||||
"file": file, | |||||
"filename": filename, | |||||
} | |||||
e.OutSuc(c, r, nil) | |||||
return | |||||
} | } | ||||
func OrderEdit(c *gin.Context) { | func OrderEdit(c *gin.Context) { | ||||
var args map[string]string | var args map[string]string | ||||
@@ -331,10 +382,10 @@ func OrderEdit(c *gin.Context) { | |||||
json.Unmarshal([]byte(order.BuyInfo), &tmp) | json.Unmarshal([]byte(order.BuyInfo), &tmp) | ||||
tmp.Time = args["time"] | tmp.Time = args["time"] | ||||
tmp.Date = args["date"] | tmp.Date = args["date"] | ||||
tmp.Phone = args["phone"] | |||||
tmp.Name = args["name"] | |||||
tmp.Phone = args["buy_phone"] | |||||
tmp.Name = args["buy_name"] | |||||
tmp.Address = args["address"] | tmp.Address = args["address"] | ||||
order.BuyPhone = args["phone"] | |||||
order.BuyPhone = args["buy_phone"] | |||||
order.BuyInfo = utils.SerializeStr(tmp) | order.BuyInfo = utils.SerializeStr(tmp) | ||||
eg.Where("id=?", order.Id).Cols("buy_phone,buy_info").Update(order) | eg.Where("id=?", order.Id).Cols("buy_phone,buy_info").Update(order) | ||||
e.OutSuc(c, "success", nil) | e.OutSuc(c, "success", nil) | ||||
@@ -1,9 +1,11 @@ | |||||
package svc | package svc | ||||
import ( | import ( | ||||
"applet/app/admin/md" | |||||
"applet/app/db" | "applet/app/db" | ||||
"applet/app/e" | "applet/app/e" | ||||
"applet/app/utils" | "applet/app/utils" | ||||
"encoding/json" | |||||
"github.com/gin-gonic/gin" | "github.com/gin-gonic/gin" | ||||
) | ) | ||||
@@ -38,6 +40,7 @@ func MarkRecord(c *gin.Context) { | |||||
if ok1 { | if ok1 { | ||||
adminName = adminMap[v.AdminId].Memo | adminName = adminMap[v.AdminId].Memo | ||||
} | } | ||||
var tmp = map[string]string{ | var tmp = map[string]string{ | ||||
"oid": utils.Int64ToStr(v.Oid), | "oid": utils.Int64ToStr(v.Oid), | ||||
"id": utils.IntToStr(v.Id), | "id": utils.IntToStr(v.Id), | ||||
@@ -45,20 +48,41 @@ func MarkRecord(c *gin.Context) { | |||||
"state": utils.IntToStr(v.State), | "state": utils.IntToStr(v.State), | ||||
"time": v.Time.Format("2006-01-02 15:04:05"), | "time": v.Time.Format("2006-01-02 15:04:05"), | ||||
"enterprise_name": enterpriseName, | "enterprise_name": enterpriseName, | ||||
"sku_str": v.Sku, | |||||
"sku_str": "", | |||||
"goods_title": v.GoodsTitle, | "goods_title": v.GoodsTitle, | ||||
"memo": v.Memo, | "memo": v.Memo, | ||||
"admin_name": adminName, | "admin_name": adminName, | ||||
"num": utils.IntToStr(v.Num), | "num": utils.IntToStr(v.Num), | ||||
"success_num": utils.IntToStr(v.SuccessNum), | "success_num": utils.IntToStr(v.SuccessNum), | ||||
} | } | ||||
skuData := make([]md.Sku, 0) | |||||
json.Unmarshal([]byte(v.Sku), &skuData) | |||||
skuStr := "" | |||||
for _, v1 := range skuData { | |||||
if skuStr != "" { | |||||
skuStr += ";" | |||||
} | |||||
skuStr += v1.Value | |||||
} | |||||
tmp["sku_str"] = skuStr | |||||
data = append(data, tmp) | data = append(data, tmp) | ||||
} | } | ||||
} | } | ||||
enterpriseList := db.GetEnterpriseList(eg) | |||||
enterpriseData := make([]map[string]string, 0) | |||||
if enterpriseList != nil { | |||||
for _, v := range *enterpriseList { | |||||
var tmp = map[string]string{ | |||||
"id": utils.IntToStr(v.Id), | |||||
"name": v.Name, | |||||
} | |||||
enterpriseData = append(enterpriseData, tmp) | |||||
} | |||||
} | |||||
res := map[string]interface{}{ | res := map[string]interface{}{ | ||||
"total": total, | |||||
"list": data, | |||||
"total": total, | |||||
"enterprise": enterpriseData, | |||||
"list": data, | |||||
} | } | ||||
e.OutSuc(c, res, nil) | e.OutSuc(c, res, nil) | ||||
return | return | ||||
@@ -134,7 +134,7 @@ func GetAdminMore(eg *xorm.Engine, ids []int) map[int]model.Admin { | |||||
data := make(map[int]model.Admin) | data := make(map[int]model.Admin) | ||||
if len(ids) > 0 { | if len(ids) > 0 { | ||||
list := make([]model.Admin, 0) | list := make([]model.Admin, 0) | ||||
eg.In("id", ids).Find(&list) | |||||
eg.In("adm_id", ids).Find(&list) | |||||
for _, v := range list { | for _, v := range list { | ||||
data[v.AdmId] = v | data[v.AdmId] = v | ||||
} | } | ||||
@@ -26,6 +26,15 @@ func GetOrderGoodsDoingList(eg *xorm.Engine, param map[string]string) (*[]model. | |||||
} | } | ||||
sess.In("admin_id", ids) | sess.In("admin_id", ids) | ||||
} | } | ||||
if param["enterprise_name"] != "" { | |||||
var data []model.Enterprise | |||||
eg.Where("name like ?", "%"+param["enterprise_name"]+"%") | |||||
ids := []int{-1} | |||||
for _, v := range data { | |||||
ids = append(ids, v.Id) | |||||
} | |||||
sess.In("enterprise_id", ids) | |||||
} | |||||
if param["oid"] != "" { | if param["oid"] != "" { | ||||
sess.And("oid like ?", "%"+param["oid"]+"%") | sess.And("oid like ?", "%"+param["oid"]+"%") | ||||
} | } | ||||
@@ -4,6 +4,7 @@ import ( | |||||
"applet/app/db/model" | "applet/app/db/model" | ||||
"applet/app/utils" | "applet/app/utils" | ||||
"github.com/syyongx/php2go" | "github.com/syyongx/php2go" | ||||
"strings" | |||||
"xorm.io/xorm" | "xorm.io/xorm" | ||||
) | ) | ||||
@@ -69,6 +70,41 @@ func GetOrderList(eg *xorm.Engine, param map[string]string) (*[]model.Order, int | |||||
} | } | ||||
return &order, count | return &order, count | ||||
} | } | ||||
func GetOrderListOutput(eg *xorm.Engine, param map[string]string) *[]model.Order { | |||||
var order []model.Order | |||||
sess := eg.Where("1=1") | |||||
if param["phone"] != "" { | |||||
sess.And("buy_phone like ?", "%"+param["phone"]+"%") | |||||
} | |||||
if param["oid"] != "" { | |||||
sess.And("oid like ?", "%"+param["oid"]+"%") | |||||
} | |||||
if param["state"] != "" { | |||||
sess.And("state =?", param["state"]) | |||||
} | |||||
if param["ids"] != "" { | |||||
sess.In("id", strings.Split(param["ids"], ",")) | |||||
} | |||||
if param["enterprise_name"] != "" { | |||||
var enterprise []model.Enterprise | |||||
eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise) | |||||
oids := []int{-1} | |||||
for _, v := range enterprise { | |||||
oids = append(oids, v.Id) | |||||
} | |||||
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 | |||||
} | |||||
return &order | |||||
} | |||||
func GetOrderListByIpad(eg *xorm.Engine, param map[string]string) (*[]model.Order, int64) { | func GetOrderListByIpad(eg *xorm.Engine, param map[string]string) (*[]model.Order, int64) { | ||||
var order []model.Order | var order []model.Order | ||||
sess := eg.Where("state!=5") | sess := eg.Where("state!=5") | ||||
@@ -183,7 +183,7 @@ func commMake(c *gin.Context, args map[string]string) { | |||||
return | return | ||||
} | } | ||||
orderGoods.State = state | orderGoods.State = state | ||||
update, err := sess.Where("id=?", orderGoods.Id).Cols("state").Update(&orderGoods) | |||||
update, err := sess.Where("id=?", orderGoods.Id).Cols("state").Update(orderGoods) | |||||
if update == 0 || err != nil { | if update == 0 || err != nil { | ||||
sess.Rollback() | sess.Rollback() | ||||
e.OutErr(c, 400, e.NewErr(400, "提交失败,请重试")) | e.OutErr(c, 400, e.NewErr(400, "提交失败,请重试")) | ||||
@@ -70,7 +70,10 @@ func TimeParseStd(src string) time.Time { | |||||
t, _ := TimeParse("2006-01-02 15:04:05", src) | t, _ := TimeParse("2006-01-02 15:04:05", src) | ||||
return t | return t | ||||
} | } | ||||
func TimeParseDateStd(src string) time.Time { | |||||
t, _ := TimeParse("2006-01-02", src) | |||||
return t | |||||
} | |||||
func TimeStdParseUnix(src string) int64 { | func TimeStdParseUnix(src string) int64 { | ||||
t, err := TimeParse("2006-01-02 15:04:05", src) | t, err := TimeParse("2006-01-02 15:04:05", src) | ||||
if err != nil { | if err != nil { | ||||
@@ -209,18 +212,18 @@ func GetDateTimeRangeStr(s string) (string, string) { | |||||
return stime.Format("2006-01-02 15:04:05"), etime.Format("2006-01-02 15:04:05") | return stime.Format("2006-01-02 15:04:05"), etime.Format("2006-01-02 15:04:05") | ||||
} | } | ||||
//获取传入的时间所在月份的第一天,即某月第一天的0点。如传入time.Now(), 返回当前月份的第一天0点时间。 | |||||
// 获取传入的时间所在月份的第一天,即某月第一天的0点。如传入time.Now(), 返回当前月份的第一天0点时间。 | |||||
func GetFirstDateOfMonth(d time.Time) time.Time { | func GetFirstDateOfMonth(d time.Time) time.Time { | ||||
d = d.AddDate(0, 0, -d.Day()+1) | d = d.AddDate(0, 0, -d.Day()+1) | ||||
return GetZeroTime(d) | return GetZeroTime(d) | ||||
} | } | ||||
//获取传入的时间所在月份的最后一天,即某月最后一天的0点。如传入time.Now(), 返回当前月份的最后一天0点时间。 | |||||
// 获取传入的时间所在月份的最后一天,即某月最后一天的0点。如传入time.Now(), 返回当前月份的最后一天0点时间。 | |||||
func GetLastDateOfMonth(d time.Time) time.Time { | func GetLastDateOfMonth(d time.Time) time.Time { | ||||
return GetFirstDateOfMonth(d).AddDate(0, 1, -1) | return GetFirstDateOfMonth(d).AddDate(0, 1, -1) | ||||
} | } | ||||
//获取某一天的0点时间 | |||||
// 获取某一天的0点时间 | |||||
func GetZeroTime(d time.Time) time.Time { | func GetZeroTime(d time.Time) time.Time { | ||||
return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location()) | return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location()) | ||||
} | } |
@@ -0,0 +1,36 @@ | |||||
package utils | |||||
import ( | |||||
"bytes" | |||||
"fmt" | |||||
"github.com/360EntSecGroup-Skylar/excelize" | |||||
"github.com/gin-gonic/gin" | |||||
"io/ioutil" | |||||
) | |||||
func Output(c *gin.Context, name string, data map[string]string) string { | |||||
//创建excel文件 | |||||
xlsx := excelize.NewFile() | |||||
//创建新表单 | |||||
index := xlsx.NewSheet(name) | |||||
for k, v := range data { | |||||
//设置单元格的值 | |||||
xlsx.SetCellValue(name, k, v) | |||||
} | |||||
//设置默认打开的表单 | |||||
xlsx.SetActiveSheet(index) | |||||
////保存文件到指定路径 | |||||
//err := xlsx.SaveAs("./" + name + ".xlsx") | |||||
//if err != nil { | |||||
// log.Fatal(err) | |||||
//} | |||||
//_ = file.Save(fileName) | |||||
c.Header("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, name+".xlsx")) | |||||
c.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") | |||||
var buffer bytes.Buffer | |||||
_ = xlsx.Write(&buffer) | |||||
r := bytes.NewReader(buffer.Bytes()) | |||||
fSrc, _ := ioutil.ReadAll(r) | |||||
str := "data:application/vnd.ms-excel;base64," + Base64RawStdEncode(string(fSrc)) | |||||
return str | |||||
} |
@@ -3,6 +3,7 @@ module applet | |||||
go 1.15 | go 1.15 | ||||
require ( | require ( | ||||
github.com/360EntSecGroup-Skylar/excelize v1.4.1 | |||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 | github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 | ||||
github.com/antchfx/htmlquery v1.3.0 // indirect | github.com/antchfx/htmlquery v1.3.0 // indirect | ||||
github.com/antchfx/xmlquery v1.3.18 // indirect | github.com/antchfx/xmlquery v1.3.18 // indirect | ||||