|
|
package express
|
|
|
|
|
|
import (
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"path/filepath"
|
|
|
"recook/internal/api/manage/excel"
|
|
|
"recook/internal/back"
|
|
|
"recook/internal/cache"
|
|
|
"recook/internal/dbc"
|
|
|
"recook/internal/model/order"
|
|
|
"recook/internal/static_path"
|
|
|
"recook/tools"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
type queryNoShipOrderParam struct {
|
|
|
UserID uint `json:"userId"`
|
|
|
Page uint `json:"page"`
|
|
|
}
|
|
|
|
|
|
func QuerySupportExpressCompany(c *gin.Context) {
|
|
|
back.Suc(c, "", cache.GetExpressComps())
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
查未发货订单
|
|
|
*/
|
|
|
func QueryNoShipOrderList(c *gin.Context) {
|
|
|
var p queryNoShipOrderParam
|
|
|
if err := tools.Params(&p, c); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
|
|
|
var noShipOrderList []order.Information
|
|
|
dbc.DB.Limit(20).Offset(p.Page*20).Order("id desc").Find(&noShipOrderList, "(status = 1 express_status = 0) OR (status = 1 express_status = 1)")
|
|
|
|
|
|
var total uint
|
|
|
dbc.DB.Table((&order.Information{}).TableName()).Where("(status = 1 express_status = 0) OR (status = 1 express_status = 1)").Count(&total)
|
|
|
|
|
|
var list []*excel.ExpressRow
|
|
|
for i := range noShipOrderList {
|
|
|
orderInfo := noShipOrderList[i]
|
|
|
var addr order.Addr
|
|
|
dbc.DB.First(&addr, "order_id = ?", orderInfo.ID)
|
|
|
|
|
|
var goodsList []order.GoodsDetail // 没有申请售后且没有发货
|
|
|
dbc.DB.Find(&goodsList, "order_id = ? AND ass_type = 0 AND express_status = 0", orderInfo.ID)
|
|
|
|
|
|
for _, g := range goodsList {
|
|
|
one := excel.NewWithReflect(orderInfo, g, addr)
|
|
|
list = append(list, one)
|
|
|
}
|
|
|
}
|
|
|
back.Suc(c, "", gin.H{
|
|
|
"total": total,
|
|
|
"list": list,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
type downloadNoShipOrderParam struct {
|
|
|
UserID uint `json:"userId"`
|
|
|
Status uint `json:"status"`
|
|
|
OrderID uint `json:"orderId"`
|
|
|
VendorID uint `json:"vendorId"`
|
|
|
UserName string `json:"userName"`
|
|
|
UserPhone string `json:"userPhone"`
|
|
|
StartDate string `json:"startDate"`
|
|
|
EndDate string `json:"endDate"`
|
|
|
ShippingMethod int `json:"shipping_method"`
|
|
|
}
|
|
|
type RecookExpressCompany struct {
|
|
|
ID uint
|
|
|
Name string
|
|
|
Code string
|
|
|
}
|
|
|
|
|
|
// TableName sets the insert table name for this struct type
|
|
|
func (r *RecookExpressCompany) TableName() string {
|
|
|
return "recook_express_company"
|
|
|
}
|
|
|
|
|
|
func DownloadExcelOfNoShipOrder(c *gin.Context) {
|
|
|
var p downloadNoShipOrderParam
|
|
|
if err := tools.Params(&p, c); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
where := "(recook_order_goods_detail.ass_type = 0 or (recook_order_goods_detail.ass_type != 0 and recook_order_goods_detail.is_closed=1)) AND recook_order_goods_detail.express_status = 0 AND recook_order_goods_detail.store_id = 0"
|
|
|
whereAddr := "1=1"
|
|
|
if p.UserName != "" {
|
|
|
whereAddr += " and recook_order_addr.receiver_name = '" + p.UserName + "'"
|
|
|
}
|
|
|
if p.UserPhone != "" {
|
|
|
whereAddr += " and recook_order_addr.mobile = '" + p.UserPhone + "'"
|
|
|
}
|
|
|
if p.ShippingMethod == 1 {
|
|
|
where += " and recook_order_goods_detail.shipping_method = 1"
|
|
|
} else {
|
|
|
where += " and recook_order_goods_detail.shipping_method = 0"
|
|
|
}
|
|
|
|
|
|
var goodsList []order.GoodsDetail // 没有申请售后且没有发货 售后关闭订单
|
|
|
dbc.DB.Table("recook_order_goods_detail").Select("recook_order_goods_detail.*").
|
|
|
Joins("INNER JOIN recook_order_addr on recook_order_goods_detail.order_id = recook_order_addr.order_id").
|
|
|
Where(where).Where(whereAddr).Find(&goodsList, order.GoodsDetail{
|
|
|
OrderID: p.OrderID,
|
|
|
VendorID: p.VendorID,
|
|
|
PayStatus: 1,
|
|
|
})
|
|
|
|
|
|
var list []*excel.ExpressRow
|
|
|
for i, v := range goodsList {
|
|
|
var addr order.Addr
|
|
|
dbc.DB.First(&addr, "order_id = ?", v.OrderID)
|
|
|
|
|
|
var orderInfo order.Information
|
|
|
dbc.DB.Select("pay_time, status").First(&orderInfo, v.OrderID)
|
|
|
|
|
|
if orderInfo.Status != 1 {
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
one := excel.NewWithReflect(orderInfo, goodsList[i], addr)
|
|
|
list = append(list, one)
|
|
|
}
|
|
|
var companyList []RecookExpressCompany
|
|
|
dbc.DB.Find(&companyList)
|
|
|
var newCompanList []string
|
|
|
for _, _info := range companyList {
|
|
|
newCompanList = append(newCompanList, _info.Name)
|
|
|
}
|
|
|
f := excel.CreateExcelFile(list, newCompanList)
|
|
|
name := time.Now().Format("20060102-150405") + tools.GenerateGoodsHashSign() + ".xlsx"
|
|
|
err := f.SaveAs(filepath.Join(static_path.Dir.Root, static_path.Dir.Temp, name))
|
|
|
if err != nil {
|
|
|
back.Err(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
back.Suc(c, "", gin.H{
|
|
|
// "path": filepath.Join(domain.GetName(), static_file.Dir.Static, static_file.Dir.Temp, name),
|
|
|
"path": filepath.Join(static_path.Dir.Static, static_path.Dir.Temp, name),
|
|
|
})
|
|
|
}
|
|
|
|
|
|
type downloadIsShipOrderParam struct {
|
|
|
UserID uint `json:"userId"`
|
|
|
Status uint `json:"status"` //1是已发货,2已完成
|
|
|
OrderID uint `json:"orderId"`
|
|
|
VendorID uint `json:"vendorId"`
|
|
|
UserName string `json:"userName"`
|
|
|
UserPhone string `json:"userPhone"`
|
|
|
StartDate string `json:"startDate"`
|
|
|
EndDate string `json:"endDate"`
|
|
|
ShippingMethod int `json:"shipping_method"`
|
|
|
}
|
|
|
|
|
|
func DownloadExcelOfIsShipOrder(c *gin.Context) {
|
|
|
var p downloadIsShipOrderParam
|
|
|
if err := tools.Params(&p, c); err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
//express_status快递状态 0待发货 1已发货 2确认收货
|
|
|
where := ""
|
|
|
if p.Status != 0 {
|
|
|
where = "recook_order_goods_detail.express_status = " + strconv.Itoa(int(p.Status)) + " AND recook_order_goods_detail.store_id = 0"
|
|
|
} else {
|
|
|
where = "recook_order_goods_detail.store_id = 0"
|
|
|
}
|
|
|
|
|
|
whereAddr := "1=1"
|
|
|
if p.UserName != "" {
|
|
|
whereAddr += " and recook_order_addr.receiver_name = '" + p.UserName + "'"
|
|
|
}
|
|
|
if p.UserPhone != "" {
|
|
|
whereAddr += " and recook_order_addr.mobile = '" + p.UserPhone + "'"
|
|
|
}
|
|
|
if p.ShippingMethod == 1 {
|
|
|
where += " and recook_order_goods_detail.shipping_method = 1"
|
|
|
} else {
|
|
|
where += " and recook_order_goods_detail.shipping_method = 0"
|
|
|
}
|
|
|
|
|
|
var goodsList []order.GoodsDetail
|
|
|
dbc.DB.Table("recook_order_goods_detail").Select("recook_order_goods_detail.*").
|
|
|
Joins("INNER JOIN recook_order_addr on recook_order_goods_detail.order_id = recook_order_addr.order_id").
|
|
|
Where(where).Where(whereAddr).Find(&goodsList, order.GoodsDetail{
|
|
|
PayStatus: 1,
|
|
|
})
|
|
|
|
|
|
var list []*excel.ExpressRow
|
|
|
for i, v := range goodsList {
|
|
|
var addr order.Addr
|
|
|
dbc.DB.First(&addr, "order_id = ?", v.OrderID)
|
|
|
|
|
|
var orderInfo order.Information
|
|
|
dbc.DB.Select("pay_time, status").First(&orderInfo, v.OrderID)
|
|
|
|
|
|
if orderInfo.Status == 1 || orderInfo.Status == 4 {
|
|
|
|
|
|
} else {
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
one := excel.NewWithReflect(orderInfo, goodsList[i], addr)
|
|
|
list = append(list, one)
|
|
|
}
|
|
|
var companyList []RecookExpressCompany
|
|
|
dbc.DB.Find(&companyList)
|
|
|
var newCompanList []string
|
|
|
for _, _info := range companyList {
|
|
|
newCompanList = append(newCompanList, _info.Name)
|
|
|
}
|
|
|
f := excel.CreateExcelFile(list, newCompanList)
|
|
|
name := time.Now().Format("20060102-150405") + tools.GenerateGoodsHashSign() + ".xlsx"
|
|
|
err := f.SaveAs(filepath.Join(static_path.Dir.Root, static_path.Dir.Temp, name))
|
|
|
if err != nil {
|
|
|
back.Err(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
back.Suc(c, "", gin.H{
|
|
|
// "path": filepath.Join(domain.GetName(), static_file.Dir.Static, static_file.Dir.Temp, name),
|
|
|
"path": filepath.Join(static_path.Dir.Static, static_path.Dir.Temp, name),
|
|
|
})
|
|
|
}
|