作者 tangxvhui

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/partnermg into dev

# Conflicts:
#	pkg/application/order/service/order.go
#	pkg/domain/order.go
@@ -2,8 +2,8 @@ package query @@ -2,8 +2,8 @@ package query
2 2
3 type ListDividendOrdersQuery struct { 3 type ListDividendOrdersQuery struct {
4 // 合伙人类别 4 // 合伙人类别
5 - PartnerName string `json:"partnerName"`  
6 - OrderNumber string `json:"orderNumber"` 5 + PartnerId string `json:"partnerId"`
  6 + SearchText string `json:"searchText"`
7 PageSize int `json:"pageSize"` 7 PageSize int `json:"pageSize"`
8 PageNumber int `json:"pageNumber"` 8 PageNumber int `json:"pageNumber"`
9 } 9 }
1 package service 1 package service
2 2
3 import ( 3 import (
  4 + "fmt"
4 "github.com/linmadan/egglib-go/core/application" 5 "github.com/linmadan/egglib-go/core/application"
5 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory" 6 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
6 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/command" 7 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/command"
@@ -101,7 +102,7 @@ func (OrderPaymentService *OrderPaymentService) CreateOrderPayment(command *comm @@ -101,7 +102,7 @@ func (OrderPaymentService *OrderPaymentService) CreateOrderPayment(command *comm
101 } 102 }
102 103
103 // 返回订单支付列表 104 // 返回订单支付列表
104 -func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymentQuery *query.GetOrderPaymentQuery) (map[string]interface{}, []*domain.OrderPayment, error) { 105 +func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymentQuery *query.GetOrderPaymentQuery) ([]*domain.OrderPayment, error) {
105 var ( 106 var (
106 transactionContext, _ = factory.CreateTransactionContext(nil) 107 transactionContext, _ = factory.CreateTransactionContext(nil)
107 OrderDao, _ = factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext}) 108 OrderDao, _ = factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext})
@@ -109,10 +110,10 @@ func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymen @@ -109,10 +110,10 @@ func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymen
109 err error 110 err error
110 ) 111 )
111 if err = listOrderPaymentQuery.ValidateQuery(); err != nil { 112 if err = listOrderPaymentQuery.ValidateQuery(); err != nil {
112 - return nil, nil, lib.ThrowError(lib.ARG_ERROR, err.Error()) 113 + return nil, lib.ThrowError(lib.ARG_ERROR, err.Error())
113 } 114 }
114 if err := transactionContext.StartTransaction(); err != nil { 115 if err := transactionContext.StartTransaction(); err != nil {
115 - return nil, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 116 + return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
116 } 117 }
117 defer func() { 118 defer func() {
118 if err != nil { 119 if err != nil {
@@ -123,26 +124,22 @@ func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymen @@ -123,26 +124,22 @@ func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymen
123 if OrderPaymentRepository, err = factory.CreateOrderPaymentRepository(map[string]interface{}{ 124 if OrderPaymentRepository, err = factory.CreateOrderPaymentRepository(map[string]interface{}{
124 "transactionContext": transactionContext, 125 "transactionContext": transactionContext,
125 }); err != nil { 126 }); err != nil {
126 - return nil, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 127 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
127 } 128 }
128 queryOption := domain.OrderPaymentQuery{ 129 queryOption := domain.OrderPaymentQuery{
129 OrderId: listOrderPaymentQuery.OrderId, 130 OrderId: listOrderPaymentQuery.OrderId,
130 } 131 }
131 - orderBase, e := OrderDao.GetOrderBaseInfo(listOrderPaymentQuery.OrderId) 132 + _, e := OrderDao.GetOrderBaseInfo(listOrderPaymentQuery.OrderId)
132 if e != nil { 133 if e != nil {
133 - return nil, nil, e 134 + return nil, e
134 } 135 }
135 if OrderPayments, err = OrderPaymentRepository.Find(queryOption); err != nil { 136 if OrderPayments, err = OrderPaymentRepository.Find(queryOption); err != nil {
136 - return nil, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 137 + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
137 } 138 }
138 - //if count, err = OrderPaymentRepository.CountAll(queryOption); err != nil {  
139 - // return nil, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
140 - //}  
141 -  
142 if err = transactionContext.CommitTransaction(); err != nil { 139 if err = transactionContext.CommitTransaction(); err != nil {
143 - return nil, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 140 + return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
144 } 141 }
145 - return orderBase, OrderPayments, nil 142 + return OrderPayments, nil
146 } 143 }
147 144
148 // 返回分红管理列表 145 // 返回分红管理列表
@@ -167,8 +164,8 @@ func (OrderPaymentService *OrderPaymentService) ListDividendOrders(listOrderPaym @@ -167,8 +164,8 @@ func (OrderPaymentService *OrderPaymentService) ListDividendOrders(listOrderPaym
167 } 164 }
168 }() 165 }()
169 if count, orders, err = OrderDao.GetDividendOrders(map[string]interface{}{ 166 if count, orders, err = OrderDao.GetDividendOrders(map[string]interface{}{
170 - "orderCode": listOrderPaymentQuery.OrderNumber,  
171 - "partnerName": listOrderPaymentQuery.PartnerName, 167 + "orderCode": listOrderPaymentQuery.SearchText,
  168 + "partnerId": listOrderPaymentQuery.PartnerId,
172 "orderType": 1, 169 "orderType": 1,
173 "offset": (listOrderPaymentQuery.PageNumber - 1) * listOrderPaymentQuery.PageSize, 170 "offset": (listOrderPaymentQuery.PageNumber - 1) * listOrderPaymentQuery.PageSize,
174 "limit": listOrderPaymentQuery.PageSize, 171 "limit": listOrderPaymentQuery.PageSize,
@@ -177,6 +174,7 @@ func (OrderPaymentService *OrderPaymentService) ListDividendOrders(listOrderPaym @@ -177,6 +174,7 @@ func (OrderPaymentService *OrderPaymentService) ListDividendOrders(listOrderPaym
177 } 174 }
178 175
179 type DividendOrderItem struct { 176 type DividendOrderItem struct {
  177 + OrderId string `json:"id"` //订单编号
180 OrderNumber string `json:"orderNumber"` //订单号 178 OrderNumber string `json:"orderNumber"` //订单号
181 OrderState int `json:"orderState"` //订单状态 179 OrderState int `json:"orderState"` //订单状态
182 StateOfPayment string `json:"stateOfPayment"` //支付状态 180 StateOfPayment string `json:"stateOfPayment"` //支付状态
@@ -192,6 +190,7 @@ func (OrderPaymentService *OrderPaymentService) ListDividendOrders(listOrderPaym @@ -192,6 +190,7 @@ func (OrderPaymentService *OrderPaymentService) ListDividendOrders(listOrderPaym
192 for i := range orders { 190 for i := range orders {
193 order := orders[i] 191 order := orders[i]
194 item := DividendOrderItem{ 192 item := DividendOrderItem{
  193 + OrderId: fmt.Sprintf("%v", order.Id),
195 OrderNumber: order.OrderCode, 194 OrderNumber: order.OrderCode,
196 OrderState: order.OrderStatus, 195 OrderState: order.OrderStatus,
197 StateOfPayment: "", 196 StateOfPayment: "",
1 package domain 1 package domain
2 2
3 import ( 3 import (
  4 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/utils"
4 "time" 5 "time"
5 ) 6 )
6 7
@@ -109,6 +110,37 @@ func (order *Order) Update(data map[string]interface{}) error { @@ -109,6 +110,37 @@ func (order *Order) Update(data map[string]interface{}) error {
109 return nil 110 return nil
110 } 111 }
111 112
  113 +//订单累计分红
  114 +func (m *Order) OrderTotalBonus() float64 {
  115 + return utils.Decimal(m.OrderActualAmount * (m.PartnerBonusPercent / 100.0))
  116 +}
  117 +
  118 +//订单已收分红
  119 +func (m *Order) OrderBonusReceive() float64 {
  120 + return utils.Decimal(m.OrderPaymentAmount * (m.PartnerBonusPercent / 100.0))
  121 +}
  122 +
  123 +//订单未收分红
  124 +func (m *Order) OrderBonusWait() float64 {
  125 + return m.OrderTotalBonus() - m.OrderBonusReceive()
  126 +}
  127 +
  128 +//分红支出
  129 +func (m *Order) OrderBonusOutstanding() float64 {
  130 + if m.OrderAmount <= m.OrderActualAmount {
  131 + return 0
  132 + }
  133 + return utils.Decimal((m.OrderAmount - m.OrderActualAmount) * (m.PartnerBonusPercent / 100.0))
  134 +}
  135 +
  136 +//订单被取消金额
  137 +func (m *Order) OrderAmountCancel() float64 {
  138 + if m.OrderAmount <= m.OrderActualAmount {
  139 + return 0
  140 + }
  141 + return utils.Decimal((m.OrderAmount - m.OrderActualAmount))
  142 +}
  143 +
112 type OrderFindOneQuery struct { 144 type OrderFindOneQuery struct {
113 OrderId int64 145 OrderId int64
114 } 146 }
@@ -67,8 +67,8 @@ func (dao *OrderDao) GetDividendOrders(options map[string]interface{}) (count in @@ -67,8 +67,8 @@ func (dao *OrderDao) GetDividendOrders(options map[string]interface{}) (count in
67 if v, ok := options["orderType"]; ok { 67 if v, ok := options["orderType"]; ok {
68 q.Where(`"order".order_type=?`, v) 68 q.Where(`"order".order_type=?`, v)
69 } 69 }
70 - if v, ok := options["partnerName"]; ok && len(v.(string)) > 0 {  
71 - q.Where(`partner_info.partner_name like ?`, "%"+v.(string)+"%") 70 + if v, ok := options["partnerId"]; ok && len(v.(string)) > 0 {
  71 + q.Where(`"order".partner_id =?`, v)
72 } 72 }
73 if v, ok := options["offset"]; ok { 73 if v, ok := options["offset"]; ok {
74 q.Offset(v.(int)) 74 q.Offset(v.(int))
@@ -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 )
@@ -76,11 +84,13 @@ func (c *DividendsController) Edit() { @@ -76,11 +84,13 @@ func (c *DividendsController) Edit() {
76 //Edit 分红支付详情 84 //Edit 分红支付详情
77 func (c *DividendsController) Detail() { 85 func (c *DividendsController) Detail() {
78 type Parameter struct { 86 type Parameter struct {
79 - Id int64 `json:"id"` //订单编号 87 + Id string `json:"id"` //订单编号
80 } 88 }
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,17 +98,28 @@ func (c *DividendsController) Detail() { @@ -88,17 +98,28 @@ func (c *DividendsController) Detail() {
88 return 98 return
89 } 99 }
90 100
91 - cmd := OrderPaymentQuery.GetOrderPaymentQuery{  
92 - OrderId: param.Id,  
93 - }  
94 - serve := OrderPaymentSvr.NewOrderPaymentService(nil) 101 + cmd := OrderPaymentQuery.GetOrderPaymentQuery{}
  102 + cmd.OrderId, _ = strconv.ParseInt(param.Id, 10, 64)
  103 +
  104 + var (
  105 + OrderPaymentSvr = OrderPaymentSvr.NewOrderPaymentService(nil)
  106 + OrderSvr = OrderSvr.NewOrderService(nil)
  107 + PartnerInfoSvr = PartnerInfoSvr.NewPartnerInfoService(nil)
  108 + )
95 var data []*domain.OrderPayment 109 var data []*domain.OrderPayment
96 - var extral map[string]interface{}  
97 - extral, data, err = serve.ListOrderPayment(&cmd) 110 + data, err = OrderPaymentSvr.ListOrderPayment(&cmd)
98 if err != nil { 111 if err != nil {
99 c.ResponseError(err) 112 c.ResponseError(err)
100 return 113 return
101 } 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 + }
102 123
103 type DividendPayment struct { 124 type DividendPayment struct {
104 PaymentForGoods float64 `json:"paymentForGoods"` 125 PaymentForGoods float64 `json:"paymentForGoods"`
@@ -107,8 +128,34 @@ func (c *DividendsController) Detail() { @@ -107,8 +128,34 @@ func (c *DividendsController) Detail() {
107 Dividend float64 `json:"dividend"` 128 Dividend float64 `json:"dividend"`
108 DividendProportion float64 `json:"dividendProportion"` 129 DividendProportion float64 `json:"dividendProportion"`
109 } 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 + }
110 type Response struct { 154 type Response struct {
111 DividendPayment []DividendPayment `json:"dividendPayment"` 155 DividendPayment []DividendPayment `json:"dividendPayment"`
  156 + Order Order `json:"order"`
  157 + Partner Partner `json:"partner"`
  158 + Commission Commission `json:"commission"`
112 } 159 }
113 rsp := Response{DividendPayment: make([]DividendPayment, 0)} 160 rsp := Response{DividendPayment: make([]DividendPayment, 0)}
114 for i := range data { 161 for i := range data {
@@ -118,10 +165,35 @@ func (c *DividendsController) Detail() { @@ -118,10 +165,35 @@ func (c *DividendsController) Detail() {
118 UpdateTime: item.UpdateAt.Local().Format("2006-01-02 15:04:05"), 165 UpdateTime: item.UpdateAt.Local().Format("2006-01-02 15:04:05"),
119 StateOfPayment: item.BonusStatus, 166 StateOfPayment: item.BonusStatus,
120 Dividend: item.BonusAmount, 167 Dividend: item.BonusAmount,
121 - DividendProportion: extral["PartnerBonusPercent"].(float64), 168 + DividendProportion: order.PartnerBonusPercent,
122 } 169 }
123 rsp.DividendPayment = append(rsp.DividendPayment, payment) 170 rsp.DividendPayment = append(rsp.DividendPayment, payment)
124 } 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 + }
125 197
126 c.ResponseData(rsp) 198 c.ResponseData(rsp)
127 return 199 return