完成购物车功能及下单功能
This commit is contained in:
@@ -0,0 +1,266 @@
|
||||
package com.gxwebsoft.shop.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.shop.entity.GoodsCategory;
|
||||
import com.gxwebsoft.shop.entity.Merchant;
|
||||
import com.gxwebsoft.shop.service.CartService;
|
||||
import com.gxwebsoft.shop.entity.Cart;
|
||||
import com.gxwebsoft.shop.param.CartParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.shop.service.MerchantService;
|
||||
import com.gxwebsoft.shop.vo.CartShopVo;
|
||||
import com.gxwebsoft.shop.vo.CartVo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.gxwebsoft.common.core.utils.CommonUtil.toTreeData;
|
||||
|
||||
/**
|
||||
* 购物车控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-07-29 21:02:39
|
||||
*/
|
||||
@Api(tags = "购物车管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/shop/cart")
|
||||
public class CartController extends BaseController {
|
||||
@Resource
|
||||
private CartService cartService;
|
||||
@Resource
|
||||
private MerchantService merchantService;
|
||||
|
||||
@ApiOperation("我的购物车")
|
||||
@GetMapping("/myCart")
|
||||
public ApiResult<?> myCart(CartParam param){
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser == null) {
|
||||
return fail("请先登录",null);
|
||||
}
|
||||
// 查询购物车
|
||||
param.setUserId(getLoginUserId().longValue());
|
||||
final List<Cart> carts = cartService.listRelMpj(param);
|
||||
// final List<Cart> carts = cartService.list(new LambdaQueryWrapper<Cart>()
|
||||
// .eq(Cart::getUserId, loginUser.getUserId())
|
||||
// .eq(Cart::getIsPay, 0)
|
||||
// .eq(Cart::getIsNew, 0)
|
||||
// .eq(Cart::getDeleted, 0)
|
||||
// .last("limit 100"));
|
||||
|
||||
// 收集店铺ID
|
||||
final Set<Integer> merchantIds = carts.stream().map(Cart::getMerchantId).collect(Collectors.toSet());
|
||||
|
||||
// 查询店铺列
|
||||
final List<Merchant> merchants = merchantService.list(new LambdaQueryWrapper<Merchant>()
|
||||
.select(Merchant::getMerchantId,Merchant::getMerchantName,Merchant::getImage,Merchant::getShopType)
|
||||
.in(Merchant::getMerchantId, merchantIds));
|
||||
|
||||
// 返回空列表
|
||||
if (CollectionUtils.isEmpty(merchants)) {
|
||||
return success(merchants);
|
||||
}
|
||||
|
||||
final Map<Integer, List<Cart>> collect = carts.stream().collect(Collectors.groupingBy(Cart::getMerchantId));
|
||||
|
||||
// 封装数据
|
||||
merchants.forEach(d -> {
|
||||
d.setCarts(collect.get(d.getMerchantId()));
|
||||
});
|
||||
|
||||
// 计算购物车金额
|
||||
HashMap<String, Object> map = computeCart();
|
||||
map.put("merchants",merchants);
|
||||
|
||||
return success(map);
|
||||
}
|
||||
|
||||
@ApiOperation("添加购物车")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Cart cart) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser == null) {
|
||||
return fail("请先登录");
|
||||
}
|
||||
|
||||
// 购物车是否已存在
|
||||
final Cart item = cartService.getOne(new LambdaQueryWrapper<Cart>().eq(Cart::getUserId, loginUser.getUserId()).eq(Cart::getGoodsId, cart.getGoodsId()).last("limit 1"));
|
||||
cart.setUserId(loginUser.getUserId().longValue());
|
||||
|
||||
// 修改购物车
|
||||
if (item != null) {
|
||||
item.setCartNum(item.getCartNum() + cart.getCartNum());
|
||||
cartService.updateById(item);
|
||||
return success("添加成功",computeCart());
|
||||
}
|
||||
|
||||
// 新添加商品
|
||||
if (cartService.save(cart)) {
|
||||
return success("添加成功",computeCart());
|
||||
}
|
||||
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@ApiOperation("修改购物车")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Cart cart) {
|
||||
if (cartService.updateById(cart)) {
|
||||
return success("修改成功",computeCart());
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@ApiOperation("计算购物车金额")
|
||||
@GetMapping("/count")
|
||||
public HashMap<String, Object> computeCart() {
|
||||
// 查询购物车数据
|
||||
final List<Cart> carts = cartService.list(new LambdaQueryWrapper<Cart>()
|
||||
.select(Cart::getId,Cart::getPrice,Cart::getCartNum)
|
||||
.eq(Cart::getUserId, getLoginUserId())
|
||||
.eq(Cart::getSelected,1)
|
||||
.eq(Cart::getIsPay, 0)
|
||||
);
|
||||
|
||||
// 计算单品合计价格
|
||||
carts.forEach(d -> {
|
||||
d.setTotalPrice(d.getPrice().multiply(BigDecimal.valueOf(d.getCartNum())));
|
||||
});
|
||||
|
||||
// 保存到数据库
|
||||
cartService.updateBatchById(carts);
|
||||
|
||||
// 计算购物车金额
|
||||
final Integer reduce = carts.stream().map(Cart::getCartNum).reduce(Integer::sum).orElse(0);
|
||||
final BigDecimal reduced = carts.stream().map(Cart::getTotalPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
// 是否全选
|
||||
Boolean selectAll = cartService.count(new LambdaQueryWrapper<Cart>()
|
||||
.eq(Cart::getUserId, getLoginUserId())
|
||||
.eq(Cart::getSelected, 0)
|
||||
.eq(Cart::getIsPay, 0)
|
||||
) == 0;
|
||||
|
||||
|
||||
// 返回给前端
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("totalCartNum",reduce);
|
||||
map.put("totalPrice",reduced);
|
||||
map.put("selectAll",selectAll);
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
@ApiOperation("全选操作")
|
||||
@PutMapping("/onSelectAll/{yes}")
|
||||
public ApiResult<?> onSelectAll(@PathVariable("yes") Boolean yes) {
|
||||
// 是否全选
|
||||
if (yes.equals(true)) {
|
||||
// 全勾选
|
||||
cartService.update(new LambdaUpdateWrapper<Cart>()
|
||||
.eq(Cart::getUserId, getLoginUserId())
|
||||
.eq(Cart::getIsPay, 0)
|
||||
.eq(Cart::getSelected,0)
|
||||
.set(Cart::getSelected,1)
|
||||
);
|
||||
return success("修改成功",computeCart());
|
||||
}
|
||||
// 全不勾选
|
||||
cartService.update(new LambdaUpdateWrapper<Cart>()
|
||||
.eq(Cart::getUserId, getLoginUserId())
|
||||
.eq(Cart::getIsPay, 0)
|
||||
.eq(Cart::getSelected,1)
|
||||
.set(Cart::getSelected,0)
|
||||
);
|
||||
return success("修改成功",computeCart());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// @ApiOperation("按店铺ID更新选择状态")
|
||||
// @PutMapping("/updateCartByMerchantId/{id}")
|
||||
// public ApiResult<?> updateCartByMerchantId(@PathVariable("id") Long id) {
|
||||
//
|
||||
// if (cartService.updateById()) {
|
||||
// return success("修改成功");
|
||||
// }
|
||||
// return fail("修改失败");
|
||||
// }
|
||||
|
||||
|
||||
@ApiOperation("分页查询购物车")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Cart>> page(CartParam param) {
|
||||
// 使用关联查询
|
||||
return success(cartService.pageRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("查询全部购物车")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Cart>> list(CartParam param) {
|
||||
// 使用关联查询
|
||||
return success(cartService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:cart:list')")
|
||||
@ApiOperation("根据id查询购物车")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Cart> get(@PathVariable("id") Long id) {
|
||||
// 使用关联查询
|
||||
return success(cartService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@ApiOperation("删除购物车")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (cartService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@ApiOperation("批量添加购物车")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Cart> list) {
|
||||
if (cartService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@ApiOperation("批量修改购物车")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Cart> batchParam) {
|
||||
if (batchParam.update(cartService, "id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@ApiOperation("批量删除购物车")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (cartService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,7 +23,11 @@ import com.gxwebsoft.common.core.utils.RequestUtil;
|
||||
import com.gxwebsoft.common.core.utils.WxUtil;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.Role;
|
||||
import com.gxwebsoft.shop.entity.Cart;
|
||||
import com.gxwebsoft.shop.entity.OrderGoods;
|
||||
import com.gxwebsoft.shop.entity.OrderInfo;
|
||||
import com.gxwebsoft.shop.param.CartParam;
|
||||
import com.gxwebsoft.shop.service.CartService;
|
||||
import com.gxwebsoft.shop.service.OrderGoodsService;
|
||||
import com.gxwebsoft.shop.service.OrderInfoService;
|
||||
import com.gxwebsoft.shop.service.OrderService;
|
||||
@@ -48,10 +52,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Instant;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -78,7 +79,11 @@ public class OrderController extends BaseController {
|
||||
@Resource
|
||||
private CardService cardService;
|
||||
@Resource
|
||||
private CartService cartService;
|
||||
@Resource
|
||||
private RequestUtil requestUtil;
|
||||
@Resource
|
||||
private CartController cartController;
|
||||
|
||||
@ApiOperation("分页查询订单")
|
||||
@GetMapping("/page")
|
||||
@@ -217,14 +222,40 @@ public class OrderController extends BaseController {
|
||||
if (orderService.save(order)) {
|
||||
// 商城订单
|
||||
if (order.getType().equals(0)) {
|
||||
order.getGoodsList().forEach(d -> {
|
||||
d.setOrderId(order.getOrderId());
|
||||
d.setTimeFlag(timeMillis);
|
||||
d.setVersion(10);
|
||||
d.setDateTime(DateUtil.date());
|
||||
d.setUserId(getLoginUser().getUserId());
|
||||
d.setExpirationTime(order.getExpirationTime());
|
||||
});
|
||||
// order.getGoodsList().forEach(d -> {
|
||||
// d.setOrderId(order.getOrderId());
|
||||
// d.setTimeFlag(timeMillis);
|
||||
// d.setVersion(10);
|
||||
// d.setDateTime(DateUtil.date());
|
||||
// d.setUserId(getLoginUser().getUserId());
|
||||
// d.setExpirationTime(order.getExpirationTime());
|
||||
// });
|
||||
|
||||
// 从购物车获取订单数据
|
||||
final CartParam cartParam = new CartParam();
|
||||
cartParam.setUserId(getLoginUserId().longValue());
|
||||
cartParam.setSelected(true);
|
||||
final List<Cart> carts = cartService.listRelMpj(cartParam);
|
||||
final ArrayList<OrderGoods> orderGoods = new ArrayList<>();
|
||||
if (!CollectionUtils.isEmpty(carts)) {
|
||||
carts.forEach(d -> {
|
||||
final OrderGoods goods = new OrderGoods();
|
||||
goods.setOrderId(order.getOrderId());
|
||||
goods.setImage(d.getImage());
|
||||
goods.setGoodsName(d.getGoodsName());
|
||||
goods.setGoodsId(Math.toIntExact(d.getGoodsId()));
|
||||
goods.setTotalNum(d.getCartNum());
|
||||
goods.setPrice(d.getPrice());
|
||||
goods.setVersion(10);
|
||||
goods.setUserId(order.getUserId());
|
||||
goods.setTimeFlag(timeMillis);
|
||||
goods.setDateTime(DateUtil.date());
|
||||
goods.setExpirationTime(order.getExpirationTime());
|
||||
orderGoods.add(goods);
|
||||
});
|
||||
System.out.println("carts = " + carts);
|
||||
order.setGoodsList(orderGoods);
|
||||
}
|
||||
orderGoodsService.saveBatch(order.getGoodsList());
|
||||
}
|
||||
// 预定订单
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.gxwebsoft.shop.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 购物车
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-07-29 21:02:39
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value = "Cart对象", description = "购物车")
|
||||
@TableName("shop_cart")
|
||||
public class Cart implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "购物车表ID")
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "类型 0商城 1预定 ")
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty(value = "商品ID")
|
||||
private Long goodsId;
|
||||
|
||||
@ApiModelProperty(value = "商品属性")
|
||||
private String goodsAttrUnique;
|
||||
|
||||
@ApiModelProperty(value = "商品价格")
|
||||
private BigDecimal price;
|
||||
|
||||
@ApiModelProperty(value = "商品数量")
|
||||
private Integer cartNum;
|
||||
|
||||
@ApiModelProperty(value = "单品合计")
|
||||
private BigDecimal totalPrice;
|
||||
|
||||
@ApiModelProperty(value = "0 = 未购买 1 = 已购买")
|
||||
private Boolean isPay;
|
||||
|
||||
@ApiModelProperty(value = "是否为立即购买")
|
||||
private Boolean isNew;
|
||||
|
||||
@ApiModelProperty(value = "是否选中")
|
||||
private Boolean selected;
|
||||
|
||||
@ApiModelProperty(value = "拼团id")
|
||||
private Integer combinationId;
|
||||
|
||||
@ApiModelProperty(value = "秒杀产品ID")
|
||||
private Integer seckillId;
|
||||
|
||||
@ApiModelProperty(value = "砍价id")
|
||||
private Integer bargainId;
|
||||
|
||||
@ApiModelProperty(value = "商户ID")
|
||||
private Integer merchantId;
|
||||
|
||||
@ApiModelProperty(value = "用户ID")
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty(value = "租户id")
|
||||
private Integer tenantId;
|
||||
|
||||
@ApiModelProperty(value = "添加时间")
|
||||
private Date createTime;
|
||||
|
||||
@ApiModelProperty(value = "修改时间")
|
||||
private Date updateTime;
|
||||
|
||||
@ApiModelProperty(value = "店铺名称")
|
||||
@TableField(exist = false)
|
||||
private String merchantName;
|
||||
|
||||
@ApiModelProperty(value = "商品名称")
|
||||
@TableField(exist = false)
|
||||
private String goodsName;
|
||||
|
||||
@ApiModelProperty(value = "商品图片")
|
||||
@TableField(exist = false)
|
||||
private String image;
|
||||
|
||||
@ApiModelProperty(value = "是否全选")
|
||||
@TableField(exist = false)
|
||||
private Boolean selectAll;
|
||||
|
||||
@ApiModelProperty("子菜单")
|
||||
@TableField(exist = false)
|
||||
private List<Cart> children;
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.annotation.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
@@ -129,4 +130,8 @@ public class Merchant implements Serializable {
|
||||
@TableField(exist = false)
|
||||
private String roleName;
|
||||
|
||||
@ApiModelProperty(value = "按店铺分类的购物车商品")
|
||||
@TableField(exist = false)
|
||||
private List<Cart> carts;
|
||||
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@ package com.gxwebsoft.shop.entity;
|
||||
import java.math.BigDecimal;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import java.time.LocalDate;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.time.LocalTime;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.gxwebsoft.shop.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.gxwebsoft.shop.entity.Cart;
|
||||
import com.gxwebsoft.shop.param.CartParam;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 购物车Mapper
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-07-29 21:02:39
|
||||
*/
|
||||
public interface CartMapper extends MPJBaseMapper<Cart> {
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param param 查询参数
|
||||
* @return List<Cart>
|
||||
*/
|
||||
List<Cart> selectPageRel(@Param("page") IPage<Cart> page,
|
||||
@Param("param") CartParam param);
|
||||
|
||||
/**
|
||||
* 查询全部
|
||||
*
|
||||
* @param param 查询参数
|
||||
* @return List<User>
|
||||
*/
|
||||
List<Cart> selectListRel(@Param("param") CartParam param);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?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.gxwebsoft.shop.mapper.CartMapper">
|
||||
|
||||
<!-- 关联查询sql -->
|
||||
<sql id="selectSql">
|
||||
SELECT a.*,b.goods_name,b.image,c.merchant_name
|
||||
FROM shop_cart a
|
||||
LEFT JOIN shop_goods b ON a.goods_id = b.goods_id
|
||||
LEFT JOIN shop_merchant c ON a.merchant_id = b.merchant_id
|
||||
<where>
|
||||
<if test="param.id != null">
|
||||
AND a.id = #{param.id}
|
||||
</if>
|
||||
<if test="param.type != null">
|
||||
AND a.type = #{param.type}
|
||||
</if>
|
||||
<if test="param.goodsId != null">
|
||||
AND a.goods_id LIKE CONCAT('%', #{param.goodsId}, '%')
|
||||
</if>
|
||||
<if test="param.goodsAttrUnique != null">
|
||||
AND a.goods_attr_unique LIKE CONCAT('%', #{param.goodsAttrUnique}, '%')
|
||||
</if>
|
||||
<if test="param.cartNum != null">
|
||||
AND a.cart_num = #{param.cartNum}
|
||||
</if>
|
||||
<if test="param.isPay != null">
|
||||
AND a.is_pay = #{param.isPay}
|
||||
</if>
|
||||
<if test="param.isNew != null">
|
||||
AND a.is_new = #{param.isNew}
|
||||
</if>
|
||||
<if test="param.combinationId != null">
|
||||
AND a.combination_id = #{param.combinationId}
|
||||
</if>
|
||||
<if test="param.seckillId != null">
|
||||
AND a.seckill_id = #{param.seckillId}
|
||||
</if>
|
||||
<if test="param.bargainId != null">
|
||||
AND a.bargain_id = #{param.bargainId}
|
||||
</if>
|
||||
<if test="param.userId != null">
|
||||
AND a.user_id LIKE CONCAT('%', #{param.userId}, '%')
|
||||
</if>
|
||||
<if test="param.selected != null">
|
||||
AND a.selected = #{param.selected}
|
||||
</if>
|
||||
|
||||
<!-- <if test="param.deleted != null">-->
|
||||
<!-- AND a.deleted = #{param.deleted}-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="param.deleted == null">-->
|
||||
<!-- AND a.deleted = 0-->
|
||||
<!-- </if>-->
|
||||
<if test="param.createTimeStart != null">
|
||||
AND a.create_time >= #{param.createTimeStart}
|
||||
</if>
|
||||
<if test="param.createTimeEnd != null">
|
||||
AND a.create_time <= #{param.createTimeEnd}
|
||||
</if>
|
||||
<if test="param.keywords != null">
|
||||
AND (a.comments LIKE CONCAT('%', #{param.keywords}, '%')
|
||||
OR b.goods_name LIKE CONCAT('%', #{param.keywords}, '%')
|
||||
)
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- 分页查询 -->
|
||||
<select id="selectPageRel" resultType="com.gxwebsoft.shop.entity.Cart">
|
||||
<include refid="selectSql"></include>
|
||||
</select>
|
||||
|
||||
<!-- 查询全部 -->
|
||||
<select id="selectListRel" resultType="com.gxwebsoft.shop.entity.Cart">
|
||||
<include refid="selectSql"></include>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.gxwebsoft.shop.param;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import com.gxwebsoft.common.core.annotation.QueryField;
|
||||
import com.gxwebsoft.common.core.annotation.QueryType;
|
||||
import com.gxwebsoft.common.core.web.BaseParam;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import io.swagger.models.auth.In;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 购物车查询参数
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-07-29 21:02:39
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@ApiModel(value = "CartParam对象", description = "购物车查询参数")
|
||||
public class CartParam extends BaseParam {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "购物车表ID")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "类型 0商城 1预定 ")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty(value = "商品ID")
|
||||
private Long goodsId;
|
||||
|
||||
@ApiModelProperty(value = "商品属性")
|
||||
private String goodsAttrUnique;
|
||||
|
||||
@ApiModelProperty(value = "商品数量")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer cartNum;
|
||||
|
||||
@ApiModelProperty(value = "0 = 未购买 1 = 已购买")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Boolean isPay;
|
||||
|
||||
@ApiModelProperty(value = "是否为立即购买")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Boolean isNew;
|
||||
|
||||
@ApiModelProperty(value = "拼团id")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer combinationId;
|
||||
|
||||
@ApiModelProperty(value = "秒杀产品ID")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer seckillId;
|
||||
|
||||
@ApiModelProperty(value = "砍价id")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer bargainId;
|
||||
|
||||
@ApiModelProperty(value = "用户ID")
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty(value = "是否选中")
|
||||
private Boolean selected;
|
||||
|
||||
@ApiModelProperty(value = "商户ID")
|
||||
private Integer merchantId;
|
||||
|
||||
// @ApiModelProperty(value = "是否删除, 0否, 1是")
|
||||
// @QueryField(type = QueryType.EQ)
|
||||
// private Integer deleted;
|
||||
|
||||
@ApiModelProperty(value = "商品名称")
|
||||
@QueryField(type = QueryType.LIKE)
|
||||
private String goodsName;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.gxwebsoft.shop.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.shop.entity.Cart;
|
||||
import com.gxwebsoft.shop.param.CartParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 购物车Service
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-07-29 21:02:39
|
||||
*/
|
||||
public interface CartService extends IService<Cart> {
|
||||
|
||||
/**
|
||||
* 分页关联查询
|
||||
*
|
||||
* @param param 查询参数
|
||||
* @return PageResult<Cart>
|
||||
*/
|
||||
PageResult<Cart> pageRel(CartParam param);
|
||||
|
||||
/**
|
||||
* 关联查询全部
|
||||
*
|
||||
* @param param 查询参数
|
||||
* @return List<Cart>
|
||||
*/
|
||||
List<Cart> listRel(CartParam param);
|
||||
|
||||
/**
|
||||
* 根据id查询
|
||||
*
|
||||
* @param id 购物车表ID
|
||||
* @return Cart
|
||||
*/
|
||||
Cart getByIdRel(Long id);
|
||||
|
||||
List<Cart> listRelMpj(CartParam param);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.gxwebsoft.shop.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.gxwebsoft.shop.entity.Goods;
|
||||
import com.gxwebsoft.shop.entity.GoodsSpec;
|
||||
import com.gxwebsoft.shop.mapper.CartMapper;
|
||||
import com.gxwebsoft.shop.service.CartService;
|
||||
import com.gxwebsoft.shop.entity.Cart;
|
||||
import com.gxwebsoft.shop.param.CartParam;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 购物车Service实现
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-07-29 21:02:39
|
||||
*/
|
||||
@Service
|
||||
public class CartServiceImpl extends ServiceImpl<CartMapper, Cart> implements CartService {
|
||||
|
||||
@Override
|
||||
public PageResult<Cart> pageRel(CartParam param) {
|
||||
PageParam<Cart, CartParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
List<Cart> list = baseMapper.selectPageRel(page, param);
|
||||
return new PageResult<>(list, page.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Cart> listRel(CartParam param) {
|
||||
List<Cart> list = baseMapper.selectListRel(param);
|
||||
// 排序
|
||||
PageParam<Cart, CartParam> page = new PageParam<>();
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return page.sortRecords(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cart getByIdRel(Long id) {
|
||||
CartParam param = new CartParam();
|
||||
param.setId(id);
|
||||
return param.getOne(baseMapper.selectListRel(param));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Cart> listRelMpj(CartParam param) {
|
||||
|
||||
System.out.println("param = " + param);
|
||||
// 多表查询
|
||||
MPJLambdaWrapper<Cart> mpjLambdaWrapper = new MPJLambdaWrapper<>();
|
||||
mpjLambdaWrapper.selectAll(Cart.class)
|
||||
.select(Goods::getGoodsName)
|
||||
.select(Goods::getImage)
|
||||
.leftJoin(Goods.class,Goods::getGoodsId,Cart::getGoodsId);
|
||||
|
||||
if(param.getSelected() != null){
|
||||
mpjLambdaWrapper.eq(Cart::getSelected,param.getSelected());
|
||||
}
|
||||
|
||||
return baseMapper.selectJoinList(Cart.class, mpjLambdaWrapper);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.gxwebsoft.shop.vo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.gxwebsoft.shop.entity.Cart;
|
||||
import com.gxwebsoft.shop.entity.Goods;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value = "店铺对象", description = "店铺")
|
||||
@TableName("shop_merchant")
|
||||
public class CartShopVo implements Serializable {
|
||||
|
||||
@ApiModelProperty(value = "店铺ID")
|
||||
private Integer shopId;
|
||||
|
||||
@ApiModelProperty("店铺名称")
|
||||
private String shopName;
|
||||
|
||||
@ApiModelProperty(value = "商品列表")
|
||||
private List<Goods> goods;
|
||||
@Data
|
||||
public static class Payload {
|
||||
private Integer shopId;
|
||||
private Integer shopName;
|
||||
private List<Goods> goods;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.gxwebsoft.shop.vo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.gxwebsoft.shop.entity.Cart;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value = "Cart对象", description = "购物车")
|
||||
@TableName("shop_cart")
|
||||
public class CartVo implements Serializable {
|
||||
|
||||
@ApiModelProperty("宝贝数量")
|
||||
private Long count;
|
||||
|
||||
@ApiModelProperty("店铺列表")
|
||||
private List<CartShopVo> shops;
|
||||
@Data
|
||||
public static class Payload {
|
||||
private Integer count;
|
||||
private Integer shops;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user