<?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.caimei.www.mapper.ShoppingDao">
    <select id="getHeadCarts" resultType="com.caimei.www.pojo.order.CartItem">
		select
			p.productID as id,
			p.`name` as `name`,
			p.mainImage as image,
			p.price1 as price,
			p.unit as unit,
			c.productCount as number
		from cm_cart c
		left join product p on c.productID=p.productID
		where p.validFlag='2'
		and c.userID = #{userId}
		and p.price1TextFlag != '1'
        and p.stock != '0'
        and p.stock <![CDATA[ >= ]]> c.productCount
	</select>
	<select id="getCartSuppliers" resultType="com.caimei.www.pojo.order.CartSupplier">
		select
			s.shopID as id,
			s.name,
			s.logo
		from cm_cart c
		left join product p on c.productID = p.productID
		left join shop s on p.shopID = s.shopID
		where c.userID = #{userId}
		group by s.shopID
		order by MAX(c.addTime) desc
	</select>
	<select id="getShoppingCartBySupplierId" resultType="com.caimei.www.pojo.order.CartItem">
		select
			c.cm_cartID as id,
			p.productID as productId,
			p.`name` as `name`,
			p.mainImage as image,
			p.price1 as price,
			p.unit as unit,
			p.step as step,
			p.minBuyNumber as min,
			p.price1TextFlag as priceFlag,
			p.ladderPriceFlag as ladderFlag,
			p.validFlag as validFlag,
			p.stock as stock,
			c.productCount as number
		from product p
		left join cm_cart c on c.productID = p.productID
		where p.shopID = #{supplierId} and c.userID = #{userId}
		order by c.addTime desc
	</select>

</mapper>
