...
|
...
|
@@ -119,6 +119,51 @@ func (dao *CreditAccountDao) CooperationUsersDividendsStatistics(queryOptions ma |
|
|
return err
|
|
|
}
|
|
|
|
|
|
// 共创企业分红统计
|
|
|
func (dao *CreditAccountDao) CooperationCompanyDividendsStatistics(queryOptions map[string]interface{}, v interface{}) error {
|
|
|
creditAccount := new(models.CreditAccount)
|
|
|
query := dao.transactionContext.PgTx.Model(creditAccount)
|
|
|
query.ColumnExpr(`0 cooperation_time`)
|
|
|
query.ColumnExpr(`sum(good_amount_count) 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(org->>'orgId') org_id`)
|
|
|
query.ColumnExpr(`max(org->>'orgName') org_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))
|
|
|
}
|
|
|
if v, ok := queryOptions["paymentStatus"]; ok && v.(int32) > 0 {
|
|
|
query.Where("paymentStatus = ?", v)
|
|
|
}
|
|
|
if v, ok := queryOptions["beginTime"]; ok && !v.(time.Time).IsZero() {
|
|
|
query.Where("created_at >= ?", v)
|
|
|
}
|
|
|
if v, ok := queryOptions["endTime"]; ok && !v.(time.Time).IsZero() {
|
|
|
query.Where("created_at < ?", v)
|
|
|
}
|
|
|
query.Where("deleted_at is null")
|
|
|
if v, ok := queryOptions["sortByActuallyPaidAmount"]; ok {
|
|
|
vInt := v.(int)
|
|
|
if vInt == 1 {
|
|
|
query.Order("actually_paid_amount asc")
|
|
|
} else {
|
|
|
query.Order("actually_paid_amount desc")
|
|
|
}
|
|
|
}
|
|
|
query.GroupExpr("org->>'orgId'")
|
|
|
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参数不能为空")
|
...
|
...
|
|