| | |
| | | import com.ks.vip.pojo.DTO.VipOrderDTO; |
| | | import com.ks.vip.pojo.Enums.OrderTypeEnum; |
| | | import com.ks.vip.pojo.Enums.PayWayEnum; |
| | | import com.ks.vip.query.VipOrderQuery; |
| | | import com.ks.vip.service.VipCenterService; |
| | | import com.ks.vip.service.VipComboService; |
| | | import com.ks.vip.service.VipOrederPayService; |
| | | import com.ks.vip.service.VipOrederService; |
| | | import com.ks.vip.service.manager.RedisManager; |
| | | import com.ks.vip.util.Constant; |
| | | import com.ks.vip.util.PayUtil; |
| | |
| | | import org.yeshi.utils.wx.WXPayV3Util; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | |
| | | @Service(version = "1.0") |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public PayWayInfoDTO addOrderByBuy(VipOrderDTO t) throws VipOrderException { |
| | | if(t.getComboId() == null || t.getComboId() <= 0){ |
| | | if (t.getComboId() == null || t.getComboId() <= 0) { |
| | | throw new VipOrderException(1, "套餐ID不能为空"); |
| | | } |
| | | if(StringUtil.isNullOrEmpty(t.getUid())){ |
| | | if (StringUtil.isNullOrEmpty(t.getUid())) { |
| | | throw new VipOrderException(1, "用户ID不能为空"); |
| | | } |
| | | if(t.getPayWay() == null){ |
| | | if (t.getPayWay() == null) { |
| | | throw new VipOrderException(1, "付款方式不能为空"); |
| | | } |
| | | if(StringUtil.isNullOrEmpty(t.getThreeOrderId())){ |
| | | if (StringUtil.isNullOrEmpty(t.getThreeOrderId())) { |
| | | throw new VipOrderException(1, "付款订单号不能为空"); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | // 判断订单类型: 首单、续费 |
| | | String orderType = OrderTypeEnum.buyNewly.name(); |
| | | OrderTypeEnum orderType = OrderTypeEnum.buyNewly; |
| | | long count = vipOrderMapper.countByTypeAndUid(t.getUid(), orderType); |
| | | if(count > 0) { |
| | | orderType = OrderTypeEnum.buyRenew.name(); |
| | | if (count > 0) { |
| | | orderType = OrderTypeEnum.buyRenew; |
| | | } |
| | | |
| | | // 插入订单信息 |
| | |
| | | return new PayWayInfoDTO(PayWayEnum.weChat.getWay(), PayUtil.getPaySuccessUrl(orderId)); |
| | | } |
| | | |
| | | String formWX = PayUtil.createWXOrder(orderId, null, orderId, order.getPayMoney() ,goodsTitle); |
| | | String formWX = PayUtil.createWXOrder(orderId, null, orderId, order.getPayMoney(), goodsTitle); |
| | | //暂存2分钟 |
| | | String idWX = StringUtil.Md5(UUID.randomUUID().toString() + "#" + System.currentTimeMillis()); |
| | | redisManager.cacheCommonString(formWX, formWX, 120); |
| | |
| | | case "alipay": //支付宝 |
| | | AlipayTradeQueryResponse res = null; |
| | | try { |
| | | res = AlipayH5PayUtil.queryOrder(PayUtil.getAlipayApp(), id+"" , null); |
| | | res = AlipayH5PayUtil.queryOrder(PayUtil.getAlipayApp(), id + "", null); |
| | | //支付成功 |
| | | if (res.isSuccess() && "TRADE_SUCCESS".equalsIgnoreCase(res.getTradeStatus())) { |
| | | try { |
| | |
| | | } |
| | | case "weChat": //微信 |
| | | try { |
| | | WXPayOrderInfoV3 info = WXPayV3Util.getPayOrderInfo(id+"" , PayUtil.getWXAPP()); |
| | | WXPayOrderInfoV3 info = WXPayV3Util.getPayOrderInfo(id + "", PayUtil.getWXAPP()); |
| | | if (info != null && info.getTrade_state().equalsIgnoreCase("SUCCESS")) { |
| | | paySuccess(order); |
| | | return order; |
| | |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 支付成功更新处理 |
| | | * |
| | | * @param order |
| | | * @return |
| | | */ |
| | |
| | | Integer validDays = vipCombo.getValidDays(); |
| | | |
| | | // 判断订单类型 |
| | | String orderType = OrderTypeEnum.buyNewly.name(); |
| | | OrderTypeEnum orderType = OrderTypeEnum.buyNewly; |
| | | long count = vipOrderMapper.countByTypeAndUid(order.getUid(), orderType); |
| | | if(count > 0) { |
| | | orderType = OrderTypeEnum.buyRenew.name(); |
| | | if (count > 0) { |
| | | orderType = OrderTypeEnum.buyRenew; |
| | | } |
| | | |
| | | // order.setThreeOrderId(); TODO |
| | | order.setState(VipOrder.STATE_PAY); |
| | | order.setPayTime(new Date()); |
| | | order.setUpdateTime(new Date()); |
| | | vipOrderMapper.updateByPrimaryKeySelective(order); |
| | | order.setState(VipOrder.STATE_PAY); |
| | | order.setPayTime(new Date()); |
| | | order.setUpdateTime(new Date()); |
| | | vipOrderMapper.updateByPrimaryKeySelective(order); |
| | | |
| | | // 更新等级 |
| | | vipCenterService.saveVipCenter(order.getUid(), vipCombo.getGradeId(), validDays, order.getId() ); |
| | | // 更新等级 |
| | | vipCenterService.saveVipCenter(order.getUid(), vipCombo.getGradeId(), validDays * 24, order.getId()); |
| | | |
| | | return order; |
| | | } |
| | | return order; |
| | | } |
| | | |
| | | } |