<?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.TotalOrderMapper">

    <sql id="OrderCommon">
        select total_order.id                          as orderId,
               services.name                           as project,
               business.name                           as businessName,
               CONVERT((1 - services.fenmo / 100), decimal(10, 2)) *
               CONVERT(services.price, decimal(10, 2)) as commission,
               total_order.business_id,
               total_order.remark                      as description,
               total_order.evaluation_content,
               total_order.is_satisfaction             as evaluation_flag,
               total_order.uid                         as uid
        from total_order
                 left join services on total_order.service_id = services.id
                 left join business on total_order.business_id = business.id
    </sql>

    <select id="selectUndistributedTotalOrder" resultType="com.pz.system.domain.vo.AccompanyDemandVo">
        <include refid="OrderCommon"/>
        <where>
            <if test="ew.emptyOfWhere == false">
                and ${ew.sqlSegment}
            </if>
        </where>
    </select>

    <select id="selectTotalOrderById" resultType="com.pz.system.domain.vo.AccompanyDemandVo">
        <include refid="OrderCommon"/>
        where total_order.id = #{id}
    </select>
    <select id="selectAppOrder" resultType="com.pz.system.domain.vo.TotalOrderVo">

    </select>

    <select id="selectByOrderId" resultType="com.pz.system.domain.vo.TotalOrderVo">
        select
        t.id,
        t.order_sn,
        t.uid,
        t.em_id,
        t.city_id,
        t.business_id,
        t.service_id,
        t.pay_money,
        t.status,
        t.lng,
        t.lat,
        t.is_satisfaction,
        t.evaluation_content,
        t.refund_reason,
        t.refund_amount,
        t.pay_cs,
        t.del_flag,
        t.create_by,
        t.create_time,
        t.update_by,
        t.update_time,
        t.remark,
        e.name as emName,
        b.name as business,
        s.name as service
        from total_order t
                          left join business b on b.id = t.business_id
                          left join services s on s.id = t.service_id
                          left join employees e on e.id = t.em_id
        where t.id = #{id}
    </select>

</mapper>