| @@ -311,51 +311,55 @@ | |||||
| ) wm | ) wm | ||||
| left join | left join | ||||
| ( | ( | ||||
| select merchant_id,sum(credit_num) sum_credit_num from wx_credit_history${shardFinalTableSuffix} | |||||
| where merchant_id is not null and merchant_id != -1 and credit_num > 0 | |||||
| select credit.merchant_id,sum(credit.credit_num) sum_credit_num from wx_credit_history${shardFinalTableSuffix} credit | |||||
| INNER JOIN wx_c_user_basic_info${shardFinalTableSuffix} basic ON basic.id = credit.c_user_id | |||||
| where credit.merchant_id is not null and credit.merchant_id != -1 and credit.credit_num > 0 | |||||
| <if test=" null != startTime "> | <if test=" null != startTime "> | ||||
| and create_date >= #{startTime} | |||||
| and credit.create_date >= #{startTime} | |||||
| </if> | </if> | ||||
| <if test=" null != endTime"> | <if test=" null != endTime"> | ||||
| and create_date < #{endTime} | |||||
| and credit.create_date < #{endTime} | |||||
| </if> | </if> | ||||
| GROUP BY merchant_id | |||||
| GROUP BY credit.merchant_id | |||||
| ) a on a.merchant_id = wm.id | ) a on a.merchant_id = wm.id | ||||
| left join | left join | ||||
| ( | ( | ||||
| select merchant_id,sum(credit_num) sum_credit_num from wx_credit_history${shardFinalTableSuffix} | |||||
| where merchant_id is not null and merchant_id != -1 and credit_num < 0 | |||||
| select credit.merchant_id,sum(credit.credit_num) sum_credit_num from wx_credit_history${shardFinalTableSuffix} credit | |||||
| INNER JOIN wx_c_user_basic_info${shardFinalTableSuffix} basic ON basic.id = credit.c_user_id | |||||
| where credit.merchant_id is not null and credit.merchant_id != -1 and credit.credit_num < 0 | |||||
| <if test=" null != startTime "> | <if test=" null != startTime "> | ||||
| and create_date >= #{startTime} | |||||
| and credit.create_date >= #{startTime} | |||||
| </if> | </if> | ||||
| <if test=" null != endTime"> | <if test=" null != endTime"> | ||||
| and create_date < #{endTime} | |||||
| and credit.create_date < #{endTime} | |||||
| </if> | </if> | ||||
| GROUP BY merchant_id | |||||
| GROUP BY credit.merchant_id | |||||
| ) b on b.merchant_id = wm.id | ) b on b.merchant_id = wm.id | ||||
| left join | left join | ||||
| ( | ( | ||||
| select merchant_id,count(distinct c_user_id) count_c_user_id from wx_credit_history${shardFinalTableSuffix} | |||||
| where merchant_id is not null and merchant_id != -1 and credit_num > 0 | |||||
| select credit.merchant_id,count(distinct credit.c_user_id) count_c_user_id from wx_credit_history${shardFinalTableSuffix} credit | |||||
| INNER JOIN wx_c_user_basic_info${shardFinalTableSuffix} basic ON basic.id = credit.c_user_id | |||||
| where credit.merchant_id is not null and credit.merchant_id != -1 and credit.credit_num > 0 | |||||
| <if test=" null != startTime "> | <if test=" null != startTime "> | ||||
| and create_date >= #{startTime} | |||||
| and credit.create_date >= #{startTime} | |||||
| </if> | </if> | ||||
| <if test=" null != endTime"> | <if test=" null != endTime"> | ||||
| and create_date < #{endTime} | |||||
| and credit.create_date < #{endTime} | |||||
| </if> | </if> | ||||
| GROUP BY merchant_id | |||||
| GROUP BY credit.merchant_id | |||||
| ) c on c.merchant_id = wm.id | ) c on c.merchant_id = wm.id | ||||
| left join | left join | ||||
| ( | ( | ||||
| select merchant_id,count(distinct c_user_id) count_c_user_id from wx_credit_history${shardFinalTableSuffix} | |||||
| where merchant_id is not null and merchant_id != -1 and credit_num < 0 | |||||
| select credit.merchant_id,count(distinct credit.c_user_id) count_c_user_id from wx_credit_history${shardFinalTableSuffix} credit | |||||
| INNER JOIN wx_c_user_basic_info${shardFinalTableSuffix} basic ON basic.id = credit.c_user_id | |||||
| where credit.merchant_id is not null and credit.merchant_id != -1 and credit.credit_num < 0 | |||||
| <if test=" null != startTime "> | <if test=" null != startTime "> | ||||
| and create_date >= #{startTime} | |||||
| and credit.create_date >= #{startTime} | |||||
| </if> | </if> | ||||
| <if test=" null != endTime"> | <if test=" null != endTime"> | ||||
| and create_date <= #{endTime} | |||||
| and credit.create_date <= #{endTime} | |||||
| </if> | </if> | ||||
| GROUP BY merchant_id | |||||
| GROUP BY credit.merchant_id | |||||
| ) d on d.merchant_id = wm.id | ) d on d.merchant_id = wm.id | ||||
| where (IFNULL(a.sum_credit_num,0) > 0 or IFNULL(b.sum_credit_num,0) < 0) | where (IFNULL(a.sum_credit_num,0) > 0 or IFNULL(b.sum_credit_num,0) < 0) | ||||
| ORDER BY sumAddCredit desc | ORDER BY sumAddCredit desc | ||||