修复购物车模块
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.gxwebsoft.shop.controller;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
@@ -12,9 +13,11 @@ import com.gxwebsoft.shop.entity.Merchant;
|
||||
import com.gxwebsoft.shop.param.CartParam;
|
||||
import com.gxwebsoft.shop.service.CartService;
|
||||
import com.gxwebsoft.shop.service.MerchantService;
|
||||
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.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -41,212 +44,6 @@ public class CartController extends BaseController {
|
||||
@Resource
|
||||
private MerchantService merchantService;
|
||||
|
||||
@ApiOperation("我的购物车")
|
||||
@GetMapping("/myCart")
|
||||
public ApiResult<?> myCart(CartParam param) {
|
||||
HashMap<String, Object> map = computeCart(param);
|
||||
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser == null) {
|
||||
return fail("请先登录", null);
|
||||
}
|
||||
|
||||
// 查询购物车
|
||||
param.setUserId(loginUser.getUserId());
|
||||
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());
|
||||
if (CollectionUtils.isEmpty(merchantIds)) {
|
||||
map.put("selectAll", false);
|
||||
return success(map);
|
||||
}
|
||||
|
||||
// 查询店铺列
|
||||
final List<Merchant> merchants = merchantService.list(new LambdaQueryWrapper<Merchant>()
|
||||
.select(Merchant::getMerchantId, Merchant::getMerchantName, Merchant::getImage, Merchant::getShopType, Merchant::getAddress)
|
||||
.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()));
|
||||
});
|
||||
|
||||
// 计算购物车金额
|
||||
map.put("merchants", merchants);
|
||||
|
||||
return success(map);
|
||||
}
|
||||
|
||||
@ApiOperation("添加购物车")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Cart cart) {
|
||||
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser == null) {
|
||||
return fail("请先登录");
|
||||
}
|
||||
// 附加用户ID
|
||||
cart.setUserId(loginUser.getUserId());
|
||||
|
||||
// 字段验证
|
||||
if (cart.getCartNum() == null) {
|
||||
return fail("购买数量不能为空");
|
||||
}
|
||||
|
||||
// 立即购买按钮
|
||||
if(cart.getIsNew() != null && cart.getIsNew()){
|
||||
cartService.save(cart);
|
||||
return success(cart);
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<Cart> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
if (cart.getIsNew() != null) {
|
||||
queryWrapper.eq(Cart::getIsNew,cart.getIsNew());
|
||||
}
|
||||
|
||||
// 购物车是否已存在
|
||||
queryWrapper.eq(Cart::getUserId, loginUser.getUserId())
|
||||
.eq(Cart::getGoodsId, cart.getGoodsId())
|
||||
.eq(Cart::getType, cart.getType())
|
||||
.last("limit 1");
|
||||
|
||||
Cart item = cartService.getOne(queryWrapper);
|
||||
|
||||
// 查询购物车的参数
|
||||
final CartParam param = new CartParam();
|
||||
param.setType(cart.getType());
|
||||
if (cart.getIsNew() != null) {
|
||||
param.setIsNew(cart.getIsNew());
|
||||
}
|
||||
|
||||
// 重复商品叠加数量
|
||||
if(item != null){
|
||||
System.out.println("item = " + item);
|
||||
item.setCartNum(item.getCartNum() + cart.getCartNum());
|
||||
if (cartService.updateById(item)) {
|
||||
return success("更新成功", computeCart(param));
|
||||
}
|
||||
}
|
||||
|
||||
// 新添加商品
|
||||
if (cartService.save(cart)) {
|
||||
return success("添加成功", computeCart(param));
|
||||
}
|
||||
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@ApiOperation("修改购物车")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Cart cart) {
|
||||
if (cartService.updateById(cart)) {
|
||||
final CartParam param = new CartParam();
|
||||
param.setType(cart.getType());
|
||||
return success("修改成功", computeCart(param));
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@ApiOperation("计算购物车金额")
|
||||
@GetMapping("/count")
|
||||
public HashMap<String, Object> computeCart(CartParam param) {
|
||||
final LambdaQueryWrapper<Cart> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
queryWrapper.select(Cart::getId, Cart::getPrice, Cart::getCartNum)
|
||||
.eq(Cart::getUserId, getLoginUserId())
|
||||
.eq(Cart::getType, param.getType())
|
||||
.eq(Cart::getSelected, 1)
|
||||
.eq(Cart::getIsPay, 0);
|
||||
|
||||
// 查询购物车数据
|
||||
final List<Cart> carts = cartService.list(queryWrapper);
|
||||
|
||||
// 计算单品合计价格
|
||||
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) {
|
||||
final CartParam param = new CartParam();
|
||||
param.setType(0);
|
||||
|
||||
// 是否全选
|
||||
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(param));
|
||||
}
|
||||
// 全不勾选
|
||||
cartService.update(new LambdaUpdateWrapper<Cart>()
|
||||
.eq(Cart::getUserId, getLoginUserId())
|
||||
.eq(Cart::getIsPay, 0)
|
||||
.eq(Cart::getSelected, 1)
|
||||
.set(Cart::getSelected, 0)
|
||||
);
|
||||
return success("修改成功", computeCart(param));
|
||||
}
|
||||
|
||||
|
||||
// @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) {
|
||||
@@ -256,8 +53,12 @@ public class CartController extends BaseController {
|
||||
|
||||
@ApiOperation("查询全部购物车")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Cart>> list(CartParam param) {
|
||||
// 使用关联查询
|
||||
public ApiResult<CartVo> list(CartParam param) {
|
||||
if (ObjectUtil.isEmpty(getLoginUser())) {
|
||||
return success("请先登录",null);
|
||||
}
|
||||
// 附加用户ID
|
||||
param.setUserId(getLoginUserId());
|
||||
return success(cartService.listRel(param));
|
||||
}
|
||||
|
||||
@@ -269,6 +70,43 @@ public class CartController extends BaseController {
|
||||
return success(cartService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@ApiOperation("添加购物车")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Cart cart) {
|
||||
if (ObjectUtil.isEmpty(getLoginUser())) {
|
||||
return success("请先登录",null);
|
||||
}
|
||||
|
||||
// 修正用户ID
|
||||
cart.setUserId(getLoginUserId());
|
||||
// 修正购买数量
|
||||
if (ObjectUtil.isEmpty(cart.getCartNum())) {
|
||||
cart.setCartNum(1);
|
||||
}
|
||||
// 超出最大限制
|
||||
if (cartService.count(new LambdaUpdateWrapper<Cart>().eq(Cart::getUserId,getLoginUserId())) > 50) {
|
||||
return fail("购物车宝贝数量已满,建议您先去结算或清理~");
|
||||
}
|
||||
|
||||
if (cartService.save(cart)) {
|
||||
return success("添加成功",cart.getId());
|
||||
}
|
||||
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@ApiOperation("修改购物车")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Cart cart) {
|
||||
if (cartService.updateById(cart)) {
|
||||
final CartParam param = new CartParam();
|
||||
param.setType(cart.getType());
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:cart:remove')")
|
||||
@ApiOperation("删除购物车")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
@@ -278,6 +116,7 @@ public class CartController extends BaseController {
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:cart:save')")
|
||||
@ApiOperation("批量添加购物车")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Cart> list) {
|
||||
@@ -287,6 +126,7 @@ public class CartController extends BaseController {
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:cart:update')")
|
||||
@ApiOperation("批量修改购物车")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Cart> batchParam) {
|
||||
@@ -296,6 +136,7 @@ public class CartController extends BaseController {
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:cart:remove')")
|
||||
@ApiOperation("批量删除购物车")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
@@ -305,4 +146,126 @@ public class CartController extends BaseController {
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@ApiOperation("全选操作")
|
||||
@PutMapping("/onSelectAll/{yes}")
|
||||
public ApiResult<?> onSelectAll(@PathVariable("yes") Boolean yes) {
|
||||
if (ObjectUtil.isEmpty(getLoginUser())) {
|
||||
return success("请先登录",null);
|
||||
}
|
||||
final List<Cart> carts = cartService.list(new LambdaUpdateWrapper<Cart>()
|
||||
.eq(Cart::getSelected,!yes)
|
||||
.eq(Cart::getUserId, getLoginUserId()));
|
||||
carts.forEach(d -> {
|
||||
d.setSelected(yes);
|
||||
});
|
||||
return success("修改成功", cartService.updateBatchById(carts));
|
||||
}
|
||||
|
||||
|
||||
// @ApiOperation("我的购物车")
|
||||
// @GetMapping("/myCart")
|
||||
// public ApiResult<?> myCart(CartParam param) {
|
||||
// // 记录当前登录用户id
|
||||
// User loginUser = getLoginUser();
|
||||
// if (loginUser == null) {
|
||||
// return success("请先登录", null);
|
||||
// }
|
||||
//
|
||||
//// if (param.getIsNew() == null) {
|
||||
//// param.setIsNew(false);
|
||||
//// }
|
||||
//
|
||||
// HashMap<String, Object> map = computeCart(param);
|
||||
// System.out.println("map = " + map);
|
||||
//
|
||||
// // 查询购物车
|
||||
// param.setUserId(loginUser.getUserId());
|
||||
// final List<Cart> carts = cartService.listRelMpj(param);
|
||||
// System.out.println("carts3 = " + carts);
|
||||
//
|
||||
// // 收集店铺ID
|
||||
// final Set<Integer> merchantIds = carts.stream().map(Cart::getMerchantId).collect(Collectors.toSet());
|
||||
// if (CollectionUtils.isEmpty(merchantIds)) {
|
||||
// map.put("selectAll", false);
|
||||
// return success(map);
|
||||
// }
|
||||
//
|
||||
// // 查询店铺列
|
||||
// final List<Merchant> merchants = merchantService.list(new LambdaQueryWrapper<Merchant>()
|
||||
// .select(Merchant::getMerchantId, Merchant::getMerchantName, Merchant::getImage, Merchant::getShopType, Merchant::getAddress)
|
||||
// .in(Merchant::getMerchantId, merchantIds));
|
||||
//
|
||||
// // 返回空列表
|
||||
// if (CollectionUtils.isEmpty(merchants)) {
|
||||
// map.put("merchants", merchants);
|
||||
// return success(map);
|
||||
// }
|
||||
//
|
||||
// final Map<Integer, List<Cart>> collect = carts.stream().collect(Collectors.groupingBy(Cart::getMerchantId));
|
||||
//
|
||||
// // 封装数据
|
||||
// merchants.forEach(d -> {
|
||||
// d.setCarts(collect.get(d.getMerchantId()));
|
||||
// });
|
||||
//
|
||||
// // 计算购物车金额
|
||||
// map.put("merchants", merchants);
|
||||
//
|
||||
// return success(map);
|
||||
// }
|
||||
|
||||
|
||||
// @ApiOperation("计算购物车金额")
|
||||
// @GetMapping("/count")
|
||||
// public HashMap<String, Object> computeCart(CartParam param) {
|
||||
// final LambdaQueryWrapper<Cart> queryWrapper = new LambdaQueryWrapper<>();
|
||||
//
|
||||
// queryWrapper.select(Cart::getId, Cart::getPrice, Cart::getCartNum)
|
||||
// .eq(Cart::getUserId, getLoginUserId())
|
||||
// .eq(Cart::getType, param.getType())
|
||||
// .eq(Cart::getSelected, param.getSelected())
|
||||
// .eq(Cart::getIsPay, param.getIsPay())
|
||||
// .eq(Cart::getIsNew,param.getIsNew())
|
||||
// .eq(Cart::getId,param.getId());
|
||||
//
|
||||
//// if (param.getId() != null) {
|
||||
//// queryWrapper.eq(Cart::getId,param.getId());
|
||||
//// }
|
||||
//// if(param.getIsNew() != null){
|
||||
//// queryWrapper.eq(Cart::getIsNew,param.getIsNew());
|
||||
//// }
|
||||
//
|
||||
// // 查询购物车数据
|
||||
// final List<Cart> carts = cartService.list(queryWrapper);
|
||||
// System.out.println("carts2 = " + carts);
|
||||
//
|
||||
// // 计算单品合计价格
|
||||
// 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;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
package com.gxwebsoft.shop.controller;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.shop.service.CountService;
|
||||
import com.gxwebsoft.shop.entity.Count;
|
||||
import com.gxwebsoft.shop.param.CountParam;
|
||||
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 io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商城销售统计表控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-07-31 22:25:10
|
||||
*/
|
||||
@Api(tags = "商城销售统计表管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/shop/count")
|
||||
public class CountController extends BaseController {
|
||||
@Resource
|
||||
private CountService countService;
|
||||
|
||||
@ApiOperation("分页查询商城销售统计表")
|
||||
@GetMapping("/data")
|
||||
public ApiResult<?> data(CountParam param) {
|
||||
final DateTime dateTime = DateUtil.offsetDay(DateUtil.date(), 1);
|
||||
System.out.println("dateTime = " + dateTime);
|
||||
|
||||
final DateTime dateTime2 = DateUtil.offsetDay(DateUtil.date(), -1);
|
||||
System.out.println("dateTime2 = " + dateTime2);
|
||||
final DateTime dateTime3 = DateUtil.offsetDay(DateUtil.date(), -2);
|
||||
System.out.println("dateTime3 = " + dateTime3);
|
||||
return success(countService.list(new LambdaQueryWrapper<Count>().ge(Count::getDateTime, dateTime3).last("limit 2")));
|
||||
}
|
||||
|
||||
@ApiOperation("分页查询商城销售统计表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Count>> page(CountParam param) {
|
||||
// 使用关联查询
|
||||
return success(countService.pageRel(param));
|
||||
}
|
||||
|
||||
@ApiOperation("查询全部商城销售统计表")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Count>> list(CountParam param) {
|
||||
// 使用关联查询
|
||||
return success(countService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('shop:count:list')")
|
||||
@ApiOperation("根据id查询商城销售统计表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Count> get(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
return success(countService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@ApiOperation("添加商城销售统计表")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Count count) {
|
||||
if (countService.save(count)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@ApiOperation("修改商城销售统计表")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Count count) {
|
||||
if (countService.updateById(count)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@ApiOperation("删除商城销售统计表")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (countService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@ApiOperation("批量添加商城销售统计表")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Count> list) {
|
||||
if (countService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@ApiOperation("批量修改商城销售统计表")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Count> batchParam) {
|
||||
if (batchParam.update(countService, "id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@ApiOperation("批量删除商城销售统计表")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (countService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -221,40 +221,14 @@ 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());
|
||||
// });
|
||||
|
||||
// 从购物车获取订单数据
|
||||
final CartParam cartParam = new CartParam();
|
||||
cartParam.setUserId(loginUser.getUserId());
|
||||
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);
|
||||
}
|
||||
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());
|
||||
});
|
||||
orderGoodsService.saveBatch(order.getGoodsList());
|
||||
}
|
||||
// 预定订单
|
||||
@@ -314,6 +288,10 @@ public class OrderController extends BaseController {
|
||||
// TODO 余额支付
|
||||
if (order.getPayType().equals(0)) {
|
||||
order.setAccessToken(order.getAccessToken());
|
||||
final User loginUser = order.getLoginUser();
|
||||
if (loginUser.getBalance().compareTo(order.getTotalPrice()) < 0) {
|
||||
throw new BusinessException("余额不足");
|
||||
}
|
||||
return success("下单成功", requestUtil.balancePay(order));
|
||||
}
|
||||
|
||||
|
||||
@@ -7,10 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.shop.entity.Goods;
|
||||
import com.gxwebsoft.shop.entity.Order;
|
||||
import com.gxwebsoft.shop.entity.OrderGoods;
|
||||
import com.gxwebsoft.shop.entity.OrderInfo;
|
||||
import com.gxwebsoft.shop.entity.*;
|
||||
import com.gxwebsoft.shop.service.*;
|
||||
import com.wechat.pay.java.service.partnerpayments.jsapi.model.Transaction;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -47,6 +44,8 @@ public class WxPayNotifyNbgController extends BaseController {
|
||||
private GoodsService goodsService;
|
||||
@Resource
|
||||
private UsersService usersService;
|
||||
@Resource
|
||||
private CartService cartService;
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@@ -94,6 +93,10 @@ public class WxPayNotifyNbgController extends BaseController {
|
||||
// TODO 3.2 更新订单类型为预定的关联订单信息
|
||||
}
|
||||
|
||||
// TODO 4. 清除购物车
|
||||
final boolean remove = cartService.remove(new LambdaQueryWrapper<Cart>().eq(Cart::getUserId, order.getUserId()).eq(Cart::getIsNew, true));
|
||||
System.out.println("remove = " + remove);
|
||||
|
||||
|
||||
// TODO 5.累计会员积分
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
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.LocalDateTime;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 商城销售统计表
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-07-31 22:25:10
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value = "Count对象", description = "商城销售统计表")
|
||||
@TableName("shop_count")
|
||||
public class Count implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "ID")
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "统计日期")
|
||||
private String dateTime;
|
||||
|
||||
@ApiModelProperty(value = "总销售额")
|
||||
private BigDecimal totalPrice;
|
||||
|
||||
@ApiModelProperty(value = "今日销售额")
|
||||
private BigDecimal todayPrice;
|
||||
|
||||
@ApiModelProperty(value = "总会员数")
|
||||
private BigDecimal totalUsers;
|
||||
|
||||
@ApiModelProperty(value = "今日新增")
|
||||
private BigDecimal todayUsers;
|
||||
|
||||
@ApiModelProperty(value = "总订单笔数")
|
||||
private BigDecimal totalOrders;
|
||||
|
||||
@ApiModelProperty(value = "今日订单笔数")
|
||||
private BigDecimal todayOrders;
|
||||
|
||||
@ApiModelProperty(value = "备注")
|
||||
private String comments;
|
||||
|
||||
@ApiModelProperty(value = "状态, 0正常, 1冻结")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "租户id")
|
||||
private Integer tenantId;
|
||||
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.gxwebsoft.shop.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.gxwebsoft.shop.entity.Count;
|
||||
import com.gxwebsoft.shop.param.CountParam;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商城销售统计表Mapper
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-07-31 22:25:10
|
||||
*/
|
||||
public interface CountMapper extends BaseMapper<Count> {
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param param 查询参数
|
||||
* @return List<Count>
|
||||
*/
|
||||
List<Count> selectPageRel(@Param("page") IPage<Count> page,
|
||||
@Param("param") CountParam param);
|
||||
|
||||
/**
|
||||
* 查询全部
|
||||
*
|
||||
* @param param 查询参数
|
||||
* @return List<User>
|
||||
*/
|
||||
List<Count> selectListRel(@Param("param") CountParam param);
|
||||
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
SELECT a.*,b.goods_name,b.image,c.merchant_name,c.address
|
||||
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
|
||||
LEFT JOIN shop_merchant c ON a.merchant_id = c.merchant_id
|
||||
<where>
|
||||
<if test="param.id != null">
|
||||
AND a.id = #{param.id}
|
||||
@@ -45,13 +45,6 @@
|
||||
<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>
|
||||
@@ -59,7 +52,7 @@
|
||||
AND a.create_time <= #{param.createTimeEnd}
|
||||
</if>
|
||||
<if test="param.keywords != null">
|
||||
AND (a.comments LIKE CONCAT('%', #{param.keywords}, '%')
|
||||
AND (c.merchant_name LIKE CONCAT('%', #{param.keywords}, '%')
|
||||
OR b.goods_name LIKE CONCAT('%', #{param.keywords}, '%')
|
||||
)
|
||||
</if>
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
<?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.CountMapper">
|
||||
|
||||
<!-- 关联查询sql -->
|
||||
<sql id="selectSql">
|
||||
SELECT a.*
|
||||
FROM shop_count a
|
||||
<where>
|
||||
<if test="param.id != null">
|
||||
AND a.id = #{param.id}
|
||||
</if>
|
||||
<if test="param.dateTime != null">
|
||||
AND a.date_time LIKE CONCAT('%', #{param.dateTime}, '%')
|
||||
</if>
|
||||
<if test="param.totalPrice != null">
|
||||
AND a.total_price = #{param.totalPrice}
|
||||
</if>
|
||||
<if test="param.todayPrice != null">
|
||||
AND a.today_price = #{param.todayPrice}
|
||||
</if>
|
||||
<if test="param.totalUsers != null">
|
||||
AND a.total_users = #{param.totalUsers}
|
||||
</if>
|
||||
<if test="param.todayUsers != null">
|
||||
AND a.today_users = #{param.todayUsers}
|
||||
</if>
|
||||
<if test="param.totalOrders != null">
|
||||
AND a.total_orders = #{param.totalOrders}
|
||||
</if>
|
||||
<if test="param.todayOrders != null">
|
||||
AND a.today_orders = #{param.todayOrders}
|
||||
</if>
|
||||
<if test="param.comments != null">
|
||||
AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
|
||||
</if>
|
||||
<if test="param.status != null">
|
||||
AND a.status = #{param.status}
|
||||
</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}, '%')
|
||||
)
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- 分页查询 -->
|
||||
<select id="selectPageRel" resultType="com.gxwebsoft.shop.entity.Count">
|
||||
<include refid="selectSql"></include>
|
||||
</select>
|
||||
|
||||
<!-- 查询全部 -->
|
||||
<select id="selectListRel" resultType="com.gxwebsoft.shop.entity.Count">
|
||||
<include refid="selectSql"></include>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -76,10 +76,6 @@ public class CartParam extends BaseParam {
|
||||
@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,64 @@
|
||||
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 lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 商城销售统计表查询参数
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-07-31 22:25:10
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@ApiModel(value = "CountParam对象", description = "商城销售统计表查询参数")
|
||||
public class CountParam extends BaseParam {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "ID")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "统计日期")
|
||||
private String dateTime;
|
||||
|
||||
@ApiModelProperty(value = "总销售额")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private BigDecimal totalPrice;
|
||||
|
||||
@ApiModelProperty(value = "今日销售额")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private BigDecimal todayPrice;
|
||||
|
||||
@ApiModelProperty(value = "总会员数")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private BigDecimal totalUsers;
|
||||
|
||||
@ApiModelProperty(value = "今日新增")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private BigDecimal todayUsers;
|
||||
|
||||
@ApiModelProperty(value = "总订单笔数")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private BigDecimal totalOrders;
|
||||
|
||||
@ApiModelProperty(value = "今日订单笔数")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private BigDecimal todayOrders;
|
||||
|
||||
@ApiModelProperty(value = "备注")
|
||||
private String comments;
|
||||
|
||||
@ApiModelProperty(value = "状态, 0正常, 1冻结")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -112,4 +112,5 @@ public class MerchantParam extends BaseParam {
|
||||
@ApiModelProperty(value = "商户编号集合")
|
||||
@TableField(exist = false)
|
||||
private Set<String> merchantCodes;
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ 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 com.gxwebsoft.shop.vo.CartVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -29,7 +30,7 @@ public interface CartService extends IService<Cart> {
|
||||
* @param param 查询参数
|
||||
* @return List<Cart>
|
||||
*/
|
||||
List<Cart> listRel(CartParam param);
|
||||
CartVo listRel(CartParam param);
|
||||
|
||||
/**
|
||||
* 根据id查询
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.gxwebsoft.shop.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.shop.entity.Count;
|
||||
import com.gxwebsoft.shop.param.CountParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商城销售统计表Service
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-07-31 22:25:10
|
||||
*/
|
||||
public interface CountService extends IService<Count> {
|
||||
|
||||
/**
|
||||
* 分页关联查询
|
||||
*
|
||||
* @param param 查询参数
|
||||
* @return PageResult<Count>
|
||||
*/
|
||||
PageResult<Count> pageRel(CountParam param);
|
||||
|
||||
/**
|
||||
* 关联查询全部
|
||||
*
|
||||
* @param param 查询参数
|
||||
* @return List<Count>
|
||||
*/
|
||||
List<Count> listRel(CountParam param);
|
||||
|
||||
/**
|
||||
* 根据id查询
|
||||
*
|
||||
* @param id ID
|
||||
* @return Count
|
||||
*/
|
||||
Count getByIdRel(Integer id);
|
||||
|
||||
}
|
||||
@@ -1,7 +1,12 @@
|
||||
package com.gxwebsoft.shop.service.impl;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.gxwebsoft.common.system.entity.Dict;
|
||||
import com.gxwebsoft.common.system.entity.DictData;
|
||||
import com.gxwebsoft.shop.entity.Goods;
|
||||
import com.gxwebsoft.shop.entity.GoodsSpec;
|
||||
import com.gxwebsoft.shop.mapper.CartMapper;
|
||||
@@ -10,11 +15,15 @@ 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 com.gxwebsoft.shop.vo.CartShopVo;
|
||||
import com.gxwebsoft.shop.vo.CartVo;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* 购物车Service实现
|
||||
@@ -34,12 +43,48 @@ public class CartServiceImpl extends ServiceImpl<CartMapper, Cart> implements Ca
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Cart> listRel(CartParam param) {
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public CartVo listRel(CartParam param) {
|
||||
List<Cart> list = baseMapper.selectListRel(param);
|
||||
// 排序
|
||||
PageParam<Cart, CartParam> page = new PageParam<>();
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return page.sortRecords(list);
|
||||
final List<Cart> carts = page.sortRecords(list);
|
||||
System.out.println("carts = " + carts.size());
|
||||
// 整理数据
|
||||
final CartVo vo = new CartVo();
|
||||
// 计算单品总价
|
||||
for (Cart cart : carts) {
|
||||
cart.setTotalPrice(cart.getPrice().multiply(BigDecimal.valueOf(cart.getCartNum())));
|
||||
}
|
||||
// 计算购物车金额
|
||||
final Integer cartNum = carts.stream().map(Cart::getCartNum).reduce(Integer::sum).orElse(0);
|
||||
final Integer selectNums = carts.stream().filter(d -> d.getSelected().equals(true)).map(Cart::getCartNum).reduce(Integer::sum).orElse(0);
|
||||
final BigDecimal totalPrice = carts.stream().filter(d -> d.getSelected().equals(true)).map(Cart::getTotalPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
// 按店铺ID分组
|
||||
final Map<Integer, List<Cart>> collectCart = carts.stream().collect(Collectors.groupingBy(Cart::getMerchantId));
|
||||
final ArrayList<CartShopVo> shops = new ArrayList<>();
|
||||
if (MapUtil.isNotEmpty(collectCart)) {
|
||||
for (Integer shopId : collectCart.keySet()) {
|
||||
final CartShopVo shopVo = new CartShopVo();
|
||||
shopVo.setShopId(shopId);
|
||||
shopVo.setCarts(collectCart.get(shopId));
|
||||
if (ObjectUtil.isNotEmpty(collectCart.get(shopId).get(0))) {
|
||||
final Cart cart = collectCart.get(shopId).get(0);
|
||||
shopVo.setShopName(cart.getMerchantName());
|
||||
shopVo.setShopLogo(cart.getImage());
|
||||
}
|
||||
shops.add(shopVo);
|
||||
}
|
||||
}
|
||||
|
||||
vo.setShops(shops);
|
||||
vo.setTotalPrice(totalPrice);
|
||||
vo.setTotalNums(Long.valueOf(cartNum));
|
||||
vo.setSelectNums(Long.valueOf(selectNums));
|
||||
// updateBatchById(carts);
|
||||
|
||||
return vo;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -52,7 +97,6 @@ public class CartServiceImpl extends ServiceImpl<CartMapper, Cart> implements Ca
|
||||
@Override
|
||||
public List<Cart> listRelMpj(CartParam param) {
|
||||
|
||||
System.out.println("userId = " + param.getUserId());
|
||||
// 多表查询
|
||||
MPJLambdaWrapper<Cart> mpjLambdaWrapper = new MPJLambdaWrapper<>();
|
||||
mpjLambdaWrapper.selectAll(Cart.class)
|
||||
@@ -60,16 +104,23 @@ public class CartServiceImpl extends ServiceImpl<CartMapper, Cart> implements Ca
|
||||
.select(Goods::getImage)
|
||||
.leftJoin(Goods.class,Goods::getGoodsId,Cart::getGoodsId).eq(Cart::getUserId,param.getUserId());
|
||||
|
||||
// 查询选中状态
|
||||
if(param.getSelected() != null){
|
||||
mpjLambdaWrapper.eq(Cart::getSelected,param.getSelected());
|
||||
mpjLambdaWrapper.eq(Cart::getSelected, param.getSelected());
|
||||
}
|
||||
// 商品类型 0商城 1预定
|
||||
if(param.getType() != null){
|
||||
mpjLambdaWrapper.eq(Cart::getType,param.getType());
|
||||
}
|
||||
// 是否为立即购买
|
||||
if(param.getIsNew() != null){
|
||||
mpjLambdaWrapper.eq(Cart::getIsNew,param.getIsNew());
|
||||
}
|
||||
|
||||
// 指定cartId
|
||||
if(param.getId() != null){
|
||||
mpjLambdaWrapper.eq(Cart::getId,param.getId());
|
||||
}
|
||||
System.out.println("mpjLambdaWrapper = " + mpjLambdaWrapper);
|
||||
return baseMapper.selectJoinList(Cart.class, mpjLambdaWrapper);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.gxwebsoft.shop.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.gxwebsoft.shop.mapper.CountMapper;
|
||||
import com.gxwebsoft.shop.service.CountService;
|
||||
import com.gxwebsoft.shop.entity.Count;
|
||||
import com.gxwebsoft.shop.param.CountParam;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商城销售统计表Service实现
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-07-31 22:25:10
|
||||
*/
|
||||
@Service
|
||||
public class CountServiceImpl extends ServiceImpl<CountMapper, Count> implements CountService {
|
||||
|
||||
@Override
|
||||
public PageResult<Count> pageRel(CountParam param) {
|
||||
PageParam<Count, CountParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
List<Count> list = baseMapper.selectPageRel(page, param);
|
||||
return new PageResult<>(list, page.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Count> listRel(CountParam param) {
|
||||
List<Count> list = baseMapper.selectListRel(param);
|
||||
// 排序
|
||||
PageParam<Count, CountParam> page = new PageParam<>();
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return page.sortRecords(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Count getByIdRel(Integer id) {
|
||||
CountParam param = new CountParam();
|
||||
param.setId(id);
|
||||
return param.getOne(baseMapper.selectListRel(param));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,12 +24,15 @@ public class CartShopVo implements Serializable {
|
||||
@ApiModelProperty("店铺名称")
|
||||
private String shopName;
|
||||
|
||||
@ApiModelProperty(value = "店铺图标")
|
||||
private String shopLogo;
|
||||
|
||||
@ApiModelProperty(value = "商品列表")
|
||||
private List<Goods> goods;
|
||||
private List<Cart> carts;
|
||||
@Data
|
||||
public static class Payload {
|
||||
private Integer shopId;
|
||||
private Integer shopName;
|
||||
private List<Goods> goods;
|
||||
private List<Cart> carts;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.gxwebsoft.shop.vo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.gxwebsoft.shop.entity.Cart;
|
||||
import com.gxwebsoft.shop.entity.Merchant;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Builder;
|
||||
@@ -9,6 +10,7 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@@ -17,14 +19,23 @@ import java.util.List;
|
||||
@TableName("shop_cart")
|
||||
public class CartVo implements Serializable {
|
||||
|
||||
@ApiModelProperty("宝贝数量")
|
||||
private Long count;
|
||||
|
||||
@ApiModelProperty("店铺列表")
|
||||
private List<CartShopVo> shops;
|
||||
|
||||
@ApiModelProperty(value = "购物车总金额")
|
||||
private BigDecimal totalPrice;
|
||||
|
||||
@ApiModelProperty(value = "宝贝数量")
|
||||
private Long totalNums;
|
||||
|
||||
@ApiModelProperty(value = "已选中宝贝")
|
||||
private Long selectNums;
|
||||
|
||||
@Data
|
||||
public static class Payload {
|
||||
private Integer count;
|
||||
private Integer shops;
|
||||
private List<CartShopVo> shops;
|
||||
private BigDecimal totalPrice;
|
||||
private Long totalNums;
|
||||
private Long selectNums;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user