| | |
| | | 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.common.core.web.domain.AjaxResult; |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.order.api.model.TExchangeOrder; |
| | | import com.ruoyi.order.api.model.TShoppingOrder; |
| | | import com.ruoyi.order.api.model.TShoppingOrderRefund; |
| | | import com.ruoyi.order.api.query.ShoppingOrderQuery; |
| | | import com.ruoyi.order.api.query.TActivityStatisticsQuery; |
| | | import com.ruoyi.order.api.vo.ChargingOrderVO; |
| | | import com.ruoyi.order.api.vo.TActivityStatisticslVO; |
| | | import com.ruoyi.order.api.vo.TActivityVO; |
| | | import com.ruoyi.order.dto.*; |
| | | 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.model.WxPaymentRefundModel; |
| | | import com.ruoyi.payment.api.vo.AliQueryOrder; |
| | | import com.ruoyi.payment.api.vo.NotifyV3PayDecodeRespBody; |
| | | import io.seata.spring.annotation.GlobalTransactional; |
| | | import org.redisson.api.RLock; |
| | | import org.redisson.api.RedissonClient; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | @Autowired |
| | | public RedisTemplate redisTemplate; |
| | | |
| | | @Autowired |
| | | private RedissonClient redissonClient; |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public TActivityVO activityStatistics(TActivityStatisticsQuery dto) { |
| | | TActivityVO res = new TActivityVO(); |
| | | |
| | | |
| | | |
| | | PageInfo<TActivityStatisticslVO> pageInfo = new PageInfo<>(dto.getPageCurr(),dto.getPageSize()); |
| | | PageInfo<TActivityStatisticslVO> pageInfo1 = new PageInfo<>(1,9999999); |
| | | List<TActivityStatisticslVO> list = this.baseMapper.activityStatistics(pageInfo,dto); |
| | | List<TActivityStatisticslVO> list1 = this.baseMapper.activityStatistics(pageInfo1,dto); |
| | | List<TActivityStatisticslVO> list1 = this.baseMapper.activityStatisticsNolimit(dto); |
| | | |
| | | list.sort((o1, o2) -> o2.getCreateTime().compareTo(o1.getCreateTime())); |
| | | // 优惠券金额 |
| | | BigDecimal coupon = new BigDecimal("0"); |
| | | // 会员抵扣金额 |
| | |
| | | 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.setType("赠送会员"); |
| | | tActivityStatisticslVO.setTime(tActivityStatisticslVO.getCreateTime()); |
| | | }else{ |
| | | // 赠送 |
| | | grantVip = grantVip.add(tActivityStatisticslVO.getVipDiscountAmount()); |
| | | tActivityStatisticslVO.setType("赠送会员"); |
| | | // 会员活动 |
| | | 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: |
| | |
| | | // 充电订单 优惠券金额大于0 |
| | | if (tActivityStatisticslVO.getCouponDiscountAmount()!=null |
| | | && |
| | | (tActivityStatisticslVO.getCouponDiscountAmount().compareTo(BigDecimal.ZERO)>0)){ |
| | | stringBuilder.append("优惠券抵扣").append("+"); |
| | | } |
| | | (tActivityStatisticslVO.getCouponDiscountAmount().compareTo(BigDecimal.ZERO)>0)){ |
| | | stringBuilder.append("优惠券抵扣").append("+"); |
| | | } |
| | | if (tActivityStatisticslVO.getVipDiscountAmount()!=null &&(tActivityStatisticslVO.getVipDiscountAmount().compareTo(BigDecimal.ZERO)>0)){ |
| | | discount = discount.add(tActivityStatisticslVO.getVipDiscountAmount()); |
| | | stringBuilder.append("会员抵扣").append("+"); |
| | | } |
| | | if (stringBuilder.length()>0){ |
| | |
| | | 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.getProvince() + userAddress.getCity() + userAddress.getDistrict() + userAddress.getAddress() + userAddress.getHouseNumber()); |
| | |
| | | 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){ |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | @GlobalTransactional(rollbackFor = Exception.class)//分布式事务 |
| | | public AjaxResult cancelShoppingOrderWxRefund(String out_refund_no, String refund_id, String refund_status, String success_time) { |
| | | TShoppingOrderRefund one = shoppingOrderRefundService.getOne(new LambdaQueryWrapper<TShoppingOrderRefund>().eq(TShoppingOrderRefund::getRefundCode, out_refund_no)); |
| | | one.setRefundStatus(2); |
| | |
| | | //商品 |
| | | if(shoppingOrder.getOrderType() == 1){ |
| | | //redis锁 和支付使用同一个锁 |
| | | RedisLock redisLock = new RedisLock(redisTemplate, "SHOPPING_GOODS_LOCK", 5, 30000); |
| | | RLock lock = redissonClient.getLock("SHOPPING_GOODS_LOCK"); |
| | | try { |
| | | redisLock.lock(); |
| | | lock.tryLock(5, 30, TimeUnit.SECONDS); |
| | | TGoods goods = goodsClient.getGoodsById(shoppingOrder.getGoodsId()).getData(); |
| | | Integer inventory = goods.getInventory(); |
| | | if(-1 != inventory){ |
| | |
| | | e.printStackTrace(); |
| | | }finally { |
| | | //解锁 |
| | | redisLock.unlock(); |
| | | lock.unlock(); |
| | | } |
| | | } |
| | | //优惠券 |
| | | if(shoppingOrder.getOrderType() == 2){ |
| | | //redis锁 和支付使用同一个锁 |
| | | RedisLock redisLock = new RedisLock(redisTemplate, "SHOPPING_COUPON_LOCK", 5, 30000); |
| | | RLock lock = redissonClient.getLock("SHOPPING_COUPON_LOCK"); |
| | | try { |
| | | redisLock.lock(); |
| | | lock.tryLock(5, 30, TimeUnit.SECONDS); |
| | | TCoupon coupon = couponClient.getCouponById1(shoppingOrder.getCouponId()).getData(); |
| | | Integer inventory = coupon.getInventoryQuantity(); |
| | | if(-1 != inventory){ |
| | |
| | | e.printStackTrace(); |
| | | }finally { |
| | | //解锁 |
| | | redisLock.unlock(); |
| | | lock.unlock(); |
| | | } |
| | | } |
| | | return AjaxResult.success(); |
| | |
| | | public List<SixShopDto> sixBefore(LocalDate sixBefore, Integer status) { |
| | | return this.baseMapper.sixBefore(sixBefore,status); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public BigDecimal getSumAmount(LocalDate sixBefore) { |
| | | return this.baseMapper.getSumAmount(sixBefore); |
| | | public BigDecimal getSumAmount() { |
| | | return this.baseMapper.getSumAmount(); |
| | | } |
| | | |
| | | @Override |