feat: 点单支持套餐商品
This commit is contained in:
@@ -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 ShopTable {
|
class ShopTable {
|
||||||
@Getter
|
@Getter
|
||||||
public enum State {
|
public enum State {
|
||||||
|
|||||||
@@ -42,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.getIsPrint());
|
cartVo.getIsPack(), cartVo.getUuid(), cartVo.getType(), cartVo.getTableId(), cartVo.getIsPrint(), cartVo.getGroupProductIdList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/print")
|
@PutMapping("/print")
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ public class TbCashierCart implements Serializable {
|
|||||||
private Integer isPrint;
|
private Integer isPrint;
|
||||||
private String useCouponInfo;
|
private String useCouponInfo;
|
||||||
private int isThirdCoupon;
|
private int isThirdCoupon;
|
||||||
|
private String proGroupInfo;
|
||||||
|
|
||||||
public void copy(TbCashierCart source) {
|
public void copy(TbCashierCart source) {
|
||||||
BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true));
|
BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true));
|
||||||
|
|||||||
@@ -62,7 +62,6 @@ public class TbOrderDetail implements Serializable {
|
|||||||
|
|
||||||
private BigDecimal discountSaleAmount;
|
private BigDecimal discountSaleAmount;
|
||||||
private String discountSaleNote;
|
private String discountSaleNote;
|
||||||
|
private String proGroupInfo;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import javax.validation.constraints.Min;
|
|||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class CartVo {
|
public class CartVo {
|
||||||
@@ -27,4 +28,7 @@ public class CartVo {
|
|||||||
private String tableId;
|
private String tableId;
|
||||||
private Integer orderId;
|
private Integer orderId;
|
||||||
private Integer isPrint;
|
private Integer isPrint;
|
||||||
|
|
||||||
|
// 套餐商品选择的id信息
|
||||||
|
private List<Integer> groupProductIdList;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import com.chaozhanggui.system.cashierservice.entity.po.OrderPo;
|
|||||||
import com.chaozhanggui.system.cashierservice.entity.po.QueryCartPo;
|
import com.chaozhanggui.system.cashierservice.entity.po.QueryCartPo;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.po.SkuInfoPo;
|
import com.chaozhanggui.system.cashierservice.entity.po.SkuInfoPo;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.vo.CartVo;
|
import com.chaozhanggui.system.cashierservice.entity.vo.CartVo;
|
||||||
|
import com.chaozhanggui.system.cashierservice.entity.vo.ProductGroupVo;
|
||||||
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||||
import com.chaozhanggui.system.cashierservice.exception.NotPrintException;
|
import com.chaozhanggui.system.cashierservice.exception.NotPrintException;
|
||||||
import com.chaozhanggui.system.cashierservice.mybatis.*;
|
import com.chaozhanggui.system.cashierservice.mybatis.*;
|
||||||
@@ -31,7 +32,6 @@ import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer;
|
|||||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||||
import com.chaozhanggui.system.cashierservice.util.*;
|
import com.chaozhanggui.system.cashierservice.util.*;
|
||||||
import com.fasterxml.jackson.core.io.BigDecimalParser;
|
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@@ -215,9 +215,56 @@ public class OrderService {
|
|||||||
shopId, tableId, isTakeout ? OrderSendTypeEnums.TAKE_SELF.getValue() : OrderSendTypeEnums.TABLE.getValue());
|
shopId, tableId, isTakeout ? OrderSendTypeEnums.TAKE_SELF.getValue() : OrderSendTypeEnums.TABLE.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重置购物车套餐商品信息
|
||||||
|
*/
|
||||||
|
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 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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@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, Integer isPrint) {
|
String userId, String clientType, Integer cartId, String isGift, String isPack, String uuid,
|
||||||
|
String type, String tableId, Integer isPrint, List<Integer> groupProductIdList) {
|
||||||
if (number == null) {
|
if (number == null) {
|
||||||
return Result.fail(CodeEnum.PARAM);
|
return Result.fail(CodeEnum.PARAM);
|
||||||
}
|
}
|
||||||
@@ -353,6 +400,9 @@ public class OrderService {
|
|||||||
cart.resetTotalAmount();
|
cart.resetTotalAmount();
|
||||||
cart.setUuid(uuid);
|
cart.setUuid(uuid);
|
||||||
cart.setIsPrint(isPrint);
|
cart.setIsPrint(isPrint);
|
||||||
|
if (product != null) {
|
||||||
|
resetGroupProductCart(groupProductIdList, product, cart);
|
||||||
|
}
|
||||||
cashierCartMapper.updateByPrimaryKeySelective(cart);
|
cashierCartMapper.updateByPrimaryKeySelective(cart);
|
||||||
} else {
|
} else {
|
||||||
List<TbCashierCart> list = cashierCartMapper.selectALlByMasterId(masterId, "create");
|
List<TbCashierCart> list = cashierCartMapper.selectALlByMasterId(masterId, "create");
|
||||||
@@ -409,6 +459,9 @@ public class OrderService {
|
|||||||
cashierCart.setUuid(uuid);
|
cashierCart.setUuid(uuid);
|
||||||
cashierCart.setTableId(tableId);
|
cashierCart.setTableId(tableId);
|
||||||
cashierCart.setPlatformType(OrderPlatformTypeEnum.CASH.getValue());
|
cashierCart.setPlatformType(OrderPlatformTypeEnum.CASH.getValue());
|
||||||
|
if (product != null) {
|
||||||
|
resetGroupProductCart(groupProductIdList, product, cashierCart);
|
||||||
|
}
|
||||||
list.add(cashierCart);
|
list.add(cashierCart);
|
||||||
mpCashierCartMapper.insert(cashierCart);
|
mpCashierCartMapper.insert(cashierCart);
|
||||||
} else {
|
} else {
|
||||||
@@ -417,6 +470,9 @@ public class OrderService {
|
|||||||
} else {
|
} else {
|
||||||
cashierCart.setNumber(number);
|
cashierCart.setNumber(number);
|
||||||
}
|
}
|
||||||
|
if (product != null) {
|
||||||
|
resetGroupProductCart(groupProductIdList, product, cashierCart);
|
||||||
|
}
|
||||||
cashierCart.setIsPrint(isPrint);
|
cashierCart.setIsPrint(isPrint);
|
||||||
cashierCart.resetTotalAmount();
|
cashierCart.resetTotalAmount();
|
||||||
mpCashierCartMapper.updateById(cashierCart);
|
mpCashierCartMapper.updateById(cashierCart);
|
||||||
@@ -943,6 +999,7 @@ public class OrderService {
|
|||||||
saleAmount = saleAmount.add(shopInfo.getTableFee());
|
saleAmount = saleAmount.add(shopInfo.getTableFee());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
orderDetail.setProGroupInfo(cashierCart.getProGroupInfo());
|
||||||
orderDetail.setIsTemporary(cashierCart.getIsTemporary());
|
orderDetail.setIsTemporary(cashierCart.getIsTemporary());
|
||||||
orderDetail.setDiscountSaleNote(cashierCart.getDiscountSaleNote());
|
orderDetail.setDiscountSaleNote(cashierCart.getDiscountSaleNote());
|
||||||
orderDetail.setDiscountSaleAmount(cashierCart.getDiscountSaleAmount());
|
orderDetail.setDiscountSaleAmount(cashierCart.getDiscountSaleAmount());
|
||||||
|
|||||||
Reference in New Issue
Block a user