fusenapi/utils/order/order_status.go

171 lines
5.2 KiB
Go
Raw Normal View History

2023-06-16 10:24:31 +00:00
package order
2023-07-21 10:17:01 +00:00
import (
"fusenapi/constants"
"fusenapi/utils/configs"
"fusenapi/utils/format"
)
2023-06-16 10:24:31 +00:00
// 获取订单生产状态
2023-06-20 08:46:56 +00:00
func GetOrderStatus(orderStatus constants.Order, deliveryMethod constants.DeliveryMethod) constants.Order {
2023-06-16 10:24:31 +00:00
switch orderStatus {
//已支付
case constants.STATUS_NEW_PART_PAY, constants.STATUS_NEW_PAY_COMPLETED, constants.STATUS_NEW_SURE:
return constants.STATUS_FONT_PAID
//生产中
case constants.STATUS_NEW_PRODUTING, constants.STATUS_NEW_PRODUT_COMPLETED:
return constants.STATUS_FONT_PRODUCTION
//运输中-直邮单
case constants.STATUS_NEW_DELIVER, constants.STATUS_NEW_UPS:
return constants.STATUS_FONT_SHIPPED
//到达-云仓
case constants.STATUS_NEW_ARRIVAL:
return constants.STATUS_FONT_INVENTORY
//订单完成
case constants.STATUS_NEW_COMPLETED:
if deliveryMethod == constants.DELIVERY_METHOD_CLOUD {
return constants.STATUS_FONT_COMPLETED_CLOUD
}
return constants.STATUS_FONT_COMPLETED
//订单关闭
default:
return constants.STATUS_FONT_CLOSED
}
}
2023-07-21 10:17:01 +00:00
type GetOrderStatusAndLogisticsReq struct {
OrderStatus constants.Order
DeliveryMethod constants.DeliveryMethod
IsPayCompleted int64
2023-07-24 04:19:34 +00:00
OrderCtime int64
2023-07-24 10:04:24 +00:00
2023-07-21 10:17:01 +00:00
SureTime int64
ProductTime int64
ProductEndtime int64
DeliverTime int64
UpsDeliverTime int64
UpsTime int64
ArrivalTime int64
RecevieTime int64
WebSetTimeInfo configs.WebSetTimeInfo
}
type GetOrderStatusAndLogisticsRes struct {
OrderStatus constants.Order
LogisticsStatus constants.Order
Times []GetOrderStatusAndLogisticsResTimes
}
type GetOrderStatusAndLogisticsResTimes struct {
Key int `json:"key"`
Time string `json:"time"`
}
// 获取订单物流状态
func GetOrderStatusAndLogistics(req GetOrderStatusAndLogisticsReq) (res GetOrderStatusAndLogisticsRes) {
var status constants.Order
logisticsStatus := constants.LOGISTICS_STATUS_DRAW
times := make([]GetOrderStatusAndLogisticsResTimes, 5)
m := 1
for i := 0; i < 5; i++ {
times[i] = GetOrderStatusAndLogisticsResTimes{
Key: m,
Time: "",
}
2023-07-24 10:04:24 +00:00
m++
2023-07-21 10:17:01 +00:00
}
switch req.OrderStatus {
//已支付
case constants.STATUS_NEW_PART_PAY, constants.STATUS_NEW_PAY_COMPLETED, constants.STATUS_NEW_SURE:
status = constants.STATUS_FONT_PAID
logisticsStatus = constants.LOGISTICS_STATUS_DRAW
//生产中
case constants.STATUS_NEW_PRODUTING, constants.STATUS_NEW_PRODUT_COMPLETED:
//直邮单有完成的物流状态
if req.DeliveryMethod == constants.DELIVERY_METHOD_ADDRESS {
if req.OrderStatus == constants.STATUS_NEW_PRODUTING {
logisticsStatus = constants.LOGISTICS_STATUS_DRAW
} else {
logisticsStatus = constants.LOGISTICS_STATUS_SHIPPING
}
}
status = constants.STATUS_FONT_PRODUCTION
//运输中-直邮单
case constants.STATUS_NEW_DELIVER, constants.STATUS_NEW_UPS:
if req.DeliveryMethod == constants.DELIVERY_METHOD_ADDRESS {
if req.OrderStatus == constants.STATUS_NEW_DELIVER {
logisticsStatus = constants.LOGISTICS_STATUS_UPS
} else {
logisticsStatus = constants.LOGISTICS_STATUS_UPS_ARRIVAL
}
}
status = constants.STATUS_FONT_SHIPPED
//到达-云仓
case constants.STATUS_NEW_ARRIVAL:
case constants.STATUS_NEW_COMPLETED:
if req.DeliveryMethod == constants.DELIVERY_METHOD_CLOUD {
status = constants.STATUS_FONT_COMPLETED_CLOUD
logisticsStatus = constants.LOGISTICS_STATUS_UPS
} else {
status = constants.STATUS_FONT_COMPLETED
logisticsStatus = constants.LOGISTICS_STATUS_ARRIVAL
}
//订单关闭
default:
status = constants.STATUS_FONT_CLOSED
}
res.OrderStatus = status
res.LogisticsStatus = logisticsStatus
var daySecond int64 = 3600 * 24
if req.DeliveryMethod == constants.DELIVERY_METHOD_ADDRESS {
switch logisticsStatus {
case constants.LOGISTICS_STATUS_DRAW:
times[1].Time = format.TimeIntToFormat(req.OrderCtime + req.WebSetTimeInfo.ProductDay*daySecond)
case constants.LOGISTICS_STATUS_SHIPPING:
if req.ProductEndtime > 0 {
times[2].Time = format.TimeIntToFormat(req.ProductEndtime + req.WebSetTimeInfo.FactoryDeliverDay*daySecond)
} else {
times[2].Time = format.TimeIntToFormat(req.OrderCtime + req.WebSetTimeInfo.FactoryDeliverDay*daySecond)
}
case constants.LOGISTICS_STATUS_UPS:
if req.DeliverTime > 0 {
times[2].Time = format.TimeIntToFormat(req.DeliverTime)
times[3].Time = format.TimeIntToFormat(req.DeliverTime + req.WebSetTimeInfo.DeliverUpsDay*daySecond)
}
case constants.LOGISTICS_STATUS_UPS_ARRIVAL:
if req.DeliverTime > 0 {
times[2].Time = format.TimeIntToFormat(req.DeliverTime)
}
if req.UpsDeliverTime > 0 {
times[3].Time = format.TimeIntToFormat(req.UpsDeliverTime)
times[4].Time = format.TimeIntToFormat(req.UpsDeliverTime + req.WebSetTimeInfo.UpsTransDay*daySecond)
}
case constants.LOGISTICS_STATUS_ARRIVAL:
if req.DeliverTime > 0 {
times[2].Time = format.TimeIntToFormat(req.DeliverTime)
}
if req.UpsDeliverTime > 0 {
times[3].Time = format.TimeIntToFormat(req.UpsDeliverTime)
}
if req.UpsTime > 0 {
times[4].Time = format.TimeIntToFormat(req.UpsTime)
}
}
res.Times = times
} else {
timesData := times[0:3]
2023-07-24 10:04:24 +00:00
if logisticsStatus == constants.LOGISTICS_STATUS_DRAW {
timesData[1].Time = format.TimeIntToFormat(req.OrderCtime + req.WebSetTimeInfo.ProductDay*daySecond)
}
2023-07-21 10:17:01 +00:00
res.Times = timesData
}
return res
}