admin
2021-04-22 745320cbb4edfa4fbc8f0f95483a4ee7893d5769
src/main/java/com/yeshi/buwan/service/imp/order/OrderServiceImpl.java
@@ -13,6 +13,7 @@
import com.yeshi.buwan.exception.order.OrderException;
import com.yeshi.buwan.exception.order.PayException;
import com.yeshi.buwan.exception.vip.VIPException;
import com.yeshi.buwan.exception.vip.VideoBuyRecordException;
import com.yeshi.buwan.pptv.PPTVVipManager;
import com.yeshi.buwan.service.inter.order.OrderService;
import com.yeshi.buwan.service.manager.GoldCornManager;
@@ -62,7 +63,7 @@
    @Transactional(rollbackFor = Exception.class)
    @Override
    public OrderRecord createOrder(OrderRecord record) throws OrderException {
        if (record.getMoney() == null || (record.getType() == null && record.getVideoInfoId() == null) || record.getOrderType() == null || record.getUid() == null) {
        if (record.getMoney() == null || (record.getType() == null && record.getVideoCid() == null) || record.getOrderType() == null || record.getUid() == null) {
            throw new OrderException(1, "参数不完整");
        }
@@ -104,7 +105,7 @@
    @Transactional(rollbackFor = Exception.class)
//    @GlobalTransactional(timeoutMills = 30000, name = "buwan-order", rollbackFor = Exception.class)
    @Override
    public PayWayInfoDTO payOrder(OrderRecord record) throws OrderException, GoldCornException, PayException, VIPException, PPTVException {
    public PayWayInfoDTO payOrder(OrderRecord record) throws OrderException, GoldCornException, PayException, VIPException, PPTVException, VideoBuyRecordException {
        String orderNo = VIPOrderUtil.getOutOrderNo(record.getOrderType(), record.getId());
        switch (record.getPayWay()) {
            case OrderRecord
@@ -206,7 +207,7 @@
    @Transactional(rollbackFor = Exception.class)
    @Override
    public OrderRecord paySuccess(String id, int payWay, BigDecimal payMoney, Date payTime) throws
            VIPException, PPTVException {
            VIPException, PPTVException, VideoBuyRecordException, OrderException {
        orderLogger.info("订单支付成功目的执行:id-{},支付方式-{},支付金额-{},支付时间-{}", id, payWay, payMoney, payTime.getTime());
        Session session = vipOrderRecordDao.getSession();
@@ -215,11 +216,11 @@
        Query query = session.createSQLQuery("select * from wk_vip_order_record r where r.id=? for update").addEntity(OrderRecord.class).setCacheable(false).setParameter(0, id);
        List<OrderRecord> list = query.list();
        if (list == null || list.size() == 0)
            throw new VIPException(10, "订单不存在");
            throw new OrderException(10, "订单不存在");
        OrderRecord record = list.get(0);
        if (record.getState() != OrderRecord.STATE_NOT_PAY)
            throw new VIPException(1, "订单未处于待支付状态");
            throw new OrderException(1, "订单未处于待支付状态");
        if (payWay != OrderRecord.PAY_WAY_GOLDCORN) {
@@ -302,7 +303,7 @@
            try {
                goldCornManager.drawbackGoldCorn(record);
            } catch (Exception e) {
                throw new GoldCornException(1, "影视豆退款成功");
                throw new GoldCornException(1, "影视豆退款失败");
            }
        }
@@ -310,8 +311,20 @@
        record.setState(OrderRecord.STATE_CANCEL);
        record.setUpdateTime(new Date());
        record.setRemarks(reason);
        vipOrderRecordDao.update(record);
        session.update(record);
        orderLogger.info("取消订单成功:id-{}", id);
    }
    @Override
    public List<OrderRecord> getCanCancelOrderList(int page, int pageSize) {
        OrderRecordDao.DaoQuery daoQuery = new OrderRecordDao.DaoQuery();
        daoQuery.state = OrderRecord.STATE_NOT_PAY;
        //30分钟未支付取消订单
        daoQuery.maxCreateTime = new Date(System.currentTimeMillis() - 1000 * 60 * 30);
        daoQuery.minCreateTime = new Date(daoQuery.maxCreateTime.getTime() - 1000 * 60 * 60L * 24);
        return vipOrderRecordDao.list(daoQuery);
    }
@@ -323,6 +336,7 @@
            return record;
        switch (record.getPayWay()) {
            case OrderRecord.PAY_WAY_ALIPAY_GOLDCORN:
            case OrderRecord.PAY_WAY_ALIPAY: {
                //支付宝
                AlipayTradeQueryResponse res = null;
@@ -342,6 +356,7 @@
            }
            break;
            case OrderRecord.PAY_WAY_WX_GOLDCORN:
            case OrderRecord.PAY_WAY_WX: {
                //微信
                try {
@@ -406,16 +421,18 @@
            UserVIPInfo vip = new UserVIPInfo();
            vip.setUid(uid);
            vip.setCreateTime(new Date());
            vip.setExpireDate(getExpireTime(payTime, null, type));
            Date[] expireDate = getExpireTime(payTime, null, type);
            vip.setExpireDate(expireDate[1]);
            session.save(vip);
            return new Date[]{payTime, vip.getExpireDate()};
            return expireDate;
        } else {
            //修改
            UserVIPInfo vipInfo = (UserVIPInfo) list.get(0);
            Date expireDate = getExpireTime(payTime, vipInfo.getExpireDate(), type);
            session.createQuery("update UserVIPInfo i set i.expireDate=? ,i.updateTime=? where i.uid=?").setParameter(0, expireDate).setParameter(1, new Date()).setParameter(2, uid).executeUpdate();
            Date[] expireDate = getExpireTime(payTime, vipInfo.getExpireDate(), type);
            session.createQuery("update UserVIPInfo i set i.expireDate=? ,i.updateTime=? where i.uid=?").setParameter(0, expireDate[1]).setParameter(1, new Date()).setParameter(2, uid).executeUpdate();
            return new Date[]{vipInfo.getExpireDate() == null ? new Date() : vipInfo.getExpireDate(), expireDate};
            return expireDate;
        }
    }
@@ -427,13 +444,18 @@
     * @param type
     * @return
     */
    private Date getExpireTime(Date payTime, Date expireTime, VIPPriceType type) {
    private Date[] getExpireTime(Date payTime, Date expireTime, VIPPriceType type) {
        Calendar calendar = Calendar.getInstance();
        if (expireTime != null) {
            calendar.setTimeInMillis(expireTime.getTime());
            //之前续期时间是否大于付款时间
            if (payTime.getTime() < expireTime.getTime())
                calendar.setTimeInMillis(expireTime.getTime());
            else
                calendar.setTimeInMillis(payTime.getTime());
        } else {
            calendar.setTimeInMillis(payTime.getTime());
        }
        long startTime = calendar.getTimeInMillis();
        if (type == VIPPriceType.day) {
            calendar.add(Calendar.DAY_OF_WEEK, 1);
        } else if (type == VIPPriceType.week) {
@@ -447,7 +469,7 @@
        } else if (type == VIPPriceType.year) {
            calendar.add(Calendar.YEAR, 1);
        }
        return new Date(calendar.getTimeInMillis());
        return new Date[]{new Date(startTime), new Date(calendar.getTimeInMillis())};
    }