作者 yangfu

1.增加订单分红列表

... ... @@ -3,6 +3,7 @@ package dividend
import (
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
... ... @@ -82,7 +83,46 @@ func QuartersBonusStatics(orders []*domain.Order, action int) (bonus []protocol.
//分红订单
func DividendOrders(header *protocol.RequestHeader, request *protocol.DividendOrdersRequest) (rsp *protocol.DividendOrdersResponse, err error) {
var ()
rsp = &protocol.DividendOrdersResponse{}
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
OrderDao, _ = factory.CreateOrderDao(transactionContext)
orders []*models.Order
count int
)
if err = transactionContext.StartTransaction(); err != nil {
return nil, err
}
defer func() {
if err != nil {
transactionContext.RollbackTransaction()
}
}()
rsp = &protocol.DividendOrdersResponse{List: make([]*protocol.DividendOrderListItem, 0)}
count, orders, err = OrderDao.DividendOrders(&domain.DividendOrdersQueryOption{
DetailAction: request.DetailAction,
DividendAction: request.DividendAction,
StartTime: request.StartTime,
EndTime: request.EndTime,
Offset: request.PageIndex * request.PageSize,
Limit: request.PageSize,
})
if err != nil {
return
}
for i := range orders {
o := orders[i]
item := &protocol.DividendOrderListItem{
Id: o.Id,
OrderNo: o.OrderCode,
OrderAmount: o.OrderActualAmount,
MyDividend: utils.Decimal(o.OrderActualAmount * (o.PartnerBonusPercent / 100.0)),
}
rsp.List = append(rsp.List, item)
}
rsp.Total = count
err = transactionContext.CommitTransaction()
return
}
... ...
... ... @@ -128,7 +128,6 @@ func OrderList(header *protocol.RequestHeader, request *protocol.OrderListReques
return nil, err
}
defer func() {
err = transactionContext.CommitTransaction()
if err != nil {
transactionContext.RollbackTransaction()
}
... ... @@ -191,6 +190,8 @@ func OrderList(header *protocol.RequestHeader, request *protocol.OrderListReques
for i := range orders {
rsp.List = append(rsp.List, DomainOrderToOrderListItem(orders[i]))
}
err = transactionContext.CommitTransaction()
return
}
func DomainOrderToOrderListItem(order *domain.Order) *protocol.OrderListItem {
... ...
... ... @@ -95,7 +95,7 @@ func (m *Order) Update(data map[string]interface{}) error {
//合伙人
//订单累计分红
func (m *Order) OrderTotalBonus() float64 {
return utils.Decimal(m.OrderAmount * (m.PartnerBonusPercent / 100.0))
return utils.Decimal(m.OrderActualAmount * (m.PartnerBonusPercent / 100.0))
}
//订单已收分红
... ... @@ -124,6 +124,7 @@ func (m *Order) OrderAmountCancel() float64 {
return utils.Decimal((m.OrderAmount - m.OrderActualAmount))
}
//订单是否已读
func (m *Order) IsRead() int {
if m.UpdateAt.After(m.LastViewTime) {
return 0
... ... @@ -141,3 +142,12 @@ type OrderQueryOption struct {
Offset int `json:"offset,omitempty"`
Limit int `json:"limit,omitempty"`
}
type DividendOrdersQueryOption struct {
DetailAction int `json:"detailAction"` //明细类型(0已收明细、1未收明细)
DividendAction int `json:"dividendAction"` //分红类型(0累计分红、1分红支出)
StartTime int64 `json:"startTime" `
EndTime int64 `json:"endTime"`
Offset int `json:"offset,omitempty"`
Limit int `json:"limit,omitempty"`
}
... ...
... ... @@ -31,3 +31,10 @@ type OrderStaticQuery struct {
OrderStatus int `json:"orderStatus,omitempty"`
OrderType int `json:"orderType,omitempty"`
}
type DividendOrdersQuery struct {
DetailAction int `json:"detailAction"` //明细类型(0已收明细、1未收明细)
DividendAction int `json:"dividendAction"` //分红类型(0累计分红、1分红支出)
StartTime int64 `json:"startTime" valid:"Required"`
EndTime int64 `json:"endTime" valid:"Required"`
}
... ...
... ... @@ -17,7 +17,7 @@ func (dao *OrderDao) OrderStatics(option *domain.OrderStaticQuery) (count int, a
order := new(models.Order)
q := tx.Model(order)
q.ColumnExpr("count(*) count")
q.ColumnExpr("sum(order_amount) total_order_amount")
q.ColumnExpr("sum(order_actual_amount) total_order_amount")
if option.PartnerId > 0 {
q.Where(`"order".partner_id =?`, option.PartnerId)
}
... ... @@ -37,6 +37,38 @@ func (dao *OrderDao) OrderStatics(option *domain.OrderStaticQuery) (count int, a
return
}
//分红订单
func (dao *OrderDao) DividendOrders(option *domain.DividendOrdersQueryOption) (count int, orders []*models.Order, err error) {
tx := dao.transactionContext.PgTx
q := tx.Model(&orders)
q.Column(`order.id`, `order.order_code`, `order.order_actual_amount`, `order.partner_bonus_percent`)
q.Where(`"order".order_status >=?`, domain.OrderStatusDeliverSome) //已经发货
if option.StartTime > 0 {
q.Where(`"order".delivery_time >=?`, time.Unix(option.StartTime/1000, 0))
}
if option.EndTime > 0 {
q.Where(`"order".delivery_time <?`, time.Unix(option.EndTime/1000, 0))
}
if option.DividendAction == 0 { //累计分红
if option.DetailAction == 0 { //已收明细
q.Join(`JOIN order_payment as a ON a.order_id="order".id`)
q.Where(`"a".bonus_status=?`, domain.BonusPaid)
} else if option.DetailAction == 1 { //未收明细
q.Where(`"order".order_actual_amount>"order".order_payment_amount`, domain.BonusWaitPay)
}
} else if option.DividendAction == 1 { //分红支出
q.Where(`"order".order_amount>"order".order_actual_amount`)
}
if option.Limit > 0 {
q.Limit(option.Limit)
}
if option.Offset > 0 {
q.Offset(option.Offset)
}
count, err = q.Distinct().SelectAndCount()
return
}
func NewOrderDao(transactionContext *transaction.TransactionContext) (*OrderDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
... ...
... ... @@ -69,7 +69,7 @@ func (repository *OrderRepository) Find(queryOptions map[string]interface{}) (in
query.
SetWhere(`"order".partner_id= ?`, "partnerId").
SetWhere(`"order".order_type= ?`, "orderType").
SetWhere(`"order".order_type= ?`, "orderType").
SetWhere(`"order".order_status= ?`, "orderStatus").
SetWhere(`"order".create_at >= ?`, "beginTime").
SetWhere(`"order".create_at < ?`, "endTime").
SetLimit().
... ...
... ... @@ -27,5 +27,6 @@ func init() {
nsV1.Router("order/list", &controllers.OrderController{}, "Post:OrderList")
nsV1.Router("dividend/statistics", &controllers.DividendController{}, "Post:DividendStatistics")
nsV1.Router("dividend/orders", &controllers.DividendController{}, "Post:DividendOrders")
beego.AddNamespace(nsV1)
}
... ...
... ... @@ -33,6 +33,18 @@ type DividendOrdersRequest struct {
DividendAction int `json:"dividendAction"` //分红类型(0累计分红、1分红支出)
StartTime int64 `json:"startTime" valid:"Required"`
EndTime int64 `json:"endTime" valid:"Required"`
PageIndex int `json:"pageIndex,omitempty"`
PageSize int `json:"pageSize,omitempty"`
}
type DividendOrdersResponse struct {
List []*DividendOrderListItem `json:"list"`
Total int `json:"total"`
}
type DividendOrderListItem struct {
Id int64 `json:"id"`
OrderNo string `json:"orderNo"`
OrderAmount float64 `json:"orderAmount"`
MyDividend float64 `json:"myDividend"`
}
... ...