...
|
...
|
@@ -306,12 +306,12 @@ func (serve *OrderBonusService) PayOrderGoodBonus(orderId int64, goodId int64, a |
|
|
return fmt.Errorf("更新订单数据失败,%s", err)
|
|
|
}
|
|
|
//
|
|
|
payEvent := event.PayOrderGoodBonus{
|
|
|
OrderId: orderId,
|
|
|
GoodId: goodId,
|
|
|
AdminId: adminId,
|
|
|
GoodName: updateGood.GoodName,
|
|
|
PartnerBonus: updateGood.GetCurrentPartnerBonus(),
|
|
|
payEvent := event.BatchPayOrderGoodBonus{
|
|
|
OrderBase: oldOrder,
|
|
|
Goods: []domain.OrderGood{
|
|
|
updateGood,
|
|
|
},
|
|
|
Admin: &adminUser,
|
|
|
}
|
|
|
if err = serve.Publish(payEvent); err != nil {
|
|
|
return err
|
...
|
...
|
@@ -368,3 +368,87 @@ func (serve *OrderBonusService) UpdateOrderRemarkBonus(orderId int64, adminId in |
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//BatchPayPartnerBonus 批量支付订单中货品的分红
|
|
|
func (serve *OrderBonusService) BatchPayPartnerBonus(orderIds []int64, adminId int64) error {
|
|
|
var (
|
|
|
userRepository domain.UsersRepository
|
|
|
orderBaseReponsitory domain.OrderBaseRepository
|
|
|
orderGoodRepository domain.OrderGoodRepository
|
|
|
|
|
|
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())
|
|
|
}
|
|
|
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)
|
|
|
}
|
|
|
for _, orderId := range orderIds {
|
|
|
var oldOrder *domain.OrderBase
|
|
|
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)
|
|
|
}
|
|
|
|
|
|
if ok := adminUser.InCompany(oldOrder.CompanyId); !ok {
|
|
|
return lib.ThrowError(lib.BUSINESS_ERROR, "用户不能更新非自己公司的订单")
|
|
|
}
|
|
|
var updateGoods []domain.OrderGood
|
|
|
for i := range oldOrder.Goods {
|
|
|
thisGood := oldOrder.Goods[i]
|
|
|
if thisGood.BonusStatus == domain.OrderGoodHasPay {
|
|
|
//已支付
|
|
|
continue
|
|
|
}
|
|
|
if thisGood.PartnerBonusPercent < 0 {
|
|
|
//未设置合伙人分红比例
|
|
|
continue
|
|
|
}
|
|
|
thisGood.CurrentBonusStatus.PayPartnerBonus(&thisGood)
|
|
|
oldOrder.Goods[i] = thisGood
|
|
|
//货品更新
|
|
|
updateGoods = append(updateGoods, thisGood)
|
|
|
}
|
|
|
err = oldOrder.Compute()
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, "核算订单数据失败")
|
|
|
}
|
|
|
//更新订单货品
|
|
|
if len(updateGoods) > 0 {
|
|
|
err = orderBaseReponsitory.Save(oldOrder)
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
err = orderGoodRepository.Save(updateGoods)
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
}
|
|
|
//构建事件
|
|
|
payEvent := event.BatchPayOrderGoodBonus{
|
|
|
OrderBase: oldOrder,
|
|
|
Goods: updateGoods,
|
|
|
Admin: &adminUser,
|
|
|
}
|
|
|
if err = serve.Publish(payEvent); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
|
} |
...
|
...
|
|