...
|
...
|
@@ -11,19 +11,18 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
|
|
|
)
|
|
|
|
|
|
//WxOrderServices 处理来自微信小程序(海鲜干货)的订单
|
|
|
type WxOrderServices struct {
|
|
|
//OrderBonusServices 处理订单分红的相关操作
|
|
|
type OrderBonusServices struct {
|
|
|
coreDomain.BaseEventPublisher
|
|
|
transactionContext *transaction.TransactionContext
|
|
|
}
|
|
|
|
|
|
//ModifyOrderGoodData 修改订单中的单个货品的数量
|
|
|
func (serve WxOrderServices) ModifyOrderGoodNumber(orderId int64, goodId int64, adminId int64, goodNumber int) error {
|
|
|
//UpdateBounsWithGoodNumber 分红时,因修改订单中商品的数量发生分红变动
|
|
|
func (serve OrderBonusServices) UpdateBounsByGoodNumber(orderId int64, adminId int64, goodWithNumber map[int64]int) error {
|
|
|
var (
|
|
|
userRepository domain.UsersRepository
|
|
|
orderBaseReponsitory domain.OrderBaseRepository
|
|
|
orderGoodRepository domain.OrderGoodRepository
|
|
|
oldOrderGoods domain.OrderGood
|
|
|
oldOrder *domain.OrderBase
|
|
|
adminUser domain.Users
|
|
|
err error
|
...
|
...
|
@@ -44,7 +43,7 @@ func (serve WxOrderServices) ModifyOrderGoodNumber(orderId int64, goodId int64, |
|
|
}
|
|
|
oldOrder.Goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{OrderId: orderId})
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("获取订单中的货品(id=%d)数据失败,%s", goodId, err)
|
|
|
e := fmt.Sprintf("获取订单(id=%d)中的货品数据失败,%s", orderId, err)
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
adminUser, err = userRepository.FindOne(domain.UsersFindOneQuery{Id: adminId})
|
...
|
...
|
@@ -52,10 +51,7 @@ func (serve WxOrderServices) ModifyOrderGoodNumber(orderId int64, goodId int64, |
|
|
e := fmt.Sprintf("获取管理员用户(id=%d)数据失败,%s", adminId, err)
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
if adminUser.CompanyId != oldOrderGoods.CompanyId {
|
|
|
e := fmt.Sprintf("获取管理员用户(id=%d)和货品(id=%d)不在同一家公司", adminId, goodId)
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
_ = adminUser
|
|
|
//TODO数据更新操作
|
|
|
//事件发布
|
|
|
// modifyEvent := event.OrderModify{
|
...
|
...
|
@@ -69,13 +65,12 @@ func (serve WxOrderServices) ModifyOrderGoodNumber(orderId int64, goodId int64, |
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//ModifyOrderGoodData 修改订单中的单个货品的合伙人分成比例
|
|
|
func (serve WxOrderServices) ModifyOrderGoodPartnerBonusPercent(orderId int64, goodId int64, adminId int64, goodNumber int) error {
|
|
|
//UpdateBounsByPartnerBonusPercent 分红时,因修改订单中商品的合伙人分行比例发生分红变动
|
|
|
func (serve OrderBonusServices) UpdateBounsByPartnerBonusPercent(orderId int64, adminId int64, goodWithPercent map[int]float64) error {
|
|
|
var (
|
|
|
userRepository domain.UsersRepository
|
|
|
orderBaseReponsitory domain.OrderBaseRepository
|
|
|
orderGoodRepository domain.OrderGoodRepository
|
|
|
oldOrderGoods domain.OrderGood
|
|
|
oldOrder *domain.OrderBase
|
|
|
adminUser domain.Users
|
|
|
err error
|
...
|
...
|
@@ -96,7 +91,7 @@ func (serve WxOrderServices) ModifyOrderGoodPartnerBonusPercent(orderId int64, g |
|
|
}
|
|
|
oldOrder.Goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{OrderId: orderId})
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("获取订单中的货品(id=%d)数据失败,%s", goodId, err)
|
|
|
e := fmt.Sprintf("获取订单中(id=%d)的货品数据失败,%s", orderId, err)
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
adminUser, err = userRepository.FindOne(domain.UsersFindOneQuery{Id: adminId})
|
...
|
...
|
@@ -104,10 +99,7 @@ func (serve WxOrderServices) ModifyOrderGoodPartnerBonusPercent(orderId int64, g |
|
|
e := fmt.Sprintf("获取管理员用户(id=%d)数据失败,%s", adminId, err)
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
if adminUser.CompanyId != oldOrderGoods.CompanyId {
|
|
|
e := fmt.Sprintf("获取管理员用户(id=%d)和货品(id=%d)不在同一家公司", adminId, goodId)
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
_ = adminUser
|
|
|
//TODO数据更新操作
|
|
|
//事件发布
|
|
|
// modifyEvent := event.OrderModify{
|
...
|
...
|
@@ -122,8 +114,40 @@ func (serve WxOrderServices) ModifyOrderGoodPartnerBonusPercent(orderId int64, g |
|
|
}
|
|
|
|
|
|
//PayOrderGoodBonus 支付订单中货品的分红
|
|
|
func (serve WxOrderServices) PayOrderGoodBonus(goodId int64, adminId int64) error {
|
|
|
var err error
|
|
|
func (serve OrderBonusServices) PayOrderGoodBonus(orderId int64, goodId int64, adminId int64) error {
|
|
|
var (
|
|
|
userRepository domain.UsersRepository
|
|
|
orderBaseReponsitory domain.OrderBaseRepository
|
|
|
orderGoodRepository domain.OrderGoodRepository
|
|
|
oldOrder *domain.OrderBase
|
|
|
adminUser domain.Users
|
|
|
err error
|
|
|
)
|
|
|
if orderGoodRepository, err = repository.NewOrderGoodRepository(serve.transactionContext); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if orderBaseReponsitory, err = repository.NewOrderBaseRepository(serve.transactionContext); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if userRepository, err = repository.NewUsersRepository(serve.transactionContext); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
oldOrder, err = orderBaseReponsitory.FindOne(domain.OrderBaseFindOneQuery{OrderId: orderId})
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("获取订单(id=%d)数据失败,%s", orderId, err)
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
oldOrder.Goods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{OrderId: orderId})
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("获取订单中(id=%d)的货品数据失败,%s", orderId, err)
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
adminUser, err = userRepository.FindOne(domain.UsersFindOneQuery{Id: adminId})
|
|
|
if err != nil {
|
|
|
e := fmt.Sprintf("获取管理员用户(id=%d)数据失败,%s", adminId, err)
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
|
|
|
}
|
|
|
_ = adminUser
|
|
|
//TODO
|
|
|
payEvent := event.PayOrderGoodBonus{
|
|
|
GoodId: goodId,
|
...
|
...
|
|