Compare commits
61 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
edb952695e | ||
|
|
9921d69425 | ||
|
|
f5e2be62af | ||
|
|
01225c8065 | ||
|
|
d98f2bdc64 | ||
|
|
f95d53611c | ||
|
|
56d1fbad0c | ||
|
|
aee40bef30 | ||
|
|
ae699246d0 | ||
|
|
7aed024853 | ||
|
|
eace580860 | ||
|
|
8a66e491cd | ||
|
|
cc830c8fec | ||
| 0a971b7f2b | |||
|
|
15241f4db2 | ||
|
|
13172e04bd | ||
| 546a9a77dc | |||
|
|
99c08437d9 | ||
|
|
d7915bce27 | ||
|
|
18e446083d | ||
|
|
41b6a18676 | ||
|
|
ec27167f8a | ||
|
|
8d125fddd3 | ||
|
|
267c000756 | ||
|
|
3f11d389af | ||
|
|
428791a1b6 | ||
|
|
c01dc329c9 | ||
|
|
bb386343ee | ||
|
|
3eef65777a | ||
|
|
d390054f07 | ||
|
|
b76f1f5620 | ||
|
|
b8d5195622 | ||
|
|
aa86e2a7d6 | ||
|
|
e1b4e2500a | ||
|
|
165e1fde14 | ||
|
|
d253b6d8fb | ||
|
|
32616ce3c5 | ||
|
|
e5e3bbc9f8 | ||
| 4e922fc3be | |||
| 879e574cad | |||
|
|
d9fc12fdeb | ||
|
|
976ce313c5 | ||
|
|
836b384f9c | ||
|
|
7a0e0f1343 | ||
|
|
ff4ed58506 | ||
|
|
a4c3b3392d | ||
|
|
eae6676b6c | ||
| a2b9f98ea1 | |||
| dc63edfcf0 | |||
| b12258a7dc | |||
| c83155919c | |||
|
|
43303a76af | ||
|
|
40f90128ab | ||
|
|
0c414c8130 | ||
| 8bb0357190 | |||
|
|
3c7ab7eaef | ||
|
|
0d57d1b8ba | ||
|
|
6654c091d6 | ||
|
|
df5215a876 | ||
|
|
55adcacc4c | ||
|
|
927bef9602 |
@@ -19,6 +19,23 @@ public interface TableConstant {
|
||||
}
|
||||
}
|
||||
|
||||
class Product {
|
||||
@Getter
|
||||
public enum Type {
|
||||
NORMAL("normal"), PACKAGE("package");
|
||||
private final String value;
|
||||
|
||||
Type(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public boolean equalsVals(String value) {
|
||||
return this.value.equals(value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class CashierCart {
|
||||
public static final String ID = "-999";
|
||||
|
||||
|
||||
@@ -80,6 +80,11 @@ public class TbCashierCart implements Serializable {
|
||||
private Integer isMember;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private String useCouponInfo;
|
||||
private String proGroupInfo;
|
||||
private String typeEnum;
|
||||
private Integer groupType;
|
||||
private int isWeight;
|
||||
|
||||
public String getSkuName() {
|
||||
if(StringUtils.isNotBlank(skuName)){
|
||||
@@ -112,4 +117,5 @@ public class TbCashierCart implements Serializable {
|
||||
return BigDecimal.valueOf(num).multiply(salePrice);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,5 +49,9 @@ public class TbOrderDetail implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Integer isMember;
|
||||
private String useCouponInfo;
|
||||
private BigDecimal canReturnAmount;
|
||||
private String proGroupInfo;
|
||||
private int isWeight;
|
||||
|
||||
}
|
||||
|
||||
@@ -135,6 +135,7 @@ public class TbOrderInfo implements Serializable {
|
||||
private BigDecimal productCouponDiscountAmount;
|
||||
private String couponInfoList;
|
||||
private int isPostpaid;
|
||||
private Object useCouponInfo;
|
||||
|
||||
public void setDescription(String shopName) {
|
||||
this.shopName = shopName;
|
||||
|
||||
@@ -192,7 +192,6 @@ public class TbProduct implements Serializable {
|
||||
|
||||
@Transient
|
||||
private TbProductSkuResult productSkuResult;
|
||||
|
||||
private List<ProductGroupVo> proGroupVo;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.chaozhanggui.system.cashierservice.entity.dto;
|
||||
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbActivateOutRecord;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class OrderInfoCouponInfoDTO {
|
||||
private List<TbActivateOutRecord> outRecordList;
|
||||
private Collection<OrderInfoUserCouponVo> fullReductionCoupon;
|
||||
private Collection<OrderInfoUserCouponVo> productCoupon;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.chaozhanggui.system.cashierservice.entity.dto;
|
||||
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.TbUserCouponVo;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class OrderInfoUserCouponVo extends TbUserCouponVo {
|
||||
private int returnNum = 0;
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -18,7 +19,7 @@ public class OrderVo {
|
||||
private String tableName;
|
||||
private String shopQrcode;
|
||||
|
||||
private List<TbOrderDetail> details;
|
||||
private Collection<TbOrderDetail> details;
|
||||
|
||||
private String cartListString;
|
||||
private String orderNo;
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.chaozhanggui.system.cashierservice.entity.Enum.PlatformTypeEnum;
|
||||
import com.chaozhanggui.system.cashierservice.entity.Enum.ShopWxMsgTypeEnum;
|
||||
import com.chaozhanggui.system.cashierservice.entity.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.ProductGroupVo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.TbUserCouponVo;
|
||||
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||
import com.chaozhanggui.system.cashierservice.mapper.MpCashierCartMapper;
|
||||
@@ -281,6 +282,90 @@ public class CartService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置购物车套餐商品信息
|
||||
*/
|
||||
private void resetGroupProductCart(List<Integer> productIds, TbCashierCart cashierCart) {
|
||||
if (StrUtil.isBlank(cashierCart.getProductId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
TbProduct product = productMapper.selectById(Integer.valueOf(cashierCart.getProductId()));
|
||||
|
||||
resetCartInfo(productIds, product, cashierCart);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置购物车套餐商品信息
|
||||
*/
|
||||
private void resetGroupProductCart(List<Integer> productIds, TbProduct product, TbCashierCart cashierCart) {
|
||||
if (StrUtil.isBlank(cashierCart.getProductId())) {
|
||||
return;
|
||||
}
|
||||
resetCartInfo(productIds, product, cashierCart);
|
||||
}
|
||||
|
||||
private void resetCartInfo(List<Integer> productIds, TbProduct product, TbCashierCart cashierCart) {
|
||||
boolean isChoseGroup = TableConstant.Product.Type.PACKAGE.equalsVals(product.getType()) && product.getGroupType() == 1;
|
||||
boolean isFixGroup = TableConstant.Product.Type.PACKAGE.equalsVals(product.getType()) && product.getGroupType() == 0;
|
||||
if (isChoseGroup && productIds != null && !productIds.isEmpty()) {
|
||||
String groupSnap = product.getGroupSnap();
|
||||
if (StrUtil.isNotBlank(groupSnap)) {
|
||||
ArrayList<ProductGroupVo.Food> foods = new ArrayList<>();
|
||||
HashMap<String, ProductGroupVo.Food> groupVoHashMap = new HashMap<>();
|
||||
JSONObject.parseArray(groupSnap).forEach(item -> {
|
||||
ProductGroupVo productGroupVo = ((JSONObject) item).toJavaObject(ProductGroupVo.class);
|
||||
productGroupVo.getGoods().forEach(goods -> {
|
||||
groupVoHashMap.put(goods.getProId().toString(), goods);
|
||||
});
|
||||
});
|
||||
|
||||
productIds.forEach(item -> {
|
||||
ProductGroupVo.Food food = groupVoHashMap.get(item.toString());
|
||||
if (food == null) {
|
||||
throw new MsgException("存在无效套餐商品");
|
||||
}
|
||||
foods.add(food);
|
||||
});
|
||||
|
||||
cashierCart.setProGroupInfo(JSONObject.toJSONString(foods));
|
||||
}
|
||||
}else if (isFixGroup) {
|
||||
String groupSnap = product.getGroupSnap();
|
||||
if (StrUtil.isNotBlank(groupSnap)) {
|
||||
ArrayList<ProductGroupVo.Food> foods = new ArrayList<>();
|
||||
HashMap<String, ProductGroupVo.Food> groupVoHashMap = new HashMap<>();
|
||||
JSONObject.parseArray(groupSnap).forEach(item -> {
|
||||
ProductGroupVo productGroupVo = ((JSONObject) item).toJavaObject(ProductGroupVo.class);
|
||||
productGroupVo.getGoods().forEach(goods -> {
|
||||
groupVoHashMap.put(goods.getProId().toString(), goods);
|
||||
});
|
||||
});
|
||||
|
||||
cashierCart.setProGroupInfo(JSONObject.toJSONString(groupVoHashMap.values()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private TbCashierCart getCartByCache(String shopId, String tableId, String userId, String skuId) {
|
||||
String tableCartKey = RedisCst.getTableCartKey(shopId, tableId, userId);
|
||||
if (!redisUtil.exists(tableCartKey)) {
|
||||
return null;
|
||||
}
|
||||
JSONArray array = JSON.parseArray(redisUtil.getMessage(tableCartKey));
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
JSONObject object = array.getJSONObject(i);
|
||||
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
|
||||
cashierCart.setPlaceNum(cashierCart.getPlaceNum() == null ? 0 : cashierCart.getPlaceNum());
|
||||
|
||||
if (cashierCart.getSkuId().equals(skuId)) {
|
||||
return cashierCart;
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加入购物车
|
||||
*
|
||||
@@ -295,15 +380,19 @@ public class CartService {
|
||||
Integer type = jsonObject.getInteger("type");
|
||||
Integer buyNum = jsonObject.getInteger("num");
|
||||
Integer userId = jsonObject.getInteger("userId");
|
||||
List<Integer> groupProductIdList = null;
|
||||
if (jsonObject.containsKey("groupProductIdList")) {
|
||||
groupProductIdList = jsonObject.getJSONArray("groupProductIdList").toJavaList(Integer.class);
|
||||
}
|
||||
// 商品备注
|
||||
String note = jsonObject.getString("note");
|
||||
if (StringUtils.isBlank(shopId) || StringUtils.isBlank(productId)
|
||||
|| StringUtils.isBlank(skuId) || type == null || buyNum == null) {
|
||||
|| type == null || buyNum == null) {
|
||||
return Result.fail("参数缺失");
|
||||
}
|
||||
|
||||
boolean isSeatCart = "-999".equals(productId);
|
||||
ShopEatTypeInfoDTO shopEatTypeInfoDTO = shopUtils.checkEatModel(tableId, shopId);
|
||||
ShopEatTypeInfoDTO shopEatTypeInfoDTO = shopUtils.getEatModel(tableId, shopId);
|
||||
String tableCartKey = RedisCst.getTableCartKey(shopId, tableId, userId);
|
||||
// 检查客座费并设置
|
||||
checkSeatInfo(shopEatTypeInfoDTO, tableId, userId);
|
||||
@@ -316,7 +405,7 @@ public class CartService {
|
||||
return Result.fail("该商品不存在");
|
||||
}
|
||||
// 判断商品是否已下架
|
||||
tbProductSkuWithBLOBs = productSkuMapper.selectByPrimaryKey(Integer.valueOf(skuId));
|
||||
tbProductSkuWithBLOBs = StrUtil.isBlank(skuId) ? null: productSkuMapper.selectByPrimaryKey(Integer.valueOf(skuId));
|
||||
if (tbProductSkuWithBLOBs == null || tbProductSkuWithBLOBs.getIsGrounding().equals(0)) {
|
||||
rmCart(jsonObject, skuId, tableCartKey);
|
||||
return Result.fail("商品已下架");
|
||||
@@ -350,12 +439,13 @@ public class CartService {
|
||||
BigDecimal amount = BigDecimal.ZERO;
|
||||
BigDecimal memberAmount = BigDecimal.ZERO;
|
||||
try {
|
||||
// 存在缓存
|
||||
if (redisUtil.exists(tableCartKey)) {
|
||||
JSONArray array = JSON.parseArray(redisUtil.getMessage(tableCartKey));
|
||||
if (Objects.isNull(array) || array.isEmpty()) {
|
||||
if (type == 1) {
|
||||
TbCashierCart cashierCart = addCart(productId, skuId,
|
||||
jsonObject.getInteger("userId"), buyNum, tableId, shopId, note, shopEatTypeInfoDTO);
|
||||
jsonObject.getInteger("userId"), buyNum, tableId, shopId, note, shopEatTypeInfoDTO, groupProductIdList);
|
||||
jsonArray.add(cashierCart);
|
||||
cashierCart.setPlaceNum(cashierCart.getPlaceNum() == null ? 0 : cashierCart.getPlaceNum());
|
||||
cashierCartArrayList.add(cashierCart);
|
||||
@@ -374,7 +464,9 @@ public class CartService {
|
||||
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
|
||||
cashierCart.setPlaceNum(cashierCart.getPlaceNum() == null ? 0 : cashierCart.getPlaceNum());
|
||||
|
||||
if (cashierCart.getSkuId().equals(skuId)) {
|
||||
if (cashierCart.getSkuId().equals(skuId) && (cashierCart.getGroupType() == null || cashierCart.getGroupType() == 0)) {
|
||||
resetGroupProductCart(groupProductIdList, cashierCart);
|
||||
|
||||
cashierCart.setTotalNumber(buyNum);
|
||||
cashierCart.setNumber(buyNum);
|
||||
cashierCart.setNote(note);
|
||||
@@ -402,11 +494,7 @@ public class CartService {
|
||||
product.getPackFee().multiply(BigDecimal.valueOf(buyNum)) : BigDecimal.ZERO);
|
||||
|
||||
}
|
||||
// if (isVip != null && isVip == 1) {
|
||||
// cashierCart.setTotalAmount(BigDecimal.ZERO);
|
||||
// } else {
|
||||
cashierCart.resetTotalAmount();
|
||||
// }
|
||||
cashierCart.setUpdatedAt(Instant.now().toEpochMilli());
|
||||
mpCashierCartMapper.updateById(cashierCart);
|
||||
} else {
|
||||
@@ -421,15 +509,11 @@ public class CartService {
|
||||
BigDecimal mPrice = cashierCart.getIsMember() != null && cashierCart.getIsMember() == 1 &&
|
||||
cashierCart.getMemberPrice() != null && cashierCart.getMemberPrice().compareTo(BigDecimal.ZERO) > 0 ? cashierCart.getMemberPrice() : cashierCart.getSalePrice();
|
||||
memberAmount = memberAmount.add(mPrice.multiply(BigDecimal.valueOf(cashierCart.getTotalNumber())).add(cashierCart.getPackFee()));
|
||||
|
||||
if ("-999".equals(cashierCart.getProductId())) {
|
||||
hasSeat = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (flag && type == 1) {
|
||||
TbCashierCart cashierCart = addCart(productId, skuId,
|
||||
jsonObject.getInteger("userId"), buyNum, tableId, shopId, note, shopEatTypeInfoDTO);
|
||||
jsonObject.getInteger("userId"), buyNum, tableId, shopId, note, shopEatTypeInfoDTO, groupProductIdList);
|
||||
jsonArray.add(cashierCart);
|
||||
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
|
||||
BigDecimal mPrice = cashierCart.getIsMember() != null && cashierCart.getIsMember() == 1 &&
|
||||
@@ -439,10 +523,12 @@ public class CartService {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 不存在缓存
|
||||
} else {
|
||||
if (type == 1) {
|
||||
TbCashierCart cashierCart = addCart(productId, skuId,
|
||||
jsonObject.getInteger("userId"), buyNum, tableId, shopId, note, shopEatTypeInfoDTO);
|
||||
jsonObject.getInteger("userId"), buyNum, tableId, shopId, note, shopEatTypeInfoDTO, groupProductIdList);
|
||||
if (!TableConstant.CART_SEAT_ID.equals(productId)) {
|
||||
jsonArray.add(cashierCart);
|
||||
}
|
||||
@@ -577,7 +663,7 @@ public class CartService {
|
||||
}
|
||||
|
||||
private TbCashierCart addCart(String productId, String skuId, Integer userId, Integer num,
|
||||
String tableId, String shopId, String note, ShopEatTypeInfoDTO shopEatTypeInfoDTO) throws Exception {
|
||||
String tableId, String shopId, String note, ShopEatTypeInfoDTO shopEatTypeInfoDTO, List<Integer> groupProductIds) throws Exception {
|
||||
try {
|
||||
// 查询用户信息
|
||||
TbShopUser shopUser = shopUserMapper.selectByUserIdAndShopId(String.valueOf(userId), shopId);
|
||||
@@ -612,6 +698,9 @@ public class CartService {
|
||||
cashierCart.setNumber(num);
|
||||
cashierCart.setTotalNumber(num);
|
||||
}
|
||||
cashierCart.setIsWeight("weigh".equals(product.getType()) ? 1 : 0);
|
||||
cashierCart.setTypeEnum(product.getTypeEnum());
|
||||
cashierCart.setGroupType(product.getGroupType());
|
||||
cashierCart.setNote(note);
|
||||
cashierCart.setProductId(productId);
|
||||
cashierCart.setSkuId(skuId);
|
||||
@@ -631,8 +720,8 @@ public class CartService {
|
||||
cashierCart.setUpdatedAt(Instant.now().toEpochMilli());
|
||||
cashierCart.setPackFee(BigDecimal.ZERO);
|
||||
cashierCart.setRefundNumber(0);
|
||||
cashierCart.setMemberPrice(productSku.getMemberPrice());
|
||||
if (shopEatTypeInfoDTO.isMemberPrice() && shopUser.getIsVip() == 1) {
|
||||
cashierCart.setMemberPrice(productSku.getMemberPrice());
|
||||
cashierCart.setIsMember(1);
|
||||
}
|
||||
cashierCart.setTradeDay(DateUtils.getDay());
|
||||
@@ -643,6 +732,7 @@ public class CartService {
|
||||
cashierCart.setIsVip((byte) 0);
|
||||
cashierCart.resetTotalAmount();
|
||||
cashierCart.setPlatformType(PlatformTypeEnum.MINI_APP.getValue());
|
||||
resetGroupProductCart(groupProductIds, product, cashierCart);
|
||||
mpCashierCartMapper.insert(cashierCart);
|
||||
|
||||
//修改耗材数据
|
||||
@@ -913,26 +1003,32 @@ public class CartService {
|
||||
}
|
||||
}
|
||||
|
||||
private BigDecimal calcPointsDiscountAndReturn(TbOrderInfo orderInfo, int pointsNum) {
|
||||
private BigDecimal calcPointsDiscountAndReturn(TbOrderInfo orderInfo, Integer pointsNum) {
|
||||
Long memberId = Long.valueOf(orderInfo.getMemberId());
|
||||
|
||||
if (orderInfo.getPointsNum() != null && orderInfo.getPointsNum() != 0) {
|
||||
memberPointsService.addPoints(memberId, orderInfo.getPointsNum(), "用户未支付订单积分返还: " + orderInfo.getPointsNum() + "积分", Long.valueOf(orderInfo.getId()), orderInfo.getOrderNo());
|
||||
orderInfo.setPointsNum(0);
|
||||
orderInfo.setPointsDiscountAmount(BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
OrderDeductionPointsDTO memberUsablePoints = memberPointsService.getMemberUsablePoints(memberId, orderInfo.getOrderAmount());
|
||||
if (!memberUsablePoints.getUsable()) {
|
||||
throw new MsgException(memberUsablePoints.getUnusableReason());
|
||||
}
|
||||
if (pointsNum < memberUsablePoints.getMinDeductionPoints() || pointsNum > memberUsablePoints.getMaxUsablePoints()) {
|
||||
throw new MsgException("可抵扣积分区间为: [" + memberUsablePoints.getMinDeductionPoints() + "-" + memberUsablePoints.getMaxUsablePoints() + "]");
|
||||
}
|
||||
if (pointsNum != null) {
|
||||
OrderDeductionPointsDTO memberUsablePoints = memberPointsService.getMemberUsablePoints(memberId, orderInfo.getOrderAmount());
|
||||
if (!memberUsablePoints.getUsable()) {
|
||||
throw new MsgException(memberUsablePoints.getUnusableReason());
|
||||
}
|
||||
if (pointsNum < memberUsablePoints.getMinDeductionPoints() || pointsNum > memberUsablePoints.getMaxUsablePoints()) {
|
||||
throw new MsgException("可抵扣积分区间为: [" + memberUsablePoints.getMinDeductionPoints() + "-" + memberUsablePoints.getMaxUsablePoints() + "]");
|
||||
}
|
||||
|
||||
BigDecimal discountAmount = memberPointsService.calcDeductionAmount(memberId, orderInfo.getOrderAmount(), pointsNum);
|
||||
orderInfo.setPointsNum(pointsNum);
|
||||
orderInfo.setPointsDiscountAmount(discountAmount);
|
||||
memberPointsService.deductPoints(memberId, pointsNum, "订单积分抵扣" + discountAmount + "元", Long.valueOf(orderInfo.getId()));
|
||||
return discountAmount;
|
||||
BigDecimal discountAmount = memberPointsService.calcDeductionAmount(memberId, orderInfo.getOrderAmount(), pointsNum);
|
||||
orderInfo.setPointsNum(pointsNum);
|
||||
orderInfo.setPointsDiscountAmount(discountAmount);
|
||||
memberPointsService.deductPoints(memberId, pointsNum, "订单积分抵扣" + discountAmount + "元", Long.valueOf(orderInfo.getId()));
|
||||
return discountAmount;
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private TbActivateOutRecord calcOrderInfoDiscount(CreateOrderDTO orderDTO, TbOrderInfo orderInfo, OrderCouponInfoDTO couponInfo, Integer memberId) {
|
||||
@@ -957,8 +1053,8 @@ public class CartService {
|
||||
}
|
||||
|
||||
// 计算积分优惠
|
||||
if (orderDTO.getPointsNum() != null && orderDTO.getPointsNum() != 0) {
|
||||
BigDecimal discountPointsAmount = calcPointsDiscountAndReturn(orderInfo, orderDTO.getPointsNum());
|
||||
BigDecimal discountPointsAmount = calcPointsDiscountAndReturn(orderInfo, orderDTO.getPointsNum());
|
||||
if (discountPointsAmount != null) {
|
||||
finalAmount = finalAmount.subtract(discountPointsAmount);
|
||||
orderInfo.setPointsDiscountAmount(discountPointsAmount);
|
||||
}
|
||||
@@ -1100,6 +1196,7 @@ public class CartService {
|
||||
|
||||
if (orderDetail == null) {
|
||||
orderDetail = new TbOrderDetail();
|
||||
orderDetail.setStatus(TableConstant.CashierCart.Status.RETURN.equalsVals(cashierCart.getStatus()) ? cashierCart.getStatus() : "unpaid");
|
||||
priceDTO.setHasNewInfo(true);
|
||||
priceDTO.getNewOrderDetailList().add(orderDetail);
|
||||
}
|
||||
@@ -1108,6 +1205,8 @@ public class CartService {
|
||||
orderDetail.setProductSkuName(productSku.getSpecSnap());
|
||||
}
|
||||
|
||||
orderDetail.setIsWeight(cashierCart.getIsWeight());
|
||||
orderDetail.setProGroupInfo(cashierCart.getProGroupInfo());
|
||||
orderDetail.setMemberPrice(cashierCart.getMemberPrice());
|
||||
orderDetail.setNote(cashierCart.getNote());
|
||||
orderDetail.setCreateTime(DateUtil.date().toTimestamp());
|
||||
@@ -1131,6 +1230,7 @@ public class CartService {
|
||||
}
|
||||
orderDetail.setOrderId(orderId);
|
||||
orderDetail.setIsMember(cashierCart.getIsMember());
|
||||
orderDetail.setUseCouponInfo(cashierCart.getUseCouponInfo());
|
||||
|
||||
priceDTO.getOrderDetailList().add(orderDetail);
|
||||
}
|
||||
@@ -1188,6 +1288,7 @@ public class CartService {
|
||||
balanceCart.setTotalNumber(balanceNum);
|
||||
balanceCart.setPackFee(singlePackFee.multiply(num));
|
||||
balanceCart.setTotalAmount(cashierCart.getSalePrice().multiply(num).add(balanceCart.getPackFee()));
|
||||
balanceCart.resetTotalAmount();
|
||||
balanceCartList.add(balanceCart);
|
||||
} else {
|
||||
currentUseNum = BigDecimal.valueOf(cashierCart.getNumber());
|
||||
@@ -1207,11 +1308,21 @@ public class CartService {
|
||||
tbActivateOutRecord.setCreateTime(DateUtil.date());
|
||||
tbActivateOutRecord.setRefNum(0);
|
||||
outRecords.add(tbActivateOutRecord);
|
||||
|
||||
cashierCart.setUseCouponInfo(JSONObject.toJSONString(tbActivateOutRecord));
|
||||
couponVo.setFinalDiscountAmount(discountAmount);
|
||||
|
||||
// 优惠券未消耗完毕
|
||||
if (balanceCart != null && getCanUseCoupon(couponMap, balanceCart.getProductId()) != null) {
|
||||
discountAmount = reduceProCoupon(couponMap, balanceCart, usedCouponMap, discountAmount, balanceCartList, outRecords, memberId);
|
||||
// 递归调用并累加递归返回的折扣金额
|
||||
discountAmount = discountAmount.add(reduceProCoupon(
|
||||
couponMap,
|
||||
balanceCart,
|
||||
usedCouponMap,
|
||||
BigDecimal.ZERO, // 避免重复累加,递归时传入新的初始值
|
||||
balanceCartList,
|
||||
outRecords,
|
||||
memberId
|
||||
));
|
||||
}
|
||||
return discountAmount;
|
||||
}
|
||||
@@ -1245,12 +1356,13 @@ public class CartService {
|
||||
HashMap<String, List<TbUserCouponVo>> usedCouponMap = new HashMap<>();
|
||||
ArrayList<TbActivateOutRecord> outRecords = new ArrayList<>();
|
||||
ArrayList<TbCashierCart> resetCouponList = new ArrayList<>();
|
||||
for (TbCashierCart cashierCart : cartInfoDTO.getNewCashierCarts()) {
|
||||
for (TbCashierCart cashierCart : cartInfoDTO.getCashierCarts()) {
|
||||
if (!couponMap.isEmpty()) {
|
||||
resetCouponList.add(cashierCart);
|
||||
cashierCart.setUserCouponId(null);
|
||||
}
|
||||
discountAmount = reduceProCoupon(couponMap, cashierCart, usedCouponMap, discountAmount, balanceCartList, outRecords, memberId);
|
||||
cashierCart.resetTotalAmount();
|
||||
discountAmount = discountAmount.add(reduceProCoupon(couponMap, cashierCart, usedCouponMap, BigDecimal.ZERO, balanceCartList, outRecords, memberId));
|
||||
}
|
||||
|
||||
if (!balanceCartList.isEmpty()) {
|
||||
@@ -1261,7 +1373,6 @@ public class CartService {
|
||||
// 更新购物车信息
|
||||
if (!resetCouponList.isEmpty()) {
|
||||
// 取消之前使用的历史券
|
||||
|
||||
ArrayList<Integer> resetCartIds = new ArrayList<>();
|
||||
resetCouponList.forEach(item -> {
|
||||
if (item.getUserCouponId() == null) {
|
||||
@@ -1290,6 +1401,8 @@ public class CartService {
|
||||
TbCashierCart seatInfo = null;
|
||||
Integer orderId = null;
|
||||
for (TbCashierCart tbCashierCart : allCartList) {
|
||||
tbCashierCart.setUserCouponId(null);
|
||||
tbCashierCart.setUseCouponInfo(null);
|
||||
tbCashierCart.setUseType(shopEatTypeInfoDTO.getUseType());
|
||||
cashierIds.add(tbCashierCart.getId());
|
||||
// 设置会员信息及价格
|
||||
@@ -1298,7 +1411,7 @@ public class CartService {
|
||||
} else {
|
||||
if (!TableConstant.CashierCart.ID.equals(tbCashierCart.getProductId())) {
|
||||
TbProductSkuWithBLOBs sku = productSkuMapper.selectByPrimaryKey(Integer.valueOf(tbCashierCart.getSkuId()));
|
||||
tbCashierCart.setIsMember(sku.getMemberPrice() != null && sku.getMemberPrice().compareTo(BigDecimal.ZERO) > 0 ? 1 : 0);
|
||||
tbCashierCart.setIsMember(!shopEatTypeInfoDTO.isMemberPrice() ? 0 : 1);
|
||||
}
|
||||
}
|
||||
tbCashierCart.resetTotalAmount();
|
||||
@@ -1328,16 +1441,6 @@ public class CartService {
|
||||
throw new MsgException("请选择就餐人数");
|
||||
}
|
||||
if (allCartList.isEmpty() || (shopEatTypeInfoDTO.isNeedSeatFee() && allCartList.size() < 2)) {
|
||||
// log.info("消息推送");
|
||||
// JSONObject responseData = new JSONObject();
|
||||
// responseData.put("msg", "购物车为空");
|
||||
// if (shopTable.getMaxCapacity() < seatNum) {
|
||||
// responseData.put("msg", "当前台桌最大人数为: " + shopTable.getMaxCapacity());
|
||||
// }
|
||||
// responseData.put("status", "fail");
|
||||
// responseData.put("type", orderDTO.getType());
|
||||
// responseData.put("data", "");
|
||||
// PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(responseData.toString(), tableCartKey, userId, true);
|
||||
throw new MsgException("当前台桌最大人数为: " + shopTable.getMaxCapacity());
|
||||
}
|
||||
|
||||
@@ -1436,18 +1539,30 @@ public class CartService {
|
||||
// 获取台桌信息
|
||||
TbShopTable shopTable = getTableInfoByEatType(shopEatTypeInfoDTO);
|
||||
|
||||
// 获取详细的购物车信息
|
||||
OrderCartInfoDTO cartInfoDTO = getCartInfoForOrder(shopEatTypeInfoDTO, cashierCartList, shopTable, tbShopUser);
|
||||
|
||||
// 获取订单信息
|
||||
TbOrderInfo orderInfo = null;
|
||||
if (cartInfoDTO.getOrderId() != null) {
|
||||
orderInfo = mpOrderInfoMapper.selectById(cartInfoDTO.getOrderId());
|
||||
OrderCartInfoDTO cartInfoDTO = null;
|
||||
if (orderDTO.getOrderId() != null) {
|
||||
orderInfo = mpOrderInfoMapper.selectById(orderDTO.getOrderId());
|
||||
if (!"unpaid".equals(orderInfo.getStatus())) {
|
||||
return Result.fail("订单正在支付中,请稍后再试");
|
||||
}
|
||||
// 返还上次使用的券
|
||||
returnCoupon(orderInfo);
|
||||
cartInfoDTO = getCartInfoForOrder(shopEatTypeInfoDTO, cashierCartList, shopTable, tbShopUser);
|
||||
}else {
|
||||
// 获取详细的购物车信息
|
||||
cartInfoDTO = getCartInfoForOrder(shopEatTypeInfoDTO, cashierCartList, shopTable, tbShopUser);
|
||||
if (cartInfoDTO.getOrderId() != null) {
|
||||
orderInfo = mpOrderInfoMapper.selectById(cartInfoDTO.getOrderId());
|
||||
if (!"unpaid".equals(orderInfo.getStatus())) {
|
||||
return Result.fail("订单正在支付中,请稍后再试");
|
||||
}
|
||||
// 返还上次使用的券
|
||||
returnCoupon(orderInfo);
|
||||
}
|
||||
|
||||
cartInfoDTO = getCartInfoForOrder(shopEatTypeInfoDTO, cashierCartList, shopTable, tbShopUser);
|
||||
}
|
||||
|
||||
// 获取优惠券信息
|
||||
@@ -1484,13 +1599,28 @@ public class CartService {
|
||||
}
|
||||
|
||||
couponInfo.setProductCouponMap(BeanUtil.copyProperties(couponInfo.getProductCouponMap(), HashMap.class));
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("outRecordList", couponInfo.getOutRecordList());
|
||||
map.put("fullReductionCoupon", couponInfo.getFullReductionCouponMap().values());
|
||||
map.put("productCoupon", couponInfo.getProductCouponMap().values());
|
||||
orderInfo.setCouponInfoList(JSONObject.toJSONString(map));
|
||||
|
||||
OrderInfoCouponInfoDTO infoDTO = new OrderInfoCouponInfoDTO();
|
||||
infoDTO.setOutRecordList(couponInfo.getOutRecordList());
|
||||
|
||||
ArrayList<OrderInfoUserCouponVo> productArr = new ArrayList<>();
|
||||
couponInfo.getProductCouponMap().values().forEach(item -> {
|
||||
productArr.add(BeanUtil.copyProperties(item, OrderInfoUserCouponVo.class));
|
||||
});
|
||||
infoDTO.setProductCoupon(productArr);
|
||||
|
||||
ArrayList<OrderInfoUserCouponVo> fullArr = new ArrayList<>();
|
||||
couponInfo.getFullReductionCouponMap().values().forEach(item -> {
|
||||
fullArr.add(BeanUtil.copyProperties(item, OrderInfoUserCouponVo.class));
|
||||
});
|
||||
infoDTO.setFullReductionCoupon(fullArr);
|
||||
orderInfo.setCouponInfoList(JSONObject.toJSONString(infoDTO));
|
||||
}
|
||||
|
||||
|
||||
// 计算可退款金额
|
||||
updateOrderDetailCanReturn(detailPriceDTO.getOrderDetailList(), orderInfo);
|
||||
|
||||
// 修改订单详情并打票
|
||||
updateDetailAndPrint(orderInfo, detailPriceDTO, shopEatTypeInfoDTO, orderDTO.isOnlyChangeCoupon());
|
||||
|
||||
@@ -1524,12 +1654,37 @@ public class CartService {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateOrderDetailCanReturn(List<TbOrderDetail> orderDetailList, TbOrderInfo orderInfo) {
|
||||
orderDetailList = orderDetailList.stream().filter(item -> TableConstant.OrderInfo.Status.UNPAID.equalsVals(item.getStatus())).collect(Collectors.toList());
|
||||
BigDecimal totalAmount = BigDecimal.ZERO;
|
||||
BigDecimal lastAmount = BigDecimal.ZERO;
|
||||
BigDecimal lastReturnAmount = BigDecimal.ZERO;
|
||||
BigDecimal orderAmount = orderInfo.getOrderAmount();
|
||||
for (TbOrderDetail orderDetail : orderDetailList) {
|
||||
totalAmount = totalAmount.add(orderDetail.getPriceAmount());
|
||||
}
|
||||
for (TbOrderDetail item : orderDetailList) {
|
||||
if (StrUtil.isNotBlank(orderInfo.getCouponInfoList()) || orderInfo.getPointsNum() != null) {
|
||||
BigDecimal canReturnAmount = item.getPriceAmount().divide(totalAmount.subtract(lastAmount), 10, RoundingMode.HALF_DOWN)
|
||||
.multiply(orderAmount.subtract(lastReturnAmount)).setScale(2, RoundingMode.HALF_DOWN);
|
||||
lastReturnAmount = canReturnAmount;
|
||||
lastAmount = item.getPriceAmount();
|
||||
item.setCanReturnAmount(canReturnAmount);
|
||||
}else {
|
||||
item.setCanReturnAmount(item.getPriceAmount());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void returnCoupon(TbOrderInfo orderInfo) {
|
||||
// 返还优惠券
|
||||
PayService.returnCoupon(orderInfo, shopCouponService);
|
||||
PayService.returnCoupon(orderInfo, shopCouponService, mpCashierCartMapper);
|
||||
}
|
||||
|
||||
private void consumeCoupon(List<TbActivateOutRecord> outRecordList, Integer memberId, TbOrderInfo orderInfo) {
|
||||
if (outRecordList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
boolean use = shopCouponService.use(Integer.valueOf(orderInfo.getShopId()), orderInfo.getId(), memberId, outRecordList);
|
||||
if (!use) {
|
||||
throw new MsgException("消耗券失败");
|
||||
@@ -1607,7 +1762,7 @@ public class CartService {
|
||||
public List<TbCashierCart> choseEatModel(ChoseEatModelDTO choseEatModelDTO) {
|
||||
List<TbCashierCart> cashierCartList;
|
||||
ShopEatTypeInfoDTO shopEatTypeInfoDTO = shopUtils.checkEatModel(choseEatModelDTO.getTableId(), choseEatModelDTO.getShopId());
|
||||
// 外带模式
|
||||
// 切换外带模式
|
||||
if (choseEatModelDTO.getType() == 1) {
|
||||
cashierCartList = cashierCartService.selectByShopEatTypeInfo(shopEatTypeInfoDTO, choseEatModelDTO.getUserId());
|
||||
cashierCartList = cashierCartList.stream().filter(item -> !TableConstant.CART_SEAT_ID.equals(item.getProductId())).collect(Collectors.toList());
|
||||
@@ -1649,7 +1804,7 @@ public class CartService {
|
||||
.eq(TbCashierCart::getShopId, choseEatModelDTO.getShopId())
|
||||
.gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime())
|
||||
.isNull(TbCashierCart::getOrderId)
|
||||
.eq(TbCashierCart::getTableId, choseEatModelDTO.getTableId())
|
||||
.and(r -> r.eq(TbCashierCart::getTableId, choseEatModelDTO.getTableId()).or().isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, ""))
|
||||
.and(q -> q.eq(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType()).or().isNull(TbCashierCart::getUseType).or().eq(TbCashierCart::getUseType, ""))
|
||||
.eq(TbCashierCart::getStatus, "create");
|
||||
}
|
||||
@@ -1678,6 +1833,7 @@ public class CartService {
|
||||
orderDTO.setUserCouponInfos(useCouponDTO.getUserCouponInfos());
|
||||
orderDTO.setOnlyChangeCoupon(true);
|
||||
orderDTO.setPointsNum(useCouponDTO.getPointsNum());
|
||||
orderDTO.setOrderId(useCouponDTO.getOrderId());
|
||||
return createOrder(orderDTO);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,15 +9,9 @@ import com.chaozhanggui.system.cashierservice.dao.TbOrderDetailMapper;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbOrderInfoMapper;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbShopInfoMapper;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbShopTableMapper;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbShopInfo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbShopTable;
|
||||
import com.chaozhanggui.system.cashierservice.entity.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.OrderVo;
|
||||
import com.chaozhanggui.system.cashierservice.mapper.MpCashierCartMapper;
|
||||
import com.chaozhanggui.system.cashierservice.mapper.MpOrderDetailMapper;
|
||||
import com.chaozhanggui.system.cashierservice.mapper.MpOrderInfoMapper;
|
||||
import com.chaozhanggui.system.cashierservice.mapper.MpShopInfoMapper;
|
||||
import com.chaozhanggui.system.cashierservice.mapper.*;
|
||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
@@ -28,10 +22,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -62,6 +53,8 @@ public class OrderService {
|
||||
private MpOrderInfoMapper mpOrderInfoMapper;
|
||||
@Autowired
|
||||
private MpShopInfoMapper mpShopInfoMapper;
|
||||
@Autowired
|
||||
private TbFreeDineConfigMapper freeDineConfigMapper;
|
||||
|
||||
/**
|
||||
* 创建订单
|
||||
@@ -182,9 +175,9 @@ public class OrderService {
|
||||
orderVo.setTime(orderInfo.getCreatedAt());
|
||||
if (orderInfo.getStatus().equals("paying") || orderInfo.getStatus().equals("unpaid")) {
|
||||
Long totalSeconds = orderInfo.getCreatedAt() + 15 * 60 * 1000l - System.currentTimeMillis();
|
||||
if(totalSeconds>0){
|
||||
orderVo.setExpiredMinutes(totalSeconds/1000 / 60);
|
||||
orderVo.setExpiredSeconds(totalSeconds/1000 % 60);
|
||||
if (totalSeconds > 0) {
|
||||
orderVo.setExpiredMinutes(totalSeconds / 1000 / 60);
|
||||
orderVo.setExpiredSeconds(totalSeconds / 1000 % 60);
|
||||
}
|
||||
}
|
||||
orderVo.setPayAmount(orderInfo.getOrderAmount());
|
||||
@@ -223,11 +216,37 @@ public class OrderService {
|
||||
List<TbOrderDetail> list = mpOrderDetailMapper.selectList(new LambdaQueryWrapper<TbOrderDetail>()
|
||||
.eq(TbOrderDetail::getOrderId, orderInfo.getId())
|
||||
.ne(TbOrderDetail::getProductId, TableConstant.CART_SEAT_ID));
|
||||
|
||||
int num = 0;
|
||||
for (TbOrderDetail orderDetail : list) {
|
||||
num = num + orderDetail.getNum();
|
||||
if (!"unpaid".equals(orderInfo.getStatus())) {
|
||||
HashMap<String, TbOrderDetail> detailHashMap = new HashMap<>();
|
||||
list.forEach(item -> {
|
||||
String key;
|
||||
if (item.getCartId() == null) {
|
||||
key = item.getProductId().toString() + item.getProductSkuId() + item.getPlaceNum();
|
||||
}else {
|
||||
key = item.getCartId().toString();
|
||||
}
|
||||
TbOrderDetail orderDetail = detailHashMap.get(key);
|
||||
if (orderDetail == null) {
|
||||
detailHashMap.put(key, item);
|
||||
} else {
|
||||
orderDetail.setNum(orderDetail.getNum() + item.getNum());
|
||||
orderDetail.setPriceAmount(orderDetail.getPriceAmount().add(item.getPriceAmount()));
|
||||
orderDetail.setPackAmount(orderDetail.getPackAmount().add(item.getPackAmount()));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
for (TbOrderDetail orderDetail : detailHashMap.values()) {
|
||||
num = num + orderDetail.getNum();
|
||||
}
|
||||
orderInfo.setDetailList(new ArrayList<>(detailHashMap.values()));
|
||||
} else {
|
||||
orderInfo.setDetailList(list);
|
||||
}
|
||||
orderInfo.setDetailList(list);
|
||||
|
||||
|
||||
orderInfo.setTotalNumber(num);
|
||||
}
|
||||
//
|
||||
@@ -275,8 +294,26 @@ public class OrderService {
|
||||
}
|
||||
});
|
||||
|
||||
HashMap<String, TbOrderDetail> detailHashMap = new HashMap<>();
|
||||
list.forEach(item -> {
|
||||
String key;
|
||||
if (item.getCartId() == null) {
|
||||
key = item.getProductId().toString() + item.getProductSkuId() + item.getPlaceNum();
|
||||
}else {
|
||||
key = item.getCartId().toString();
|
||||
}
|
||||
TbOrderDetail orderDetail = detailHashMap.get(key);
|
||||
if (orderDetail == null) {
|
||||
detailHashMap.put(key, item);
|
||||
} else {
|
||||
orderDetail.setNum(orderDetail.getNum() + item.getNum());
|
||||
orderDetail.setPriceAmount(orderDetail.getPriceAmount().add(item.getPriceAmount()));
|
||||
orderDetail.setPackAmount(orderDetail.getPackAmount().add(item.getPackAmount()));
|
||||
}
|
||||
});
|
||||
|
||||
// 根据placeNum进行分组
|
||||
Map<Integer, List<TbOrderDetail>> groupedByPlaceNum = list.stream()
|
||||
Map<Integer, List<TbOrderDetail>> groupedByPlaceNum = detailHashMap.values().stream()
|
||||
.collect(Collectors.groupingBy(TbOrderDetail::getPlaceNum));
|
||||
|
||||
ArrayList<HashMap<String, Object>> dataList = new ArrayList<>();
|
||||
@@ -300,14 +337,14 @@ public class OrderService {
|
||||
orderVo.setStatus(orderInfo.getStatus());
|
||||
//TODO 增加商家二维码
|
||||
orderVo.setShopQrcode(shopInfo.getShopQrcode());
|
||||
orderVo.setDetails(list);
|
||||
orderVo.setDetails(detailHashMap.values());
|
||||
orderVo.setOrderNo(orderInfo.getOrderNo());
|
||||
orderVo.setTime(orderInfo.getCreatedAt());
|
||||
if (orderInfo.getStatus().equals("paying") || orderInfo.getStatus().equals("unpaid")) {
|
||||
long totalSeconds = orderInfo.getCreatedAt() + 15 * 60 * 1000l - System.currentTimeMillis();
|
||||
if(totalSeconds>0){
|
||||
orderVo.setExpiredMinutes(totalSeconds/1000 / 60);
|
||||
orderVo.setExpiredSeconds(totalSeconds/1000 % 60);
|
||||
if (totalSeconds > 0) {
|
||||
orderVo.setExpiredMinutes(totalSeconds / 1000 / 60);
|
||||
orderVo.setExpiredSeconds(totalSeconds / 1000 % 60);
|
||||
}
|
||||
}
|
||||
orderVo.setPayAmount(orderInfo.getOrderAmount());
|
||||
@@ -328,6 +365,8 @@ public class OrderService {
|
||||
map.put("createdAt", DateUtil.formatDateTime(DateUtil.date(orderInfo.getCreatedAt())));
|
||||
map.put("paidTime", orderInfo.getPaidTime() == null ? null : DateUtil.formatDateTime(DateUtil.date(orderInfo.getPaidTime())));
|
||||
map.put("registerType", shopInfo.getRegisterType());
|
||||
map.put("freeDingConfig", freeDineConfigMapper.selectOne(new LambdaQueryWrapper<TbFreeDineConfig>()
|
||||
.eq(TbFreeDineConfig::getShopId, shopInfo.getId())));
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,6 +192,7 @@ public class PayService {
|
||||
private final TbShopCouponService shopCouponService;
|
||||
private final MpMemberInMapper mpMemberInMapper;
|
||||
private final TbMemberPointsServiceImpl memberPointsService;
|
||||
private final CartService cartService;
|
||||
|
||||
@Qualifier("tbShopCouponService")
|
||||
@Autowired
|
||||
@@ -204,13 +205,14 @@ public class PayService {
|
||||
private TbFreeDineRecordMapper tbFreeDineRecordMapper;
|
||||
private final TbFreeDineRecordService freeDineRecordService;
|
||||
|
||||
public PayService(@Qualifier("tbShopSongOrderServiceImpl") TbShopSongOrderService shopSongOrderService, MpShopTableService mpShopTableService, TbFreeDineConfigService freeDineConfigService, TbShopCouponService shopCouponService, MpMemberInMapper mpMemberInMapper, TbMemberPointsServiceImpl memberPointsService, TbFreeDineRecordService freeDineRecordService) {
|
||||
public PayService(@Qualifier("tbShopSongOrderServiceImpl") TbShopSongOrderService shopSongOrderService, MpShopTableService mpShopTableService, TbFreeDineConfigService freeDineConfigService, TbShopCouponService shopCouponService, MpMemberInMapper mpMemberInMapper, TbMemberPointsServiceImpl memberPointsService, CartService cartService, TbFreeDineRecordService freeDineRecordService) {
|
||||
this.shopSongOrderService = shopSongOrderService;
|
||||
this.mpShopTableService = mpShopTableService;
|
||||
this.freeDineConfigService = freeDineConfigService;
|
||||
this.shopCouponService = shopCouponService;
|
||||
this.mpMemberInMapper = mpMemberInMapper;
|
||||
this.memberPointsService = memberPointsService;
|
||||
this.cartService = cartService;
|
||||
this.freeDineRecordService = freeDineRecordService;
|
||||
}
|
||||
|
||||
@@ -386,6 +388,15 @@ public class PayService {
|
||||
}
|
||||
|
||||
private BigDecimal getFreeDineOrderInfo(MemberInDTO payDTO, TbUserInfo userInfo) {
|
||||
|
||||
// 取消券
|
||||
UseCouponDTO useCouponDTO = new UseCouponDTO();
|
||||
useCouponDTO.setOrderId(payDTO.getOrderId());
|
||||
useCouponDTO.setUserCouponInfos(new ArrayList<>());
|
||||
useCouponDTO.setPointsNum(null);
|
||||
useCouponDTO.setShopId(payDTO.getShopId());
|
||||
cartService.useCoupon(useCouponDTO);
|
||||
|
||||
TbOrderInfo orderInfo = mpOrderInfoMapper.selectOne(new LambdaQueryWrapper<TbOrderInfo>()
|
||||
.eq(TbOrderInfo::getId, payDTO.getOrderId())
|
||||
.in(TbOrderInfo::getStatus, TableConstant.OrderInfo.Status.UNPAID.getValue(), TableConstant.OrderInfo.Status.PAYING.getValue()));
|
||||
@@ -419,13 +430,13 @@ public class PayService {
|
||||
}
|
||||
|
||||
// 返还优惠券
|
||||
returnCoupon(orderInfo, shopCouponService);
|
||||
// returnCoupon(orderInfo, shopCouponService, mpCashierCartMapper);
|
||||
|
||||
BigDecimal shouldPayAmount = orderInfo.getOriginAmount().multiply(BigDecimal.valueOf(freeDineConfig.getRechargeTimes()));
|
||||
|
||||
|
||||
// 霸王餐积分抵扣
|
||||
if (payDTO.getPointsNum() != null) {
|
||||
// 霸王餐积分抵扣 预留
|
||||
if (false && payDTO.getPointsNum() != null) {
|
||||
OrderDeductionPointsDTO memberUsablePoints = memberPointsService.getMemberUsablePoints(Long.valueOf(userInfo.getId()), shouldPayAmount);
|
||||
if (!memberUsablePoints.getUsable()) {
|
||||
throw new MsgException(memberUsablePoints.getUnusableReason());
|
||||
@@ -491,9 +502,9 @@ public class PayService {
|
||||
return shouldPayAmount;
|
||||
}
|
||||
|
||||
static void returnCoupon(TbOrderInfo orderInfo, TbShopCouponService shopCouponService) {
|
||||
static void returnCoupon(TbOrderInfo orderInfo, TbShopCouponService shopCouponService, MpCashierCartMapper cashierCartMapper) {
|
||||
if (StrUtil.isNotBlank(orderInfo.getCouponInfoList())) {
|
||||
OrderCouponInfoDTO couponInfoDTO = JSONObject.parseObject(orderInfo.getCouponInfoList(), OrderCouponInfoDTO.class);
|
||||
OrderInfoCouponInfoDTO couponInfoDTO = JSONObject.parseObject(orderInfo.getCouponInfoList(), OrderInfoCouponInfoDTO.class);
|
||||
// 券返还
|
||||
if (!couponInfoDTO.getOutRecordList().isEmpty()) {
|
||||
couponInfoDTO.getOutRecordList().forEach(item -> {
|
||||
@@ -501,7 +512,20 @@ public class PayService {
|
||||
});
|
||||
shopCouponService.refund(couponInfoDTO.getOutRecordList());
|
||||
couponInfoDTO.setOutRecordList(new ArrayList<>());
|
||||
couponInfoDTO.setProductCoupon(new ArrayList<>());
|
||||
couponInfoDTO.setFullReductionCoupon(new ArrayList<>());
|
||||
orderInfo.setCouponInfoList(JSONObject.toJSONString(couponInfoDTO));
|
||||
orderInfo.setUserCouponId(null);
|
||||
orderInfo.setUseCouponInfo(null);
|
||||
orderInfo.setFullCouponDiscountAmount(BigDecimal.ZERO);
|
||||
orderInfo.setProductCouponDiscountAmount(BigDecimal.ZERO);
|
||||
|
||||
// 修改购物车券信息
|
||||
cashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>()
|
||||
.eq(TbCashierCart::getOrderId, orderInfo.getId())
|
||||
.set(TbCashierCart::getUserCouponId, null)
|
||||
.set(TbCashierCart::getUseCouponInfo, null));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1272,7 +1296,7 @@ public class PayService {
|
||||
* @param payType 支付平台
|
||||
* @param payOrderNO 三方支付订单号
|
||||
*/
|
||||
private void orderSuccessPay(TbOrderInfo orderInfo, String payType, String payOrderNO) {
|
||||
private void orderSuccessPay(TbOrderInfo orderInfo, String payType, String payOrderNO, boolean isFreeDine) {
|
||||
int cartCount = mpCashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>()
|
||||
.eq(TbCashierCart::getOrderId, orderInfo.getId())
|
||||
// .eq(TbCashierCart::getUseType, orderInfo.getUseType())
|
||||
@@ -1299,6 +1323,11 @@ public class PayService {
|
||||
orderInfo.setPaidTime(System.currentTimeMillis());
|
||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
|
||||
// 消费送积分
|
||||
if (!isFreeDine) {
|
||||
tbMemberPointsService.consumeAwardPoints(Long.valueOf(orderInfo.getMemberId()), Long.valueOf(orderInfo.getId()));
|
||||
}
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("token", 0);
|
||||
jsonObject.put("type", "wxcreate");
|
||||
@@ -1361,7 +1390,7 @@ public class PayService {
|
||||
}
|
||||
|
||||
if ("paying".equals(orderInfo.getStatus())) {
|
||||
orderSuccessPay(orderInfo, payType, payOrderNO);
|
||||
orderSuccessPay(orderInfo, payType, payOrderNO, false);
|
||||
|
||||
return "SUCCESS";
|
||||
|
||||
@@ -1520,7 +1549,7 @@ public class PayService {
|
||||
//充值送积分
|
||||
TbActivate activate = tbActivateMapper.selectByAmountScope(tbShopUser.getShopId(), memberIn.getAmount());
|
||||
if (ObjectUtil.isNotNull(activate)) {
|
||||
tbMemberPointsService.addPoints(Convert.toLong(tbShopUser.getId()), activate.getGiftAmount(), StrUtil.format("充值¥{}送{}积分", memberIn.getAmount(), activate.getGiftAmount()), null, memberIn.getOrderNo());
|
||||
tbMemberPointsService.addPoints(Convert.toLong(tbShopUser.getId()), activate.getGiftPoints(), StrUtil.format("充值¥{}送{}积分", memberIn.getAmount(), activate.getGiftPoints()), null, memberIn.getOrderNo());
|
||||
}
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
@@ -1627,6 +1656,7 @@ public class PayService {
|
||||
* @param payOrderNo 三方交易订单号
|
||||
*/
|
||||
private void checkFreeDineForMemberInCallBack(TbMemberIn memberIn, String payType, String payOrderNo) {
|
||||
log.info("校验是否为霸王餐充值回调");
|
||||
// 判断是否是霸王餐充值活动
|
||||
if (memberIn.getOrderId() != null) {
|
||||
TbOrderInfo orderInfo = mpOrderInfoMapper.selectById(memberIn.getOrderId());
|
||||
@@ -1657,7 +1687,7 @@ public class PayService {
|
||||
shopCouponService.use(shopId, orderInfo.getId(), Integer.valueOf(orderInfo.getUserId()), activateOutRecords);
|
||||
}
|
||||
// 更改订单状态
|
||||
orderSuccessPay(orderInfo, payType, payOrderNo);
|
||||
orderSuccessPay(orderInfo, payType, payOrderNo, true);
|
||||
|
||||
// 更改霸王餐记录
|
||||
// TbFreeDineRecord freeDineRecord = freeDineRecordService.selectByOrderId(orderInfo.getId());
|
||||
@@ -1717,12 +1747,13 @@ public class PayService {
|
||||
checkFreeDineForMemberInCallBack(memberIn, payType, payOrderNO);
|
||||
|
||||
//会员活动
|
||||
BigDecimal awardAmount = giveActivate(tbShopUser, memberIn.getAmount(), flow.getId());
|
||||
BigDecimal awardAmount = null;
|
||||
|
||||
//充值送积分
|
||||
TbActivate activate = tbActivateMapper.selectByAmountScope(tbShopUser.getShopId(), memberIn.getAmount());
|
||||
if (ObjectUtil.isNotNull(activate)) {
|
||||
tbMemberPointsService.addPoints(Convert.toLong(tbShopUser.getId()), activate.getGiftAmount(), StrUtil.format("充值¥{}送{}积分", memberIn.getAmount(), activate.getGiftAmount()), null, memberIn.getOrderNo());
|
||||
if (memberIn.getOrderId() == null && ObjectUtil.isNotNull(activate)) {
|
||||
awardAmount = giveActivate(tbShopUser, memberIn.getAmount(), flow.getId());
|
||||
tbMemberPointsService.addPoints(Convert.toLong(tbShopUser.getId()), activate.getGiftPoints(), StrUtil.format("充值¥{}送{}积分", memberIn.getAmount(), activate.getGiftPoints()), null, memberIn.getOrderNo());
|
||||
}
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("shopId", memberIn.getShopId());
|
||||
|
||||
@@ -254,12 +254,17 @@ public class ProductService {
|
||||
});
|
||||
groupList.sort(Comparator.comparingInt(TbProductGroup::getIsSale).reversed());
|
||||
|
||||
//热销
|
||||
TbProductGroup hot = new TbProductGroup();
|
||||
hot.setName("热销");
|
||||
List<TbProduct> hots = tbProductMapper.selectHot(shopId,proSets);
|
||||
hot.setProducts(handleDate(hots,true,1,false, shopInfo));
|
||||
groupList.add(0, hot);
|
||||
// //热销
|
||||
// TbProductGroup hot = new TbProductGroup();
|
||||
// hot.setName("热销");
|
||||
// List<TbProduct> hots = null;
|
||||
// if (proSets.isEmpty()) {
|
||||
// hots = new ArrayList<>();
|
||||
// }else {
|
||||
// hots = tbProductMapper.selectHot(shopId,proSets);
|
||||
// }
|
||||
// hot.setProducts(handleDate(hots,true,1,false, shopInfo));
|
||||
// groupList.add(0, hot);
|
||||
|
||||
concurrentMap.put("productInfo", groupList);
|
||||
}
|
||||
@@ -976,7 +981,6 @@ public class ProductService {
|
||||
LambdaQueryWrapper<TbCashierCart> query = new LambdaQueryWrapper<TbCashierCart>()
|
||||
.eq(TbCashierCart::getShopId, shopId)
|
||||
.eq(TbCashierCart::getProductId, TableConstant.CART_SEAT_ID)
|
||||
.eq(TbCashierCart::getSkuId, TableConstant.CART_SEAT_ID)
|
||||
.eq(TbCashierCart::getStatus, "create")
|
||||
.gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime())
|
||||
// .and(r -> r.eq(TbCashierCart::getUserId, userId).or().isNull(TbCashierCart::getUserId))
|
||||
|
||||
@@ -50,6 +50,7 @@ public class TbCashierCartServiceImpl extends ServiceImpl<MpCashierCartMapper, T
|
||||
@Override
|
||||
public List<TbCashierCart> selectByOrderId(Integer shopId, Integer orderId) {
|
||||
return list(new LambdaQueryWrapper<TbCashierCart>()
|
||||
.gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime())
|
||||
.eq(TbCashierCart::getOrderId, orderId)
|
||||
.eq(TbCashierCart::getShopId, shopId));
|
||||
}
|
||||
|
||||
@@ -122,8 +122,7 @@ public class TbShopCouponServiceImpl implements TbShopCouponService {
|
||||
|
||||
@Override
|
||||
public Result find(CouponDto param) {
|
||||
if (param.getOrderId() != null) {
|
||||
|
||||
if (param.getOrderId() != null && param.getOrderId() > 0) {
|
||||
TbShopUser tbShopUser = shopUserMapper.selectByUserIdAndShopId(param.getUserId().toString(), param.getShopId().toString());
|
||||
List<TbUserCouponVo> tbUserCouponVos = inRecordMapper.queryByVipIdAndShopId(Arrays.asList(Integer.valueOf(tbShopUser.getId())), param.getShopId());
|
||||
if (CollectionUtil.isNotEmpty(tbUserCouponVos)) {
|
||||
@@ -135,7 +134,7 @@ public class TbShopCouponServiceImpl implements TbShopCouponService {
|
||||
Map<Integer, JsonObject> coupons = new HashMap<>();
|
||||
for (TbUserCouponVo tbUserCouponVo : tbUserCouponVos) {
|
||||
if (!coupons.containsKey(tbUserCouponVo.getCouponId())) {
|
||||
setCouponInfo(coupons, tbUserCouponVo, null, week ,now, formatter);
|
||||
setCouponInfo(coupons, tbUserCouponVo, null, week, now, formatter);
|
||||
}
|
||||
JsonObject couponJson = coupons.get(tbUserCouponVo.getCouponId());
|
||||
tbUserCouponVo.setUseRestrictions(couponJson.get("useRestrictions").toString());
|
||||
|
||||
@@ -79,7 +79,7 @@ public class TbShopShareRecordServiceImpl implements TbShopShareRecordService {
|
||||
shareRecord.setInvitedName(userInfoMapper.selectNameByPrimaryKey(shareRecord.getInvitedId()));
|
||||
shareRecord.setBeInvitedName(userInfoMapper.selectNameByPrimaryKey(shareRecord.getBeInvitedId()));
|
||||
}
|
||||
result.put("records", new PageInfo<>());
|
||||
result.put("records", new PageInfo<>(records));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,7 @@ public class ShopUtils {
|
||||
public ShopEatTypeInfoDTO checkEatModel(String tableId, Object shopId) {
|
||||
|
||||
TbShopInfo shopInfo = mpShopInfoMapper.selectOne(new LambdaQueryWrapper<TbShopInfo>()
|
||||
.eq(TbShopInfo::getId, shopId)
|
||||
.eq(TbShopInfo::getStatus, 1));
|
||||
.eq(TbShopInfo::getId, shopId));
|
||||
if (shopInfo == null) {
|
||||
throw new MsgException("店铺信息不存在");
|
||||
}
|
||||
@@ -73,8 +72,7 @@ public class ShopUtils {
|
||||
String eatModel = StrUtil.isBlank(tableId) ? ShopInfoEatModelEnum.TAKE_OUT.getValue() : ShopInfoEatModelEnum.DINE_IN.getValue();
|
||||
|
||||
TbShopInfo shopInfo = mpShopInfoMapper.selectOne(new LambdaQueryWrapper<TbShopInfo>()
|
||||
.eq(TbShopInfo::getId, shopId)
|
||||
.eq(TbShopInfo::getStatus, 1));
|
||||
.eq(TbShopInfo::getId, shopId));
|
||||
if (shopInfo == null) {
|
||||
throw new MsgException("店铺信息不存在");
|
||||
}
|
||||
|
||||
@@ -244,6 +244,7 @@
|
||||
FROM
|
||||
tb_product_group
|
||||
where shop_id=#{shopId} and is_show=1
|
||||
and product_ids != '[]'
|
||||
<if test="groupId != null and groupId != ''">
|
||||
and id = #{groupId}
|
||||
</if>
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
from tb_product tb
|
||||
LEFT JOIN tb_product_sku sku ON tb.id = sku.product_id and sku.is_del = 0
|
||||
where tb.id in (${ids})
|
||||
and tb.is_grounding = 1 and tb.type!='coupon' and tb.status = 1 and tb.is_del = 0
|
||||
and tb.is_grounding = 1 and tb.type!='coupon' and tb.type != 'weigh' and tb.status = 1 and tb.is_del = 0
|
||||
and tb.days LIKE concat('%',DAYNAME(CURRENT_DATE),'%') and tb.start_time <= CURRENT_TIMESTAMP and tb.end_time >= CURRENT_TIMESTAMP
|
||||
group by tb.id
|
||||
order by tb.sort asc
|
||||
@@ -105,7 +105,7 @@
|
||||
and tb.shop_id = #{shopId}
|
||||
and tb.status = 1
|
||||
and tb.is_grounding = 1
|
||||
and tb.type != 'coupon' and tb.is_del = 0
|
||||
and tb.type != 'coupon' and tb.type != 'weigh' and tb.is_del = 0
|
||||
and tb.days LIKE concat('%',DAYNAME(CURRENT_DATE),'%') and tb.start_time <= CURRENT_TIMESTAMP and tb.end_time >= CURRENT_TIMESTAMP
|
||||
group by tb.id
|
||||
order by tb.sort asc
|
||||
|
||||
Reference in New Issue
Block a user