order_info_controlller.go
7.3 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
package controllers
import (
"errors"
"strconv"
"github.com/astaxie/beego/logs"
orderCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/command"
orderQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/query"
orderService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/service"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
)
type OrderInfoController struct {
BaseController
}
////Prepare 重写 BaseController 的Prepare方法
func (c *OrderInfoController) Prepare() {
c.BaseController.Prepare()
return
if ok := c.ValidJWTToken(); !ok {
return
}
if ok := c.ValidAdminPermission(domain.PERMISSION_ORDER); !ok {
return
}
}
//PageListOrderPurpose 分页获取意向订单列表
func (c *OrderInfoController) PageListOrderPurpose() {
type Parameter struct {
SearchText string `json:"searchText"`
Partner int64 `json:"partner"`
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(¶m); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
if param.PageNumber == 0 {
param.PageNumber = 1
}
if param.PageSize == 0 {
param.PageSize = 20
}
orderSrv := orderService.NewOrderInfoService(nil)
orderinfos, cnt, err := orderSrv.PageListOrderBase(orderQuery.ListOrderBaseQuery{
PartnerId: param.Partner,
OrderCode: param.SearchText,
OrderType: domain.OrderIntention,
Limit: param.PageSize,
Offset: (param.PageNumber - 1) * param.PageSize,
})
if err != nil {
c.ResponseError(err)
return
}
rsp := []map[string]interface{}{}
for i := range orderinfos {
orderinfo := orderinfos[i]
m := map[string]interface{}{
"createTime": orderinfo.CreateTime.Local().Format("2006-01-02 15:04:05"),
"updateTime": orderinfo.UpdateTime.Local().Format("2006-01-02 15:04:05"),
"buyer": orderinfo.Buyer.BuyerName,
"id": orderinfo.Id,
"orderId": orderinfo.OrderCode,
"partner": orderinfo.PartnerInfo.PartnerName,
"orderNum": orderinfo.OrderCompute.PlanOrderCount,
"orderPrice": orderinfo.OrderCompute.PlanOrderAmount,
"orderDist": orderinfo.RegionInfo.RegionName,
}
rsp = append(rsp, m)
}
c.ResponsePageList(rsp, cnt, param.PageNumber)
}
//GetOrderPurpose 获取意向订单详情
func (c *OrderInfoController) GetOrderPurpose() {
type Parameter struct {
Id string `json:"id"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(¶m); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
orderid, _ := strconv.ParseInt(param.Id, 10, 64)
orderSrv := orderService.NewOrderInfoService(nil)
orderinfo, err := orderSrv.GetOrderDetail(orderQuery.GetOrderQuery{
OrderId: orderid,
})
if err != nil {
c.ResponseError(err)
return
}
allGoods := []map[string]interface{}{}
for _, v := range orderinfo.Goods {
m := map[string]interface{}{
"productName": v.GoodName,
"orderNum": v.PlanGoodNumber,
"univalence": v.Price,
"partnerRatio": v.PartnerBonusPercent,
"orderPrice": v.GoodCompute.PlanAmount,
}
allGoods = append(allGoods, m)
}
rsp := map[string]interface{}{
"buyer": orderinfo.Buyer.BuyerName,
"id": orderinfo.Id,
"partnerID": orderinfo.PartnerInfo.Id,
"partner": orderinfo.PartnerInfo.PartnerName,
"orderDist": orderinfo.RegionInfo.RegionName,
"orderId": orderinfo.OrderCode,
"product": allGoods,
"commissionProportion": orderinfo.SalesmanBonusPercent,
"orderNumCount": orderinfo.OrderCompute.PlanOrderCount,
"orderAmountAdjustmentCount": orderinfo.OrderCompute.PlanOrderAmount,
}
c.ResponseData(rsp)
}
//RemoveOrderPurpose 删除意向订单
func (c *OrderInfoController) RemoveOrderPurpose() {
type Parameter struct {
Id int64 `json:"id"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(¶m); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
orderSrv := orderService.NewOrderInfoService(nil)
err = orderSrv.DeleteOrder(param.Id)
if err != nil {
c.ResponseError(err)
return
}
c.ResponseData(nil)
}
//PostPurposeOrderDetail 请求添加/更新的订单数据
type postPurposeOrderDetail struct {
Id int64 `json:"id"`
//订单编号
OrderId string `json:"orderId"`
//买家姓名
BuyerName string `json:"buyer"`
//对应合伙人 id
PartnerId int64 `json:"partnerID"`
PartnerName string `json:"partnerName"`
//业务员抽成比例
CommissionProportion float64 `json:"commissionProportion"`
//订单区域
OrderDist string `json:"orderDist"`
//商品
Product []postPurposeOrderGood `json:"product"`
}
//PostPurposeOrderGood 请求添加/更新订单中的货品
type postPurposeOrderGood struct {
Id int64 `json:"id"`
ProductName string `json:"productName"`
OrderNum int `json:"orderNum"`
Univalence float64 `json:"univalence"`
PartnerRatio float64 `json:"partnerRatio"`
}
//UpdateOrderPurpose 更新意向订单
func (c *OrderInfoController) UpdateOrderPurpose() {
//用与适配前端定义的数据结构
var (
param postPurposeOrderDetail
err error
)
if err = c.BindJsonData(¶m); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
if param.Id == 0 {
err = c.addOrderPurpose(param)
} else {
err = c.editOrderPurpose(param)
}
if err != nil {
c.ResponseError(err)
}
c.ResponseData(nil)
return
}
func (c *OrderInfoController) addOrderPurpose(param postPurposeOrderDetail) error {
orderSrv := orderService.NewOrderInfoService(nil)
newGoods := []orderCmd.OrderGoodData{}
for _, v := range param.Product {
g := orderCmd.OrderGoodData{
GoodName: v.ProductName,
PlanGoodNumber: v.OrderNum,
Price: v.Univalence,
PartnerBonusPercent: v.PartnerRatio,
}
newGoods = append(newGoods, g)
}
createcmd := orderCmd.CreateOrderCommand{
OrderType: domain.OrderIntention,
OrderCode: param.OrderId,
DeliveryCode: "",
BuyerName: param.BuyerName,
OrderRegion: param.OrderDist,
PartnerId: param.PartnerId,
SalesmanBonusPercent: param.CommissionProportion,
Goods: newGoods,
}
_, err := orderSrv.CreateNewOrder(createcmd)
return err
}
func (c *OrderInfoController) editOrderPurpose(param postPurposeOrderDetail) error {
orderSrv := orderService.NewOrderInfoService(nil)
newGoods := []orderCmd.OrderGoodData{}
for _, v := range param.Product {
g := orderCmd.OrderGoodData{
GoodName: v.ProductName,
PlanGoodNumber: v.OrderNum,
Price: v.Univalence,
PartnerBonusPercent: v.PartnerRatio,
}
newGoods = append(newGoods, g)
}
updatecmd := orderCmd.UpdateOrderCommand{
Id: param.Id,
OrderType: domain.OrderIntention,
OrderCode: param.OrderId,
DeliveryCode: "",
BuyerName: param.BuyerName,
OrderRegion: param.OrderDist,
PartnerId: param.PartnerId,
SalesmanBonusPercent: param.CommissionProportion,
Goods: newGoods,
}
_, err := orderSrv.UpdateOrderData(updatecmd)
return err
}