| | |
| | | package com.ruoyi.order.service.impl.order; |
| | | |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.github.binarywang.wxpay.bean.ecommerce.*; |
| | | import com.github.binarywang.wxpay.bean.ecommerce.ProfitSharingRequest.Receiver; |
| | | import com.github.binarywang.wxpay.bean.ecommerce.enums.TradeTypeEnum; |
| | | import com.github.binarywang.wxpay.bean.ecommerce.PartnerTransactionsResult; |
| | | import com.github.binarywang.wxpay.bean.ecommerce.RefundNotifyResult; |
| | | import com.github.binarywang.wxpay.bean.profitsharingV3.ProfitSharingNotifyResult; |
| | | import com.github.binarywang.wxpay.config.WxPayConfig; |
| | | import com.github.binarywang.wxpay.exception.WxPayException; |
| | | import com.github.binarywang.wxpay.service.WxPayService; |
| | | import com.google.common.base.Joiner; |
| | | import com.google.gson.Gson; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.core.utils.DateUtils; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import com.ruoyi.common.security.utils.CodeFactoryUtil; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.order.config.WxPayConfiguration; |
| | | import com.ruoyi.order.domain.dto.*; |
| | | import com.ruoyi.order.domain.pojo.account.OrderPayment; |
| | | import com.ruoyi.order.domain.pojo.account.OrderRefund; |
| | |
| | | import com.ruoyi.system.api.domain.poji.member.MemberCoupon; |
| | | import com.ruoyi.system.api.domain.poji.member.MemberGiftRecord; |
| | | import com.ruoyi.system.api.domain.poji.shop.Shop; |
| | | import com.ruoyi.system.api.domain.poji.shop.ShopProportionVo; |
| | | import com.ruoyi.system.api.domain.poji.sys.SysUser; |
| | | import com.ruoyi.system.api.domain.vo.*; |
| | | import com.ruoyi.system.api.service.*; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | |
| | | @Autowired |
| | | private RedissonClient redissonClient; |
| | | |
| | | @Autowired |
| | | private WxPayService wxService; |
| | | /*@Autowired |
| | | private WxPayService wxService;*/ |
| | | |
| | | @Resource |
| | | private PaymentMessageService paymentMessageService; |
| | |
| | | order.setDiscountMoney(couponDiscount); |
| | | order.setReceivableMoney(orderPayMoney); |
| | | order.setReceivableDeposit(orderPayDeposit); |
| | | order.setChangeReceivableMoney(orderPayMoney); |
| | | // 根据支付类型计算支付金额 |
| | | if (appPlaceOrderDto.getPayType() == 1) { |
| | | order.setPayMoney(orderPayMoney); |
| | |
| | | order.setPayType(2); |
| | | order.setCloseFlag(0); |
| | | } |
| | | order.setChangeReceivableMoney(appPlaceOrderVo.getUnpaidMoney()); |
| | | order.setOrderRemark(appPlaceOrderDto.getOrderRemark()); |
| | | order.setGoodsNum(goodsNum); |
| | | order.setCreateTime(new Date()); |
| | |
| | | } |
| | | |
| | | // 小程序微信下单支付 |
| | | createWxPayInfo(appPlaceOrderVo, userId, order.getShopId(), goodsName, orderNo, |
| | | /*createWxPayInfo(appPlaceOrderVo, userId, order.getShopId(), goodsName, orderNo, |
| | | orderId, order.getPayMoney(), appPlaceOrderDto.getOpenid(), |
| | | appPlaceOrderDto.getSpbillCreateIp(), goodsNameList); |
| | | appPlaceOrderDto.getSpbillCreateIp(), goodsNameList);*/ |
| | | |
| | | |
| | | //减去优惠券 |
| | |
| | | * @param payerClientIp |
| | | * @param goodsNameList |
| | | */ |
| | | private void createWxPayInfo(AppPlaceOrderVo appPlaceOrderVo, Long userId, Long shopId, |
| | | /*private void createWxPayInfo(AppPlaceOrderVo appPlaceOrderVo, Long userId, Long shopId, |
| | | String goodsName, String orderNo, |
| | | String orderId, BigDecimal payMoney, |
| | | String openid, String payerClientIp, List<String> goodsNameList){ |
| | |
| | | } catch (WxPayException e) { |
| | | throw new ServiceException(e.getMessage()); |
| | | } |
| | | } |
| | | }*/ |
| | | |
| | | |
| | | /** |
| | |
| | | order.setDiscountMoney(couponDiscount); |
| | | order.setReceivableMoney(orderPayMoney); |
| | | order.setReceivableDeposit(orderPayDeposit); |
| | | order.setChangeReceivableMoney(orderPayMoney); |
| | | order.setActivityId(activityId); |
| | | order.setActivityName(activityGoodsGetVo.getActivityName()); |
| | | // 根据支付类型设置订单支付金额,在线支付金额,订单支付金额,未支付金额,关闭标志 |
| | |
| | | appPlaceOrderVo.setUnpaidMoney(order.getReceivableMoney().subtract(order.getPayMoney())); |
| | | order.setPayType(1); |
| | | order.setCloseFlag(1); |
| | | order.setChangeReceivableMoney(orderGoodsMoney.subtract(couponDiscount)); |
| | | } else if (appPlaceActivityDto.getPayType() == 2) { |
| | | order.setPayMoney(orderPayDeposit); |
| | | order.setOnlinePayMoney(orderPayDeposit); |
| | |
| | | appPlaceOrderVo.setUnpaidMoney(order.getReceivableMoney().subtract(order.getPayMoney())); |
| | | order.setPayType(2); |
| | | order.setCloseFlag(0); |
| | | order.setChangeReceivableMoney(orderGoodsMoney.subtract(couponDiscount).subtract(orderPayDeposit)); |
| | | } |
| | | // 设置订单备注,商品数量,创建时间 |
| | | order.setOrderRemark(appPlaceActivityDto.getOrderRemark()); |
| | |
| | | merVerifyOrderVo.setUnReceiveMoney(merVerifyOrderVo.getRealReceiveMoney().subtract(order.getReceivableMoney())); |
| | | // 根据订单用户ID获取用户信息 |
| | | Member member = remoteMemberService.getMember(order.getUserId()).getData(); |
| | | merVerifyOrderVo.setUserId(order.getUserId()); |
| | | merVerifyOrderVo.setUserName(member.getRealName()); |
| | | merVerifyOrderVo.setUserMobile(member.getMobile()); |
| | | merVerifyOrderVo.setCloseFlag(order.getCloseFlag()); |
| | |
| | | } |
| | | merVerifyOrderVo.setUnReceiveMoney(merVerifyOrderVo.getRealReceiveMoney().subtract(order.getReceivableMoney())); |
| | | Member member = remoteMemberService.getMember(order.getUserId()).getData(); |
| | | merVerifyOrderVo.setUserId(order.getUserId()); |
| | | merVerifyOrderVo.setUserName(member.getRealName()); |
| | | merVerifyOrderVo.setUserMobile(member.getMobile()); |
| | | merVerifyOrderVo.setCloseFlag(order.getCloseFlag()); |
| | |
| | | payRecord.setPayType(merVerifyOrderDto.getPayType()); |
| | | payRecordService.save(payRecord); |
| | | |
| | | submitProfitSharing(orderId, order.getOrderNo(), order.getShopId(), order.getOrderMoney()); |
| | | //submitProfitSharing(orderId, order.getOrderNo(), order.getShopId(), order.getOrderMoney()); |
| | | |
| | | return merVerifyOrderVo; |
| | | } |
| | | |
| | | private void submitProfitSharing(String orderId, String orderNo, Long shopId, BigDecimal orderMoney) { |
| | | /*private void submitProfitSharing(String orderId, String orderNo, Long shopId, BigDecimal orderMoney) { |
| | | String sendMessage = ""; |
| | | String resultMessage = ""; |
| | | try { |
| | |
| | | |
| | | // 保存分账信息 |
| | | paymentMessageService.savePaymentMessage("4", orderId, sendMessage, resultMessage); |
| | | } |
| | | }*/ |
| | | |
| | | /** |
| | | * @param merVerifyCouponDto |
| | |
| | | merTotalDto.setShopIdList(shopIdList); |
| | | merTotalDto.setShopId(null); |
| | | } |
| | | if (merTotalDto.getShopAllFlag() != null && merTotalDto.getShopAllFlag() == 1) { |
| | | List<Long> shopIdList = remoteShopService.listShopIdByShopId(merTotalDto.getShopId()).getData(); |
| | | merTotalDto.setShopIdList(shopIdList); |
| | | merTotalDto.setShopId(null); |
| | | } |
| | | MerOrderTotalVo orderTotalVo = orderMapper.getMerOrderTotalOrderFrom(merTotalDto); |
| | | MerOrderTotalVo goodsTypeVo = orderMapper.getMerTotalOrderTotalGoodsType(merTotalDto); |
| | | orderTotalVo.setCycleTotal(goodsTypeVo.getCycleTotal()); |
| | |
| | | goodsTotalChangeDtoList.add(goodsTotalChangeDto); |
| | | } |
| | | //更新商品统计 |
| | | remoteGoodsService.changeGoodsTotal(goodsTotalChangeDtoList); |
| | | // 更新商户统计信息 |
| | | ShopTotalChangeDto shopTotalChangeDto = new ShopTotalChangeDto(); |
| | | shopTotalChangeDto.setShopId(order.getShopId()); |
| | |
| | | if (redisService.hasKey(SecurityConstant.PAY_MONEY_INTEGRAL)) { |
| | | Integer moneyValue = redisService.getCacheObject(SecurityConstant.PAY_MONEY_INTEGRAL); |
| | | BigDecimal moneyValueBig = BigDecimal.valueOf(moneyValue); |
| | | BigDecimal integralBig = moneyValueBig.multiply(order.getPayMoney()); |
| | | BigDecimal integralBig = moneyValueBig.multiply(order.getPayMoney()).setScale(0,BigDecimal.ROUND_HALF_UP); |
| | | Integer integral = Integer.valueOf(integralBig.toString()); |
| | | memberTotalChangeDto.setChangeIntegral(integral); |
| | | memberTotalChangeDto.setTypeIntegral(1); |
| | | memberTotalChangeDto.setOrderId(orderId); |
| | | memberTotalChangeDto.setOrderNo(order.getOrderNo()); |
| | | } |
| | | // 设置会员支付金额和支付时间 |
| | | memberTotalChangeDto.setPayMoney(order.getPayMoney()); |
| | |
| | | BigDecimal onlinePayMoney = order.getOnlinePayMoney(); |
| | | if(BigDecimal.ZERO.compareTo(onlinePayMoney) < 0){ |
| | | // 订单支付金额大于0,可发起退款 |
| | | orderWxApplyRefund(orderId, refundId, onlinePayMoney, orderRefund); |
| | | //orderWxApplyRefund(orderId, refundId, onlinePayMoney, orderRefund); |
| | | } |
| | | |
| | | orderRefund.setRefundStatus(1); |
| | |
| | | /** |
| | | * 申请退款API |
| | | */ |
| | | private void orderWxApplyRefund(String orderId, String outRefundNo, BigDecimal payMoney, OrderRefund orderRefund){ |
| | | /*private void orderWxApplyRefund(String orderId, String outRefundNo, BigDecimal payMoney, OrderRefund orderRefund){ |
| | | try { |
| | | // 创建支付订单 |
| | | OrderPayment orderPayment = orderPaymentService.getByOrderId(orderId); |
| | |
| | | } catch (WxPayException e) { |
| | | throw new ServiceException(e.getMessage()); |
| | | } |
| | | } |
| | | }*/ |
| | | |
| | | /** |
| | | * @param staffTotalDto |