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