切换导航条
此项目
正在载入...
登录
mmm-go
/
partnermg
·
提交
转到一个项目
GitLab
转到群组
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
唐旭辉
5 years ago
提交
7933ee98da049f87e51bc629b3ae3b05c6b8460a
1 个父辈
523c16f7
更新
隐藏空白字符变更
内嵌
并排对比
正在显示
2 个修改的文件
包含
97 行增加
和
91 行删除
pkg/application/syncOrder/command/sync_bestshop.go
pkg/application/syncOrder/service/sync_order.go
pkg/application/syncOrder/command/sync_bestshop.go
查看文件 @
7933ee9
...
...
@@ -29,6 +29,7 @@ type CreateOrderFromBestshop struct {
DeliveryTime
string
`json:"deliveryTime"`
PartnerId
int64
`json:"partnerId"`
Goods
[]
struct
{
Id
int64
`json:"id"`
//货品编号
Sn
string
`json:"sn"`
//商品编号
...
...
pkg/application/syncOrder/service/sync_order.go
查看文件 @
7933ee9
...
...
@@ -43,25 +43,27 @@ func (s SyncOrderService) SyncOrderFromBestshop(cmd command.CreateOrderFromBests
//检查账号是否存在
var
(
orderBestshopDao
*
dao
.
OrderBestshopDao
orderExist
bool
)
if
orderBestshopDao
,
err
=
factory
.
CreateOrderBestshopDao
(
map
[
string
]
interface
{}{
"transactionContext"
:
transactionContext
,
});
err
!=
nil
{
return
lib
.
ThrowError
(
lib
.
TRANSACTION_ERROR
,
err
.
Error
())
}
o
k
,
err
:
=
orderBestshopDao
.
OrderExist
(
cmd
.
OrderCode
)
o
rderExist
,
err
=
orderBestshopDao
.
OrderExist
(
cmd
.
OrderCode
)
if
err
!=
nil
{
return
lib
.
ThrowError
(
lib
.
TRANSACTION_ERROR
,
"orderBestshopDao.OrderExist err:"
+
err
.
Error
())
}
if
ok
{
logs
.
Info
(
"订单已存在,order_code=%s"
,
cmd
.
OrderCode
)
return
nil
}
err
=
transactionContext
.
CommitTransaction
()
if
err
!=
nil
{
return
lib
.
ThrowError
(
lib
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
err
=
s
.
CreateOrderFromBestshop
(
cmd
)
if
orderExist
{
err
=
s
.
UpdateOrderFromBestshop
(
cmd
)
}
else
{
err
=
s
.
CreateOrderFromBestshop
(
cmd
)
}
return
err
}
...
...
@@ -115,6 +117,7 @@ func (s SyncOrderService) CreateOrderFromBestshop(cmd command.CreateOrderFromBes
goods
:=
[]
domain
.
OrderGoodBestShop
{}
for
i
:=
range
cmd
.
Goods
{
good
:=
domain
.
OrderGoodBestShop
{
Id
:
cmd
.
Goods
[
i
]
.
Id
,
OrderId
:
order
.
Id
,
Sn
:
cmd
.
Goods
[
i
]
.
Sn
,
Bn
:
cmd
.
Goods
[
i
]
.
Bn
,
...
...
@@ -257,90 +260,92 @@ func (s SyncOrderService) copyOrderBestshopToOrderBase(orderBestshop *domain.Ord
return
nil
}
// func (s SyncOrderService) UpdateOrderFromBestshop(cmd command.CreateOrderFromBestshop) error {
// var (
// transactionContext, _ = factory.CreateTransactionContext(nil)
// err error
// )
// if err = transactionContext.StartTransaction(); err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
// }
// defer func() {
// transactionContext.RollbackTransaction()
// }()
// var (
// orderBestshopRepository domain.OrderBestshopRepository
// orderGoodBestshopRepository domain.OrderGoodBestshopRepository
// )
// if orderBestshopRepository, err = factory.CreateOrderBestshopRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// }); err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
// }
// if orderGoodBestshopRepository, err = factory.CreateOrderGoodBestshopRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// }); err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
// }
// var (
// orderData *domain.OrderBestShop
// orderGoods []domain.OrderGoodBestShop
// )
// orderData, err = orderBestshopRepository.FindOne(domain.OrderBestshopFindOneQuery{
// OrderCode: cmd.OrderCode,
// })
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, "获取orderBestshop(order_code=%s)数据失败,err=%s", cmd.OrderCode, err.Error())
// }
// orderData.OrderCode = cmd.OrderCode
// orderData.OrderTime = cmd.OrderTime
// orderData.OrderState = cmd.OrderState
// orderData.OrderCount = cmd.OrderCount
// orderData.OrderAmount = cmd.OrderAmount
// orderData.PartnerId = cmd.PartnerId
// orderData.BuyerName = cmd.BuyerName
// orderData.BuyerPhone = cmd.BuyerPhone
// orderData.BuyerAddress = cmd.BuyerAddress
// orderData.BuyerRemark = cmd.BuyerRemark
// orderData.BuyerId = cmd.BuyerId
// orderData.DeliveryState = cmd.DeliveryState
// orderData.DeliveryTime = cmd.DeliveryTime
// orderData.CompanyId = cmd.CompanyId
// err = orderBestshopRepository.Edit(orderData)
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, "添加order_bestshop失败:"+err.Error())
// }
// orderGoods, err = orderGoodBestshopRepository.Find(domain.OrderGoodBestshopFindQuery{
// OrderId: orderData.Id,
// })
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, "获取orderGoodBestshop(order_id=%s)数据失败,err=%s", orderData.Id, err.Error())
// }
func
(
s
SyncOrderService
)
UpdateOrderFromBestshop
(
cmd
command
.
CreateOrderFromBestshop
)
error
{
var
(
transactionContext
,
_
=
factory
.
CreateTransactionContext
(
nil
)
err
error
)
if
err
=
transactionContext
.
StartTransaction
();
err
!=
nil
{
return
lib
.
ThrowError
(
lib
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
defer
func
()
{
transactionContext
.
RollbackTransaction
()
}()
var
(
orderBestshopRepository
domain
.
OrderBestshopRepository
orderGoodBestshopRepository
domain
.
OrderGoodBestshopRepository
)
if
orderBestshopRepository
,
err
=
factory
.
CreateOrderBestshopRepository
(
map
[
string
]
interface
{}{
"transactionContext"
:
transactionContext
,
});
err
!=
nil
{
return
lib
.
ThrowError
(
lib
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
if
orderGoodBestshopRepository
,
err
=
factory
.
CreateOrderGoodBestshopRepository
(
map
[
string
]
interface
{}{
"transactionContext"
:
transactionContext
,
});
err
!=
nil
{
return
lib
.
ThrowError
(
lib
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
var
(
orderData
*
domain
.
OrderBestShop
orderGoods
[]
domain
.
OrderGoodBestShop
)
orderData
,
err
=
orderBestshopRepository
.
FindOne
(
domain
.
OrderBestshopFindOneQuery
{
OrderCode
:
cmd
.
OrderCode
,
})
if
err
!=
nil
{
return
lib
.
ThrowError
(
lib
.
INTERNAL_SERVER_ERROR
,
"获取orderBestshop(order_code=%s)数据失败,err=%s"
,
cmd
.
OrderCode
,
err
.
Error
())
}
// for i := range orderGoods {
// var updated bool
// for ii := range cmd.Goods {
// if cmd.Goods[ii].Sn != orderGoods[i].Sn {
// continue
// }
// good := orderGoods[i]
// good.Sn= cmd.Goods[i].Sn,
// good.Bn= cmd.Goods[i].Bn,
// good.Name= cmd.Goods[i].Name,
// good.Price cmd.Goods[i].Price,
// good.Nums: cmd.Goods[i].Nums,
// good.Amount: cmd.Goods[i].Amount,
// }
// err = orderGoodBestshopRepository.Edit(&orderGoods[i])
// if err != nil {
// logs.Error("更新order_good_bestshop失败:" + err.Error())
orderData
.
OrderCode
=
cmd
.
OrderCode
orderData
.
OrderTime
=
cmd
.
OrderTime
orderData
.
OrderState
=
cmd
.
OrderState
orderData
.
OrderCount
=
cmd
.
OrderCount
orderData
.
OrderAmount
=
cmd
.
OrderAmount
orderData
.
PartnerId
=
cmd
.
PartnerId
orderData
.
BuyerName
=
cmd
.
BuyerName
orderData
.
BuyerPhone
=
cmd
.
BuyerPhone
orderData
.
BuyerAddress
=
cmd
.
BuyerAddress
orderData
.
BuyerRemark
=
cmd
.
BuyerRemark
orderData
.
BuyerId
=
cmd
.
BuyerId
orderData
.
DeliveryState
=
cmd
.
DeliveryState
orderData
.
DeliveryTime
=
cmd
.
DeliveryTime
orderData
.
CompanyId
=
cmd
.
CompanyId
err
=
orderBestshopRepository
.
Edit
(
orderData
)
if
err
!=
nil
{
return
lib
.
ThrowError
(
lib
.
INTERNAL_SERVER_ERROR
,
"添加order_bestshop失败:"
+
err
.
Error
())
}
orderGoods
,
err
=
orderGoodBestshopRepository
.
Find
(
domain
.
OrderGoodBestshopFindQuery
{
OrderId
:
orderData
.
Id
,
})
if
err
!=
nil
{
e
:=
fmt
.
Sprintf
(
"获取orderGoodBestshop(order_id=%d)数据失败,err=%s"
,
orderData
.
Id
,
err
.
Error
())
return
lib
.
ThrowError
(
lib
.
INTERNAL_SERVER_ERROR
,
e
)
}
// }
// }
// err = transactionContext.CommitTransaction()
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
// }
// return nil
// }
for
i
:=
range
orderGoods
{
var
updated
bool
for
ii
:=
range
cmd
.
Goods
{
if
cmd
.
Goods
[
ii
]
.
Id
!=
orderGoods
[
i
]
.
Id
{
continue
}
orderGoods
[
i
]
.
Sn
=
cmd
.
Goods
[
ii
]
.
Sn
orderGoods
[
i
]
.
Bn
=
cmd
.
Goods
[
ii
]
.
Bn
orderGoods
[
i
]
.
Name
=
cmd
.
Goods
[
ii
]
.
Name
orderGoods
[
i
]
.
Price
=
cmd
.
Goods
[
ii
]
.
Price
orderGoods
[
i
]
.
Nums
=
cmd
.
Goods
[
ii
]
.
Nums
orderGoods
[
i
]
.
Amount
=
cmd
.
Goods
[
ii
]
.
Amount
updated
=
true
}
if
updated
{
err
=
orderGoodBestshopRepository
.
Edit
(
&
orderGoods
[
i
])
if
err
!=
nil
{
logs
.
Error
(
"更新order_good_bestshop失败:"
+
err
.
Error
())
}
}
}
err
=
transactionContext
.
CommitTransaction
()
if
err
!=
nil
{
return
lib
.
ThrowError
(
lib
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
return
nil
}
...
...
请
注册
或
登录
后发表评论