From 970ed0f8df6a19e4e3dae062c4e2e2232a0b97d0 Mon Sep 17 00:00:00 2001 From: huanghongfa <huanghongfa123456> Date: 星期三, 21 四月 2021 11:06:45 +0800 Subject: [PATCH] 删除商家bug修复 --- springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopOrderServiceImpl.java | 179 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 162 insertions(+), 17 deletions(-) diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopOrderServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopOrderServiceImpl.java index 12ec2ce..e434084 100644 --- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopOrderServiceImpl.java +++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopOrderServiceImpl.java @@ -4,11 +4,11 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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.model.dtos.PageDTO; import com.panzhihua.common.model.dtos.shop.*; import com.panzhihua.common.model.vos.R; +import com.panzhihua.common.utlis.DateUtils; import com.panzhihua.common.utlis.WxPayUtils; import com.panzhihua.service_community.dao.ComShopOrderDAO; import com.panzhihua.service_community.model.dos.ComShopOrderDO; @@ -21,11 +21,13 @@ import com.panzhihua.service_community.service.ComShopOrderService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.math.BigDecimal; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -55,12 +57,24 @@ private ComShopOrderGoodsDAO comShopOrderGoodsDAO; @Resource private ComShopOrderDAO comShopOrderDAO; - + @Resource + private ComShopOrderPayDAO comShopOrderPayDAO; + @Value("${min.app.isTest}") + private Boolean isTest; + @Value("${min.app.appid}") + private String appid; + @Value("${min.app.payKey}") + private String payKey; + @Value("${min.app.mchId}") + private String mchId; + @Value("${min.app.notifyUrl}") + private String notifyUrl; /** * 订单预览 - * @param orderPreviewDTO 请求参数 - * @return 订单预览数据 + * + * @param orderPreviewDTO 请求参数 + * @return 订单预览数据 */ @Override public R orderPreview(ComShopOrderPreviewDTO orderPreviewDTO){ @@ -163,11 +177,12 @@ } }else{//查询到用户上一笔订单 ComShopUserAddressDO userAddressDO = comShopUserAddressDAO.selectById(shopOrders.get(0).getReceiverId()); - ComShopUserAddressVO userAddressVO = new ComShopUserAddressVO(); - BeanUtils.copyProperties(userAddressDO,userAddressVO); - orderPreviewVO.setUserAddressVO(userAddressVO); + if(userAddressDO != null){ + ComShopUserAddressVO userAddressVO = new ComShopUserAddressVO(); + BeanUtils.copyProperties(userAddressDO,userAddressVO); + orderPreviewVO.setUserAddressVO(userAddressVO); + } } - return R.ok(orderPreviewVO); } @@ -181,7 +196,6 @@ public R orderCreate(ComShopOrderCreateDTO orderCreateDTO){ //创建返回参数 ComShopOrderVO shopOrderVO = new ComShopOrderVO(); - //查询用户收货地址 ComShopUserAddressDO userAddressDO = comShopUserAddressDAO.selectById(orderCreateDTO.getReceiverId()); if(userAddressDO == null){ @@ -195,10 +209,8 @@ String orderNo = OrderNoUtils.NextOrderNo(userId); //配送方式 Integer deliveryType = 0; - //订单总金额 BigDecimal orderTotal = BigDecimal.ZERO; - //创建订单商品信息 List<ComShopOrderGoodsDO> orderGoodsDOList = new ArrayList<>(); if(!orderCreateDTO.getOrderGoodsList().isEmpty()){ @@ -234,12 +246,10 @@ orderTotal = orderTotal.add(orderGoodsDO.getGoodsAttrPrice().multiply(BigDecimal.valueOf(orderGoodsDO.getAmount()))); } } - //如果是购物车提交,需要将购物车内商品移除 if(orderCreateDTO.getSubmitType().equals(ComShopOrderCreateDTO.submitType.cart)){ comShopCartDAO.deleteBatchIds(orderCreateDTO.getCartIds()); } - //创建订单信息 ComShopOrderDO shopOrderDO = new ComShopOrderDO(); shopOrderDO.setOrderNo(orderNo); @@ -256,14 +266,12 @@ shopOrderDO.setRemark(orderCreateDTO.getRemark()); } this.baseMapper.insert(shopOrderDO); - if(!orderGoodsDOList.isEmpty()){ orderGoodsDOList.forEach(orderGoods ->{ orderGoods.setOrderId(shopOrderDO.getId()); comShopOrderGoodsDAO.insert(orderGoods); }); } - //创建订单操作记录 ComShopOrderOperateDO orderOperateDO = new ComShopOrderOperateDO(); orderOperateDO.setOrderNo(orderNo); @@ -277,14 +285,18 @@ orderOperateDO.setOperationBy("用户"); } comShopOrderOperateDAO.insert(orderOperateDO); - shopOrderVO.setOrderNo(orderNo); shopOrderVO.setOrderTotal(orderTotal); try { + BigDecimal money = orderTotal; + if(isTest){ + money = BigDecimal.valueOf(0.01); + } //调用wx支付 - String xml = WxPayUtils.getUnifiedorder("",orderCreateDTO.getOpenId(),orderNo,orderTotal); + String xml = WxPayUtils.getUnifiedorder(appid,mchId,payKey,notifyUrl,"商品购买",orderCreateDTO.getOpenId(),orderNo,money); log.info("微信支付返回参数:" + xml); + shopOrderVO.setPayResult(xml); }catch (Exception e){ log.error("调用微信支付异常,异常原因:" + e.getMessage()); } @@ -359,6 +371,7 @@ //查询订单下商品信息 List<ComShopOrderGoodsDO> orderGoodsDOList = comShopOrderGoodsDAO.selectList(new QueryWrapper<ComShopOrderGoodsDO>() .eq("order_no",shopOrderDO.getOrderNo())); + StringBuilder sbr = new StringBuilder(""); if(!orderGoodsDOList.isEmpty()){ orderGoodsDOList.forEach(orderGoods -> { ComShopOrderGoodsVO orderGoodsVO = new ComShopOrderGoodsVO(); @@ -367,9 +380,11 @@ orderGoodsVO.setGoodsPic(orderGoods.getGoodsAttrPic()); orderGoodsVO.setPrice(orderGoods.getGoodsAttrPrice()); orderGoodsVOS.add(orderGoodsVO); + sbr.append(orderGoods.getGoodsName() + " " ); }); } orderVO.setOrderGoodsVOList(orderGoodsVOS); + orderVO.setGoodsName(sbr.toString()); ComShopUserAddressVO userAddressVO = new ComShopUserAddressVO(); //查询用户收货地址 @@ -379,6 +394,15 @@ orderVO.setUserAddressVO(userAddressVO); } + //操作日志 + List<ComShopOrderOperateDO> listOperLog = comShopOrderOperateDAO.selectList(new LambdaQueryWrapper<ComShopOrderOperateDO>().eq(ComShopOrderOperateDO::getOrderNo, shopOrderDO.getOrderNo())); + List<ComShopOrderOperateVO> listOperLogVO = new ArrayList<>(listOperLog.size()); + listOperLog.forEach(logDO ->{ + ComShopOrderOperateVO copyVO = new ComShopOrderOperateVO(); + BeanUtils.copyProperties(logDO,copyVO); + listOperLogVO.add(copyVO); + }); + orderVO.setLogs(listOperLogVO); return R.ok(orderVO); } @@ -596,6 +620,12 @@ @Override public R getFundsStat(Long userId) { ComShopFundsVO comShopFundsVO = comShopOrderDAO.queryStatis(userId); + if(comShopFundsVO==null){ + comShopFundsVO = new ComShopFundsVO(); + comShopFundsVO.setMonthTotal(new BigDecimal(0)); + comShopFundsVO.setTodayTotal(new BigDecimal(0)); + comShopFundsVO.setWeekTotal(new BigDecimal(0)); + } return R.ok(comShopFundsVO); } @@ -634,4 +664,119 @@ IPage<ComShopOrderSearchVO> ipage = this.baseMapper.pageOrderBy(page, pageComShopOrderSearchDTO); return R.ok(ipage); } + + @Override + public R capitalDetailByStore(Long id) { + if(id==null){ + R.fail("订单号不能为空!"); + } + CapitalDetailVO vo = this.baseMapper.capitalDetailByStore(id); + return R.ok(vo); + } + + /** + * 微信支付订单回调 + * @param wxPayNotifyOrderDTO 订单支付回调参数 + */ + @Transactional(rollbackFor = Exception.class) + @Override + public void wxOrderPayNotify(WxPayNotifyOrderDTO wxPayNotifyOrderDTO){ + log.info("微信订单支付回调开始处理逻辑"); + if(StringUtils.isEmpty(wxPayNotifyOrderDTO.getOrderTradeNo())){ + log.error("微信支付回调失败,订单号为空"); + return; + } + + log.info("微信订单支付回调开始查询订单"); + //查询订单 + ComShopOrderDO shopOrderDO = this.baseMapper.selectOne(new QueryWrapper<ComShopOrderDO>().lambda().eq(ComShopOrderDO::getOrderNo,wxPayNotifyOrderDTO.getOrderTradeNo())); + if(shopOrderDO == null){ + log.error("未查询到支付订单,订单回调失败,订单号:" + wxPayNotifyOrderDTO.getOrderTradeNo()); + return; + } + shopOrderDO.setStatus(ComShopOrderDO.status.dfh); + shopOrderDO.setPayType(ComShopOrderDO.payType.wx); + shopOrderDO.setPayStatus(ComShopOrderDO.payStatus.yes); + shopOrderDO.setPayAmount(BigDecimal.valueOf(Integer.parseInt(wxPayNotifyOrderDTO.getCashFee()) / 100)); + shopOrderDO.setWxTardeNo(wxPayNotifyOrderDTO.getWxTradeNo()); + shopOrderDO.setPayTime(DateUtils.stringToDate(wxPayNotifyOrderDTO.getPayTime(),new SimpleDateFormat("yyyyMMddHHmmss"))); + this.baseMapper.updateById(shopOrderDO); + + //查询订单商品 + List<ComShopOrderGoodsDO> orderGoodsList = comShopOrderGoodsDAO.selectList(new QueryWrapper<ComShopOrderGoodsDO>().lambda().eq(ComShopOrderGoodsDO ::getOrderNo,shopOrderDO.getOrderNo())); + if(!orderGoodsList.isEmpty()){ + int goodsNub = 0; + for (ComShopOrderGoodsDO orderGood:orderGoodsList) { + goodsNub += orderGood.getAmount(); + //更新商品信息 + ComShopGoodsDO goodsDO = comShopGoodsDAO.selectById(orderGood.getGoodsId()); + if(goodsDO != null){ + goodsDO.setSale(goodsDO.getSale() + orderGood.getAmount()); + comShopGoodsDAO.updateById(goodsDO); + } + + //更新商品规格 + ComShopGoodsAttrDO goodsAttrDO = comShopGoodsAttrDAO.selectById(orderGood.getGoodsAttrId()); + if(goodsAttrDO != null){ + goodsAttrDO.setSale(goodsAttrDO.getSale() + orderGood.getAmount()); + comShopGoodsAttrDAO.updateById(goodsAttrDO); + } + } + + //更新店铺销量以及销售额 + ComShopStoreDO storeDO = comShopStoreDAO.selectById(shopOrderDO.getStoreId()); + if(storeDO != null){ + storeDO.setSale(storeDO.getSale() + goodsNub); + storeDO.setSaleVolume(storeDO.getSaleVolume().add(shopOrderDO.getTotalAmount())); + comShopStoreDAO.updateById(storeDO); + } + } + + //添加订单操作记录 + ComShopOrderOperateDO orderOperateDO = new ComShopOrderOperateDO(); + orderOperateDO.setOrderNo(shopOrderDO.getOrderNo()); + orderOperateDO.setOperationType(ComShopOrderOperateDO.operationType.pay); + orderOperateDO.setOperationTime(new Date()); + orderOperateDO.setOperationContent("用户支付订单"); + orderOperateDO.setOperationBy("用户"); + comShopOrderOperateDAO.insert(orderOperateDO); + + //添加订单支付记录表 + ComShopOrderPayDO orderPayDO = new ComShopOrderPayDO(); + orderPayDO.setOrderNo(shopOrderDO.getOrderNo()); + orderPayDO.setOrderAmount(shopOrderDO.getTotalAmount()); + orderPayDO.setWxTradeNo(wxPayNotifyOrderDTO.getWxTradeNo()); + orderPayDO.setPayStatus(ComShopOrderPayDO.payStatus.yes); + orderPayDO.setPayAmount(shopOrderDO.getPayAmount()); + orderPayDO.setPayTime(shopOrderDO.getPayTime()); + comShopOrderPayDAO.insert(orderPayDO); + } + + /** + * 订单去支付 + * @param orderPayDTO 请求参数 + * @return 支付对象 + */ + public R wxPay(OrderPayDTO orderPayDTO){ + //创建返回参数 + ComShopOrderVO shopOrderVO = new ComShopOrderVO(); + //查询订单 + ComShopOrderDO orderDO = comShopOrderDAO.selectOne(new QueryWrapper<ComShopOrderDO>().lambda().eq(ComShopOrderDO::getOrderNo,orderPayDTO.getOrderNo())); + if(orderDO == null){ + return R.fail("订单不存在"); + } + try { + BigDecimal money = orderDO.getTotalAmount(); + if(isTest){ + money = BigDecimal.valueOf(0.01); + } + //调用wx支付 + String xml = WxPayUtils.getUnifiedorder(appid,mchId,payKey,notifyUrl,"商品购买",orderPayDTO.getOpenId(),orderDO.getOrderNo(),money); + log.info("微信支付返回参数:" + xml); + shopOrderVO.setPayResult(xml); + }catch (Exception e){ + log.error("调用微信支付异常,异常原因:" + e.getMessage()); + } + return R.ok(shopOrderVO); + } } -- Gitblit v1.7.1