...
|
...
|
@@ -2,6 +2,7 @@ package service |
|
|
|
|
|
import (
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/command"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/query"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
|
...
|
...
|
@@ -43,10 +44,25 @@ func (service OrderService) PageListOrder(listOrderQuery query.ListOrderQuery) ( |
|
|
if err != nil {
|
|
|
return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
cnt, err = orderRepository.CountAll(query)
|
|
|
if err != nil {
|
|
|
return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
var PartnerInfoRepository domain.PartnerInfoRepository
|
|
|
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
for i := range orders {
|
|
|
var partnerData *domain.PartnerInfo
|
|
|
partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: orders[i].PartnerInfo.Id})
|
|
|
if err != nil {
|
|
|
return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
orders[i].PartnerInfo = partnerData.Partner
|
|
|
}
|
|
|
return orders, cnt, nil
|
|
|
}
|
|
|
|
...
|
...
|
@@ -74,9 +90,251 @@ func (service OrderService) GetOrder(getOrderQuery query.GetOrderQuery) (*domain |
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
var PartnerInfoRepository domain.PartnerInfoRepository
|
|
|
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
var partnerData *domain.PartnerInfo
|
|
|
partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: order.PartnerInfo.Id})
|
|
|
if err != nil {
|
|
|
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
order.PartnerInfo = partnerData.Partner
|
|
|
|
|
|
return order, nil
|
|
|
}
|
|
|
|
|
|
func (service OrderService) CreateOrde() error {
|
|
|
//CreateOrderPurpose 创建意向单
|
|
|
func (service OrderService) CreateOrderPurpose(command command.CreateOrderCommand) error {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
err error
|
|
|
)
|
|
|
if err = command.ValidateCommand(); err != nil {
|
|
|
return lib.ThrowError(lib.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var PartnerInfoRepository domain.PartnerInfoRepository
|
|
|
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
var partnerData *domain.PartnerInfo
|
|
|
partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: command.PartnerId})
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
var orderRepository domain.OrderRepository
|
|
|
if orderRepository, err = factory.CreateOrderRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
newOrder := &domain.Order{
|
|
|
//订单类型
|
|
|
OrderType: domain.OrderIntention,
|
|
|
//订单编号
|
|
|
OrderCode: command.OrderCode,
|
|
|
//订单名称
|
|
|
OrderName: command.OrderName,
|
|
|
//订单状态
|
|
|
OrderStatus: domain.OrderStatusReserve,
|
|
|
//数量
|
|
|
OrderCount: command.OrderCount,
|
|
|
//实际数量
|
|
|
OrderActualCount: 0,
|
|
|
//订单金额
|
|
|
OrderAmount: command.OrderAmount,
|
|
|
//实际订单金额
|
|
|
OrderActualAmount: 0,
|
|
|
//订单已支付分红金额(货款)
|
|
|
OrderPaymentAmount: 0,
|
|
|
//订单区域信息
|
|
|
OrderRegionInfo: domain.RegionInfo{
|
|
|
RegionName: command.OrderRegion,
|
|
|
},
|
|
|
//买家
|
|
|
Buyer: domain.Buyer{
|
|
|
BuyerName: command.BuyerName,
|
|
|
ShippingAddress: command.BuyerAddress,
|
|
|
ContactInfo: command.BuyerPhone,
|
|
|
},
|
|
|
PartnerInfo: partnerData.Partner,
|
|
|
//合伙人分红百分比
|
|
|
PartnerBonusPercent: command.PartnerBonusPercent,
|
|
|
//业务员分红百分比
|
|
|
SalesmanBonusPercent: command.SalesmanBonusPercent,
|
|
|
}
|
|
|
err = orderRepository.Save(newOrder)
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//UpdateOrderPurpose 更新意向单
|
|
|
func (service OrderService) UpdateOrderPurpose(command command.UpdateOrderCommand) error {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
err error
|
|
|
)
|
|
|
if err = command.ValidateCommand(); err != nil {
|
|
|
return lib.ThrowError(lib.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var (
|
|
|
orderRepository domain.OrderRepository
|
|
|
orderData *domain.Order
|
|
|
)
|
|
|
if orderRepository, err = factory.CreateOrderRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
orderData, err = orderRepository.FindOne(domain.OrderFindOneQuery{
|
|
|
OrderId: command.Id,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
err = orderData.Update(map[string]interface{}{
|
|
|
//订单编号
|
|
|
"orderCode": command.OrderCode,
|
|
|
"oderName": command.OrderName,
|
|
|
"orderCount": command.OrderCount,
|
|
|
"orderAmount": command.OrderAmount,
|
|
|
"buyer": domain.Buyer{
|
|
|
BuyerName: orderData.Buyer.BuyerName,
|
|
|
ContactInfo: command.BuyerPhone,
|
|
|
ShippingAddress: command.BuyerAddress,
|
|
|
},
|
|
|
"orderRegion": domain.RegionInfo{
|
|
|
RegionName: command.OrderRegion,
|
|
|
},
|
|
|
"partnerBonusPercent": command.PartnerBonusPercent,
|
|
|
"salesmanBonusPercent": command.SalesmanBonusPercent,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
err = orderRepository.Save(orderData)
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//RemoveOrder 删除意向单
|
|
|
func (service OrderService) RemoveOrder(id int64) error {
|
|
|
//实际业务
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
var (
|
|
|
orderRepository domain.OrderRepository
|
|
|
order *domain.Order
|
|
|
)
|
|
|
if value, err := factory.CreateOrderRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
orderRepository = value
|
|
|
}
|
|
|
order, err = orderRepository.FindOne(domain.OrderFindOneQuery{
|
|
|
OrderId: id,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.RES_NO_FIND_ERROR, err.Error())
|
|
|
}
|
|
|
err = orderRepository.Remove(order.Id)
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//UpdateOrderReal 更新实发单
|
|
|
func (service OrderService) UpdateOrderReal(command command.UpdateOrderRealCommand) error {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
err error
|
|
|
)
|
|
|
if err = command.ValidateCommand(); err != nil {
|
|
|
return lib.ThrowError(lib.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var (
|
|
|
orderRepository domain.OrderRepository
|
|
|
orderData *domain.Order
|
|
|
)
|
|
|
if orderRepository, err = factory.CreateOrderRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
orderData, err = orderRepository.FindOne(domain.OrderFindOneQuery{
|
|
|
OrderId: command.Id,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
err = orderData.Update(map[string]interface{}{
|
|
|
//订单编号
|
|
|
"orderCode": command.OrderCode,
|
|
|
"oderName": command.OrderName,
|
|
|
"orderActualCount": command.OrderActualCount,
|
|
|
"orderActualAmount": command.OrderActualAmount,
|
|
|
"buyer": domain.Buyer{
|
|
|
BuyerName: orderData.Buyer.BuyerName,
|
|
|
ContactInfo: command.BuyerPhone,
|
|
|
ShippingAddress: command.BuyerAddress,
|
|
|
},
|
|
|
"orderRegion": domain.RegionInfo{
|
|
|
RegionName: command.OrderRegion,
|
|
|
},
|
|
|
"partnerBonusPercent": command.PartnerBonusPercent,
|
|
|
"salesmanBonusPercent": command.SalesmanBonusPercent,
|
|
|
"orderStatus": command.OrderStatus,
|
|
|
})
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
err = orderRepository.Save(orderData)
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
if err != nil {
|
|
|
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
return nil
|
|
|
} |
...
|
...
|
|