From 1772afb069b75871572c9c438bbd2bc403f864df Mon Sep 17 00:00:00 2001 From: puzhibing <393733352@qq.com> Date: 星期三, 13 十二月 2023 11:43:51 +0800 Subject: [PATCH] 修改bug --- ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java | 140 ++++++++++++++++++++++++++++++++++------------ 1 files changed, 103 insertions(+), 37 deletions(-) diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java index f686694..7219ae5 100644 --- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java +++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -954,6 +955,41 @@ R<com.alibaba.fastjson.JSONObject> r = HuiFuTianXiaUtil.weixinPayment(outTradeNo, description, payMoney.doubleValue(), openid, request.getNotifyUrl()); if(r.getCode() != 200){ throw new ServiceException(r.getMsg()); + }else{ + new Thread(new Runnable() { + @Override + public void run() { + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); + int time = 0; + for (int i = 0; i < 13; i++) { + try { + time += (5000 * i); + Thread.sleep(time); + } catch (InterruptedException e) { + e.printStackTrace(); + } + R<WeixinPaymentNotifyVo> voR = HuiFuTianXiaUtil.queryPayment(outTradeNo, sdf.format(new Date())); + if(voR.getCode() == 200){ + WeixinPaymentNotifyVo data = voR.getData(); + //P:处理中;S:成功;F:失败;I: 初始(初始状态很罕见,请联系汇付技术人员处理); + String transStat = data.getTransStat(); + if("S".equals(transStat)){ + PartnerTransactionsResult transaction = new PartnerTransactionsResult(); + transaction.setOutTradeNo(data.getReqSeqId()); + payBack(transaction, data.getFeeFlag() == 1 ? BigDecimal.ZERO : new BigDecimal(data.getFeeAmount())); + return; + } + if("P".equals(transStat) || "F".equals(transStat)){ + continue; + } + log.error("支付失败,流水号:{}, 状态码:{}", outTradeNo, transStat); + return; + }else{ + log.error("支付查询失败!流水号:{},结果:{}", outTradeNo, voR.getMsg()); + } + } + } + }).start(); } com.alibaba.fastjson.JSONObject data = r.getData(); String mainMchId = WxPayConfiguration.getPlatformTyMacId(); @@ -1897,10 +1933,14 @@ } this.saveOrUpdate(order); // 订单金额大于0时进行分账 - if (order.getOnlinePayMoney().compareTo(BigDecimal.ZERO)>0) { + OrderPayment orderPayment = orderPaymentService.getOne(new QueryWrapper<OrderPayment>() + .eq("order_id", order.getOrderId()).eq("pay_status", 2) + .eq("del_flag", 0)); + BigDecimal bigDecimal = orderPayment.getPayMoney().subtract(orderPayment.getFeeAmount()).setScale(2, BigDecimal.ROUND_HALF_EVEN); + if (bigDecimal.compareTo(BigDecimal.ZERO)>0) { // TODO: 2023/10/17 更换分账渠道(汇付天下) // submitProfitSharing(orderId, order.getOrderNo(), order.getShopId(), order.getOnlinePayMoney(),order.getOrderFrom()); - submitProfitSharing1(orderId, order.getOrderNo(), order.getShopId(), order.getOnlinePayMoney(),order.getOrderFrom()); + submitProfitSharing1(orderId, order.getOrderNo(), order.getShopId(), bigDecimal, order.getOrderFrom()); } //创建支付记录 if(merVerifyOrderDto.getRelPayMoney().compareTo(BigDecimal.ZERO)>0){ @@ -2083,7 +2123,7 @@ if(proportionPercent.compareTo(BigDecimal.ZERO)>0){ PaymentDelaytransHFTXVo result = new PaymentDelaytransHFTXVo(); // 计算分成金额 - int amount = orderMoney.multiply(proportionPercent).setScale(0, RoundingMode.UP).intValue(); + int amount = orderMoney.multiply(new BigDecimal(100)).setScale(0, RoundingMode.HALF_EVEN).intValue(); BigDecimal multiply = orderMoney.multiply(proportionPercent.divide(new BigDecimal(100))).setScale(2, RoundingMode.HALF_EVEN); log.info("订单分账:{} 分账金额: {}", orderNo, amount); if (amount > 0) { @@ -2100,16 +2140,21 @@ //分账对象 JSONArray acctInfos = new JSONArray(); - JSONObject jsonObject = new JSONObject(); - jsonObject.put("div_amt", String.format("%.2f", multiply.doubleValue())); - jsonObject.put("huifu_id", vo.getHuifuId()); - acctInfos.add(jsonObject); + if(multiply.compareTo(BigDecimal.ZERO) > 0){ + JSONObject jsonObject = new JSONObject(); + jsonObject.put("div_amt", String.format("%.2f", multiply.doubleValue())); + jsonObject.put("huifu_id", vo.getHuifuId()); + acctInfos.add(jsonObject); + } //平台商户 - double pt_amount = orderMoney.subtract(multiply).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("div_amt", String.format("%.2f", pt_amount)); - jsonObject1.put("huifu_id", "6666000141216769"); - acctInfos.add(jsonObject1); + BigDecimal pt_amount = orderMoney.subtract(multiply).setScale(2, RoundingMode.HALF_EVEN); + if(pt_amount.compareTo(BigDecimal.ZERO) > 0){ + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("div_amt", String.format("%.2f", pt_amount.doubleValue())); + jsonObject1.put("huifu_id", "6666000141216769"); + acctInfos.add(jsonObject1); + } + R<PaymentDelaytransHFTXVo> hftxVoR = HuiFuTianXiaUtil.paymentDelaytrans(request.getOutOrderNo(), org_req_date, outTradeNo, acctInfos); if(hftxVoR.getCode() != 200){ throw new ServiceException(hftxVoR.getMsg()); @@ -2845,7 +2890,7 @@ // 根据用户ID列表获取用户信息 MgtBaseBathDto mgtBaseBathDto = new MgtBaseBathDto(); mgtBaseBathDto.setIds(userIdSj.toString()); - List<MgtSimpleMemberVo> simpleMemberVoList = remoteMemberService.listSimpleVoByIds(mgtBaseBathDto).getData(); + List<MgtSimpleMemberVo> simpleMemberVoList = remoteMemberService.listSimpleVoByIds(userIdSj.toString()).getData(); Map<Long, MgtSimpleMemberVo> userMap = simpleMemberVoList.stream() .collect(Collectors.toMap(MgtSimpleMemberVo::getUserId, Function.identity())); // 遍历订单列表,设置用户信息 @@ -3005,13 +3050,14 @@ .collect(Collectors.toMap(MgtSimpleShopVo::getShopId, Function.identity())); mgtBaseBathDto = new MgtBaseBathDto(); mgtBaseBathDto.setIds(userJoinedString); - List<MgtSimpleMemberVo> simpleMemberVoList = remoteMemberService.listSimpleVoByIds(mgtBaseBathDto).getData(); + List<MgtSimpleMemberVo> simpleMemberVoList = remoteMemberService.listSimpleVoByIds(userJoinedString).getData(); Map<Long, MgtSimpleMemberVo> userMap = simpleMemberVoList.stream() .collect(Collectors.toMap(MgtSimpleMemberVo::getUserId, Function.identity())); // 遍历列表,设置店铺名称、用户名称和未支付金额 for (MgtActivityOrderPageVo mgtActivityOrderPageVo : activityOrderPageVoList) { if(mgtActivityOrderPageVo.getShopId()!=null){ - mgtActivityOrderPageVo.setShopName(shopMap.get(mgtActivityOrderPageVo.getShopId()).getShopName()); + MgtSimpleShopVo mgtSimpleShopVo = shopMap.get(mgtActivityOrderPageVo.getShopId()); + mgtActivityOrderPageVo.setShopName(null == mgtSimpleShopVo ? "" : mgtSimpleShopVo.getShopName()); } if (userMap.get(mgtActivityOrderPageVo.getUserId()) != null) { @@ -3130,7 +3176,7 @@ String userJoinedString = String.join(",", userIdSet.stream().map(Object::toString).collect(Collectors.toList())); MgtBaseBathDto mgtBaseBathDto = new MgtBaseBathDto(); mgtBaseBathDto.setIds(userJoinedString); - List<MgtSimpleMemberVo> simpleMemberVoList = remoteMemberService.listSimpleVoByIds(mgtBaseBathDto).getData(); + List<MgtSimpleMemberVo> simpleMemberVoList = remoteMemberService.listSimpleVoByIds(userJoinedString).getData(); userMap = simpleMemberVoList.stream() .collect(Collectors.toMap(MgtSimpleMemberVo::getUserId, Function.identity())); } @@ -3181,8 +3227,6 @@ Order order = this.getById(orderId); // 获取会员信息 Member member = remoteMemberService.getMember(order.getUserId()).getData(); - // 获取商店信息 - Shop shop = remoteShopService.getShop(order.getShopId()).getData(); // 获取订单商品详细信息 List<MgtOrderGoodsDetailVo> orderGoodsDetailVoList = orderGoodsService.listMgtVoByOrderId(orderId); // 设置MgtOrderDetailVo属性 @@ -3212,6 +3256,7 @@ } // 设置订单编号 mgtOrderDetailVo.setOrderNo(order.getOrderNo()); + mgtOrderDetailVo.setOutTradeNo(order.getOutTradeNo()); // 设置订单来源 switch (order.getOrderFrom()) { case 1: @@ -3242,10 +3287,12 @@ mgtOrderDetailVo.setCancelTime(order.getCancelTime()); mgtOrderDetailVo.setOrderRemark(order.getOrderRemark()); mgtOrderDetailVo.setShopId(order.getShopId()); - if (shop != null) { + if (3 == order.getOrderStatus()) { + // 获取商店信息 + Shop shop = remoteShopService.getShop(order.getShopId()).getData(); mgtOrderDetailVo.setShopName(shop.getShopName()); } else { - mgtOrderDetailVo.setShopName("商户已被删除"); + mgtOrderDetailVo.setShopName(""); } mgtOrderDetailVo.setVerifyTime(order.getUseTime()); //获取支付记录 @@ -3872,7 +3919,7 @@ mgtTotalOrderTotalVo.setOrderTotal(totalOrderTotalVo.getOrderTotal()); mgtTotalOrderTotalVo.setOnlineTotal(totalOrderTotalVo.getOnlineTotal()); mgtTotalOrderTotalVo.setOfflineTotal(totalOrderTotalVo.getOfflineTotal()); - mgtTotalOrderTotalVo.setActivityTotal(0); + mgtTotalOrderTotalVo.setActivityTotal(totalOrderTotalVo.getActivityTotal()); mgtTotalOrderTotalVo.setOrderMoney(totalOrderTotalVo.getOrderMoney()); mgtTotalOrderTotalVo.setOnlineMoney(totalOrderTotalVo.getOnlineMoney()); mgtTotalOrderTotalVo.setOfflineMoney(totalOrderTotalVo.getOfflineMoney()); @@ -5007,7 +5054,7 @@ String userJoinedString = String.join(",", userIdSet.stream().map(Object::toString).collect(Collectors.toList())); MgtBaseBathDto mgtBaseBathDto = new MgtBaseBathDto(); mgtBaseBathDto.setIds(userJoinedString); - List<MgtSimpleMemberVo> simpleMemberVoList = remoteMemberService.listSimpleVoByIds(mgtBaseBathDto).getData(); + List<MgtSimpleMemberVo> simpleMemberVoList = remoteMemberService.listSimpleVoByIds(userJoinedString).getData(); userMap = simpleMemberVoList.stream() .collect(Collectors.toMap(MgtSimpleMemberVo::getUserId, Function.identity())); } @@ -5067,6 +5114,9 @@ try { redissonLock.lock(30, TimeUnit.SECONDS); Integer surpNum = redisService.getCacheObject(SecurityConstant.ACTIVITY_GOODS + "-" + order.getActivityId() + "-" + orderGoods.getGoodsId()); + if(null == surpNum){ + surpNum = 0; + } redisService.setCacheObject(SecurityConstant.ACTIVITY_GOODS + "-" + order.getActivityId() + "-" + orderGoods.getGoodsId(), surpNum + orderGoods.getBuyNum()); } finally { redissonLock.unlock(); @@ -5117,7 +5167,7 @@ @Override @Transactional @GlobalTransactional(rollbackFor = Exception.class) - public void payBack(PartnerTransactionsResult transaction) { + public void payBack(PartnerTransactionsResult transaction, BigDecimal feeAmount) { log.info("订单支付回调---"+transaction.toString()); // Order order = this.getById(orderId); // 更新订单状态 outTradeNo @@ -5171,12 +5221,8 @@ goodsTotalChangeDto.setChangeType(1); goodsTotalChangeDto.setChangeNum(orderGoods.getBuyNum()); goodsTotalChangeDto.setMoney(orderGoods.getGoodsReceivableMoney()); - Integer bugGoodsNum = orderMapper.countUserBuyGoodsNum(order.getUserId(), orderGoods.getGoodsId()); - if (bugGoodsNum == null || bugGoodsNum < 1) { - goodsTotalChangeDto.setPersonNum(1); - }else{ - goodsTotalChangeDto.setPersonNum(0); - } + Integer bugGoodsNum = orderMapper.countUserBuyGoodsNum(orderGoods.getGoodsId()); + goodsTotalChangeDto.setPersonNum(bugGoodsNum); goodsTotalChangeDtoList.add(goodsTotalChangeDto); } //更新商品统计 @@ -5251,7 +5297,7 @@ profitsSharingService.applyProfitSharing(request);*/ } //修改支付记录生成支付记录 - orderPaymentService.updatePaySuccess(transaction.getOutTradeNo(), transaction.getTransactionId()); + orderPaymentService.updatePaySuccess(transaction.getOutTradeNo(), feeAmount, transaction.getTransactionId()); PayRecord payRecord = new PayRecord(); payRecord.setDelFlag(0); payRecord.setOrderId(orderId); @@ -5332,6 +5378,9 @@ try { redissonLock.lock(30, TimeUnit.SECONDS); Integer surpNum = redisService.getCacheObject(SecurityConstant.ACTIVITY_GOODS + "-" + order.getActivityId() + "-" + orderGoods.getGoodsId()); + if(null == surpNum){ + surpNum = 0; + } redisService.setCacheObject(SecurityConstant.ACTIVITY_GOODS + "-" + order.getActivityId() + "-" + orderGoods.getGoodsId(), surpNum + orderGoods.getBuyNum()); } finally { redissonLock.unlock(); @@ -5382,12 +5431,8 @@ goodsTotalChangeDto.setChangeType(2); goodsTotalChangeDto.setChangeNum(orderGoods.getBuyNum()); goodsTotalChangeDto.setMoney(orderGoods.getGoodsReceivableMoney()); - Integer bugGoodsNum = orderMapper.countUserBuyGoodsNum(order.getUserId(), orderGoods.getGoodsId()); - if (bugGoodsNum == null || bugGoodsNum <= orderGoods.getBuyNum()) { - goodsTotalChangeDto.setPersonNum(1); - }else{ - goodsTotalChangeDto.setPersonNum(0); - } + Integer bugGoodsNum = orderMapper.countUserBuyGoodsNum(orderGoods.getGoodsId()); + goodsTotalChangeDto.setPersonNum(bugGoodsNum); goodsTotalChangeDtoList.add(goodsTotalChangeDto); } remoteGoodsService.changeGoodsTotal(goodsTotalChangeDtoList); @@ -6069,6 +6114,9 @@ try { redissonLock.lock(30, TimeUnit.SECONDS); Integer surpNum = redisService.getCacheObject(SecurityConstant.ACTIVITY_GOODS + "-" + order.getActivityId() + "-" + orderGoods.getGoodsId()); + if(null == surpNum){ + surpNum = 0; + } redisService.setCacheObject(SecurityConstant.ACTIVITY_GOODS + "-" + order.getActivityId() + "-" + orderGoods.getGoodsId(), surpNum + orderGoods.getBuyNum()); } finally { redissonLock.unlock(); @@ -6148,7 +6196,7 @@ // 获取用户列表 MgtBaseBathDto mgtBaseBathDto = new MgtBaseBathDto(); mgtBaseBathDto.setIds(userIdSj.toString()); - List<MgtSimpleMemberVo> simpleMemberVoList = remoteMemberService.listSimpleVoByIds(mgtBaseBathDto).getData(); + List<MgtSimpleMemberVo> simpleMemberVoList = remoteMemberService.listSimpleVoByIds(userIdSj.toString()).getData(); // 将用户列表转换为Map,以便根据用户ID快速查找用户信息 Map<Long, MgtSimpleMemberVo> userMap = simpleMemberVoList.stream() .collect(Collectors.toMap(MgtSimpleMemberVo::getUserId, Function.identity())); @@ -6229,4 +6277,22 @@ ProfitSharingResult profitSharingResult = wxService.getEcommerceService().queryProfitSharing(request); return profitSharingResult; } + + @Override + public List<String> getActivityOrderGoods(String activityId) { + List<Order> orders = this.baseMapper.selectList(new QueryWrapper<Order>() + .eq("del_flag", 0) + .in("order_status", Arrays.asList(1, 2, 3)) + .eq("activity_id", activityId) + ); + if(orders.size() > 0){ + List<String> collect = orders.stream().map(Order::getOrderId).collect(Collectors.toList()); + List<OrderGoods> list = orderGoodsService.list(new QueryWrapper<OrderGoods>() + .eq("del_flag", 0) + .in("order_id", collect) + ); + return list.stream().map(OrderGoods::getGoodsId).collect(Collectors.toList()); + } + return new ArrayList<>(); + } } -- Gitblit v1.7.1