...
|
...
|
@@ -55,27 +55,6 @@ func (dao *CreditAccountDao) CheckCreditAccountNumberAvailable(queryOptions map[ |
|
|
|
|
|
// 分红统计(分红明细)
|
|
|
func (dao *CreditAccountDao) DividendsStatistics(queryOptions map[string]interface{}, v interface{}) error {
|
|
|
// sql := `
|
|
|
//select
|
|
|
//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
|
|
|
//`
|
|
|
//
|
|
|
//
|
|
|
// if _, ok := queryOptions["beginTime"]; ok {
|
|
|
// sql += `created_at>? and created_at<? and `
|
|
|
// }
|
|
|
// 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"])
|
|
|
|
|
|
creditAccount := new(models.CreditAccount)
|
|
|
query := dao.transactionContext.PgTx.Model(creditAccount)
|
|
|
query.ColumnExpr(`sum(settlement_amount) total`)
|
...
|
...
|
@@ -95,6 +74,42 @@ func (dao *CreditAccountDao) DividendsStatistics(queryOptions map[string]interfa |
|
|
return err
|
|
|
}
|
|
|
|
|
|
// 分红统计(分红明细)
|
|
|
func (dao *CreditAccountDao) CooperationUsersDividendsStatistics(queryOptions map[string]interface{}, v interface{}) error {
|
|
|
creditAccount := new(models.CreditAccount)
|
|
|
query := dao.transactionContext.PgTx.Model(creditAccount)
|
|
|
query.ColumnExpr(`0 cooperation_time`)
|
|
|
query.ColumnExpr(`0 dividends_order_amount`)
|
|
|
query.ColumnExpr(`sum(settlement_amount) divides_amount`)
|
|
|
query.ColumnExpr(`sum((case when payment_status = 1 then actually_paid_amount else 0 end)) actually_paid_amount`)
|
|
|
query.ColumnExpr(`max(participator->>'userId') user_id`)
|
|
|
query.ColumnExpr(`max(participator#>>'{userInfo,userName}') user_name`)
|
|
|
if _, ok := queryOptions["beginTime"]; ok {
|
|
|
query.Where(`created_at>? `, queryOptions["beginTime"])
|
|
|
query.Where(`created_at<? `, queryOptions["endTime"])
|
|
|
}
|
|
|
if v, ok := queryOptions["userBaseId"]; ok && v.(int64) > 0 {
|
|
|
query.Where(fmt.Sprintf(`participator->>'userBaseId'='%v' `, v))
|
|
|
}
|
|
|
if v, ok := queryOptions["orgId"]; ok && v.(int64) > 0 {
|
|
|
query.Where(fmt.Sprintf(` org->>'orgId'= '%v'`, v))
|
|
|
}
|
|
|
query.Where("deleted_at is null")
|
|
|
if v, ok := queryOptions["sortByActuallyPaidAmount"]; ok {
|
|
|
vInt := v.(int)
|
|
|
if vInt == 1 {
|
|
|
query.Order("divides_amount asc")
|
|
|
} else {
|
|
|
query.Order("divides_amount desc")
|
|
|
}
|
|
|
}
|
|
|
query.GroupExpr("participator->>'userBaseId'")
|
|
|
query.Limit(queryOptions["limit"].(int))
|
|
|
query.Offset(queryOptions["offset"].(int))
|
|
|
err := query.Select(v)
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
func NewCreditAccountDao(transactionContext *pgTransaction.TransactionContext) (*CreditAccountDao, error) {
|
|
|
if transactionContext == nil {
|
|
|
return nil, fmt.Errorf("transactionContext参数不能为空")
|
...
|
...
|
|