作者 陈志颖

合并分支 'dev' 到 'test'

Dev



查看合并请求 !16
@@ -16,7 +16,7 @@ type CooperationModeStatisticsDto struct { @@ -16,7 +16,7 @@ type CooperationModeStatisticsDto struct {
16 // 共创人数 16 // 共创人数
17 CooperationPeople float64 `json:"cooperationPeople"` 17 CooperationPeople float64 `json:"cooperationPeople"`
18 // 分红预算 18 // 分红预算
19 - DividendsEstimate string `json:"dividendsEstimate"` 19 + DividendsEstimate float64 `json:"dividendsEstimate"`
20 // 订单金额 20 // 订单金额
21 OrderAmount float64 `json:"orderAmount"` 21 OrderAmount float64 `json:"orderAmount"`
22 // 共创模式编号 22 // 共创模式编号
@@ -107,6 +107,30 @@ func (dao *DividendsEstimateDao) CountDividendsEstimate(queryOptions map[string] @@ -107,6 +107,30 @@ func (dao *DividendsEstimateDao) CountDividendsEstimate(queryOptions map[string]
107 } 107 }
108 } 108 }
109 109
  110 +// CountDividendsEstimate 统计当前分红预算单总数
  111 +func (dao *DividendsEstimateDao) CountDividendsEstimateDividendsAmount(queryOptions map[string]interface{}) (float64, error) {
  112 + tx := dao.transactionContext.PgTx
  113 + var dividendsEstimateModels []*models.DividendsEstimate
  114 + query := tx.Model(&dividendsEstimateModels)
  115 + query.ColumnExpr("sum(dividends_amount) amount")
  116 + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
  117 + query = query.Where(`dividends_estimate.company @> '{"companyId":"?"}'`, companyId)
  118 + }
  119 + if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
  120 + query = query.Where(`dividends_estimate.org @> '{"orgId":"?"}'`, orgId)
  121 + }
  122 + if _, ok := queryOptions["beginTime"]; ok {
  123 + 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)))
  124 + }
  125 + query.AllWithDeleted()
  126 + query.Where("is_canceled is null")
  127 + var dividendsAmount float64
  128 + if err := query.Select(&dividendsAmount); err != nil {
  129 + return 0, err
  130 + }
  131 + return dividendsAmount, nil
  132 +}
  133 +
