<?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.ruoyi.mall.mapper.IndexDataMapper">

    <select id="selectTodayPrice" resultType="decimal">
        SELECT
            IFNULL(SUM(payment), 0.00)
        FROM
            mall_order_order
        <where>
            <if test="shopId != null and shopId != 0">and shop_id = #{shopId}</if>
            and del_flag = '0'
            AND `status` IN ('3', '4')
            AND DATE_FORMAT(create_at, '%Y-%m-%d') = CURDATE()
        </where>
    </select>

    <select id="selectTodayVisitCount" resultType="integer">
        SELECT
            COUNT(id)
        FROM
            mall_member_login_log
        WHERE DATE_FORMAT(login_at, '%Y-%m-%d') = CURDATE()
    </select>

    <select id="selectTodayOrderCount" resultType="integer">
        SELECT
            COUNT(id)
        FROM
            mall_order_order
        <where>
            <if test="shopId != null and shopId != 0">and shop_id = #{shopId}</if>
            and del_flag = '0'
            AND `status` IN ('3', '4')
            AND DATE_FORMAT(create_at, '%Y-%m-%d') = CURDATE()
        </where>

    </select>

    <select id="oneWeekDate" resultType="string">
        SELECT
            `date`
        FROM
            past_7_day_view
        ORDER BY `date` ASC
    </select>

    <select id="oneWeekPrice" resultType="decimal">
        SELECT
            (SELECT
                 IFNULL(SUM(payment), 0.00)
             FROM
                 mall_order_order
            <where>
                <if test="shopId != null and shopId != 0">and shop_id = #{shopId}</if>
                and del_flag = '0'
                AND `status` IN ('3', '4')
                AND DATE_FORMAT(create_at, '%Y-%m-%d') = p7dv.date)
            </where>

        FROM
            past_7_day_view p7dv
        ORDER BY `date` ASC
    </select>

    <select id="oneWeekVisitCount" resultType="integer">
        SELECT
            (SELECT
                 COUNT(id)
             FROM
                 mall_member_login_log
             WHERE DATE_FORMAT(login_at, '%Y-%m-%d') = p7dv.date)
        FROM
            past_7_day_view p7dv
        ORDER BY `date` ASC
    </select>

    <select id="oneWeekOrderCount" resultType="integer">
        SELECT
            (SELECT
                 COUNT(id)
             FROM
                 mall_order_order
            <where>
                <if test="shopId != null and shopId != 0">and shop_id = #{shopId}</if>
                and del_flag = '0'
                AND `status` IN ('3', '4')
                AND DATE_FORMAT(create_at, '%Y-%m-%d') = p7dv.date)
            </where>

        FROM
            past_7_day_view p7dv
        ORDER BY `date` ASC
    </select>

</mapper>
