<?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="org.jeecg.modules.system.app.mapper.AppOrderMapper">

    <select id="queryPage" resultType="org.jeecg.modules.system.app.vo.OrderPageVO">
        SELECT
        o.id,
        o.order_code,
        o.create_time,
        s.`name` siteName,
        o.amount,
        o.price
        FROM
        nm_order o
        LEFT JOIN nm_site s ON s.org_code = o.org_code
        <where>
            <if test="appOrderPageForm.orgCode != null and appOrderPageForm.orgCode !=''">
                and o.org_code = #{appOrderPageForm.orgCode}
            </if>
            <if test="appOrderPageForm.userPhone != null and appOrderPageForm.userPhone !=''">
                and o.use_phone LIKE CONCAT('%',#{appOrderPageForm.userPhone},'%')
            </if>
            <if test="appOrderPageForm.orderCode != null and appOrderPageForm.orderCode !=''">
                and o.order_code LIKE CONCAT('%',#{appOrderPageForm.orderCode},'%')
            </if>
            <if test="appOrderPageForm.orderStatus != null">
                and o.order_status = #{appOrderPageForm.orderStatus}
            </if>
            <if test="appOrderPageForm.afterSaleStatus != null">
                and o.after_sale_status = #{appOrderPageForm.afterSaleStatus}
            </if>
            <if test="appOrderPageForm.startTime != null">
                and DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%s') <![CDATA[ >= ]]> #{appOrderPageForm.startTime}
            </if>
            <if test="appOrderPageForm.endTime != null">
                and DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%s') <![CDATA[ <= ]]> #{appOrderPageForm.endTime}
            </if>
        </where>
        ORDER BY o.create_time DESC
    </select>
    <select id="countTypeAndProductIds" resultType="java.lang.Integer">
        select  count(1) from nm_order where product_ids in
        <foreach collection="productIds" item="productId" open="(" separator="," close=")">
            #{productId}
        </foreach>
        and `type`=#{type} and order_status in (1,2,3)
    </select>
    <select id="findByNewOrderInfo" resultType="org.jeecg.modules.app.vo.game.GameOrderVo">
        select b.avatar,b.username  from nm_order a
        left join  sys_user b on a.user_id = b.id
        where product_ids in
        <foreach collection="productIds" item="productId" open="(" separator="," close=")">
            #{productId}
        </foreach>
        and `type`=#{type} and order_status in (1,2,3)
        order by pay_time desc
        limit 20
    </select>
    <select id="findByTeachingCount" resultType="java.lang.Long">
        select count(1)  from nm_order_pro_info
        where product_id in
        <foreach collection="productIds" item="productId" open="(" separator="," close=")">
            #{productId}
        </foreach>
    </select>
    <select id="findByOrderNumCount" resultType="java.lang.Long">
        select count(DISTINCT  order_id)  from nm_order_pro_info
        where product_id in
        <foreach collection="productIds" item="productId" open="(" separator="," close=")">
            #{productId}
        </foreach>
    </select>
</mapper>