作者 陈志颖

合并分支 'dev' 到 'test'

Dev



查看合并请求 !16
... ... @@ -16,7 +16,7 @@ type CooperationModeStatisticsDto struct {
// 共创人数
CooperationPeople float64 `json:"cooperationPeople"`
// 分红预算
DividendsEstimate string `json:"dividendsEstimate"`
DividendsEstimate float64 `json:"dividendsEstimate"`
// 订单金额
OrderAmount float64 `json:"orderAmount"`
// 共创模式编号
... ...
... ... @@ -107,6 +107,30 @@ func (dao *DividendsEstimateDao) CountDividendsEstimate(queryOptions map[string]
}
}
// CountDividendsEstimate 统计当前分红预算单总数
func (dao *DividendsEstimateDao) CountDividendsEstimateDividendsAmount(queryOptions map[string]interface{}) (float64, error) {
tx := dao.transactionContext.PgTx
var dividendsEstimateModels []*models.DividendsEstimate
query := tx.Model(&dividendsEstimateModels)
query.ColumnExpr("sum(dividends_amount) amount")
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`dividends_estimate.company @> '{"companyId":"?"}'`, companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query = query.Where(`dividends_estimate.org @> '{"orgId":"?"}'`, orgId)
}
if _, ok := queryOptions["beginTime"]; ok {
query.Where(fmt.Sprintf("created_at>='%s' and created_at<'%s'", (queryOptions["beginTime"].(time.Time)).Format(time.RFC3339), (queryOptions["endTime"].(time.Time)).Format(time.RFC3339)))
}
query.AllWithDeleted()
query.Where("is_canceled is null")
var dividendsAmount float64
if err := query.Select(&dividendsAmount); err != nil {
return 0, err
}
return dividendsAmount, nil
}
func NewDividendsEstimateDao(transactionContext *pgTransaction.TransactionContext) (*DividendsEstimateDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为空")
... ...
... ... @@ -5,7 +5,6 @@ import (
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"time"
)
type OrderGoodDao struct {
... ... @@ -81,32 +80,6 @@ func (dao *OrderGoodDao) CooperationUserModeStatistics(queryOptions map[string]i
return goods, err
}
// DividendsStatistics 企业分红统计
//
// queryOptions 查询参数
// - beginTime 开始时间
// - endTime 结束时间
// - companyId 企业Id
// - orgId 组织Id
// - paymentStatus 支付状态
func (dao *OrderGoodDao) CompanyDividendsStatistics(queryOptions map[string]interface{}) (*domain.DividendStatisticsDto, error) {
tx := dao.transactionContext.PgTx
var queryTime, queryPaymentStatus string
if _, ok := queryOptions["beginTime"]; ok {
queryTime = fmt.Sprintf("and created_at>='%s' and created_at<'%s'", (queryOptions["beginTime"].(time.Time)).Format(time.RFC3339), (queryOptions["endTime"].(time.Time)).Format(time.RFC3339))
}
if _, ok := queryOptions["paymentStatus"]; ok {
queryPaymentStatus = fmt.Sprintf(" and payment_status=%v", queryOptions["paymentStatus"])
}
sql := fmt.Sprintf(`select sum(actually_paid_amount) dividends_estimate,0 order_amount
from credit_accounts
where company->>'companyId' = '?' and org->>'orgId' = '?' and deleted_at is null %v %v
`, queryTime, queryPaymentStatus)
var s = &domain.DividendStatisticsDto{}
_, err := tx.Query(s, sql, queryOptions["companyId"], queryOptions["orgId"])
return s, err
}
func NewOrderGoodDao(transactionContext *pgTransaction.TransactionContext) (*OrderGoodDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
... ...
... ... @@ -347,7 +347,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
Roles: undertaker.Referrer.Roles,
UserInfo: undertaker.Referrer.UserInfo,
UserType: undertaker.Referrer.UserType,
UserName: undertaker.Referrer.UserInfo.UserName,
UserName: undertaker.Referrer.UserName,
UserPhone: undertaker.Referrer.UserPhone,
Company: undertaker.Referrer.Company,
},
... ...
... ... @@ -118,7 +118,6 @@ func (ptr *CooperationStatisticsService) CompanyDividendsStatistics(queryOptions
}
queryOptions = tool_funs.SimpleStructToMap(&request)
orderGoodDao, _ := dao.NewOrderGoodDao(ptr.transactionContext)
var beginTime, endTime time.Time
var res = make(map[string]interface{})
if request.Action == 1 {
... ... @@ -129,23 +128,28 @@ func (ptr *CooperationStatisticsService) CompanyDividendsStatistics(queryOptions
queryOptions["beginTime"] = beginTime
queryOptions["endTime"] = endTime
}
totalDividends, err := orderGoodDao.CompanyDividendsStatistics(queryOptions)
dividendsEstimateDao, _ := dao.NewDividendsEstimateDao(ptr.transactionContext)
dividendsEstimate, err := dividendsEstimateDao.CountDividendsEstimateDividendsAmount(queryOptions)
if err != nil {
return nil, err
}
queryOptions["paymentStatus"] = 2
dividendsEstimate, err := orderGoodDao.CompanyDividendsStatistics(queryOptions)
if err != nil {
var dividends = &CreditAccountStatisticsResponse{}
orderGoodDao, _ := dao.NewCreditAccountDao(ptr.transactionContext)
if err := orderGoodDao.DividendsStatistics(queryOptions, dividends); err != nil {
return nil, err
}
orderAmount := ptr.CalculateOrderAmount(queryOptions)
res["creditAccount"] = dividendsEstimate.DividendsEstimate // 本月账期结算统计
res["orderAmount"] = orderAmount // 订单金额统计
res["dividendsEstimate"] = totalDividends.DividendsEstimate // 分红预算统计
res["creditAccount"] = dividends.Paid // 本月账期结算统计
res["orderAmount"] = orderAmount // 订单金额统计
res["dividendsEstimate"] = utils.Round(dividendsEstimate, 1) // 分红预算统计
return res, nil
}
// CalculateOrderAmount 计算订单总金额
// 订单总金额 = 订单总金额 - 退货总金额
func (ptr *CooperationStatisticsService) CalculateOrderAmount(queryOption map[string]interface{}) float64 {
orderDao, err := dao.NewDividendsOrderDao(ptr.transactionContext)
if err != nil {
... ... @@ -157,9 +161,9 @@ func (ptr *CooperationStatisticsService) CalculateOrderAmount(queryOption map[st
}
returnedOrderDao, _ := dao.NewDividendsReturnedOrderDao(ptr.transactionContext)
returnedAmount, _ := returnedOrderDao.CalculateDividendsReturnedOrderAmount(queryOption)
if math.Abs(returnedAmount) > math.Abs(amount) {
return 0
}
//if math.Abs(returnedAmount) > math.Abs(amount) {
// return 0
//}
return utils.Round(math.Abs(amount)-math.Abs(returnedAmount), 1)
}
... ...