feat: 代客下单支持套餐商品
This commit is contained in:
parent
467f6e9434
commit
2e46f9ab0f
|
|
@ -20,6 +20,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 ThirdPartyCoupon {
|
||||
@Getter
|
||||
public enum Plat {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import lombok.Data;
|
|||
|
||||
import javax.validation.constraints.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class AddCartDTO {
|
||||
|
|
@ -24,6 +25,9 @@ public class AddCartDTO {
|
|||
private Integer cartId;
|
||||
private String note;
|
||||
|
||||
// 套餐商品选择的id信息
|
||||
private List<Integer> groupProductIdList;
|
||||
|
||||
// 用餐类型
|
||||
@NotBlank
|
||||
private String useType;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import javax.validation.constraints.Min;
|
|||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class UpdateCartDTO {
|
||||
|
|
@ -27,4 +28,7 @@ public class UpdateCartDTO {
|
|||
// 是否等叫
|
||||
private Integer isWaitCall;
|
||||
|
||||
// 套餐商品选择的id信息
|
||||
private List<Integer> groupProductIdList;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -181,6 +181,8 @@ public class TbCashierCart implements Serializable {
|
|||
private Integer isThirdCoupon;
|
||||
// 是否等叫
|
||||
private Integer isWaitCall;
|
||||
// 套餐商品,选择的商品信息
|
||||
private String proGroupInfo;
|
||||
|
||||
public void copy(TbCashierCart source) {
|
||||
BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
|
|
|
|||
|
|
@ -141,6 +141,7 @@ public class TbOrderDetail implements Serializable {
|
|||
private BigDecimal canReturnAmount;
|
||||
private Integer isThirdCoupon;
|
||||
private Integer isWaitCall;
|
||||
private String proGroupInfo;
|
||||
|
||||
public void copy(TbOrderDetail source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
|
|
|
|||
|
|
@ -50,10 +50,7 @@ import cn.ysk.cashier.service.impl.TbPayServiceImpl;
|
|||
import cn.ysk.cashier.service.order.TbOrderInfoService;
|
||||
import cn.ysk.cashier.service.shop.TbShopTableService;
|
||||
import cn.ysk.cashier.utils.*;
|
||||
import cn.ysk.cashier.vo.ActivateInInfoVO;
|
||||
import cn.ysk.cashier.vo.OrderInfoUserCouponVo;
|
||||
import cn.ysk.cashier.vo.PendingCountVO;
|
||||
import cn.ysk.cashier.vo.TbUserCouponVo;
|
||||
import cn.ysk.cashier.vo.*;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
|
|
@ -449,6 +446,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
throw new BadRequestException("商品不存在或已下架, id: " + updateCartDTO.getSkuId());
|
||||
}
|
||||
|
||||
resetGroupProductCart(updateCartDTO.getGroupProductIdList(), product, tbCashierCart);
|
||||
tbCashierCart.setCoverImg(product.getCoverImg());
|
||||
tbCashierCart.setIsSku(product.getTypeEnum());
|
||||
tbCashierCart.setName(product.getName());
|
||||
|
|
@ -494,6 +492,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
if (tbCashierCart.getOrderId() != null && StrUtil.isNotBlank(updateCartDTO.getNote())) {
|
||||
orderDetailMapper.update(null, new LambdaUpdateWrapper<TbOrderDetail>()
|
||||
.eq(TbOrderDetail::getCartId, tbCashierCart.getId())
|
||||
.set(TbOrderDetail::getProGroupInfo, tbCashierCart.getProGroupInfo())
|
||||
.set(TbOrderDetail::getIsWaitCall, updateCartDTO.getIsWaitCall())
|
||||
.set(TbOrderDetail::getNote, updateCartDTO.getNote()));
|
||||
}
|
||||
|
|
@ -512,6 +511,51 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
return orderInfo == null ? 1 : orderInfo.getPlaceNum() + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置购物车套餐商品信息
|
||||
*/
|
||||
private void resetGroupProductCart(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 BadRequestException("存在无效套餐商品");
|
||||
}
|
||||
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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TbCashierCart addCartForUser(AddCartDTO addCartDTO) {
|
||||
addCartDTO.setTableId(OrderUseTypeEnum.TAKEOUT.getValue().equals(addCartDTO.getUseType()) ? null : addCartDTO.getTableId());
|
||||
|
|
@ -528,6 +572,11 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
throw new BadRequestException(product.getName() + "商品库存不足");
|
||||
}
|
||||
|
||||
boolean isChoseGroup = TableConstant.Product.Type.PACKAGE.equalsVals(product.getType()) && product.getGroupType() == 1;
|
||||
if (isChoseGroup && (addCartDTO.getGroupProductIdList() == null || addCartDTO.getGroupProductIdList().isEmpty())) {
|
||||
throw new BadRequestException("可选套餐,清先选择套餐商品");
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<TbCashierCart> query = new LambdaQueryWrapper<TbCashierCart>()
|
||||
.eq(TbCashierCart::getShopId, addCartDTO.getShopId())
|
||||
.gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime())
|
||||
|
|
@ -555,6 +604,8 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
// 首次加入
|
||||
if (tbCashierCart == null) {
|
||||
tbCashierCart = new TbCashierCart();
|
||||
resetGroupProductCart(addCartDTO.getGroupProductIdList(), product, tbCashierCart);
|
||||
|
||||
tbCashierCart.setUseType(shopEatTypeInfoDTO.getUseType());
|
||||
tbCashierCart.setCoverImg(product.getCoverImg());
|
||||
tbCashierCart.setCreatedAt(System.currentTimeMillis());
|
||||
|
|
@ -598,6 +649,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
mpCashierCartService.save(tbCashierCart);
|
||||
|
||||
} else {
|
||||
resetGroupProductCart(addCartDTO.getGroupProductIdList(), product, tbCashierCart);
|
||||
tbCashierCart.setIsMember(!shopEatTypeInfoDTO.isMemberPrice() ? 0 : addCartDTO.getVipUserId() == null ? 0 : 1);
|
||||
tbCashierCart.setNote(addCartDTO.getNote());
|
||||
tbCashierCart.setTotalAmount(addCartDTO.getNum().multiply(productSku.getSalePrice()));
|
||||
|
|
@ -1612,6 +1664,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
orderDetail.setProductId(Integer.valueOf(cashierCart.getProductId()));
|
||||
}
|
||||
|
||||
orderDetail.setProGroupInfo(cashierCart.getProGroupInfo());
|
||||
orderDetail.setDiscountSaleAmount(cashierCart.getDiscountSaleAmount());
|
||||
orderDetail.setIsWaitCall(cashierCart.getIsWaitCall());
|
||||
orderDetail.setUserCouponId(cashierCart.getUserCouponId());
|
||||
|
|
|
|||
Loading…
Reference in New Issue