zero-admin-3

思考并回答以下问题:

order

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package handler

import (
"net/http"

"zero-admin/api/internal/logic/order/order"
"zero-admin/api/internal/svc"
"zero-admin/api/internal/types"

"github.com/zeromicro/go-zero/rest/httpx"
)

func OrderAddHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.AddOrderReq
if err := httpx.Parse(r, &req); err != nil {
httpx.Error(w, err)
return
}

l := logic.NewOrderAddLogic(r.Context(), ctx)
resp, err := l.OrderAdd(req)
if err != nil {
httpx.Error(w, err)
} else {
httpx.OkJson(w, resp)
}
}
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package logic

import (
"context"
"encoding/json"
"zero-admin/api/internal/common/errorx"
"zero-admin/rpc/oms/omsclient"

"zero-admin/api/internal/svc"
"zero-admin/api/internal/types"

"github.com/zeromicro/go-zero/core/logx"
)

type OrderAddLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}

func NewOrderAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) OrderAddLogic {
return OrderAddLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}

func (l *OrderAddLogic) OrderAdd(req types.AddOrderReq) (*types.AddOrderResp, error) {
_, err := l.svcCtx.OrderService.OrderAdd(l.ctx, &omsclient.OrderAddReq{
MemberId: req.MemberId,
CouponId: req.CouponId,
OrderSn: req.OrderSn,
CreateTime: req.CreateTime,
MemberUsername: req.MemberUsername,
TotalAmount: req.TotalAmount,
PayAmount: req.PayAmount,
FreightAmount: req.FreightAmount,
PromotionAmount: req.PromotionAmount,
IntegrationAmount: req.IntegrationAmount,
CouponAmount: req.CouponAmount,
DiscountAmount: req.DiscountAmount,
PayType: req.PayType,
SourceType: req.SourceType,
Status: req.Status,
OrderType: req.OrderType,
DeliveryCompany: req.DeliveryCompany,
DeliverySn: req.DeliverySn,
AutoConfirmDay: req.AutoConfirmDay,
Integration: req.Integration,
Growth: req.Growth,
PromotionInfo: req.PromotionInfo,
BillType: req.BillType,
BillHeader: req.BillHeader,
BillContent: req.BillContent,
BillReceiverPhone: req.BillReceiverPhone,
BillReceiverEmail: req.BillReceiverEmail,
ReceiverName: req.ReceiverName,
ReceiverPhone: req.ReceiverPhone,
ReceiverPostCode: req.ReceiverPostCode,
ReceiverProvince: req.ReceiverProvince,
ReceiverCity: req.ReceiverCity,
ReceiverRegion: req.ReceiverRegion,
ReceiverDetailAddress: req.ReceiverDetailAddress,
Note: req.Note,
ConfirmStatus: req.ConfirmStatus,
DeleteStatus: req.DeleteStatus,
UseIntegration: req.UseIntegration,
})

if err != nil {
reqStr, _ := json.Marshal(req)
logx.WithContext(l.ctx).Errorf("添加订单信息失败,参数:%s,异常:%s", reqStr, err.Error())
return nil, errorx.NewDefaultError("添加订单信息失败")
}

return &types.AddOrderResp{
Code: "000000",
Message: "添加订单信息成功",
}, nil
}

0%