提交 a09d76a2 authored 作者: 吴德鹏's avatar 吴德鹏

update

上级 420a90b7
......@@ -136,6 +136,13 @@ public class OrderController extends Controller {
List<TbCfCartRecordR> list = new ArrayList<>();
TbCfItemSkus itemSkus = skuOptional.get();
BigDecimal orderPrice = itemSkus.getSkuPrice().multiply(new BigDecimal(itemNum));
//校验优惠券是否可用
if (StringUtils.isBlank(toitableId)) {
boolean check = checkCoupon(toitableId, orderPrice);
if (!check) {
return new Result<>(code, "Coupon invalid !");
}
}
Map<String, Object> map = queryUserAvailableCoupons(orderPrice);
list.add(getCart(item, itemSku, itemNum, itemSkus.getSkuPrice(), itemSkus));
......@@ -164,6 +171,18 @@ public class OrderController extends Controller {
return new Result<>(order);
}
public boolean checkCoupon(String couponId, BigDecimal orderPrice) {
logger.info("orderPrice:" + orderPrice);
Optional<TbCfToicoupon> byId = toicouponRepository.findById(couponId);
if (byId.isPresent()) {
TbCfToicoupon coupon = byId.get();
logger.info("amout:" + coupon.deductAmount());
System.out.println(orderPrice.compareTo(coupon.deductAmount()) >= 0);
return orderPrice.compareTo(coupon.deductAmount()) >= 0;
}
return false;
}
@PostMapping("/settle")
public Result<TbCfOrder> settleAccount(@RequestBody String[] ids, @RequestParam(value = "toitableId", required = false) String toitableId,
@RequestParam(value = "open", required = false) boolean open) throws ParseException {
......@@ -174,8 +193,16 @@ public class OrderController extends Controller {
for (TbCfCartRecordR cart : allByUserId) {
orderPrice = orderPrice.add(cart.getItemPrice().multiply(new BigDecimal(cart.getItemNum())));
}
Map<String, Object> couponMap = queryUserAvailableCoupons(orderPrice);
int code = ResultCodeEnum.VALIDATE_ERROR.getCode();
//校验优惠券是否可用
if (StringUtils.isBlank(toitableId)) {
boolean check = checkCoupon(toitableId, orderPrice);
if (!check) {
return new Result<>(code, "Coupon invalid !");
}
}
if (allByUserId.isEmpty()) {
return new Result<>(code, "There are no items in the shopping cart");
}
......@@ -249,7 +276,7 @@ public class OrderController extends Controller {
boolean payNow = !noPayNow;
// BigDecimal orderPrice=BigDecimal.ZERO;
BigDecimal orderPrice = BigDecimal.ZERO;
if (payNow) {
Optional<TbCfStationItem> byId = itemRepository.findById(itemId);
......@@ -271,7 +298,7 @@ public class OrderController extends Controller {
// }
TbCfItemSkus skuObj = skuOptional.get();
// orderPrice=skuObj.getSkuPrice().multiply(new BigDecimal(itemNum));
orderPrice = skuObj.getSkuPrice().multiply(new BigDecimal(itemNum));
allByUserId.add(getCart(stationItem, itemSku, itemNum, skuObj.getSkuPrice(), skuObj));
} else {
......@@ -285,11 +312,18 @@ public class OrderController extends Controller {
// return new Result<>(v_code, "Goods in short stock!");
// }
// }
// for (TbCfCartRecordR cart : allByUserId) {
// orderPrice = orderPrice.add(cart.getItemPrice().multiply(new BigDecimal(cart.getItemNum())));
// }
for (TbCfCartRecordR cart : allByUserId) {
orderPrice = orderPrice.add(cart.getItemPrice().multiply(new BigDecimal(cart.getItemNum())));
}
}
// Map<String, Object> map = queryUserAvailableCoupons(orderPrice);
//校验优惠券是否可用
if (StringUtils.isBlank(toitableId)) {
boolean check = checkCoupon(toitableId, orderPrice);
if (!check) {
return new Result<>(v_code, "Coupon invalid !");
}
}
Map<String, Object> map = queryUserAvailableCoupons(orderPrice);
//Check that one of items in the cart run out of stock
......@@ -313,7 +347,7 @@ public class OrderController extends Controller {
TbCfOrder order = new TbCfOrder();
// order.setCouponMap(map);
order.setCouponMap(map);
order.setUserName(user.display());
TbCfAddress address = addressOptional.get();
......
......@@ -18,7 +18,7 @@ public interface TbCfStationItemRepository extends PagingAndSortingRepository<Tb
Page<TbCfStationItem> findAllByItemLabelContaining(String label, Pageable pageable);
@Query(value = "select a from #{#entityName} a WHERE a.itemId <> :itemId and (a.itemDescritionId = :descriptionId or a.itemCategorytwo = :categoryTwo or a.itemCategory = :category )")
@Query(value = "select a from #{#entityName} a WHERE a.itemId <> :itemId and (a.itemDescritionId = :descriptionId or a.itemCategorytwo = :categoryTwo or a.itemCategory = :category ) order by a.createTime desc ")
Page<TbCfStationItem> getRecommendItems(@Param("itemId") String itemId, @Param("descriptionId") String descriptionId, @Param("categoryTwo") String categoryTwo, @Param("category") String category, Pageable pageable);
@Query(value = "select a from #{#entityName} a WHERE a in (SELECT l.item FROM ItemLabel l WHERE l.description IN :tags) and (SELECT count(x.item) FROM ItemLabel x WHERE x.item = a and x.description IN :tags) >= :num ")
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论