| | |
| | | import com.alipay.api.AlipayApiException; |
| | | import com.alipay.api.response.AlipayTradeQueryResponse; |
| | | import com.yeshi.buwan.dao.vip.OrderRecordDao; |
| | | import com.yeshi.buwan.domain.vip.OrderRecord; |
| | | import com.yeshi.buwan.domain.vip.OrderType; |
| | | import com.yeshi.buwan.domain.vip.UserVIPInfo; |
| | | import com.yeshi.buwan.domain.vip.VIPPriceType; |
| | | import com.yeshi.buwan.dao.vip.VIPPriceDao; |
| | | import com.yeshi.buwan.domain.vip.*; |
| | | import com.yeshi.buwan.dto.order.OrderPaySuccessForm; |
| | | import com.yeshi.buwan.dto.order.PayWayInfoDTO; |
| | | import com.yeshi.buwan.exception.PPTVException; |
| | | import com.yeshi.buwan.exception.goldcorn.GoldCornException; |
| | |
| | | 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.videos.pptv.PPTVVipManager; |
| | | import com.yeshi.buwan.service.inter.order.OrderService; |
| | | import com.yeshi.buwan.service.manager.GoldCornManager; |
| | | import com.yeshi.buwan.util.Constant; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.yeshi.utils.alipay.AlipayH5PayUtil; |
| | | import org.yeshi.utils.entity.wx.WXPayOrderInfoV3; |
| | | import org.yeshi.utils.ios.pay.IOSPayVerifyUtil; |
| | | import org.yeshi.utils.ios.pay.vo.IOSAPPBuyVerifyResult; |
| | | import org.yeshi.utils.wx.WXPayV3Util; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | |
| | | @Resource |
| | | private GoldCornManager goldCornManager; |
| | | |
| | | @Resource |
| | | private VIPPriceDao vipPriceDao; |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | |
| | | } catch (Exception e) { |
| | | throw new GoldCornException(1, "影视豆扣除出错"); |
| | | } |
| | | paySuccess(record.getId(), OrderRecord.PAY_WAY_GOLDCORN, null, new Date()); |
| | | paySuccess(new OrderPaySuccessForm(record.getId(), OrderRecord.PAY_WAY_GOLDCORN, null, new Date())); |
| | | |
| | | orderLogger.info("订单影视豆支付成功:id-{}", record.getId()); |
| | | case OrderRecord |
| | |
| | | } catch (Exception e) { |
| | | throw new GoldCornException(1, "影视豆扣除出错"); |
| | | } |
| | | paySuccess(record.getId(), OrderRecord.PAY_WAY_GOLDCORN, null, new Date()); |
| | | paySuccess(new OrderPaySuccessForm(record.getId(), OrderRecord.PAY_WAY_GOLDCORN, null, new Date())); |
| | | orderLogger.info("订单影视豆支付成功:id-{} 类型-{}", record.getId(), record.getOrderType().name()); |
| | | case OrderRecord |
| | | .PAY_WAY_WX: { |
| | |
| | | } catch (Exception e) { |
| | | throw new GoldCornException(1, "影视豆扣除出错"); |
| | | } |
| | | paySuccess(record.getId(), OrderRecord.PAY_WAY_GOLDCORN, null, new Date()); |
| | | paySuccess(new OrderPaySuccessForm(record.getId(), OrderRecord.PAY_WAY_GOLDCORN, null, new Date())); |
| | | return new PayWayInfoDTO(0, VipUtil.getPaySuccessUrl(record.getId())); |
| | | } |
| | | case OrderRecord.PAY_WAY_IAPP: |
| | |
| | | return OrderRecord.STATE_PAY; |
| | | else |
| | | return OrderRecord.STATE_NOT_PAY; |
| | | case OrderRecord.PAY_WAY_IAPP: |
| | | if (record.getMoneyPay()) |
| | | return OrderRecord.STATE_PAY; |
| | | else |
| | | return OrderRecord.STATE_NOT_PAY; |
| | | } |
| | | return OrderRecord.STATE_NOT_PAY; |
| | | } |
| | |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public OrderRecord paySuccess(String id, int payWay, BigDecimal payMoney, Date payTime) throws |
| | | public OrderRecord paySuccess(OrderPaySuccessForm successForm) throws |
| | | VIPException, PPTVException, VideoBuyRecordException, OrderException { |
| | | orderLogger.info("订单支付成功目的执行:id-{},支付方式-{},支付金额-{},支付时间-{}", id, payWay, payMoney, payTime.getTime()); |
| | | orderLogger.info("订单支付成功目的执行:id-{},支付方式-{},支付金额-{},支付时间-{}", successForm.getId(), successForm.getPayWay(), successForm.getPayMoney(), successForm.getPayTime()); |
| | | |
| | | Session session = vipOrderRecordDao.getSession(); |
| | | |
| | | //修改记录 |
| | | Query query = session.createSQLQuery("select * from wk_vip_order_record r where r.id=? for update").addEntity(OrderRecord.class).setCacheable(false).setParameter(0, id); |
| | | Query query = session.createSQLQuery("select * from wk_vip_order_record r where r.id=? for update").addEntity(OrderRecord.class).setCacheable(false).setParameter(0, successForm.getId()); |
| | | List<OrderRecord> list = query.list(); |
| | | if (list == null || list.size() == 0) |
| | | throw new OrderException(10, "订单不存在"); |
| | |
| | | throw new OrderException(1, "订单未处于待支付状态"); |
| | | |
| | | |
| | | if (payWay != OrderRecord.PAY_WAY_GOLDCORN) { |
| | | record.setPayMoney(payMoney); |
| | | if (successForm.getPayWay() != OrderRecord.PAY_WAY_GOLDCORN) { |
| | | record.setPayMoney(successForm.getPayMoney()); |
| | | record.setMoneyPay(true); |
| | | record.setAppleTransactionId(successForm.getAppleTransactionId()); |
| | | record.setAppleOriginalTransactionId(successForm.getAppleOriginalTransactionId()); |
| | | } else { |
| | | record.setGoldCornPay(true); |
| | | } |
| | | |
| | | record.setPayTime(payTime); |
| | | record.setPayTime(successForm.getPayTime()); |
| | | 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(); |
| | | session.createSQLQuery("insert into wk_vip_order_pay_success(id,create_time) value(?,now())").setParameter(0, successForm.getId()).executeUpdate(); |
| | | } |
| | | |
| | | if (record.getOrderType() == OrderType.vip) { |
| | | Date[] expireDate = addExpireTime(session, record.getUid(), payTime, record.getType()); |
| | | Date[] expireDate = addExpireTime(session, record.getUid(), successForm.getPayTime(), record.getType()); |
| | | record.setVipStartTime(expireDate[0]); |
| | | record.setVipEndTime(expireDate[1]); |
| | | if (expireDate == null) { |
| | |
| | | |
| | | |
| | | if (record.getState() == OrderRecord.STATE_PAY) { |
| | | orderLogger.info("订单全部支付成功:id-{}", id); |
| | | orderLogger.info("订单全部支付成功:id-{}", successForm.getId()); |
| | | //购买VIP |
| | | pptvVipManager.buyVIP(record); |
| | | orderLogger.info("购买VIP成功:id-{}", id); |
| | | orderLogger.info("购买VIP成功:id-{}", successForm.getId()); |
| | | } else { |
| | | orderLogger.info("订单部分支付成功:id-{}", id); |
| | | orderLogger.info("订单部分支付成功:id-{}", successForm.getId()); |
| | | } |
| | | |
| | | } else if (record.getOrderType() == OrderType.video) { |
| | | record.setVipStartTime(payTime); |
| | | record.setVipStartTime(successForm.getPayTime()); |
| | | //7天之内有效 |
| | | record.setVipEndTime(new Date(payTime.getTime() + 1000 * 60 * 60L * 24 * 7)); |
| | | record.setVipEndTime(new Date(successForm.getPayTime().getTime() + 1000 * 60 * 60L * 24 * 7)); |
| | | session.update(record); |
| | | //单片购买成功(7天有效期) |
| | | if (record.getState() == OrderRecord.STATE_PAY) { |
| | | orderLogger.info("订单全部支付成功:id-{}", id); |
| | | orderLogger.info("订单全部支付成功:id-{}", successForm.getId()); |
| | | //购买单片 |
| | | pptvVipManager.buyVideo(record); |
| | | orderLogger.info("购买单片成功:id-{}", id); |
| | | orderLogger.info("购买单片成功:id-{}", successForm.getId()); |
| | | } else { |
| | | orderLogger.info("订单部分支付成功:id-{}", id); |
| | | orderLogger.info("订单部分支付成功:id-{}", successForm.getId()); |
| | | } |
| | | } |
| | | |
| | |
| | | //支付成功 |
| | | if (res.isSuccess() && "TRADE_SUCCESS".equalsIgnoreCase(res.getTradeStatus())) { |
| | | try { |
| | | return paySuccess(id, OrderRecord.PAY_WAY_ALIPAY, new BigDecimal(res.getTotalAmount()), new Date()); |
| | | return paySuccess(new OrderPaySuccessForm(id, OrderRecord.PAY_WAY_ALIPAY, new BigDecimal(res.getTotalAmount()), new Date())); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | try { |
| | | WXPayOrderInfoV3 info = WXPayV3Util.getPayOrderInfo(VIPOrderUtil.getOutOrderNo(record.getOrderType(), id), VipUtil.getWXAPP()); |
| | | if (info != null && info.getTrade_state().equalsIgnoreCase("SUCCESS")) { |
| | | paySuccess(id, record.getPayWay(), new BigDecimal(info.getAmount().getPayer_total()).divide(new BigDecimal(100), 2, RoundingMode.FLOOR), new Date()); |
| | | paySuccess(new OrderPaySuccessForm(id, record.getPayWay(), new BigDecimal(info.getAmount().getPayer_total()).divide(new BigDecimal(100), 2, RoundingMode.FLOOR), new Date())); |
| | | return record; |
| | | } |
| | | } catch (Exception e) { |
| | |
| | | |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public OrderRecord checkApplePay(String orderNo, String receipt) throws Exception { |
| | | OrderRecord orderRecord = vipOrderRecordDao.find(OrderRecord.class, orderNo); |
| | | if (orderRecord == null) { |
| | | throw new OrderException(1, "订单号不存在"); |
| | | } |
| | | |
| | | if (!StringUtil.isNullOrEmpty(orderRecord.getAppleTransactionId())) { |
| | | throw new OrderException(2, "订单已支付"); |
| | | } |
| | | |
| | | IOSAPPBuyVerifyResult result = IOSPayVerifyUtil.buyAppVerify(receipt, "28ca52e358b94c4eba3de41dfa7dd023", false); |
| | | List<IOSAPPBuyVerifyResult.OrderInfo> orderInfoList = result.getLatestReceiptInfo(); |
| | | IOSAPPBuyVerifyResult.OrderInfo orderInfo = orderInfoList.get(0); |
| | | String productId = orderInfo.getProduct_id(); |
| | | VIPPrice vipPrice = vipPriceDao.selectByIOSProductId(productId); |
| | | if (vipPrice == null) |
| | | throw new Exception("商品ID不存在"); |
| | | if (orderRecord.getType() != vipPrice.getType()) |
| | | throw new Exception("价格类型不匹配"); |
| | | //String id, int payWay, BigDecimal payMoney, Date payTime, String appleTransactionId, String appleOriginalTransactionId |
| | | OrderPaySuccessForm successForm = new OrderPaySuccessForm(orderRecord.getId(), OrderRecord.PAY_WAY_IAPP, new BigDecimal(0), new Date(orderInfo.getPurchaseDateMs()), orderInfo.getTransactionId(), orderInfo.getOriginalTransactionId()); |
| | | paySuccess(successForm); |
| | | return null; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<OrderRecord> listOrderRecord(String uid, OrderType orderType, Integer state, int page, int pageSize) { |