退单接口修改 购物车查询逻辑修改
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
package cn.ysk.cashier.exception;
|
package cn.ysk.cashier.exception;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||||
@@ -23,4 +24,8 @@ public class BadRequestException extends RuntimeException{
|
|||||||
super(msg);
|
super(msg);
|
||||||
this.status = status.value();
|
this.status = status.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BadRequestException(String template ,Object... args){
|
||||||
|
super(StrUtil.format(template, args));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package cn.ysk.cashier.dto.shoptable;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Min;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@@ -12,4 +13,8 @@ public class ReturnCartDTO {
|
|||||||
private Integer shopId;
|
private Integer shopId;
|
||||||
@NotNull
|
@NotNull
|
||||||
private Long tableId;
|
private Long tableId;
|
||||||
|
@NotNull
|
||||||
|
@Min(value = 1, message = "最小数量为1")
|
||||||
|
private Integer num;
|
||||||
|
private String note;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import cn.ysk.cashier.vo.TbCashierCartVO;
|
|||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
import org.apache.ibatis.annotations.Update;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -36,4 +37,15 @@ public interface TbCashierCartMapper extends BaseMapper<TbCashierCart> {
|
|||||||
|
|
||||||
@Select("select a.*, b.spec_snap from tb_cashier_cart as a left join tb_product_sku as b on a.sku_id=b.id where a.shop_id=#{shopId} and a.status='refund';")
|
@Select("select a.*, b.spec_snap from tb_cashier_cart as a left join tb_product_sku as b on a.sku_id=b.id where a.shop_id=#{shopId} and a.status='refund';")
|
||||||
List<TbCashierCartVO> selectPending(Integer shopId);
|
List<TbCashierCartVO> selectPending(Integer shopId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新购物车数量以及金额
|
||||||
|
* @param id id
|
||||||
|
* @param status 状态
|
||||||
|
* @param changeNum 修改数量 正数增加 负数减少
|
||||||
|
* @return 影响行数
|
||||||
|
*/
|
||||||
|
@Update("update tb_cashier_cart set status=#{status}, total_amount=(number+#{changeNum})*sale_price,number=number+#{changeNum},total_number=total_number+#{changeNum} " +
|
||||||
|
"where id=#{id}")
|
||||||
|
int updateNumAmountStatus(Integer id, String status, Integer changeNum);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,18 @@ package cn.ysk.cashier.mybatis.mapper;
|
|||||||
|
|
||||||
import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Update;
|
||||||
|
|
||||||
public interface TbOrderDetailMapper extends BaseMapper<TbOrderDetail> {
|
public interface TbOrderDetailMapper extends BaseMapper<TbOrderDetail> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新购物车数量以及金额
|
||||||
|
* @param id id
|
||||||
|
* @param status 状态
|
||||||
|
* @param changeNum 修改数量 正数增加 负数减少
|
||||||
|
* @return 影响行数
|
||||||
|
*/
|
||||||
|
@Update("update tb_order_detail set status=#{status}, price_amount=(num+#{changeNum})*price,num=num+#{changeNum} " +
|
||||||
|
"where id=#{id}")
|
||||||
|
int updateNumAmountStatus(Integer id, String status, int changeNum);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,4 @@ public interface TbOrderInfoMapper extends BaseMapper<TbOrderInfo> {
|
|||||||
"order_amount=origin_amount-#{priceAmount}, amount=amount-#{priceAmount}," +
|
"order_amount=origin_amount-#{priceAmount}, amount=amount-#{priceAmount}," +
|
||||||
"order_amount=order_amount-#{priceAmount} where id=#{orderId} and origin_amount-#{priceAmount} >= 0")
|
"order_amount=order_amount-#{priceAmount} where id=#{orderId} and origin_amount-#{priceAmount} >= 0")
|
||||||
int updateOrderAmount(Integer orderId, BigDecimal priceAmount, BigDecimal packAmount);
|
int updateOrderAmount(Integer orderId, BigDecimal priceAmount, BigDecimal packAmount);
|
||||||
|
|
||||||
void cancelOrder();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,6 +122,9 @@ public class TbOrderDetail implements Serializable {
|
|||||||
@Column(name = "`use_type`")
|
@Column(name = "`use_type`")
|
||||||
private String useType;
|
private String useType;
|
||||||
|
|
||||||
|
@Column(name = "`refund_remark`")
|
||||||
|
private String refundRemark;
|
||||||
|
|
||||||
public void copy(TbOrderDetail source){
|
public void copy(TbOrderDetail source){
|
||||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -235,7 +235,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||||||
|
|
||||||
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(criteria.getShopId(), date.getQrcode());
|
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(criteria.getShopId(), date.getQrcode());
|
||||||
orderInfo = getCurrentOrder(shopEatTypeInfoDTO);
|
orderInfo = getCurrentOrder(shopEatTypeInfoDTO);
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.info(e.getMessage());
|
log.info(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -614,6 +614,10 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||||||
throw new BadRequestException("购物车商品不存在或已退单");
|
throw new BadRequestException("购物车商品不存在或已退单");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (removeCartDTO.getNum() > cashierCart.getNumber()) {
|
||||||
|
throw new BadRequestException("最大退菜数量为: {}", cashierCart.getNumber());
|
||||||
|
}
|
||||||
|
|
||||||
TbOrderDetail tbOrderDetail = orderDetailMapper.selectOne(new LambdaQueryWrapper<TbOrderDetail>()
|
TbOrderDetail tbOrderDetail = orderDetailMapper.selectOne(new LambdaQueryWrapper<TbOrderDetail>()
|
||||||
.eq(TbOrderDetail::getShopId, removeCartDTO.getShopId())
|
.eq(TbOrderDetail::getShopId, removeCartDTO.getShopId())
|
||||||
.eq(TbOrderDetail::getCartId, cashierCart.getId())
|
.eq(TbOrderDetail::getCartId, cashierCart.getId())
|
||||||
@@ -646,17 +650,41 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
cashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>()
|
|
||||||
.eq(TbCashierCart::getId, cashierCart.getId())
|
|
||||||
.set(TbCashierCart::getStatus, "return"));
|
|
||||||
|
|
||||||
orderDetailMapper.update(null, new LambdaUpdateWrapper<TbOrderDetail>()
|
if (cashierCart.getNumber().equals(removeCartDTO.getNum())) {
|
||||||
.eq(TbOrderDetail::getId, tbOrderDetail.getId())
|
cashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>()
|
||||||
.set(TbOrderDetail::getUpdateTime, DateUtil.date())
|
.eq(TbCashierCart::getId, cashierCart.getId())
|
||||||
.set(TbOrderDetail::getStatus, "return"));
|
.set(TbCashierCart::getStatus, "return"));
|
||||||
|
orderDetailMapper.update(null, new LambdaUpdateWrapper<TbOrderDetail>()
|
||||||
|
.eq(TbOrderDetail::getId, tbOrderDetail.getId())
|
||||||
|
.set(TbOrderDetail::getUpdateTime, DateUtil.date())
|
||||||
|
.set(TbOrderDetail::getStatus, "return"));
|
||||||
|
}else {
|
||||||
|
//生成退菜的购物车记录
|
||||||
|
TbCashierCart returnCart = BeanUtil.copyProperties(cashierCart, TbCashierCart.class);
|
||||||
|
returnCart.setNumber(removeCartDTO.getNum());
|
||||||
|
returnCart.setId(null);
|
||||||
|
returnCart.setTotalNumber(removeCartDTO.getNum());
|
||||||
|
returnCart.setTotalAmount(returnCart.getSalePrice().multiply(BigDecimal.valueOf(returnCart.getNumber())));
|
||||||
|
returnCart.setStatus("return");
|
||||||
|
cashierCartMapper.insert(returnCart);
|
||||||
|
|
||||||
|
TbOrderDetail returnOrderDetail = BeanUtil.copyProperties(tbOrderDetail, TbOrderDetail.class);
|
||||||
|
returnOrderDetail.setId(null);
|
||||||
|
returnOrderDetail.setNum(returnCart.getNumber());
|
||||||
|
returnOrderDetail.setCartId(returnCart.getId());
|
||||||
|
returnOrderDetail.setPrice(returnCart.getSalePrice());
|
||||||
|
returnOrderDetail.setPriceAmount(returnCart.getTotalAmount());
|
||||||
|
returnOrderDetail.setStatus("return");
|
||||||
|
returnOrderDetail.setRefundNumber(returnCart.getRefundNumber());
|
||||||
|
returnOrderDetail.setRefundRemark(removeCartDTO.getNote());
|
||||||
|
orderDetailMapper.insert(returnOrderDetail);
|
||||||
|
|
||||||
|
cashierCartMapper.updateNumAmountStatus(cashierCart.getId(), cashierCart.getStatus(), -returnCart.getNumber());
|
||||||
|
orderDetailMapper.updateNumAmountStatus(orderDetail.getId(), orderDetail.getStatus(), -returnCart.getNumber());
|
||||||
|
}
|
||||||
|
|
||||||
rabbitMsgUtils.printDishesTicket(tbOrderDetail.getOrderId(), true, tbOrderDetail);
|
rabbitMsgUtils.printDishesTicket(tbOrderDetail.getOrderId(), true, tbOrderDetail);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cashierCart.getOrderId() != null) {
|
if (cashierCart.getOrderId() != null) {
|
||||||
@@ -718,10 +746,10 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||||||
.and(q -> q.eq(TbCashierCart::getMasterId, masterId).or().isNull(TbCashierCart::getMasterId));
|
.and(q -> q.eq(TbCashierCart::getMasterId, masterId).or().isNull(TbCashierCart::getMasterId));
|
||||||
|
|
||||||
if (!shopEatTypeInfoDTO.isTakeout()) {
|
if (!shopEatTypeInfoDTO.isTakeout()) {
|
||||||
queryWrapper.eq(TbCashierCart::getTableId, tableId);
|
queryWrapper.eq(TbCashierCart::getTableId, tableId)
|
||||||
} else {
|
|
||||||
queryWrapper.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, ""))
|
|
||||||
.in(TbCashierCart::getPlatformType, OrderPlatformTypeEnum.PC.getValue(), OrderPlatformTypeEnum.CASH.getValue());
|
.in(TbCashierCart::getPlatformType, OrderPlatformTypeEnum.PC.getValue(), OrderPlatformTypeEnum.CASH.getValue());
|
||||||
|
} else {
|
||||||
|
queryWrapper.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
com.baomidou.mybatisplus.extension.plugins.pagination.Page<TbCashierCart> cartPage = cashierCartMapper
|
com.baomidou.mybatisplus.extension.plugins.pagination.Page<TbCashierCart> cartPage = cashierCartMapper
|
||||||
@@ -1311,7 +1339,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||||||
// 清空台桌信息
|
// 清空台桌信息
|
||||||
if (shopEatTypeInfoDTO.isDineInBefore()) {
|
if (shopEatTypeInfoDTO.isDineInBefore()) {
|
||||||
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
|
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
|
||||||
.eq(TbShopTable::getShopId, createOrderDTO.getShopId())
|
.eq(TbShopTable::getShopId, createOrderDTO.getShopId())
|
||||||
.eq(TbShopTable::getQrcode, createOrderDTO.getTableId())
|
.eq(TbShopTable::getQrcode, createOrderDTO.getTableId())
|
||||||
.set(TbShopTable::getProductNum, 0)
|
.set(TbShopTable::getProductNum, 0)
|
||||||
.set(TbShopTable::getTotalAmount, 0)
|
.set(TbShopTable::getTotalAmount, 0)
|
||||||
@@ -1319,7 +1347,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||||||
.set(TbShopTable::getUseNum, 0)
|
.set(TbShopTable::getUseNum, 0)
|
||||||
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
|
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
|
||||||
// 设置台桌信息
|
// 设置台桌信息
|
||||||
}else {
|
} else {
|
||||||
LambdaUpdateWrapper<TbShopTable> wrapper = new LambdaUpdateWrapper<TbShopTable>()
|
LambdaUpdateWrapper<TbShopTable> wrapper = new LambdaUpdateWrapper<TbShopTable>()
|
||||||
.eq(TbShopTable::getShopId, createOrderDTO.getShopId())
|
.eq(TbShopTable::getShopId, createOrderDTO.getShopId())
|
||||||
.eq(TbShopTable::getQrcode, createOrderDTO.getTableId())
|
.eq(TbShopTable::getQrcode, createOrderDTO.getTableId())
|
||||||
@@ -1649,7 +1677,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object updateVip(UpdateVipDTO updateVipDTO) {
|
public Object updateVip(UpdateVipDTO updateVipDTO) {
|
||||||
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(updateVipDTO.getShopId(), updateVipDTO.getTableId());
|
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(updateVipDTO.getShopId(), updateVipDTO.getTableId());
|
||||||
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
|
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
|
||||||
.in(TbCashierCart::getStatus, "create", "return")
|
.in(TbCashierCart::getStatus, "create", "return")
|
||||||
@@ -1671,7 +1699,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||||||
return orderInfoMapper.update(null, new LambdaUpdateWrapper<TbOrderInfo>()
|
return orderInfoMapper.update(null, new LambdaUpdateWrapper<TbOrderInfo>()
|
||||||
.eq(TbOrderInfo::getId, orderId)
|
.eq(TbOrderInfo::getId, orderId)
|
||||||
.set(TbOrderInfo::getUserId, updateVipDTO.getVipUserId()));
|
.set(TbOrderInfo::getUserId, updateVipDTO.getVipUserId()));
|
||||||
}else {
|
} else {
|
||||||
return orderInfoMapper.update(null, new LambdaUpdateWrapper<TbOrderInfo>()
|
return orderInfoMapper.update(null, new LambdaUpdateWrapper<TbOrderInfo>()
|
||||||
.eq(TbOrderInfo::getId, orderId)
|
.eq(TbOrderInfo::getId, orderId)
|
||||||
.set(TbOrderInfo::getUserId, null));
|
.set(TbOrderInfo::getUserId, null));
|
||||||
@@ -2078,7 +2106,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||||||
} else if ("deposit".equals(payType)) {
|
} else if ("deposit".equals(payType)) {
|
||||||
orderInfoService.depositReturn(Integer.valueOf(orderInfo.getUserId()), Integer.valueOf(orderInfo.getShopId()), returnOrderInfo.getRefundAmount());
|
orderInfoService.depositReturn(Integer.valueOf(orderInfo.getUserId()), Integer.valueOf(orderInfo.getShopId()), returnOrderInfo.getRefundAmount());
|
||||||
orderInfo.setStatus("refund");
|
orderInfo.setStatus("refund");
|
||||||
}else if ("cash".equals(payType)) {
|
} else if ("cash".equals(payType)) {
|
||||||
orderInfo.setStatus("refund");
|
orderInfo.setStatus("refund");
|
||||||
}
|
}
|
||||||
orderInfoMapper.updateById(orderInfo);
|
orderInfoMapper.updateById(orderInfo);
|
||||||
|
|||||||
Reference in New Issue
Block a user