作者 yangfu

1.增加订单分红列表

@@ -3,6 +3,7 @@ package dividend @@ -3,6 +3,7 @@ package dividend
3 import ( 3 import (
4 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory" 4 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory"
5 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" 5 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
  6 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models"
6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" 7 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
7 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" 8 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
8 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" 9 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
@@ -82,7 +83,46 @@ func QuartersBonusStatics(orders []*domain.Order, action int) (bonus []protocol. @@ -82,7 +83,46 @@ func QuartersBonusStatics(orders []*domain.Order, action int) (bonus []protocol.
82 83
83 //分红订单 84 //分红订单
84 func DividendOrders(header *protocol.RequestHeader, request *protocol.DividendOrdersRequest) (rsp *protocol.DividendOrdersResponse, err error) { 85 func DividendOrders(header *protocol.RequestHeader, request *protocol.DividendOrdersRequest) (rsp *protocol.DividendOrdersResponse, err error) {
85 - var ()  
86 - rsp = &protocol.DividendOrdersResponse{} 86 + var (
  87 + transactionContext, _ = factory.CreateTransactionContext(nil)
  88 + OrderDao, _ = factory.CreateOrderDao(transactionContext)
  89 + orders []*models.Order
  90 + count int
  91 + )
  92 + if err = transactionContext.StartTransaction(); err != nil {
  93 + return nil, err
  94 + }
  95 + defer func() {
  96 + if err != nil {
  97 + transactionContext.RollbackTransaction()
  98 + }
  99 + }()
  100 + rsp = &protocol.DividendOrdersResponse{List: make([]*protocol.DividendOrderListItem, 0)}
  101 +
  102 + count, orders, err = OrderDao.DividendOrders(&domain.DividendOrdersQueryOption{
  103 + DetailAction: request.DetailAction,
  104 + DividendAction: request.DividendAction,
  105 + StartTime: request.StartTime,
  106 + EndTime: request.EndTime,
  107 + Offset: request.PageIndex * request.PageSize,
  108 + Limit: request.PageSize,
  109 + })
  110 + if err != nil {
  111 + return
  112 + }
  113 +
  114 + for i := range orders {
  115 + o := orders[i]
  116 + item := &protocol.DividendOrderListItem{
  117 + Id: o.Id,
  118 + OrderNo: o.OrderCode,
  119 + OrderAmount: o.OrderActualAmount,
  120 + MyDividend: utils.Decimal(o.OrderActualAmount * (o.PartnerBonusPercent / 100.0)),
  121 + }
  122 + rsp.List = append(rsp.List, item)
  123 + }
  124 + rsp.Total = count
  125 +
  126 + err = transactionContext.CommitTransaction()
87 return 127 return
88 } 128 }
@@ -128,7 +128,6 @@ func OrderList(header *protocol.RequestHeader, request *protocol.OrderListReques @@ -128,7 +128,6 @@ func OrderList(header *protocol.RequestHeader, request *protocol.OrderListReques
128 return nil, err 128 return nil, err
129 } 129 }
130 defer func() { 130 defer func() {
131 - err = transactionContext.CommitTransaction()  
132 if err != nil { 131 if err != nil {
133 transactionContext.RollbackTransaction() 132 transactionContext.RollbackTransaction()
134 } 133 }
@@ -191,6 +190,8 @@ func OrderList(header *protocol.RequestHeader, request *protocol.OrderListReques @@ -191,6 +190,8 @@ func OrderList(header *protocol.RequestHeader, request *protocol.OrderListReques
191 for i := range orders { 190 for i := range orders {
192 rsp.List = append(rsp.List, DomainOrderToOrderListItem(orders[i])) 191 rsp.List = append(rsp.List, DomainOrderToOrderListItem(orders[i]))
193 } 192 }
  193 +
  194 + err = transactionContext.CommitTransaction()
194 return 195 return
195 } 196 }
196 func DomainOrderToOrderListItem(order *domain.Order) *protocol.OrderListItem { 197 func DomainOrderToOrderListItem(order *domain.Order) *protocol.OrderListItem {
@@ -95,7 +95,7 @@ func (m *Order) Update(data map[string]interface{}) error { @@ -95,7 +95,7 @@ func (m *Order) Update(data map[string]interface{}) error {
95 //合伙人 95 //合伙人
96 //订单累计分红 96 //订单累计分红
97 func (m *Order) OrderTotalBonus() float64 { 97 func (m *Order) OrderTotalBonus() float64 {
98 - return utils.Decimal(m.OrderAmount * (m.PartnerBonusPercent / 100.0)) 98 + return utils.Decimal(m.OrderActualAmount * (m.PartnerBonusPercent / 100.0))
99 } 99 }
100 100
101 //订单已收分红 101 //订单已收分红
@@ -124,6 +124,7 @@ func (m *Order) OrderAmountCancel() float64 { @@ -124,6 +124,7 @@ func (m *Order) OrderAmountCancel() float64 {
124 return utils.Decimal((m.OrderAmount - m.OrderActualAmount)) 124 return utils.Decimal((m.OrderAmount - m.OrderActualAmount))
125 } 125 }
126 126
  127 +//订单是否已读
127 func (m *Order) IsRead() int { 128 func (m *Order) IsRead() int {
128 if m.UpdateAt.After(m.LastViewTime) { 129 if m.UpdateAt.After(m.LastViewTime) {
129 return 0 130 return 0
@@ -141,3 +142,12 @@ type OrderQueryOption struct { @@ -141,3 +142,12 @@ type OrderQueryOption struct {
141 Offset int `json:"offset,omitempty"` 142 Offset int `json:"offset,omitempty"`
142 Limit int `json:"limit,omitempty"` 143 Limit int `json:"limit,omitempty"`
143 } 144 }
  145 +
  146 +type DividendOrdersQueryOption struct {
  147 + DetailAction int `json:"detailAction"` //明细类型(0已收明细、1未收明细)
  148 + DividendAction int `json:"dividendAction"` //分红类型(0累计分红、1分红支出)
  149 + StartTime int64 `json:"startTime" `
  150 + EndTime int64 `json:"endTime"`
  151 + Offset int `json:"offset,omitempty"`
  152 + Limit int `json:"limit,omitempty"`
  153 +}
@@ -31,3 +31,10 @@ type OrderStaticQuery struct { @@ -31,3 +31,10 @@ type OrderStaticQuery struct {
31 OrderStatus int `json:"orderStatus,omitempty"` 31 OrderStatus int `json:"orderStatus,omitempty"`
32 OrderType int `json:"orderType,omitempty"` 32 OrderType int `json:"orderType,omitempty"`
33 } 33 }
  34 +
  35 +type DividendOrdersQuery struct {
  36 + DetailAction int `json:"detailAction"` //明细类型(0已收明细、1未收明细)
  37 + DividendAction int `json:"dividendAction"` //分红类型(0累计分红、1分红支出)
  38 + StartTime int64 `json:"startTime" valid:"Required"`
  39 + EndTime int64 `json:"endTime" valid:"Required"`
  40 +}
@@ -17,7 +17,7 @@ func (dao *OrderDao) OrderStatics(option *domain.OrderStaticQuery) (count int, a @@ -17,7 +17,7 @@ func (dao *OrderDao) OrderStatics(option *domain.OrderStaticQuery) (count int, a
17 order := new(models.Order) 17 order := new(models.Order)
18 q := tx.Model(order) 18 q := tx.Model(order)
19 q.ColumnExpr("count(*) count") 19 q.ColumnExpr("count(*) count")
20 - q.ColumnExpr("sum(order_amount) total_order_amount") 20 + q.ColumnExpr("sum(order_actual_amount) total_order_amount")
21 if option.PartnerId > 0 { 21 if option.PartnerId > 0 {
22 q.Where(`"order".partner_id =?`, option.PartnerId) 22 q.Where(`"order".partner_id =?`, option.PartnerId)
23 } 23 }
@@ -37,6 +37,38 @@ func (dao *OrderDao) OrderStatics(option *domain.OrderStaticQuery) (count int, a @@ -37,6 +37,38 @@ func (dao *OrderDao) OrderStatics(option *domain.OrderStaticQuery) (count int, a
37 return 37 return
38 } 38 }
39 39
  40 +//分红订单
  41 +func (dao *OrderDao) DividendOrders(option *domain.DividendOrdersQueryOption) (count int, orders []*models.Order, err error) {
  42 + tx := dao.transactionContext.PgTx
  43 + q := tx.Model(&orders)
  44 + q.Column(`order.id`, `order.order_code`, `order.order_actual_amount`, `order.partner_bonus_percent`)
  45 + q.Where(`"order".order_status >=?`, domain.OrderStatusDeliverSome) //已经发货
  46 + if option.StartTime > 0 {
  47 + q.Where(`"order".delivery_time >=?`, time.Unix(option.StartTime/1000, 0))
  48 + }
  49 + if option.EndTime > 0 {
  50 + q.Where(`"order".delivery_time <?`, time.Unix(option.EndTime/1000, 0))
  51 + }
  52 + if option.DividendAction == 0 { //累计分红
  53 + if option.DetailAction == 0 { //已收明细
  54 + q.Join(`JOIN order_payment as a ON a.order_id="order".id`)
  55 + q.Where(`"a".bonus_status=?`, domain.BonusPaid)
  56 + } else if option.DetailAction == 1 { //未收明细
  57 + q.Where(`"order".order_actual_amount>"order".order_payment_amount`, domain.BonusWaitPay)
  58 + }
  59 + } else if option.DividendAction == 1 { //分红支出
  60 + q.Where(`"order".order_amount>"order".order_actual_amount`)
  61 + }
  62 + if option.Limit > 0 {
  63 + q.Limit(option.Limit)
  64 + }
  65 + if option.Offset > 0 {
  66 + q.Offset(option.Offset)
  67 + }
  68 + count, err = q.Distinct().SelectAndCount()
  69 + return
  70 +}
  71 +
40 func NewOrderDao(transactionContext *transaction.TransactionContext) (*OrderDao, error) { 72 func NewOrderDao(transactionContext *transaction.TransactionContext) (*OrderDao, error) {
41 if transactionContext == nil { 73 if transactionContext == nil {
42 return nil, fmt.Errorf("transactionContext参数不能为nil") 74 return nil, fmt.Errorf("transactionContext参数不能为nil")
@@ -69,7 +69,7 @@ func (repository *OrderRepository) Find(queryOptions map[string]interface{}) (in @@ -69,7 +69,7 @@ func (repository *OrderRepository) Find(queryOptions map[string]interface{}) (in
69 query. 69 query.
70 SetWhere(`"order".partner_id= ?`, "partnerId"). 70 SetWhere(`"order".partner_id= ?`, "partnerId").
71 SetWhere(`"order".order_type= ?`, "orderType"). 71 SetWhere(`"order".order_type= ?`, "orderType").
72 - SetWhere(`"order".order_type= ?`, "orderType"). 72 + SetWhere(`"order".order_status= ?`, "orderStatus").
73 SetWhere(`"order".create_at >= ?`, "beginTime"). 73 SetWhere(`"order".create_at >= ?`, "beginTime").
74 SetWhere(`"order".create_at < ?`, "endTime"). 74 SetWhere(`"order".create_at < ?`, "endTime").
75 SetLimit(). 75 SetLimit().
@@ -27,5 +27,6 @@ func init() { @@ -27,5 +27,6 @@ func init() {
27 nsV1.Router("order/list", &controllers.OrderController{}, "Post:OrderList") 27 nsV1.Router("order/list", &controllers.OrderController{}, "Post:OrderList")
28 28
29 nsV1.Router("dividend/statistics", &controllers.DividendController{}, "Post:DividendStatistics") 29 nsV1.Router("dividend/statistics", &controllers.DividendController{}, "Post:DividendStatistics")
  30 + nsV1.Router("dividend/orders", &controllers.DividendController{}, "Post:DividendOrders")
30 beego.AddNamespace(nsV1) 31 beego.AddNamespace(nsV1)
31 } 32 }
@@ -33,6 +33,18 @@ type DividendOrdersRequest struct { @@ -33,6 +33,18 @@ type DividendOrdersRequest struct {
33 DividendAction int `json:"dividendAction"` //分红类型(0累计分红、1分红支出) 33 DividendAction int `json:"dividendAction"` //分红类型(0累计分红、1分红支出)
34 StartTime int64 `json:"startTime" valid:"Required"` 34 StartTime int64 `json:"startTime" valid:"Required"`
35 EndTime int64 `json:"endTime" valid:"Required"` 35 EndTime int64 `json:"endTime" valid:"Required"`
  36 +
  37 + PageIndex int `json:"pageIndex,omitempty"`
  38 + PageSize int `json:"pageSize,omitempty"`
36 } 39 }
37 type DividendOrdersResponse struct { 40 type DividendOrdersResponse struct {
  41 + List []*DividendOrderListItem `json:"list"`
  42 + Total int `json:"total"`
  43 +}
  44 +
  45 +type DividendOrderListItem struct {
  46 + Id int64 `json:"id"`
  47 + OrderNo string `json:"orderNo"`
  48 + OrderAmount float64 `json:"orderAmount"`
  49 + MyDividend float64 `json:"myDividend"`
38 } 50 }