feat: add manual fulfillment order creation
This commit is contained in:
@@ -2,6 +2,7 @@ package handler
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"affiliate_dash/internal/middleware"
|
||||
@@ -76,14 +77,64 @@ func (h *MerchantHandler) UpdateProductStatus(c *gin.Context) {
|
||||
|
||||
func (h *MerchantHandler) ListOrders(c *gin.Context) {
|
||||
page, size := pageParams(c)
|
||||
list, total, err := h.fulfillmentSvc.ListOrders(middleware.GetMerchantID(c), page, size, c.Query("order_status"))
|
||||
orderSource := strings.TrimSpace(c.Query("order_source"))
|
||||
list, total, err := h.fulfillmentSvc.ListOrders(middleware.GetMerchantID(c), page, size, c.Query("order_status"), orderSource)
|
||||
if err != nil {
|
||||
if orderSource != "" && err.Error() == "无效的订单来源" {
|
||||
response.BadRequest(c, err.Error())
|
||||
return
|
||||
}
|
||||
response.ServerError(c, err.Error())
|
||||
return
|
||||
}
|
||||
response.Page(c, list, total, page, size)
|
||||
}
|
||||
|
||||
type merchantManualOrderReq struct {
|
||||
ClientOrderNo string `json:"client_order_no" binding:"required,max=96"`
|
||||
SKU string `json:"sku" binding:"required,max=96"`
|
||||
Quantity int64 `json:"quantity"`
|
||||
BuyerReference string `json:"buyer_reference" binding:"max=128"`
|
||||
GameAccount string `json:"game_account" binding:"max=128"`
|
||||
Note string `json:"note" binding:"max=512"`
|
||||
}
|
||||
|
||||
// CreateManualOrder 在商户后台创建真实订单;扣款、库存和回调与开放 API 下单保持一致。
|
||||
func (h *MerchantHandler) CreateManualOrder(c *gin.Context) {
|
||||
var req merchantManualOrderReq
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.BadRequest(c, "参数错误:商户单号与商品必填")
|
||||
return
|
||||
}
|
||||
data := map[string]string{}
|
||||
if gameAccount := strings.TrimSpace(req.GameAccount); gameAccount != "" {
|
||||
data["game_account"] = gameAccount
|
||||
}
|
||||
if note := strings.TrimSpace(req.Note); note != "" {
|
||||
data["manual_note"] = note
|
||||
}
|
||||
result, err := h.fulfillmentSvc.CreateManualOrder(service.CreateManualOrderInput{
|
||||
MerchantID: middleware.GetMerchantID(c),
|
||||
ActorUserID: middleware.GetUserID(c),
|
||||
ClientOrderNo: req.ClientOrderNo,
|
||||
SKU: req.SKU,
|
||||
Quantity: req.Quantity,
|
||||
BuyerReference: req.BuyerReference,
|
||||
RequestData: data,
|
||||
})
|
||||
if err != nil {
|
||||
response.BadRequest(c, err.Error())
|
||||
return
|
||||
}
|
||||
canShip, cannotShipReason := service.CanFulfill(result.Order)
|
||||
response.OK(c, gin.H{
|
||||
"order": result.Order,
|
||||
"idempotent": result.Idempotent,
|
||||
"can_ship": canShip,
|
||||
"cannot_ship_reason": cannotShipReason,
|
||||
})
|
||||
}
|
||||
|
||||
type merchantTestOrderReq struct {
|
||||
SKU string `json:"sku" binding:"required"`
|
||||
BuyerReference string `json:"buyer_reference"`
|
||||
|
||||
Reference in New Issue
Block a user