正在显示
5 个修改的文件
包含
32 行增加
和
8 行删除
@@ -3,11 +3,12 @@ package factory | @@ -3,11 +3,12 @@ package factory | ||
3 | import ( | 3 | import ( |
4 | "github.com/linmadan/egglib-go/core/application" | 4 | "github.com/linmadan/egglib-go/core/application" |
5 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg" | 5 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg" |
6 | - "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction" | 6 | + pG "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction" |
7 | ) | 7 | ) |
8 | 8 | ||
9 | func CreateTransactionContext(options map[string]interface{}) (application.TransactionContext, error) { | 9 | func CreateTransactionContext(options map[string]interface{}) (application.TransactionContext, error) { |
10 | - return &transaction.TransactionContext{ | ||
11 | - PgDd: pg.DB, | ||
12 | - }, nil | 10 | + //return &transaction.TransactionContext{ |
11 | + // PgDd: pg.DB, | ||
12 | + //}, nil | ||
13 | + return pG.NewPGTransactionContext(pg.DB), nil | ||
13 | } | 14 | } |
@@ -29,6 +29,8 @@ type CreateOrderFromBestshop struct { | @@ -29,6 +29,8 @@ type CreateOrderFromBestshop struct { | ||
29 | DeliveryTime string `json:"deliveryTime"` | 29 | DeliveryTime string `json:"deliveryTime"` |
30 | PartnerId int64 `json:"partnerId"` | 30 | PartnerId int64 `json:"partnerId"` |
31 | OrderArea string `json:"orderArea"` | 31 | OrderArea string `json:"orderArea"` |
32 | + //小程序id | ||
33 | + WxAppletId string `json:"wxAppletId"` | ||
32 | Goods []struct { | 34 | Goods []struct { |
33 | Id int64 `json:"id"` | 35 | Id int64 `json:"id"` |
34 | //货品编号 | 36 | //货品编号 |
@@ -37,7 +37,7 @@ func (s SyncOrderService) SyncOrderFromBestshop(cmd command.CreateOrderFromBests | @@ -37,7 +37,7 @@ func (s SyncOrderService) SyncOrderFromBestshop(cmd command.CreateOrderFromBests | ||
37 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | 37 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) |
38 | } | 38 | } |
39 | defer func() { | 39 | defer func() { |
40 | - transactionContext.RollbackTransaction() | 40 | + _ = transactionContext.RollbackTransaction() |
41 | }() | 41 | }() |
42 | 42 | ||
43 | //检查账号是否存在 | 43 | //检查账号是否存在 |
@@ -101,7 +101,7 @@ func (s SyncOrderService) CreateOrderFromBestshop(cmd command.CreateOrderFromBes | @@ -101,7 +101,7 @@ func (s SyncOrderService) CreateOrderFromBestshop(cmd command.CreateOrderFromBes | ||
101 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | 101 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) |
102 | } | 102 | } |
103 | defer func() { | 103 | defer func() { |
104 | - transactionContext.RollbackTransaction() | 104 | + _ = transactionContext.RollbackTransaction() |
105 | }() | 105 | }() |
106 | var ( | 106 | var ( |
107 | orderBestshopRepository domain.OrderBestshopRepository | 107 | orderBestshopRepository domain.OrderBestshopRepository |
@@ -117,6 +117,7 @@ func (s SyncOrderService) CreateOrderFromBestshop(cmd command.CreateOrderFromBes | @@ -117,6 +117,7 @@ func (s SyncOrderService) CreateOrderFromBestshop(cmd command.CreateOrderFromBes | ||
117 | }); err != nil { | 117 | }); err != nil { |
118 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | 118 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) |
119 | } | 119 | } |
120 | + // TODO 增加小程序id | ||
120 | order := domain.OrderBestShop{ | 121 | order := domain.OrderBestShop{ |
121 | OrderCode: cmd.OrderCode, | 122 | OrderCode: cmd.OrderCode, |
122 | OrderTime: cmd.OrderTime, | 123 | OrderTime: cmd.OrderTime, |
@@ -135,6 +136,7 @@ func (s SyncOrderService) CreateOrderFromBestshop(cmd command.CreateOrderFromBes | @@ -135,6 +136,7 @@ func (s SyncOrderService) CreateOrderFromBestshop(cmd command.CreateOrderFromBes | ||
135 | IsCopy: false, | 136 | IsCopy: false, |
136 | CompanyId: cmd.CompanyId, | 137 | CompanyId: cmd.CompanyId, |
137 | OrderArea: cmd.OrderArea, | 138 | OrderArea: cmd.OrderArea, |
139 | + WxAppletId: cmd.WxAppletId, | ||
138 | } | 140 | } |
139 | err = orderBestshopRepository.Add(&order) | 141 | err = orderBestshopRepository.Add(&order) |
140 | if err != nil { | 142 | if err != nil { |
@@ -232,11 +234,16 @@ func (s SyncOrderService) copyOrderBestshopToOrderBase(orderBestshop *domain.Ord | @@ -232,11 +234,16 @@ func (s SyncOrderService) copyOrderBestshopToOrderBase(orderBestshop *domain.Ord | ||
232 | e := fmt.Sprintf("未找到指定的合伙人的公司(partner_id=%d,company_id=%d)数据,%s", orderBestshop.PartnerId, partnerData.CompanyId, err) | 234 | e := fmt.Sprintf("未找到指定的合伙人的公司(partner_id=%d,company_id=%d)数据,%s", orderBestshop.PartnerId, partnerData.CompanyId, err) |
233 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e) | 235 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e) |
234 | } | 236 | } |
237 | + // TODO 判断多小程序 | ||
235 | for _, v := range companyData.Applets { | 238 | for _, v := range companyData.Applets { |
236 | //BEST_SHOP_UNIONID string = "gh_18eb644002fb" //香米小程序原始id | 239 | //BEST_SHOP_UNIONID string = "gh_18eb644002fb" //香米小程序原始id |
237 | //接收香米小程序的订单数据 | 240 | //接收香米小程序的订单数据 |
238 | - if len(v.Id) > 0 { | 241 | + //if len(v.Id) > 0 { |
242 | + // canCopyOrder = true | ||
243 | + //} | ||
244 | + if v.Id == orderBestshop.WxAppletId { | ||
239 | canCopyOrder = true | 245 | canCopyOrder = true |
246 | + break | ||
240 | } | 247 | } |
241 | } | 248 | } |
242 | if !canCopyOrder { | 249 | if !canCopyOrder { |
@@ -329,7 +336,7 @@ func (s SyncOrderService) UpdateOrderFromBestshop(cmd command.CreateOrderFromBes | @@ -329,7 +336,7 @@ func (s SyncOrderService) UpdateOrderFromBestshop(cmd command.CreateOrderFromBes | ||
329 | if err != nil { | 336 | if err != nil { |
330 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, "获取orderBestshop(order_code=%s)数据失败,err=%s", cmd.OrderCode, err.Error()) | 337 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, "获取orderBestshop(order_code=%s)数据失败,err=%s", cmd.OrderCode, err.Error()) |
331 | } | 338 | } |
332 | - | 339 | + // TODO 增加小程序id |
333 | orderData.OrderCode = cmd.OrderCode | 340 | orderData.OrderCode = cmd.OrderCode |
334 | orderData.OrderTime = cmd.OrderTime | 341 | orderData.OrderTime = cmd.OrderTime |
335 | orderData.OrderState = cmd.OrderState | 342 | orderData.OrderState = cmd.OrderState |
@@ -344,6 +351,7 @@ func (s SyncOrderService) UpdateOrderFromBestshop(cmd command.CreateOrderFromBes | @@ -344,6 +351,7 @@ func (s SyncOrderService) UpdateOrderFromBestshop(cmd command.CreateOrderFromBes | ||
344 | orderData.DeliveryState = cmd.DeliveryState | 351 | orderData.DeliveryState = cmd.DeliveryState |
345 | orderData.DeliveryTime = cmd.DeliveryTime | 352 | orderData.DeliveryTime = cmd.DeliveryTime |
346 | orderData.CompanyId = cmd.CompanyId | 353 | orderData.CompanyId = cmd.CompanyId |
354 | + orderData.WxAppletId = cmd.WxAppletId | ||
347 | err = orderBestshopRepository.Edit(orderData) | 355 | err = orderBestshopRepository.Edit(orderData) |
348 | if err != nil { | 356 | if err != nil { |
349 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, "编辑order_bestshop失败:"+err.Error()) | 357 | return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, "编辑order_bestshop失败:"+err.Error()) |
@@ -41,6 +41,8 @@ type OrderBestShop struct { | @@ -41,6 +41,8 @@ type OrderBestShop struct { | ||
41 | CompanyId int64 `json:"companyId"` | 41 | CompanyId int64 `json:"companyId"` |
42 | //订单区域 | 42 | //订单区域 |
43 | OrderArea string `json:"orderArea"` | 43 | OrderArea string `json:"orderArea"` |
44 | + // 微信小程序id | ||
45 | + WxAppletId string `jsons:"wxAppletId"` | ||
44 | } | 46 | } |
45 | 47 | ||
46 | func (order OrderBestShop) CopyToOrderBase(o *OrderBase) { | 48 | func (order OrderBestShop) CopyToOrderBase(o *OrderBase) { |
@@ -13,14 +13,18 @@ import ( | @@ -13,14 +13,18 @@ import ( | ||
13 | func DataFromXiangMi(message *sarama.ConsumerMessage) error { | 13 | func DataFromXiangMi(message *sarama.ConsumerMessage) error { |
14 | logs.Info("Done Message claimed: timestamp = %v, topic = %s offset = %v value = %v \n", | 14 | logs.Info("Done Message claimed: timestamp = %v, topic = %s offset = %v value = %v \n", |
15 | message.Timestamp, message.Topic, message.Offset, string(message.Value)) | 15 | message.Timestamp, message.Topic, message.Offset, string(message.Value)) |
16 | + | ||
16 | var ( | 17 | var ( |
17 | msgData DataFromMessage | 18 | msgData DataFromMessage |
18 | err error | 19 | err error |
19 | ) | 20 | ) |
21 | + | ||
20 | err = json.Unmarshal(message.Value, &msgData) | 22 | err = json.Unmarshal(message.Value, &msgData) |
21 | if err != nil { | 23 | if err != nil { |
22 | return fmt.Errorf("[Consumer][SyncBestshopOrder] 解析kafka数据失败;%s", err) | 24 | return fmt.Errorf("[Consumer][SyncBestshopOrder] 解析kafka数据失败;%s", err) |
23 | } | 25 | } |
26 | + | ||
27 | + // TODO 使用小程序id作为module | ||
24 | dataAction := msgData.Module + "/" + msgData.Action | 28 | dataAction := msgData.Module + "/" + msgData.Action |
25 | switch dataAction { | 29 | switch dataAction { |
26 | case "xiangmi.order/ship": | 30 | case "xiangmi.order/ship": |
@@ -29,6 +33,13 @@ func DataFromXiangMi(message *sarama.ConsumerMessage) error { | @@ -29,6 +33,13 @@ func DataFromXiangMi(message *sarama.ConsumerMessage) error { | ||
29 | e := fmt.Errorf("[Consumer][SyncBestshopOrder] %s", err) | 33 | e := fmt.Errorf("[Consumer][SyncBestshopOrder] %s", err) |
30 | return e | 34 | return e |
31 | } | 35 | } |
36 | + // TODO 统一操作小程序订单 | ||
37 | + case "wxapplet.order/ship": | ||
38 | + err = syncBestshopOrder(msgData.Data) | ||
39 | + if err != nil { | ||
40 | + e := fmt.Errorf("[Consumer][SyncBestshopOrder] %s", err) | ||
41 | + return e | ||
42 | + } | ||
32 | default: | 43 | default: |
33 | logs.Error("未找到执行动作:Module=%s,Action=%s", msgData.Module, msgData.Action) | 44 | logs.Error("未找到执行动作:Module=%s,Action=%s", msgData.Module, msgData.Action) |
34 | } | 45 | } |
-
请 注册 或 登录 后发表评论