作者 yangfu

分红详情修改

@@ -60,6 +60,12 @@ func (service OrderService) GetOrder(getOrderQuery query.GetOrderQuery) (*domain @@ -60,6 +60,12 @@ func (service OrderService) GetOrder(getOrderQuery query.GetOrderQuery) (*domain
60 orderRepository domain.OrderRepository 60 orderRepository domain.OrderRepository
61 order *domain.Order 61 order *domain.Order
62 ) 62 )
  63 + if err := transactionContext.StartTransaction(); err != nil {
  64 + return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
  65 + }
  66 + defer func() {
  67 + transactionContext.RollbackTransaction()
  68 + }()
63 if value, err := factory.CreateOrderRepository(map[string]interface{}{ 69 if value, err := factory.CreateOrderRepository(map[string]interface{}{
64 "transactionContext": transactionContext, 70 "transactionContext": transactionContext,
65 }); err != nil { 71 }); err != nil {
@@ -73,7 +79,7 @@ func (service OrderService) GetOrder(getOrderQuery query.GetOrderQuery) (*domain @@ -73,7 +79,7 @@ func (service OrderService) GetOrder(getOrderQuery query.GetOrderQuery) (*domain
73 if err != nil { 79 if err != nil {
74 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 80 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
75 } 81 }
76 - 82 + err = transactionContext.CommitTransaction()
77 return order, nil 83 return order, nil
78 } 84 }
79 85
@@ -102,7 +102,7 @@ func (OrderPaymentService *OrderPaymentService) CreateOrderPayment(command *comm @@ -102,7 +102,7 @@ func (OrderPaymentService *OrderPaymentService) CreateOrderPayment(command *comm
102 } 102 }
103 103
104 // 返回订单支付列表 104 // 返回订单支付列表
105 -func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymentQuery *query.GetOrderPaymentQuery) (map[string]interface{}, []*domain.OrderPayment, error) { 105 +func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymentQuery *query.GetOrderPaymentQuery) ([]*domain.OrderPayment, error) {
106 var ( 106 var (
107 transactionContext, _ = factory.CreateTransactionContext(nil) 107 transactionContext, _ = factory.CreateTransactionContext(nil)
108 OrderDao, _ = factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext}) 108 OrderDao, _ = factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext})
@@ -110,10 +110,10 @@ func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymen @@ -110,10 +110,10 @@ func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymen
110 err error 110 err error
111 ) 111 )
112 if err = listOrderPaymentQuery.ValidateQuery(); err != nil { 112 if err = listOrderPaymentQuery.ValidateQuery(); err != nil {
113 - return nil, nil, lib.ThrowError(lib.ARG_ERROR, err.Error()) 113 + return nil, lib.ThrowError(lib.ARG_ERROR, err.Error())
114 } 114 }
115 if err := transactionContext.StartTransaction(); err != nil { 115 if err := transactionContext.StartTransaction(); err != nil {
116 - return nil, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 116 + return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
117 } 117 }
118 defer func() { 118 defer func() {
119 if err != nil { 119 if err != nil {
@@ -124,26 +124,22 @@ func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymen @@ -124,26 +124,22 @@ func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymen
124 if OrderPaymentRepository, err = factory.CreateOrderPaymentRepository(map[string]interface{}{ 124 if OrderPaymentRepository, err = factory.CreateOrderPaymentRepository(map[string]interface{}{
125 "transactionContext": transactionContext, 125 "transactionContext": transactionContext,
126 }); err != nil { 126 }); err != nil {
127 - return nil, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 127 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
128 } 128 }
129 queryOption := domain.OrderPaymentQuery{ 129 queryOption := domain.OrderPaymentQuery{
130 OrderId: listOrderPaymentQuery.OrderId, 130 OrderId: listOrderPaymentQuery.OrderId,
131 } 131 }
132 - orderBase, e := OrderDao.GetOrderBaseInfo(listOrderPaymentQuery.OrderId) 132 + _, e := OrderDao.GetOrderBaseInfo(listOrderPaymentQuery.OrderId)
133 if e != nil { 133 if e != nil {
134 - return nil, nil, e 134 + return nil, e
135 } 135 }
136 if OrderPayments, err = OrderPaymentRepository.Find(queryOption); err != nil { 136 if OrderPayments, err = OrderPaymentRepository.Find(queryOption); err != nil {
137 - return nil, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 137 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
138 } 138 }
139 - //if count, err = OrderPaymentRepository.CountAll(queryOption); err != nil {  
140 - // return nil, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
141 - //}  
142 -  
143 if err = transactionContext.CommitTransaction(); err != nil { 139 if err = transactionContext.CommitTransaction(); err != nil {
144 - return nil, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 140 + return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
145 } 141 }
146 - return orderBase, OrderPayments, nil 142 + return OrderPayments, nil
147 } 143 }
148 144
149 // 返回分红管理列表 145 // 返回分红管理列表
1 package domain 1 package domain
2 2
3 -import "time" 3 +import (
  4 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/utils"
  5 + "time"
  6 +)
4 7
5 const ( 8 const (
6 OrderStatusReserve = iota + 1 //预定中 9 OrderStatusReserve = iota + 1 //预定中
@@ -65,6 +68,37 @@ func (order Order) Update(data map[string]interface{}) error { @@ -65,6 +68,37 @@ func (order Order) Update(data map[string]interface{}) error {
65 return nil 68 return nil
66 } 69 }
67 70
  71 +//订单累计分红
  72 +func (m *Order) OrderTotalBonus() float64 {
  73 + return utils.Decimal(m.OrderActualAmount * (m.PartnerBonusPercent / 100.0))
  74 +}
  75 +
  76 +//订单已收分红
  77 +func (m *Order) OrderBonusReceive() float64 {
  78 + return utils.Decimal(m.OrderPaymentAmount * (m.PartnerBonusPercent / 100.0))
  79 +}
  80 +
  81 +//订单未收分红
  82 +func (m *Order) OrderBonusWait() float64 {
  83 + return m.OrderTotalBonus() - m.OrderBonusReceive()
  84 +}
  85 +
  86 +//分红支出
  87 +func (m *Order) OrderBonusOutstanding() float64 {
  88 + if m.OrderAmount <= m.OrderActualAmount {
  89 + return 0
  90 + }
  91 + return utils.Decimal((m.OrderAmount - m.OrderActualAmount) * (m.PartnerBonusPercent / 100.0))
  92 +}
  93 +
  94 +//订单被取消金额
  95 +func (m *Order) OrderAmountCancel() float64 {
  96 + if m.OrderAmount <= m.OrderActualAmount {
  97 + return 0
  98 + }
  99 + return utils.Decimal((m.OrderAmount - m.OrderActualAmount))
  100 +}
  101 +
68 type OrderFindOneQuery struct { 102 type OrderFindOneQuery struct {
69 OrderId int64 103 OrderId int64
70 } 104 }
@@ -2,10 +2,18 @@ package controllers @@ -2,10 +2,18 @@ package controllers
2 2
3 import ( 3 import (
4 "errors" 4 "errors"
  5 + "fmt"
5 "github.com/astaxie/beego/logs" 6 "github.com/astaxie/beego/logs"
6 OrderPaymentCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/command" 7 OrderPaymentCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/command"
7 OrderPaymentQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/query" 8 OrderPaymentQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/query"
8 OrderPaymentSvr "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/service" 9 OrderPaymentSvr "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/service"
  10 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/utils"
  11 +
  12 + OrderQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/query"
  13 + OrderSvr "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/service"
  14 +
  15 + PartnerInfoQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/query"
  16 + PartnerInfoSvr "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/service"
9 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" 17 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
10 "strconv" 18 "strconv"
11 ) 19 )
@@ -81,6 +89,8 @@ func (c *DividendsController) Detail() { @@ -81,6 +89,8 @@ func (c *DividendsController) Detail() {
81 var ( 89 var (
82 param Parameter 90 param Parameter
83 err error 91 err error
  92 + order *domain.Order
  93 + partner *domain.PartnerInfo
84 ) 94 )
85 if err = c.BindJsonData(&param); err != nil { 95 if err = c.BindJsonData(&param); err != nil {
86 logs.Error(err) 96 logs.Error(err)
@@ -88,18 +98,28 @@ func (c *DividendsController) Detail() { @@ -88,18 +98,28 @@ func (c *DividendsController) Detail() {
88 return 98 return
89 } 99 }
90 100
91 - cmd := OrderPaymentQuery.GetOrderPaymentQuery{  
92 - //OrderId: param.Id,  
93 - } 101 + cmd := OrderPaymentQuery.GetOrderPaymentQuery{}
94 cmd.OrderId, _ = strconv.ParseInt(param.Id, 10, 64) 102 cmd.OrderId, _ = strconv.ParseInt(param.Id, 10, 64)
95 - serve := OrderPaymentSvr.NewOrderPaymentService(nil) 103 +
  104 + var (
  105 + OrderPaymentSvr = OrderPaymentSvr.NewOrderPaymentService(nil)
  106 + OrderSvr = OrderSvr.NewOrderService(nil)
  107 + PartnerInfoSvr = PartnerInfoSvr.NewPartnerInfoService(nil)
  108 + )
96 var data []*domain.OrderPayment 109 var data []*domain.OrderPayment
97 - var extral map[string]interface{}  
98 - extral, data, err = serve.ListOrderPayment(&cmd) 110 + data, err = OrderPaymentSvr.ListOrderPayment(&cmd)
99 if err != nil { 111 if err != nil {
100 c.ResponseError(err) 112 c.ResponseError(err)
101 return 113 return
102 } 114 }
  115 + if order, err = OrderSvr.GetOrder(OrderQuery.GetOrderQuery{OrderId: cmd.OrderId}); err != nil {
  116 + c.ResponseError(err)
  117 + return
  118 + }
  119 + if partner, err = PartnerInfoSvr.GetPartnerInfo(PartnerInfoQuery.GetPartnerInfoQuery{Id: order.PartnerInfo.Id}); err != nil {
  120 + c.ResponseError(err)
  121 + return
  122 + }
103 123
104 type DividendPayment struct { 124 type DividendPayment struct {
105 PaymentForGoods float64 `json:"paymentForGoods"` 125 PaymentForGoods float64 `json:"paymentForGoods"`
@@ -108,8 +128,34 @@ func (c *DividendsController) Detail() { @@ -108,8 +128,34 @@ func (c *DividendsController) Detail() {
108 Dividend float64 `json:"dividend"` 128 Dividend float64 `json:"dividend"`
109 DividendProportion float64 `json:"dividendProportion"` 129 DividendProportion float64 `json:"dividendProportion"`
110 } 130 }
  131 + type Order struct {
  132 + OrderNumber string `json:"orderNumber"` //订单号
  133 + OrderState int `json:"orderState"` //订单状态
  134 + CreateTime string `json:"createTime"` //订单创建时间
  135 + OrderName string `json:"orderName"` //订单名称
  136 + OrderNum string `json:"orderNum"` //订单数量
  137 + OrderAmount string `json:"orderAmount"` //订单金额
  138 + Id string `json:"id"` //订单编号
  139 + }
  140 + type Partner struct {
  141 + PartnerName string `json:"partnerName"` //合伙人姓名
  142 + DividendProportion float64 `json:"dividendProportion"` //分红比例
  143 + DividendsReceivable float64 `json:"dividendsReceivable"` //应收分红
  144 + DividendSpending float64 `json:"dividendSpending"` //分红支出
  145 + ReceiveDividends float64 `json:"receiveDividends"` //实收分红
  146 + NotReceivedDividends float64 `json:"notReceivedDividends"` //未收分红
  147 + RceivedDividends float64 `json:"receivedDividends"` //已收分红
  148 + }
  149 + type Commission struct {
  150 + SalesmanName string `json:"salesmanName"` //业务员名称
  151 + CommissionProportion float64 `json:"commissionProportion"` //业务员抽成比例
  152 + ExpectedCommission float64 `json:"expectedCommission"` //业务员预计抽成
  153 + }
111 type Response struct { 154 type Response struct {
112 DividendPayment []DividendPayment `json:"dividendPayment"` 155 DividendPayment []DividendPayment `json:"dividendPayment"`
  156 + Order Order `json:"order"`
  157 + Partner Partner `json:"partner"`
  158 + Commission Commission `json:"commission"`
113 } 159 }
114 rsp := Response{DividendPayment: make([]DividendPayment, 0)} 160 rsp := Response{DividendPayment: make([]DividendPayment, 0)}
115 for i := range data { 161 for i := range data {
@@ -119,10 +165,35 @@ func (c *DividendsController) Detail() { @@ -119,10 +165,35 @@ func (c *DividendsController) Detail() {
119 UpdateTime: item.UpdateAt.Local().Format("2006-01-02 15:04:05"), 165 UpdateTime: item.UpdateAt.Local().Format("2006-01-02 15:04:05"),
120 StateOfPayment: item.BonusStatus, 166 StateOfPayment: item.BonusStatus,
121 Dividend: item.BonusAmount, 167 Dividend: item.BonusAmount,
122 - DividendProportion: extral["PartnerBonusPercent"].(float64), 168 + DividendProportion: order.PartnerBonusPercent,
123 } 169 }
124 rsp.DividendPayment = append(rsp.DividendPayment, payment) 170 rsp.DividendPayment = append(rsp.DividendPayment, payment)
125 } 171 }
  172 + rsp.Order = Order{
  173 + OrderNumber: order.OrderCode,
  174 + OrderState: order.OrderStatus,
  175 + CreateTime: order.CreateAt.Local().Format("2006-01-02 15:04:05"),
  176 + OrderName: order.OrderName,
  177 + OrderNum: fmt.Sprintf("%v", order.OrderCount),
  178 + OrderAmount: fmt.Sprintf("%v", order.OrderAmount),
  179 + Id: fmt.Sprintf("%v", order.Id),
  180 + }
  181 + rsp.Partner = Partner{
  182 + PartnerName: partner.Partner.PartnerName,
  183 + DividendProportion: order.PartnerBonusPercent,
  184 + DividendsReceivable: order.OrderTotalBonus() + order.OrderBonusOutstanding(), //应收分红 = 实收分红+分红支出
  185 + DividendSpending: order.OrderBonusOutstanding(), //分红支出
  186 + ReceiveDividends: order.OrderBonusReceive() + order.OrderBonusWait(), //应实收分红 = 已收分红 + 等待分红
  187 + NotReceivedDividends: order.OrderBonusWait(), //未收分红
  188 + RceivedDividends: order.OrderBonusReceive(),
  189 + }
  190 + rsp.Commission = Commission{
  191 + CommissionProportion: order.SalesmanBonusPercent,
  192 + ExpectedCommission: utils.Decimal(order.OrderActualAmount * (order.SalesmanBonusPercent / 100)),
  193 + }
  194 + if len(partner.Salesman) > 0 {
  195 + rsp.Commission.SalesmanName = partner.Salesman[0].Name
  196 + }
126 197
127 c.ResponseData(rsp) 198 c.ResponseData(rsp)
128 return 199 return