<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.cyksj.mapper.mirrorshop.UserMirrorShopDistributeMoneyApplyMapper">


    <select id="getApplyDetailByUserId" resultType="com.cyksj.model.views.UserMirrorShopView">
        select ifnull(cast(sum(da.money) / 100 as decimal(10, 2)), 0) as gotMoney,
               cast(u.mp_money / 100 as decimal(10, 2))               as availableMoney,
               cast(sum(dp.money) / 100 as decimal(10, 2))               as joinFeeTaskMoney
        from (select id, mp_money from user where id = #{userId} limit 1) u
                 left join user_mirror_shop_distribute_money_apply da on da.user_id = u.id and verify_status = 'success'
        left join user_mirror_shop_distribute_waiting_send_points dp on dp.shop_user_id = u.id and dp.type = 2 and dp.send_status in ('waiting','success')
        group by u.id, u.mp_money
    </select>
</mapper>