- ExportMTWaybills

- Obj2Excel
This commit is contained in:
gazebo
2018-09-30 18:58:05 +08:00
parent 834a5b9c24
commit d0df68740e
5 changed files with 200 additions and 0 deletions

View File

@@ -3,8 +3,11 @@ package orderman
import (
"time"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/basesch"
"git.rosy.net.cn/jx-callback/business/jxutils/excel"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/globals"
"github.com/astaxie/beego/orm"
)
@@ -15,6 +18,12 @@ const (
defPageSize = 50
)
type tMTWaybillExport struct {
model.Waybill
StoreName string
StoreID int `orm:"column(store_id)"`
}
func (c *OrderManager) GetStoreOrderInfo(storeID string, lastHours int, fromStatus, toStatus, offset, pageSize int) (orders []*model.GoodsOrderExt, err error) {
globals.SugarLogger.Debugf("GetStoreOrderInfo storeID:%s", storeID)
if lastHours > maxLastHours {
@@ -167,3 +176,44 @@ func (c *OrderManager) GetOrderWaybillInfo(vendorOrderID string, vendorID int) (
globals.SugarLogger.Infof("GetOrderWaybillInfo orderID:%s failed with error:%v", vendorOrderID, err)
return nil, err
}
func (c *OrderManager) ExportMTWaybills(fromDateStr, toDateStr string) (excelContent []byte, err error) {
globals.SugarLogger.Debugf("ExportMTWaybills from:%s to:%s", fromDateStr, toDateStr)
fromDate := utils.Str2Time(fromDateStr)
if toDateStr == "" {
toDateStr = fromDateStr
}
toDate := utils.Str2Time(toDateStr)
var waybills []*tMTWaybillExport
sql := `
SELECT t1.*, t2.store_name, IF(t2.store_id <> 0, t2.store_id, t2.jx_store_id) store_id
FROM waybill t1
JOIN goods_order t2 ON t1.vendor_order_id = t2.vendor_order_id
WHERE t1.waybill_vendor_id = 102 AND t1.status = 105 AND t1.waybill_created_at >= ? AND t1.waybill_created_at <= ?
ORDER BY t1.id
`
db := dao.GetDB()
if err = dao.GetRows(db, &waybills, sql, fromDate, toDate); err == nil {
config := []*excel.Obj2ExcelSheetConfig{
&excel.Obj2ExcelSheetConfig{
Title: "Sheet1",
Data: waybills,
CaptionList: []string{
"VendorWaybillID",
"WaybillVendorID",
"VendorOrderID",
"OrderVendorID",
"StoreName",
"StoreID",
"CourierName",
"Status",
"DesiredFee",
"WaybillCreatedAt",
},
},
}
return excel.Obj2Excel(config), nil
}
return nil, err
}