<?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.czg.service.order.mapper.CashierCartMapper">

    <select id="getCartByTableCode" resultType="com.czg.order.entity.OrderDetail">
        select cart.shop_id                                as shopId,
               cart.number                                 as num,
               pros.pack_fee                               as packAmount,
               cart.pack_number                            as packNumber,
               cart.is_temporary                           as isTemporary,
               cart.discount_sale_note                     as discountSaleNote,
               cart.is_print                               as isPrint,
               cart.is_wait_call                           as isWaitCall,
               cart.pro_group_info                         as proGroupInfo,
               cart.remark                                 as remark,
               cart.product_id                             as productId,
               pros.cover_img                              as productImg,
               pros.type                                   as productType,
               cart.sku_id                                 as skuId,
               skus.spec_info                              as skuName,
               case cart.is_gift
                   when 1 then 0
                   else cart.discount_sale_amount end      as discountSaleAmount,
               case cart.is_gift
                   when 1 then 0
                   else case cart.is_temporary
                            when 1 then cart.discount_sale_amount
                            else skus.sale_price end end   as price,
               case cart.is_gift
                   when 1 then 0
                   else case cart.is_temporary
                            when 1 then cart.discount_sale_amount
                            else skus.member_price end end as memberPrice,
               'wait-pay'                                  as status,
               #{placeNum}                                 as placeNum,
               case cart.is_temporary
                   when 1 then cart.product_name
                   else pros.name
                   end                                     as productName
        from tb_cashier_cart cart
                 left join tb_product pros on cart.product_id = pros.id
                 left join tb_prod_sku skus on cart.sku_id = skus.id
        where table_code = #{tableCode}
          and cart.shop_id = #{shopId}
    </select>
</mapper>
