作者 yangfu

分红预算统计修改

... ... @@ -61,13 +61,16 @@ sum(settlement_amount) total,
sum((case when payment_status = 1 then actually_paid_amount else 0 end)) paid,
sum((case when settlement_time is not null then settlement_amount else 0 end)) accounted
from credit_accounts
where created_at>? and created_at<?
where
`
if v, ok := queryOptions["userBaseId"]; ok {
sql += fmt.Sprintf(`and participator->>'userBaseId'='%v'`, v)
if _, ok := queryOptions["beginTime"]; ok {
sql += `created_at>? and created_at<? and `
}
if v, ok := queryOptions["orgId"]; ok {
sql += fmt.Sprintf(`and org->>'orgId'= '%v'`, v)
if v, ok := queryOptions["userBaseId"]; ok && v.(int64) > 0 {
sql += fmt.Sprintf(`participator->>'userBaseId'='%v'`, v)
}
if v, ok := queryOptions["orgId"]; ok && v.(int64) > 0 {
sql += fmt.Sprintf(`org->>'orgId'= '%v'`, v)
}
_, err := dao.transactionContext.PgDd.Query(v, sql, queryOptions["beginTime"], queryOptions["endTime"])
return err
... ...
... ... @@ -55,7 +55,27 @@ func (dao *DividendsOrderDao) CheckDividendsOrderNumberAvailable(queryOptions ma
// CalculateDividendsOrderAmount 计算分红订单金额
func (dao *DividendsOrderDao) CalculateDividendsOrderAmount(queryOptions map[string]interface{}) (float64, error) {
return 0, nil
tx := dao.transactionContext.PgTx
var dividendsOrderModel = new(models.DividendsOrder)
query := tx.Model(dividendsOrderModel)
query.ColumnExpr("sum(dividends_order_amount) dividends_order_amount")
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query.Where("company->>'companyId' = '?'", companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query.Where("org->>'orgId' = '?'", orgId)
}
if beginTime, ok := queryOptions["beginTime"]; ok {
query.Where("order_time>= ?", beginTime)
}
if endTime, ok := queryOptions["endTime"]; ok {
query.Where("order_time< ?", endTime)
}
err := query.Select()
if err != nil {
return 0, err
}
return dividendsOrderModel.DividendsOrderAmount, nil
}
func NewDividendsOrderDao(transactionContext *pgTransaction.TransactionContext) (*DividendsOrderDao, error) {
... ...
... ... @@ -35,6 +35,31 @@ func (dao *DividendsReturnedOrderDao) GenerateDividendsReturnedOrderNumber() (st
}
}
// CalculateDividendsOrderAmount 计算分红订单金额
func (dao *DividendsReturnedOrderDao) CalculateDividendsReturnedOrderAmount(queryOptions map[string]interface{}) (float64, error) {
tx := dao.transactionContext.PgTx
var dividendsOrderModel = new(models.DividendsReturnedOrder)
query := tx.Model(dividendsOrderModel)
query.ColumnExpr("sum(dividends_returned_order_refund) dividends_returned_order_refund")
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query.Where("company->>'companyId' = '?'", companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query.Where("org->>'orgId' = '?'", orgId)
}
if beginTime, ok := queryOptions["beginTime"]; ok {
query.Where("order_time>= ?", beginTime)
}
if endTime, ok := queryOptions["endTime"]; ok {
query.Where("order_time< ?", endTime)
}
err := query.Select()
if err != nil {
return 0, err
}
return dividendsOrderModel.DividendsReturnedOrderRefund, nil
}
func NewDividendsReturnedOrderDao(transactionContext *pgTransaction.TransactionContext) (*DividendsReturnedOrderDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能未")
... ...
... ... @@ -74,7 +74,7 @@ func (dao *OrderGoodDao) CompanyDividendsStatistics(queryOptions map[string]inte
}
sql := fmt.Sprintf(`select sum(actually_paid_amount) dividends_estimate,0 order_amount
from credit_accounts
where company->>'companyId' = '?' and org->>'orgId' = '?' %v %v
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"])
... ...
... ... @@ -8,6 +8,8 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
"math"
"time"
)
... ... @@ -23,6 +25,7 @@ func (ptr *CooperationStatisticsService) CooperationGoodsStatistics(queryOptions
OrgId int64 `json:"orgId" valid:"Required"`
RankType int `json:"rankType" valid:"Required"`
Top int `json:"top" valid:"Required"`
Offset int `json:"offset"`
}{}
if err := LoadQueryObject(queryOptions, &request); err != nil {
return nil, err
... ... @@ -46,6 +49,9 @@ func (ptr *CooperationStatisticsService) CooperationGoodsStatistics(queryOptions
if request.Top > 0 {
queryOptions["limit"] = request.Top
}
if request.Offset > 0 {
queryOptions["offset"] = request.Offset
}
goods, err := orderGoodDao.CooperationGoodsStatistics(queryOptions)
if err != nil {
return nil, err
... ... @@ -131,13 +137,31 @@ func (ptr *CooperationStatisticsService) CompanyDividendsStatistics(queryOptions
if err != nil {
return nil, err
}
orderAmount := ptr.CalculateOrderAmount(queryOptions)
res["creditAccount"] = totalDividends.DividendsEstimate
res["orderAmount"] = totalDividends.OrderAmount
res["dividendsEstimate"] = dividendsEstimate.DividendsEstimate
res["creditAccount"] = dividendsEstimate.DividendsEstimate // 本月账期结算统计
res["orderAmount"] = orderAmount // 订单金额统计
res["dividendsEstimate"] = totalDividends.DividendsEstimate // 分红预算统计
return res, nil
}
func (ptr *CooperationStatisticsService) CalculateOrderAmount(queryOption map[string]interface{}) float64 {
orderDao, err := dao.NewDividendsOrderDao(ptr.transactionContext)
if err != nil {
log.Logger.Error(err.Error())
}
amount, err := orderDao.CalculateDividendsOrderAmount(queryOption)
if err != nil {
log.Logger.Error(err.Error())
}
returnedOrderDao, _ := dao.NewDividendsReturnedOrderDao(ptr.transactionContext)
returnedAmount, _ := returnedOrderDao.CalculateDividendsReturnedOrderAmount(queryOption)
if math.Abs(returnedAmount) > math.Abs(amount) {
return 0
}
return utils.Round(math.Abs(amount)-math.Abs(returnedAmount), 1)
}
func LoadQueryOptions(queryOption map[string]interface{}, keys ...string) (map[string]interface{}, error) {
var res = make(map[string]interface{})
for i := 0; i < len(keys); i++ {
... ...
... ... @@ -92,6 +92,10 @@ func (ptr *CooperationStatisticsService) SearchContractDividends(queryOptions ma
}
// TODO: 3.根据合约查询订单金额
//for i:=range results{
// queryOptions["cooperationContractNumber"] =results[i].CooperationContractNumber
// results[i].DividendsOrderAmount = ptr.CalculateOrderAmount(queryOptions)
//}
return results, nil
}
... ... @@ -189,12 +193,32 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s
}
// 2.合约分红列表
if _, ok := queryOptions["userBaseId"]; ok {
} else if _, ok := queryOptions["orgId"]; ok {
}
res["dividends"] = []struct{}{}
creditAccountRepository, _ := repository.NewCreditAccountRepository(ptr.transactionContext)
queryOptions["cooperationContractNumber"] = contract.CooperationContractNumber
_, creditAccounts, err := creditAccountRepository.Find(queryOptions)
if err != nil {
return res, err
}
var dividends = make([]interface{}, 0)
for i := range creditAccounts {
a := creditAccounts[i]
dividends = append(dividends, map[string]interface{}{
"creditAccountId": a.CreditAccountId,
"goodName": "",
"dividendsType": a.AccountDetail.DividendsType,
"dividendsRatio": 0,
"dividendsAmount": a.AccountDetail.DividendsAmount,
"dividendsUser": map[string]interface{}{
"userInfo": a.Participator.UserInfo,
"userId": a.Participator.UserId,
},
"dividendsParticipateType": a.ParticipateType,
"paymentStatus": a.PaymentStatus,
"dividendsEstimateTime": a.CreatedAt.Unix() * 1000,
"orderOrReturnedOrderNum": a.CreditAccountOrderNum,
})
}
res["dividends"] = dividends
return res, nil
}
... ...
... ... @@ -12,6 +12,7 @@ func TransformToContractUndertakerFeedbackDomainModelFromPgModels(
FeedbackAttachment: contractUndertakerFeedbackModel.FeedbackAttachment,
FeedbackContent: contractUndertakerFeedbackModel.FeedbackContent,
CooperationContractNumber: contractUndertakerFeedbackModel.CooperationContractNumber,
CooperationContractName: contractUndertakerFeedbackModel.CooperationContractName,
ContractUndertaker: contractUndertakerFeedbackModel.ContractUndertaker,
Org: contractUndertakerFeedbackModel.Org,
Company: contractUndertakerFeedbackModel.Company,
... ...
... ... @@ -156,6 +156,15 @@ func (repository *ContractUndertakerFeedbackRepository) Find(queryOptions map[st
if undertakerName, ok := queryOptions["undertakerName"]; ok && undertakerName != "" {
query.Where("contract_undertaker->>'userName' like ?", fmt.Sprintf("%%%s%%", undertakerName))
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query.Where("company->>'companyId' = '?'", companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query.Where("org->>'orgId' = '?'", orgId)
}
if orgIds, ok := queryOptions["orgIds"]; ok && len(orgIds.([]int64)) > 0 {
query.Where("org->>'orgId' in (?)", pg.In(orgIds))
}
// 搜索内容包括项目合约名称、承接人姓名、承接内容关键字
if matchWord, ok := queryOptions["matchWord"]; ok && matchWord != "" {
query.WhereGroup(func(q *orm.Query) (*orm.Query, error) {
... ...
... ... @@ -201,6 +201,9 @@ func (repository *CreditAccountRepository) Find(queryOptions map[string]interfac
if participatorName, ok := queryOptions["participatorName"]; ok && participatorName != "" {
query.Where(`(credit_account.participator->>'userName')::text LIKE ?`, fmt.Sprintf("%%%s%%", participatorName))
}
if cooperationContractNumber, ok := queryOptions["cooperation_contract_number"]; ok && cooperationContractNumber != "" {
query.Where(`cooperation_contract_number = ?`, fmt.Sprintf("%%%s%%", cooperationContractNumber))
}
if paymentStatus, ok := queryOptions["paymentStatus"]; ok && paymentStatus.(int32) != 0 {
query.Where("payment_status = ?", paymentStatus)
}
... ...
... ... @@ -292,6 +292,9 @@ func (repository *DividendsEstimateRepository) Find(queryOptions map[string]inte
if orderOrReturnedOrderNum, ok := queryOptions["orderOrReturnedOrderNum"]; ok && orderOrReturnedOrderNum != "" {
query.Where("order_or_returned_order_num = ?", orderOrReturnedOrderNum)
}
if dividendsAccountStatus, ok := queryOptions["dividendsAccountStatus"]; ok && (dividendsAccountStatus.(int32)) > 0 {
query.Where("dividends_account_status = ?", dividendsAccountStatus)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query.Where("company->>'companyId' = '?'", companyId)
}
... ...