Files
jx-callback/controllers/jx_order.go
gazebo 446dc061fa - add param forceCreate for CreateWaybillOnProviders
- fix error msg bug in BaseScheduler.CreateWaybillOnProviders
2019-02-14 10:53:45 +08:00

260 lines
12 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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/business/model"
"git.rosy.net.cn/jx-callback/globals"
"github.com/astaxie/beego"
)
// 订单相关API
type OrderController struct {
beego.Controller
}
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.Ctx, params.VendorOrderID, params.VendorID, params.Ctx.GetUserName())
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.Ctx, params.VendorOrderID, params.VendorID, params.Ctx.GetUserName())
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.Ctx, params.VendorOrderID, params.VendorID, params.Ctx.GetUserName())
return nil, "", err
})
}
// @Title 创建三方运单
// @Description 创建三方运单
// @Param token header string true "认证token"
// @Param vendorOrderID formData string true "订单ID"
// @Param vendorID formData int true "订单所属的厂商ID"
// @Param forceCreate formData bool false "是否强制创建(忽略订单状态检查)"
// @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.CreateWaybillOnProvidersEx(params.Ctx, params.VendorOrderID, params.VendorID, params.ForceCreate)
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.Ctx, 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-1表示全部"
// @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.Ctx, 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.Ctx, 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.Ctx, 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.Ctx, 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.Ctx, params.FromDate, params.ToDate)
globals.SugarLogger.Debug(err)
return retVal, model.ErrorCodeIgnore, 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 orderID query string false "订单号,如果此项不为空,忽略其它所有查询条件"
// @Param keyword query string false "查询关键字"
// @Param fromDate query string true "开始日期包含格式2006-01-02"
// @Param toDate query string false "结束日期包含格式2006-01-02"
// @Param vendorIDs query string false "订单所属厂商列表[1,2,3],缺省不限制"
// @Param waybillVendorIDs query string false "承运人所属厂商列表[1,2,3],缺省不限制"
// @Param storeIDs query string false "京西门店ID列表[1,2,3],缺省不限制"
// @Param statuss query string false "订单状态列表[1,2,3],缺省不限制"
// @Param cities query string false "城市code列表[1,2,3],缺省不限制"
// @Param offset query int false "结果起始序号以0开始缺省为0"
// @Param pageSize query int false "结果页大小缺省为50-1表示全部"
// @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.Ctx, params.FromDate, params.ToDate, params.MapData, params.Offset, params.PageSize)
return retVal, "", err
})
}
// @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 waybillVendorIDs query string false "承运人所属厂商列表[1,2,3],缺省不限制"
// @Param statuss query string false "运单状态列表[1,2,3],缺省不限制"
// @Param offset query int false "结果起始序号以0开始缺省为0"
// @Param pageSize query int false "结果页大小缺省为50-1表示全部"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetWaybills [get]
func (c *OrderController) GetWaybills() {
c.callGetWaybills(func(params *tOrderGetWaybillsParams) (retVal interface{}, errCode string, err error) {
retVal, err = orderman.FixedOrderManager.GetWaybills(params.Ctx, params.FromDate, params.ToDate, params.MapData, params.Offset, params.PageSize)
return retVal, "", err
})
}
// @Title 查询订单/运单事件
// @Description 查询订单/运单事件
// @Param token header string true "认证token"
// @Param vendorOrderID query string true "订单/运单ID"
// @Param vendorID query int true "订单/运单所属厂商ID"
// @Param orderType query int true "订单1运单2订单+运单:-1"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetOrderStatusList [get]
func (c *OrderController) GetOrderStatusList() {
c.callGetOrderStatusList(func(params *tOrderGetOrderStatusListParams) (retVal interface{}, errCode string, err error) {
retVal, err = orderman.FixedOrderManager.GetOrderStatusList(params.Ctx, params.VendorOrderID, params.VendorID, params.OrderType)
return retVal, "", err
})
}