<?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="cn.com.xingxi.store.data.mapper.WxaStoreShoppingCartsMapper">

    <select id="selectCartsListByUserId" resultType="ShoppingCartDTO">
        SELECT t_carts.*
        FROM t_carts
        WHERE t_carts.delFlag = '0'
          AND t_carts.mercId = #{mercId}
          AND t_carts.userId = #{userId}
    </select>

    <select id="selectCheckedCartsListByUserId" resultType="ShoppingCartDTO">
        SELECT t_carts.*
        FROM t_carts
        WHERE t_carts.delFlag = '0'
          AND t_carts.checkFlag = '1'
          AND t_carts.mercId = #{mercId}
          AND t_carts.userId = #{userId}
    </select>

    <select id="selectCartBySkuId" resultType="Carts">
        SELECT t_carts.*
        FROM t_carts
        WHERE t_carts.delFlag = '0'
          AND t_carts.mercId = #{mercId}
          AND t_carts.userId = #{userId}
          AND t_carts.prodId = #{productId}
          AND t_carts.pprId = #{skuId}
    </select>


    <select id="selectCartsByUpId" resultType="Carts">
        SELECT t_carts.*
        FROM t_carts
        WHERE t_carts.delFlag = '0'
          AND t_carts.upId = #{upId}
    </select>

    <update id="updateAddCarts" parameterType="Carts">
        update t_carts
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">userId = #{userId},</if>
            <if test="mercId != null">mercId = #{mercId},</if>
            <if test="prodId != null">prodId = #{prodId},</if>
            <if test="pprId != null">pprId = #{pprId},</if>
            <if test="upId != null and upId != ''">upId = #{upId},</if>
            <if test="prodQty != null">prodQty = prodQty + #{prodQty},</if>
            <if test="checkFlag != null and checkFlag != ''">checkFlag = #{checkFlag},</if>
            <if test="delFlag != null and delFlag != ''">delFlag = #{delFlag},</if>
            <if test="createUser != null and createUser != ''">createUser = #{createUser},</if>
            <if test="createTime != null">createTime = #{createTime},</if>
            <if test="updateUser != null and updateUser != ''">updateUser = #{updateUser},</if>
            <if test="updateTime != null">updateTime = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

</mapper>
