作者 yangfu

增加:分红统计修改

... ... @@ -143,8 +143,8 @@ func imRefreshToken(request *protocol.CheckImRequest, rsp *protocol.CheckImRespo
// 获取客服id
func getRandomCustomerAccount(userId int64, ctx *transaction.TransactionContext) (acid int64) {
CustomerServiceRepository, _ := factory.CreateCustomerServiceRepository(ctx)
total, customers, err := CustomerServiceRepository.Find(map[string]interface{}{"sortById": domain.ASC})
ImCustomerServiceRepository, _ := factory.CreateImCustomerServiceRepository(ctx)
total, customers, err := ImCustomerServiceRepository.Find(map[string]interface{}{"sortById": domain.ASC})
if err != nil {
log.Error(err)
return 0
... ...
... ... @@ -125,7 +125,7 @@ func OrderList(header *protocol.RequestHeader, request *protocol.DividendOrdersR
item := &protocol.DividendOrderListItem{
Id: o.Id,
DeliveryNo: o.DeliveryCode,
OrderAmount: o.OrderAmount(),
OrderAmount: o.PlanOrderAmount,
DividendReceivable: utils.Decimal(o.OrderTotalBonus()),
}
rsp.List = append(rsp.List, item)
... ...
... ... @@ -53,6 +53,6 @@ func CreateImInfoRepository(transactionContext *transaction.TransactionContext)
}
//CreateImInfoRepository Im信息
func CreateCustomerServiceRepository(transactionContext *transaction.TransactionContext) (domain.CustomerServiceRepository, error) {
return repository.NewCustomerServiceRepository(transactionContext)
func CreateImCustomerServiceRepository(transactionContext *transaction.TransactionContext) (domain.ImCustomerServiceRepository, error) {
return repository.NewImCustomerServiceRepository(transactionContext)
}
... ...
... ... @@ -81,7 +81,7 @@ func orderProducts(order *domain.OrderBase) interface{} {
item["orderCount"] = good.PlanGoodNumber
item["orderAmount"] = good.PlanAmount
item["dividendPercent"] = good.PartnerBonusPercent
item["dividendReceivable"] = good.PlanPartnerBonus //收分红
item["dividendReceivable"] = good.PlanPartnerBonus //收分红
item["dividendReceived"] = good.PartnerBonusHas //已收分红
item["dividendUnReceive"] = good.PartnerBonusNot // 未收分红
item["dividendExpend"] = good.PartnerBonusExpense //分红支出
... ... @@ -176,7 +176,6 @@ func List(header *protocol.RequestHeader, request *protocol.OrderListRequest) (r
Limit: request.PageSize,
Offset: request.PageSize * request.PageIndex,
SortByUpdateTime: domain.DESC,
//IsDisable: "0",
}
if request.StartTime > 0 {
queryOption.BeginTime = time.Unix(request.StartTime/1000, 0)
... ... @@ -189,48 +188,15 @@ func List(header *protocol.RequestHeader, request *protocol.OrderListRequest) (r
//统计数据
if request.PageIndex == 0 {
var (
//partShipmentQuantity, allShipmentQuantity int
cumulativeQuantity int
)
//部分发货的订单数量
//partShipmentQuantity, _, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{
// EndTime: request.EndTime,
// BeginTime: request.StartTime,
// OrderType: domain.OrderReal,
// PartnerId: header.UserId,
// OrderStatus: domain.OrderStatusDeliverSome,
//})
//全部发货的订单数量
//allShipmentQuantity, _, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{
// EndTime: request.EndTime,
// BeginTime: request.StartTime,
// OrderType: domain.OrderReal,
// PartnerId: header.UserId,
// //OrderStatus: domain.OrderStatusDeliverAll,
//})
//累计实发订单
cumulativeQuantity, _, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{
EndTime: time.Now().Unix() * 1000,
//BeginTime: request.StartTime,
EndTime: time.Now().Unix() * 1000,
OrderType: domain.OrderReal,
PartnerId: header.UserId,
})
//累计意向订单
//intentionQuantity, _, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{
// EndTime: time.Now().Unix() * 1000,
// //BeginTime: request.StartTime,
// OrderType: domain.OrderIntention,
// PartnerId: header.UserId,
//})
//订单数量
//rsp.Statistics["partShipmentQuantity"] = partShipmentQuantity
//rsp.Statistics["allShipmentQuantity"] = allShipmentQuantity
//rsp.Statistics["orderQuantity"] = partShipmentQuantity + allShipmentQuantity //所有订单 = 部分发货 + 已经发货
//rsp.Statistics["cumulativeQuantity"] = cumulativeQuantity
rsp.Total = cumulativeQuantity
//实发订单 = 部分发货 + 全部发货
//rsp.Statistics["intentionQuantity"] = intentionQuantity
}
if len(orders) == 0 {
... ... @@ -244,14 +210,15 @@ func List(header *protocol.RequestHeader, request *protocol.OrderListRequest) (r
return
}
func DomainOrderToOrderListItem(order *domain.OrderBase) *protocol.OrderListItem {
bonusStatic := order.OrderBonusStatic()
return &protocol.OrderListItem{
Id: order.Id,
OrderType: order.OrderType,
OrderNo: order.OrderCode,
DeliveryNo: order.DeliveryCode,
OrderAmount: order.OrderAmount(),
OrderAmount: order.PlanOrderAmount,
UpdateTime: order.UpdateTime.Unix() * 1000,
MyDividend: order.OrderTotalBonus(),
MyDividend: bonusStatic.OrderTotalBonus(),
IsRead: order.IsRead(),
}
}
... ...
... ... @@ -2,7 +2,7 @@ package domain
import "time"
type CustomerService struct {
type ImCustomerService struct {
// id
Id int64
// 用户id(合伙人Id)
... ... @@ -17,14 +17,14 @@ type CustomerService struct {
UpdateTime time.Time
}
type CustomerServiceRepository interface {
Save(dm *CustomerService) (*CustomerService, error)
Remove(dm *CustomerService) (*CustomerService, error)
FindOne(queryOptions map[string]interface{}) (*CustomerService, error)
Find(queryOptions map[string]interface{}) (int64, []*CustomerService, error)
type ImCustomerServiceRepository interface {
Save(dm *ImCustomerService) (*ImCustomerService, error)
Remove(dm *ImCustomerService) (*ImCustomerService, error)
FindOne(queryOptions map[string]interface{}) (*ImCustomerService, error)
Find(queryOptions map[string]interface{}) (int64, []*ImCustomerService, error)
}
func (m *CustomerService) Identify() interface{} {
func (m *ImCustomerService) Identify() interface{} {
if m.Id == 0 {
return nil
}
... ...
... ... @@ -121,6 +121,21 @@ func (m *OrderBase) IsRead() int {
return 1
}
func (m *OrderBase) OrderBonusStatic() *OrderStatics {
return &OrderStatics{
BonusStatus: m.BonusStatus,
PlanOrderCount: m.PlanOrderCount,
PlanOrderAmount: m.PlanOrderAmount,
UseOrderCount: m.UseOrderCount,
UseOrderAmount: m.UseOrderAmount,
PlanPartnerBonus: m.PlanPartnerBonus,
UsePartnerBonus: m.UsePartnerBonus,
PartnerBonusHas: m.PartnerBonusHas,
PartnerBonusNot: m.PartnerBonusNot,
PartnerBonusExpense: m.PartnerBonusExpense,
}
}
type OrderQueryOption struct {
PartnerId int64 `json:"partnerId,omitempty"`
OrderType int `json:"orderType,omitempty"`
... ...
package domain
import "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
//分洪统计
type OrderStatics struct {
//1:待支付分红 2:已支付分红
BonusStatus int8
//预计的订单内货品总数
PlanOrderCount int
//预计的订单的总金额
PlanOrderAmount float64
//按需使用的订单内货品总数 (初始值=-1)
UseOrderCount int
//按需使用的订单内货品总数 (初始值=-1)
UseOrderAmount float64
//合伙人应收分红
PlanPartnerBonus float64
//调整后的合伙人应收分红 (初始值=-1)
UsePartnerBonus float64
//合伙人已收分红
PartnerBonusHas float64
//合伙人未收分红
PartnerBonusNot float64
//合伙人分红支出
PartnerBonusExpense float64
}
//订单应收分红
func (m *OrderStatics) OrderTotalBonus() float64 {
if m.UseOrderCount >= 0 {
return utils.Decimal(m.UsePartnerBonus + m.PartnerBonusExpense)
}
return utils.Decimal(m.PlanPartnerBonus)
}
//订单已收分红
func (m *OrderStatics) OrderBonusReceive() float64 {
return utils.Decimal(m.PartnerBonusHas)
}
//订单未收分红
func (m *OrderStatics) OrderBonusWait() float64 {
bonusWait := m.OrderTotalBonus() - m.OrderBonusReceive()
if bonusWait < 0 {
return 0
}
return bonusWait
}
//分红支出
func (m *OrderStatics) OrderBonusOutstanding() float64 {
return utils.Decimal(m.PartnerBonusExpense)
}
//订单被取消金额
func (m *OrderStatics) OrderAmountCancel() float64 {
if m.UseOrderAmount < 0 {
return 0
}
if m.PlanOrderAmount > m.UseOrderAmount {
return 0
}
return utils.Decimal(m.UseOrderAmount - m.PlanOrderAmount)
}
//订单金额
func (m *OrderStatics) OrderAmount() float64 {
if m.UseOrderAmount < 0 {
return m.PlanOrderAmount
}
return m.UseOrderAmount
}
... ...
... ... @@ -20,7 +20,8 @@ func (dao *OrderBaseDao) OrderStatics(option *domain.OrderStaticQuery) (count in
var orderAmount float64
q := tx.Model(order)
q.ColumnExpr("count(*) count")
q.ColumnExpr("sum(case when use_order_amount >0 THEN use_order_amount else plan_order_amount END) total_order_actual_amount")
//q.ColumnExpr("sum(case when use_order_amount >0 THEN use_order_amount else plan_order_amount END) total_order_actual_amount")
q.ColumnExpr("sum(plan_order_amount) total_order_actual_amount")
q.ColumnExpr("sum(use_order_amount) total_order_amount")
if option.PartnerId > 0 {
q.Where(`"order_base".partner_id =?`, option.PartnerId)
... ...
... ... @@ -34,7 +34,7 @@ func init() {
(*models.OrderBase)(nil),
(*models.OrderGood)(nil),
(*models.ImInfo)(nil),
(*models.CustomerService)(nil),
(*models.ImCustomerService)(nil),
} {
err := DB.CreateTable(model, &orm.CreateTableOptions{
Temp: false,
... ...
... ... @@ -2,8 +2,8 @@ package models
import "time"
type CustomerService struct {
tableName struct{} `pg:"customer_service"`
type ImCustomerService struct {
tableName struct{} `pg:"im_customer_service"`
// id
Id int64
// 用户id(合伙人Id)
... ...
... ... @@ -7,14 +7,14 @@ import (
. "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
)
type CustomerServiceRepository struct {
type ImCustomerServiceRepository struct {
transactionContext *transaction.TransactionContext
}
func (repository *CustomerServiceRepository) Save(dm *domain.CustomerService) (*domain.CustomerService, error) {
func (repository *ImCustomerServiceRepository) Save(dm *domain.ImCustomerService) (*domain.ImCustomerService, error) {
var (
err error
m = &models.CustomerService{}
m = &models.ImCustomerService{}
tx = repository.transactionContext.PgTx
)
if err = GobModelTransform(m, dm); err != nil {
... ... @@ -32,63 +32,63 @@ func (repository *CustomerServiceRepository) Save(dm *domain.CustomerService) (*
return dm, nil
}
func (repository *CustomerServiceRepository) Remove(CustomerService *domain.CustomerService) (*domain.CustomerService, error) {
func (repository *ImCustomerServiceRepository) Remove(ImCustomerService *domain.ImCustomerService) (*domain.ImCustomerService, error) {
var (
tx = repository.transactionContext.PgTx
CustomerServiceModel = &models.CustomerService{Id: CustomerService.Identify().(int64)}
tx = repository.transactionContext.PgTx
ImCustomerServiceModel = &models.ImCustomerService{Id: ImCustomerService.Identify().(int64)}
)
if _, err := tx.Model(CustomerServiceModel).Where("id = ?", CustomerService.Id).Delete(); err != nil {
return CustomerService, err
if _, err := tx.Model(ImCustomerServiceModel).Where("id = ?", ImCustomerService.Id).Delete(); err != nil {
return ImCustomerService, err
}
return CustomerService, nil
return ImCustomerService, nil
}
func (repository *CustomerServiceRepository) FindOne(queryOptions map[string]interface{}) (*domain.CustomerService, error) {
func (repository *ImCustomerServiceRepository) FindOne(queryOptions map[string]interface{}) (*domain.ImCustomerService, error) {
tx := repository.transactionContext.PgTx
CustomerServiceModel := new(models.CustomerService)
query := NewQuery(tx.Model(CustomerServiceModel), queryOptions)
ImCustomerServiceModel := new(models.ImCustomerService)
query := NewQuery(tx.Model(ImCustomerServiceModel), queryOptions)
query.SetWhere("id = ?", "id")
query.SetWhere("user_id = ?", "user_id")
if err := query.First(); err != nil {
return nil, domain.QueryNoRow
}
if CustomerServiceModel.Id == 0 {
if ImCustomerServiceModel.Id == 0 {
return nil, domain.QueryNoRow
}
return repository.transformPgModelToDomainModel(CustomerServiceModel)
return repository.transformPgModelToDomainModel(ImCustomerServiceModel)
}
func (repository *CustomerServiceRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CustomerService, error) {
func (repository *ImCustomerServiceRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ImCustomerService, error) {
tx := repository.transactionContext.PgTx
var CustomerServiceModels []*models.CustomerService
CustomerServices := make([]*domain.CustomerService, 0)
query := NewQuery(tx.Model(&CustomerServiceModels), queryOptions).
var ImCustomerServiceModels []*models.ImCustomerService
ImCustomerServices := make([]*domain.ImCustomerService, 0)
query := NewQuery(tx.Model(&ImCustomerServiceModels), queryOptions).
SetOrder("create_time", "sortByCreateTime").
SetOrder("update_time", "sortByUpdateTime").
SetOrder("id", "sortById")
var err error
if query.AffectRow, err = query.SelectAndCount(); err != nil {
return 0, CustomerServices, err
return 0, ImCustomerServices, err
}
for _, CustomerServiceModel := range CustomerServiceModels {
if CustomerService, err := repository.transformPgModelToDomainModel(CustomerServiceModel); err != nil {
return 0, CustomerServices, err
for _, ImCustomerServiceModel := range ImCustomerServiceModels {
if ImCustomerService, err := repository.transformPgModelToDomainModel(ImCustomerServiceModel); err != nil {
return 0, ImCustomerServices, err
} else {
CustomerServices = append(CustomerServices, CustomerService)
ImCustomerServices = append(ImCustomerServices, ImCustomerService)
}
}
return int64(query.AffectRow), CustomerServices, nil
return int64(query.AffectRow), ImCustomerServices, nil
}
func (repository *CustomerServiceRepository) transformPgModelToDomainModel(CustomerServiceModel *models.CustomerService) (*domain.CustomerService, error) {
m := &domain.CustomerService{}
err := GobModelTransform(m, CustomerServiceModel)
func (repository *ImCustomerServiceRepository) transformPgModelToDomainModel(ImCustomerServiceModel *models.ImCustomerService) (*domain.ImCustomerService, error) {
m := &domain.ImCustomerService{}
err := GobModelTransform(m, ImCustomerServiceModel)
return m, err
}
func NewCustomerServiceRepository(transactionContext *transaction.TransactionContext) (*CustomerServiceRepository, error) {
func NewImCustomerServiceRepository(transactionContext *transaction.TransactionContext) (*ImCustomerServiceRepository, error) {
if transactionContext == nil {
return nil, ERR_EMPTY_TC
}
return &CustomerServiceRepository{transactionContext: transactionContext}, nil
return &ImCustomerServiceRepository{transactionContext: transactionContext}, nil
}
... ...