Files
baseapi/platformapi/mtwmapi/order.go
gazebo b3edcac513 - up
2019-05-31 15:00:29 +08:00

335 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 mtwmapi
import (
"git.rosy.net.cn/baseapi/utils"
)
const (
MaxBatchPullPhoneNumberLimit = 1000
)
// http://developer.waimai.meituan.com/home/doc/food/99
const (
OrderStatusUserCommitted = "1" // 用户已提交订单
OrderStatusNew = "2" // 向商家推送订单
OrderStatusReceived = "3" // 商家已收到
OrderStatusAccepted = "4" // 商家已确认
OrderStatusDelivering = "6" // 订单配送中
OrderStatusDelivered = "7" // 订单已送达
OrderStatusFinished = "8" // 订单已完成
OrderStatusCanceled = "9" // 订单已取消
)
const (
WaybillStatusWait4Delivery = "0" // 配送单发往配送
WaybillStatusPending = "5" // 配送压单
WaybillStatusAccepted = "10" // 配送单已确认
WaybillStatusCourierArrived = "15" // 骑手已到店
WaybillStatusPickedup = "20" // 骑手已取餐
WaybillStatusDelivered = "40" // 骑手已送达
WaybillStatusCanceled = "100" // 配送单已取消
)
// APP方URL 推送用户或客服取消订单(必接)
const (
CancelReasonAcceptTimeout = 1001 // 系统取消,超时未确认
CancelReasonPayTimeout = 1002 // 系统取消在线支付订单15分钟未支付
CancelReasonPayCanceled = 1101 // 用户取消,在线支付中取消
CancelReasonCancelBeforeAccepted = 1102 // 用户取消,商家确认前取消
CancelReasonRefundCanceled = 1103 // 用户取消,用户退款取消
CancelReasonWrongOrder = 1201 // 客服取消,用户下错单
CancelReasonUserTest = 1202 // 客服取消,用户测试
CancelReasonDuplicatedOrder = 1203 // 客服取消,重复订单
CancelReasonCSOther = 1204 // 客服取消,其他原因
CancelReasonOther = 1301 // 其他原因
)
const (
ResTypePending = 0 // 未处理
ResTypeMerchantRefused = 1 // 商家驳回退款请求
ResTypeMerchantAgreed = 2 // 商家同意退款
ResTypeCSRefused = 3 // 客服驳回退款请求
ResTypeCSAgreed = 4 // 客服帮商家同意退款
ResTypeTimeoutAutoAgreed = 5 // 超过3小时自动同意
ResTypeAutoAgreed = 6 // 系统自动确认
ResTypeUserCancelApply = 7 // 用户取消退款申请
ResTypeUserCancelComplain = 8 // 用户取消退款申诉
)
const (
NotifyTypeApply = "apply" // 发起全款退款
NotifyTypePartyApply = "part" // 发起部分退款
NotifyTypeSuccess = "agree" // 确认退款
NotifyTypeReject = "reject" // 驳回退款
NotifyTypeCancelRefund = "cancelRefund" // 用户取消退款申请
NotifyTypeCancelRefundComplaint = "cancelRefundComplaint" // 用户取消退款申诉
)
const (
UserApplyCancelWaitMinute = 30 // 用户申请退款后商家未在30分钟内大连锁商家为3小时内处理退款请求系统将自动同意退款
)
const (
RefundTypeAll = 1
RefundTypePart = 2
)
const (
ExtrasPromotionTypeTaoCanZeng = 4 // 套餐赠
ExtrasPromotionTypeManZeng = 5 // 满赠
)
type RefundSku struct {
AppFoodCode string `json:"app_food_code"`
SkuID string `json:"sku_id,omitempty"`
Count int `json:"count"`
}
type RefundSkuDetail struct {
AppFoodCode string `json:"app_food_code"`
BoxNum float32 `json:"box_num"`
BoxPrice float64 `json:"box_price"`
Count int `json:"count"`
FoodName string `json:"food_name"`
FoodPrice float64 `json:"food_price"`
OriginFoodPrice float64 `json:"origin_food_price"`
RefundPrice float64 `json:"refund_price"`
SkuID string `json:"sku_id"`
Spec string `json:"spec"`
}
type RefundOrderDetail struct {
ApplyReason string `json:"apply_reason"`
ApplyType int `json:"apply_type"`
CTime int64 `json:"ctime"`
Money float64 `json:"money"`
OrderID int64 `json:"order_id"`
Pictures []string `json:"pictures"`
RefundType int `json:"refund_type"`
ResReason string `json:"res_reason"`
ResType int `json:"res_type"`
UTime int64 `json:"utime"`
WmAppRetailForOrderPartRefundList []*RefundSkuDetail `json:"wmAppRetailForOrderPartRefundList"`
WmOrderIDView int64 `json:"wm_order_id_view"`
}
type OrderExtraInfo struct {
ActDetailID int `json:"act_detail_id,omitempty"`
MtCharge float64 `json:"mt_charge,omitempty"`
PoiCharge float64 `json:"poi_charge,omitempty"`
ReduceFee float64 `json:"reduce_fee,omitempty"`
Remark string `json:"remark,omitempty"`
Type int `json:"type,omitempty"`
}
type OrderInfo struct {
AppOrderCode string `json:"app_order_code"`
AppPoiCode string `json:"app_poi_code"`
AvgSendTime int `json:"avg_send_time"`
BackupRecipientPhone string `json:"backup_recipient_phone"`
Caution string `json:"caution"`
CityID int `json:"city_id"`
Ctime int64 `json:"ctime"`
DaySeq int `json:"day_seq"`
DeliveryTime int `json:"delivery_time"`
Detail string `json:"detail"`
DinnersNumber int `json:"dinners_number"`
ExpectDeliverTime int `json:"expect_deliver_time"`
Extras string `json:"extras"`
ExtraList []*OrderExtraInfo `json:"extraList"`
HasInvoiced int `json:"has_invoiced"`
InvoiceTitle string `json:"invoice_title"`
IsFavorites bool `json:"is_favorites"`
IsPoiFirstOrder bool `json:"is_poi_first_order"`
IsPre int `json:"is_pre"`
IsThirdShipping int `json:"is_third_shipping"`
Latitude float64 `json:"latitude"`
LogisticsCode string `json:"logistics_code"`
Longitude float64 `json:"longitude"`
OrderCompletedTime int `json:"order_completed_time"`
OrderConfirmTime int `json:"order_confirm_time"`
OrderID int64 `json:"order_id"`
OrderSendTime int `json:"order_send_time"`
OriginalPrice float64 `json:"original_price"`
PackageBagMoney int `json:"package_bag_money"`
PayType int `json:"pay_type"`
PickType int `json:"pick_type"`
PoiReceiveDetail string `json:"poi_receive_detail"`
RecipientAddress string `json:"recipient_address"`
RecipientName string `json:"recipient_name"`
RecipientPhone string `json:"recipient_phone"`
Remark string `json:"remark"`
Result string `json:"result"`
ShipperPhone string `json:"shipper_phone"`
ShippingFee float64 `json:"shipping_fee"`
ShippingType int `json:"shipping_type"`
SourceID int `json:"source_id"`
Status int `json:"status"`
TaxpayerID string `json:"taxpayer_id"`
Total float64 `json:"total"`
Utime int64 `json:"utime"`
WmOrderIDView int64 `json:"wm_order_id_view"`
WmPoiAddress string `json:"wm_poi_address"`
WmPoiID int `json:"wm_poi_id"`
WmPoiName string `json:"wm_poi_name"`
WmPoiPhone string `json:"wm_poi_phone"`
}
func (a *API) OrderReceived(orderID int64) (err error) {
_, err = a.AccessAPI("order/poi_received", true, map[string]interface{}{
KeyOrderID: orderID,
})
return err
}
func (a *API) OrderConfirm(orderID int64) (err error) {
_, err = a.AccessAPI("order/confirm", true, map[string]interface{}{
KeyOrderID: orderID,
})
return err
}
func (a *API) OrderCancel(orderID int64, cancelReason string, cancelReasonCode int) (err error) {
_, err = a.AccessAPI("order/cancel", true, map[string]interface{}{
KeyOrderID: orderID,
"reason": cancelReason,
"reason_code": cancelReasonCode,
})
return err
}
func (a *API) OrderDelivering(orderID int64) (err error) {
_, err = a.AccessAPI("order/delivering", true, map[string]interface{}{
KeyOrderID: orderID,
})
return err
}
func (a *API) OrderArrived(orderID int64) (err error) {
_, err = a.AccessAPI("order/arrived", true, map[string]interface{}{
KeyOrderID: orderID,
})
return err
}
func (a *API) OrderRefundAgree(orderID int64, reason string) (err error) {
_, err = a.AccessAPI("order/refund/agree", true, map[string]interface{}{
KeyOrderID: orderID,
"reason": reason,
})
return err
}
func (a *API) OrderRefundReject(orderID int64, reason string) (err error) {
_, err = a.AccessAPI("order/refund/reject", true, map[string]interface{}{
KeyOrderID: orderID,
"reason": reason,
})
return err
}
func (a *API) OrderApplyPartRefund(orderID int64, reason string, removeSkuList []*RefundSku) (err error) {
_, err = a.AccessAPI("order/applyPartRefund", false, map[string]interface{}{
KeyOrderID: orderID,
"reason": reason,
"food_data": string(utils.MustMarshal(removeSkuList)),
})
return err
}
func (a *API) OrderViewStatus(orderID int64) (status int, err error) {
result, err := a.AccessAPI("order/viewstatus", true, map[string]interface{}{
KeyOrderID: orderID,
})
if err == nil {
return int(utils.MustInterface2Int64(result.(map[string]interface{})["status"])), nil
}
return 0, err
}
func (a *API) OrderGetOrderDetail(orderID int64, isMTLogistics bool) (orderInfo map[string]interface{}, err error) {
params := map[string]interface{}{
KeyOrderID: orderID,
}
if isMTLogistics {
params["is_mt_logistics"] = 1
}
result, err := a.AccessAPI("order/getOrderDetail", true, params)
if err == nil {
return result.(map[string]interface{}), nil
}
return nil, err
}
func (a *API) OrderGetOrderDetail2(orderID int64, isMTLogistics bool) (orderInfo *OrderInfo, err error) {
orderMap, err := a.OrderGetOrderDetail(orderID, isMTLogistics)
if err == nil {
if err = utils.Map2StructByJson(orderMap, &orderInfo, false); err == nil {
err = utils.UnmarshalUseNumber([]byte(orderInfo.Extras), &orderInfo.ExtraList)
}
}
return orderInfo, err
}
func (a *API) OrderLogisticsPush(orderID int64, reason string) (err error) {
_, err = a.AccessAPI("order/logistics/push", true, map[string]interface{}{
KeyOrderID: orderID,
})
return err
}
func (a *API) OrderLogisticsCancel(orderID int64, reason string) (err error) {
_, err = a.AccessAPI("order/logistics/cancel", true, map[string]interface{}{
KeyOrderID: orderID,
})
return err
}
func (a *API) OrderLogisticsStatus(orderID int64) (status map[string]interface{}, err error) {
result, err := a.AccessAPI("order/logistics/status", true, map[string]interface{}{
KeyOrderID: orderID,
})
if err == nil {
return result.(map[string]interface{}), nil
}
return nil, err
}
// limit最大为MaxBatchPullPhoneNumberLimit = 1000
func (a *API) OrderBatchPullPhoneNumber(poiCode string, offset, limit int) (realNumberList []map[string]interface{}, err error) {
params := map[string]interface{}{
"offset": offset,
"limit": limit,
}
if poiCode != "" {
params[KeyAppPoiCode] = poiCode
}
result, err := a.AccessAPI("order/batchPullPhoneNumber", false, params)
if err == nil {
return utils.Slice2MapSlice(result.([]interface{})), nil
}
return nil, err
}
// 专快混配送转为商家自配送
func (a *API) OrderLogisticsChange2Self(orderID int64) (err error) {
_, err = a.AccessAPI("order/logistics/change/poi_self", false, map[string]interface{}{
KeyOrderID: orderID,
})
return err
}
func (a *API) GetOrderRefundDetail(orderID int64, refundType int) (refundOrderDetail *RefundOrderDetail, err error) {
params := map[string]interface{}{
"wm_order_id_view": orderID,
}
if refundType > 0 {
params["refund_type"] = refundType
}
result, err := a.AccessAPI("ecommerce/order/getOrderRefundDetail", true, params)
if err == nil {
utils.Map2StructByJson(result.([]interface{})[0], &refundOrderDetail, false)
}
return refundOrderDetail, err
}