package com.hai.dao;

import com.hai.entity.HighOrder;
import com.hai.model.HighOrderData;
import com.hai.model.HighOrderModel;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;

import java.util.List;
import java.util.Map;

/**
 * mapper扩展类
 */
public interface HighOrderMapperExt {

    @Select({"SELECT * FROM high_order ho WHERE TIMESTAMPDIFF(MINUTE,ho.create_time,SYSDATE()) > 15 AND ho.order_status = 1"})
    @Results({
            @Result(column="id", property="id", jdbcType= JdbcType.BIGINT, id=true),
            @Result(column="order_no", property="orderNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="mem_id", property="memId", jdbcType=JdbcType.BIGINT),
            @Result(column="mem_name", property="memName", jdbcType=JdbcType.VARCHAR),
            @Result(column="pay_model", property="payModel", jdbcType=JdbcType.INTEGER),
            @Result(column="pay_type", property="payType", jdbcType=JdbcType.INTEGER),
            @Result(column="pay_gold", property="payGold", jdbcType=JdbcType.INTEGER),
            @Result(column="pay_price", property="payPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="pay_real_price", property="payRealPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="pay_serial_no", property="paySerialNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="order_status", property="orderStatus", jdbcType=JdbcType.INTEGER),
            @Result(column="total_price", property="totalPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="pay_time", property="payTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="cancel_time", property="cancelTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="finish_time", property="finishTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="remarks", property="remarks", jdbcType=JdbcType.VARCHAR),
            @Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR),
            @Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR),
            @Result(column="ext_3", property="ext3", jdbcType=JdbcType.VARCHAR)
    })
    List<HighOrder> getCloseOrder();

