puzhibing
9 小时以前 88580dae55106dcf4a8f80693b90638e07af02fa
ruoyi-service/ruoyi-order/src/main/resources/mapper/order/TShoppingOrderMapper.xml
@@ -44,24 +44,38 @@
        id, code, app_user_id, order_type, goods_id, coupon_id, purchase_quantity, app_user_address_id, order_amount, app_coupon_id, coupon_discount_amount, vip_discount, vip_discount_amount, payment_amount, payment_status, payment_type, serial_number, remark, status, express_company, express_number, consigner_id, consigner_time, receiving_time, cancellation_time, cancellation_id, refund_code, refund_amount, refund_status, refund_serial_number, refund_time, create_time, del_flag
    </sql>
    <select id="activityStatistics" resultType="com.ruoyi.order.api.vo.TActivityStatisticslVO">
        select * from (
        select t9.code ,t9.order_amount as orderAmount,
        t9.coupon_discount_amount as couponDiscountAmount,
        t9.vip_discount_amount as vipDiscountAmount,
        t9.payment_amount as paymentAmount,
        t9.create_time as createTime,
        t9.app_user_id as appUserId,
        1 as orderType
        from t_charging_order t9
        where t9.id = 0
        <if test="req.orderType == null or req.orderType == 1">
        <if test="req.type == null or req.type == 1 or req.type == 2">
        select t1.code ,t1.order_amount as orderAmount,
               t1.coupon_discount_amount as couponDiscountAmount,
               t1.vip_discount_amount as vipDiscountAmount,
               t1.payment_amount as paymentAmount,
               t1.create_time as createTime,
               1 as orderType
            union all
            select
            t1.code ,
            t1.order_amount as orderAmount,
            t1.coupon_discount_amount as couponDiscountAmount,
            t1.vip_discount_amount as vipDiscountAmount,
            t1.payment_amount as paymentAmount,
            t1.create_time as createTime,
            t1.app_user_id as appUserId,
            1 as orderType
            from t_charging_order t1
            where 1 = 1
            <if test="null != req.code and req.code!=''">
                and t1.code  LIKE CONCAT('%',#{req.code},'%')
            </if>
            <if test="req.type != null and req.type != '' and req.type == 1">
                and t1.coupon_discount_amount  IS NOT NULL and t1.coupon_discount_amount  != 0
            <if test="req.type != null and req.type == 1">
                and t1.coupon_discount_amount > 0
            </if>
            <if test="req.type != null and req.type != '' and req.type == 2">
                and t1.vip_discount_amount  IS NOT NULL and t1.vip_discount_amount  != 0
            <if test="req.type != null and req.type == 2">
                and t1.vip_discount_amount > 0
            </if>
            <if test="null != req.userIds and req.userIds.size()>0" >
                and t1.app_user_id in
@@ -78,147 +92,119 @@
            <if test="req.endTime != null and req.endTime != '' and req.startTime != null and req.startTime != ''">
                AND (t1.create_time between CONCAT(#{req.startTime},':00') and CONCAT(#{req.endTime},':59'))
            </if>
        and t1.recharge_payment_status =2
        and t1.refund_status !=2
            and (t1.vip_discount_amount > 0 or t1.coupon_discount_amount > 0)
            and t1.recharge_payment_status =2
            AND t1.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
        </if>
        </if>
        <if test="req.orderType == null or req.orderType == 2">
        <if test="req.type == null or req.type == 1 or req.type == 2">
            union all
            select t2.code ,t2.order_amount as orderAmount,
            t2.coupon_discount_amount as couponDiscountAmount,
            t2.vip_discount_amount as vipDiscountAmount,
            t2.payment_amount as paymentAmount,
            t2.create_time as createTime,
            2 as orderType
            from t_shopping_order t2
            where 1 = 1
            <if test="null != req.code and req.code!=''">
                and t2.code  LIKE CONCAT('%',#{req.code},'%')
            </if>
            <if test="req.type != null and req.type != '' and req.type == 1">
                and t2.coupon_discount_amount  IS NOT NULL and t2.coupon_discount_amount  != 0
            </if>
            <if test="req.type != null and req.type != '' and req.type == 2">
                and t2.vip_discount_amount  IS NOT NULL and t2.vip_discount_amount  != 0
            </if>
            <if test="req.type == null ">
                and t2.vip_discount_amount  IS NOT NULL and t2.vip_discount_amount  != 0 and t2.coupon_discount_amount  IS NOT NULL and t2.coupon_discount_amount  != 0
            </if>
            <if test="null != req.userIds and req.userIds.size()>0" >
                and t2.app_user_id in
                <foreach collection="req.userIds" item="item" index="index" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="req.endTime != null and req.endTime != '' and req.startTime != null and req.startTime != ''">
                AND (t2.create_time between CONCAT(#{req.startTime},':00') and CONCAT(#{req.endTime},':59'))
            </if>
            and t2.refund_status !=2
            and t2.payment_status =2
            AND t2.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
        </if>
        </if>
        <if test="req.orderType == null or req.orderType == 3">
            <if test="req.type == null or req.type == 3">
                union all
                select t3.code ,t3.order_amount as orderAmount,
                0 as couponDiscountAmount,
                t3.discount_amount as vipDiscountAmount,
                t3.payment_amount as paymentAmount,
                t3.create_time as createTime,
                3 as orderType
                from t_vip_order t3
                where 1 = 1
                and t3.type =1
                <if test="null != req.code and req.code!=''">
                    and t3.code  LIKE CONCAT('%',#{req.code},'%')
        <if test="req.siteId == null">
            <if test="req.orderType == null or req.orderType == 2">
                <if test="req.type == null or req.type == 1 or req.type == 2">
                    union all
                    select t2.code ,t2.order_amount as paymentAmount,
                    t2.coupon_discount_amount as couponDiscountAmount,
                    t2.vip_discount_amount as vipDiscountAmount,
                    t2.payment_amount as orderAmount,
                    t2.create_time as createTime,
                    t2.app_user_id as appUserId,
                    2 as orderType
                    from t_shopping_order t2
                    where 1 = 1
                    <if test="null != req.code and req.code!=''">
                        and t2.code  LIKE CONCAT('%',#{req.code},'%')
                    </if>
                    <if test="req.type != null and req.type != '' and req.type == 1">
                        and (t2.coupon_discount_amount  > 0)
                    </if>
                    <if test="req.type != null and req.type != '' and req.type == 2">
                        and ( t2.vip_discount_amount  > 0)
                    </if>
                    <if test="req.type == null ">
                        and (t2.vip_discount_amount  > 0 or t2.coupon_discount_amount  > 0)
                    </if>
                    <if test="null != req.userIds and req.userIds.size()>0" >
                        and t2.app_user_id in
                        <foreach collection="req.userIds" item="item" index="index" separator="," open="(" close=")">
                            #{item}
                        </foreach>
                    </if>
                    <if test="req.endTime != null and req.endTime != '' and req.startTime != null and req.startTime != ''">
                        AND (t2.create_time between CONCAT(#{req.startTime},':00') and CONCAT(#{req.endTime},':59'))
                    </if>
                    and t2.payment_status =2
                    AND t2.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
                </if>
                <if test="req.type == null ">
                    and t3.discount_amount  IS NOT NULL and t3.discount_amount  != 0
            </if>
            <if test="req.orderType == null or req.orderType == 3">
                <if test="req.type == null or req.type == 3">
                    union all
                    select t3.code ,t3.order_amount as orderAmount,
                    0 as couponDiscountAmount,
                    t3.discount_amount as vipDiscountAmount,
                    t3.payment_amount as paymentAmount,
                    t3.create_time as createTime,
                    t3.app_user_id as appUserId,
                    3 as orderType
                    from t_vip_order t3
                    where 1 = 1
                    and t3.type =1
                    <if test="null != req.code and req.code!=''">
                        and t3.code  LIKE CONCAT('%',#{req.code},'%')
                    </if>
                    and t3.discount_amount  > 0
                    <if test="null != req.userIds and req.userIds.size()>0" >
                        and t3.app_user_id in
                        <foreach collection="req.userIds" item="item" index="index" separator="," open="(" close=")">
                            #{item}
                        </foreach>
                    </if>
                    <if test="req.endTime != null and req.endTime != '' and req.startTime != null and req.startTime != ''">
                        AND (t3.create_time between CONCAT(#{req.startTime},':00') and CONCAT(#{req.endTime},':59'))
                    </if>
                    and t3.payment_status =2
                    AND t3.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
                </if>
                <if test="null != req.userIds and req.userIds.size()>0" >
                    and t3.app_user_id in
                    <foreach collection="req.userIds" item="item" index="index" separator="," open="(" close=")">
                        #{item}
                    </foreach>
            </if>
            <if test="req.orderType == null or req.orderType == 4">
                <if test="req.type == null or req.type == 4">
                    union all
                    select t5.code ,t5.order_amount as orderAmount,
                    0 as couponDiscountAmount,
                    0 as vipDiscountAmount,
                    0 as paymentAmount,
                    t5.create_time as createTime,
                    t5.app_user_id as appUserId,
                    4 as orderType
                    from t_grant_vip t5
                    where 1 = 1
                    <if test="null != req.code and req.code!=''">
                        and t5.code  LIKE CONCAT('%',#{req.code},'%')
                    </if>
                    <if test="null != req.userIds and req.userIds.size()>0" >
                        and t5.app_user_id in
                        <foreach collection="req.userIds" item="item" index="index" separator="," open="(" close=")">
                            #{item}
                        </foreach>
                    </if>
                    <if test="req.endTime != null and req.endTime != '' and req.startTime != null and req.startTime != ''">
                        AND (t5.create_time between CONCAT(#{req.startTime},':00') and CONCAT(#{req.endTime},':59'))
                    </if>
                    AND t5.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
                </if>
                <if test="req.endTime != null and req.endTime != '' and req.startTime != null and req.startTime != ''">
                    AND (t3.create_time between CONCAT(#{req.startTime},':00') and CONCAT(#{req.endTime},':59'))
                </if>
                and t3.payment_status =2
                AND t3.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
            </if>
        </if>
        <if test="req.orderType == null or req.orderType == 4">
            <if test="req.type == null or req.type == 4">
                union all
                select t4.code ,t4.order_amount as orderAmount,
                0 as couponDiscountAmount,
                t4.discount_amount as vipDiscountAmount,
                t4.payment_amount as paymentAmount,
                t4.create_time as createTime,
                4 as orderType
                from t_vip_order t4
                where 1 = 1
                and t4.type =2
                <if test="null != req.code and req.code!=''">
                    and t4.code  LIKE CONCAT('%',#{req.code},'%')
                </if>
                <if test="req.type == null ">
                    and t4.discount_amount  IS NOT NULL and t4.discount_amount  != 0
                </if>
                <if test="null != req.userIds and req.userIds.size()>0" >
                    and t4.app_user_id in
                    <foreach collection="req.userIds" item="item" index="index" separator="," open="(" close=")">
                        #{item}
                    </foreach>
                </if>
                <if test="req.endTime != null and req.endTime != '' and req.startTime != null and req.startTime != ''">
                    AND (t4.create_time between CONCAT(#{req.startTime},':00') and CONCAT(#{req.endTime},':59'))
                </if>
                and t4.payment_status =2
                AND t4.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
            </if>
        </if>
        <if test="req.orderType == null or req.orderType == 4">
            <if test="req.type == null or req.type == 4">
                union all
                select t5.code ,t5.order_amount as orderAmount,
                0 as couponDiscountAmount,
                0 as vipDiscountAmount,
                0 as paymentAmount,
                t5.create_time as createTime,
                4 as orderType
                from t_grant_vip t5
                where 1 = 1
                <if test="null != req.code and req.code!=''">
                    and t5.code  LIKE CONCAT('%',#{req.code},'%')
                </if>
                <if test="null != req.userIds and req.userIds.size()>0" >
                    and t5.app_user_id in
                    <foreach collection="req.userIds" item="item" index="index" separator="," open="(" close=")">
                        #{item}
                    </foreach>
                </if>
                <if test="req.endTime != null and req.endTime != '' and req.startTime != null and req.startTime != ''">
                    AND (t5.create_time between CONCAT(#{req.startTime},':00') and CONCAT(#{req.endTime},':59'))
                </if>
                AND t5.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
            </if>
        </if>
                    )
        order by createTime DESC
    </select>
    
    
    
    <select id="getNoInvoicedOrder" resultMap="BaseResultMap">
        select * from t_shopping_order where del_flag = 0 and app_user_id = #{appUserId}
        select * from t_shopping_order where del_flag = 0 and payment_status = 2 and status = 3 and app_user_id = #{appUserId} and refund_status is null
        <if test="null != month and '' != month">
            and DATE_FORMAT(create_time, '%Y-%m') = #{month}
        </if>
        and id not in (select order_id from t_order_invoice_detail where order_type = 2)
        and id not in (select tod.order_id from t_order_invoice_detail tod inner join t_order_invoice toi on toi.id = tod.order_invoice_id where tod.order_type = 2 and toi.status != 4)
        order by create_time desc
        <if test="null != pageCurr and null != pageSize">
            limit #{pageCurr}, #{pageSize}
@@ -227,9 +213,12 @@
    <select id="pageList" resultType="com.ruoyi.order.api.model.TShoppingOrder">
        select t1.*
        from t_shopping_order t1
        where 1=1
        where 1 = 1
        <if test="null != req.code and req.code!=''">
            and t1.code  LIKE CONCAT('%',#{req.code},'%')
        </if>
        <if test="null != req.status">
            and t1.status = #{req.status}
        </if>
        <if test="null != req.userIds and req.userIds.size()>0" >
            and t1.app_user_id in
@@ -238,22 +227,240 @@
            </foreach>
        </if>
        <if test="null != req.couponIds and req.couponIds.size()>0 or null != req.couponIds and req.couponIds.size()>0" >
            and (t1.goods_id in
            <foreach collection="req.goodsIds" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
                     or
        <if test="null != req.couponIds and req.couponIds.size()>0" >
            and t1.coupon_id in
            <foreach collection="req.couponIds" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
            )
        </if>
        <if test="null != req.goodsIds and req.goodsIds.size()>0" >
            and t1.goods_id in
            <foreach collection="req.goodsIds" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="startTime1 != null and startTime1!=''">
            and (t1.create_time between #{startTime1} and #{startTime2}
            and (t1.create_time between #{startTime1} and #{startTime2})
        </if>
        and t1.payment_status = 2
        AND t1.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
        order by t1.create_time desc
    </select>
    <select id="sixBefore" resultType="com.ruoyi.order.dto.SixShopDto">
        SELECT
            DATE_FORMAT( subquery.create_time, '%m' ) AS MONTH,
   count(1) AS count,
   SUM(payment_amount) AS paymentAmount
        FROM
            (
            SELECT
            create_time,
            payment_amount
            FROM
            t_shopping_order
            WHERE del_flag = 0 and payment_status = 2 and ISNULL(refund_status) and status!=4
            <if test="null != sixBefore">
                and create_time &gt;= #{sixBefore}
            </if>
            <if test="null != status">
                and status = #{status}
            </if>
            ) AS subquery
        GROUP BY
            DATE_FORMAT( subquery.create_time, '%m' )
    </select>
    <select id="getSumAmount" resultType="java.math.BigDecimal">
        select sum(payment_amount)
        from t_shopping_order
        where del_flag = 0 and payment_status = 2 and ISNULL(refund_status) and status!=4
        <if test="sixBefore != null">
            and DATE_FORMAT(create_time, '%Y-%m-%d') &gt;= DATE_FORMAT(#{sixBefore}, '%Y-%m-%d')
        </if>
    </select>
    <select id="getData" resultType="java.util.Map">
        SELECT
        DATE_FORMAT( subquery.create_time, '%Y-%m-%d' ) AS MONTH,
        count(1) AS orderNum,
        SUM(payment_amount) AS paymentAmount
        FROM
        (
        SELECT
        create_time,
        payment_amount
        FROM
        t_shopping_order
            WHERE del_flag = 0 and payment_status = 2 and ISNULL(refund_status) and status!=4 and
                DATE_FORMAT(create_time, '%Y-%m-%d') between #{statisticsQueryDto.startTime} and #{statisticsQueryDto.endTime}
        ) AS subquery
        GROUP BY
        DATE_FORMAT( subquery.create_time, '%Y-%m-%d' )
    </select>
    <select id="activityStatisticsNolimit" resultType="com.ruoyi.order.api.vo.TActivityStatisticslVO">
        select * from (
        select t9.code ,t9.order_amount as orderAmount,
        t9.coupon_discount_amount as couponDiscountAmount,
        t9.vip_discount_amount as vipDiscountAmount,
        t9.payment_amount as paymentAmount,
        t9.create_time as createTime,
        t9.app_user_id as appUserId,
        1 as orderType
        from t_charging_order t9
        where t9.id = 0
        <if test="req.orderType == null or req.orderType == 1">
            <if test="req.type == null or req.type == 1 or req.type == 2">
                union all
                select
                t1.code ,
                t1.order_amount as orderAmount,
                t1.coupon_discount_amount as couponDiscountAmount,
                t1.vip_discount_amount as vipDiscountAmount,
                t1.payment_amount as paymentAmount,
                t1.create_time as createTime,
                t1.app_user_id as appUserId,
                1 as orderType
                from t_charging_order t1
                where 1 = 1
                <if test="null != req.code and req.code!=''">
                    and t1.code  LIKE CONCAT('%',#{req.code},'%')
                </if>
                <if test="req.type != null and req.type == 1">
                    and t1.coupon_discount_amount > 0
                </if>
                <if test="req.type != null and req.type == 2">
                    and t1.vip_discount_amount > 0
                </if>
                <if test="null != req.userIds and req.userIds.size()>0" >
                    and t1.app_user_id in
                    <foreach collection="req.userIds" item="item" index="index" separator="," open="(" close=")">
                        #{item}
                    </foreach>
                </if>
                <if test="null != req.chargingPileIds and req.chargingPileIds.size()>0" >
                    and t1.charging_pile_id in
                    <foreach collection="req.chargingPileIds" item="item" index="index" separator="," open="(" close=")">
                        #{item}
                    </foreach>
                </if>
                <if test="req.endTime != null and req.endTime != '' and req.startTime != null and req.startTime != ''">
                    AND (t1.create_time between CONCAT(#{req.startTime},':00') and CONCAT(#{req.endTime},':59'))
                </if>
                and (t1.vip_discount_amount > 0 or t1.coupon_discount_amount > 0)
                and t1.recharge_payment_status =2
                AND t1.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
            </if>
        </if>
        <if test="req.siteId == null">
            <if test="req.orderType == null or req.orderType == 2">
                <if test="req.type == null or req.type == 1 or req.type == 2">
                    union all
                    select t2.code ,t2.order_amount as paymentAmount,
                    t2.coupon_discount_amount as couponDiscountAmount,
                    t2.vip_discount_amount as vipDiscountAmount,
                    t2.payment_amount as orderAmount,
                    t2.create_time as createTime,
                    t2.app_user_id as appUserId,
                    2 as orderType
                    from t_shopping_order t2
                    where 1 = 1
                    <if test="null != req.code and req.code!=''">
                        and t2.code  LIKE CONCAT('%',#{req.code},'%')
                    </if>
                    <if test="req.type != null and req.type != '' and req.type == 1">
                        and (t2.coupon_discount_amount  > 0)
                    </if>
                    <if test="req.type != null and req.type != '' and req.type == 2">
                        and ( t2.vip_discount_amount  > 0)
                    </if>
                    <if test="req.type == null ">
                        and (t2.vip_discount_amount  > 0 or t2.coupon_discount_amount  > 0)
                    </if>
                    <if test="null != req.userIds and req.userIds.size()>0" >
                        and t2.app_user_id in
                        <foreach collection="req.userIds" item="item" index="index" separator="," open="(" close=")">
                            #{item}
                        </foreach>
                    </if>
                    <if test="req.endTime != null and req.endTime != '' and req.startTime != null and req.startTime != ''">
                        AND (t2.create_time between CONCAT(#{req.startTime},':00') and CONCAT(#{req.endTime},':59'))
                    </if>
                    and t2.payment_status =2
                    AND t2.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
                </if>
            </if>
            <if test="req.orderType == null or req.orderType == 3">
                <if test="req.type == null or req.type == 3">
                    union all
                    select t3.code ,t3.order_amount as orderAmount,
                    0 as couponDiscountAmount,
                    t3.discount_amount as vipDiscountAmount,
                    t3.payment_amount as paymentAmount,
                    t3.create_time as createTime,
                    t3.app_user_id as appUserId,
                    3 as orderType
                    from t_vip_order t3
                    where 1 = 1
                    and t3.type =1
                    <if test="null != req.code and req.code!=''">
                        and t3.code  LIKE CONCAT('%',#{req.code},'%')
                    </if>
                    and t3.discount_amount  > 0
                    <if test="null != req.userIds and req.userIds.size()>0" >
                        and t3.app_user_id in
                        <foreach collection="req.userIds" item="item" index="index" separator="," open="(" close=")">
                            #{item}
                        </foreach>
                    </if>
                    <if test="req.endTime != null and req.endTime != '' and req.startTime != null and req.startTime != ''">
                        AND (t3.create_time between CONCAT(#{req.startTime},':00') and CONCAT(#{req.endTime},':59'))
                    </if>
                    and t3.payment_status =2
                    AND t3.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
                </if>
            </if>
            <if test="req.orderType == null or req.orderType == 4">
                <if test="req.type == null or req.type == 4">
                    union all
                    select t5.code ,t5.order_amount as orderAmount,
                    0 as couponDiscountAmount,
                    0 as vipDiscountAmount,
                    0 as paymentAmount,
                    t5.create_time as createTime,
                    t5.app_user_id as appUserId,
                    4 as orderType
                    from t_grant_vip t5
                    where 1 = 1
                    <if test="null != req.code and req.code!=''">
                        and t5.code  LIKE CONCAT('%',#{req.code},'%')
                    </if>
                    <if test="null != req.userIds and req.userIds.size()>0" >
                        and t5.app_user_id in
                        <foreach collection="req.userIds" item="item" index="index" separator="," open="(" close=")">
                            #{item}
                        </foreach>
                    </if>
                    <if test="req.endTime != null and req.endTime != '' and req.startTime != null and req.startTime != ''">
                        AND (t5.create_time between CONCAT(#{req.startTime},':00') and CONCAT(#{req.endTime},':59'))
                    </if>
                    AND t5.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
                </if>
            </if>
        </if>
        )
        order by createTime DESC
    </select>
</mapper>