<?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.pz.system.mapper.DbmyOrderMapper">

    <resultMap type="com.pz.system.domain.DbmyOrder" id="DbmyOrderResult">
        <result property="id" column="id"/>
        <result property="orderId" column="order_id"/>
        <result property="ypName" column="yp_name"/>
        <result property="ydAddress" column="yd_address"/>
        <result property="isCf" column="is_cf"/>
        <result property="prescriptionAttachment" column="prescription_attachment"/>
        <result property="way" column="way"/>
        <result property="recipient" column="recipient"/>
        <result property="adress" column="adress"/>
        <result property="addressInfo" column="address_info"/>
        <result property="phone" column="phone"/>
        <result property="isRefrigerate" column="is_refrigerate"/>
        <result property="status" column="status"/>
        <result property="overTime" column="over_time"/>
        <result property="voucher" column="voucher"/>
        <result property="pzShr" column="pz_shr"/>
        <result property="pzAddress" column="pz_address"/>
        <result property="pzShPhone" column="pz_sh_phone"/>
        <result property="pzShRemake" column="pz_sh_remake"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>
    <select id="findDbmyOrderVoPage" resultType="com.pz.system.domain.vo.DbmyOrderVo">
        SELECT
        tlo.order_type as order_type,
        tlo.id as toOrderId,
        tlo.order_sn AS orderSn,
        tlo.pay_money AS PayMoney,
        s.`name` AS serviceName,
        c.`name` AS cityName,
        e.`name` AS eName,
        tlo.remark AS remark,
        yyod.`status` AS yStatus,
        tlo.`status` AS tStatus,
        tlo.is_satisfaction AS isSatisfaction,
        tlo.evaluation_content AS evaluationContent,
        yyod.create_time as createTime,
        yyod.is_refrigerate as isRefrigerate
        FROM
        dbmy_order AS yyod
        LEFT JOIN total_order AS tlo ON yyod.order_id = tlo.id
        LEFT JOIN city AS c ON c.id = tlo.city_id
        LEFT JOIN services AS s ON s.id = tlo.service_id
        LEFT JOIN employees AS e ON e.id = tlo.em_id
        LEFT JOIN company AS co ON co.id = e.company_id
        <where>

            <if test="bo.orderSn != null and bo.orderSn != ''">
                and tlo.order_sn LIKE CONCAT('%', #{bo.orderSn}, '%')
            </if>
            <if test="bo.orderType != null">
                and tlo.order_type = #{orderType}
            </if>
            <if test="bo.userId != null">
                and co.uid = #{bo.userId}
            </if>
            <if test="bo.startTime != null and bo.startTime != '' and bo.endTime != null and bo.endTime != ''">
                and yyod.create_time &gt; = #{bo.startTime} and yyod.create_time &lt; = #{bo.endTime}
            </if>
            <if test="bo.yStatus != null">
                and yyod.`status` = #{yStatus}
            </if>
            <if test="bo.receiverName != null and bo.receiverName != ''">
                and e.name LIKE CONCAT('%', #{receiverName}, '%')
            </if>
            and yyod.create_time &lt; NOW()
        </where>
        order by yyod.create_time desc
    </select>

    <select id="selectSonOrderInfoByTotalId" resultType="com.pz.merchant.domain.vo.SonOrderVo">
        select dbmy_order.status  as orderStatus,
               sys_user.nick_name as userName,
               sys_user.avatar,
               dbmy_order.id      as sonOrderId
        from dbmy_order
                 left join total_order on total_order.id = dbmy_order.order_id
                 left join sys_user on sys_user.user_id = total_order.uid
        where dbmy_order.order_id = #{id}
    </select>

    <select id="selectDbmyOrderDetailDataByTotalId" resultType="com.pz.system.domain.vo.DbmyOrderItemVo">
        select total_order.id                           as orderId,
               dbmy_order.id                            as serviceOrderId,
               total_order.business_id,
               total_order.status                       as orderStatus,
               dbmy_order.status                        as serviceStatus,
               services.name                            as project,
               business.name                            as businessName,
               CONVERT((1 - services.fenmo / 100), decimal (10, 2)) *
               CONVERT(services.price, decimal (10, 2)) as commission,
               dbmy_order.yp_name,
               dbmy_order.yd_address,
               dbmy_order.way,
               dbmy_order.is_cf,
               dbmy_order.prescription_attachment,
               dbmy_order.phone,
               dbmy_order.recipient,
               dbmy_order.address                       as address,
               dbmy_order.address_info,
               dbmy_order.is_refrigerate,
               total_order.remark                       as description,
               dbmy_order.remark,
               dbmy_order.voucher,
               total_order.evaluation_content,
               total_order.is_satisfaction              as evaluation_flag,
               total_order.uid                          as userId,
               employees.uid                            as euserId
        from total_order
                 left join business on total_order.business_id = business.id
                 left join employees on total_order.em_id = employees.id
                 left join dbmy_order on dbmy_order.order_id = total_order.id
                 left join services on total_order.service_id = services.id
        where total_order.id = #{id}
    </select>
    <select id="selectFinishTime" resultType="java.lang.String">
        select over_time
        from total_order t
                 left join dbmy_order d on d.order_id = t.id
        where d.status = 2
          and t.id = #{id}
    </select>


</mapper>