From dab3fa0453c471874cd1371397cdd47a58da2c09 Mon Sep 17 00:00:00 2001 From: Sum1Dream <418471657@qq.com> Date: Wed, 6 Jul 2022 15:27:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=9D=E8=B4=B9=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E4=BB=BB=E5=8A=A1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/HighOrderServiceImpl.java | 111 +++++++++++++++--- 1 file changed, 95 insertions(+), 16 deletions(-) diff --git a/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java index 27a704cf..0adef86d 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java @@ -1777,10 +1777,104 @@ public class HighOrderServiceImpl implements HighOrderService { HighOrder highOrder = new HighOrder(); HighUser user = highUserService.findByUserId(object.getLong("userId")); + + + JSONObject productDetail = thirdProductConfig.getThirdPartyByDetail(object.getInteger("platformId") , object.getInteger("productType") , object.getLong("companyId")); + + // 积分抵扣金额 + BigDecimal integralPrice = new BigDecimal(0); + // 优惠券抵扣金额 + BigDecimal discountPrice = new BigDecimal(0); + + // 定义优惠券 + HighDiscountUserRel highDiscountUserRel = null; + // 判断是否有优惠券 + if (object.getLong("memDiscountId") != null) { + // 优惠券信息 + highDiscountUserRel = highDiscountUserRelService.getRelById(object.getLong("memDiscountId")); + highOrder.setMemDiscountId(object.getLong("memDiscountId")); + if (highDiscountUserRel == null || highDiscountUserRel.getStatus() != 1) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券状态错误"); + } + if (!highDiscountUserRel.getHighDiscount().getUseScope().equals(DiscountUseScope.type1.getType()) + && !highDiscountUserRel.getHighDiscount().getUseScope().equals(DiscountUseScope.type3.getType())) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法使用此优惠券"); + } + } + + // 使用优惠券 + // 优惠券抵扣 +// if (highDiscountUserRel != null) { +// highOrder.setMemDiscountName(highDiscountUserRel.getHighDiscount().getDiscountName()); +// // 卡卷类型 1:满减 2:抵扣 3:折扣 +// if (highDiscountUserRel.getHighDiscount().getDiscountType() == 1) { +// // 如果商品支付总额 小于 满减价格 +// if (outRechargePrice.getRechargePrice().compareTo(highDiscountUserRel.getHighDiscount().getDiscountCondition()) < 0) { +// throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, "订单未达到" + highDiscountUserRel.getHighDiscount().getDiscountCondition() + "元,无法使用此优惠券"); +// } +// // 计算支付金额 = 商品充值总额 - 满减额度 +// payPrice = outRechargePrice.getRechargePrice().subtract(highDiscountUserRel.getHighDiscount().getDiscountPrice()); +// outRechargeOrder.setDiscountDeductionPrice(highDiscountUserRel.getHighDiscount().getDiscountPrice()); +// +// } +// +// // 卡卷类型 1:满减 2:抵扣 3:折扣 +// if (highDiscountUserRel.getHighDiscount().getDiscountType() == 2) { +// // 计算支付金额 = 商品充值总额 - 满减额度 +// payPrice = outRechargePrice.getRechargePrice().subtract(highDiscountUserRel.getHighDiscount().getDiscountPrice()); +// outRechargeOrder.setDiscountDeductionPrice(highDiscountUserRel.getHighDiscount().getDiscountPrice()); +// +// } +// +// // 卡卷类型 1:满减 2:抵扣 3:折扣 +// if (highDiscountUserRel.getHighDiscount().getDiscountType() == 3) { +// BigDecimal discountPrice = highDiscountUserRel.getHighDiscount().getDiscountPrice(); +// // 订单总额 * 折扣 +// payPrice = outRechargePrice.getRechargePrice().multiply(discountPrice); +// outRechargeOrder.setDiscountDeductionPrice(outRechargePrice.getRechargePrice().subtract(payPrice)); +// outRechargeOrder.setPayRealPrice(payPrice); +// } +// } + JSONObject jsonObject = null; // 1 星巴克 2 肯德基 if (object.getInteger("productType") == 1) { + // 下单 jsonObject = QianZhuConfig.starbucksOrders(object.getLong("userId") , object.getString("storeCode") , object.getString("orderItems") , object.getString("customerMobile")); + + // 判断下单是否成功 + if (!jsonObject.getBoolean("success")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , jsonObject.getString("message")); + } + + // 根据订单号查询订单详情 + JSONObject orderObject = QianZhuConfig.starbucksOrderByOrderNo(jsonObject.getJSONObject("data").getString("orderNo")); + + // 判断下单是否成功 + if (!orderObject.getBoolean("success")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , jsonObject.getString("message")); + } + JSONArray starbucksOrder = orderObject.getJSONArray(""); + // 根据订单号查询订单内容并插入数据 + if (jsonObject != null && jsonObject.getBoolean("success")) { + + + + highOrder.setOrderNo(jsonObject.getJSONObject("data").getString("orderNo")); + highOrder.setRegionId(object.getString("regionId")); + highOrder.setCreateTime(new Date()); + highOrder.setMemId(user.getId()); + highOrder.setMemName(user.getName()); + highOrder.setMemPhone(user.getPhone()); + highOrder.setOrderStatus(1); + highOrder.setRemarks(object.getString("userRemark")); + highOrderMapper.insert(highOrder); + + + } else { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , jsonObject.getString("message")); + } + } else if (object.getInteger("productType") == 2) { if (object.getInteger("eatType") == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请选择就餐方式!"); @@ -1788,24 +1882,9 @@ public class HighOrderServiceImpl implements HighOrderService { jsonObject = QianZhuConfig.createKfcOrder(object.getInteger("eatType") , object.getString("storeCode") , object.getString("customerMobile") , object.getString("orderItems") , object.getString("userId"), object.getString("userRemark")); } - if (jsonObject != null && jsonObject.getBoolean("success")) { - - highOrder.setOrderNo(jsonObject.getJSONObject("data").getString("orderNo")); - highOrder.setRegionId(object.getString("regionId")); - highOrder.setCreateTime(new Date()); - highOrder.setMemId(user.getId()); - highOrder.setMemName(user.getName()); - highOrder.setMemPhone(user.getPhone()); - highOrder.setOrderStatus(1); - highOrder.setRemarks(object.getString("userRemark")); - highOrderMapper.insert(highOrder); - - return jsonObject.getJSONObject("data"); - } else { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , jsonObject.getString("message")); - } + return jsonObject.getJSONObject("data"); } }