| | |
| | | import com.dsh.account.util.PayMoneyUtil; |
| | | import com.dsh.account.util.RedisUtil; |
| | | import com.dsh.account.util.ResultUtil; |
| | | import com.dsh.account.util.wx.WxV3PayConfig; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.StringUtils; |
| | |
| | | String code = vipPayment.getCode(); |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpay("购买年度会员", "", code, vipPayment.getAmount().toString(), |
| | | "/base/appUser/addVipPaymentWeChatCallback", "APP", ""); |
| | | if (weixinpay.getCode() == 200) { |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | int num = 1; |
| | | int wait = 0; |
| | | while (num <= 10) { |
| | | int min = 5000; |
| | | wait += (min * num); |
| | | VipPayment vipPayment1 = VipPaymentServiceImpl.this.getOne(new QueryWrapper<VipPayment>().eq("code", code)); |
| | | if (vipPayment1.getPayStatus() == 2) { |
| | | return; |
| | | } |
| | | /** |
| | | * SUCCESS--支付成功 |
| | | * REFUND--转入退款 |
| | | * NOTPAY--未支付 |
| | | * CLOSED--已关闭 |
| | | * REVOKED--已撤销(刷卡支付) |
| | | * USERPAYING--用户支付中 |
| | | * PAYERROR--支付失败(其他原因,如银行返回失败) |
| | | * ACCEPT--已接收,等待扣款 |
| | | */ |
| | | ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryWXOrder(code, ""); |
| | | if (resultUtil.getCode() == 200) { |
| | | Map<String, String> map = resultUtil.getData(); |
| | | String trade_type = map.get("trade_type"); |
| | | String trade_state = map.get("trade_state"); |
| | | String transaction_id = map.get("transaction_id"); |
| | | if ("REFUND".equals(trade_state) || "NOTPAY".equals(trade_state) || "CLOSED".equals(trade_state) || "REVOKED".equals(trade_state) || "PAYERROR".equals(trade_state)) { |
| | | vipPayment1.setState(3); |
| | | VipPaymentServiceImpl.this.updateById(vipPayment1); |
| | | return; |
| | | } |
| | | if ("SUCCESS".equals(trade_state)) { |
| | | vipPayment1.setPayStatus(2); |
| | | vipPayment1.setPayTime(new Date()); |
| | | vipPayment1.setOrderNumber(transaction_id); |
| | | VipPaymentServiceImpl.this.updateById(vipPayment1); |
| | | TAppUser appUser = appUserService.getById(vipPayment1.getAppUserId()); |
| | | Date vipEndTime = appUser.getVipEndTime(); |
| | | if (null == vipEndTime) { |
| | | vipEndTime = new Date(); |
| | | } |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(vipEndTime); |
| | | calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) + 1); |
| | | appUser.setIsVip(1); |
| | | appUser.setVipEndTime(calendar.getTime()); |
| | | appUserService.updateById(appUser); |
| | | // 注册会员送券 先判断是否有注册送券类型的优惠券 判断优惠券状态 审核是否通过 是否删除 是否在有效期内 是否领取数量达上限 |
| | | List<Long> longs = userConponClient.queryCouponByUser(appUser.getId()); |
| | | redisUtil.setStrValue("VIP_P_" + vipPayment1.getAppUserId(), JSON.toJSONString(longs), 3600); |
| | | return; |
| | | } |
| | | if ("USERPAYING".equals(trade_state) || "ACCEPT".equals(trade_state)) { |
| | | Thread.sleep(wait); |
| | | num++; |
| | | } |
| | | } else { |
| | | Thread.sleep(wait); |
| | | num++; |
| | | } |
| | | if (10 == num) { |
| | | vipPayment1.setState(3); |
| | | VipPaymentServiceImpl.this.updateById(vipPayment1); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }).start(); |
| | | } |
| | | // ResultUtil weixinpay = payMoneyUtil.weixinpayV3(WxV3PayConfig.smidVx,"购买年度会员", |
| | | // code,"/base/appUser/addVipPaymentWeChatCallback1", |
| | | // Long.valueOf(vipPayment.getAmount().toString())); |
| | | return weixinpay; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 支付宝 |
| | |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | private String smid = "2088330203191220";//平台支付宝商户号 |
| | | public ResultUtil alipay(VipPayment vipPayment) throws Exception { |
| | | String code = vipPayment.getCode(); |
| | | ResultUtil alipay = payMoneyUtil.alipay("购买年度会员", "购买年度会员", vipPayment.getAppUserId() + "", code, vipPayment.getAmount().toString(), |
| | | String amount = vipPayment.getAmount().toString(); |
| | | ResultUtil alipay = payMoneyUtil.alipay |
| | | (smid,"购买年度会员", "购买年度会员", |
| | | vipPayment.getAppUserId() + "", |
| | | code, vipPayment.getAmount().toString(), |
| | | "/base/appUser/addVipPaymentAliCallback"); |
| | | if (alipay.getCode() == 200) { |
| | | new Thread(new Runnable() { |
| | |
| | | AlipayTradeQueryResponse resultUtil = payMoneyUtil.queryALIOrder(code); |
| | | |
| | | if (resultUtil.getCode().equals("10000")) { |
| | | // Map<String, String> map = resultUtil.getData(); |
| | | // String tradeStatus = map.get("tradeStatus"); |
| | | // String tradeNo = map.get("tradeNo"); |
| | | |
| | | String tradeNo = resultUtil.getTradeNo(); |
| | | String tradeStatus = resultUtil.getTradeStatus(); |
| | | System.out.println("ssssss" + tradeStatus); |
| | | if ("TRADE_CLOSED".equals(tradeStatus) || "TRADE_FINISHED".equals(tradeStatus)) { |
| | | vipPayment1.setState(3); |
| | | VipPaymentServiceImpl.this.updateById(vipPayment1); |
| | | |
| | | return; |
| | | } |
| | | if ("TRADE_SUCCESS".equals(tradeStatus)) { |
| | |
| | | // 注册会员送券 先判断是否有注册送券类型的优惠券 判断优惠券状态 审核是否通过 是否删除 是否在有效期内 是否领取数量达上限 |
| | | List<Long> longs = userConponClient.queryCouponByUser(appUser.getId()); |
| | | redisUtil.setStrValue("VIP_P_" + vipPayment1.getAppUserId(), JSON.toJSONString(longs), 3600); |
| | | // 如果交易结束 将当前订单金额分配到商户 |
| | | // payMoneyUtil.confirm(smid,vipPayment.getCode(),tradeNo,amount); |
| | | return; |
| | | } |
| | | if ("WAIT_BUYER_PAY".equals(tradeStatus)) { |
| | |
| | | VipPaymentServiceImpl.this.updateById(vipPayment1); |
| | | |
| | | TAppUser appUser = appUserService.getById(vipPayment1.getAppUserId()); |
| | | Date vipEndTime = appUser.getVipEndTime(); |
| | | if (null == vipEndTime) { |
| | | vipEndTime = new Date(); |
| | | } |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(new Date()); |
| | | calendar.setTime(vipEndTime); |
| | | calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) + 1); |
| | | appUser.setIsVip(1); |
| | | appUser.setVipEndTime(calendar.getTime()); |
| | | appUserService.updateById(appUser); |
| | | // 注册会员送券 先判断是否有注册送券类型的优惠券 判断优惠券状态 审核是否通过 是否删除 是否在有效期内 是否领取数量达上限 |