后端 + 前端:添加到购物车
This commit is contained in:
@@ -3,14 +3,109 @@ package cn.iocoder.mall.order.application.controller.users;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.order.api.CartService;
|
||||
import cn.iocoder.mall.order.api.OrderService;
|
||||
import cn.iocoder.mall.order.api.bo.CartItemBO;
|
||||
import cn.iocoder.mall.order.application.vo.UsersOrderConfirmCreateVO;
|
||||
import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder;
|
||||
import com.alibaba.dubbo.config.annotation.Reference;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("users/cart")
|
||||
public class UsersCartController {
|
||||
|
||||
// TODO 注入
|
||||
@Reference(validation = "true")
|
||||
private CartService cartService;
|
||||
// TODO 注入
|
||||
@Reference(validation = "true")
|
||||
private OrderService orderService;
|
||||
|
||||
@PostMapping("add")
|
||||
public CommonResult<Integer> add(@Param("skuId") Integer skuId,
|
||||
@Param("quantity") Integer quantity) {
|
||||
// 添加到购物车
|
||||
CommonResult<Boolean> addResult = cartService.add(UserSecurityContextHolder.getContext().getUserId(),
|
||||
skuId, quantity);
|
||||
// 添加失败,则直接返回错误
|
||||
if (addResult.isError()) {
|
||||
return CommonResult.error(addResult);
|
||||
}
|
||||
// 获得目前购物车商品总数量
|
||||
return cartService.count(UserSecurityContextHolder.getContext().getUserId());
|
||||
}
|
||||
|
||||
@PostMapping("update_quantity")
|
||||
public CommonResult<Integer> updateQuantity(@Param("skuId") Integer skuId,
|
||||
@Param("quantity") Integer quantity) {
|
||||
// 添加到购物车
|
||||
CommonResult<Boolean> updateQuantityResult = cartService.updateQuantity(UserSecurityContextHolder.getContext().getUserId(),
|
||||
skuId, quantity);
|
||||
// 添加失败,则直接返回错误
|
||||
if (updateQuantityResult.isError()) {
|
||||
return CommonResult.error(updateQuantityResult);
|
||||
}
|
||||
// 获得目前购物车商品总数量
|
||||
// TODO 芋艿,需要改成价格计算
|
||||
return cartService.count(UserSecurityContextHolder.getContext().getUserId());
|
||||
}
|
||||
|
||||
@PostMapping("update_selected")
|
||||
public CommonResult<Integer> updateSelected(@Param("skuId") Integer skuId,
|
||||
@Param("selected") Boolean selected) {
|
||||
// 添加到购物车
|
||||
CommonResult<Boolean> updateSelectedResult = cartService.updateSelected(UserSecurityContextHolder.getContext().getUserId(),
|
||||
skuId, selected);
|
||||
// 添加失败,则直接返回错误
|
||||
if (updateSelectedResult.isError()) {
|
||||
return CommonResult.error(updateSelectedResult);
|
||||
}
|
||||
// 获得目前购物车商品总数量
|
||||
// TODO 芋艿,需要改成价格计算
|
||||
return cartService.count(UserSecurityContextHolder.getContext().getUserId());
|
||||
}
|
||||
|
||||
@GetMapping("count")
|
||||
public CommonResult<Integer> count() {
|
||||
return cartService.count(UserSecurityContextHolder.getContext().getUserId());
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
public CommonResult<UsersOrderConfirmCreateVO> list() {
|
||||
// 获得购物车中所有的
|
||||
List<CartItemBO> cartItems = cartService.list(UserSecurityContextHolder.getContext().getUserId(), null);
|
||||
// 购物车为空时,构造空的 UsersOrderConfirmCreateVO 返回
|
||||
if (cartItems.isEmpty()) {
|
||||
UsersOrderConfirmCreateVO result = new UsersOrderConfirmCreateVO();
|
||||
result.setItemGroups(Collections.emptyList());
|
||||
result.setFee(new UsersOrderConfirmCreateVO.Fee(0, 0, 0, 0));
|
||||
return CommonResult.success(result);
|
||||
}
|
||||
// 购物车非空时,获得具体结果
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@GetMapping("/confirm_create_order")
|
||||
public CommonResult<UsersOrderConfirmCreateVO> getConfirmCreateOrder() {
|
||||
// 获得购物车中选中的
|
||||
List<CartItemBO> cartItems = cartService.list(UserSecurityContextHolder.getContext().getUserId(), true);
|
||||
// 购物车为空时,构造空的 UsersOrderConfirmCreateVO 返回
|
||||
if (cartItems.isEmpty()) {
|
||||
UsersOrderConfirmCreateVO result = new UsersOrderConfirmCreateVO();
|
||||
result.setItemGroups(Collections.emptyList());
|
||||
result.setFee(new UsersOrderConfirmCreateVO.Fee(0, 0, 0, 0));
|
||||
return CommonResult.success(result);
|
||||
}
|
||||
// 购物车非空时,获得具体结果
|
||||
// return CommonResult.success(CartConvert.INSTANCE.convert(calcOrderPriceResult.getData()));
|
||||
return null;
|
||||
}
|
||||
|
||||
public CommonResult<Object> confirmOrder() {
|
||||
// 查询购物车列表(选中的)
|
||||
// cartService.list(userId, true);
|
||||
|
||||
@@ -133,6 +133,15 @@ public class UsersOrderConfirmCreateVO {
|
||||
*/
|
||||
private Integer presentTotal;
|
||||
|
||||
public Fee() {
|
||||
}
|
||||
|
||||
public Fee(Integer originalTotal, Integer discountTotal, Integer postageTotal, Integer presentTotal) {
|
||||
this.originalTotal = originalTotal;
|
||||
this.discountTotal = discountTotal;
|
||||
this.postageTotal = postageTotal;
|
||||
this.presentTotal = presentTotal;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -39,9 +39,10 @@ public interface CartService {
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @param skuId 商品 SKU 编号
|
||||
* @param selected 是否选中
|
||||
* @return 是否成功
|
||||
*/
|
||||
CommonResult<Boolean> updateSelected(Integer userId, Integer skuId);
|
||||
CommonResult<Boolean> updateSelected(Integer userId, Integer skuId, Boolean selected);
|
||||
|
||||
/**
|
||||
* 购物车删除商品
|
||||
@@ -67,7 +68,7 @@ public interface CartService {
|
||||
* @param userId 用户编号
|
||||
* @return 商品数量
|
||||
*/
|
||||
CommonResult<Integer> count(Integer userId, String nobody, Integer shopId);
|
||||
CommonResult<Integer> count(Integer userId);
|
||||
|
||||
/**
|
||||
* 显示买家购物车中的商品列表,并根据 selected 进行过滤。
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package cn.iocoder.mall.order.api.constant;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public enum CartItemStatusEnum {
|
||||
|
||||
ENABLE(1, "正常"),
|
||||
DELETE_BY_MANUAL(2, "主动删除"),
|
||||
DELETE_BY_(3, "下单删除"),
|
||||
;
|
||||
|
||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CartItemStatusEnum::getValue).toArray();
|
||||
|
||||
/**
|
||||
* 状态值
|
||||
*/
|
||||
private Integer value;
|
||||
/**
|
||||
* 状态名
|
||||
*/
|
||||
private String name;
|
||||
|
||||
CartItemStatusEnum(Integer value, String name) {
|
||||
this.value = value;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public CartItemStatusEnum setValue(Integer value) {
|
||||
this.value = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public CartItemStatusEnum setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,6 +27,12 @@ public enum OrderErrorCodeEnum {
|
||||
ORDER_ITEM_ONLY_ONE(1008000004, "订单Item只有一个!"),
|
||||
ORDER_ITEM_SOME_NOT_EXISTS(-1, "有不存在的商品"), // TODO 芋艿 后面改下错误码
|
||||
|
||||
|
||||
// ========== 购物车 ==========
|
||||
CARD_ITEM_NOT_FOUND(1008003000, "购物车项不存在"),
|
||||
CARD_ITEM_SKU_NOT_FOUND(1008003001, "商品不存在"),
|
||||
CARD_ITEM_SKU_QUANTITY_NOT_ENOUGH(1008003002, "商品库存不足"),
|
||||
|
||||
;
|
||||
|
||||
private final int code;
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package cn.iocoder.mall.order.biz.dao;
|
||||
|
||||
import cn.iocoder.mall.order.biz.dataobject.CartItemDO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface CartMapper {
|
||||
|
||||
CartItemDO selectById(@Param("id") Integer id);
|
||||
|
||||
List<CartItemDO> selectByIds(@Param("ids") Collection<Integer> ids);
|
||||
|
||||
CartItemDO selectByUserIdAndSkuIdAndStatus(@Param("userId") Integer userId,
|
||||
@Param("skuId") Integer skuId,
|
||||
@Param("status") Integer status);
|
||||
|
||||
Integer selectQuantitySumByUserIdAndStatus(@Param("userId") Integer userId,
|
||||
@Param("status") Integer status);
|
||||
|
||||
// List<CartItemDO> selectListByStatus(@Param("status") Integer status);
|
||||
//
|
||||
// List<CartItemDO> selectListByTitleLike(@Param("title") String title,
|
||||
// @Param("offset") Integer offset,
|
||||
// @Param("limit") Integer limit);
|
||||
|
||||
// Integer selectCountByTitleLike(@Param("title") String title);
|
||||
|
||||
void insert(CartItemDO cartItemDO);
|
||||
|
||||
int update(CartItemDO cartItemDO);
|
||||
|
||||
int updateQuantity(@Param("id") Integer id,
|
||||
@Param("quantityIncr") Integer quantityIncr);
|
||||
|
||||
}
|
||||
@@ -13,4 +13,5 @@ import org.springframework.stereotype.Repository;
|
||||
public interface OrderCancelMapper {
|
||||
|
||||
int insert(OrderCancelDO orderCancelDO);
|
||||
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class CartItemDO extends BaseDO {
|
||||
/**
|
||||
* 订单编号
|
||||
*/
|
||||
private String orderId;
|
||||
private Integer orderId;
|
||||
/**
|
||||
* 订单创建时间
|
||||
*/
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
package cn.iocoder.mall.order.biz.mock;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.product.api.ProductSpuService;
|
||||
import cn.iocoder.mall.product.api.bo.ProductSkuDetailBO;
|
||||
import cn.iocoder.mall.product.api.bo.ProductSpuBO;
|
||||
import cn.iocoder.mall.product.api.bo.ProductSpuDetailBO;
|
||||
import cn.iocoder.mall.product.api.bo.ProductSpuPageBO;
|
||||
import cn.iocoder.mall.product.api.dto.ProductSpuAddDTO;
|
||||
import cn.iocoder.mall.product.api.dto.ProductSpuPageDTO;
|
||||
import cn.iocoder.mall.product.api.dto.ProductSpuUpdateDTO;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Sin
|
||||
* @time 2019-03-24 15:24
|
||||
*/
|
||||
public class ProductSpuServiceMock implements ProductSpuService {
|
||||
|
||||
@Override
|
||||
public CommonResult<ProductSpuDetailBO> getProductSpuDetail(Integer id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<ProductSpuDetailBO> addProductSpu(Integer adminId, ProductSpuAddDTO productSpuAddDTO) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> updateProductSpu(Integer adminId, ProductSpuUpdateDTO productSpuUpdateDTO) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> updateProductSpuSort(Integer adminId, Integer spuId, Integer sort) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<ProductSpuPageBO> getProductSpuPage(ProductSpuPageDTO productSpuPageDTO) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<List<ProductSpuBO>> getProductSpuList(Collection<Integer> ids) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<List<ProductSkuDetailBO>> getProductSkuDetailList(Collection<Integer> ids) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.iocoder.mall.order.biz.service;
|
||||
|
||||
import cn.iocoder.common.framework.constant.CommonStatusEnum;
|
||||
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.order.api.CartService;
|
||||
@@ -7,12 +8,17 @@ import cn.iocoder.mall.order.api.bo.CalcOrderPriceBO;
|
||||
import cn.iocoder.mall.order.api.bo.CartBO;
|
||||
import cn.iocoder.mall.order.api.bo.CartItemBO;
|
||||
import cn.iocoder.mall.order.api.bo.OrderCreateBO;
|
||||
import cn.iocoder.mall.order.api.constant.CartItemStatusEnum;
|
||||
import cn.iocoder.mall.order.api.constant.OrderErrorCodeEnum;
|
||||
import cn.iocoder.mall.order.api.dto.CalcOrderPriceDTO;
|
||||
import cn.iocoder.mall.order.biz.convert.CartConvert;
|
||||
import cn.iocoder.mall.order.biz.dao.CartMapper;
|
||||
import cn.iocoder.mall.order.biz.dataobject.CartItemDO;
|
||||
import cn.iocoder.mall.product.api.ProductSpuService;
|
||||
import cn.iocoder.mall.product.api.bo.ProductSkuBO;
|
||||
import cn.iocoder.mall.product.api.bo.ProductSkuDetailBO;
|
||||
import com.alibaba.dubbo.config.annotation.Reference;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
@@ -28,19 +34,97 @@ public class CartServiceImpl implements CartService {
|
||||
@Reference(validation = "true")
|
||||
private ProductSpuService productSpuService;
|
||||
|
||||
@Autowired
|
||||
private CartMapper cartMapper;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("Duplicates")
|
||||
public CommonResult<Boolean> add(Integer userId, Integer skuId, Integer quantity) {
|
||||
return null;
|
||||
// 查询 SKU 是否合法
|
||||
CommonResult<ProductSkuBO> skuResult = productSpuService.getProductSku(skuId);
|
||||
if (skuResult.isError()) {
|
||||
return CommonResult.error(skuResult);
|
||||
}
|
||||
ProductSkuBO sku = skuResult.getData();
|
||||
if (sku == null
|
||||
|| CommonStatusEnum.DISABLE.getValue().equals(sku.getStatus())) { // sku 被禁用
|
||||
return ServiceExceptionUtil.error(OrderErrorCodeEnum.CARD_ITEM_SKU_NOT_FOUND.getCode());
|
||||
}
|
||||
// TODO 芋艿,后续基于商品是否上下架进一步完善。
|
||||
// 查询 CartItemDO
|
||||
CartItemDO item = cartMapper.selectByUserIdAndSkuIdAndStatus(userId, skuId, CartItemStatusEnum.ENABLE.getValue());
|
||||
// 存在,则进行数量更新
|
||||
if (item != null) {
|
||||
return updateQuantity0(item, sku, quantity);
|
||||
}
|
||||
// 不存在,则进行插入
|
||||
return add0(userId, sku, quantity);
|
||||
}
|
||||
|
||||
private CommonResult<Boolean> add0(Integer userId, ProductSkuBO sku, Integer quantity) {
|
||||
// 校验库存
|
||||
if (quantity > sku.getQuantity()) {
|
||||
return ServiceExceptionUtil.error(OrderErrorCodeEnum.CARD_ITEM_SKU_NOT_FOUND.getCode());
|
||||
}
|
||||
// 创建 CartItemDO 对象,并进行保存。
|
||||
CartItemDO item = new CartItemDO()
|
||||
// 基础字段
|
||||
.setStatus(CartItemStatusEnum.ENABLE.getValue()).setSelected(true)
|
||||
// 买家信息
|
||||
.setUserId(userId)
|
||||
// 商品信息
|
||||
.setSpuId(sku.getSpuId()).setSkuId(sku.getId()).setQuantity(quantity);
|
||||
item.setCreateTime(new Date());
|
||||
cartMapper.insert(item);
|
||||
// 返回成功
|
||||
return CommonResult.success(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("Duplicates")
|
||||
public CommonResult<Boolean> updateQuantity(Integer userId, Integer skuId, Integer quantity) {
|
||||
return null;
|
||||
// 查询 SKU 是否合法
|
||||
CommonResult<ProductSkuBO> skuResult = productSpuService.getProductSku(skuId);
|
||||
if (skuResult.isError()) {
|
||||
return CommonResult.error(skuResult);
|
||||
}
|
||||
ProductSkuBO sku = skuResult.getData();
|
||||
if (sku == null
|
||||
|| CommonStatusEnum.DISABLE.getValue().equals(sku.getStatus())) { // sku 被禁用
|
||||
return ServiceExceptionUtil.error(OrderErrorCodeEnum.CARD_ITEM_SKU_NOT_FOUND.getCode());
|
||||
}
|
||||
// 查询 CartItemDO
|
||||
CartItemDO item = cartMapper.selectByUserIdAndSkuIdAndStatus(userId, skuId, CartItemStatusEnum.ENABLE.getValue());
|
||||
if (item == null) {
|
||||
return ServiceExceptionUtil.error(OrderErrorCodeEnum.CARD_ITEM_NOT_FOUND.getCode());
|
||||
}
|
||||
// TODO 芋艿,后续基于商品是否上下架进一步完善。
|
||||
return updateQuantity0(item, sku, quantity);
|
||||
}
|
||||
|
||||
private CommonResult<Boolean> updateQuantity0(CartItemDO item, ProductSkuBO sku, Integer quantity) {
|
||||
// 校验库存
|
||||
if (item.getQuantity() + quantity > sku.getQuantity()) {
|
||||
return ServiceExceptionUtil.error(OrderErrorCodeEnum.CARD_ITEM_SKU_NOT_FOUND.getCode());
|
||||
}
|
||||
// 更新 CartItemDO
|
||||
cartMapper.updateQuantity(item.getId(), quantity);
|
||||
// 返回成功
|
||||
return CommonResult.success(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> updateSelected(Integer userId, Integer skuId) {
|
||||
return null;
|
||||
public CommonResult<Boolean> updateSelected(Integer userId, Integer skuId, Boolean selected) {
|
||||
// 查询 CartItemDO
|
||||
CartItemDO item = cartMapper.selectByUserIdAndSkuIdAndStatus(userId, skuId, CartItemStatusEnum.ENABLE.getValue());
|
||||
if (item == null) {
|
||||
return ServiceExceptionUtil.error(OrderErrorCodeEnum.CARD_ITEM_NOT_FOUND.getCode());
|
||||
}
|
||||
// 更新 CartItemDO
|
||||
CartItemDO updateCartItem = new CartItemDO().setId(item.getId()).setSelected(selected);
|
||||
cartMapper.update(updateCartItem);
|
||||
// 返回成功
|
||||
return CommonResult.success(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,8 +138,8 @@ public class CartServiceImpl implements CartService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Integer> count(Integer userId, String nobody, Integer shopId) {
|
||||
return null;
|
||||
public CommonResult<Integer> count(Integer userId) {
|
||||
return CommonResult.success(cartMapper.selectQuantitySumByUserIdAndStatus(userId, CartItemStatusEnum.ENABLE.getValue()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
<?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.iocoder.mall.order.biz.dao.CartMapper">
|
||||
|
||||
<sql id="FIELDS">
|
||||
id, status, delete_time, selected, user_id,
|
||||
spu_id, sku_id, quantity, order_id, order_create_time,
|
||||
create_time
|
||||
</sql>
|
||||
|
||||
<select id="selectById" parameterType="Integer" resultType="CartItemDO">
|
||||
SELECT
|
||||
<include refid="FIELDS" />
|
||||
FROM cart_item
|
||||
WHERE id = #{id}
|
||||
-- AND deleted = 0
|
||||
</select>
|
||||
|
||||
<select id="selectByIds" resultType="CartItemDO">
|
||||
SELECT
|
||||
<include refid="FIELDS" />
|
||||
FROM cart_item
|
||||
WHERE id IN
|
||||
<foreach item="id" collection="ids" separator="," open="(" close=")" index="">
|
||||
#{id}
|
||||
</foreach>
|
||||
-- AND deleted = 0
|
||||
</select>
|
||||
|
||||
<select id="selectByUserIdAndSkuIdAndStatus" resultType="CartItemDO">
|
||||
SELECT
|
||||
<include refid="FIELDS" />
|
||||
FROM cart_item
|
||||
WHERE user_id = #{userId}
|
||||
AND sku_id = #{skuId}
|
||||
AND status = #{status}
|
||||
-- AND deleted = 0
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<select id="selectQuantitySumByUserIdAndStatus" resultType="Integer">
|
||||
SELECT
|
||||
SUM(quantity)
|
||||
FROM cart_item
|
||||
WHERE user_id = #{userId}
|
||||
AND status = #{status}
|
||||
-- AND deleted = 0
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="CartItemDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
|
||||
INSERT INTO cart_item (
|
||||
status, delete_time, selected, user_id,
|
||||
spu_id, sku_id, quantity, order_id, order_create_time,
|
||||
create_time
|
||||
) VALUES (
|
||||
#{status}, #{deleteTime}, #{selected}, #{userId},
|
||||
#{spuId}, #{skuId}, #{quantity}, #{orderId}, #{orderCreateTime},
|
||||
#{createTime}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="CartItemDO">
|
||||
UPDATE cart_item
|
||||
<set>
|
||||
<if test="status != null">
|
||||
status = #{status},
|
||||
</if>
|
||||
<if test="deleteTime != null">
|
||||
delete_time = #{deleteTime},
|
||||
</if>
|
||||
<if test="selected != null">
|
||||
selected = #{selected},
|
||||
</if>
|
||||
<if test="quantity != null">
|
||||
quantity = #{quantity},
|
||||
</if>
|
||||
<if test="orderId != null">
|
||||
order_id = #{orderId},
|
||||
</if>
|
||||
<if test="orderCreateTime != null">
|
||||
order_create_time = #{orderCreateTime},
|
||||
</if>
|
||||
<if test="price != null">
|
||||
price = #{price},
|
||||
</if>
|
||||
<if test="quantity != null">
|
||||
quantity = #{quantity},
|
||||
</if>
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="updateQuantity" parameterType="CartItemDO">
|
||||
UPDATE cart_item
|
||||
SET quantity = quantity + #{quantityIncr}
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user