| | |
| | | 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; |
| | | |
| | |
| | | |
| | | @Resource |
| | | private TShoppingOrderRefundService shoppingOrderRefundService; |
| | | |
| | | @Autowired |
| | | public RedisTemplate redisTemplate; |
| | | |
| | | |
| | | |
| | |
| | | |
| | | //退款金额 |
| | | BigDecimal refundAmount = shoppingOrder.getPaymentAmount().subtract(bigDecimal); |
| | | |
| | | |
| | | //先查询第三方订单状态订单是否退款 |
| | | //支付方式(1=微信,2=支付宝) |
| | | Integer paymentType = shoppingOrder.getPaymentType(); |
| | |
| | | AjaxResult success = cancelShoppingOrderWxRefund(resp.getOutTradeNo(), resp.getTradeNo(), "SUCCESS", sdf1.format(new Date())); |
| | | if(success.isSuccess()){ |
| | | shoppingOrderRefundService.save(shoppingOrderRefund); |
| | | //商品 |
| | | 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锁 和支付使用同一个锁 |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | TShoppingOrder shoppingOrder = this.getById(one.getShoppingOrderId()); |
| | | //商品 |
| | | if(shoppingOrder.getOrderType() == 1){ |
| | | // todo 需完善redis锁 |
| | | //redis锁 和支付使用同一个锁 |
| | | TGoods goods = goodsClient.getGoodsById(shoppingOrder.getGoodsId()).getData(); |
| | | Integer inventory = goods.getInventory(); |
| | | if(-1 != inventory){ |
| | | goods.setInventory(inventory + shoppingOrder.getPurchaseQuantity()); |
| | | goodsClient.updateGoods(goods); |
| | | 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锁 |
| | | TCoupon coupon = couponClient.getCouponById1(shoppingOrder.getCouponId()).getData(); |
| | | Integer inventory = coupon.getInventoryQuantity(); |
| | | if(-1 != inventory){ |
| | | coupon.setInventoryQuantity(inventory + shoppingOrder.getPurchaseQuantity()); |
| | | couponClient.updateCoupon(coupon); |
| | | //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(); |