<?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.fzm.mall.server.admin.order.mapper.OrderMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.fzm.mall.server.admin.order.model.Order">
        <id column="id" property="id" />
        <result column="oid" property="oid" />
        <result column="uid" property="uid" />
        <result column="pay_id" property="payId" />
        <result column="merchant_id" property="merchantId" />
        <result column="post_fee" property="postFee" />
        <result column="total" property="total" />
        <result column="accept_digital" property="acceptDigital" />
        <result column="pay_type" property="payType" />
        <result column="order_type" property="orderType" />
        <result column="order_state" property="orderState" />
        <result column="delivery" property="delivery" />
        <result column="uname" property="uname" />
        <result column="phone" property="phone" />
        <result column="address" property="address" />
        <result column="is_delete" property="isDelete" />
        <result column="consult_discount_amount" property="consultDiscountAmount" />
        <result column="consult_discount_type" property="consultDiscountType" />
        <result column="discount_amount" property="discountAmount" />
        <result column="amount" property="amount" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />

        <collection property="goodsList" javaType="java.util.ArrayList" ofType="com.fzm.mall.server.admin.distribution.model.ParcelCenterGoods">
            <result column="good_name" property="name" />
            <result column="good_number" property="number" />
            <result column="good_amount" property="amount" />
            <result column="good_thumb" property="thumb" />
            <result column="good_sku_id" property="skuId" />
            <collection property="propValList" ofType="string">
                <result column="prop_val" property="prop_val" />
            </collection>
        </collection>

    </resultMap>

    <select id="page" resultType="com.fzm.mall.server.admin.order.entity.dto.OrderDTO">
        select *
        from `order_info`
        <where>
            <if test="uid != null">
                and uid like CONCAT('%', #{uid},'%')
            </if>
            <if test="oid != null">
                and oid like CONCAT('%', #{oid},'%')
            </if>
            <if test="orderState != null">
                and order_state = #{orderState}
            </if>
            <if test="merchantId != null">
                and merchant_id = #{merchantId}
            </if>
        </where>
        order by create_time desc
    </select>

    <select id="read" resultMap="BaseResultMap">
        select o.*, od.name as good_name, od.number as good_number, od.amount as good_amount, gs.thumb as good_thumb, gsp.prop_val
        from (select * from `order_info` where oid = #{oid}) o
        left join order_detail od on od.oid = o.oid
        left join goods_sku gs on gs.goods_id = od.goods_id and gs.sku_id = od.sku_id
        left join goods_sku_prop gsp on gsp.sku_id = od.sku_id
        where o.oid = #{oid}
    </select>

    <select id="listPayRecord" resultType="com.fzm.mall.server.admin.order.model.PayRecord">
        select pay_type, paid_amount as payAmount, out_biz_no as payId, pay_time
        from order_pay
        where oids_json like CONCAT('%', #{oid},'%')
    </select>
</mapper>
