From 0d5bade502337cab3fc2f96cf2d6891ded35bb77 Mon Sep 17 00:00:00 2001 From: zhibing.pu <393733352@qq.com> Date: 星期一, 15 四月 2024 20:50:29 +0800 Subject: [PATCH] 新增加功能 --- UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/specialTrain/server/impl/OrderPrivateCarServiceImpl.java | 135 ++++++++++++++++++++++++++++++++++++-------- 1 files changed, 110 insertions(+), 25 deletions(-) diff --git a/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/specialTrain/server/impl/OrderPrivateCarServiceImpl.java b/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/specialTrain/server/impl/OrderPrivateCarServiceImpl.java index d9f38a1..36125cb 100644 --- a/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/specialTrain/server/impl/OrderPrivateCarServiceImpl.java +++ b/UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/specialTrain/server/impl/OrderPrivateCarServiceImpl.java @@ -196,6 +196,9 @@ @Autowired private IPhoneService phoneService; + + @Autowired + private IRedEnvelopePaymentSettingsService redEnvelopePaymentSettingsService; @@ -957,7 +960,7 @@ @Override - public ResultUtil payPrivateCarOrder(Integer payType, Integer bankCardId, Integer orderId, Integer couponId, Integer type, Integer language) throws Exception { + public ResultUtil payPrivateCarOrder(Integer payType, Integer bankCardId, Integer orderId, Integer couponId, Integer redDeduction, Integer type, Integer language) throws Exception { OrderPrivateCar orderPrivateCar = this.selectById(orderId); if(orderPrivateCar.getState() == 8 || orderPrivateCar.getState() == 9){ return ResultUtil.error(language == 1 ? "订单已完成支付,不允许重复支付" : language == 2 ? "The order has been paid, recurring payments is not allowed." : "La commande a été payée, les paiements récurrents ne sont pas autorisés.", ""); @@ -991,6 +994,10 @@ //计算优惠券 UserCouponRecord userCouponRecord = null; if(null != couponId){ + //TODO 待翻译 + if(null != redDeduction && 1 == redDeduction){ + return ResultUtil.error(language == 1 ? "优惠券和红包不能同时使用" : language == 2 ? "" : "", ""); + } userCouponRecord = userCouponRecordService.selectById(couponId); if(!userCouponRecord.getCompanyId().equals(orderPrivateCar.getCompanyId())){ return ResultUtil.error(language == 1 ? "优惠券不能用于此订单" : language == 2 ? "Coupon cannot be used for this order." : "Le coupon ne peut pas être utilisé pour cette commande.", ""); @@ -1014,12 +1021,62 @@ orderMoney=new BigDecimal(orderMoney).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); //计算红包 - UserRedPacketRecord query = userRedPacketRecordService.query(uid, orderPrivateCar.getCompanyId(), 1, 1, orderMoney); - if(null != query && query.getMoney().compareTo(orderMoney) < 0){ - orderMoney = orderMoney - query.getMoney(); - orderPrivateCar.setRedPacketMoney(query.getMoney()); - orderPrivateCar.setRedPacketId(query.getId()); + if(null != redDeduction && 1 == redDeduction){ + RedEnvelopePaymentSettings redEnvelopePaymentSettings = redEnvelopePaymentSettingsService.getRedEnvelopePaymentSettings(); + if(null != redEnvelopePaymentSettings){ + Double total = userRedPacketRecordService.queryRemainingAmount(uid); + List<UserRedPacketRecord> userRedPacketRecords = userRedPacketRecordService.selectList(new EntityWrapper<UserRedPacketRecord>().eq("userId", uid) + .eq("state", 1).eq("companyId", orderPrivateCar.getCompanyId()).gt("remainingAmount", 0).orderBy("insertTime", false)); + if(total.compareTo(orderMoney) >= 0){ + BigDecimal deductionRatio = redEnvelopePaymentSettings.getDeductionRatio(); + BigDecimal multiply = new BigDecimal(orderMoney).multiply(deductionRatio.divide(new BigDecimal(100))); + orderPrivateCar.setRedPacketMoney(multiply.doubleValue()); + orderMoney = orderMoney - multiply.doubleValue(); + + //获取红包id + JSONArray jsonArray = new JSONArray(); + for (UserRedPacketRecord userRedPacketRecord : userRedPacketRecords) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", userRedPacketRecord.getId()); + BigDecimal remainingAmount = new BigDecimal(userRedPacketRecord.getRemainingAmount()); + if(multiply.compareTo(remainingAmount) >= 0){ + multiply = multiply.subtract(remainingAmount); + jsonObject.put("money", remainingAmount); + jsonArray.add(jsonObject); + }else{ + userRedPacketRecord.setRemainingAmount(remainingAmount.subtract(multiply).doubleValue()); + jsonObject.put("money", multiply); + jsonArray.add(jsonObject); + break; + } + } + orderPrivateCar.setRedPacketId(jsonArray.toJSONString()); + }else{ + orderPrivateCar.setRedPacketMoney(total); + orderMoney = orderMoney - total; + //获取红包id + JSONArray jsonArray = new JSONArray(); + BigDecimal multiply = new BigDecimal(total); + for (UserRedPacketRecord userRedPacketRecord : userRedPacketRecords) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", userRedPacketRecord.getId()); + BigDecimal remainingAmount = new BigDecimal(userRedPacketRecord.getRemainingAmount()); + if(multiply.compareTo(remainingAmount) >= 0){ + multiply = multiply.subtract(remainingAmount); + jsonObject.put("money", remainingAmount); + jsonArray.add(jsonObject); + }else{ + userRedPacketRecord.setRemainingAmount(remainingAmount.subtract(multiply).doubleValue()); + jsonObject.put("money", multiply); + jsonArray.add(jsonObject); + break; + } + } + orderPrivateCar.setRedPacketId(jsonArray.toJSONString()); + } + } } + if(payType == 1){//手机支付 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); @@ -1089,18 +1146,29 @@ orderPrivateCar.setPayType(3); orderPrivateCar.setPayMoney(orderMoney); orderPrivateCar.setOrderMoney(orderPrivateCar.getOrderMoney()+orderPrivateCar.getFreeMoney().doubleValue()); - + //处理优惠券和红包 if(null != userCouponRecord){ userCouponRecord.setState(2); userCouponRecord.setEndTime(new Date()); userCouponRecordService.updateById(userCouponRecord); } - if(null != query){ - query.setState(2); - query.setEndTime(new Date()); - userRedPacketRecordService.updateById(query); + if(null != orderPrivateCar.getRedPacketId()){ + JSONArray jsonArray = JSON.parseArray(orderPrivateCar.getRedPacketId()); + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject jsonObject = jsonArray.getJSONObject(i); + Integer id1 = jsonObject.getInteger("id"); + Double money = jsonObject.getDouble("money"); + UserRedPacketRecord userRedPacketRecord = userRedPacketRecordService.selectById(id1); + userRedPacketRecord.setRemainingAmount(userRedPacketRecord.getRemainingAmount() - money); + if(0 == userRedPacketRecord.getRemainingAmount()){ + userRedPacketRecord.setState(2); + userRedPacketRecord.setEndTime(new Date()); + } + userRedPacketRecordService.updateById(userRedPacketRecord); + } } + if(orderPrivateCar.getIsplatPay()==1){ //添加已收入明细 Company company = companyService.selectById(orderPrivateCar.getCompanyId()); @@ -1445,18 +1513,28 @@ driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); driverService.updateById(driver); } - if(null != query){ - query.setState(2); - query.setEndTime(new Date()); - userRedPacketRecordService.updateById(query); - - Double money = query.getMoney(); + if(null != orderPrivateCar.getRedPacketId()){ + JSONArray jsonArray = JSON.parseArray(orderPrivateCar.getRedPacketId()); + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject jsonObject = jsonArray.getJSONObject(i); + Integer id1 = jsonObject.getInteger("id"); + Double money = jsonObject.getDouble("money"); + UserRedPacketRecord userRedPacketRecord = userRedPacketRecordService.selectById(id1); + userRedPacketRecord.setRemainingAmount(userRedPacketRecord.getRemainingAmount() - money); + if(0 == userRedPacketRecord.getRemainingAmount()){ + userRedPacketRecord.setState(2); + userRedPacketRecord.setEndTime(new Date()); + } + userRedPacketRecordService.updateById(userRedPacketRecord); + } + Double money = orderPrivateCar.getRedPacketMoney(); incomeService.saveData(2, orderPrivateCar.getDriverId(), 7, orderPrivateCar.getId(), 1, money); driver.setBusinessMoney(new BigDecimal(null != driver.getBusinessMoney() ? driver.getBusinessMoney() : 0).add(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); driver.setLaveBusinessMoney(new BigDecimal(null != driver.getLaveBusinessMoney() ? driver.getLaveBusinessMoney() : 0).add(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); driver.setBalance(new BigDecimal(null != driver.getBalance() ? driver.getBalance() : 0).add(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); driverService.updateById(driver); } + if(null != orderPrivateCar.getDiscountMoney() && 0 < orderPrivateCar.getDiscountMoney()){ Double money = orderPrivateCar.getDiscountMoney(); incomeService.saveData(2, orderPrivateCar.getDriverId(), 6, orderPrivateCar.getId(), 1, money); @@ -1849,10 +1927,7 @@ }else{//随机金额 Double startMoney = Double.valueOf(String.valueOf(query.get("startMoney"))); Double endMoney = Double.valueOf(String.valueOf(query.get("endMoney"))); - int i = new BigDecimal(endMoney).subtract(new BigDecimal(startMoney)).intValue(); - Random random = new Random(); - int num = random.nextInt(i); - money = new BigDecimal(startMoney).add(new BigDecimal(num)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); + money = new BigDecimal(startMoney + (Math.random() * (endMoney - startMoney))).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); } //判断当前红包是否大于剩余可领取总金额 if(money.compareTo(Double.valueOf(query.get("lavePrice").toString())) > 0){ @@ -1867,6 +1942,7 @@ //添加临时红包数据 UserRedPacketRecord userRedPacketRecord = new UserRedPacketRecord(); userRedPacketRecord.setMoney(money); + userRedPacketRecord.setRemainingAmount(money); Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + Integer.valueOf(String.valueOf(query.get("effective")))); @@ -2067,10 +2143,19 @@ userCouponRecordService.updateById(userCouponRecord); } if(null != orderPrivateCar.getRedPacketId()){ - UserRedPacketRecord userRedPacketRecord = userRedPacketRecordService.selectById(orderPrivateCar.getRedPacketId()); - userRedPacketRecord.setState(2); - userRedPacketRecord.setEndTime(new Date()); - userRedPacketRecordService.updateById(userRedPacketRecord); + JSONArray jsonArray = JSON.parseArray(orderPrivateCar.getRedPacketId()); + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject jsonObject = jsonArray.getJSONObject(i); + Integer id1 = jsonObject.getInteger("id"); + Double money = jsonObject.getDouble("money"); + UserRedPacketRecord userRedPacketRecord = userRedPacketRecordService.selectById(id1); + userRedPacketRecord.setRemainingAmount(userRedPacketRecord.getRemainingAmount() - money); + if(0 == userRedPacketRecord.getRemainingAmount()){ + userRedPacketRecord.setState(2); + } + userRedPacketRecord.setEndTime(new Date()); + userRedPacketRecordService.updateById(userRedPacketRecord); + } } -- Gitblit v1.7.1