| | |
| | | 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; |
| | | |
| | | |
| | | |
| | |
| | | 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); |
| | | if(query.getStatus() != 0){ |
| | | wrapper.eq(TShoppingOrder::getStatus, query.getStatus()); |
| | | } |
| | |
| | | TAppUserAddress userAddress = appUserAddressClient.getAppUserAddressById(shoppingOrder.getAppUserAddressId()).getData(); |
| | | info.setConsignee(userAddress.getName()); |
| | | info.setPhone(userAddress.getPhone()); |
| | | info.setAddress(userAddress.getAddress()); |
| | | info.setAddress(userAddress.getProvince() + userAddress.getCity() + userAddress.getDistrict() + userAddress.getAddress()); |
| | | info.setExpressCompany(shoppingOrder.getExpressCompany()); |
| | | info.setExpressNumber(shoppingOrder.getExpressNumber()); |
| | | String name = ""; |
| | |
| | | |
| | | //退款金额 |
| | | 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.setNotify_url("/order/t-shopping-order/cancelShoppingOrderWxRefund"); |
| | | WxPaymentRefundModel.RefundAmount amount = new WxPaymentRefundModel.RefundAmount(); |
| | | amount.setRefund(refundAmount.multiply(new BigDecimal(100)).intValue()); |
| | | amount.setTotal(shoppingOrder.getPaymentAmount().multiply(new BigDecimal(100)).intValue()); |
| | |
| | | model.setAmount(amount); |
| | | R<String> orderR = wxPaymentClient.refundOrderR(model); |
| | | if(200 == orderR.getCode()){ |
| | | this.updateById(shoppingOrder); |
| | | shoppingOrderRefundService.save(shoppingOrderRefund); |
| | | } |
| | | } |
| | |
| | | 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(); |
| | |
| | | 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.setRefundStatus(2); |
| | | 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()); |
| | | 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){ |
| | | // 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(); |
| | |
| | | @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){ |
| | |
| | | return this.baseMapper.getSumAmount(sixBefore); |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> getData(ChargingStatisticsQueryDto statisticsQueryDto) { |
| | | return this.baseMapper.getData(statisticsQueryDto); |
| | | } |
| | | |
| | | |
| | | } |