package com.miaxis.order.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.miaxis.newgzpt.domain.GzptSchActivation;
import com.miaxis.newgzpt.domain.GzptSchPayLog;
import com.miaxis.newgzpt.domain.GzptUserInfo;
import com.miaxis.newgzpt.service.IGzptSchActivationService;
import com.miaxis.newgzpt.service.IGzptSchPayConfigService;
import com.miaxis.newgzpt.service.IGzptSchPayLogService;
import com.miaxis.newgzpt.service.IGzptUserInfoService;
import com.miaxis.order.domain.OrderInfo;
import com.miaxis.order.dto.QuerySchoolOrderListDTO;
import com.miaxis.order.mapper.OrderInfoMapper;
import com.miaxis.order.service.IOrderInfoService;
import com.miaxis.order.vo.QuerySchoolOrderListVo;
import com.miaxis.userInfo.domain.UserVip;
import com.miaxis.userInfo.service.IUserVipService;
import com.miaxis.wx.domain.WxJsOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 订单信息Service业务层处理
 *
 * @author miaxis
 * @date 2022-06-01
 */
@Service
public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo> implements IOrderInfoService {
    @Autowired
    private OrderInfoMapper orderInfoMapper;

    @Autowired
    private IUserVipService userVipService;

    @Autowired
    private IGzptUserInfoService userInfoService;

    @Autowired
    private IGzptSchActivationService schActivationService;

    @Autowired
    private IGzptSchPayLogService schPayLogService;

    @Autowired
    private IGzptSchPayConfigService schPayConfigService;

    /**
     * 查询订单信息列表
     *
     * @param orderInfo 订单信息
     * @return 订单信息
     */
    @Override
    public List<OrderInfo> selectOrderInfoList(OrderInfo orderInfo) {
        return orderInfoMapper.selectOrderInfoList(orderInfo);
    }

    @Override
    public OrderInfo getByOutTradeNo(String outTradeNo) {
        return orderInfoMapper.getByOutTradeNo(outTradeNo);
    }



    public void writeVipDataToDb(WxJsOrder order, int payType) {
        long oneYearLong = 1000 * 60 * 60 * 24 * 365l;
        Date now = new Date();

        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setGoodsName(order.getGoodsName());
        orderInfo.setUserId(order.getUserId());
        orderInfo.setOutTradeNo(order.getOutTradeNo());
        orderInfo.setTotal(order.getTotal());
        orderInfo.setTradeType(1);
        orderInfo.setSuccessTime(now);
        orderInfo.setPayType(payType);
        orderInfo.setDqbh(order.getDqbh());
        orderInfo.setDqmc(order.getDqmc());
        orderInfo.setSchool(order.getSchool());
        orderInfo.setSchoolName(order.getSchoolName());
        orderInfo.setSchoolCommission(order.getSchoolCommission());
        orderInfo.setPhoneType(order.getPhoneType());


        GzptUserInfo userInfo = userInfoService.getInfoById(order.getUserId());

        if ("理论计时".equals(order.getGoodsName())) {
            //激活操作
            saveActiva(order, userInfo);
        } else if ("科一专项VIP(含计时)".equals(order.getGoodsName())) {
            UserVip userVip = userVipService.getUserVipByUserId(order.getUserId());
            if (userVip != null) {
                //修改会员信息
                Date km1Date = userVip.getSubject1();
                if (km1Date != null) {  //存在会员时间
                    if (km1Date.compareTo(now) < 0) {  //会员已过期
                        long x = now.getTime() + oneYearLong;
                        Date km1oneYear = new Date(x);
                        userVip.setSubject1(km1oneYear);
                    } else {  //会员时间延长
                        long x = km1Date.getTime() + oneYearLong;
                        Date km1oneYear = new Date(x);
                        userVip.setSubject1(km1oneYear);
                    }
                    userVipService.updateById(userVip);
                    this.save(orderInfo);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km1oneYear = new Date(x);
                    userVip.setSubject1(km1oneYear);
                    userVipService.updateById(userVip);
                    this.save(orderInfo);
                }
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(order.getUserId());
                uv.setUserName(order.getUserName());
                long x = now.getTime() + oneYearLong;
                Date km1oneYear = new Date(x);
                uv.setSubject1(km1oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }
            //激活操作
            saveActiva(order, userInfo);
        } else if ("科一专项VIP".equals(order.getGoodsName())) {
            UserVip userVip = userVipService.getUserVipByUserId(order.getUserId());
            if (userVip != null) {
                //修改会员信息
                Date km1Date = userVip.getSubject1();
                if (km1Date != null) {  //存在会员时间
                    if (km1Date.compareTo(now) < 0) {  //会员已过期
                        long x = now.getTime() + oneYearLong;
                        Date km1oneYear = new Date(x);
                        userVip.setSubject1(km1oneYear);
                    } else {  //会员时间延长
                        long x = km1Date.getTime() + oneYearLong;
                        Date km1oneYear = new Date(x);
                        userVip.setSubject1(km1oneYear);
                    }
                    userVipService.updateById(userVip);
                    this.save(orderInfo);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km1oneYear = new Date(x);
                    userVip.setSubject1(km1oneYear);
                    userVipService.updateById(userVip);
                    this.save(orderInfo);
                }
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(order.getUserId());
                uv.setUserName(order.getUserName());
                long x = now.getTime() + oneYearLong;
                Date km1oneYear = new Date(x);
                uv.setSubject1(km1oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }

        } else if ("科二专项VIP(含计时)".equals(order.getGoodsName())) {
            UserVip userVip = userVipService.getUserVipByUserId(order.getUserId());
            if (userVip != null) {
                //修改会员信息
                Date km2Date = userVip.getSubject2();
                if (km2Date != null) {  //存在会员时间
                    if (km2Date.compareTo(now) < 0) {  //会员已过期
                        long x = now.getTime() + oneYearLong;
                        Date km2oneYear = new Date(x);
                        userVip.setSubject2(km2oneYear);
                    } else {  //会员时间延长
                        long x = km2Date.getTime() + oneYearLong;
                        Date km2oneYear = new Date(x);
                        userVip.setSubject2(km2oneYear);
                    }
                    userVipService.updateById(userVip);
                    this.save(orderInfo);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km2oneYear = new Date(x);
                    userVip.setSubject2(km2oneYear);
                    userVipService.updateById(userVip);
                    this.save(orderInfo);
                }
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(order.getUserId());
                uv.setUserName(order.getUserName());
                long x = now.getTime() + oneYearLong;
                Date km2oneYear = new Date(x);
                uv.setSubject2(km2oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }
            //激活操作
            saveActiva(order, userInfo);
        } else if ("科二专项VIP".equals(order.getGoodsName())) {
            UserVip userVip = userVipService.getUserVipByUserId(order.getUserId());
            if (userVip != null) {
                //修改会员信息
                Date km2Date = userVip.getSubject2();
                if (km2Date != null) {  //存在会员时间
                    if (km2Date.compareTo(now) < 0) {  //会员已过期
                        long x = now.getTime() + oneYearLong;
                        Date km2oneYear = new Date(x);
                        userVip.setSubject2(km2oneYear);
                    } else {  //会员时间延长
                        long x = km2Date.getTime() + oneYearLong;
                        Date km2oneYear = new Date(x);
                        userVip.setSubject2(km2oneYear);
                    }
                    userVipService.updateById(userVip);
                    this.save(orderInfo);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km2oneYear = new Date(x);
                    userVip.setSubject2(km2oneYear);
                    userVipService.updateById(userVip);
                    this.save(orderInfo);
                }
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(order.getUserId());
                uv.setUserName(order.getUserName());
                long x = now.getTime() + oneYearLong;
                Date km2oneYear = new Date(x);
                uv.setSubject2(km2oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }
        } else if ("科三专项VIP(含计时)".equals(order.getGoodsName())) {
            UserVip userVip = userVipService.getUserVipByUserId(order.getUserId());
            if (userVip != null) {
                //修改会员信息
                Date km3Date = userVip.getSubject3();
                if (km3Date != null) {  //存在会员时间
                    if (km3Date.compareTo(now) < 0) {  //会员已过期
                        long x = now.getTime() + oneYearLong;
                        Date km3oneYear = new Date(x);
                        userVip.setSubject3(km3oneYear);
                    } else {  //会员时间延长
                        long x = km3Date.getTime() + oneYearLong;
                        Date km3oneYear = new Date(x);
                        userVip.setSubject3(km3oneYear);
                    }
                    userVipService.updateById(userVip);
                    this.save(orderInfo);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                    userVipService.updateById(userVip);
                    this.save(orderInfo);
                }
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(order.getUserId());
                uv.setUserName(order.getUserName());
                long x = now.getTime() + oneYearLong;
                Date km3oneYear = new Date(x);
                uv.setSubject3(km3oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }
            //激活操作
            saveActiva(order, userInfo);
        } else if ("科三专项VIP".equals(order.getGoodsName())) {
            UserVip userVip = userVipService.getUserVipByUserId(order.getUserId());
            if (userVip != null) {
                //修改会员信息
                Date km3Date = userVip.getSubject3();
                if (km3Date != null) {  //存在会员时间
                    if (km3Date.compareTo(now) < 0) {  //会员已过期
                        long x = now.getTime() + oneYearLong;
                        Date km3oneYear = new Date(x);
                        userVip.setSubject3(km3oneYear);
                    } else {  //会员时间延长
                        long x = km3Date.getTime() + oneYearLong;
                        Date km3oneYear = new Date(x);
                        userVip.setSubject3(km3oneYear);
                    }
                    userVipService.updateById(userVip);
                    this.save(orderInfo);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                    userVipService.updateById(userVip);
                    this.save(orderInfo);
                }
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(order.getUserId());
                uv.setUserName(order.getUserName());
                long x = now.getTime() + oneYearLong;
                Date km3oneYear = new Date(x);
                uv.setSubject3(km3oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }

        } else if ("科四专项VIP(含计时)".equals(order.getGoodsName())) {
            UserVip userVip = userVipService.getUserVipByUserId(order.getUserId());
            if (userVip != null) {
                //修改会员信息
                Date km4Date = userVip.getSubject4();
                if (km4Date != null) {  //存在会员时间
                    if (km4Date.compareTo(now) < 0) {  //会员已过期
                        long x = now.getTime() + oneYearLong;
                        Date km4oneYear = new Date(x);
                        userVip.setSubject4(km4oneYear);
                    } else {  //会员时间延长
                        long x = km4Date.getTime() + oneYearLong;
                        Date km4oneYear = new Date(x);
                        userVip.setSubject4(km4oneYear);
                    }
                    userVipService.updateById(userVip);
                    this.save(orderInfo);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                    userVipService.updateById(userVip);
                    this.save(orderInfo);
                }
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(order.getUserId());
                uv.setUserName(order.getUserName());
                long x = now.getTime() + oneYearLong;
                Date km4oneYear = new Date(x);
                uv.setSubject4(km4oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }
            //激活操作
            saveActiva(order, userInfo);
        } else if ("科四专项VIP".equals(order.getGoodsName())) {
            UserVip userVip = userVipService.getUserVipByUserId(order.getUserId());
            if (userVip != null) {
                //修改会员信息
                Date km4Date = userVip.getSubject4();
                if (km4Date != null) {  //存在会员时间
                    if (km4Date.compareTo(now) < 0) {  //会员已过期
                        long x = now.getTime() + oneYearLong;
                        Date km4oneYear = new Date(x);
                        userVip.setSubject4(km4oneYear);
                    } else {  //会员时间延长
                        long x = km4Date.getTime() + oneYearLong;
                        Date km4oneYear = new Date(x);
                        userVip.setSubject4(km4oneYear);
                    }
                    userVipService.updateById(userVip);
                    this.save(orderInfo);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                    userVipService.updateById(userVip);
                    this.save(orderInfo);
                }
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(order.getUserId());
                uv.setUserName(order.getUserName());
                long x = now.getTime() + oneYearLong;
                Date km4oneYear = new Date(x);
                uv.setSubject4(km4oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }

        } else if ("科目一二三四所有付费权益".equals(order.getGoodsName())) {
            UserVip userVip = userVipService.getUserVipByUserId(order.getUserId());
            if (userVip != null) {
                //修改会员信息
                Date km1Date = userVip.getSubject1();
                Date km2Date = userVip.getSubject2();
                Date km3Date = userVip.getSubject3();
                Date km4Date = userVip.getSubject4();
                if (km1Date != null) { //科目一处理
                    long x = km1Date.getTime() + oneYearLong;
                    Date km1oneYear = new Date(x);
                    userVip.setSubject1(km1oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km1oneYear = new Date(x);
                    userVip.setSubject1(km1oneYear);
                }
                if (km2Date != null) { //科目二处理
                    long x = km2Date.getTime() + oneYearLong;
                    Date km2oneYear = new Date(x);
                    userVip.setSubject2(km2oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km2oneYear = new Date(x);
                    userVip.setSubject2(km2oneYear);
                }
                if (km3Date != null) { //科目三处理
                    long x = km3Date.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                }
                if (km4Date != null) { //科目四处理
                    long x = km4Date.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                }
                userVipService.updateById(userVip);
                this.save(orderInfo);
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(order.getUserId());
                uv.setUserName(order.getUserName());
                long x = now.getTime() + oneYearLong;
                Date oneYear = new Date(x);
                uv.setSubject1(oneYear);
                uv.setSubject2(oneYear);
                uv.setSubject3(oneYear);
                uv.setSubject4(oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }
        } else if ("科一+科四VIP(含计时)".equals(order.getGoodsName())) {
            UserVip userVip = userVipService.getUserVipByUserId(order.getUserId());
            if (userVip != null) {
                //修改会员信息
                Date km1Date = userVip.getSubject1();
                Date km4Date = userVip.getSubject4();
                if (km1Date != null) { //科目一处理
                    long x = km1Date.getTime() + oneYearLong;
                    Date km1oneYear = new Date(x);
                    userVip.setSubject1(km1oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km1oneYear = new Date(x);
                    userVip.setSubject1(km1oneYear);
                }
                if (km4Date != null) { //科目四处理
                    long x = km4Date.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                }
                userVipService.updateById(userVip);
                this.save(orderInfo);
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(order.getUserId());
                uv.setUserName(order.getUserName());
                long x = now.getTime() + oneYearLong;
                Date oneYear = new Date(x);
                uv.setSubject1(oneYear);
                uv.setSubject4(oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }
            //激活操作
            saveActiva(order, userInfo);
        } else if ("科一+科四VIP".equals(order.getGoodsName())) {
            UserVip userVip = userVipService.getUserVipByUserId(order.getUserId());
            if (userVip != null) {
                //修改会员信息
                Date km1Date = userVip.getSubject1();
                Date km4Date = userVip.getSubject4();
                if (km1Date != null) { //科目一处理
                    long x = km1Date.getTime() + oneYearLong;
                    Date km1oneYear = new Date(x);
                    userVip.setSubject1(km1oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km1oneYear = new Date(x);
                    userVip.setSubject1(km1oneYear);
                }
                if (km4Date != null) { //科目四处理
                    long x = km4Date.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                }
                userVipService.updateById(userVip);
                this.save(orderInfo);
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(order.getUserId());
                uv.setUserName(order.getUserName());
                long x = now.getTime() + oneYearLong;
                Date oneYear = new Date(x);
                uv.setSubject1(oneYear);
                uv.setSubject4(oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }
        } else if ("科二+科三VIP(含计时)".equals(order.getGoodsName())) {
            UserVip userVip = userVipService.getUserVipByUserId(order.getUserId());
            if (userVip != null) {
                //修改会员信息
                Date km2Date = userVip.getSubject2();
                Date km3Date = userVip.getSubject3();
                if (km2Date != null) { //科目二处理
                    long x = km2Date.getTime() + oneYearLong;
                    Date km2oneYear = new Date(x);
                    userVip.setSubject2(km2oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km2oneYear = new Date(x);
                    userVip.setSubject2(km2oneYear);
                }
                if (km3Date != null) { //科目三处理
                    long x = km3Date.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                }
                userVipService.updateById(userVip);
                this.save(orderInfo);
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(order.getUserId());
                uv.setUserName(order.getUserName());
                long x = now.getTime() + oneYearLong;
                Date oneYear = new Date(x);
                uv.setSubject2(oneYear);
                uv.setSubject3(oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }
            //激活操作
            saveActiva(order, userInfo);
        } else if ("科二+科三VIP".equals(order.getGoodsName())) {
            UserVip userVip = userVipService.getUserVipByUserId(order.getUserId());
            if (userVip != null) {
                //修改会员信息
                Date km2Date = userVip.getSubject2();
                Date km3Date = userVip.getSubject3();
                if (km2Date != null) { //科目二处理
                    long x = km2Date.getTime() + oneYearLong;
                    Date km2oneYear = new Date(x);
                    userVip.setSubject2(km2oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km2oneYear = new Date(x);
                    userVip.setSubject2(km2oneYear);
                }
                if (km3Date != null) { //科目三处理
                    long x = km3Date.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                }
                userVipService.updateById(userVip);
                this.save(orderInfo);
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(order.getUserId());
                uv.setUserName(order.getUserName());
                long x = now.getTime() + oneYearLong;
                Date oneYear = new Date(x);
                uv.setSubject2(oneYear);
                uv.setSubject3(oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }
        } else if ("科二+科三+科四(含计时)".equals(order.getGoodsName())) {
            UserVip userVip = userVipService.getUserVipByUserId(order.getUserId());
            if (userVip != null) {
                //修改会员信息
                Date km2Date = userVip.getSubject2();
                Date km3Date = userVip.getSubject3();
                Date km4Date = userVip.getSubject4();
                if (km2Date != null) { //科目二处理
                    long x = km2Date.getTime() + oneYearLong;
                    Date km2oneYear = new Date(x);
                    userVip.setSubject2(km2oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km2oneYear = new Date(x);
                    userVip.setSubject2(km2oneYear);
                }
                if (km3Date != null) { //科目三处理
                    long x = km3Date.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                }
                if (km4Date != null) { //科目四处理
                    long x = km4Date.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                }
                userVipService.updateById(userVip);
                this.save(orderInfo);
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(order.getUserId());
                uv.setUserName(order.getUserName());
                long x = now.getTime() + oneYearLong;
                Date oneYear = new Date(x);
                uv.setSubject2(oneYear);
                uv.setSubject3(oneYear);
                uv.setSubject4(oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }
            //激活操作
            saveActiva(order, userInfo);
        } else if ("科二+科三+科四".equals(order.getGoodsName())) {
            UserVip userVip = userVipService.getUserVipByUserId(order.getUserId());
            if (userVip != null) {
                //修改会员信息
                Date km2Date = userVip.getSubject2();
                Date km3Date = userVip.getSubject3();
                Date km4Date = userVip.getSubject4();
                if (km2Date != null) { //科目二处理
                    long x = km2Date.getTime() + oneYearLong;
                    Date km2oneYear = new Date(x);
                    userVip.setSubject2(km2oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km2oneYear = new Date(x);
                    userVip.setSubject2(km2oneYear);
                }
                if (km3Date != null) { //科目三处理
                    long x = km3Date.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                }
                if (km4Date != null) { //科目四处理
                    long x = km4Date.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                }
                userVipService.updateById(userVip);
                this.save(orderInfo);
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(order.getUserId());
                uv.setUserName(order.getUserName());
                long x = now.getTime() + oneYearLong;
                Date oneYear = new Date(x);
                uv.setSubject2(oneYear);
                uv.setSubject3(oneYear);
                uv.setSubject4(oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }
        } else if ("科三+科四VIP(含计时)".equals(order.getGoodsName())) {
            UserVip userVip = userVipService.getUserVipByUserId(order.getUserId());
            if (userVip != null) {
                //修改会员信息
                Date km3Date = userVip.getSubject3();
                Date km4Date = userVip.getSubject4();
                if (km3Date != null) { //科目三处理
                    long x = km3Date.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                }
                if (km4Date != null) { //科目四处理
                    long x = km4Date.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                }
                userVipService.updateById(userVip);
                this.save(orderInfo);
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(order.getUserId());
                uv.setUserName(order.getUserName());
                long x = now.getTime() + oneYearLong;
                Date oneYear = new Date(x);
                uv.setSubject3(oneYear);
                uv.setSubject4(oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }
            //激活操作
            saveActiva(order, userInfo);
        } else if ("科三+科四VIP".equals(order.getGoodsName())) {
            UserVip userVip = userVipService.getUserVipByUserId(order.getUserId());
            if (userVip != null) {
                //修改会员信息
                Date km3Date = userVip.getSubject3();
                Date km4Date = userVip.getSubject4();
                if (km3Date != null) { //科目三处理
                    long x = km3Date.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                }
                if (km4Date != null) { //科目四处理
                    long x = km4Date.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                }
                userVipService.updateById(userVip);
                this.save(orderInfo);
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(order.getUserId());
                uv.setUserName(order.getUserName());
                long x = now.getTime() + oneYearLong;
                Date oneYear = new Date(x);
                uv.setSubject3(oneYear);
                uv.setSubject4(oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }
        } else if ("全科目超级VIP(含计时)".equals(order.getGoodsName())){
            UserVip userVip = userVipService.getUserVipByUserId(order.getUserId());
            if (userVip != null) {
                //修改会员信息
                Date km1Date = userVip.getSubject1();
                Date km2Date = userVip.getSubject2();
                Date km3Date = userVip.getSubject3();
                Date km4Date = userVip.getSubject4();
                if (km1Date != null) { //科目一处理
                    long x = km1Date.getTime() + oneYearLong;
                    Date km1oneYear = new Date(x);
                    userVip.setSubject1(km1oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km1oneYear = new Date(x);
                    userVip.setSubject1(km1oneYear);
                }
                if (km2Date != null) { //科目二处理
                    long x = km2Date.getTime() + oneYearLong;
                    Date km2oneYear = new Date(x);
                    userVip.setSubject2(km2oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km2oneYear = new Date(x);
                    userVip.setSubject2(km2oneYear);
                }
                if (km3Date != null) { //科目三处理
                    long x = km3Date.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                }
                if (km4Date != null) { //科目四处理
                    long x = km4Date.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                }
                userVipService.updateById(userVip);
                this.save(orderInfo);
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(order.getUserId());
                uv.setUserName(order.getUserName());
                long x = now.getTime() + oneYearLong;
                Date oneYear = new Date(x);
                uv.setSubject1(oneYear);
                uv.setSubject2(oneYear);
                uv.setSubject3(oneYear);
                uv.setSubject4(oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }
            //激活操作
            saveActiva(order, userInfo);
        } else if ("全科目超级VIP".equals(order.getGoodsName())) {
            UserVip userVip = userVipService.getUserVipByUserId(order.getUserId());
            if (userVip != null) {
                //修改会员信息
                Date km1Date = userVip.getSubject1();
                Date km2Date = userVip.getSubject2();
                Date km3Date = userVip.getSubject3();
                Date km4Date = userVip.getSubject4();
                if (km1Date != null) { //科目一处理
                    long x = km1Date.getTime() + oneYearLong;
                    Date km1oneYear = new Date(x);
                    userVip.setSubject1(km1oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km1oneYear = new Date(x);
                    userVip.setSubject1(km1oneYear);
                }
                if (km2Date != null) { //科目二处理
                    long x = km2Date.getTime() + oneYearLong;
                    Date km2oneYear = new Date(x);
                    userVip.setSubject2(km2oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km2oneYear = new Date(x);
                    userVip.setSubject2(km2oneYear);
                }
                if (km3Date != null) { //科目三处理
                    long x = km3Date.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                }
                if (km4Date != null) { //科目四处理
                    long x = km4Date.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                }
                userVipService.updateById(userVip);
                this.save(orderInfo);
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(order.getUserId());
                uv.setUserName(order.getUserName());
                long x = now.getTime() + oneYearLong;
                Date oneYear = new Date(x);
                uv.setSubject1(oneYear);
                uv.setSubject2(oneYear);
                uv.setSubject3(oneYear);
                uv.setSubject4(oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }
        }
        int isShare = schPayConfigService.isSchPayConfigByJxbh(userInfo.getCity());
        if (isShare == 1) {
            //如果是合作驾校插入消费记录表
            savePayLog(order, userInfo);
        }
    }



    @Override
    public void writeVipDataToDb(String goodsName, Long userId, String userName, String outTrandeNo, Integer total, Integer payType) {
        long oneYearLong = 1000 * 60 * 60 * 24 * 365l;
        Date now = new Date();

        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setGoodsName(goodsName);
        orderInfo.setUserId(userId);
        orderInfo.setOutTradeNo(outTrandeNo);
        orderInfo.setTotal(total);
        orderInfo.setTradeType(1);
        orderInfo.setSuccessTime(now);
        orderInfo.setPayType(payType);


        if ("科一专项VIP".equals(goodsName)) {
            UserVip userVip = userVipService.getUserVipByUserId(userId);
            if (userVip != null) {
                //修改会员信息
                Date km1Date = userVip.getSubject1();
                if (km1Date != null) {  //存在会员时间
                    if (km1Date.compareTo(now) < 0) {  //会员已过期
                        long x = now.getTime() + oneYearLong;
                        Date km1oneYear = new Date(x);
                        userVip.setSubject1(km1oneYear);
                    } else {  //会员时间延长
                        long x = km1Date.getTime() + oneYearLong;
                        Date km1oneYear = new Date(x);
                        userVip.setSubject1(km1oneYear);
                    }
                    userVipService.updateById(userVip);
                    this.save(orderInfo);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km1oneYear = new Date(x);
                    userVip.setSubject1(km1oneYear);
                    userVipService.updateById(userVip);
                    this.save(orderInfo);
                }
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(userId);
                uv.setUserName(userName);
                long x = now.getTime() + oneYearLong;
                Date km1oneYear = new Date(x);
                uv.setSubject1(km1oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }

        } else if ("科二专项VIP".equals(goodsName)) {
            UserVip userVip = userVipService.getUserVipByUserId(userId);
            if (userVip != null) {
                //修改会员信息
                Date km2Date = userVip.getSubject2();
                if (km2Date != null) {  //存在会员时间
                    if (km2Date.compareTo(now) < 0) {  //会员已过期
                        long x = now.getTime() + oneYearLong;
                        Date km2oneYear = new Date(x);
                        userVip.setSubject2(km2oneYear);
                    } else {  //会员时间延长
                        long x = km2Date.getTime() + oneYearLong;
                        Date km2oneYear = new Date(x);
                        userVip.setSubject2(km2oneYear);
                    }
                    userVipService.updateById(userVip);
                    this.save(orderInfo);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km2oneYear = new Date(x);
                    userVip.setSubject2(km2oneYear);
                    userVipService.updateById(userVip);
                    this.save(orderInfo);
                }
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(userId);
                uv.setUserName(userName);
                long x = now.getTime() + oneYearLong;
                Date km2oneYear = new Date(x);
                uv.setSubject2(km2oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }
        } else if ("科三专项VIP".equals(goodsName)) {
            UserVip userVip = userVipService.getUserVipByUserId(userId);
            if (userVip != null) {
                //修改会员信息
                Date km3Date = userVip.getSubject3();
                if (km3Date != null) {  //存在会员时间
                    if (km3Date.compareTo(now) < 0) {  //会员已过期
                        long x = now.getTime() + oneYearLong;
                        Date km3oneYear = new Date(x);
                        userVip.setSubject3(km3oneYear);
                    } else {  //会员时间延长
                        long x = km3Date.getTime() + oneYearLong;
                        Date km3oneYear = new Date(x);
                        userVip.setSubject3(km3oneYear);
                    }
                    userVipService.updateById(userVip);
                    this.save(orderInfo);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                    userVipService.updateById(userVip);
                    this.save(orderInfo);
                }
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(userId);
                uv.setUserName(userName);
                long x = now.getTime() + oneYearLong;
                Date km3oneYear = new Date(x);
                uv.setSubject3(km3oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }

        } else if ("科四专项VIP".equals(goodsName)) {
            UserVip userVip = userVipService.getUserVipByUserId(userId);
            if (userVip != null) {
                //修改会员信息
                Date km4Date = userVip.getSubject4();
                if (km4Date != null) {  //存在会员时间
                    if (km4Date.compareTo(now) < 0) {  //会员已过期
                        long x = now.getTime() + oneYearLong;
                        Date km4oneYear = new Date(x);
                        userVip.setSubject4(km4oneYear);
                    } else {  //会员时间延长
                        long x = km4Date.getTime() + oneYearLong;
                        Date km4oneYear = new Date(x);
                        userVip.setSubject4(km4oneYear);
                    }
                    userVipService.updateById(userVip);
                    this.save(orderInfo);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                    userVipService.updateById(userVip);
                    this.save(orderInfo);
                }
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(userId);
                uv.setUserName(userName);
                long x = now.getTime() + oneYearLong;
                Date km4oneYear = new Date(x);
                uv.setSubject4(km4oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }

        } else if ("科目一二三四所有付费权益".equals(goodsName)) {
            UserVip userVip = userVipService.getUserVipByUserId(userId);
            if (userVip != null) {
                //修改会员信息
                Date km1Date = userVip.getSubject1();
                Date km2Date = userVip.getSubject2();
                Date km3Date = userVip.getSubject3();
                Date km4Date = userVip.getSubject4();
                if (km1Date != null) { //科目一处理
                    long x = km1Date.getTime() + oneYearLong;
                    Date km1oneYear = new Date(x);
                    userVip.setSubject1(km1oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km1oneYear = new Date(x);
                    userVip.setSubject1(km1oneYear);
                }
                if (km2Date != null) { //科目二处理
                    long x = km2Date.getTime() + oneYearLong;
                    Date km2oneYear = new Date(x);
                    userVip.setSubject2(km2oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km2oneYear = new Date(x);
                    userVip.setSubject2(km2oneYear);
                }
                if (km3Date != null) { //科目三处理
                    long x = km3Date.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                }
                if (km4Date != null) { //科目四处理
                    long x = km4Date.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                }
                userVipService.updateById(userVip);
                this.save(orderInfo);
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(userId);
                uv.setUserName(userName);
                long x = now.getTime() + oneYearLong;
                Date oneYear = new Date(x);
                uv.setSubject1(oneYear);
                uv.setSubject2(oneYear);
                uv.setSubject3(oneYear);
                uv.setSubject4(oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }
        } else if ("科一+科四VIP".equals(goodsName)) {
            UserVip userVip = userVipService.getUserVipByUserId(userId);
            if (userVip != null) {
                //修改会员信息
                Date km1Date = userVip.getSubject1();
                Date km4Date = userVip.getSubject4();
                if (km1Date != null) { //科目一处理
                    long x = km1Date.getTime() + oneYearLong;
                    Date km1oneYear = new Date(x);
                    userVip.setSubject1(km1oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km1oneYear = new Date(x);
                    userVip.setSubject1(km1oneYear);
                }
                if (km4Date != null) { //科目四处理
                    long x = km4Date.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                }
                userVipService.updateById(userVip);
                this.save(orderInfo);
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(userId);
                uv.setUserName(userName);
                long x = now.getTime() + oneYearLong;
                Date oneYear = new Date(x);
                uv.setSubject1(oneYear);
                uv.setSubject4(oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }
        } else if ("科二+科三VIP".equals(goodsName)) {
            UserVip userVip = userVipService.getUserVipByUserId(userId);
            if (userVip != null) {
                //修改会员信息
                Date km2Date = userVip.getSubject2();
                Date km3Date = userVip.getSubject3();
                if (km2Date != null) { //科目二处理
                    long x = km2Date.getTime() + oneYearLong;
                    Date km2oneYear = new Date(x);
                    userVip.setSubject2(km2oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km2oneYear = new Date(x);
                    userVip.setSubject2(km2oneYear);
                }
                if (km3Date != null) { //科目三处理
                    long x = km3Date.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                }
                userVipService.updateById(userVip);
                this.save(orderInfo);
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(userId);
                uv.setUserName(userName);
                long x = now.getTime() + oneYearLong;
                Date oneYear = new Date(x);
                uv.setSubject2(oneYear);
                uv.setSubject3(oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }
        } else if ("科二+科三+科四".equals(goodsName)) {
            UserVip userVip = userVipService.getUserVipByUserId(userId);
            if (userVip != null) {
                //修改会员信息
                Date km2Date = userVip.getSubject2();
                Date km3Date = userVip.getSubject3();
                Date km4Date = userVip.getSubject4();
                if (km2Date != null) { //科目二处理
                    long x = km2Date.getTime() + oneYearLong;
                    Date km2oneYear = new Date(x);
                    userVip.setSubject2(km2oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km2oneYear = new Date(x);
                    userVip.setSubject2(km2oneYear);
                }
                if (km3Date != null) { //科目三处理
                    long x = km3Date.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                }
                if (km4Date != null) { //科目四处理
                    long x = km4Date.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                }
                userVipService.updateById(userVip);
                this.save(orderInfo);
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(userId);
                uv.setUserName(userName);
                long x = now.getTime() + oneYearLong;
                Date oneYear = new Date(x);
                uv.setSubject2(oneYear);
                uv.setSubject3(oneYear);
                uv.setSubject4(oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }
        } else if ("科三+科四VIP".equals(goodsName)) {
            UserVip userVip = userVipService.getUserVipByUserId(userId);
            if (userVip != null) {
                //修改会员信息
                Date km3Date = userVip.getSubject3();
                Date km4Date = userVip.getSubject4();
                if (km3Date != null) { //科目三处理
                    long x = km3Date.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                }
                if (km4Date != null) { //科目四处理
                    long x = km4Date.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                }
                userVipService.updateById(userVip);
                this.save(orderInfo);
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(userId);
                uv.setUserName(userName);
                long x = now.getTime() + oneYearLong;
                Date oneYear = new Date(x);
                uv.setSubject3(oneYear);
                uv.setSubject4(oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }
        } else if ("全科目超级VIP".equals(goodsName)) {
            UserVip userVip = userVipService.getUserVipByUserId(userId);
            if (userVip != null) {
                //修改会员信息
                Date km1Date = userVip.getSubject1();
                Date km2Date = userVip.getSubject2();
                Date km3Date = userVip.getSubject3();
                Date km4Date = userVip.getSubject4();
                if (km1Date != null) { //科目一处理
                    long x = km1Date.getTime() + oneYearLong;
                    Date km1oneYear = new Date(x);
                    userVip.setSubject1(km1oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km1oneYear = new Date(x);
                    userVip.setSubject1(km1oneYear);
                }
                if (km2Date != null) { //科目二处理
                    long x = km2Date.getTime() + oneYearLong;
                    Date km2oneYear = new Date(x);
                    userVip.setSubject2(km2oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km2oneYear = new Date(x);
                    userVip.setSubject2(km2oneYear);
                }
                if (km3Date != null) { //科目三处理
                    long x = km3Date.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km3oneYear = new Date(x);
                    userVip.setSubject3(km3oneYear);
                }
                if (km4Date != null) { //科目四处理
                    long x = km4Date.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                } else {
                    long x = now.getTime() + oneYearLong;
                    Date km4oneYear = new Date(x);
                    userVip.setSubject4(km4oneYear);
                }
                userVipService.updateById(userVip);
                this.save(orderInfo);
            } else {
                //新增会员信息
                UserVip uv = new UserVip();
                uv.setUserId(userId);
                uv.setUserName(userName);
                long x = now.getTime() + oneYearLong;
                Date oneYear = new Date(x);
                uv.setSubject1(oneYear);
                uv.setSubject2(oneYear);
                uv.setSubject3(oneYear);
                uv.setSubject4(oneYear);
                userVipService.save(uv);
                this.save(orderInfo);
            }
        }

    }

    @Override
    public List<QuerySchoolOrderListVo> selectSchoolOrderInfoList(QuerySchoolOrderListDTO schoolOrderListDTO) {
        return null;
    }



    /**
     * 插入支付记录
     * @param order
     * @param gzptUserInfo
     */
    private void savePayLog(WxJsOrder order, GzptUserInfo gzptUserInfo) {
        GzptSchPayLog schPayLog = new GzptSchPayLog();
        schPayLog.setStuId(gzptUserInfo.getOutId());
        schPayLog.setDqbh(order.getDqbh());
        schPayLog.setPrice(order.getTotal());
        schPayLog.setJxbh(order.getSchool());
        schPayLog.setCrtime(new Date());
        schPayLog.setState(1); // 1充值  2退款
        schPayLogService.saveSchPayLog(schPayLog);
    }

    /**
     * 插入激活记录
     * @param order
     * @param gzptUserInfo
     */
    private void saveActiva(WxJsOrder order, GzptUserInfo gzptUserInfo) {
        GzptSchActivation schActivation = new GzptSchActivation();
        schActivation.setDqbh(order.getDqbh());
        schActivation.setDqmc(order.getDqmc());
        schActivation.setJxbh(order.getSchool());
        schActivation.setJxmc(order.getSchoolName());
        schActivation.setUserId(order.getUserId());
        schActivation.setStuId(gzptUserInfo.getOutId());
        schActivation.setCrtime(new Date());
        schActivationService.saveSchActivation(schActivation);
    }
}
