feat: 1.单品改价 2.免厨打
This commit is contained in:
parent
4c209ac27b
commit
e5c74051c7
|
|
@ -4,10 +4,7 @@ import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.OrderVo;
|
import com.chaozhanggui.system.cashierservice.entity.OrderVo;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.dto.AddTemporaryDishesDTO;
|
import com.chaozhanggui.system.cashierservice.entity.dto.*;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.dto.ChoseCountDTO;
|
|
||||||
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnCartDTO;
|
|
||||||
import com.chaozhanggui.system.cashierservice.entity.dto.UpdateVipDTO;
|
|
||||||
import com.chaozhanggui.system.cashierservice.entity.vo.CartVo;
|
import com.chaozhanggui.system.cashierservice.entity.vo.CartVo;
|
||||||
import com.chaozhanggui.system.cashierservice.service.OrderService;
|
import com.chaozhanggui.system.cashierservice.service.OrderService;
|
||||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||||
|
|
@ -45,7 +42,7 @@ public class OrderController {
|
||||||
String userId = jsonObject.getString("accountId");
|
String userId = jsonObject.getString("accountId");
|
||||||
return orderService.createCart(cartVo.getMasterId(), cartVo.getProductId(), cartVo.getShopId(), cartVo.getSkuId(),
|
return orderService.createCart(cartVo.getMasterId(), cartVo.getProductId(), cartVo.getShopId(), cartVo.getSkuId(),
|
||||||
cartVo.getNumber(), userId, clientType, cartVo.getCartId(), cartVo.getIsGift(),
|
cartVo.getNumber(), userId, clientType, cartVo.getCartId(), cartVo.getIsGift(),
|
||||||
cartVo.getIsPack(), cartVo.getUuid(), cartVo.getType(), cartVo.getTableId());
|
cartVo.getIsPack(), cartVo.getUuid(), cartVo.getType(), cartVo.getTableId(), cartVo.getIsPrint());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/temporaryDishes")
|
@PostMapping("/temporaryDishes")
|
||||||
|
|
@ -53,6 +50,11 @@ public class OrderController {
|
||||||
return Result.success(CodeEnum.SUCCESS, orderService.addTemporaryDishes(temporaryDishesDTO));
|
return Result.success(CodeEnum.SUCCESS, orderService.addTemporaryDishes(temporaryDishesDTO));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PutMapping("/updatePrice")
|
||||||
|
public Result updatePrice(@Valid @RequestBody UpdatePriceDTO updatePriceDTO) {
|
||||||
|
return Result.success(CodeEnum.SUCCESS, orderService.updatePrice(updatePriceDTO));
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/queryCart")
|
@GetMapping("/queryCart")
|
||||||
public Result queryCart(@RequestHeader("token") String token,
|
public Result queryCart(@RequestHeader("token") String token,
|
||||||
@RequestHeader("loginName") String loginName,
|
@RequestHeader("loginName") String loginName,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.chaozhanggui.system.cashierservice.entity.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.DecimalMin;
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UpdatePriceDTO {
|
||||||
|
@NotNull
|
||||||
|
private Integer shopId;
|
||||||
|
@NotNull
|
||||||
|
private Integer cartId;
|
||||||
|
@DecimalMin("0.01")
|
||||||
|
@NotNull
|
||||||
|
private BigDecimal amount;
|
||||||
|
@NotBlank(message = "折扣原因不能为空")
|
||||||
|
private String note;
|
||||||
|
}
|
||||||
|
|
@ -26,4 +26,5 @@ public class CartVo {
|
||||||
private String masterId;
|
private String masterId;
|
||||||
private String tableId;
|
private String tableId;
|
||||||
private Integer orderId;
|
private Integer orderId;
|
||||||
|
private Boolean isPrint;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.TbShopPermission;
|
import com.chaozhanggui.system.cashierservice.entity.TbShopPermission;
|
||||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -37,5 +38,12 @@ public interface MpOrderDetailService extends IService<TbOrderDetail> {
|
||||||
* @param orderId 订单id
|
* @param orderId 订单id
|
||||||
*/
|
*/
|
||||||
boolean removeByOrderId(Integer orderId);
|
boolean removeByOrderId(Integer orderId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据购物车id修改detail价格
|
||||||
|
* @param cartId 购物车id
|
||||||
|
* @param totalAmount 总价格
|
||||||
|
*/
|
||||||
|
boolean updatePriceByCartId(Integer cartId, BigDecimal saleAmount, BigDecimal totalAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import com.chaozhanggui.system.cashierservice.bean.constant.TableConstant;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail;
|
import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo;
|
import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -23,5 +24,8 @@ public interface MpOrderInfoService extends IService<TbOrderInfo> {
|
||||||
* @return 是否成功
|
* @return 是否成功
|
||||||
*/
|
*/
|
||||||
boolean updateStateById(Integer shopId, Integer orderId, TableConstant.Status status);
|
boolean updateStateById(Integer shopId, Integer orderId, TableConstant.Status status);
|
||||||
|
|
||||||
|
boolean incrAmount(Integer orderId, BigDecimal subtract);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -209,7 +209,7 @@ public class OrderService {
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Result createCart(String masterId, Integer productId, Integer shopId, Integer skuId, BigDecimal number,
|
public Result createCart(String masterId, Integer productId, Integer shopId, Integer skuId, BigDecimal number,
|
||||||
String userId, String clientType, Integer cartId, String isGift, String isPack, String uuid, String type, String tableId) {
|
String userId, String clientType, Integer cartId, String isGift, String isPack, String uuid, String type, String tableId, Boolean isPrint) {
|
||||||
if (number == null) {
|
if (number == null) {
|
||||||
return Result.fail(CodeEnum.PARAM);
|
return Result.fail(CodeEnum.PARAM);
|
||||||
}
|
}
|
||||||
|
|
@ -336,6 +336,7 @@ public class OrderService {
|
||||||
cart.setTotalNumber(number);
|
cart.setTotalNumber(number);
|
||||||
cart.resetTotalAmount();
|
cart.resetTotalAmount();
|
||||||
cart.setUuid(uuid);
|
cart.setUuid(uuid);
|
||||||
|
cart.setIsPrint(isPrint);
|
||||||
cashierCartMapper.updateByPrimaryKeySelective(cart);
|
cashierCartMapper.updateByPrimaryKeySelective(cart);
|
||||||
} else {
|
} else {
|
||||||
List<TbCashierCart> list = cashierCartMapper.selectALlByMasterId(masterId, "create");
|
List<TbCashierCart> list = cashierCartMapper.selectALlByMasterId(masterId, "create");
|
||||||
|
|
@ -362,6 +363,7 @@ public class OrderService {
|
||||||
cashierCart.setMemberPrice(skuWithBLOBs.getMemberPrice());
|
cashierCart.setMemberPrice(skuWithBLOBs.getMemberPrice());
|
||||||
cashierCart.setIsMember(0);
|
cashierCart.setIsMember(0);
|
||||||
}
|
}
|
||||||
|
cashierCart.setIsPrint(isPrint);
|
||||||
cashierCart.setShopId(shopId.toString());
|
cashierCart.setShopId(shopId.toString());
|
||||||
cashierCart.setTradeDay(DateUtils.getDay());
|
cashierCart.setTradeDay(DateUtils.getDay());
|
||||||
cashierCart.setStatus("create");
|
cashierCart.setStatus("create");
|
||||||
|
|
@ -399,7 +401,7 @@ public class OrderService {
|
||||||
} else {
|
} else {
|
||||||
cashierCart.setNumber(number);
|
cashierCart.setNumber(number);
|
||||||
}
|
}
|
||||||
|
cashierCart.setIsPrint(isPrint);
|
||||||
cashierCart.resetTotalAmount();
|
cashierCart.resetTotalAmount();
|
||||||
mpCashierCartMapper.updateById(cashierCart);
|
mpCashierCartMapper.updateById(cashierCart);
|
||||||
}
|
}
|
||||||
|
|
@ -2092,4 +2094,36 @@ public class OrderService {
|
||||||
}
|
}
|
||||||
return tbCashierCart;
|
return tbCashierCart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object updatePrice(UpdatePriceDTO updatePriceDTO) {
|
||||||
|
TbCashierCart cashierCart = mpCashierCartService.selectByShopIdAndId(updatePriceDTO.getShopId(), updatePriceDTO.getCartId(), TableConstant.OrderInfo.Status.CREATE);
|
||||||
|
if (cashierCart == null) {
|
||||||
|
throw new MsgException("购物车商品不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cashierCart.getIsMember() == 0) {
|
||||||
|
if (cashierCart.getSalePrice().subtract(updatePriceDTO.getAmount()).compareTo(BigDecimal.ZERO) < 0) {
|
||||||
|
throw new MsgException("折扣金额不能超过单价");
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
if (cashierCart.getMemberPrice().subtract(updatePriceDTO.getAmount()).compareTo(BigDecimal.ZERO) < 0) {
|
||||||
|
throw new MsgException("折扣金额不能超过单价");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BigDecimal oldAmount = cashierCart.getTotalAmount();
|
||||||
|
cashierCart.setDiscountSaleAmount(updatePriceDTO.getAmount());
|
||||||
|
cashierCart.resetTotalAmount();
|
||||||
|
cashierCart.setUpdatedAt(DateUtil.date().getTime());
|
||||||
|
cashierCart.setDiscountSaleNote(updatePriceDTO.getNote());
|
||||||
|
cashierCart.setDiscountSaleAmount(updatePriceDTO.getAmount());
|
||||||
|
mpCashierCartService.updateById(cashierCart);
|
||||||
|
|
||||||
|
// 更新订单和detail价格
|
||||||
|
if (cashierCart.getOrderId() != null) {
|
||||||
|
mpOrderDetailService.updatePriceByCartId(cashierCart.getId(), updatePriceDTO.getAmount(), cashierCart.getTotalAmount());
|
||||||
|
mpOrderInfoService.incrAmount(cashierCart.getOrderId(), cashierCart.getTotalAmount().subtract(oldAmount));
|
||||||
|
}
|
||||||
|
return cashierCart;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -50,5 +51,13 @@ public class MpOrderDetailServiceImpl extends ServiceImpl<MPOrderDetailMapper, T
|
||||||
return remove(new LambdaQueryWrapper<TbOrderDetail>()
|
return remove(new LambdaQueryWrapper<TbOrderDetail>()
|
||||||
.eq(TbOrderDetail::getOrderId, orderId));
|
.eq(TbOrderDetail::getOrderId, orderId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updatePriceByCartId(Integer cartId, BigDecimal saleAmount, BigDecimal totalAmount) {
|
||||||
|
return update(new LambdaUpdateWrapper<TbOrderDetail>()
|
||||||
|
.eq(TbOrderDetail::getCartId, cartId)
|
||||||
|
.set(TbOrderDetail::getPrice, saleAmount)
|
||||||
|
.set(TbOrderDetail::getPriceAmount, totalAmount));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.chaozhanggui.system.cashierservice.service.impl;
|
package com.chaozhanggui.system.cashierservice.service.impl;
|
||||||
|
|
||||||
import cn.hutool.Hutool;
|
import cn.hutool.Hutool;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.chaozhanggui.system.cashierservice.bean.constant.TableConstant;
|
import com.chaozhanggui.system.cashierservice.bean.constant.TableConstant;
|
||||||
|
|
@ -12,6 +13,7 @@ import com.chaozhanggui.system.cashierservice.service.MpOrderDetailService;
|
||||||
import com.chaozhanggui.system.cashierservice.service.MpOrderInfoService;
|
import com.chaozhanggui.system.cashierservice.service.MpOrderInfoService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -30,5 +32,18 @@ public class MpOrderInfoServiceImpl extends ServiceImpl<MPOrderInfoMapper, TbOrd
|
||||||
.eq(TbOrderInfo::getId, orderId)
|
.eq(TbOrderInfo::getId, orderId)
|
||||||
.set(TbOrderInfo::getStatus, status.getValue()));
|
.set(TbOrderInfo::getStatus, status.getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean incrAmount(Integer orderId, BigDecimal subtract) {
|
||||||
|
return update(new LambdaUpdateWrapper<TbOrderInfo>()
|
||||||
|
.eq(TbOrderInfo::getId, orderId)
|
||||||
|
.eq(TbOrderInfo::getStatus, TableConstant.OrderInfo.Status.UNPAID.getValue())
|
||||||
|
.apply(StrUtil.format("settlement_amount + {} >= 0", subtract))
|
||||||
|
.setSql(StrUtil.format("settlement_amount=settlement_amount+{}", subtract))
|
||||||
|
.setSql(StrUtil.format("order_amount=order_amount+{}", subtract))
|
||||||
|
.setSql(StrUtil.format("amount=amount+{}", subtract))
|
||||||
|
.setSql(StrUtil.format("origin_amount=origin_amount+{}", subtract))
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue