作者 唐旭辉

bug 修复

... ... @@ -120,8 +120,8 @@ func (subscriber *OrderLogSubscriber) HandleEvent(domainEvent coreDomain.DomainE
}
err = orderLogRepository.Add(&orderLog)
break
case event.BATCH_PAY_ORDER_GOOD_BONUS_EVENT:
currentEvent := domainEvent.(event.BatchPayOrderGoodBonus)
case event.PAY_ORDER_GOOD_BONUS_EVENT:
currentEvent := domainEvent.(event.PayOrderGoodBonus)
orderLog := domain.OrderLog{
OperatorType: domain.ORDER_LOG_OPERATOR_ADMIN,
OperatorId: currentEvent.Admin.Id,
... ... @@ -145,6 +145,34 @@ func (subscriber *OrderLogSubscriber) HandleEvent(domainEvent coreDomain.DomainE
}
err = orderLogRepository.Add(&orderLog)
break
case event.BATCH_PAY_ORDER_GOOD_BONUS_EVENT:
currentEvent := domainEvent.(event.BatchPayOrderGoodBonus)
for i := range currentEvent {
orderLog := domain.OrderLog{
OperatorType: domain.ORDER_LOG_OPERATOR_ADMIN,
OperatorId: currentEvent[i].Admin.Id,
Operator: adminUser.Name,
AlterTime: time.Now(),
DataFrom: domain.ORDER_LOG_FROM,
LogAction: "支付",
OrderId: currentEvent[i].OrderBase.Id,
Descript: []domain.OrderLogDescript{},
}
for ii := range currentEvent[i].Goods {
m := domain.OrderLogDescript{
GoodId: currentEvent[i].Goods[ii].Id,
Title: "支付分红",
Item: currentEvent[i].Goods[ii].GoodName,
Action: []string{
fmt.Sprintf(`支付分红"¥%.2f"`, currentEvent[i].Goods[ii].GetCurrentPartnerBonus()),
},
}
orderLog.Descript = append(orderLog.Descript, m)
}
err = orderLogRepository.Add(&orderLog)
}
break
}
return err
}
... ...
... ... @@ -534,110 +534,6 @@ func (service OrderInfoService) deleteOldOrderGoods(newGoods []domain.OrderGood,
return
}
//Delivery 发货
// func (service OrderInfoService) Delivery(cmd command.OrderDeliveryCommand) 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 (
// orderBaseRepository domain.OrderBaseRepository
// orderGoodRepository domain.OrderGoodRepository
// oldOrderData *domain.OrderBase
// oldOrderGoods []domain.OrderGood
// orderBaseDao *dao.OrderBaseDao
// )
// if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// }); err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
// }
// if orderGoodRepository, err = factory.CreateOrderGoodRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// }); err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
// }
// //获取旧的订单
// oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
// CompanyId: cmd.CompanyId,
// OrderId: cmd.OrderId,
// })
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))
// }
// if oldOrderData.OrderType != domain.OrderIntention {
// return lib.ThrowError(lib.BUSINESS_ERROR, "订单类型已发生变更")
// }
// if orderBaseDao, err = factory.CreateOrderBaseDao(map[string]interface{}{
// "transactionContext": transactionContext,
// }); err != nil {
// return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
// }
// //检查delivery_code是否重复
// if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.CompanyId, cmd.OrderId); err != nil {
// return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
// } else if ok {
// return lib.ThrowError(lib.BUSINESS_ERROR, "发货号已存在")
// }
// //获取旧的订单中的商品
// oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
// OrderId: cmd.OrderId,
// CompanyId: cmd.CompanyId,
// })
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单中的商品列表失败:%s", err))
// }
// for _, newGood := range cmd.Goods {
// for i := range oldOrderGoods {
// if newGood.Id != oldOrderGoods[i].Id {
// continue
// }
// oldOrderGoods[i].GoodName = newGood.GoodName
// oldOrderGoods[i].PlanGoodNumber = newGood.PlanGoodNumber
// oldOrderGoods[i].Price = newGood.Price
// oldOrderGoods[i].PartnerBonusPercent = newGood.PartnerBonusPercent
// oldOrderGoods[i].Remark = newGood.Remark
// err = oldOrderGoods[i].Compute()
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的数值失败:%s", err))
// }
// err = oldOrderGoods[i].CurrentBonusStatus.WartPayPartnerBonus(&oldOrderGoods[i])
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的分红数值失败:%s", err))
// }
// }
// }
// oldOrderData.DeliveryCode = cmd.DeliveryCode
// oldOrderData.DeliveryTime = time.Now()
// oldOrderData.Goods = oldOrderGoods
// //变更订单类型
// oldOrderData.OrderType = domain.OrderReal
// err = oldOrderData.Compute()
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中合计的数值失败:%s", err))
// }
// err = orderBaseRepository.Save(oldOrderData)
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单数据失败:%s", err))
// }
// err = orderGoodRepository.Save(oldOrderGoods)
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单中的商品数据失败:%s", err))
// }
// err = transactionContext.CommitTransaction()
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
// }
// return nil
// }
//DisableOrEnable 开启关闭订单
func (service OrderInfoService) DisableOrEnable(cmd command.DisableOrderCommand) error {
var (
... ... @@ -682,102 +578,6 @@ func (service OrderInfoService) DisableOrEnable(cmd command.DisableOrderCommand)
return nil
}
//UpdateGoodBouns 分红时,更新货品的分红相关的数值
// func (service OrderInfoService) UpdateGoodBouns(cmd command.UpdateGoodBouns) 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 (
// orderBaseRepository domain.OrderBaseRepository
// orderGoodRepository domain.OrderGoodRepository
// oldOrderData *domain.OrderBase
// oldOrderGoods []domain.OrderGood
// )
// if orderBaseRepository, err = factory.CreateOrderBaseRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// }); err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
// }
// if orderGoodRepository, err = factory.CreateOrderGoodRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// }); err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
// }
// //获取旧的订单
// oldOrderData, err = orderBaseRepository.FindOne(domain.OrderBaseFindOneQuery{
// OrderId: cmd.Id,
// CompanyId: cmd.CompanyId,
// })
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单:%s", err))
// }
// if oldOrderData.OrderType != domain.OrderReal {
// return lib.ThrowError(lib.BUSINESS_ERROR, fmt.Sprintf("指定的订单的订单类型发生变更"))
// }
// //获取旧的订单中的商品
// oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
// OrderId: cmd.Id,
// })
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("未找到指定的订单中的商品列表失败:%s", err))
// }
// for _, newGood := range cmd.GoodBouns {
// for i := range oldOrderGoods {
// if newGood.GoodId != oldOrderGoods[i].Id {
// continue
// }
// oldOrderGoods[i].UseGoodNumber = newGood.UseGoodNumber
// oldOrderGoods[i].Remark = newGood.Remark
// oldOrderGoods[i].BonusStatus = newGood.BounsStatus
// err = oldOrderGoods[i].Compute()
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的数值失败:%s", err))
// }
// switch newGood.BounsStatus {
// case domain.OrderGoodWaitPay:
// err = oldOrderGoods[i].CurrentBonusStatus.WartPayPartnerBonus(&oldOrderGoods[i])
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的分红数值失败:%s", err))
// }
// case domain.OrderGoodHasPay:
// err = oldOrderGoods[i].CurrentBonusStatus.PayPartnerBonus(&oldOrderGoods[i])
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中商品的分红数值失败:%s", err))
// }
// default:
// return lib.ThrowError(lib.ARG_ERROR, fmt.Sprintf("货品的支付状态错误"))
// }
// }
// }
// oldOrderData.Goods = oldOrderGoods
// err = oldOrderData.Compute()
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("核算订单中合计的数值失败:%s", err))
// }
// err = orderBaseRepository.Save(oldOrderData)
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单数据失败:%s", err))
// }
// err = orderGoodRepository.Save(oldOrderGoods)
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("保存订单中的商品数据失败:%s", err))
// }
// err = transactionContext.CommitTransaction()
// if err != nil {
// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
// }
// return nil
// }
//PageListOrderBouns 获取订单的分红列表
func (service OrderInfoService) PageListOrderBonus(listOrderQuery query.ListOrderBonusQuery) ([]map[string]interface{}, int, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
... ...
... ... @@ -4,37 +4,24 @@ import "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
const (
//支付订单中货品的分红
//PAY_ORDER_GOOD_BONUS_EVENT string = "PayOrderGoodBonus"
PAY_ORDER_GOOD_BONUS_EVENT string = "PayOrderGoodBonus"
BATCH_PAY_ORDER_GOOD_BONUS_EVENT string = "BatchPayOrderGoodBonus"
)
//PayOrderGoodBonus
//事件:支付订单中货品的分红
// type PayOrderGoodBonus struct {
// //订单id
// OrderId int64
// //货品名称
// GoodName string
// //订单中的货品id
// GoodId int64
// //管理员id
// AdminId int64
// //分红额度
// PartnerBonus float64
// }
type BatchPayOrderGoodBonus []PayOrderGoodBonus
// func (p PayOrderGoodBonus) EventType() string {
// return PAY_ORDER_GOOD_BONUS_EVENT
// }
func (p BatchPayOrderGoodBonus) EventType() string {
return BATCH_PAY_ORDER_GOOD_BONUS_EVENT
}
//PayOrderGoodBonus
//事件:批量支付一个订单中货品的分红
type BatchPayOrderGoodBonus struct {
type PayOrderGoodBonus struct {
OrderBase *domain.OrderBase
Goods []domain.OrderGood
Admin *domain.Users
}
func (p BatchPayOrderGoodBonus) EventType() string {
return BATCH_PAY_ORDER_GOOD_BONUS_EVENT
func (p PayOrderGoodBonus) EventType() string {
return PAY_ORDER_GOOD_BONUS_EVENT
}
... ...
... ... @@ -306,7 +306,7 @@ func (serve *OrderBonusService) PayOrderGoodBonus(orderId int64, goodId int64, a
return fmt.Errorf("更新订单数据失败,%s", err)
}
//
payEvent := event.BatchPayOrderGoodBonus{
payEvent := event.PayOrderGoodBonus{
OrderBase: oldOrder,
Goods: []domain.OrderGood{
updateGood,
... ... @@ -393,6 +393,7 @@ func (serve *OrderBonusService) BatchPayPartnerBonus(orderIds []int64, adminId i
e := fmt.Sprintf("获取管理员用户(id=%d)数据失败,%s", adminId, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
var payEvents []event.PayOrderGoodBonus
for _, orderId := range orderIds {
var oldOrder *domain.OrderBase
oldOrder, err = orderBaseReponsitory.FindOne(domain.OrderBaseFindOneQuery{OrderId: orderId})
... ... @@ -441,14 +442,15 @@ func (serve *OrderBonusService) BatchPayPartnerBonus(orderIds []int64, adminId i
}
}
//构建事件
payEvent := event.BatchPayOrderGoodBonus{
payEvent := event.PayOrderGoodBonus{
OrderBase: oldOrder,
Goods: updateGoods,
Admin: &adminUser,
}
if err = serve.Publish(payEvent); err != nil {
return err
}
payEvents = append(payEvents, payEvent)
}
if err = serve.Publish(event.BatchPayOrderGoodBonus(payEvents)); err != nil {
return err
}
return nil
}
... ...