作者 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,10 +2,10 @@ package query
type ListDividendOrdersQuery struct {
// 合伙人类别
PartnerName string `json:"partnerName"`
OrderNumber string `json:"orderNumber"`
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
PartnerId string `json:"partnerId"`
SearchText string `json:"searchText"`
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
}
func (q *ListDividendOrdersQuery) ValidateQuery() error {
... ...
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/command"
... ... @@ -101,7 +102,7 @@ func (OrderPaymentService *OrderPaymentService) CreateOrderPayment(command *comm
}
// 返回订单支付列表
func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymentQuery *query.GetOrderPaymentQuery) (map[string]interface{}, []*domain.OrderPayment, error) {
func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymentQuery *query.GetOrderPaymentQuery) ([]*domain.OrderPayment, error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
OrderDao, _ = factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext})
... ... @@ -109,10 +110,10 @@ func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymen
err error
)
if err = listOrderPaymentQuery.ValidateQuery(); err != nil {
return nil, nil, lib.ThrowError(lib.ARG_ERROR, err.Error())
return nil, lib.ThrowError(lib.ARG_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
defer func() {
if err != nil {
... ... @@ -123,26 +124,22 @@ func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymen
if OrderPaymentRepository, err = factory.CreateOrderPaymentRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
queryOption := domain.OrderPaymentQuery{
OrderId: listOrderPaymentQuery.OrderId,
}
orderBase, e := OrderDao.GetOrderBaseInfo(listOrderPaymentQuery.OrderId)
_, e := OrderDao.GetOrderBaseInfo(listOrderPaymentQuery.OrderId)
if e != nil {
return nil, nil, e
return nil, e
}
if OrderPayments, err = OrderPaymentRepository.Find(queryOption); err != nil {
return nil, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
//if count, err = OrderPaymentRepository.CountAll(queryOption); err != nil {
// return nil, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
//}
if err = transactionContext.CommitTransaction(); err != nil {
return nil, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
return orderBase, OrderPayments, nil
return OrderPayments, nil
}
// 返回分红管理列表
... ... @@ -167,16 +164,17 @@ func (OrderPaymentService *OrderPaymentService) ListDividendOrders(listOrderPaym
}
}()
if count, orders, err = OrderDao.GetDividendOrders(map[string]interface{}{
"orderCode": listOrderPaymentQuery.OrderNumber,
"partnerName": listOrderPaymentQuery.PartnerName,
"orderType": 1,
"offset": (listOrderPaymentQuery.PageNumber - 1) * listOrderPaymentQuery.PageSize,
"limit": listOrderPaymentQuery.PageSize,
"orderCode": listOrderPaymentQuery.SearchText,
"partnerId": listOrderPaymentQuery.PartnerId,
"orderType": 1,
"offset": (listOrderPaymentQuery.PageNumber - 1) * listOrderPaymentQuery.PageSize,
"limit": listOrderPaymentQuery.PageSize,
}); err != nil {
return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
type DividendOrderItem struct {
OrderId string `json:"id"` //订单编号
OrderNumber string `json:"orderNumber"` //订单号
OrderState int `json:"orderState"` //订单状态
StateOfPayment string `json:"stateOfPayment"` //支付状态
... ... @@ -192,6 +190,7 @@ func (OrderPaymentService *OrderPaymentService) ListDividendOrders(listOrderPaym
for i := range orders {
order := orders[i]
item := DividendOrderItem{
OrderId: fmt.Sprintf("%v", order.Id),
OrderNumber: order.OrderCode,
OrderState: order.OrderStatus,
StateOfPayment: "",
... ...
package domain
import (
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/utils"
"time"
)
... ... @@ -109,6 +110,37 @@ func (order *Order) Update(data map[string]interface{}) error {
return nil
}
//订单累计分红
func (m *Order) OrderTotalBonus() float64 {
return utils.Decimal(m.OrderActualAmount * (m.PartnerBonusPercent / 100.0))
}
//订单已收分红
func (m *Order) OrderBonusReceive() float64 {
return utils.Decimal(m.OrderPaymentAmount * (m.PartnerBonusPercent / 100.0))
}
//订单未收分红
func (m *Order) OrderBonusWait() float64 {
return m.OrderTotalBonus() - m.OrderBonusReceive()
}
//分红支出
func (m *Order) OrderBonusOutstanding() float64 {
if m.OrderAmount <= m.OrderActualAmount {
return 0
}
return utils.Decimal((m.OrderAmount - m.OrderActualAmount) * (m.PartnerBonusPercent / 100.0))
}
//订单被取消金额
func (m *Order) OrderAmountCancel() float64 {
if m.OrderAmount <= m.OrderActualAmount {
return 0
}
return utils.Decimal((m.OrderAmount - m.OrderActualAmount))
}
type OrderFindOneQuery struct {
OrderId int64
}
... ...
... ... @@ -67,8 +67,8 @@ func (dao *OrderDao) GetDividendOrders(options map[string]interface{}) (count in
if v, ok := options["orderType"]; ok {
q.Where(`"order".order_type=?`, v)
}
if v, ok := options["partnerName"]; ok && len(v.(string)) > 0 {
q.Where(`partner_info.partner_name like ?`, "%"+v.(string)+"%")
if v, ok := options["partnerId"]; ok && len(v.(string)) > 0 {
q.Where(`"order".partner_id =?`, v)
}
if v, ok := options["offset"]; ok {
q.Offset(v.(int))
... ...
... ... @@ -2,10 +2,18 @@ package controllers
import (
"errors"
"fmt"
"github.com/astaxie/beego/logs"
OrderPaymentCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/command"
OrderPaymentQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/query"
OrderPaymentSvr "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/service"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/utils"
OrderQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/query"
OrderSvr "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/service"
PartnerInfoQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/query"
PartnerInfoSvr "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/service"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"strconv"
)
... ... @@ -76,11 +84,13 @@ func (c *DividendsController) Edit() {
//Edit 分红支付详情
func (c *DividendsController) Detail() {
type Parameter struct {
Id int64 `json:"id"` //订单编号
Id string `json:"id"` //订单编号
}
var (
param Parameter
err error
param Parameter
err error
order *domain.Order
partner *domain.PartnerInfo
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
... ... @@ -88,17 +98,28 @@ func (c *DividendsController) Detail() {
return
}
cmd := OrderPaymentQuery.GetOrderPaymentQuery{
OrderId: param.Id,
}
serve := OrderPaymentSvr.NewOrderPaymentService(nil)
cmd := OrderPaymentQuery.GetOrderPaymentQuery{}
cmd.OrderId, _ = strconv.ParseInt(param.Id, 10, 64)
var (
OrderPaymentSvr = OrderPaymentSvr.NewOrderPaymentService(nil)
OrderSvr = OrderSvr.NewOrderService(nil)
PartnerInfoSvr = PartnerInfoSvr.NewPartnerInfoService(nil)
)
var data []*domain.OrderPayment
var extral map[string]interface{}
extral, data, err = serve.ListOrderPayment(&cmd)
data, err = OrderPaymentSvr.ListOrderPayment(&cmd)
if err != nil {
c.ResponseError(err)
return
}
if order, err = OrderSvr.GetOrder(OrderQuery.GetOrderQuery{OrderId: cmd.OrderId}); err != nil {
c.ResponseError(err)
return
}
if partner, err = PartnerInfoSvr.GetPartnerInfo(PartnerInfoQuery.GetPartnerInfoQuery{Id: order.PartnerInfo.Id}); err != nil {
c.ResponseError(err)
return
}
type DividendPayment struct {
PaymentForGoods float64 `json:"paymentForGoods"`
... ... @@ -107,8 +128,34 @@ func (c *DividendsController) Detail() {
Dividend float64 `json:"dividend"`
DividendProportion float64 `json:"dividendProportion"`
}
type Order struct {
OrderNumber string `json:"orderNumber"` //订单号
OrderState int `json:"orderState"` //订单状态
CreateTime string `json:"createTime"` //订单创建时间
OrderName string `json:"orderName"` //订单名称
OrderNum string `json:"orderNum"` //订单数量
OrderAmount string `json:"orderAmount"` //订单金额
Id string `json:"id"` //订单编号
}
type Partner struct {
PartnerName string `json:"partnerName"` //合伙人姓名
DividendProportion float64 `json:"dividendProportion"` //分红比例
DividendsReceivable float64 `json:"dividendsReceivable"` //应收分红
DividendSpending float64 `json:"dividendSpending"` //分红支出
ReceiveDividends float64 `json:"receiveDividends"` //实收分红
NotReceivedDividends float64 `json:"notReceivedDividends"` //未收分红
RceivedDividends float64 `json:"receivedDividends"` //已收分红
}
type Commission struct {
SalesmanName string `json:"salesmanName"` //业务员名称
CommissionProportion float64 `json:"commissionProportion"` //业务员抽成比例
ExpectedCommission float64 `json:"expectedCommission"` //业务员预计抽成
}
type Response struct {
DividendPayment []DividendPayment `json:"dividendPayment"`
Order Order `json:"order"`
Partner Partner `json:"partner"`
Commission Commission `json:"commission"`
}
rsp := Response{DividendPayment: make([]DividendPayment, 0)}
for i := range data {
... ... @@ -118,10 +165,35 @@ func (c *DividendsController) Detail() {
UpdateTime: item.UpdateAt.Local().Format("2006-01-02 15:04:05"),
StateOfPayment: item.BonusStatus,
Dividend: item.BonusAmount,
DividendProportion: extral["PartnerBonusPercent"].(float64),
DividendProportion: order.PartnerBonusPercent,
}
rsp.DividendPayment = append(rsp.DividendPayment, payment)
}
rsp.Order = Order{
OrderNumber: order.OrderCode,
OrderState: order.OrderStatus,
CreateTime: order.CreateAt.Local().Format("2006-01-02 15:04:05"),
OrderName: order.OrderName,
OrderNum: fmt.Sprintf("%v", order.OrderCount),
OrderAmount: fmt.Sprintf("%v", order.OrderAmount),
Id: fmt.Sprintf("%v", order.Id),
}
rsp.Partner = Partner{
PartnerName: partner.Partner.PartnerName,
DividendProportion: order.PartnerBonusPercent,
DividendsReceivable: order.OrderTotalBonus() + order.OrderBonusOutstanding(), //应收分红 = 实收分红+分红支出
DividendSpending: order.OrderBonusOutstanding(), //分红支出
ReceiveDividends: order.OrderBonusReceive() + order.OrderBonusWait(), //应实收分红 = 已收分红 + 等待分红
NotReceivedDividends: order.OrderBonusWait(), //未收分红
RceivedDividends: order.OrderBonusReceive(),
}
rsp.Commission = Commission{
CommissionProportion: order.SalesmanBonusPercent,
ExpectedCommission: utils.Decimal(order.OrderActualAmount * (order.SalesmanBonusPercent / 100)),
}
if len(partner.Salesman) > 0 {
rsp.Commission.SalesmanName = partner.Salesman[0].Name
}
c.ResponseData(rsp)
return
... ...