|  |  |  | 
|---|
|  |  |  | package com.ruoyi.order.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.toolkit.Wrappers; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.ruoyi.order.mapper.TShoppingOrderMapper; | 
|---|
|  |  |  | import com.ruoyi.order.service.TShoppingOrderRefundService; | 
|---|
|  |  |  | import com.ruoyi.order.service.TShoppingOrderService; | 
|---|
|  |  |  | import com.ruoyi.order.util.RedisLock; | 
|---|
|  |  |  | import com.ruoyi.other.api.domain.TCoupon; | 
|---|
|  |  |  | import com.ruoyi.other.api.domain.TGoods; | 
|---|
|  |  |  | import com.ruoyi.other.api.feignClient.CouponClient; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.ruoyi.payment.api.vo.AliQueryOrder; | 
|---|
|  |  |  | import com.ruoyi.payment.api.vo.NotifyV3PayDecodeRespBody; | 
|---|
|  |  |  | import io.seata.spring.annotation.GlobalTransactional; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.data.redis.core.RedisTemplate; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.util.StringUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | import java.math.BigDecimal; | 
|---|
|  |  |  | import java.math.RoundingMode; | 
|---|
|  |  |  | import java.text.SimpleDateFormat; | 
|---|
|  |  |  | import java.time.LocalDate; | 
|---|
|  |  |  | import java.time.LocalDateTime; | 
|---|
|  |  |  | import java.time.format.DateTimeFormatter; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | public class TShoppingOrderServiceImpl extends ServiceImpl<TShoppingOrderMapper, TShoppingOrder> implements TShoppingOrderService { | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private TokenService tokenService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private GoodsClient goodsClient; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private CouponClient couponClient; | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private AppUserClient appUserClient; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private AppUserAddressClient appUserAddressClient; | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private AppCouponClient appCouponClient; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private WxPaymentClient wxPaymentClient; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private AliPaymentClient aliPaymentClient; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private TShoppingOrderRefundService shoppingOrderRefundService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | public RedisTemplate redisTemplate; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public TActivityVO activityStatistics(TActivityStatisticsQuery dto) { | 
|---|
|  |  |  | TActivityVO res = new TActivityVO(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | PageInfo<TActivityStatisticslVO> pageInfo = new PageInfo<>(dto.getPageCurr(),dto.getPageSize()); | 
|---|
|  |  |  | List<TActivityStatisticslVO> list = this.baseMapper.activityStatistics(pageInfo,dto); | 
|---|
|  |  |  | list.sort((o1, o2) -> o2.getCreateTime().compareTo(o1.getCreateTime())); | 
|---|
|  |  |  | List<TActivityStatisticslVO> list1 = this.baseMapper.activityStatisticsNolimit(dto); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 优惠券金额 | 
|---|
|  |  |  | BigDecimal coupon = new BigDecimal("0"); | 
|---|
|  |  |  | // 会员抵扣金额 | 
|---|
|  |  |  | 
|---|
|  |  |  | BigDecimal vipActivity = new BigDecimal("0"); | 
|---|
|  |  |  | // 赠送会员 | 
|---|
|  |  |  | BigDecimal grantVip = new BigDecimal("0"); | 
|---|
|  |  |  | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (TActivityStatisticslVO tActivityStatisticslVO : list) { | 
|---|
|  |  |  | for (TActivityStatisticslVO tActivityStatisticslVO : list1) { | 
|---|
|  |  |  | TAppUser data = appUserClient.getUserById(tActivityStatisticslVO.getAppUserId()).getData(); | 
|---|
|  |  |  | if (data!=null){ | 
|---|
|  |  |  | tActivityStatisticslVO.setPhone(data.getPhone()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 判断享有了哪些类型 | 
|---|
|  |  |  | switch (tActivityStatisticslVO.getOrderType()){ | 
|---|
|  |  |  | case 1: | 
|---|
|  |  |  | 
|---|
|  |  |  | // 充电订单 优惠券金额大于0 | 
|---|
|  |  |  | if (tActivityStatisticslVO.getCouponDiscountAmount()!=null | 
|---|
|  |  |  | && | 
|---|
|  |  |  | (tActivityStatisticslVO.getCouponDiscountAmount().compareTo(BigDecimal.ZERO)>0)){ | 
|---|
|  |  |  | (tActivityStatisticslVO.getCouponDiscountAmount().compareTo(BigDecimal.ZERO)>0)){ | 
|---|
|  |  |  | coupon = coupon.add(tActivityStatisticslVO.getCouponDiscountAmount()); | 
|---|
|  |  |  | stringBuilder.append("优惠券抵扣").append("+"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (tActivityStatisticslVO.getVipDiscountAmount()!=null | 
|---|
|  |  |  | && | 
|---|
|  |  |  | (tActivityStatisticslVO.getCouponDiscountAmount().compareTo(BigDecimal.ZERO)>0)){ | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (tActivityStatisticslVO.getVipDiscountAmount()!=null &&(tActivityStatisticslVO.getVipDiscountAmount().compareTo(BigDecimal.ZERO)>0)){ | 
|---|
|  |  |  | discount = discount.add(tActivityStatisticslVO.getVipDiscountAmount()); | 
|---|
|  |  |  | stringBuilder.append("会员抵扣").append("+"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | stringBuilder.deleteCharAt(stringBuilder.length()-1); | 
|---|
|  |  |  | tActivityStatisticslVO.setType(stringBuilder.toString()); | 
|---|
|  |  |  | tActivityStatisticslVO.setTime(simpleDateFormat.format(tActivityStatisticslVO.getCreateTime())); | 
|---|
|  |  |  | if (stringBuilder.length()>0){ | 
|---|
|  |  |  | stringBuilder.deleteCharAt(stringBuilder.length()-1); | 
|---|
|  |  |  | tActivityStatisticslVO.setType(stringBuilder.toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | tActivityStatisticslVO.setTime(tActivityStatisticslVO.getCreateTime()); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 2: | 
|---|
|  |  |  | StringBuilder stringBuilder1 = new StringBuilder(); | 
|---|
|  |  |  | 
|---|
|  |  |  | discount = discount.add(tActivityStatisticslVO.getVipDiscountAmount()); | 
|---|
|  |  |  | stringBuilder1.append("会员抵扣").append("+"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | stringBuilder1.deleteCharAt(stringBuilder1.length()-1); | 
|---|
|  |  |  | if (stringBuilder1.length()>0){ | 
|---|
|  |  |  | stringBuilder1.deleteCharAt(stringBuilder1.length()-1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | tActivityStatisticslVO.setType(stringBuilder1.toString()); | 
|---|
|  |  |  | tActivityStatisticslVO.setTime(simpleDateFormat.format(tActivityStatisticslVO.getCreateTime())); | 
|---|
|  |  |  | tActivityStatisticslVO.setTime(tActivityStatisticslVO.getCreateTime()); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 3: | 
|---|
|  |  |  | // 会员订单 优惠金额大于0 | 
|---|
|  |  |  | if (tActivityStatisticslVO.getVipDiscountAmount()!=null | 
|---|
|  |  |  | && | 
|---|
|  |  |  | (tActivityStatisticslVO.getCouponDiscountAmount().compareTo(BigDecimal.ZERO)>0)){ | 
|---|
|  |  |  | if (tActivityStatisticslVO.getVipDiscountAmount()!=null){ | 
|---|
|  |  |  | vipActivity = vipActivity.add(tActivityStatisticslVO.getVipDiscountAmount()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | tActivityStatisticslVO.setType("会员活动"); | 
|---|
|  |  |  | tActivityStatisticslVO.setTime(simpleDateFormat.format(tActivityStatisticslVO.getCreateTime())); | 
|---|
|  |  |  | tActivityStatisticslVO.setTime(tActivityStatisticslVO.getCreateTime()); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 4: | 
|---|
|  |  |  | // 赠送会员订单 如果支付金额为0 那么就是后台赠送的会员 | 
|---|
|  |  |  | if (tActivityStatisticslVO.getPaymentAmount().compareTo(BigDecimal.ZERO)==0){ | 
|---|
|  |  |  | grantVip = grantVip.add(tActivityStatisticslVO.getOrderAmount()); | 
|---|
|  |  |  | tActivityStatisticslVO.setType("赠送会员"); | 
|---|
|  |  |  | tActivityStatisticslVO.setTime(simpleDateFormat.format(tActivityStatisticslVO.getCreateTime())); | 
|---|
|  |  |  | tActivityStatisticslVO.setTime(tActivityStatisticslVO.getCreateTime()); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | // 会员活动 | 
|---|
|  |  |  | vipActivity = vipActivity.add(tActivityStatisticslVO.getVipDiscountAmount()); | 
|---|
|  |  |  | tActivityStatisticslVO.setType("会员活动"); | 
|---|
|  |  |  | tActivityStatisticslVO.setTime(tActivityStatisticslVO.getCreateTime()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Long> appUserIds = list.stream().map(TActivityStatisticslVO::getAppUserId).collect(Collectors.toList()); | 
|---|
|  |  |  | List<TAppUser> appUsers = appUserClient.getUserByIds(appUserIds).getData(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (TActivityStatisticslVO tActivityStatisticslVO : list) { | 
|---|
|  |  |  | TAppUser appUser = appUsers.stream().filter(user -> user.getId().equals(tActivityStatisticslVO.getAppUserId())).findFirst().orElse(null); | 
|---|
|  |  |  | if(Objects.nonNull(appUser)){ | 
|---|
|  |  |  | tActivityStatisticslVO.setPhone(appUser.getPhone()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 判断享有了哪些类型 | 
|---|
|  |  |  | switch (tActivityStatisticslVO.getOrderType()){ | 
|---|
|  |  |  | case 1: | 
|---|
|  |  |  | StringBuilder stringBuilder = new StringBuilder(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 充电订单 优惠券金额大于0 | 
|---|
|  |  |  | if (tActivityStatisticslVO.getCouponDiscountAmount()!=null | 
|---|
|  |  |  | && | 
|---|
|  |  |  | (tActivityStatisticslVO.getCouponDiscountAmount().compareTo(BigDecimal.ZERO)>0)){ | 
|---|
|  |  |  | stringBuilder.append("优惠券抵扣").append("+"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (tActivityStatisticslVO.getVipDiscountAmount()!=null &&(tActivityStatisticslVO.getVipDiscountAmount().compareTo(BigDecimal.ZERO)>0)){ | 
|---|
|  |  |  | stringBuilder.append("会员抵扣").append("+"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (stringBuilder.length()>0){ | 
|---|
|  |  |  | stringBuilder.deleteCharAt(stringBuilder.length()-1); | 
|---|
|  |  |  | tActivityStatisticslVO.setType(stringBuilder.toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | tActivityStatisticslVO.setTime(tActivityStatisticslVO.getCreateTime()); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 2: | 
|---|
|  |  |  | StringBuilder stringBuilder1 = new StringBuilder(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 购物订单 优惠券金额大于0 | 
|---|
|  |  |  | if (tActivityStatisticslVO.getCouponDiscountAmount()!=null | 
|---|
|  |  |  | && | 
|---|
|  |  |  | (tActivityStatisticslVO.getCouponDiscountAmount().compareTo(BigDecimal.ZERO)>0)){ | 
|---|
|  |  |  | stringBuilder1.append("优惠券抵扣").append("+"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (tActivityStatisticslVO.getVipDiscountAmount()!=null | 
|---|
|  |  |  | && | 
|---|
|  |  |  | (tActivityStatisticslVO.getVipDiscountAmount().compareTo(BigDecimal.ZERO)>0)){ | 
|---|
|  |  |  | stringBuilder1.append("会员抵扣").append("+"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (stringBuilder1.length()>0){ | 
|---|
|  |  |  | stringBuilder1.deleteCharAt(stringBuilder1.length()-1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | tActivityStatisticslVO.setType(stringBuilder1.toString()); | 
|---|
|  |  |  | tActivityStatisticslVO.setTime(tActivityStatisticslVO.getCreateTime()); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 3: | 
|---|
|  |  |  | // 会员订单 优惠金额大于0 | 
|---|
|  |  |  | tActivityStatisticslVO.setType("会员活动"); | 
|---|
|  |  |  | tActivityStatisticslVO.setTime(tActivityStatisticslVO.getCreateTime()); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 4: | 
|---|
|  |  |  | // 赠送会员订单 如果支付金额为0 那么就是后台赠送的会员 | 
|---|
|  |  |  | if (tActivityStatisticslVO.getPaymentAmount().compareTo(BigDecimal.ZERO)==0){ | 
|---|
|  |  |  | tActivityStatisticslVO.setType("赠送会员"); | 
|---|
|  |  |  | tActivityStatisticslVO.setTime(tActivityStatisticslVO.getCreateTime()); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | // 赠送 | 
|---|
|  |  |  | grantVip = grantVip.add(tActivityStatisticslVO.getVipDiscountAmount()); | 
|---|
|  |  |  | tActivityStatisticslVO.setType("赠送会员"); | 
|---|
|  |  |  | tActivityStatisticslVO.setTime(simpleDateFormat.format(tActivityStatisticslVO.getCreateTime())); | 
|---|
|  |  |  | tActivityStatisticslVO.setTime(tActivityStatisticslVO.getCreateTime()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | res.setGrantVip(grantVip); | 
|---|
|  |  |  | return res; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取小程序商城购买订单列表 | 
|---|
|  |  |  | * @param query | 
|---|
|  |  |  | 
|---|
|  |  |  | public Map<String, Object> getMyShoppingOrderList(GetMyShoppingOrderList query) { | 
|---|
|  |  |  | Long userId = tokenService.getLoginUserApplet().getUserId(); | 
|---|
|  |  |  | LambdaQueryWrapper<TShoppingOrder> wrapper = new LambdaQueryWrapper<TShoppingOrder>().eq(TShoppingOrder::getDelFlag, 0) | 
|---|
|  |  |  | .eq(TShoppingOrder::getAppUserId, userId); | 
|---|
|  |  |  | .eq(TShoppingOrder::getAppUserId, userId).eq(TShoppingOrder::getPaymentStatus, 2).notIn(TShoppingOrder::getStatus, Arrays.asList(5)); | 
|---|
|  |  |  | if(query.getStatus() != 0){ | 
|---|
|  |  |  | wrapper.eq(TShoppingOrder::getStatus, query.getStatus()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | map.put("total", count); | 
|---|
|  |  |  | return map; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取购买订单详情 | 
|---|
|  |  |  | * @param id | 
|---|
|  |  |  | 
|---|
|  |  |  | MyShoppingOrderInfo info = new MyShoppingOrderInfo(); | 
|---|
|  |  |  | info.setId(id); | 
|---|
|  |  |  | info.setStatus(shoppingOrder.getStatus()); | 
|---|
|  |  |  | TAppUserAddress userAddress = appUserAddressClient.getAppUserAddressById(shoppingOrder.getAppUserAddressId()).getData(); | 
|---|
|  |  |  | TAppUserAddress userAddress = JSON.parseObject(shoppingOrder.getAddressJson(), TAppUserAddress.class); | 
|---|
|  |  |  | info.setConsignee(userAddress.getName()); | 
|---|
|  |  |  | info.setPhone(userAddress.getPhone()); | 
|---|
|  |  |  | info.setAddress(userAddress.getAddress()); | 
|---|
|  |  |  | info.setAddress(userAddress.getProvince() + userAddress.getCity() + userAddress.getDistrict() + userAddress.getAddress() + userAddress.getHouseNumber()); | 
|---|
|  |  |  | info.setExpressCompany(shoppingOrder.getExpressCompany()); | 
|---|
|  |  |  | info.setExpressNumber(shoppingOrder.getExpressNumber()); | 
|---|
|  |  |  | String name = ""; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return info; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 取消订单 | 
|---|
|  |  |  | * @param id | 
|---|
|  |  |  | 
|---|
|  |  |  | if(shoppingOrder.getPaymentAmount().compareTo(bigDecimal) == 0 && shoppingOrder.getStatus() == 4){ | 
|---|
|  |  |  | return AjaxResult.error("订单已取消,不能重复操作"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //退款金额 | 
|---|
|  |  |  | BigDecimal refundAmount = shoppingOrder.getPaymentAmount().subtract(bigDecimal); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //先查询第三方订单状态订单是否退款 | 
|---|
|  |  |  | //支付方式(1=微信,2=支付宝) | 
|---|
|  |  |  | Integer paymentType = shoppingOrder.getPaymentType(); | 
|---|
|  |  |  | 
|---|
|  |  |  | shoppingOrderRefund.setPayType(shoppingOrder.getPaymentType()); | 
|---|
|  |  |  | shoppingOrderRefund.setShoppingOrderId(shoppingOrder.getId()); | 
|---|
|  |  |  | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); | 
|---|
|  |  |  | shoppingOrderRefund.setRefundCode("GDF" + sdf.format(new Date()) + (Math.random() * 1000)); | 
|---|
|  |  |  | shoppingOrderRefund.setRefundCode("GDF" + sdf.format(new Date()) + Double.valueOf((Math.random() * 1000)).intValue()); | 
|---|
|  |  |  | shoppingOrderRefund.setRefundAmount(refundAmount); | 
|---|
|  |  |  | shoppingOrderRefund.setRefundStatus(1); | 
|---|
|  |  |  | shoppingOrderRefund.setCode(shoppingOrder.getCode()); | 
|---|
|  |  |  | 
|---|
|  |  |  | shoppingOrderRefund.setRefundRemark("全额退款"); | 
|---|
|  |  |  | shoppingOrderRefund.setRefundTotalAmount(refundAmount.add(bigDecimal)); | 
|---|
|  |  |  | shoppingOrderRefund.setPayAmount(shoppingOrder.getPaymentAmount()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | shoppingOrder.setCancellationTime(LocalDateTime.now()); | 
|---|
|  |  |  | shoppingOrder.setCancellationId(shoppingOrder.getAppUserId()); | 
|---|
|  |  |  | if(1 == paymentType){ | 
|---|
|  |  |  | WxPaymentRefundModel model = new WxPaymentRefundModel(); | 
|---|
|  |  |  | model.setOut_trade_no(shoppingOrder.getCode()); | 
|---|
|  |  |  | model.setTransaction_id(shoppingOrder.getSerialNumber()); | 
|---|
|  |  |  | model.setOut_refund_no(shoppingOrderRefund.getRefundCode()); | 
|---|
|  |  |  | model.setReason("取消订单"); | 
|---|
|  |  |  | model.setNotify_url("http://127.0.0.1:9000/order/t-shopping-order/cancelShoppingOrderWxRefund"); | 
|---|
|  |  |  | model.setReason("取消商城订单"); | 
|---|
|  |  |  | model.setNotify_url("/payment/wx/refund/notify"); | 
|---|
|  |  |  | WxPaymentRefundModel.RefundAmount amount = new WxPaymentRefundModel.RefundAmount(); | 
|---|
|  |  |  | amount.setRefund(refundAmount.multiply(new BigDecimal(100)).intValue()); | 
|---|
|  |  |  | amount.setTotal(shoppingOrder.getPaymentAmount().multiply(new BigDecimal(100)).intValue()); | 
|---|
|  |  |  | amount.setCurrency("CNY"); | 
|---|
|  |  |  | model.setAmount(amount); | 
|---|
|  |  |  | R<String> orderR = wxPaymentClient.refundOrderR(model); | 
|---|
|  |  |  | R<Map<String, Object>> orderR = wxPaymentClient.refundOrderR(model); | 
|---|
|  |  |  | if(200 == orderR.getCode()){ | 
|---|
|  |  |  | this.updateById(shoppingOrder); | 
|---|
|  |  |  | shoppingOrderRefundService.save(shoppingOrderRefund); | 
|---|
|  |  |  | //手续费 | 
|---|
|  |  |  | Map<String, Object> amount1 = (Map<String, Object>) orderR.getData().get("amount"); | 
|---|
|  |  |  | Object refund_fee1 = amount1.get("refund_fee"); | 
|---|
|  |  |  | BigDecimal refund_fee = new BigDecimal(null == refund_fee1 ? "0" : refund_fee1.toString()).divide(new BigDecimal(100)); | 
|---|
|  |  |  | shoppingOrderRefund.setRefundFee(refund_fee); | 
|---|
|  |  |  | shoppingOrderRefundService.updateById(shoppingOrderRefund); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(2 == paymentType){ | 
|---|
|  |  |  | 
|---|
|  |  |  | dto.setOutTradeNo(shoppingOrder.getCode()); | 
|---|
|  |  |  | dto.setOutRequestNo(shoppingOrderRefund.getCode()); | 
|---|
|  |  |  | dto.setRefundAmount(refundAmount.toString()); | 
|---|
|  |  |  | dto.setRefundReason("取消订单"); | 
|---|
|  |  |  | dto.setRefundReason("取消商城订单"); | 
|---|
|  |  |  | RefundResp resp = aliPaymentClient.refund(dto).getData(); | 
|---|
|  |  |  | if(null != resp){ | 
|---|
|  |  |  | this.updateById(shoppingOrder); | 
|---|
|  |  |  | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-DDTHH:mm:ss+TIMEZONE"); | 
|---|
|  |  |  | AjaxResult success = cancelShoppingOrderWxRefund(resp.getOutTradeNo(), resp.getTradeNo(), "SUCCESS", sdf1.format(new Date())); | 
|---|
|  |  |  | if(success.isSuccess()){ | 
|---|
|  |  |  | shoppingOrderRefundService.save(shoppingOrderRefund); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return AjaxResult.success(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 商城订单取消订单微信退款处理 | 
|---|
|  |  |  | * @param out_refund_no 退款单号 | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @GlobalTransactional(rollbackFor = Exception.class)//分布式事务 | 
|---|
|  |  |  | public AjaxResult cancelShoppingOrderWxRefund(String out_refund_no, String refund_id, String refund_status, String success_time) { | 
|---|
|  |  |  | if("SUCCESS".equals(refund_status)){ | 
|---|
|  |  |  | TShoppingOrderRefund one = shoppingOrderRefundService.getOne(new LambdaQueryWrapper<TShoppingOrderRefund>().eq(TShoppingOrderRefund::getRefundCode, out_refund_no)); | 
|---|
|  |  |  | one.setRefundSerialNumber(refund_id); | 
|---|
|  |  |  | one.setRefundTime(LocalDateTime.parse(success_time, DateTimeFormatter.ofPattern("yyyy-MM-DDTHH:mm:ss+TIMEZONE"))); | 
|---|
|  |  |  | shoppingOrderRefundService.updateById(one); | 
|---|
|  |  |  | //判断是否需要回退库存 | 
|---|
|  |  |  | TShoppingOrder shoppingOrder = this.getById(one.getShoppingOrderId()); | 
|---|
|  |  |  | //商品 | 
|---|
|  |  |  | if(shoppingOrder.getOrderType() == 1){ | 
|---|
|  |  |  | // todo 需完善redis锁 | 
|---|
|  |  |  | //redis锁 和支付使用同一个锁 | 
|---|
|  |  |  | TShoppingOrderRefund one = shoppingOrderRefundService.getOne(new LambdaQueryWrapper<TShoppingOrderRefund>().eq(TShoppingOrderRefund::getRefundCode, out_refund_no)); | 
|---|
|  |  |  | one.setRefundStatus(2); | 
|---|
|  |  |  | one.setRefundSerialNumber(refund_id); | 
|---|
|  |  |  | one.setRefundTime(LocalDateTime.now()); | 
|---|
|  |  |  | shoppingOrderRefundService.updateById(one); | 
|---|
|  |  |  | //判断是否需要回退库存 | 
|---|
|  |  |  | TShoppingOrder shoppingOrder = this.getById(one.getShoppingOrderId()); | 
|---|
|  |  |  | shoppingOrder.setStatus(4); | 
|---|
|  |  |  | shoppingOrder.setRefundCode(one.getRefundSerialNumber()); | 
|---|
|  |  |  | shoppingOrder.setRefundAmount(one.getRefundAmount()); | 
|---|
|  |  |  | shoppingOrder.setRefundStatus(2); | 
|---|
|  |  |  | shoppingOrder.setRefundTime(one.getRefundTime()); | 
|---|
|  |  |  | this.updateById(shoppingOrder); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //商品 | 
|---|
|  |  |  | if(shoppingOrder.getOrderType() == 1){ | 
|---|
|  |  |  | //redis锁 和支付使用同一个锁 | 
|---|
|  |  |  | RedisLock redisLock = new RedisLock(redisTemplate, "SHOPPING_GOODS_LOCK", 5, 30000); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | redisLock.lock(); | 
|---|
|  |  |  | TGoods goods = goodsClient.getGoodsById(shoppingOrder.getGoodsId()).getData(); | 
|---|
|  |  |  | Integer inventory = goods.getInventory(); | 
|---|
|  |  |  | if(-1 != inventory){ | 
|---|
|  |  |  | goods.setInventory(inventory + shoppingOrder.getPurchaseQuantity()); | 
|---|
|  |  |  | goodsClient.updateGoods(goods); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | }finally { | 
|---|
|  |  |  | //解锁 | 
|---|
|  |  |  | redisLock.unlock(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //优惠券 | 
|---|
|  |  |  | if(shoppingOrder.getOrderType() == 2){ | 
|---|
|  |  |  | //redis锁 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //优惠券 | 
|---|
|  |  |  | if(shoppingOrder.getOrderType() == 2){ | 
|---|
|  |  |  | //redis锁 和支付使用同一个锁 | 
|---|
|  |  |  | RedisLock redisLock = new RedisLock(redisTemplate, "SHOPPING_COUPON_LOCK", 5, 30000); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | redisLock.lock(); | 
|---|
|  |  |  | TCoupon coupon = couponClient.getCouponById1(shoppingOrder.getCouponId()).getData(); | 
|---|
|  |  |  | Integer inventory = coupon.getInventoryQuantity(); | 
|---|
|  |  |  | if(-1 != inventory){ | 
|---|
|  |  |  | coupon.setInventoryQuantity(inventory + shoppingOrder.getPurchaseQuantity()); | 
|---|
|  |  |  | couponClient.updateCoupon(coupon); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | }finally { | 
|---|
|  |  |  | //解锁 | 
|---|
|  |  |  | redisLock.unlock(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return AjaxResult.success(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取未开票的订单列表 | 
|---|
|  |  |  | * @param query | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<MyShoppingOrderList> getNoInvoicedOrder(GetNoInvoicedOrder query) { | 
|---|
|  |  |  | Long userId = tokenService.getLoginUserApplet().getUserId(); | 
|---|
|  |  |  | List<TShoppingOrder> list = this.baseMapper.getNoInvoicedOrder(userId, query.getMonth(), query.getPageCurr(), query.getPageSize()); | 
|---|
|  |  |  | Integer pageCurr = (query.getPageCurr() - 1) * query.getPageSize(); | 
|---|
|  |  |  | List<TShoppingOrder> list = this.baseMapper.getNoInvoicedOrder(userId, query.getMonth(), pageCurr, query.getPageSize()); | 
|---|
|  |  |  | List<MyShoppingOrderList> pageList = new ArrayList<>(); | 
|---|
|  |  |  | for (TShoppingOrder tShoppingOrder : list) { | 
|---|
|  |  |  | MyShoppingOrderList myShoppingOrderList = new MyShoppingOrderList(); | 
|---|
|  |  |  | 
|---|
|  |  |  | name = goods.getName(); | 
|---|
|  |  |  | imgUrl = goods.getCoverPicture(); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | TCoupon coupon = couponClient.getCouponById1(tShoppingOrder.getGoodsId()).getData(); | 
|---|
|  |  |  | TCoupon coupon = couponClient.getCouponById1(tShoppingOrder.getCouponId()).getData(); | 
|---|
|  |  |  | name = coupon.getName(); | 
|---|
|  |  |  | imgUrl = coupon.getCoverPicture(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | TShoppingOrder shoppingOrder = this.baseMapper.selectOne(Wrappers.lambdaQuery(TShoppingOrder.class).eq(TShoppingOrder::getCode, code)); | 
|---|
|  |  |  | shoppingOrder.setPaymentStatus(2); | 
|---|
|  |  |  | shoppingOrder.setSerialNumber(outTradeNo); | 
|---|
|  |  |  | shoppingOrder.setPayTime(LocalDateTime.now()); | 
|---|
|  |  |  | this.updateById(shoppingOrder); | 
|---|
|  |  |  | //如果是优惠券,赠送优惠券 | 
|---|
|  |  |  | if (shoppingOrder.getOrderType()==2){ | 
|---|
|  |  |  | 
|---|
|  |  |  | if (data1!=null){ | 
|---|
|  |  |  | tShoppingOrder.setName(data1.getName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | tShoppingOrder.setStatus(3); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (tShoppingOrder.getAppUserId() != null){ | 
|---|
|  |  |  | 
|---|
|  |  |  | pageInfo.setRecords(list); | 
|---|
|  |  |  | return pageInfo; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<SixShopDto> sixBefore(LocalDate sixBefore, Integer status) { | 
|---|
|  |  |  | return this.baseMapper.sixBefore(sixBefore,status); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public BigDecimal getSumAmount() { | 
|---|
|  |  |  | return this.baseMapper.getSumAmount(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<Map<String, Object>> getData(ChargingStatisticsQueryDto statisticsQueryDto) { | 
|---|
|  |  |  | return this.baseMapper.getData(statisticsQueryDto); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|