110 func NewDividendsEstimateDao(transactionContext *pgTransaction.TransactionContext) (*DividendsEstimateDao, error) { 134 func NewDividendsEstimateDao(transactionContext *pgTransaction.TransactionContext) (*DividendsEstimateDao, error) {
111 if transactionContext == nil { 135 if transactionContext == nil {
112 return nil, fmt.Errorf("transactionContext参数不能为空") 136 return nil, fmt.Errorf("transactionContext参数不能为空")
@@ -5,7 +5,6 @@ import ( @@ -5,7 +5,6 @@ import (
5 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 5 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" 6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models" 7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
8 - "time"  
9 ) 8 )
10 9
11 type OrderGoodDao struct { 10 type OrderGoodDao struct {
@@ -81,32 +80,6 @@ func (dao *OrderGoodDao) CooperationUserModeStatistics(queryOptions map[string]i @@ -81,32 +80,6 @@ func (dao *OrderGoodDao) CooperationUserModeStatistics(queryOptions map[string]i
81 return goods, err 80 return goods, err
82 } 81 }
83 82
84 -// DividendsStatistics 企业分红统计  
85 -//  
86 -// queryOptions 查询参数  
87 -// - beginTime 开始时间  
88 -// - endTime 结束时间  
89 -// - companyId 企业Id  
90 -// - orgId 组织Id  
91 -// - paymentStatus 支付状态  
92 -func (dao *OrderGoodDao) CompanyDividendsStatistics(queryOptions map[string]interface{}) (*domain.DividendStatisticsDto, error) {  
93 - tx := dao.transactionContext.PgTx  
94 - var queryTime, queryPaymentStatus string  
95 - if _, ok := queryOptions["beginTime"]; ok {  
96 - 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))  
97 - }  
98 - if _, ok := queryOptions["paymentStatus"]; ok {  
99 - queryPaymentStatus = fmt.Sprintf(" and payment_status=%v", queryOptions["paymentStatus"])  
100 - }  
101 - sql := fmt.Sprintf(`select sum(actually_paid_amount) dividends_estimate,0 order_amount  
102 -from credit_accounts  
103 -where company->>'companyId' = '?' and org->>'orgId' = '?' and deleted_at is null %v %v  
104 -`, queryTime, queryPaymentStatus)  
105 - var s = &domain.DividendStatisticsDto{}  
106 - _, err := tx.Query(s, sql, queryOptions["companyId"], queryOptions["orgId"])  
107 - return s, err  
108 -}  
109 -  
110 func NewOrderGoodDao(transactionContext *pgTransaction.TransactionContext) (*OrderGoodDao, error) { 83 func NewOrderGoodDao(transactionContext *pgTransaction.TransactionContext) (*OrderGoodDao, error) {
111 if transactionContext == nil { 84 if transactionContext == nil {
112 return nil, fmt.Errorf("transactionContext参数不能为nil") 85 return nil, fmt.Errorf("transactionContext参数不能为nil")
@@ -347,7 +347,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -347,7 +347,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
347 Roles: undertaker.Referrer.Roles, 347 Roles: undertaker.Referrer.Roles,
348 UserInfo: undertaker.Referrer.UserInfo, 348 UserInfo: undertaker.Referrer.UserInfo,
349 UserType: undertaker.Referrer.UserType, 349 UserType: undertaker.Referrer.UserType,
350 - UserName: undertaker.Referrer.UserInfo.UserName, 350 + UserName: undertaker.Referrer.UserName,
351 UserPhone: undertaker.Referrer.UserPhone, 351 UserPhone: undertaker.Referrer.UserPhone,
352 Company: undertaker.Referrer.Company, 352 Company: undertaker.Referrer.Company,
353 }, 353 },
@@ -118,7 +118,6 @@ func (ptr *CooperationStatisticsService) CompanyDividendsStatistics(queryOptions @@ -118,7 +118,6 @@ func (ptr *CooperationStatisticsService) CompanyDividendsStatistics(queryOptions
118 } 118 }
119 queryOptions = tool_funs.SimpleStructToMap(&request) 119 queryOptions = tool_funs.SimpleStructToMap(&request)
120 120
121 - orderGoodDao, _ := dao.NewOrderGoodDao(ptr.transactionContext)  
122 var beginTime, endTime time.Time 121 var beginTime, endTime time.Time
123 var res = make(map[string]interface{}) 122 var res = make(map[string]interface{})
124 if request.Action == 1 { 123 if request.Action == 1 {
@@ -129,23 +128,28 @@ func (ptr *CooperationStatisticsService) CompanyDividendsStatistics(queryOptions @@ -129,23 +128,28 @@ func (ptr *CooperationStatisticsService) CompanyDividendsStatistics(queryOptions
129 queryOptions["beginTime"] = beginTime 128 queryOptions["beginTime"] = beginTime
130 queryOptions["endTime"] = endTime 129 queryOptions["endTime"] = endTime
131 } 130 }
132 - totalDividends, err := orderGoodDao.CompanyDividendsStatistics(queryOptions) 131 +
  132 + dividendsEstimateDao, _ := dao.NewDividendsEstimateDao(ptr.transactionContext)
  133 + dividendsEstimate, err := dividendsEstimateDao.CountDividendsEstimateDividendsAmount(queryOptions)
133 if err != nil { 134 if err != nil {
134 return nil, err 135 return nil, err
135 } 136 }
136 queryOptions["paymentStatus"] = 2 137 queryOptions["paymentStatus"] = 2
137 - dividendsEstimate, err := orderGoodDao.CompanyDividendsStatistics(queryOptions)  
138 - if err != nil { 138 + var dividends = &CreditAccountStatisticsResponse{}
  139 + orderGoodDao, _ := dao.NewCreditAccountDao(ptr.transactionContext)
  140 + if err := orderGoodDao.DividendsStatistics(queryOptions, dividends); err != nil {
139 return nil, err 141 return nil, err
140 } 142 }
141 orderAmount := ptr.CalculateOrderAmount(queryOptions) 143 orderAmount := ptr.CalculateOrderAmount(queryOptions)
142 144
143 - res["creditAccount"] = dividendsEstimate.DividendsEstimate // 本月账期结算统计 145 + res["creditAccount"] = dividends.Paid // 本月账期结算统计
144 res["orderAmount"] = orderAmount // 订单金额统计 146 res["orderAmount"] = orderAmount // 订单金额统计
145 - res["dividendsEstimate"] = totalDividends.DividendsEstimate // 分红预算统计 147 + res["dividendsEstimate"] = utils.Round(dividendsEstimate, 1) // 分红预算统计
146 return res, nil 148 return res, nil
147 } 149 }
148 150
  151 +// CalculateOrderAmount 计算订单总金额
  152 +// 订单总金额 = 订单总金额 - 退货总金额
149 func (ptr *CooperationStatisticsService) CalculateOrderAmount(queryOption map[string]interface{}) float64 { 153 func (ptr *CooperationStatisticsService) CalculateOrderAmount(queryOption map[string]interface{}) float64 {
150 orderDao, err := dao.NewDividendsOrderDao(ptr.transactionContext) 154 orderDao, err := dao.NewDividendsOrderDao(ptr.transactionContext)
151 if err != nil { 155 if err != nil {
@@ -157,9 +161,9 @@ func (ptr *CooperationStatisticsService) CalculateOrderAmount(queryOption map[st @@ -157,9 +161,9 @@ func (ptr *CooperationStatisticsService) CalculateOrderAmount(queryOption map[st
157 } 161 }
158 returnedOrderDao, _ := dao.NewDividendsReturnedOrderDao(ptr.transactionContext) 162 returnedOrderDao, _ := dao.NewDividendsReturnedOrderDao(ptr.transactionContext)
159 returnedAmount, _ := returnedOrderDao.CalculateDividendsReturnedOrderAmount(queryOption) 163 returnedAmount, _ := returnedOrderDao.CalculateDividendsReturnedOrderAmount(queryOption)
160 - if math.Abs(returnedAmount) > math.Abs(amount) {  
161 - return 0  
162 - } 164 + //if math.Abs(returnedAmount) > math.Abs(amount) {
  165 + // return 0
  166 + //}
163 return utils.Round(math.Abs(amount)-math.Abs(returnedAmount), 1) 167 return utils.Round(math.Abs(amount)-math.Abs(returnedAmount), 1)
164 } 168 }
165 169