    @Select({
            "<script>",
            "select",
            "coupon_code_id, child_order_id, goods_name , giveaway_type , order_no,mem_name,mem_phone,pay_model,a.pay_type as pay_type, coupon.merchant_id as merchant_id, store_id,pay_gold,pay_price,pay_real_price, ",
            "pay_serial_no,order_status,total_price,a.create_time as create_time ,order_id,company_id, goods_type ",
            "from high_coupon coupon join (  select * from high_order od ",
            "join (select cc.id as coupon_code_id, co.goods_name , co.giveaway_type ,   cc.child_order_id, merchant_id,coupon_id,order_id,store_id, goods_type ",
            "from high_coupon_code cc join high_child_order co on cc.child_order_id = co.id) cocc on cocc.order_id = od.id ",
            ") a on coupon.id = a.coupon_id ",
            "where ",
            "1=1 ",
            "<if test='map.companyId != null'> AND company_id = #{map.companyId}  </if>",
            "<if test='map.merchantId != null'> AND merchant_id = #{map.merchantId}  </if>",
            "<if test='map.storeId != null'> AND store_id = #{map.storeId}  </if>",
            "<if test='map.memPhone != null'> AND mem_phone = #{map.memPhone}  </if>",
            "<if test='map.orderNo != null'> AND order_no = #{map.orderNo}  </if>",
            "<if test='map.payModel != null'> AND pay_model = #{map.payModel}  </if>",
            "<if test='map.payType != null'> AND pay_type = #{map.payType}  </if>",
            "<if test='map.orderStatus != null'> AND order_status = #{map.orderStatus}  </if>",
            " order by create_time  desc ",
            "</script>"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="order_no", property="orderNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="mem_id", property="memId", jdbcType=JdbcType.BIGINT),
            @Result(column="mem_name", property="memName", jdbcType=JdbcType.VARCHAR),
            @Result(column="mem_phone", property="memPhone", jdbcType=JdbcType.VARCHAR),
            @Result(column="pay_model", property="payModel", jdbcType=JdbcType.INTEGER),
            @Result(column="pay_type", property="payType", jdbcType=JdbcType.INTEGER),
            @Result(column="pay_gold", property="payGold", jdbcType=JdbcType.INTEGER),
            @Result(column="pay_price", property="payPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="goods_name", property="goodsName", jdbcType=JdbcType.VARCHAR),
            @Result(column="giveaway_type", property="giveawayType", jdbcType=JdbcType.BIT),
            @Result(column="pay_real_price", property="payRealPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="pay_serial_no", property="paySerialNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="order_status", property="orderStatus", jdbcType=JdbcType.INTEGER),
            @Result(column="total_price", property="totalPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="pay_time", property="payTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="cancel_time", property="cancelTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="finish_time", property="finishTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="child_order_id", property="childOrderId", jdbcType=JdbcType.BIGINT),
            @Result(column="company_id", property="companyId", jdbcType=JdbcType.BIGINT),
            @Result(column="merchant_id", property="merchantId", jdbcType=JdbcType.BIGINT),
            @Result(column="store_id", property="storeId", jdbcType=JdbcType.BIGINT),
            @Result(column="goods_type", property="goodsType", jdbcType=JdbcType.INTEGER),
    })
    List<HighOrderData> selectOrderDataList(@Param("map") Map<String,Object> map);

    @Select({"<script>" +
            " SELECT" +
            " (select mer.merchant_name from high_merchant mer where EXISTS (select 1 from high_coupon cou where cou.id = a.goods_id and mer.id = cou.merchant_id)) merchantName," +
            " case a.goods_type when 1 then '卡券' when 2 then '金币充值' when 3 then '加油缴费' end goodsType, " +
            " a.goods_name goodsName, " +
            " a.goods_type goodsTypeId," +
            " case a.giveaway_type when 1 then '赠送' when 0 then '购买' end giveawayType," +
            " b.order_no orderNo," +
            " b.mem_name memName," +
            " b.mem_phone memPhone," +
            " case b.pay_model when 1 then '金币' when 2 then '第三方' end payModel, " +
            " case b.pay_type when 1 then '支付宝' when 2 then '微信' when 3 then '金币' when 4 then '工会卡' end payType," +
            " b.pay_serial_no paySerialNo," +
            " case a.giveaway_type when 0 then b.total_price when 1 then 0 end totalPrice," +
            " b.mem_discount_name memDiscountName," +
            " b.deduction_price deductionPrice," +
            " case a.giveaway_type when 0 then case when b.pay_gold is null then 0 else pay_gold end when 1 then 0 end payGold," +
            " case a.giveaway_type when 0 then b.pay_price when 1 then 0 end payPrice," +
            " case a.giveaway_type when 0 then case when b.pay_gold is not null then convert(b.pay_gold / 100,decimal(10,2)) else b.pay_real_price end when 1 then 0 end payRealPrice," +
            " case b.order_status when 1 then '待支付' when 2 then '已支付' when 3 then '已完成' when 4 then '已退款' when 5 then '已取消' when 6 then '退款中' when 7 then '退款失败' end orderStatus, " +
            " b.order_status orderStatusId," +
            " b.create_time createTime," +
            " b.pay_time payTime," +
            " b.cancel_time cancelTime," +
            " b.refund_time refundTime," +
            " b.refund_content refundContent," +
            " b.refusal_refund_content refusalRefundContent" +
            " FROM" +
            " high_child_order a," +
            " high_order b" +
            " WHERE" +
            " a.order_id = b.id" +
            " and a.goods_type = 1" +
            " and a.giveaway_type = 0" +
            " and EXISTS (select 1 from high_coupon c where c.id = a.goods_id " +
            " <if test='map.companyId != null'> and c.company_id = #{map.companyId} </if> " +
            " <if test='map.memDiscountName != null'> and c.coupon_name = #{map.memDiscountName} </if>",
            " <if test='map.merchantId != null'> and c.merchant_id = #{map.merchantId} </if> )" +
            " <if test='map.orderNo != null'> and b.order_no = #{map.orderNo}</if>",
            " <if test='map.paySerialNo != null'> and b.pay_serial_no = #{map.paySerialNo} </if>",
            " <if test='map.payModel != null'> and b.pay_model = #{map.payModel} </if>",
            " <if test='map.payType != null'> and b.pay_type = #{map.payType} </if>",
            " <if test='map.memPhone != null'> and b.mem_phone = #{map.memPhone} </if>",
            " <if test='map.orderStatus != null'> and b.order_status in (#{map.orderStatus}) </if>",
            " <if test='map.createTimeS != null'> <![CDATA[ and b.create_time >= #{map.createTimeS} ]]> </if>",
            " <if test='map.createTimeE != null'> <![CDATA[ and b.create_time <= #{map.createTimeE} ]]> </if>",
            " <if test='map.payTimeS != null'> <![CDATA[ and b.pay_time >= #{map.payTimeS} ]]> </if>",
            " <if test='map.payTimeE != null'> <![CDATA[ and b.pay_time <= #{map.payTimeE} ]]> </if>",
            " GROUP BY a.id" +
            " ORDER BY b.create_time desc" +
            "</script>"})
    List<HighOrderModel> selectGoodsOrderList(@Param("map") Map<String,Object> map);


    @Select({"<script>" +
            " SELECT" +
            " (select st.store_name from high_merchant_store st where st.id = a.goods_id) merchantName," +
            " case a.goods_type when 1 then '卡券' when 2 then '金币充值' when 3 then '加油缴费' end goodsType," +
            " b.id orderId, " +
            " a.goods_name goodsName, " +
            " a.goods_type goodsTypeId," +
            " case a.giveaway_type when 1 then '赠送' when 0 then '购买' end giveawayType," +
            " b.order_no orderNo," +
            " b.mem_name memName," +
            " b.mem_phone memPhone," +
            " case b.pay_model when 1 then '金币' when 2 then '第三方' end payModel, " +
            " case b.pay_type when 1 then '支付宝' when 2 then '微信' when 3 then '金币' when 4 then '工会卡' end payType," +
            " b.pay_serial_no paySerialNo," +
            " case a.giveaway_type when 0 then b.total_price when 1 then 0 end totalPrice," +
            " b.mem_discount_name memDiscountName," +
            " b.deduction_price deductionPrice," +
            " case a.giveaway_type when 0 then case when b.pay_gold is null then 0 else pay_gold end when 1 then 0 end payGold," +
            " case a.giveaway_type when 0 then b.pay_price when 1 then 0 end payPrice," +
            " case a.giveaway_type when 0 then case when b.pay_gold is not null then convert(b.pay_gold / 100,decimal(10,2)) else b.pay_real_price end when 1 then 0 end payRealPrice," +
            " case b.order_status when 1 then '待支付' when 2 then '已支付' when 3 then '已完成' when 4 then '已退款' when 5 then '已取消' when 6 then '退款中' when 7 then '退款失败' end orderStatus, " +
            " b.order_status orderStatusId," +
            " b.create_time createTime," +
            " b.pay_time payTime," +
            " b.cancel_time cancelTime," +
            " b.refund_time refundTime," +
            " b.refund_content refundContent," +
            " b.refusal_refund_content refusalRefundContent" +
            " FROM" +
            " high_child_order a," +
            " high_order b" +
            " WHERE" +
            " a.order_id = b.id" +
            " and a.goods_type = 3" +
            " and a.giveaway_type = 0" +
            " and EXISTS (select 1 from high_merchant_store c where c.id = a.goods_id " +
            " <if test='map.companyId != null'> and c.company_id = #{map.companyId} </if> " +
            " <if test='map.merchantId != null'> and c.merchant_id = #{map.merchantId} </if> )" +
            " <if test='map.orderNo != null'> and b.order_no = #{map.orderNo}</if>",
            " <if test='map.paySerialNo != null'> and b.pay_serial_no = #{map.paySerialNo} </if>",
            " <if test='map.payModel != null'> and b.pay_model = #{map.payModel} </if>",
            " <if test='map.payType != null'> and b.pay_type = #{map.payType} </if>",
            " <if test='map.orderStatus != null'> and b.order_status in (#{map.orderStatus}) </if>",
            " <if test='map.createTimeS != null'> <![CDATA[ and b.create_time >= #{map.createTimeS} ]]> </if>",
            " <if test='map.createTimeE != null'> <![CDATA[ and b.create_time <= #{map.createTimeE} ]]> </if>",
            " <if test='map.payTimeS != null'> <![CDATA[ and b.pay_time >= #{map.payTimeS} ]]> </if>",
            " <if test='map.payTimeE != null'> <![CDATA[ and b.pay_time <= #{map.payTimeE} ]]> </if>",
            " GROUP BY a.id ORDER BY b.create_time desc" +
            "</script>"})
    List<HighOrderModel> selectGasOrderList(@Param("map") Map<String,Object> map);

    @Select({"<script>" +
            " SELECT" +
            " (select st.store_name from high_merchant_store st where st.id = a.goods_id) merchantName," +
            " case a.goods_type when 1 then '卡券' when 2 then '金币充值' when 3 then '加油缴费' end goodsType," +
            " b.id orderId, " +
            " a.goods_name goodsName, " +
            " a.goods_type goodsTypeId," +
            " case a.giveaway_type when 1 then '赠送' when 0 then '购买' end giveawayType," +
            " b.order_no orderNo," +
            " b.mem_name memName," +
            " b.mem_phone memPhone," +
            " case b.pay_model when 1 then '金币' when 2 then '第三方' end payModel, " +
            " case b.pay_type when 1 then '支付宝' when 2 then '微信' when 3 then '金币' when 4 then '工会卡' end payType," +
            " b.pay_serial_no paySerialNo," +
            " case a.giveaway_type when 0 then b.total_price when 1 then 0 end totalPrice," +
            " b.mem_discount_name memDiscountName," +
            " b.deduction_price deductionPrice," +
            " case a.giveaway_type when 0 then case when b.pay_gold is null then 0 else pay_gold end when 1 then 0 end payGold," +
            " case a.giveaway_type when 0 then b.pay_price when 1 then 0 end payPrice," +
            " case a.giveaway_type when 0 then case when b.pay_gold is not null then convert(b.pay_gold / 100,decimal(10,2)) else b.pay_real_price end when 1 then 0 end payRealPrice," +
            " case b.order_status when 1 then '待支付' when 2 then '已支付' when 3 then '已完成' when 4 then '已退款' when 5 then '已取消' when 6 then '退款中' when 7 then '退款失败' end orderStatus, " +
            " b.order_status orderStatusId," +
            " b.create_time createTime," +
            " b.pay_time payTime," +
            " b.cancel_time cancelTime," +
            " b.refund_time refundTime," +
            " b.refund_content refundContent," +
            " b.refusal_refund_content refusalRefundContent" +
            " FROM" +
            " high_child_order a," +
            " high_order b" +
            " WHERE" +
            " a.order_id = b.id" +
            " and a.goods_type = 4" +
            " and a.giveaway_type = 0" +
/*            " and EXISTS (select 1 from high_merchant_store c where c.id = a.goods_id " +
            " <if test='map.companyId != null'> and c.company_id = #{map.companyId} </if> " +
            " <if test='map.merchantId != null'> and c.merchant_id = #{map.merchantId} </if> )" +*/
            " <if test='map.orderNo != null'> and b.order_no = #{map.orderNo}</if>",
            " <if test='map.paySerialNo != null'> and b.pay_serial_no = #{map.paySerialNo} </if>",
            " <if test='map.payModel != null'> and b.pay_model = #{map.payModel} </if>",
            " <if test='map.payType != null'> and b.pay_type = #{map.payType} </if>",
            " <if test='map.orderStatus != null'> and b.order_status in (#{map.orderStatus}) </if>",
            " <if test='map.createTimeS != null'> <![CDATA[ and b.create_time >= #{map.createTimeS} ]]> </if>",
            " <if test='map.createTimeE != null'> <![CDATA[ and b.create_time <= #{map.createTimeE} ]]> </if>",
            " <if test='map.payTimeS != null'> <![CDATA[ and b.pay_time >= #{map.payTimeS} ]]> </if>",
            " <if test='map.payTimeE != null'> <![CDATA[ and b.pay_time <= #{map.payTimeE} ]]> </if>",
            " GROUP BY a.id ORDER BY b.create_time desc" +
                    "</script>"})
    List<HighOrderModel> selectKfcOrderList(@Param("map") Map<String,Object> map);


    @Select({"<script>" +
            " SELECT" +
            " (select st.store_name from high_merchant_store st where st.id = a.goods_id) merchantName," +
            " case a.goods_type when 1 then '卡券' when 2 then '金币充值' when 3 then '加油缴费' end goodsType," +
            " b.id orderId, " +
            " a.goods_name goodsName, " +
            " a.goods_type goodsTypeId," +
            " case a.giveaway_type when 1 then '赠送' when 0 then '购买' end giveawayType," +
            " b.order_no orderNo," +
            " b.mem_name memName," +
            " b.mem_phone memPhone," +
            " case b.pay_model when 1 then '金币' when 2 then '第三方' end payModel, " +
            " case b.pay_type when 1 then '支付宝' when 2 then '微信' when 3 then '金币' when 4 then '工会卡' end payType," +
            " b.pay_serial_no paySerialNo," +
            " case a.giveaway_type when 0 then b.total_price when 1 then 0 end totalPrice," +
            " b.mem_discount_name memDiscountName," +
            " b.deduction_price deductionPrice," +
            " case a.giveaway_type when 0 then case when b.pay_gold is null then 0 else pay_gold end when 1 then 0 end payGold," +
            " case a.giveaway_type when 0 then b.pay_price when 1 then 0 end payPrice," +
            " case a.giveaway_type when 0 then case when b.pay_gold is not null then convert(b.pay_gold / 100,decimal(10,2)) else b.pay_real_price end when 1 then 0 end payRealPrice," +
            " case b.order_status when 1 then '待支付' when 2 then '已支付' when 3 then '已完成' when 4 then '已退款' when 5 then '已取消' when 6 then '退款中' when 7 then '退款失败' end orderStatus, " +
            " b.order_status orderStatusId," +
            " b.create_time createTime," +
            " b.pay_time payTime," +
            " b.cancel_time cancelTime," +
            " b.refund_time refundTime," +
            " b.refund_content refundContent," +
            " b.refusal_refund_content refusalRefundContent" +
            " FROM" +
            " high_child_order a," +
            " high_order b" +
            " WHERE" +
            " a.order_id = b.id" +
            " and a.goods_type = 5" +
            " and a.giveaway_type = 0" +
/*            " and EXISTS (select 1 from high_merchant_store c where c.id = a.goods_id " +
            " <if test='map.companyId != null'> and c.company_id = #{map.companyId} </if> " +
            " <if test='map.merchantId != null'> and c.merchant_id = #{map.merchantId} </if> )" +*/
            " <if test='map.orderNo != null'> and b.order_no = #{map.orderNo}</if>",
            " <if test='map.paySerialNo != null'> and b.pay_serial_no = #{map.paySerialNo} </if>",
            " <if test='map.payModel != null'> and b.pay_model = #{map.payModel} </if>",
            " <if test='map.payType != null'> and b.pay_type = #{map.payType} </if>",
            " <if test='map.orderStatus != null'> and b.order_status in (#{map.orderStatus}) </if>",
            " <if test='map.createTimeS != null'> <![CDATA[ and b.create_time >= #{map.createTimeS} ]]> </if>",
            " <if test='map.createTimeE != null'> <![CDATA[ and b.create_time <= #{map.createTimeE} ]]> </if>",
            " <if test='map.payTimeS != null'> <![CDATA[ and b.pay_time >= #{map.payTimeS} ]]> </if>",
            " <if test='map.payTimeE != null'> <![CDATA[ and b.pay_time <= #{map.payTimeE} ]]> </if>",
            " GROUP BY a.id ORDER BY b.create_time desc" +
            "</script>"})
    List<HighOrderModel> selectCinemaOrderList(@Param("map") Map<String,Object> map);

    @Select({"<script>" +
            " SELECT" +
            " (select st.store_name from high_merchant_store st where st.id = a.goods_id) merchantName," +
            " case a.goods_type when 1 then '卡券' when 2 then '金币充值' when 3 then '加油缴费' end goodsType," +
            " b.id orderId, " +
            " a.goods_name goodsName, " +
            " a.goods_type goodsTypeId," +
            " case a.giveaway_type when 1 then '赠送' when 0 then '购买' end giveawayType," +
            " b.order_no orderNo," +
            " b.mem_name memName," +
            " b.mem_phone memPhone," +
            " case b.pay_model when 1 then '金币' when 2 then '第三方' end payModel, " +
            " case b.pay_type when 1 then '支付宝' when 2 then '微信' when 3 then '金币' when 4 then '工会卡' end payType," +
            " b.pay_serial_no paySerialNo," +
            " case a.giveaway_type when 0 then b.total_price when 1 then 0 end totalPrice," +
            " b.mem_discount_name memDiscountName," +
            " b.deduction_price deductionPrice," +
            " case a.giveaway_type when 0 then case when b.pay_gold is null then 0 else pay_gold end when 1 then 0 end payGold," +
            " case a.giveaway_type when 0 then b.pay_price when 1 then 0 end payPrice," +
            " case a.giveaway_type when 0 then case when b.pay_gold is not null then convert(b.pay_gold / 100,decimal(10,2)) else b.pay_real_price end when 1 then 0 end payRealPrice," +
            " case b.order_status when 1 then '待支付' when 2 then '已支付' when 3 then '已完成' when 4 then '已退款' when 5 then '已取消' when 6 then '退款中' when 7 then '退款失败' end orderStatus, " +
            " b.order_status orderStatusId," +
            " b.create_time createTime," +
            " b.pay_time payTime," +
            " b.cancel_time cancelTime," +
            " b.refund_time refundTime," +
            " b.refund_content refundContent," +
            " b.refusal_refund_content refusalRefundContent" +
            " FROM" +
            " high_child_order a," +
            " high_order b" +
            " WHERE" +
            " a.order_id = b.id" +
            " and a.goods_type = 6" +
            " and a.giveaway_type = 0" +
/*            " and EXISTS (select 1 from high_merchant_store c where c.id = a.goods_id " +
            " <if test='map.companyId != null'> and c.company_id = #{map.companyId} </if> " +
            " <if test='map.merchantId != null'> and c.merchant_id = #{map.merchantId} </if> )" +*/
            " <if test='map.orderNo != null'> and b.order_no = #{map.orderNo}</if>",
            " <if test='map.paySerialNo != null'> and b.pay_serial_no = #{map.paySerialNo} </if>",
            " <if test='map.payModel != null'> and b.pay_model = #{map.payModel} </if>",
            " <if test='map.payType != null'> and b.pay_type = #{map.payType} </if>",
            " <if test='map.orderStatus != null'> and b.order_status in (#{map.orderStatus}) </if>",
            " <if test='map.createTimeS != null'> <![CDATA[ and b.create_time >= #{map.createTimeS} ]]> </if>",
            " <if test='map.createTimeE != null'> <![CDATA[ and b.create_time <= #{map.createTimeE} ]]> </if>",
            " <if test='map.payTimeS != null'> <![CDATA[ and b.pay_time >= #{map.payTimeS} ]]> </if>",
            " <if test='map.payTimeE != null'> <![CDATA[ and b.pay_time <= #{map.payTimeE} ]]> </if>",
            " GROUP BY a.id ORDER BY b.create_time desc" +
            "</script>"})
    List<HighOrderModel> getMobileOrderList(@Param("map") Map<String,Object> map);
    
    
    @Select({"<script>" +
            "           SELECT" +
            "            (select mer.merchant_name from high_merchant mer where EXISTS (select 1 from high_coupon cou where cou.id = a.goods_id and mer.id = cou.merchant_id))  merchantName," +
            "            case a.goods_type when 1 then '卡券' when 2 then '金币充值' when 3 then '加油缴费' end goodsType, " +
            "            a.goods_name goodsName, " +
            "            a.goods_type goodsTypeId," +
            "            case a.giveaway_type when 1 then '赠送' when 0 then '购买' end giveawayType," +
            "            b.order_no orderNo," +
            "            b.mem_name memName," +
            "            b.mem_phone memPhone," +
            "            case b.pay_model when 1 then '金币' when 2 then '第三方' end payModel, " +
            "            case b.pay_type when 1 then '支付宝' when 2 then '微信' when 3 then '金币' when 4 then '工会卡' end payType," +
            "            b.pay_serial_no paySerialNo," +
            "            case a.giveaway_type when 0 then b.total_price when 1 then 0 end totalPrice," +
            "            b.mem_discount_name memDiscountName," +
            "            b.deduction_price deductionPrice," +
            "            case a.giveaway_type when 0 then case when b.pay_gold is null then 0 else pay_gold end when 1 then 0 end payGold," +
            "            case a.giveaway_type when 0 then b.pay_price when 1 then 0 end payPrice," +
            "            case a.giveaway_type when 0 then case when b.pay_gold is not null then convert(b.pay_gold / 100,decimal(10,2)) else b.pay_real_price end when 1 then 0 end payRealPrice," +
            "            case b.order_status when 1 then '待支付' when 2 then '已支付' when 3 then '已完成' when 4 then '已退款' when 5 then '已取消' when 6 then '退款中' when 7 then '退款失败' end orderStatus, " +
            "            b.order_status orderStatusId," +
            "            b.create_time createTime," +
            "            b.pay_time payTime," +
            "            b.cancel_time cancelTime," +
            "            b.refund_time refundTime," +
            "            b.refund_content refundContent," +
            "            b.refusal_refund_content refusalRefundContent" +
            "            FROM" +
            "            high_child_order a," +
            "            high_order b" +
            "            WHERE" +
            "            a.order_id = b.id" +
            "            and a.giveaway_type = 0" +
            "            and b.Identification_code = #{map.identificationCode}" +
            "            <if test='map.orderNo != null'> and b.order_no = #{map.orderNo} </if>" +
            "            <if test='map.paySerialNo != null'> and b.pay_serial_no = #{map.paySerialNo} </if>" +
            "            <if test='map.payModel != null'> and b.pay_model = #{map.payModel} </if>" +
            "            <if test='map.memDiscountName != null'> and a.goods_name = #{map.memDiscountName} </if>" +
            "            <if test='map.memPhone != null'> and b.mem_phone = #{map.memPhone} </if>" +
            "            <if test='map.payType != null'> and b.pay_type = #{map.payType} </if>" +
            "            <if test='map.memPhone != null'> and b.mem_phone = #{map.memPhone} </if> " +
            "            <if test='map.orderStatus != null'> and b.order_status in (#{map.orderStatus}) </if>" +
            "            <if test='map.createTimeS != null'> <![CDATA[ and b.create_time >= #{map.createTimeS} ]]> </if>" +
            "            <if test='map.createTimeE != null'> <![CDATA[ and b.create_time <= #{map.createTimeE} ]]> </if>" +
            "            <if test='map.payTimeS != null'> <![CDATA[ and b.pay_time >= #{map.payTimeS} ]]> </if>" +
            "            <if test='map.payTimeE != null'> <![CDATA[ and b.pay_time <= #{map.payTimeE} ]]> </if>" +
            "            GROUP BY a.id" +
            "           ORDER BY b.create_time desc" +
            "</script>"})
    List<HighOrderModel> getOrderListByIdCode(@Param("map") Map<String,Object> map);

    /**
     * 查询处于已经支付和待支付的话费订单
     */
    @Select({"SELECT" +
            " b.*" +
            " FROM" +
            " high_child_order a," +
            " high_order b" +
            " WHERE" +
            " a.order_id = b.id" +
            " and a.goods_type = 6" +
            " and b.order_status in (1,2) " +
            " and a.giveaway_type = 0" +
            " GROUP BY b.id"})
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="order_no", property="orderNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="mem_discount_id", property="memDiscountId", jdbcType=JdbcType.BIGINT),
            @Result(column="mem_discount_name", property="memDiscountName", jdbcType=JdbcType.VARCHAR),
            @Result(column="mem_id", property="memId", jdbcType=JdbcType.BIGINT),
            @Result(column="mem_name", property="memName", jdbcType=JdbcType.VARCHAR),
            @Result(column="mem_phone", property="memPhone", jdbcType=JdbcType.VARCHAR),
            @Result(column="pay_model", property="payModel", jdbcType=JdbcType.INTEGER),
            @Result(column="pay_type", property="payType", jdbcType=JdbcType.INTEGER),
            @Result(column="pay_gold", property="payGold", jdbcType=JdbcType.INTEGER),
            @Result(column="pay_price", property="payPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="pay_real_price", property="payRealPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="pay_serial_no", property="paySerialNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="deduction_price", property="deductionPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="order_status", property="orderStatus", jdbcType=JdbcType.INTEGER),
            @Result(column="total_price", property="totalPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="pay_time", property="payTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="cancel_time", property="cancelTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="cancel_remarks", property="cancelRemarks", jdbcType=JdbcType.VARCHAR),
            @Result(column="finish_time", property="finishTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="remarks", property="remarks", jdbcType=JdbcType.VARCHAR),
            @Result(column="refund_time", property="refundTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="refund_price", property="refundPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="refund_content", property="refundContent", jdbcType=JdbcType.VARCHAR),
            @Result(column="refusal_refund_content", property="refusalRefundContent", jdbcType=JdbcType.VARCHAR),
            @Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR),
            @Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR),
            @Result(column="ext_3", property="ext3", jdbcType=JdbcType.VARCHAR)
    })
    List<HighOrder> selectAlreadyPaidMobileOrder();


    /**
     * 查询处于已经支付和待支付的KFC订单
     */
    @Select({"SELECT " +
            " b.*" +
            " FROM" +
            " high_child_order a," +
            " high_order b" +
            " WHERE" +
            " a.order_id = b.id" +
            " and a.goods_type = 4" +
            " and b.order_status in (1,2) " +
            " and a.giveaway_type = 0" +
            " GROUP BY b.id"})
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="order_no", property="orderNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="mem_discount_id", property="memDiscountId", jdbcType=JdbcType.BIGINT),
            @Result(column="mem_discount_name", property="memDiscountName", jdbcType=JdbcType.VARCHAR),
            @Result(column="mem_id", property="memId", jdbcType=JdbcType.BIGINT),
            @Result(column="mem_name", property="memName", jdbcType=JdbcType.VARCHAR),
            @Result(column="mem_phone", property="memPhone", jdbcType=JdbcType.VARCHAR),
            @Result(column="pay_model", property="payModel", jdbcType=JdbcType.INTEGER),
            @Result(column="pay_type", property="payType", jdbcType=JdbcType.INTEGER),
            @Result(column="pay_gold", property="payGold", jdbcType=JdbcType.INTEGER),
            @Result(column="pay_price", property="payPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="pay_real_price", property="payRealPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="pay_serial_no", property="paySerialNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="deduction_price", property="deductionPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="order_status", property="orderStatus", jdbcType=JdbcType.INTEGER),
            @Result(column="total_price", property="totalPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="pay_time", property="payTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="cancel_time", property="cancelTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="cancel_remarks", property="cancelRemarks", jdbcType=JdbcType.VARCHAR),
            @Result(column="finish_time", property="finishTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="remarks", property="remarks", jdbcType=JdbcType.VARCHAR),
            @Result(column="refund_time", property="refundTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="refund_price", property="refundPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="refund_content", property="refundContent", jdbcType=JdbcType.VARCHAR),
            @Result(column="refusal_refund_content", property="refusalRefundContent", jdbcType=JdbcType.VARCHAR),
            @Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR),
            @Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR),
            @Result(column="ext_3", property="ext3", jdbcType=JdbcType.VARCHAR)
    })
    List<HighOrder> selectAlreadyPaidKfcOrder();


    /**
     * 查询处于已经支付和待支付的电影票订单
     */
    @Select({"SELECT" +
            " b.*" +
            " FROM" +
            " high_child_order a," +
            " high_order b" +
            " WHERE" +
            " a.order_id = b.id" +
            " and a.goods_type = 5" +
            " and b.order_status in (1,2)" +
            " and a.giveaway_type = 0" +
            " GROUP BY b.id"})
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="order_no", property="orderNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="mem_discount_id", property="memDiscountId", jdbcType=JdbcType.BIGINT),
            @Result(column="mem_discount_name", property="memDiscountName", jdbcType=JdbcType.VARCHAR),
            @Result(column="mem_id", property="memId", jdbcType=JdbcType.BIGINT),
            @Result(column="mem_name", property="memName", jdbcType=JdbcType.VARCHAR),
            @Result(column="mem_phone", property="memPhone", jdbcType=JdbcType.VARCHAR),
            @Result(column="pay_model", property="payModel", jdbcType=JdbcType.INTEGER),
            @Result(column="pay_type", property="payType", jdbcType=JdbcType.INTEGER),
            @Result(column="pay_gold", property="payGold", jdbcType=JdbcType.INTEGER),
            @Result(column="pay_price", property="payPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="pay_real_price", property="payRealPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="pay_serial_no", property="paySerialNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="deduction_price", property="deductionPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="order_status", property="orderStatus", jdbcType=JdbcType.INTEGER),
            @Result(column="total_price", property="totalPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="pay_time", property="payTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="cancel_time", property="cancelTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="cancel_remarks", property="cancelRemarks", jdbcType=JdbcType.VARCHAR),
            @Result(column="finish_time", property="finishTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="remarks", property="remarks", jdbcType=JdbcType.VARCHAR),
            @Result(column="refund_time", property="refundTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="refund_price", property="refundPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="refund_content", property="refundContent", jdbcType=JdbcType.VARCHAR),
            @Result(column="refusal_refund_content", property="refusalRefundContent", jdbcType=JdbcType.VARCHAR),
            @Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR),
            @Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR),
            @Result(column="ext_3", property="ext3", jdbcType=JdbcType.VARCHAR)
    })
    List<HighOrder> selectAlreadyPaidCinemaOrder();

    @Select("select a.id,a.order_no,TRIM(BOTH '\"' FROM b.transaction_id)  pay_serial_no from " +
            "(select id,order_no from high_order where order_status = 5 and create_time >= '2021-06-21 00:00:00') a" +
            "LEFT JOIN (select JSON_EXTRACT(body_info,'$.out_trade_no') out_trade_no,JSON_EXTRACT(body_info,'$.transaction_id') transaction_id from high_pay_record where create_time >= '2021-06-21 00:00:00' and res_type = 2 GROUP BY JSON_EXTRACT(body_info,'$.out_trade_no')) b on a.order_no = b.out_trade_no where b.out_trade_no is not null")
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="order_no", property="orderNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="mem_discount_id", property="memDiscountId", jdbcType=JdbcType.BIGINT),
            @Result(column="mem_discount_name", property="memDiscountName", jdbcType=JdbcType.VARCHAR),
            @Result(column="mem_id", property="memId", jdbcType=JdbcType.BIGINT),
            @Result(column="mem_name", property="memName", jdbcType=JdbcType.VARCHAR),
            @Result(column="mem_phone", property="memPhone", jdbcType=JdbcType.VARCHAR),
            @Result(column="pay_model", property="payModel", jdbcType=JdbcType.INTEGER),
            @Result(column="pay_type", property="payType", jdbcType=JdbcType.INTEGER),
            @Result(column="pay_gold", property="payGold", jdbcType=JdbcType.INTEGER),
            @Result(column="pay_price", property="payPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="pay_real_price", property="payRealPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="pay_serial_no", property="paySerialNo", jdbcType=JdbcType.VARCHAR),
            @Result(column="deduction_price", property="deductionPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="order_status", property="orderStatus", jdbcType=JdbcType.INTEGER),
            @Result(column="total_price", property="totalPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="pay_time", property="payTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="cancel_time", property="cancelTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="cancel_remarks", property="cancelRemarks", jdbcType=JdbcType.VARCHAR),
            @Result(column="finish_time", property="finishTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="remarks", property="remarks", jdbcType=JdbcType.VARCHAR),
            @Result(column="refund_time", property="refundTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="refund_price", property="refundPrice", jdbcType=JdbcType.DECIMAL),
            @Result(column="refund_content", property="refundContent", jdbcType=JdbcType.VARCHAR),
            @Result(column="refusal_refund_content", property="refusalRefundContent", jdbcType=JdbcType.VARCHAR),
            @Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR),
            @Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR),
            @Result(column="ext_3", property="ext3", jdbcType=JdbcType.VARCHAR)
    })
    List<HighOrder> selectTest();

    @Select({"select a.id orderId,b.id childOrderId from high_order a,high_child_order b where a.id = b.order_id and b.goods_type = 3 and a.order_status = 2 and TIMESTAMPDIFF(MINUTE,a.pay_time,SYSDATE()) > 60*24 GROUP BY b.id"})
    List<Map<String,Object>> selectFinishGasOrder();


}
