新增功能:收银台

This commit is contained in:
2024-08-05 01:30:24 +08:00
parent d235907508
commit 6814d7ed9f
19 changed files with 814 additions and 143 deletions
@@ -7,6 +7,7 @@ import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.common.core.web.BatchParam;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.system.entity.Role;
import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.shop.entity.Cart;
import com.gxwebsoft.shop.entity.Merchant;
@@ -23,10 +24,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -76,7 +74,6 @@ public class CartController extends BaseController {
if (ObjectUtil.isEmpty(getLoginUser())) {
return success("请先登录",null);
}
// 修正用户ID
cart.setUserId(getLoginUserId());
// 修正购买数量
@@ -87,7 +84,17 @@ public class CartController extends BaseController {
if (cartService.count(new LambdaUpdateWrapper<Cart>().eq(Cart::getUserId,getLoginUserId())) > 50) {
return fail("购物车宝贝数量已满,建议您先去结算或清理~");
}
// 重复商品叠加数量
final Cart one = cartService.getOne(new LambdaQueryWrapper<Cart>()
.eq(Cart::getUserId, getLoginUserId())
.eq(Cart::getGoodsId,cart.getGoodsId())
.eq(Cart::getSpec,cart.getSpec())
.last("limit 1"));
if(ObjectUtil.isNotEmpty(one)){
one.setCartNum(cart.getCartNum()+1);
cartService.updateById(one);
return success("更新成功",one.getId());
}
if (cartService.save(cart)) {
return success("添加成功",cart.getId());
}
@@ -161,111 +168,26 @@ public class CartController extends BaseController {
return success("修改成功", cartService.updateBatchById(carts));
}
@ApiOperation("增加数量")
@PutMapping("/addCartNum")
public ApiResult<?> addCartNum(@RequestBody Cart cart) {
if (ObjectUtil.isEmpty(getLoginUser())) {
return success("请先登录",null);
}
cart.setCartNum(cart.getCartNum()+1);
cartService.updateById(cart);
return success("操作成功");
}
// @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;
// }
@ApiOperation("减少数量")
@PutMapping("/subCartNum")
public ApiResult<?> subCartNum(@RequestBody Cart cart) {
if (ObjectUtil.isEmpty(getLoginUser())) {
return success("请先登录",null);
}
cart.setCartNum(cart.getCartNum()-1);
cartService.updateById(cart);
return success("操作成功");
}
}
@@ -0,0 +1,227 @@
package com.gxwebsoft.shop.controller;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.gxwebsoft.common.core.utils.CommonUtil;
import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.common.system.entity.Role;
import com.gxwebsoft.shop.entity.Cart;
import com.gxwebsoft.shop.service.CashierService;
import com.gxwebsoft.shop.entity.Cashier;
import com.gxwebsoft.shop.param.CashierParam;
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.vo.CashierVo;
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.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
/**
* 收银控制器
*
* @author 科技小王子
* @since 2024-08-04 11:51:43
*/
@Api(tags = "收银管理")
@RestController
@RequestMapping("/api/shop/cashier")
public class CashierController extends BaseController {
@Resource
private CashierService cashierService;
@ApiOperation("分页查询收银")
@GetMapping("/page")
public ApiResult<PageResult<Cashier>> page(CashierParam param) {
// 使用关联查询
return success(cashierService.pageRel(param));
}
@ApiOperation("查询全部收银")
@GetMapping()
public ApiResult<CashierVo> list(CashierParam param) {
if (ObjectUtil.isEmpty(getLoginUser())) {
return success("请先登录",null);
}
// 附加收银员ID
param.setCashierId(getLoginUserId());
// 收银员ID
// final Set<String> collect = getLoginUser().getRoles().stream().map(Role::getRoleCode).collect(Collectors.toSet());
// if (!collect.contains("merchantClerk")) {
// return fail("这个账户没有收银权限",null);
// }
return success(cashierService.listRel(param));
}
@ApiOperation("按groupId分组查询全部收银")
@GetMapping("/listByGroupId")
public ApiResult<List<CashierVo>> listByGroupId(CashierParam param) {
if (ObjectUtil.isEmpty(getLoginUser())) {
return success("请先登录",null);
}
// 附加收银员ID
param.setCashierId(getLoginUserId());
// 收银员ID
return success(cashierService.listRelByGroupId(param));
}
@PreAuthorize("hasAuthority('shop:cashier:list')")
@ApiOperation("根据id查询收银")
@GetMapping("/{id}")
public ApiResult<Cashier> get(@PathVariable("id") Integer id) {
// 使用关联查询
return success(cashierService.getByIdRel(id));
}
@ApiOperation("添加收银")
@PostMapping()
public ApiResult<?> save(@RequestBody Cashier cashier) {
if (ObjectUtil.isEmpty(getLoginUser())) {
return success("请先登录",null);
}
cashier.setCashierId(getLoginUserId());
// 修正购买数量
if (ObjectUtil.isEmpty(cashier.getCartNum())) {
cashier.setCartNum(1);
}
// 超出最大限制
if (cashierService.count(new LambdaUpdateWrapper<Cashier>().eq(Cashier::getCashierId,getLoginUserId())) > 50) {
return fail("购物车宝贝数量已满,建议您先去结算或清理~");
}
// 重复商品叠加数量
final Cashier one = cashierService.getOne(new LambdaQueryWrapper<Cashier>()
.eq(Cashier::getCashierId,getLoginUserId())
.eq(Cashier::getGoodsId,cashier.getGoodsId())
.eq(Cashier::getSpec,cashier.getSpec())
.eq(Cashier::getGroupId,0)
.last("limit 1"));
if(ObjectUtil.isNotEmpty(one)){
return fail("请勿重复添加");
}
if (cashierService.save(cashier)) {
return success("添加成功");
}
return fail("添加失败");
}
@ApiOperation("修改收银")
@PutMapping()
public ApiResult<?> update(@RequestBody Cashier cashier) {
if (cashierService.updateById(cashier)) {
return success("修改成功");
}
return fail("修改失败");
}
@ApiOperation("删除收银")
@DeleteMapping("/{id}")
public ApiResult<?> remove(@PathVariable("id") Integer id) {
if (cashierService.removeById(id)) {
return success("删除成功");
}
return fail("删除失败");
}
@ApiOperation("批量添加收银")
@PostMapping("/batch")
public ApiResult<?> saveBatch(@RequestBody List<Cashier> list) {
if (cashierService.saveBatch(list)) {
return success("添加成功");
}
return fail("添加失败");
}
@ApiOperation("批量修改收银")
@PutMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody BatchParam<Cashier> batchParam) {
if (batchParam.update(cashierService, "id")) {
return success("修改成功");
}
return fail("修改失败");
}
@ApiOperation("批量删除收银")
@DeleteMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
if (cashierService.removeByIds(ids)) {
return success("删除成功");
}
return fail("删除失败");
}
@ApiOperation("增加数量")
@PutMapping("/addCartNum")
public ApiResult<?> addCartNum(@RequestBody Cashier cashier) {
if (ObjectUtil.isEmpty(getLoginUser())) {
return success("请先登录",null);
}
cashier.setCartNum(cashier.getCartNum()+1);
cashierService.updateById(cashier);
return success("操作成功");
}
@ApiOperation("减少数量")
@PutMapping("/subCartNum")
public ApiResult<?> subCartNum(@RequestBody Cashier cashier) {
if (ObjectUtil.isEmpty(getLoginUser())) {
return success("请先登录",null);
}
cashier.setCartNum(cashier.getCartNum()-1);
cashierService.updateById(cashier);
return success("操作成功");
}
@ApiOperation("清空")
@PutMapping("/cearCartNum")
public ApiResult<?> removeCartNum(@RequestBody Cashier cashier) {
if (ObjectUtil.isEmpty(getLoginUser())) {
return success("请先登录",null);
}
cashier.setCartNum(cashier.getCartNum()-1);
cashierService.updateById(cashier);
return success("操作成功");
}
@ApiOperation("挂单")
@PutMapping("/packCashier")
public ApiResult<?> packCashier() {
if (ObjectUtil.isEmpty(getLoginUser())) {
return success("请先登录",null);
}
final int groupId = Integer.parseInt(getLoginUserId().toString() + RandomUtil.randomInt(1, 100));
final boolean update = cashierService.update(new LambdaUpdateWrapper<Cashier>().eq(Cashier::getGroupId, 0).eq(Cashier::getCashierId, getLoginUserId()).set(Cashier::getGroupId, groupId));
return success("操作成功",update);
}
@ApiOperation("取单")
@PutMapping("/getByGroup/{id}")
public ApiResult<?> getByGroup(@PathVariable("id") Integer id) {
if (cashierService.update(new LambdaUpdateWrapper<Cashier>().eq(Cashier::getGroupId,id).set(Cashier::getGroupId,0))) {
return success("删除成功");
}
return fail("删除失败");
}
@ApiOperation("删除整单")
@DeleteMapping("/removeByGroup/{id}")
public ApiResult<?> removeByGroup(@PathVariable("id") Integer id) {
if (cashierService.remove(new LambdaQueryWrapper<Cashier>().eq(Cashier::getGroupId,id))) {
return success("删除成功");
}
return fail("删除失败");
}
}
@@ -1,23 +1,21 @@
package com.gxwebsoft.shop.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.gxwebsoft.cms.entity.Navigation;
import com.gxwebsoft.common.core.utils.JSONUtil;
import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.common.core.web.BatchParam;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.shop.entity.*;
import com.gxwebsoft.shop.entity.Goods;
import com.gxwebsoft.shop.entity.GoodsCategory;
import com.gxwebsoft.shop.entity.GoodsSpec;
import com.gxwebsoft.shop.param.GoodsCategoryParam;
import com.gxwebsoft.shop.param.GoodsSpecParam;
import com.gxwebsoft.shop.service.GoodsCategoryService;
import com.gxwebsoft.shop.service.GoodsService;
import com.gxwebsoft.shop.service.GoodsSpecService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
@@ -3,19 +3,16 @@ 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.utils.JSONUtil;
import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.shop.entity.GoodsSku;
import com.gxwebsoft.shop.entity.GoodsSkuVO;
import com.gxwebsoft.shop.entity.GoodsSpec;
import com.gxwebsoft.shop.service.GoodsService;
import com.gxwebsoft.shop.entity.Goods;
import com.gxwebsoft.shop.param.GoodsParam;
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.BaseController;
import com.gxwebsoft.common.core.web.BatchParam;
import com.gxwebsoft.common.core.annotation.OperationLog;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.shop.entity.Goods;
import com.gxwebsoft.shop.entity.GoodsSku;
import com.gxwebsoft.shop.entity.GoodsSpec;
import com.gxwebsoft.shop.param.GoodsParam;
import com.gxwebsoft.shop.service.GoodsService;
import com.gxwebsoft.shop.service.GoodsSkuService;
import com.gxwebsoft.shop.service.GoodsSpecService;
import io.swagger.annotations.Api;
@@ -80,6 +77,7 @@ public class GoodsController extends BaseController {
@GetMapping("/page")
public ApiResult<PageResult<Goods>> page(GoodsParam param) {
// 使用关联查询
System.out.println("param = " + param);
return success(goodsService.pageRel(param));
}
@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
@@ -154,19 +155,22 @@ public class OrderController extends BaseController {
@PostMapping()
public ApiResult<?> save(@RequestBody Order order, HttpServletRequest request) {
String access_token = JwtUtil.getAccessToken(request);
// 记录当前登录用户id
User loginUser = getLoginUser();
if (loginUser == null) {
if (ObjectUtil.isEmpty(loginUser)) {
return fail("请先登录");
}
// 微信openid(必填)
if (StrUtil.isBlank(loginUser.getOpenid())) {
if (order.getType().equals(1) && StrUtil.isBlank(loginUser.getOpenid())) {
return fail("微信openid(必填)");
}
// 商品描述(必填)
if (StrUtil.isBlank(order.getComments())) {
return fail("商品描述(必填)");
}
// 判断场地是否被抢占
if (order.getType().equals(1)) {
order.getOrderInfo().forEach(d -> {
@@ -181,11 +185,11 @@ public class OrderController extends BaseController {
}
}
// 微信支付(商品金额不能为0)
// if (order.getPayType().equals(1)) {
// if (order.getTotalPrice().compareTo(BigDecimal.ZERO) == 0) {
// return fail("商品金额不能为0");
// }
// }
if (order.getPayType().equals(1)) {
if (order.getTotalPrice().compareTo(BigDecimal.ZERO) == 0) {
return fail("商品金额不能为0");
}
}
// 已下过订单
if(order.getOrderId() != null){
@@ -0,0 +1,97 @@
package com.gxwebsoft.shop.entity;
import java.math.BigDecimal;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
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-08-04 11:51:43
*/
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "Cashier对象", description = "收银")
@TableName("shop_cashier")
public class Cashier implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "收银单ID")
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
@ApiModelProperty(value = "类型 0商城 1外卖")
private Integer type;
@ApiModelProperty(value = "唯一标识")
private String code;
@ApiModelProperty(value = "商品ID")
private Integer goodsId;
@ApiModelProperty(value = "商品规格")
private String spec;
@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 merchantId;
@ApiModelProperty(value = "用户ID")
private Integer userId;
@ApiModelProperty(value = "收银员ID")
private Integer cashierId;
@ApiModelProperty(value = "收银单分组ID")
private Integer groupId;
@ApiModelProperty(value = "备注")
private String comments;
@ApiModelProperty(value = "租户id")
private Integer tenantId;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "修改时间")
private Date updateTime;
@ApiModelProperty(value = "商品名称")
@TableField(exist = false)
private String goodsName;
@ApiModelProperty(value = "商品图片")
@TableField(exist = false)
private String image;
}
@@ -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.Cashier;
import com.gxwebsoft.shop.param.CashierParam;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 收银Mapper
*
* @author 科技小王子
* @since 2024-08-04 11:51:43
*/
public interface CashierMapper extends BaseMapper<Cashier> {
/**
* 分页查询
*
* @param page 分页对象
* @param param 查询参数
* @return List<Cashier>
*/
List<Cashier> selectPageRel(@Param("page") IPage<Cashier> page,
@Param("param") CashierParam param);
/**
* 查询全部
*
* @param param 查询参数
* @return List<User>
*/
List<Cashier> selectListRel(@Param("param") CashierParam param);
}
@@ -42,6 +42,9 @@
<if test="param.userId != null">
AND a.user_id LIKE CONCAT('%', #{param.userId}, '%')
</if>
<if test="param.adminId != null">
AND a.admin_id LIKE CONCAT('%', #{param.adminId}, '%')
</if>
<if test="param.selected != null">
AND a.selected = #{param.selected}
</if>
@@ -0,0 +1,81 @@
<?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.CashierMapper">
<!-- 关联查询sql -->
<sql id="selectSql">
SELECT a.*,b.goods_name,b.image,c.merchant_name,c.address
FROM shop_cashier a
LEFT JOIN shop_goods b ON a.goods_id = b.goods_id
LEFT JOIN shop_merchant c ON a.merchant_id = c.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.code != null">
AND a.code LIKE CONCAT('%', #{param.code}, '%')
</if>
<if test="param.goodsId != null">
AND a.goods_id LIKE CONCAT('%', #{param.goodsId}, '%')
</if>
<if test="param.spec != null">
AND a.spec LIKE CONCAT('%', #{param.spec}, '%')
</if>
<if test="param.price != null">
AND a.price = #{param.price}
</if>
<if test="param.cartNum != null">
AND a.cart_num = #{param.cartNum}
</if>
<if test="param.totalPrice != null">
AND a.total_price = #{param.totalPrice}
</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.selected != null">
AND a.selected = #{param.selected}
</if>
<if test="param.merchantId != null">
AND a.merchant_id LIKE CONCAT('%', #{param.merchantId}, '%')
</if>
<if test="param.userId != null">
AND a.user_id LIKE CONCAT('%', #{param.userId}, '%')
</if>
<if test="param.cashierId != null">
AND a.cashier_id LIKE CONCAT('%', #{param.cashierId}, '%')
</if>
<if test="param.groupId != null">
AND a.group_id LIKE CONCAT('%', #{param.groupId}, '%')
</if>
<if test="param.createTimeStart != null">
AND a.create_time &gt;= #{param.createTimeStart}
</if>
<if test="param.createTimeEnd != null">
AND a.create_time &lt;= #{param.createTimeEnd}
</if>
<if test="param.keywords != null">
AND (c.merchant_name LIKE CONCAT('%', #{param.keywords}, '%')
OR b.goods_name LIKE CONCAT('%', #{param.keywords}, '%')
)
</if>
</where>
</sql>
<!-- 分页查询 -->
<select id="selectPageRel" resultType="com.gxwebsoft.shop.entity.Cashier">
<include refid="selectSql"></include>
</select>
<!-- 查询全部 -->
<select id="selectListRel" resultType="com.gxwebsoft.shop.entity.Cashier">
<include refid="selectSql"></include>
</select>
</mapper>
@@ -100,12 +100,12 @@
<if test="param.createTimeEnd != null">
AND a.create_time &lt;= #{param.createTimeEnd}
</if>
<if test="param.keywords != null">
AND (a.comments LIKE CONCAT('%', #{param.keywords}, '%')
OR a.goods_name = #{param.keywords}
OR a.code = #{param.keywords}
)
</if>
<!-- <if test="param.keywords != null">-->
<!-- AND (a.comments LIKE CONCAT('%', #{param.keywords}, '%')-->
<!-- OR a.goods_name = #{param.keywords}-->
<!-- OR a.code = #{param.keywords}-->
<!-- )-->
<!-- </if>-->
</where>
</sql>
@@ -0,0 +1,85 @@
package com.gxwebsoft.shop.param;
import java.math.BigDecimal;
import com.baomidou.mybatisplus.annotation.TableField;
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-08-04 11:51:43
*/
@Data
@EqualsAndHashCode(callSuper = false)
@JsonInclude(JsonInclude.Include.NON_NULL)
@ApiModel(value = "CashierParam对象", description = "收银查询参数")
public class CashierParam extends BaseParam {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "收银单ID")
@QueryField(type = QueryType.EQ)
private Integer id;
@ApiModelProperty(value = "类型 0商城 1外卖")
@QueryField(type = QueryType.EQ)
private Integer type;
@ApiModelProperty(value = "唯一标识")
private String code;
@ApiModelProperty(value = "商品ID")
private Integer goodsId;
@ApiModelProperty(value = "商品规格")
private String spec;
@ApiModelProperty(value = "商品价格")
@QueryField(type = QueryType.EQ)
private BigDecimal price;
@ApiModelProperty(value = "商品数量")
@QueryField(type = QueryType.EQ)
private Integer cartNum;
@ApiModelProperty(value = "单商品合计")
@QueryField(type = QueryType.EQ)
private BigDecimal totalPrice;
@ApiModelProperty(value = "0 = 未购买 1 = 已购买")
@QueryField(type = QueryType.EQ)
private Boolean isPay;
@ApiModelProperty(value = "是否为立即购买")
@QueryField(type = QueryType.EQ)
private Boolean isNew;
@ApiModelProperty(value = "是否选中")
@QueryField(type = QueryType.EQ)
private Boolean selected;
@ApiModelProperty(value = "商户ID")
private Integer merchantId;
@ApiModelProperty(value = "用户ID")
private Integer userId;
@ApiModelProperty(value = "收银员ID")
private Integer cashierId;
@ApiModelProperty(value = "收银单分组ID")
private Integer groupId;
@ApiModelProperty(value = "按groupId分组")
@TableField(exist = false)
private Boolean showByGroup;
}
@@ -123,7 +123,6 @@ public class GoodsParam extends BaseParam {
@QueryField(type = QueryType.EQ)
private Integer deleted;
@ApiModelProperty(value = "父级分类ID")
@TableField(exist = false)
private Integer parentId;
@@ -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.Cashier;
import com.gxwebsoft.shop.param.CashierParam;
import com.gxwebsoft.shop.vo.CashierVo;
import java.util.List;
/**
* 收银Service
*
* @author 科技小王子
* @since 2024-08-04 11:51:43
*/
public interface CashierService extends IService<Cashier> {
/**
* 分页关联查询
*
* @param param 查询参数
* @return PageResult<Cashier>
*/
PageResult<Cashier> pageRel(CashierParam param);
/**
* 关联查询全部
*
* @param param 查询参数
* @return List<Cashier>
*/
CashierVo listRel(CashierParam param);
/**
* 根据id查询
*
* @param id 收银单ID
* @return Cashier
*/
Cashier getByIdRel(Integer id);
List<CashierVo> listRelByGroupId(CashierParam param);
}
@@ -73,6 +73,7 @@ public class CartServiceImpl extends ServiceImpl<CartMapper, Cart> implements Ca
final Cart cart = collectCart.get(shopId).get(0);
shopVo.setShopName(cart.getMerchantName());
shopVo.setShopLogo(cart.getImage());
shopVo.setAddress(cart.getAddress());
}
shops.add(shopVo);
}
@@ -0,0 +1,119 @@
package com.gxwebsoft.shop.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.entity.Cart;
import com.gxwebsoft.shop.mapper.CashierMapper;
import com.gxwebsoft.shop.service.CashierService;
import com.gxwebsoft.shop.entity.Cashier;
import com.gxwebsoft.shop.param.CashierParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.shop.vo.CartVo;
import com.gxwebsoft.shop.vo.CashierVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 收银Service实现
*
* @author 科技小王子
* @since 2024-08-04 11:51:43
*/
@Service
public class CashierServiceImpl extends ServiceImpl<CashierMapper, Cashier> implements CashierService {
@Override
public PageResult<Cashier> pageRel(CashierParam param) {
PageParam<Cashier, CashierParam> page = new PageParam<>(param);
page.setDefaultOrder("create_time desc");
List<Cashier> list = baseMapper.selectPageRel(page, param);
return new PageResult<>(list, page.getTotal());
}
@Override
@Transactional(rollbackFor = {Exception.class})
public CashierVo listRel(CashierParam param) {
List<Cashier> list = baseMapper.selectListRel(param);
// 排序
PageParam<Cashier, CashierParam> page = new PageParam<>();
page.setDefaultOrder("create_time desc");
final List<Cashier> cashiers = page.sortRecords(list);
// 整理数据
final CashierVo vo = new CashierVo();
// 计算单品总价
for (Cashier cashier : cashiers) {
cashier.setTotalPrice(cashier.getPrice().multiply(BigDecimal.valueOf(cashier.getCartNum())));
}
// 计算购物车金额
final Integer cartNum = cashiers.stream().map(Cashier::getCartNum).reduce(Integer::sum).orElse(0);
final Integer selectNums = cashiers.stream().filter(d -> d.getSelected().equals(true)).map(Cashier::getCartNum).reduce(Integer::sum).orElse(0);
final BigDecimal totalPrice = cashiers.stream().filter(d -> d.getSelected().equals(true)).map(Cashier::getTotalPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
// 封装数据
vo.setCashiers(cashiers);
vo.setTotalPrice(totalPrice);
vo.setTotalNums(Long.valueOf(cartNum));
vo.setSelectNums(Long.valueOf(selectNums));
return vo;
}
@Override
@Transactional(rollbackFor = {Exception.class})
public List<CashierVo> listRelByGroupId(CashierParam param) {
List<Cashier> list = baseMapper.selectListRel(param);
// 排序
PageParam<Cashier, CashierParam> page = new PageParam<>();
page.setDefaultOrder("create_time desc");
final List<Cashier> cashiers = page.sortRecords(list);
// 计算单品总价
cashiers.forEach(d->{
d.setTotalPrice(d.getPrice().multiply(BigDecimal.valueOf(d.getCartNum())));
});
final Map<Integer, List<Cashier>> collectByGroupId = cashiers.stream().collect(Collectors.groupingBy(Cashier::getGroupId));
// 整理数据
final ArrayList<CashierVo> cashierVos = new ArrayList<>();
for (Integer groupId : collectByGroupId.keySet()) {
final CashierVo vo = new CashierVo();
final List<Cashier> cashierList = collectByGroupId.get(groupId);
for (Cashier cashier : cashierList) {
if (cashier.getGroupId().equals(groupId)) {
// 计算购物车金额
final Integer cartNum = cashierList.stream().map(Cashier::getCartNum).reduce(Integer::sum).orElse(0);
final Integer selectNums = cashierList.stream().filter(d -> d.getSelected().equals(true)).map(Cashier::getCartNum).reduce(Integer::sum).orElse(0);
final BigDecimal totalPrice = cashierList.stream().filter(d -> d.getSelected().equals(true)).map(Cashier::getTotalPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
vo.setGroupId(Long.valueOf(groupId));
vo.setCashiers(cashierList);
vo.setTotalPrice(totalPrice);
vo.setTotalNums(Long.valueOf(cartNum));
vo.setSelectNums(Long.valueOf(selectNums));
vo.setComments("订单备注:");
}
}
cashierVos.add(vo);
}
return cashierVos;
}
@Override
public Cashier getByIdRel(Integer id) {
CashierParam param = new CashierParam();
param.setId(id);
return param.getOne(baseMapper.selectListRel(param));
}
}
@@ -43,6 +43,7 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
PageParam<Goods, GoodsParam> page = new PageParam<>(param);
page.setDefaultOrder("sort_number asc, create_time desc");
List<Goods> list = baseMapper.selectPageRel(page, param);
System.out.println("list = " + list);
final Set<Integer> goodsIds = list.stream().map(Goods::getGoodsId).collect(Collectors.toSet());
if (!CollectionUtils.isEmpty(goodsIds)) {
final List<GoodsSpec> specs = goodsSpecService.list(new LambdaQueryWrapper<GoodsSpec>().in(GoodsSpec::getGoodsId, goodsIds));
@@ -27,12 +27,17 @@ public class CartShopVo implements Serializable {
@ApiModelProperty(value = "店铺图标")
private String shopLogo;
@ApiModelProperty(value = "门店地址")
private String address;
@ApiModelProperty(value = "商品列表")
private List<Cart> carts;
@Data
public static class Payload {
private Integer shopId;
private Integer shopName;
private String shopName;
private String shopLogo;
private String address;
private List<Cart> carts;
}
}
@@ -0,0 +1,49 @@
package com.gxwebsoft.shop.vo;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.gxwebsoft.shop.entity.Cashier;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.models.auth.In;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "Cart对象", description = "购物车")
@TableName("shop_cart")
public class CashierVo implements Serializable {
@ApiModelProperty(value = "购物车总金额")
private BigDecimal totalPrice;
@ApiModelProperty(value = "宝贝数量")
private Long totalNums;
@ApiModelProperty(value = "已选中宝贝")
private Long selectNums;
@ApiModelProperty(value = "收银商品列表")
private List<Cashier> cashiers;
@ApiModelProperty(value = "分组ID")
private Long groupId;
@ApiModelProperty(value = "订单备注")
private String comments;
@Data
public static class Payload {
private BigDecimal totalPrice;
private Long totalNums;
private Long selectNums;
private List<Cashier> cashiers;
private Long groupId;
}
}
@@ -87,7 +87,8 @@ public class ShopGenerator {
// "shop_dealer_user",
// "shop_dealer_withdraw"
// "shop_cart"
"shop_count"
// "shop_count"
"shop_cashier"
};
// 需要去除的表前缀
private static final String[] TABLE_PREFIX = new String[]{