227 lines
9.8 KiB
Go
227 lines
9.8 KiB
Go
package controllers
|
||
|
||
import (
|
||
"fmt"
|
||
"strings"
|
||
"time"
|
||
|
||
"git.rosy.net.cn/baseapi/utils"
|
||
"git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
||
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/defsch"
|
||
"git.rosy.net.cn/jx-callback/globals"
|
||
"github.com/astaxie/beego"
|
||
)
|
||
|
||
// 订单相关API
|
||
type OrderController struct {
|
||
beego.Controller
|
||
}
|
||
|
||
func GetUserNameFromToken(token string) string {
|
||
userName := token
|
||
if len(userName) > 10 {
|
||
userName = userName[:10]
|
||
}
|
||
return userName
|
||
}
|
||
|
||
func (c *OrderController) URLMapping() {
|
||
c.Mapping("GetStoreOrderInfo", c.GetStoreOrderInfo)
|
||
c.Mapping("GetOrderSkuInfo", c.GetOrderSkuInfo)
|
||
|
||
c.Mapping("FinishedPickup", c.FinishedPickup)
|
||
c.Mapping("SelfDelivering", c.SelfDelivering)
|
||
c.Mapping("CreateWaybillOnProviders", c.CreateWaybillOnProviders)
|
||
c.Mapping("SelfDelivered", c.SelfDelivered)
|
||
}
|
||
|
||
// @Title 完成拣货
|
||
// @Description 完成拣货
|
||
// @Param token header string true "认证token"
|
||
// @Param vendorOrderID formData string true "订单ID"
|
||
// @Param vendorID formData int true "订单所属的厂商ID"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /FinishedPickup [post]
|
||
func (c *OrderController) FinishedPickup() {
|
||
c.callFinishedPickup(func(params *tOrderFinishedPickupParams) (retVal interface{}, errCode string, err error) {
|
||
err = defsch.FixedScheduler.PickupGoodsAndUpdateStatus(params.VendorOrderID, params.VendorID, GetUserNameFromToken(params.Token))
|
||
return nil, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 转自送
|
||
// @Description 转自送,对于配送类型为纯自送的,就是表示自送开始
|
||
// @Param token header string true "认证token"
|
||
// @Param vendorOrderID formData string true "订单ID"
|
||
// @Param vendorID formData int true "订单所属的厂商ID"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /SelfDelivering [post]
|
||
func (c *OrderController) SelfDelivering() {
|
||
c.callSelfDelivering(func(params *tOrderSelfDeliveringParams) (retVal interface{}, errCode string, err error) {
|
||
err = defsch.FixedScheduler.SelfDeliveringAndUpdateStatusExt(params.VendorOrderID, params.VendorID, GetUserNameFromToken(params.Token))
|
||
return nil, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 自送送达
|
||
// @Description 自送送达
|
||
// @Param token header string true "认证token"
|
||
// @Param vendorOrderID formData string true "订单ID"
|
||
// @Param vendorID formData int true "订单所属的厂商ID"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /SelfDelivered [post]
|
||
func (c *OrderController) SelfDelivered() {
|
||
c.callSelfDelivered(func(params *tOrderSelfDeliveredParams) (retVal interface{}, errCode string, err error) {
|
||
err = defsch.FixedScheduler.SelfDeliveredAndUpdateStatus(params.VendorOrderID, params.VendorID, GetUserNameFromToken(params.Token))
|
||
return nil, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 创建三方运单
|
||
// @Description 创建三方运单
|
||
// @Param token header string true "认证token"
|
||
// @Param vendorOrderID formData string true "订单ID"
|
||
// @Param vendorID formData int true "订单所属的厂商ID"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /CreateWaybillOnProviders [post]
|
||
func (c *OrderController) CreateWaybillOnProviders() {
|
||
c.callCreateWaybillOnProviders(func(params *tOrderCreateWaybillOnProvidersParams) (retVal interface{}, errCode string, err error) {
|
||
retVal, err = defsch.FixedScheduler.CreateWaybillOnProviders(params.VendorOrderID, params.VendorID, GetUserNameFromToken(params.Token))
|
||
return retVal, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 得到门店订单信息
|
||
// @Description 得到门店订单信息
|
||
// @Param token header string true "认证token"
|
||
// @Param storeID query string true "京西门店ID"
|
||
// @Param lastHours query int false "最近多少小时的信息(缺省为两天)"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /GetStoreOrderCountInfo [get]
|
||
func (c *OrderController) GetStoreOrderCountInfo() {
|
||
c.callGetStoreOrderCountInfo(func(params *tOrderGetStoreOrderCountInfoParams) (retVal interface{}, errCode string, err error) {
|
||
retVal, err = orderman.FixedOrderManager.GetStoreOrderCountInfo(params.StoreID, params.LastHours)
|
||
return retVal, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 得到门店订单状态信息
|
||
// @Description 得到门店订单状态信息
|
||
// @Param token header string true "认证token"
|
||
// @Param storeID query string true "京西门店ID"
|
||
// @Param lastHours query int false "最近多少小时的信息(缺省为两天)"
|
||
// @Param fromStatus query int true "起始状态(包括)"
|
||
// @Param toStatus query int false "结束状态(包括)"
|
||
// @Param offset query int false "订单列表起始序号(以0开始,缺省为0)"
|
||
// @Param pageSize query int false "订单列表页大小(缺省为50)"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /GetStoreOrderInfo [get]
|
||
func (c *OrderController) GetStoreOrderInfo() {
|
||
c.callGetStoreOrderInfo(func(params *tOrderGetStoreOrderInfoParams) (retVal interface{}, errCode string, err error) {
|
||
retVal, err = orderman.FixedOrderManager.GetStoreOrderInfo(params.StoreID, params.LastHours, params.FromStatus, params.ToStatus, params.Offset, params.PageSize)
|
||
return retVal, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 得到订单SKU信息
|
||
// @Description 得到订单SKU信息
|
||
// @Param token header string true "认证token"
|
||
// @Param vendorOrderID query string true "订单ID"
|
||
// @Param vendorID query int true "订单所属的厂商ID"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /GetOrderSkuInfo [get]
|
||
func (c *OrderController) GetOrderSkuInfo() {
|
||
c.callGetOrderSkuInfo(func(params *tOrderGetOrderSkuInfoParams) (retVal interface{}, errCode string, err error) {
|
||
retVal, err = orderman.FixedOrderManager.GetOrderSkuInfo(params.VendorOrderID, params.VendorID)
|
||
return retVal, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 得到订单详情
|
||
// @Description 得到订单详情
|
||
// @Param token header string true "认证token"
|
||
// @Param vendorOrderID query string true "订单ID"
|
||
// @Param vendorID query int true "订单所属的厂商ID"
|
||
// @Param refresh query bool false "是否从购物平台刷新数据"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /GetOrderInfo [get]
|
||
func (c *OrderController) GetOrderInfo() {
|
||
c.callGetOrderInfo(func(params *tOrderGetOrderInfoParams) (retVal interface{}, errCode string, err error) {
|
||
retVal, err = orderman.FixedOrderManager.GetOrderInfo(params.VendorOrderID, params.VendorID, params.Refresh)
|
||
return retVal, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 得到订单运单信息
|
||
// @Description 得到订单运单信息
|
||
// @Param token header string true "认证token"
|
||
// @Param vendorOrderID query string true "订单ID"
|
||
// @Param vendorID query int true "订单所属的厂商ID"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /GetOrderWaybillInfo [get]
|
||
func (c *OrderController) GetOrderWaybillInfo() {
|
||
c.callGetOrderWaybillInfo(func(params *tOrderGetOrderWaybillInfoParams) (retVal interface{}, errCode string, err error) {
|
||
retVal, err = orderman.FixedOrderManager.GetOrderWaybillInfo(params.VendorOrderID, params.VendorID)
|
||
return retVal, "", err
|
||
})
|
||
}
|
||
|
||
// @Title 导出美团运单
|
||
// @Description 导出美团运单(excel文件),注意时间跨度不要太长,最多只能是一个月
|
||
// @Param token header string true "认证token"
|
||
// @Param fromDate query string true "开始日期(包含),格式(2006-01-02)"
|
||
// @Param toDate query string false "结束日期(包含),格式(2006-01-02)"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /ExportMTWaybills [get]
|
||
func (c *OrderController) ExportMTWaybills() {
|
||
var content []byte
|
||
var fromDate, toDate string
|
||
c.callExportMTWaybills(func(params *tOrderExportMTWaybillsParams) (retVal interface{}, errCode string, err error) {
|
||
fromDate = params.FromDate
|
||
toDate = params.ToDate
|
||
if toDate == "" {
|
||
toDate = fromDate
|
||
}
|
||
content, err = orderman.FixedOrderManager.ExportMTWaybills(params.FromDate, params.ToDate)
|
||
globals.SugarLogger.Debug(err)
|
||
return retVal, ignoreCode, err
|
||
})
|
||
if content != nil {
|
||
c.Ctx.ResponseWriter.Header().Set("Content-Type", "application/vnd.ms-excel")
|
||
fileName := strings.Replace(fmt.Sprintf("attachment;filename=美团运单表%s至%sat%s.xlsx", fromDate, toDate, utils.Time2Str(time.Now())), " ", "-", 1)
|
||
c.Ctx.ResponseWriter.Header().Set("content-disposition", fileName)
|
||
c.Ctx.ResponseWriter.Write(content)
|
||
}
|
||
}
|
||
|
||
// @Title 查询订单
|
||
// @Description 查询订单
|
||
// @Param token header string true "认证token"
|
||
// @Param keyword query string false "查询关键字"
|
||
// @Param fromDate query string true "开始日期(包含),格式(2006-01-02)"
|
||
// @Param toDate query string false "结束日期(包含),格式(2006-01-02)"
|
||
// @Param vendorID query int false "订单所属厂商"
|
||
// @Param storeIDs query string false "京西门店ID列表[1,2,3],缺省不限制"
|
||
// @Param statuss query string false "订单状态列表[1,2,3],缺省不限制"
|
||
// @Param offset query int false "结果起始序号(以0开始,缺省为0)"
|
||
// @Param pageSize query int false "结果页大小(缺省为50,0表示不限制)"
|
||
// @Success 200 {object} controllers.CallResult
|
||
// @Failure 200 {object} controllers.CallResult
|
||
// @router /GetOrders [get]
|
||
func (c *OrderController) GetOrders() {
|
||
c.callGetOrders(func(params *tOrderGetOrdersParams) (retVal interface{}, errCode string, err error) {
|
||
retVal, err = orderman.FixedOrderManager.GetOrders(params.FromDate, params.ToDate, params.MapData)
|
||
return retVal, "", err
|
||
})
|
||
}
|