From 19533a17aa55fafc70d0a385928e785cb50e1ebc Mon Sep 17 00:00:00 2001 From: admin <2780501319@qq.com> Date: 星期五, 30 七月 2021 02:05:14 +0800 Subject: [PATCH] 爱奇艺视频更新 --- src/main/java/com/yeshi/buwan/service/imp/order/OrderServiceImpl.java | 200 +++++++++++++++++++++++++++++++------------------ 1 files changed, 125 insertions(+), 75 deletions(-) diff --git a/src/main/java/com/yeshi/buwan/service/imp/order/OrderServiceImpl.java b/src/main/java/com/yeshi/buwan/service/imp/order/OrderServiceImpl.java index 0a18deb..c0596de 100644 --- a/src/main/java/com/yeshi/buwan/service/imp/order/OrderServiceImpl.java +++ b/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.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, "鍙傛暟涓嶅畬鏁�"); } @@ -73,6 +74,25 @@ if (record.getCreateTime() == null) { record.setCreateTime(new Date()); } + + if (record.getPayWay() == OrderRecord.PAY_WAY_WX) { + if (record.getGoldCorn() != null && record.getGoldCorn() > 0) { + if (record.getMoney().compareTo(new BigDecimal("0")) == 0) { + record.setPayWay(OrderRecord.PAY_WAY_GOLDCORN); + } else { + record.setPayWay(OrderRecord.PAY_WAY_WX_GOLDCORN); + } + } + } else if (record.getPayWay() == OrderRecord.PAY_WAY_ALIPAY) { + if (record.getGoldCorn() != null && record.getGoldCorn() > 0) { + if (record.getMoney().compareTo(new BigDecimal("0")) == 0) { + record.setPayWay(OrderRecord.PAY_WAY_GOLDCORN); + } else { + record.setPayWay(OrderRecord.PAY_WAY_ALIPAY_GOLDCORN); + } + } + } + record.setMoneyPay(false); record.setGoldCornPay(false); @@ -85,8 +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 { - //TODO 褰辫璞嗘敮浠� + 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 @@ -97,12 +116,16 @@ } catch (Exception e) { throw new GoldCornException(1, "褰辫璞嗘墸闄ゅ嚭閿�"); } + paySuccess(record.getId(), OrderRecord.PAY_WAY_GOLDCORN, null, new Date()); orderLogger.info("璁㈠崟褰辫璞嗘敮浠樻垚鍔燂細id-{}", record.getId()); case OrderRecord .PAY_WAY_ALIPAY: { + if (record.getMoney() != null && record.getMoney().compareTo(new BigDecimal(0)) == 0) { + return new PayWayInfoDTO(0, VipUtil.getPaySuccessUrl(record.getId())); + } //鐢熸垚鏀粯瀹濇敮浠樿鍗� - String form = VipUtil.getVipChargeAlipayForm(record.getId(), orderNo, record.getMoney()); + String form = VipUtil.getVipChargeAlipayForm(record.getId(), record.getOrderType(), orderNo, record.getMoney()); //鏆傚瓨2鍒嗛挓 String id = StringUtil.Md5(UUID.randomUUID().toString() + "#" + System.currentTimeMillis()); redisManager.cacheCommonString(id, form, 120); @@ -115,12 +138,17 @@ .PAY_WAY_WX_GOLDCORN: try { goldCornManager.consumeGoldCorn(record, record.getGoldCorn()); + } catch (Exception e) { throw new GoldCornException(1, "褰辫璞嗘墸闄ゅ嚭閿�"); } + paySuccess(record.getId(), OrderRecord.PAY_WAY_GOLDCORN, null, new Date()); orderLogger.info("璁㈠崟褰辫璞嗘敮浠樻垚鍔燂細id-{} 绫诲瀷-{}", record.getId(), record.getOrderType().name()); case OrderRecord .PAY_WAY_WX: { + if (record.getMoney() != null && record.getMoney().compareTo(new BigDecimal(0)) == 0) { + return new PayWayInfoDTO(0, VipUtil.getPaySuccessUrl(record.getId())); + } //鐢熸垚寰俊鏀粯璁㈠崟 try { String title = ""; @@ -141,12 +169,15 @@ case OrderRecord.PAY_WAY_GOLDCORN: { try { goldCornManager.consumeGoldCorn(record, record.getGoldCorn()); + orderLogger.info("璁㈠崟褰辫璞嗘敮浠樻垚鍔燂細id-{}", record.getId()); } catch (Exception e) { throw new GoldCornException(1, "褰辫璞嗘墸闄ゅ嚭閿�"); } - orderLogger.info("璁㈠崟褰辫璞嗘敮浠樻垚鍔燂細id-{}", record.getId()); + paySuccess(record.getId(), OrderRecord.PAY_WAY_GOLDCORN, null, new Date()); + return new PayWayInfoDTO(0, VipUtil.getPaySuccessUrl(record.getId())); } - break; + case OrderRecord.PAY_WAY_IAPP: + return new PayWayInfoDTO(OrderRecord.PAY_WAY_IAPP, null); } throw new OrderException(1, "鏀粯鏂瑰紡涓嶅瓨鍦�"); } @@ -178,7 +209,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("璁㈠崟鏀粯鎴愬姛鐩殑鎵ц锛歩d-{}锛屾敮浠樻柟寮�-{},鏀粯閲戦-{}锛屾敮浠樻椂闂�-{}", id, payWay, payMoney, payTime.getTime()); Session session = vipOrderRecordDao.getSession(); @@ -186,69 +217,67 @@ //淇敼璁板綍 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 OrderException(10, "璁㈠崟涓嶅瓨鍦�"); - if (list != null && list.size() > 0) { - OrderRecord record = list.get(0); - if (record.getState() != OrderRecord.STATE_NOT_PAY) - throw new VIPException(1, "璁㈠崟鏈浜庡緟鏀粯鐘舵��"); + OrderRecord record = list.get(0); + if (record.getState() != OrderRecord.STATE_NOT_PAY) + throw new OrderException(1, "璁㈠崟鏈浜庡緟鏀粯鐘舵��"); - if (record.getPayWay() != OrderRecord.PAY_WAY_GOLDCORN) { - record.setPayMoney(payMoney); - record.setMoneyPay(true); - } else { - record.setGoldCornPay(true); - } - - record.setPayTime(payTime); - record.setUpdateTime(new Date()); - record.setState(getPayState(record)); - - //宸茬粡鏀粯鎴愬姛 - if (record.getState() == OrderRecord.STATE_PAY) { - session.createSQLQuery("insert into wk_vip_order_pay_success(id,create_time) value(?,now())").setParameter(0, id).executeUpdate(); - - } - - if (record.getOrderType() == OrderType.vip) { - Date[] expireDate = addExpireTime(session, record.getUid(), payTime, record.getType()); - record.setVipStartTime(expireDate[0]); - record.setVipEndTime(expireDate[1]); - if (expireDate == null) { - throw new VIPException(2, "娣诲姞鐢ㄦ埛浼氬憳鏃堕棿鍑洪敊"); - } - session.update(record); - - - if (record.getState() == OrderRecord.STATE_PAY) { - orderLogger.info("璁㈠崟鍏ㄩ儴鏀粯鎴愬姛锛歩d-{}", id); - //璐拱VIP - pptvVipManager.buyVIP(record); - orderLogger.info("璐拱VIP鎴愬姛锛歩d-{}", id); - } else { - orderLogger.info("璁㈠崟閮ㄥ垎鏀粯鎴愬姛锛歩d-{}", id); - } - - } else if (record.getOrderType() == OrderType.video) { - record.setVipStartTime(payTime); - //7澶╀箣鍐呮湁鏁� - record.setVipEndTime(new Date(payTime.getTime() + 1000 * 60 * 60L * 24 * 7)); - session.update(record); - //鍗曠墖璐拱鎴愬姛锛�7澶╂湁鏁堟湡锛� - if (record.getState() == OrderRecord.STATE_PAY) { - orderLogger.info("璁㈠崟鍏ㄩ儴鏀粯鎴愬姛锛歩d-{}", id); - //璐拱鍗曠墖 - pptvVipManager.buyVideo(record); - orderLogger.info("璐拱鍗曠墖鎴愬姛锛歩d-{}", id); - } else { - orderLogger.info("璁㈠崟閮ㄥ垎鏀粯鎴愬姛锛歩d-{}", id); - } - } - - return record; + if (payWay != OrderRecord.PAY_WAY_GOLDCORN) { + record.setPayMoney(payMoney); + record.setMoneyPay(true); } else { - throw new VIPException(10, "璁㈠崟涓嶅瓨鍦�"); + record.setGoldCornPay(true); } + + record.setPayTime(payTime); + record.setUpdateTime(new Date()); + record.setState(getPayState(record)); + + //宸茬粡鏀粯鎴愬姛 + if (record.getState() == OrderRecord.STATE_PAY) { + session.createSQLQuery("insert into wk_vip_order_pay_success(id,create_time) value(?,now())").setParameter(0, id).executeUpdate(); + } + + if (record.getOrderType() == OrderType.vip) { + Date[] expireDate = addExpireTime(session, record.getUid(), payTime, record.getType()); + record.setVipStartTime(expireDate[0]); + record.setVipEndTime(expireDate[1]); + if (expireDate == null) { + throw new VIPException(2, "娣诲姞鐢ㄦ埛浼氬憳鏃堕棿鍑洪敊"); + } + session.update(record); + + + if (record.getState() == OrderRecord.STATE_PAY) { + orderLogger.info("璁㈠崟鍏ㄩ儴鏀粯鎴愬姛锛歩d-{}", id); + //璐拱VIP + pptvVipManager.buyVIP(record); + orderLogger.info("璐拱VIP鎴愬姛锛歩d-{}", id); + } else { + orderLogger.info("璁㈠崟閮ㄥ垎鏀粯鎴愬姛锛歩d-{}", id); + } + + } else if (record.getOrderType() == OrderType.video) { + record.setVipStartTime(payTime); + //7澶╀箣鍐呮湁鏁� + record.setVipEndTime(new Date(payTime.getTime() + 1000 * 60 * 60L * 24 * 7)); + session.update(record); + //鍗曠墖璐拱鎴愬姛锛�7澶╂湁鏁堟湡锛� + if (record.getState() == OrderRecord.STATE_PAY) { + orderLogger.info("璁㈠崟鍏ㄩ儴鏀粯鎴愬姛锛歩d-{}", id); + //璐拱鍗曠墖 + pptvVipManager.buyVideo(record); + orderLogger.info("璐拱鍗曠墖鎴愬姛锛歩d-{}", id); + } else { + orderLogger.info("璁㈠崟閮ㄥ垎鏀粯鎴愬姛锛歩d-{}", id); + } + } + + return record; + } @@ -276,7 +305,7 @@ try { goldCornManager.drawbackGoldCorn(record); } catch (Exception e) { - throw new GoldCornException(1, "褰辫璞嗛��娆炬垚鍔�"); + throw new GoldCornException(1, "褰辫璞嗛��娆惧け璐�"); } } @@ -284,8 +313,20 @@ record.setState(OrderRecord.STATE_CANCEL); record.setUpdateTime(new Date()); record.setRemarks(reason); - vipOrderRecordDao.update(record); + session.update(record); orderLogger.info("鍙栨秷璁㈠崟鎴愬姛锛歩d-{}", 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); } @@ -297,6 +338,7 @@ return record; switch (record.getPayWay()) { + case OrderRecord.PAY_WAY_ALIPAY_GOLDCORN: case OrderRecord.PAY_WAY_ALIPAY: { //鏀粯瀹� AlipayTradeQueryResponse res = null; @@ -316,6 +358,7 @@ } break; + case OrderRecord.PAY_WAY_WX_GOLDCORN: case OrderRecord.PAY_WAY_WX: { //寰俊 try { @@ -380,16 +423,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; } } @@ -401,13 +446,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) { @@ -421,7 +471,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())}; } -- Gitblit v1.8.0