Merge branch 'refs/heads/dev' into test

This commit is contained in:
2024-10-30 10:40:17 +08:00
10 changed files with 169 additions and 94 deletions

View File

@@ -10,7 +10,7 @@ public interface TableConstant {
@Getter
enum Status {
REFUNDING("refunding"), REFUND("refund"), CLOSED("closed"), CREATE("create"),
UNPAID("unpaid"), PAYING("paying"), RETURN("return"), CANCEL("cancel");
UNPAID("unpaid"), PAYING("paying"), RETURN("return"), CANCELLED("cancelled");
private final String value;
Status(String value) {
this.value = value;
@@ -62,6 +62,8 @@ public interface TableConstant {
}
class CashierCart {
public static final String ID = "-999";
@Getter
public enum Status {
REFUNDING("refunding"), REFUND("refund"), CLOSED("closed"), CREATE("create"),

View File

@@ -213,6 +213,9 @@ public class OrderController {
*/
@PutMapping("/choseCount")
public Result choseCount(@Validated @RequestBody ChoseCountDTO choseCountDTO) {
if (choseCountDTO.getNum() == null) {
return Result.success(CodeEnum.SUCCESS);
}
return Result.success(CodeEnum.SUCCESS, orderService.choseCount(choseCountDTO));
}

View File

@@ -14,7 +14,6 @@ public class ChoseCountDTO {
private Integer shopId;
@NotEmpty
private String tableId;
@NotNull
@Min(1)
private Integer num;
}

View File

@@ -11,6 +11,7 @@ public class ShopEatTypeInfoDTO {
private boolean isMunchies;
private boolean isDineInAfter;
private boolean isDineInBefore;
private boolean needSeatFee;
private TbShopInfo shopInfo;
private String useType;
private String sendType;

View File

@@ -0,0 +1,19 @@
package com.chaozhanggui.system.cashierservice.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.chaozhanggui.system.cashierservice.bean.constant.TableConstant;
import com.chaozhanggui.system.cashierservice.entity.TbCashierCart;
import com.chaozhanggui.system.cashierservice.entity.TbShopTable;
import java.util.List;
/**
* (TbShopPermission)表服务接口
*
* @author makejava
* @since 2024-09-14 17:08:48
*/
public interface MpShopTableService extends IService<TbShopTable> {
}

View File

@@ -96,6 +96,7 @@ public class OrderService {
private final TbShopOpenIdMapper shopOpenIdMapper;
private final MpShopTableMapper mpShopTableMapper;
private final MpOrderInfoService mpOrderInfoService;
private final MpShopTableService mpShopTableService;
@Autowired
TbConsInfoMapper tbConsInfoMapper;
@@ -132,13 +133,14 @@ public class OrderService {
public OrderService(WxAccountUtil wxAccountUtil, MPCashierCartMapper mpCashierCartMapper,
TbShopOpenIdMapper shopOpenIdMapper, MpShopTableMapper mpShopTableMapper, MpOrderInfoService mpOrderInfoService,
TbShopOpenIdMapper shopOpenIdMapper, MpShopTableMapper mpShopTableMapper, MpOrderInfoService mpOrderInfoService, MpShopTableService mpShopTableService,
TbCashierCartMapper tbCashierCartMapper, MpCashierCartService mpCashierCartService) {
this.wxAccountUtil = wxAccountUtil;
this.mpCashierCartMapper = mpCashierCartMapper;
this.shopOpenIdMapper = shopOpenIdMapper;
this.mpShopTableMapper = mpShopTableMapper;
this.mpOrderInfoService = mpOrderInfoService;
this.mpShopTableService = mpShopTableService;
this.tbCashierCartMapper = tbCashierCartMapper;
this.mpCashierCartService = mpCashierCartService;
}
@@ -162,8 +164,9 @@ public class OrderService {
boolean isDineInAfter = !isMunchies && !isTakeout;
boolean isDineInBefore = isMunchies && !isTakeout;
boolean needSeatFee = shopInfo.getIsTableFee() == null || shopInfo.getIsTableFee() == 0;
return new ShopEatTypeInfoDTO(isTakeout, isMunchies, isDineInAfter, isDineInBefore, shopInfo, isTakeout ? OrderUseTypeEnum.TAKEOUT.getValue() :
return new ShopEatTypeInfoDTO(isTakeout, isMunchies, isDineInAfter, isDineInBefore, needSeatFee, shopInfo, isTakeout ? OrderUseTypeEnum.TAKEOUT.getValue() :
isMunchies ? OrderUseTypeEnum.DINE_IN_BEFORE.getValue() : OrderUseTypeEnum.DINE_IN_AFTER.getValue(), isTakeout ? OrderSendTypeEnums.TAKE_SELF.getValue() : OrderSendTypeEnums.TABLE.getValue());
}
@@ -178,26 +181,9 @@ public class OrderService {
String eatModel = StrUtil.isBlank(tableId) ? ShopInfoEatModelEnum.TAKE_OUT.getValue() : ShopInfoEatModelEnum.DINE_IN.getValue();
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(shopId, eatModel);
TbProduct product = mpProductMapper.selectOne(new LambdaQueryWrapper<TbProduct>()
.eq(TbProduct::getId, productId)
.eq(TbProduct::getStatus, 1));
if (ObjectUtil.isEmpty(product)) {
return Result.fail(CodeEnum.PRODUCTINFOERROR);
}
TbProductSkuWithBLOBs skuWithBLOBs;
if ("1".equals(product.getTypeEnum())) {
skuWithBLOBs = tbProductSkuMapper.selectByProduct(productId);
} else {
skuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(skuId);
}
if (ObjectUtil.isEmpty(skuWithBLOBs)) {
return Result.fail(CodeEnum.PRODUCTSKUERROR);
}
// 台桌点单
boolean isSeatCart = TableConstant.CashierCart.ID.equals(productId.toString());
if ((StrUtil.isNotBlank(tableId))) {
TbShopTable shopTable = mpShopTableMapper.selectOne(new LambdaUpdateWrapper<TbShopTable>()
.eq(TbShopTable::getQrcode, tableId)
@@ -206,6 +192,9 @@ public class OrderService {
if (shopTable == null) {
return Result.fail("台桌不处于开台或空闲状态");
}
if (shopEatTypeInfoDTO.isNeedSeatFee() && number > shopTable.getMaxCapacity() && isSeatCart) {
return Result.fail("当前台桌最大人数未: " + shopTable.getMaxCapacity());
}
}
LambdaQueryWrapper<TbCashierCart> cartQuery = new LambdaQueryWrapper<TbCashierCart>()
@@ -215,60 +204,78 @@ public class OrderService {
.in(TbCashierCart::getStatus, "create")
.eq(TbCashierCart::getId, cartId);
// 后付款订单只查询为空的
if (shopEatTypeInfoDTO.isDineInAfter()) {
cartQuery.isNull(TbCashierCart::getPlaceNum);
}
TbCashierCart cart = mpCashierCartMapper.selectOne(cartQuery);
// 校验是否是代客下单往期订单
if (shopEatTypeInfoDTO.isDineInAfter() && cart != null && cart.getPlaceNum() != null) {
if (shopEatTypeInfoDTO.isDineInAfter() && cart != null && cart.getPlaceNum() != null && !isSeatCart) {
return Result.fail("后付费已下单订单仅支持退款");
}
TbProduct product = null;
TbProductSkuWithBLOBs skuWithBLOBs = null;
if (!isSeatCart) {
product = mpProductMapper.selectOne(new LambdaQueryWrapper<TbProduct>()
.eq(TbProduct::getId, productId)
.eq(TbProduct::getStatus, 1));
if (ObjectUtil.isEmpty(product)) {
return Result.fail(CodeEnum.PRODUCTINFOERROR);
}
// 首次加入购物车,并且拥有起售数,设置为起售数
if (cart == null && skuWithBLOBs.getSuit() != null && skuWithBLOBs.getSuit() != 0) {
number = skuWithBLOBs.getSuit();
// 低于起售,删除商品
} else if (cart != null && skuWithBLOBs.getSuit() != null && skuWithBLOBs.getSuit() != 0 && number < skuWithBLOBs.getSuit()) {
delCart(masterId, cartId);
if (StrUtil.isNotBlank(cart.getOrderId()) && StrUtil.isNotBlank(cart.getTableId())) {
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
.notIn(TbCashierCart::getStatus, "final", "refund", "closed", "pending")
.eq(TbCashierCart::getShopId, cart.getShopId());
TbCashierCart finalCart = cart;
queryWrapper.eq(TbCashierCart::getTableId, cart.getTableId())
.and(q -> q.or(
query -> query.eq(TbCashierCart::getMasterId, finalCart.getMasterId())
.or()
.isNull(TbCashierCart::getMasterId)
.or()
.eq(TbCashierCart::getMasterId, "")
)
.or(query -> query.eq(TbCashierCart::getOrderId, finalCart.getOrderId())
.or()
.isNull(TbCashierCart::getOrderId)));
if ("1".equals(product.getTypeEnum())) {
skuWithBLOBs = tbProductSkuMapper.selectByProduct(productId);
} else {
skuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(skuId);
}
List<TbCashierCart> list = mpCashierCartMapper.selectList(queryWrapper.eq(TbCashierCart::getStatus, "create"));
if (list.isEmpty()) {
tbOrderInfoMapper.deleteByPrimaryKey(Integer.valueOf(finalCart.getOrderId()));
if (ObjectUtil.isEmpty(skuWithBLOBs)) {
return Result.fail(CodeEnum.PRODUCTSKUERROR);
}
// 首次加入购物车,并且拥有起售数,设置为起售数
if (cart == null && skuWithBLOBs.getSuit() != null && skuWithBLOBs.getSuit() != 0) {
number = skuWithBLOBs.getSuit();
// 低于起售,删除商品
} else if (cart != null && skuWithBLOBs.getSuit() != null && skuWithBLOBs.getSuit() != 0 && number < skuWithBLOBs.getSuit()) {
delCart(masterId, cartId);
if (StrUtil.isNotBlank(cart.getOrderId()) && StrUtil.isNotBlank(cart.getTableId())) {
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
.notIn(TbCashierCart::getStatus, "final", "refund", "closed", "pending")
.eq(TbCashierCart::getShopId, cart.getShopId());
TbCashierCart finalCart = cart;
queryWrapper.eq(TbCashierCart::getTableId, cart.getTableId())
.and(q -> q.or(
query -> query.eq(TbCashierCart::getMasterId, finalCart.getMasterId())
.or()
.isNull(TbCashierCart::getMasterId)
.or()
.eq(TbCashierCart::getMasterId, "")
)
.or(query -> query.eq(TbCashierCart::getOrderId, finalCart.getOrderId())
.or()
.isNull(TbCashierCart::getOrderId)));
List<TbCashierCart> list = mpCashierCartMapper.selectList(queryWrapper.eq(TbCashierCart::getStatus, "create"));
if (list.isEmpty()) {
tbOrderInfoMapper.deleteByPrimaryKey(Integer.valueOf(cart.getOrderId()));
}
}
setRedisTableCartInfo(tableId, shopId, Collections.singletonList(cart), false);
return Result.success(CodeEnum.SUCCESS, masterId);
}
// 校验库存
if ("1".equals(product.getIsStock().toString())) {
if (product.getStockNumber() - number < 0) {
return Result.fail(CodeEnum.STOCKERROR);
}
}
setRedisTableCartInfo(tableId, shopId, Collections.singletonList(cart), false);
return Result.success(CodeEnum.SUCCESS, masterId);
}
// 校验库存
if ("1".equals(product.getIsStock().toString())) {
if (product.getStockNumber() - number < 0) {
return Result.fail(CodeEnum.STOCKERROR);
}
}
if (StringUtils.isEmpty(masterId)) {
boolean flag = redisUtil.exists("SHOP:CODE:" + clientType + ":" + shopId);
if (flag) {
@@ -304,10 +311,18 @@ public class OrderService {
if (isPack.equals("false")) {
cart.setPackFee(BigDecimal.ZERO);
} else {
cart.setPackFee(new BigDecimal(number).multiply(product.getPackFee()));
if (!isSeatCart) {
cart.setPackFee(new BigDecimal(number).multiply(product.getPackFee()));
}else{
cart.setPackFee(BigDecimal.ZERO);
}
}
if (isGift.equals("false")) {
cart.setTotalAmount(new BigDecimal(number).multiply(skuWithBLOBs.getSalePrice()).add(cart.getPackFee()));
if (!isSeatCart) {
cart.setTotalAmount(new BigDecimal(number).multiply(skuWithBLOBs.getSalePrice()).add(cart.getPackFee()));
}else {
cart.setTotalAmount(new BigDecimal(number).multiply(cart.getSalePrice()).add(cart.getPackFee()));
}
} else {
cart.setTotalAmount(BigDecimal.ZERO);
}
@@ -324,31 +339,42 @@ public class OrderService {
if (Objects.isNull(cashierCart)) {
cashierCart = new TbCashierCart();
cashierCart.setUseType(shopEatTypeInfoDTO.getUseType());
cashierCart.setCoverImg(product.getCoverImg());
if (product != null) {
cashierCart.setCoverImg(product.getCoverImg());
cashierCart.setIsSku(product.getTypeEnum());
cashierCart.setName(product.getName());
cashierCart.setCategoryId(product.getCategoryId());
}
cashierCart.setCreatedAt(System.currentTimeMillis());
cashierCart.setIsSku(product.getTypeEnum());
cashierCart.setMasterId(masterId);
cashierCart.setUuid(uuid);
cashierCart.setMerchantId(userId);
cashierCart.setName(product.getName());
cashierCart.setProductId(productId.toString());
cashierCart.setSalePrice(skuWithBLOBs.getSalePrice());
cashierCart.setSkuId(skuWithBLOBs.getId().toString());
if (skuWithBLOBs != null) {
cashierCart.setSalePrice(skuWithBLOBs.getSalePrice());
cashierCart.setSkuId(skuWithBLOBs.getId().toString());
cashierCart.setSkuName(skuWithBLOBs.getSpecSnap());
}
cashierCart.setShopId(shopId.toString());
cashierCart.setTradeDay(DateUtils.getDay());
cashierCart.setStatus("create");
cashierCart.setIsPack(isPack);
cashierCart.setIsGift(isGift);
cashierCart.setSkuName(skuWithBLOBs.getSpecSnap());
if (isGift.equals("false")) {
cashierCart.setTotalAmount(new BigDecimal(number).multiply(skuWithBLOBs.getSalePrice()));
if (isSeatCart) {
cashierCart.setTotalAmount(new BigDecimal(number).multiply(cashierCart.getSalePrice()));
}else {
cashierCart.setTotalAmount(new BigDecimal(number).multiply(skuWithBLOBs.getSalePrice()));
}
} else {
cashierCart.setTotalAmount(BigDecimal.ZERO);
}
if (isPack.equals("false")) {
cashierCart.setPackFee(BigDecimal.ZERO);
} else {
cashierCart.setPackFee(new BigDecimal(number).multiply(product.getPackFee()));
if (!isSeatCart) {
cashierCart.setPackFee(new BigDecimal(number).multiply(product.getPackFee()));
}
cashierCart.setTotalAmount(cashierCart.getTotalAmount().add(cashierCart.getPackFee()));
}
@@ -356,7 +382,6 @@ public class OrderService {
cashierCart.setUserId(Integer.valueOf(userId));
cashierCart.setNumber(number);
cashierCart.setUuid(uuid);
cashierCart.setCategoryId(product.getCategoryId());
cashierCart.setTableId(tableId);
cashierCart.setPlatformType(OrderPlatformTypeEnum.CASH.getValue());
list.add(cashierCart);
@@ -370,7 +395,9 @@ public class OrderService {
if (isPack.equals("false")) {
cashierCart.setPackFee(BigDecimal.ZERO);
} else {
cashierCart.setPackFee(new BigDecimal(number).multiply(product.getPackFee()));
if (!isSeatCart) {
cashierCart.setPackFee(new BigDecimal(number).multiply(product.getPackFee()));
}
}
cashierCart.setTotalAmount(new BigDecimal(cashierCart.getNumber()).multiply(skuWithBLOBs.getSalePrice()).add(cashierCart.getPackFee()));
mpCashierCartMapper.updateById(cashierCart);
@@ -380,15 +407,6 @@ public class OrderService {
}
// TbCashierCart finalCart1 = cart;
// ThreadUtil.execute(() -> {
// ThreadUtil.sleep(1, TimeUnit.SECONDS);
// if (finalCart1.getOrderId() != null && finalCart1.getTableId() != null) {
// log.info("购物车数量改变,开始校验订单是否为空");
// printMechineConsumer.printReturnTicket(Integer.valueOf(finalCart1.getOrderId()), tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(finalCart1.getOrderId())));
// }
// });
setRedisTableCartInfo(tableId, shopId, Collections.singletonList(cart), true);
return Result.success(CodeEnum.SUCCESS, masterId);
@@ -518,10 +536,10 @@ public class OrderService {
// 检查购物车商品是否已经全部退款
if (!returnCashierCarts.isEmpty() && returnCashierCarts.size() == list.size()) {
List<Integer> cartIds = returnCashierCarts.stream().map(TbCashierCart::getId).collect(Collectors.toList());
mpCashierCartService.updateStateByIds(Integer.valueOf(shopId), cartIds, TableConstant.Status.CANCEL);
mpOrderDetailService.updateStateByCartIds(Integer.valueOf(shopId), cartIds, TableConstant.Status.CANCEL);
mpCashierCartService.updateStateByIds(Integer.valueOf(shopId), cartIds, TableConstant.Status.CLOSED);
mpOrderDetailService.updateStateByCartIds(Integer.valueOf(shopId), cartIds, TableConstant.Status.CLOSED);
if (StrUtil.isNotBlank(orderId)) {
mpOrderInfoService.updateStateById(Integer.valueOf(shopId), Integer.valueOf(orderId), TableConstant.Status.CANCEL);
mpOrderInfoService.updateStateById(Integer.valueOf(shopId), Integer.valueOf(orderId), TableConstant.Status.CANCELLED);
}
String finalMasterId = masterId;
@@ -739,8 +757,6 @@ public class OrderService {
// 获取当前台桌最新订单,先付款模式不获取
String currentOrderKey = RedisCst.getCurrentOrderKey(orderVo.getTableId(), orderVo.getShopId().toString());
TbOrderInfo orderInfo = getCurrentOrder(eatTypeInfoDTO, orderVo.getTableId(), orderVo.getShopId());
Integer orderId = orderInfo == null ? null : orderInfo.getId();
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
.eq(TbCashierCart::getShopId, orderVo.getShopId())
@@ -787,8 +803,11 @@ public class OrderService {
ArrayList<Integer> cashierIds = new ArrayList<>();
// 就餐人数
Integer mealNum = null;
Integer orderId = null;
for (TbCashierCart cart : list) {
if (StrUtil.isNotBlank(cart.getOrderId())) {
orderId = Integer.valueOf(cart.getOrderId());
}
cashierIds.add(cart.getId());
if ("-999".equals(cart.getProductId())) {
mealNum = cart.getNumber();
@@ -901,6 +920,10 @@ public class OrderService {
// 创建订单
String orderNo = generateOrderNumber();
TbToken tbToken = tokenMapper.selectByToken(token);
TbOrderInfo orderInfo = null;
if (orderId != null) {
orderInfo = mPOrderInfoMapper.selectById(orderId);
}
if (orderInfo == null || !"unpaid".equals(orderInfo.getStatus())) {
redisUtil.deleteByKey(currentOrderKey);
}
@@ -1776,7 +1799,7 @@ public class OrderService {
if (shopInfo == null) throw new NotPrintException("店铺信息不存在");
if (shopInfo.getIsTableFee() != null && shopInfo.getIsTableFee() == 1) {
throw new NotPrintException("当前店铺无需选择餐位费");
return Result.success(CodeEnum.SUCCESS);
}
TbShopTable shopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper<TbShopTable>()

View File

@@ -35,7 +35,7 @@ public class MpOrderDetailServiceImpl extends ServiceImpl<MPOrderDetailMapper, T
return update(new LambdaUpdateWrapper<TbOrderDetail>()
.eq(TbOrderDetail::getShopId, shopId)
.in(TbOrderDetail::getCartId, cartIds)
.set(TbOrderDetail::getStatus, status));
.set(TbOrderDetail::getStatus, status.getValue()));
}
}

View File

@@ -1,5 +1,6 @@
package com.chaozhanggui.system.cashierservice.service.impl;
import cn.hutool.Hutool;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chaozhanggui.system.cashierservice.bean.constant.TableConstant;
@@ -27,7 +28,7 @@ public class MpOrderInfoServiceImpl extends ServiceImpl<MPOrderInfoMapper, TbOrd
return update(new LambdaUpdateWrapper<TbOrderInfo>()
.eq(TbOrderInfo::getShopId, shopId)
.eq(TbOrderInfo::getId, orderId)
.set(TbOrderInfo::getStatus, status));
.set(TbOrderInfo::getStatus, status.getValue()));
}
}

View File

@@ -0,0 +1,27 @@
package com.chaozhanggui.system.cashierservice.service.impl;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chaozhanggui.system.cashierservice.bean.constant.TableConstant;
import com.chaozhanggui.system.cashierservice.entity.TbCashierCart;
import com.chaozhanggui.system.cashierservice.entity.TbShopTable;
import com.chaozhanggui.system.cashierservice.mybatis.MPCashierCartMapper;
import com.chaozhanggui.system.cashierservice.mybatis.MpShopTableMapper;
import com.chaozhanggui.system.cashierservice.service.MpCashierCartService;
import com.chaozhanggui.system.cashierservice.service.MpShopTableService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* (TbShopPermission)表服务实现类
*
* @author makejava
* @since 2024-09-14 17:08:49
*/
@Service
public class MpShopTableServiceImpl extends ServiceImpl<MpShopTableMapper, TbShopTable> implements MpShopTableService {
}

View File

@@ -231,7 +231,7 @@
<select id="selectTableInfo" resultType="com.chaozhanggui.system.cashierservice.entity.vo.TbShopTableVO">
select a.*, b.user_id, b.master_id, b.id as orderId, b.order_no as orderNo, b.amount as orderAmount from tb_shop_table a
left join tb_order_info b on a.qrcode=b.table_id and (b.`status`='unpaid') and b.master_id is not null
and b.shop_id=#{shopId} and b.trade_day=#{day} and b.use_type!='takeout' and b.order_type='cash' and b.created_at > UNIX_TIMESTAMP(DATE_SUB(CURDATE(), INTERVAL 1 DAY)) * 1000
and b.shop_id=#{shopId} and b.use_type!='takeout' and b.created_at > UNIX_TIMESTAMP(DATE_SUB(CURDATE(), INTERVAL 1 DAY)) * 1000
where a.shop_id=#{shopId}
<if test="areaId != null and areaId !=''">
and a.area_id = #{areaId}
@@ -242,6 +242,6 @@
and a.status = #{status}
</if>
GROUP BY a.id
order by a.id desc
order by b.created_at desc
</select>
</mapper>