<?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="cn.qihangerp.mapper.OOrderMapper">

    <resultMap id="BaseResultMap" type="cn.qihangerp.model.entity.OOrder">
            <id property="id" column="id" jdbcType="BIGINT"/>
            <result property="orderNum" column="order_num" jdbcType="VARCHAR"/>
            <result property="shopType" column="shop_type" jdbcType="INTEGER"/>
            <result property="shopId" column="shop_id" jdbcType="BIGINT"/>
            <result property="remark" column="remark" jdbcType="VARCHAR"/>
            <result property="buyerMemo" column="buyer_memo" jdbcType="VARCHAR"/>
            <result property="sellerMemo" column="seller_memo" jdbcType="VARCHAR"/>
            <result property="tag" column="tag" jdbcType="VARCHAR"/>
            <result property="goodsAmount" column="goods_amount" jdbcType="DOUBLE"/>
            <result property="postFee" column="post_fee" jdbcType="DOUBLE"/>
            <result property="sellerDiscount" column="seller_discount" jdbcType="DOUBLE"/>
            <result property="platformDiscount" column="platform_discount" jdbcType="DOUBLE"/>
            <result property="changeAmount" column="change_amount" jdbcType="DOUBLE"/>
            <result property="amount" column="amount" jdbcType="DOUBLE"/>
            <result property="payment" column="payment" jdbcType="DOUBLE"/>
            <result property="payDiscount" column="pay_discount" jdbcType="DOUBLE"/>
            <result property="receiverName" column="receiver_name" jdbcType="VARCHAR"/>
            <result property="receiverMobile" column="receiver_mobile" jdbcType="VARCHAR"/>
            <result property="address" column="address" jdbcType="VARCHAR"/>
            <result property="province" column="province" jdbcType="VARCHAR"/>
            <result property="city" column="city" jdbcType="VARCHAR"/>
            <result property="town" column="town" jdbcType="VARCHAR"/>
            <result property="orderCreateTime" column="order_create_time" jdbcType="TIMESTAMP"/>
            <result property="orderUpdateTime" column="order_update_time" jdbcType="TIMESTAMP"/>
            <result property="orderFinishTime" column="order_finish_time" jdbcType="TIMESTAMP"/>
            <result property="orderStatus" column="order_status" jdbcType="VARCHAR"/>
            <result property="orderStatusText" column="order_status_text" jdbcType="VARCHAR"/>
            <result property="shipper" column="shipper" jdbcType="BIGINT"/>
            <result property="shipType" column="ship_type" jdbcType="INTEGER"/>
            <result property="shipStatus" column="ship_status" jdbcType="INTEGER"/>
            <result property="shipCompany" column="ship_company" jdbcType="VARCHAR"/>
            <result property="shipCode" column="ship_code" jdbcType="VARCHAR"/>
            <result property="shipTime" column="ship_time" jdbcType="TIMESTAMP"/>
            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
            <result property="createBy" column="create_by" jdbcType="VARCHAR"/>
            <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
            <result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
            <result property="cancelReason" column="cancel_reason" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,order_num,shop_type,
        shop_id,remark,buyer_memo,seller_memo,tag,
          goods_amount,post_fee,seller_discount,platform_discount,change_amount,amount,payment,pay_discount,
          receiver_name,receiver_mobile,
        address,province,city,town,
          order_create_time,order_update_time,order_finish_time,order_status,
          shipper,ship_type,ship_status,ship_company,
        ship_code,ship_time,create_time,
        create_by,update_time,update_by,cancel_reason
    </sql>

    <resultMap id="DiscountResultMap" type="cn.qihangerp.model.vo.OrderDiscountVo">
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <result property="discountAmount" column="discount_amount" jdbcType="VARCHAR"/>
        <result property="description" column="description" jdbcType="VARCHAR"/>
    </resultMap>
    <select id="getTaoOrderDiscount" parameterType="String" resultMap="DiscountResultMap">
        select promotion_name as name,discount_fee as discount_amount,promotion_desc as description from oms_tao_order_promotion
        where id = #{tid}
    </select>

    <select id="getJdOrderDiscount" parameterType="String" resultMap="DiscountResultMap">
        select coupon_type as name,coupon_price as discount_amount from oms_jd_order_coupon
        where order_id = #{orderId}
    </select>
    <select id="salesDaily" resultType="cn.qihangerp.model.vo.SalesDailyVo">
        SELECT
            DATE(order_create_time) AS date,
            COUNT(*) AS count,
            SUM(payment) AS amount

        FROM
            o_order

        GROUP BY
            date
        ORDER BY
            date

            LIMIT 30
    </select>

    <select id="getTodaySalesDaily" resultType="cn.qihangerp.model.vo.SalesDailyVo">
        SELECT

            COUNT(*) AS count,
            SUM(payment) AS amount

        FROM
            o_order

        WHERE DATE(`order_create_time`) = CURDATE();
    </select>
    <select id="getWaitShipOrderAllCount" resultType="int">
        SELECT
            COUNT(*) AS count
        FROM
            o_order as o
        WHERE ship_status != 11 and (ship_status =0 or ship_status=1)
    </select>
</mapper>
