From 70d2a5d0f9c6951b2d4cac954041ed73582ff7eb Mon Sep 17 00:00:00 2001 From: liujie <1793218484@qq.com> Date: 星期一, 09 六月 2025 11:54:00 +0800 Subject: [PATCH] 6.9新增登录失败冻结逻辑 --- springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopFlowerOrderServiceImpl.java | 144 ++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 120 insertions(+), 24 deletions(-) diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopFlowerOrderServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopFlowerOrderServiceImpl.java index 8c6ec90..17e2145 100644 --- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopFlowerOrderServiceImpl.java +++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopFlowerOrderServiceImpl.java @@ -1,26 +1,34 @@ package com.panzhihua.service_community.service.impl; +import cn.binarywang.wx.miniapp.api.WxMaService; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DatePattern; +import cn.hutool.core.date.DateUnit; +import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.panzhihua.common.constants.Constants; import com.panzhihua.common.model.dtos.shop.*; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.model.vos.community.convenient.ConvenientElevatingPointVO; import com.panzhihua.common.model.vos.community.convenient.ConvenientMerchantVO; import com.panzhihua.common.model.vos.shop.*; -import com.panzhihua.common.utlis.DateUtils; -import com.panzhihua.common.utlis.OrderNoUtils; -import com.panzhihua.common.utlis.StringUtils; -import com.panzhihua.common.utlis.WxPayUtils; +import com.panzhihua.common.model.vos.user.SysUserVO; +import com.panzhihua.common.service.user.UserService; +import com.panzhihua.common.utlis.*; import com.panzhihua.common.utlis.wx.WXPayUtil; import com.panzhihua.service_community.dao.*; import com.panzhihua.service_community.model.dos.*; import com.panzhihua.service_community.service.ComShopFlowerOrderService; +import com.panzhihua.service_community.util.WxMaConfiguration; import lombok.extern.slf4j.Slf4j; +import me.chanjar.weixin.common.error.WxErrorException; +import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -28,6 +36,7 @@ import javax.annotation.Resource; import java.math.BigDecimal; +import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; @@ -71,6 +80,12 @@ private ComShopFlowerRefundOrderDAO comShopFlowerRefundOrderDAO; @Resource private ComShopFlowerOrderDeliveryDAO comShopFlowerOrderDeliveryDAO; + @Resource + private WxMaConfiguration wxMaConfiguration; + @Resource + private UserService userService; + @Resource + private RabbitTemplate rabbitTemplate; @Value("${hcMin.app.isTest}") @@ -326,6 +341,12 @@ } catch (Exception e) { log.error("调用微信支付异常,异常原因:" + e.getMessage()); } + //发送消息到mq + rabbitTemplate.convertAndSend("huacheng.shop.order.exchange", "huacheng.shop.order.key", shopOrderVO, message -> { + //30分钟后 + message.getMessageProperties().setHeader("x-delay", 1800*1000); + return message; + }); return R.ok(shopOrderVO); } @@ -350,10 +371,10 @@ ComShopFlowerOrderGoodsVO orderGoodsVO = new ComShopFlowerOrderGoodsVO(); BeanUtils.copyProperties(orderGoods, orderGoodsVO); // 根据商品规格id查询商品规格 - ComShopFlowerGoodsAttrDO goodsAttrDO = comShopFlowerGoodsAttrDAO.selectById(orderGoods.getGoodsAttrId()); - if (goodsAttrDO != null) { - orderGoodsVO.setGoodsAttr(goodsAttrDO.getGoodsAttrName()); - } +// ComShopFlowerGoodsAttrDO goodsAttrDO = comShopFlowerGoodsAttrDAO.selectById(orderGoods.getGoodsAttrId()); +// if (goodsAttrDO != null) { + orderGoodsVO.setGoodsAttr(orderGoods.getGoodsAttrName()); +// } orderGoodsVO.setNum(orderGoods.getAmount()); orderGoodsVO.setGoodsPic(orderGoods.getGoodsAttrPic()); orderGoodsVO.setPrice(orderGoods.getGoodsAttrPrice()); @@ -377,6 +398,24 @@ orderVo.setComShopFlowerEvaluateVO(comShopFlowerEvaluateVO); } } + + //判断是否可以退款 订单是否已超过15天 是否已有退款订单 + int count = comShopFlowerRefundOrderDAO.selectCountRefundNowByOrderId(orderVo.getOrderId()); + if (count > 0){ + orderVo.setRefundable(2); + }else { + if (null == orderVo.getReceivingTime()){ + orderVo.setRefundable(2); + }else { + //收货时间往前推15天和当前时间做比较 + Date date = DateUtils.addDay(orderVo.getReceivingTime(), 15); + if(date.before(new Date())){ + orderVo.setRefundable(2); + } + } + } + + }); } return R.ok(orderPageVOIPage); @@ -399,7 +438,7 @@ //查询自提点信息 ConvenientElevatingPointDO convenientElevatingPointDO = convenientElevatingPointDAO.selectOne(new LambdaQueryWrapper<ConvenientElevatingPointDO>().eq(ConvenientElevatingPointDO::getWechatAccount, phone)); if (isNull(convenientElevatingPointDO)) { - return R.fail("自提点不存在"); + return R.ok("订单不在该自提点"); } Long pointDOId = convenientElevatingPointDO.getId(); shopOrderDO = this.baseMapper.selectOne(new LambdaQueryWrapper<ComShopFlowerOrderDO>().eq(ComShopFlowerOrderDO::getId, orderId).eq(ComShopFlowerOrderDO::getPointId, pointDOId)); @@ -433,7 +472,7 @@ orderGoodsVO.setGoodsPic(orderGoods.getGoodsAttrPic()); orderGoodsVO.setPrice(orderGoods.getGoodsAttrPrice()); // 查询商品信息判断商品状态 - ComShopFlowerGoodsDO goodsDO = comShopFlowerGoodsDAO.selectById(orderGoods.getGoodsId()); + /* ComShopFlowerGoodsDO goodsDO = comShopFlowerGoodsDAO.selectById(orderGoods.getGoodsId()); if (goodsDO == null || goodsDO.getDeleteStatus().equals(ComShopFlowerGoodsDO.deleteStatus.yes) || goodsDO.getDeleteStatus().equals(ComShopFlowerGoodsDO.status.recovery)) { orderGoodsVO.setGoodsStatus(ComShopFlowerOrderGoodsVO.goodsStatus.ysc); @@ -441,17 +480,18 @@ orderGoodsVO.setGoodsStatus(ComShopFlowerOrderGoodsVO.goodsStatus.yxj); } else if (goodsDO.getStatus().equals(ComShopFlowerGoodsDO.status.sell)) { orderGoodsVO.setGoodsStatus(ComShopFlowerOrderGoodsVO.goodsStatus.csz); - } + }*/ // 根据商品规格id查询商品规格 - ComShopFlowerGoodsAttrDO goodsAttrDO = comShopFlowerGoodsAttrDAO.selectById(orderGoods.getGoodsAttrId()); - if (goodsAttrDO != null) { - orderGoodsVO.setGoodsAttr(goodsAttrDO.getGoodsAttrName()); - } +// ComShopFlowerGoodsAttrDO goodsAttrDO = comShopFlowerGoodsAttrDAO.selectById(orderGoods.getGoodsAttrId()); + orderGoodsVO.setGoodsAttr(orderGoods.getGoodsAttrName()); orderGoodsVOS.add(orderGoodsVO); sbr.append(orderGoods.getGoodsName()).append(" "); }); + orderVO.setGoodsAttrPic(orderGoodsDOList.get(0).getGoodsAttrPic()); + orderVO.setGoodsAttrName(orderGoodsDOList.get(0).getGoodsAttrName()); } + orderVO.setOrderGoodsVOList(orderGoodsVOS); orderVO.setGoodsName(sbr.toString()); @@ -464,7 +504,7 @@ } // 操作日志 - List<ComShopFlowerOrderOperateDO> listOperLog = +/* List<ComShopFlowerOrderOperateDO> listOperLog = comShopFlowerOrderOperateDAO.selectList(new LambdaQueryWrapper<ComShopFlowerOrderOperateDO>() .eq(ComShopFlowerOrderOperateDO::getOrderNo, shopOrderDO.getOrderNo())); List<ComShopFlowerOrderOperateVO> listOperLogVO = new ArrayList<>(listOperLog.size()); @@ -473,7 +513,7 @@ BeanUtils.copyProperties(logDO, copyVO); listOperLogVO.add(copyVO); }); - orderVO.setLogs(listOperLogVO); + orderVO.setLogs(listOperLogVO);*/ Long pointId = shopOrderDO.getPointId(); if (null != pointId) { ConvenientElevatingPointDO convenientElevatingPointDO = convenientElevatingPointDAO.selectById(pointId); @@ -489,15 +529,33 @@ } } //设置退款金额 - ComShopFlowerRefundOrderDO comShopFlowerRefundOrderDO = comShopFlowerRefundOrderDAO.selectOne(new LambdaQueryWrapper<ComShopFlowerRefundOrderDO>().eq(ComShopFlowerRefundOrderDO::getOrderId, shopOrderDO.getOrderNo())); + ComShopFlowerRefundOrderDO comShopFlowerRefundOrderDO = comShopFlowerRefundOrderDAO.selectOne(new LambdaQueryWrapper<ComShopFlowerRefundOrderDO>().eq(ComShopFlowerRefundOrderDO::getOrderId, shopOrderDO.getId())); if (nonNull(comShopFlowerRefundOrderDO)) { orderVO.setRefundAmount(comShopFlowerRefundOrderDO.getRefundAmount()); + orderVO.setRefundTime(comShopFlowerRefundOrderDO.getRefundTime()); } //如果状态时取消状态,更新时间为去取消时间 if (shopOrderDO.getStatus() == ComShopFlowerOrderDO.status.yqx) { orderVO.setCancelTime(shopOrderDO.getUpdateAt()); } + //判断是否可以退款 订单是否已超过15天 是否已有退款订单 + int count = comShopFlowerRefundOrderDAO.selectCountRefundNowByOrderId(orderId); + if (count > 0){ + orderVO.setRefundable(2); + }else { + if (null == orderVO.getReceivingTime()){ + orderVO.setRefundable(2); + }else { + //收货时间往前推15天和当前时间做比较 + Date date = DateUtils.addDay(orderVO.getReceivingTime(), 15); + if(date.before(new Date())){ + orderVO.setRefundable(2); + } + } + } + + return R.ok(orderVO); } @@ -646,6 +704,14 @@ orderOperateDO.setOperationBy("用户"); } comShopFlowerOrderOperateDAO.insert(orderOperateDO); + + //一个自提订单算一个货 + if (ComShopFlowerOrderDO.deliveryType.store == shopOrderDO.getDeliveryType()){ + ConvenientElevatingPointDO convenientElevatingPointDO = convenientElevatingPointDAO.selectById(shopOrderDO.getPointId()); + convenientElevatingPointDO.setPrepareGoodsNum(convenientElevatingPointDO.getPrepareGoodsNum() - 1); + convenientElevatingPointDO.setAlreadyGoodsNum(convenientElevatingPointDO.getAlreadyGoodsNum() + 1); + convenientElevatingPointDAO.updateById(convenientElevatingPointDO); + } return R.ok(); } else { return R.fail("确认收货失败"); @@ -692,6 +758,17 @@ int inserted = comShopFlowerOrderOperateDAO.insert(orderOperateDO); if (inserted != 1) { log.error("订单发货日志保存错误"); + } + //发货通知 + WxMaService maService = wxMaConfiguration.getMaService(Constants.HC_APP_ID); + R userOpenId = userService.getUserOpenId(comShopOrderDO.getUserId()); + if (R.isOk(userOpenId)) { + String openid = userOpenId.getData().toString(); + try { + WxUtil.sendDeliverGoodsNotice(openid,maService.getAccessToken(),orderShipDTO.getLogisticsCompany(),orderShipDTO.getLogisticsNo(),comShopOrderDO.getOrderNo(), DateUtil.format(new Date(), "yyyy-MM-dd HH:mm")); + } catch (WxErrorException e) { + e.printStackTrace(); + } } return R.ok("发货成功"); } @@ -833,6 +910,9 @@ List<ComShopFlowerOrderGoodsDO> orderGoodsList = comShopFlowerOrderGoodsDAO.selectList(new QueryWrapper<ComShopFlowerOrderGoodsDO>().lambda() .eq(ComShopFlowerOrderGoodsDO::getOrderNo, shopOrderDO.getOrderNo())); + + ConvenientMerchantDO storeDO = convenientMerchantDAO.selectById(shopOrderDO.getStoreId()); + if (!orderGoodsList.isEmpty()) { int goodsNub = 0; for (ComShopFlowerOrderGoodsDO orderGood : orderGoodsList) { @@ -855,7 +935,6 @@ } // 更新店铺销量以及销售额 - ConvenientMerchantDO storeDO = convenientMerchantDAO.selectById(shopOrderDO.getStoreId()); if (storeDO != null) { storeDO.setSale(storeDO.getSale() + goodsNub); storeDO.setSaleVolume(storeDO.getSaleVolume().add(shopOrderDO.getTotalAmount())); @@ -885,6 +964,23 @@ orderPayDO.setOrderId(shopOrderDO.getId()); orderPayDO.setPayType(ComShopFlowerOrderPayDO.payType.zf); comShopFlowerOrderPayDAO.insert(orderPayDO); + if (nonNull(storeDO)){ + WxMaService maService = wxMaConfiguration.getMaService(Constants.HC_APP_ID); + R sysUserVOR = userService.getSysUserVOByPhone(storeDO.getMobilePhone()); + if (R.isOk(sysUserVOR)) { + SysUserVO sysUserVO = JSONObject.parseObject(JSONObject.toJSONString(sysUserVOR.getData()), SysUserVO.class); + try { + DecimalFormat df = new DecimalFormat("#.00"); + WxUtil.sendNewOrderNotice(sysUserVO.getOpenid(),maService.getAccessToken(),shopOrderDO.getOrderNo(), + shopOrderDO.getDeliveryType()==1?"拼单订单":"快递订单",orderGoodsList.get(0).getGoodsName(), + df.format(shopOrderDO.getTotalAmount()), + DateUtil.format(shopOrderDO.getCreateAt(),"yyyy-MM-dd HH:mm")); + } catch (WxErrorException e) { + e.printStackTrace(); + } + } + } + } /** @@ -951,8 +1047,8 @@ Map<String, Integer> retMap = new HashMap<>(); int amountTotal = 0; for (int i = 0; i < statusStr.length; i++) { - if (collect.containsKey(i)) { - Integer amount = collect.get(i); + if (collect.containsKey(i+1)) { + Integer amount = collect.get(i+1); amountTotal = amountTotal + amount; retMap.put(statusStr[i], amount); } else { @@ -990,8 +1086,8 @@ R r1 = this.selectCountByDeliveryType(ComShopFlowerOrderDO.deliveryType.express, userId); retMap.put("kdddStatus", r1.getData()); //营业额 - List<ComShopOrderStoreIdCountVO> comShopOrderStoreIdCountVOS3 = this.baseMapper.selectSumAmountByStoreId(storeId); - Map<String, Integer> yyeMap = comShopOrderStoreIdCountVOS3.stream().collect(Collectors.toMap(ComShopOrderStoreIdCountVO::getCountName, ComShopOrderStoreIdCountVO::getCountNum)); + List<ComShopOrderStoreIdNumVO> comShopOrderStoreIdCountVOS3 = this.baseMapper.selectSumAmountByStoreId(storeId); + Map<String, BigDecimal> yyeMap = comShopOrderStoreIdCountVOS3.stream().collect(Collectors.toMap(ComShopOrderStoreIdNumVO::getCountName, ComShopOrderStoreIdNumVO::getCountNum)); retMap.put("yye", yyeMap); //在售商品 Integer countSale = comShopFlowerGoodsDAO.selectCountSaleByStoreId(storeId); @@ -999,7 +1095,6 @@ //退款申请 Integer refundOrder = comShopFlowerRefundOrderDAO.selectCountByStoreId(storeId); retMap.put("refundOrder", refundOrder); - return R.ok(retMap); } @@ -1122,4 +1217,5 @@ comShopFlowerOrderDeliveryNoListVO.setPage(orderPageVOIPage); return R.ok(comShopFlowerOrderDeliveryNoListVO); } + } -- Gitblit v1.7.1