|
@@ -13,6 +13,7 @@ import (
|
|
|
// 产品管理
|
|
|
func Order(r *GinRouter) {
|
|
|
r.POSTJWT("/order/create", OrderAdd)
|
|
|
+ r.POSTJWT("/order/createBatch", OrderAddBatch)
|
|
|
r.GETJWT("/order/list", OrderList)
|
|
|
r.POSTJWT("/order/update", OrderUpdate)
|
|
|
r.GETJWT("/order/detail/:id", OrderDetail)
|
|
@@ -20,7 +21,55 @@ func Order(r *GinRouter) {
|
|
|
r.GETJWT("/order/count", OrderCount)
|
|
|
}
|
|
|
|
|
|
-// 新增订单
|
|
|
+// 批量新增订单
|
|
|
+func OrderAddBatch(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
+ var orders []*model.OrderAddReq
|
|
|
+ err := c.ShouldBindJSON(&orders)
|
|
|
+ if err != nil {
|
|
|
+ return nil, errors.New("参数错误!")
|
|
|
+ }
|
|
|
+ ctx := apictx.CreateRepoCtx()
|
|
|
+ _userId := apictx.User.ID
|
|
|
+ userId, _ := primitive.ObjectIDFromHex(_userId)
|
|
|
+
|
|
|
+ if len(orders) < 1 {
|
|
|
+ return nil, errors.New("购物车为空")
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range orders {
|
|
|
+ order := &model.Order{}
|
|
|
+ order.UserId = userId
|
|
|
+ order.SupplyId = v.Supply.Id
|
|
|
+ order.Address = v.Address
|
|
|
+ // order.Products
|
|
|
+ // 组装商品和设置默认状态
|
|
|
+ if len(v.Products) > 0 {
|
|
|
+ for _, p := range v.Products {
|
|
|
+ order.Products = append(order.Products, &model.OrderProduct{
|
|
|
+ Id: p.ProductId,
|
|
|
+ SupplyId: p.SupplyId,
|
|
|
+ Name: p.Name,
|
|
|
+ Size: p.Size,
|
|
|
+ Color: p.Color,
|
|
|
+ Unit: p.Unit,
|
|
|
+ Cover: p.Cover,
|
|
|
+ ExpressNo: "",
|
|
|
+ Status: -1,
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ order.DeliveryMethod = v.DeliveryMethod
|
|
|
+ order.Remark = v.Remark
|
|
|
+ order.Status = -1
|
|
|
+ order.CreateTime = time.Now()
|
|
|
+ repo.RepoAddDoc(ctx, repo.CollectionOrder, order)
|
|
|
+ }
|
|
|
+
|
|
|
+ return true, nil
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
func OrderAdd(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
var form model.Order
|
|
|
err := c.ShouldBindJSON(&form)
|