44323
2023-11-27 aa925d851857f50eff0556411366690d9a78a0e5
cloud-server-account/src/main/java/com/dsh/account/service/impl/VipPaymentServiceImpl.java
@@ -1,5 +1,6 @@
package com.dsh.account.service.impl;
import com.alibaba.fastjson.JSON;
import com.alipay.api.response.AlipayTradeQueryResponse;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -11,11 +12,13 @@
import com.dsh.account.service.IVipPaymentService;
import com.dsh.account.service.TAppUserService;
import com.dsh.account.util.PayMoneyUtil;
import com.dsh.account.util.RedisUtil;
import com.dsh.account.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
@@ -35,8 +38,16 @@
    @Autowired
    private PayMoneyUtil payMoneyUtil;
    @Resource
    private UserConponClient userConponClient;
    @Autowired
    private RedisUtil redisUtil;
    /**
     * 购买年度会员
     *
     * @param uid
     * @return
     * @throws Exception
@@ -63,6 +74,7 @@
    /**
     * 微信
     *
     * @param vipPayment
     * @return
     * @throws Exception
@@ -82,7 +94,7 @@
                            int min = 5000;
                            wait += (min * num);
                            VipPayment vipPayment1 = VipPaymentServiceImpl.this.getOne(new QueryWrapper<VipPayment>().eq("code", code));
                            if(vipPayment1.getPayStatus() != 1){
                            if (vipPayment1.getPayStatus() == 2) {
                                return;
                            }
                            /**
@@ -123,7 +135,8 @@
                                    appUser.setVipEndTime(calendar.getTime());
                                    appUserService.updateById(appUser);
                                    // 注册会员送券 先判断是否有注册送券类型的优惠券 判断优惠券状态 审核是否通过 是否删除 是否在有效期内 是否领取数量达上限
                                    userConponClient.queryCouponByUser(appUser.getId());
                                    List<Long> longs = userConponClient.queryCouponByUser(appUser.getId());
                                    redisUtil.setStrValue("VIP_P_" + vipPayment1.getAppUserId(), JSON.toJSONString(longs), 3600);
                                    return;
                                }
                                if("USERPAYING".equals(trade_state) || "ACCEPT".equals(trade_state)){
@@ -151,6 +164,7 @@
    /**
     * 支付宝
     *
     * @param vipPayment
     * @return
     * @throws Exception
@@ -214,7 +228,8 @@
                                    appUser.setVipEndTime(calendar.getTime());
                                    appUserService.updateById(appUser);
                                    // 注册会员送券 先判断是否有注册送券类型的优惠券 判断优惠券状态 审核是否通过 是否删除 是否在有效期内 是否领取数量达上限
                                    userConponClient.queryCouponByUser(appUser.getId());
                                    List<Long> longs = userConponClient.queryCouponByUser(appUser.getId());
                                    redisUtil.setStrValue("VIP_P_" + vipPayment1.getAppUserId(), JSON.toJSONString(longs), 3600);
                                    return;
                                }
                                if("WAIT_BUYER_PAY".equals(tradeStatus)){
@@ -240,11 +255,9 @@
    }
    @Autowired
    private UserConponClient userConponClient;
    /**
     * 购买年度会员支付回调处理
     *
     * @param code
     * @param orderNumber
     * @throws Exception
@@ -252,7 +265,7 @@
    @Override
    public synchronized ResultUtil addVipPaymentCallback(String code, String orderNumber) throws Exception {
        VipPayment vipPayment1 = VipPaymentServiceImpl.this.getOne(new QueryWrapper<VipPayment>().eq("code", code));
        if(vipPayment1.getPayStatus() != 1){
        if (vipPayment1.getPayStatus() == 2) {
            return ResultUtil.success();
        }
        vipPayment1.setPayStatus(2);
@@ -261,16 +274,14 @@
        VipPaymentServiceImpl.this.updateById(vipPayment1);
        TAppUser appUser = appUserService.getById(vipPayment1.getAppUserId());
        Date vipEndTime = appUser.getVipEndTime();
        if(null == vipEndTime){
            vipEndTime = new Date();
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) + 1);
        appUser.setVipEndTime(calendar.getTime());
        appUserService.updateById(appUser);
        // 注册会员送券 先判断是否有注册送券类型的优惠券 判断优惠券状态 审核是否通过 是否删除 是否在有效期内 是否领取数量达上限
        List<Long> longs = userConponClient.queryCouponByUser(appUser.getId());
        redisUtil.setStrValue("VIP_P_" + vipPayment1.getAppUserId(), JSON.toJSONString(longs), 3600);
        return ResultUtil.success();
    }