<?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="vip.xiaonuo.biz.modular.couponrecord.mapper.BizCouponRecordMapper">

    <select id="getPageList" resultType="vip.xiaonuo.biz.modular.couponrecord.entity.BizCouponRecord">
        select
            bcr.id,
            bcr.coupon_no,
            bcr.time,
            bcr.coupon_status,
            bcr.start_time,
            bcr.end_time,
            bcr.destroy_user,
            bcr.destroy_time,
            bcr.org_id,
            su.name userName,
            su.phone,
            u.name destroyUserName,
            so.name destroyOrgName,
            brr.coupon_amount
        from biz_coupon_record bcr
        left join biz_recharge_record brr on bcr.recharge_record_id = brr.id
        left join SYS_USER su on su.id = brr.user_id
        left join SYS_USER u on u.id = bcr.destroy_user
        left join SYS_ORG so on so.id = bcr.org_id
        ${ew.customSqlSegment}
    </select>
    <select id="getCouponNoList" resultType="vip.xiaonuo.biz.modular.couponrecord.entity.BizCouponRecord">
        SELECT
            brr.user_id,
            GROUP_CONCAT(bcr.coupon_no ORDER BY brr.user_id ASC SEPARATOR ', ') AS coupon_no
        FROM
            biz_coupon_record bcr
            LEFT JOIN biz_recharge_record brr ON bcr.recharge_record_id = brr.id
            ${ew.customSqlSegment}
    </select>
    <select id="getList" resultType="vip.xiaonuo.biz.modular.couponrecord.entity.BizCouponRecord">
        select
            bcr.id,
            bcr.coupon_no,
            bcr.time,
            bcr.coupon_status,
            bcr.start_time,
            bcr.end_time,
            bcr.destroy_user,
            bcr.destroy_time,
            bcr.org_id,
            su.name userName,
            su.phone,
            u.name destroyUserName,
            so.name destroyOrgName,
            brr.coupon_amount
        from biz_coupon_record bcr
                 left join biz_recharge_record brr on bcr.recharge_record_id = brr.id
                 left join SYS_USER su on su.id = brr.user_id
                 left join SYS_USER u on u.id = bcr.destroy_user
                 left join SYS_ORG so on so.id = bcr.org_id
            ${ew.customSqlSegment}
    </select>
</mapper>
