/ 风控支持 /

    1. SELECT U.user_id, U.country_id AS '国家', U.language AS '语言', U.email, U.telephone, T.withdrawing AS '提币申请', T.withdraw_fee AS '手续费',
    2. A.margin_balance/1e8 AS '保证金余额', T.times_deposit AS '充次数', T.times_withdraw AS '提次数', T.total_deposit AS '总充值', T.total_withdraw AS '总提现',
    3. from_unixtime(T.first_deposit/1000+28800,'%Y-%m-%d') AS '首充时间',
    4. from_unixtime(T.last_deposit/1000+28800,'%Y-%m-%d') AS '最后时间',
    5. from_unixtime(T.first_withdraw/1000+28800,'%Y-%m-%d') AS '首提时间',
    6. from_unixtime(T.last_withdraw/1000+28800,'%Y-%m-%d') AS '最后时间',
    7. C.total_commission AS '总佣金', B.total_bonus AS '总赠金',
    8. TS.transfer_in AS '转入',TS.transfer_out AS '转出', TS.transfer_in - TS.transfer_out AS '净转'
    9. FROM management.t_trade_user AS U
    10. LEFT JOIN clear.t_account AS A ON A.client_id = U.user_id
    11. LEFT JOIN (
    12. SELECT USER_ID, transaction_status,
    13. IF(transaction_status='0',amount/1e8,NULL) AS 'withdrawing',
    14. IF(transaction_status='0',withdraw_fee/1e8,NULL) AS 'withdraw_fee',
    15. COUNT(IF(transaction_status='5',true,NULL)) AS 'times_deposit',
    16. COUNT(IF(transaction_status='7',true,NULL)) AS 'times_withdraw',
    17. SUM(IF(transaction_status='5',amount/1e8,0)) AS 'total_deposit',
    18. SUM(IF(transaction_status='7',amount/1e8,0)) AS 'total_withdraw',
    19. MIN(IF(transaction_status='5',operate_time,NULL)) AS 'first_deposit',
    20. MAX(IF(transaction_status='5',operate_time,NULL)) AS 'last_deposit',
    21. MIN(IF(transaction_status='7',operate_time,NULL)) AS 'first_withdraw',
    22. MAX(IF(transaction_status='7',operate_time,NULL)) AS 'last_withdraw'
    23. FROM management.t_wallet_transaction_history WHERE transaction_status IN ('0','5','7')
    24. GROUP BY USER_ID) AS T
    25. ON U.USER_ID = T.USER_ID
    26. LEFT JOIN (SELECT inviter, SUM(commission_amount)/1e8 as 'total_commission' FROM affiliate.t_affiliate_commission_transfer GROUP BY inviter)AS C
    27. ON C.inviter = U.USER_ID
    28. LEFT JOIN (SELECT SUM(amount/1e8)AS total_bonus, in_client_id FROM management.t_donation_transfer WHERE transfer_status = 7 GROUP BY in_client_id) AS B
    29. ON B.in_client_id = U.USER_ID
    30. LEFT JOIN (SELECT transfer_out_client_id, transf