支持 .env 配置,并完善源头对接文档与测试订单
- 增加 .env.example 与 godotenv 加载,start.sh 自动读环境变量 - 重写发给源头的开放接口对接文档 - 订单页支持创建测试订单(可直接已支付并复制店铺订单号)
This commit is contained in:
@@ -45,30 +45,43 @@ func (h *OrderHandler) List(c *gin.Context) {
|
||||
}
|
||||
|
||||
type createOrderReq struct {
|
||||
SkinID uint `json:"skin_id" binding:"required"`
|
||||
BuyerName string `json:"buyer_name"`
|
||||
Remark string `json:"remark"`
|
||||
SkinID uint `json:"skin_id" binding:"required"`
|
||||
BuyerName string `json:"buyer_name"`
|
||||
Remark string `json:"remark"`
|
||||
Status string `json:"status"` // 管理员可传 paid 直接可发货
|
||||
DistributorID *uint `json:"distributor_id"` // 管理员可指定分销商
|
||||
}
|
||||
|
||||
func (h *OrderHandler) Create(c *gin.Context) {
|
||||
var req createOrderReq
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.BadRequest(c, "参数错误")
|
||||
response.BadRequest(c, "参数错误:请选择商品")
|
||||
return
|
||||
}
|
||||
distributorID := middleware.GetUserID(c)
|
||||
// 管理员可指定分销商
|
||||
status := ""
|
||||
// 管理员可指定分销商、创建已支付测试单
|
||||
if middleware.GetRole(c) == model.RoleAdmin {
|
||||
if req.DistributorID != nil && *req.DistributorID > 0 {
|
||||
distributorID = *req.DistributorID
|
||||
}
|
||||
if d := c.Query("distributor_id"); d != "" {
|
||||
id, _ := strconv.ParseUint(d, 10, 64)
|
||||
distributorID = uint(id)
|
||||
}
|
||||
if req.Status == model.OrderStatusPaid {
|
||||
status = model.OrderStatusPaid
|
||||
}
|
||||
}
|
||||
if req.BuyerName == "" {
|
||||
req.BuyerName = "测试买家"
|
||||
}
|
||||
order, err := h.svc.Create(service.CreateOrderInput{
|
||||
SkinID: req.SkinID,
|
||||
DistributorID: distributorID,
|
||||
BuyerName: req.BuyerName,
|
||||
Remark: req.Remark,
|
||||
Status: status,
|
||||
})
|
||||
if err != nil {
|
||||
response.BadRequest(c, err.Error())
|
||||
|
||||
Reference in New Issue
Block a user