| | |
| | | import com.dsh.account.service.UserIntegralChangesService; |
| | | import com.dsh.account.util.*; |
| | | import com.dsh.account.util.akeylogin.Md5Util; |
| | | import com.dsh.account.util.wx.WxV3PayConfig; |
| | | import com.dsh.account.vo.GroupCityInfoVO; |
| | | import com.dsh.account.vo.entity.DayData; |
| | | import com.dsh.account.vo.entity.MonthData; |
| | |
| | | @Resource |
| | | private UserConponClient ucponClient; |
| | | |
| | | |
| | | @Resource |
| | | private CoursePackageClient cpageClient; |
| | | |
| | |
| | | |
| | | @Resource |
| | | private IntroduceRewardsClient introduceRewardsClient; |
| | | |
| | | |
| | | private String aliAppid = "2021004105665036";//支付宝appid |
| | | |
| | |
| | | } |
| | | //查询该用户是否超出限领数量 |
| | | Integer usercounts = userConponClient.queryCounts1(queryIds); |
| | | |
| | | if (usercounts == coupon.getPickUpQuantity()) { |
| | | return new ResultUtil<>(0, "限领数量已达最大"); |
| | | } |
| | | |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5); |
| | | //生成支付订单 |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | System.out.println(exchangeType); |
| | | System.out.println("兑换积分商品"+exchangeType); |
| | | try { |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5); |
| | |
| | | if(null != merchandise.getIntegral()){ |
| | | pointsMerchandise.setIntegral(merchandise.getIntegral() * goodsNums); |
| | | } |
| | | if(exchangeType.getExchangeType() == 2){ |
| | | if(exchangeType.getExchangeType() == 2 || exchangeType.getExchangeType() == 3){ |
| | | pointsMerchandise.setCash(merchandise.getCash()); |
| | | pointsMerchandise.setCashPayType(exchangeType.getPayType()); |
| | | } |
| | | |
| | | Double m = new BigDecimal((merchandise.getIntegral() == null ? 0 : merchandise.getIntegral())).add((merchandise.getCash() == null ? BigDecimal.ZERO : merchandise.getCash())).doubleValue(); |
| | | if((m * goodsNums) == 0) { |
| | | pointsMerchandise.setPayStatus(2); |
| | | pointsMerchandise.setPaymentTime(new Date()); |
| | | } |
| | | returnId = mcClient.saveDetailsUserPointMercase(pointsMerchandise); |
| | | if((m * goodsNums) == 0 && pointsMerchandise.getPayStatus() == 2){ |
| | | returnModel.setReturnId(returnId); |
| | | return ResultUtil.success(returnModel); |
| | | } |
| | | |
| | | |
| | | System.err.println("兑换方式"+exchangeType); |
| | | switch (exchangeType.getExchangeType()) { |
| | | // 积分 |
| | | case 1: |
| | |
| | | coursePackageOrder.setInsertTime(new Date()); |
| | | coursePackageOrder.setOrderType(2); |
| | | paymentClient.savePaymentCoursePackage(coursePackageOrder); |
| | | return WechatPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(exchangeType.getStuIds().size())), code); |
| | | } else { |
| | | return WechatPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(goodsNums)), code); |
| | | return WechatPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(exchangeType.getStuIds().size())), code,merchandise.getId()); |
| | | } else if (merchandise.getType() == 1){ |
| | | return WechatPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(goodsNums)), code,merchandise.getId()); |
| | | }else if(merchandise.getType() == 3){ |
| | | return WechatPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(goodsNums)), code,merchandise.getId()); |
| | | } |
| | | } catch (Exception e) { |
| | | return ResultUtil.runErr(); |
| | | } |
| | | case 2: |
| | | if (merchandise.getType() == 2) { |
| | | return AlipayPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(exchangeType.getStuIds().size())), code, returnId); |
| | | return AlipayPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(exchangeType.getStuIds().size())), code, merchandise.getId()); |
| | | } else { |
| | | return AlipayPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(goodsNums)), code, returnId); |
| | | return AlipayPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(goodsNums)), code, merchandise.getId()); |
| | | } |
| | | default: |
| | | break; |
| | |
| | | case 1: |
| | | try { |
| | | if (merchandise.getType() == 2) { |
| | | return WechatPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(exchangeType.getStuIds().size())), code); |
| | | return WechatPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(exchangeType.getStuIds().size())), code,merchandise.getId()); |
| | | } else { |
| | | return WechatPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(goodsNums)), code); |
| | | return WechatPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(goodsNums)), code,merchandise.getId()); |
| | | } |
| | | } catch (Exception e) { |
| | | return ResultUtil.runErr(); |
| | | } |
| | | case 2: |
| | | if (merchandise.getType() == 2) { |
| | | return AlipayPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(exchangeType.getStuIds().size())), code, returnId); |
| | | return AlipayPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(exchangeType.getStuIds().size())), code, merchandise.getId()); |
| | | } else { |
| | | return AlipayPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(goodsNums)), code, returnId); |
| | | return AlipayPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(goodsNums)), code, merchandise.getId()); |
| | | } |
| | | default: |
| | | break; |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 优惠券微信支付 |
| | | * @param body |
| | |
| | | public ResultUtil weChatPaymentCoupon(String body, UserCouponPayment userCouponPayment) throws Exception { |
| | | String code = userCouponPayment.getCode(); |
| | | Double cash = userCouponPayment.getCash(); |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpay(body, "", code, cash.toString(), |
| | | "/base/coupon/weChatPaymentCouponCallback", "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); |
| | | Thread.sleep(wait); |
| | | UserCouponPayment userCouponPayment1 = userCouponPaymentClient.getUserCouponPayment(code); |
| | | if (userCouponPayment1.getStatus() == 2) { |
| | | break; |
| | | } |
| | | ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryWXOrder(code, ""); |
| | | if (resultUtil.getCode() == 200 && userCouponPayment1.getStatus() == 1) { |
| | | /** |
| | | * SUCCESS—支付成功, |
| | | * REFUND—转入退款, |
| | | * NOTPAY—未支付, |
| | | * CLOSED—已关闭, |
| | | * REVOKED—已撤销(刷卡支付), |
| | | * USERPAYING--用户支付中, |
| | | * PAYERROR--支付失败(其他原因,如银行返回失败) |
| | | */ |
| | | Map<String, String> data1 = resultUtil.getData(); |
| | | String s = data1.get("trade_state"); |
| | | String transaction_id = data1.get("transaction_id"); |
| | | if ("REFUND".equals(s) || "CLOSED".equals(s) || "REVOKED".equals(s) || "PAYERROR".equals(s) || num == 10) { |
| | | //有待支付的订单,这里不处理 |
| | | userCouponPayment1.setStatus(-1); |
| | | userCouponPaymentClient.updateUserCouponPayment(userCouponPayment1); |
| | | break; |
| | | } |
| | | if ("SUCCESS".equals(s)) { |
| | | userCouponPayment1.setStatus(2); |
| | | userCouponPayment1.setPaymentTime(new Date()); |
| | | userCouponPayment1.setOrderNumber(transaction_id); |
| | | userCouponPaymentClient.updateUserCouponPayment(userCouponPayment1); |
| | | Integer couponId = userCouponPayment.getCouponId(); |
| | | Coupon coupon = userConponClient.queryCouponById(couponId); |
| | | List<Integer> couponStoreIds = userConponClient.getCouponStoreIds(couponId); |
| | | System.err.println("购买优惠券"); |
| | | if (coupon!=null){ |
| | | if (!couponStoreIds.isEmpty()&&!couponStoreIds.contains(-1)){ |
| | | // 微信商户号 |
| | | String s2 = storeClient.getmerchantNumberByOperatorId(coupon.getCityManagerId()); |
| | | System.err.println("微信商户号"+s2); |
| | | |
| | | UserCoupon userCoupon = new UserCoupon(); |
| | | userCoupon.setCouponId(userCouponPayment1.getCouponId()); |
| | | userCoupon.setUserId(userCouponPayment1.getUserId()); |
| | | userCoupon.setStatus(1); |
| | | userCoupon.setInsertTime(new Date()); |
| | | userConponClient.insertToAppuserCoupon(userCoupon); |
| | | |
| | | if(null != userCouponPayment1.getIntegral() && 0 != userCouponPayment1.getIntegral()){ |
| | | //扣积分 |
| | | TAppUser user = appUserService.getById(userCouponPayment1.getUserId()); |
| | | user.setIntegral(user.getIntegral() - userCouponPayment1.getIntegral().intValue()); |
| | | appUserService.updateById(user); |
| | | } |
| | | break; |
| | | } |
| | | if ("USERPAYING".equals(s) || "NOTPAY".equals(s)) { |
| | | num++; |
| | | } |
| | | } |
| | | if(!StringUtils.hasLength(s2)){ |
| | | return ResultUtil.error("运营商未配置微信商户号,获取支付失败!"); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }).start(); |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpayV3(s2,"购买优惠券", |
| | | code,"/base/coupon/weChatPaymentCouponCallback1", |
| | | cash.toString()); |
| | | return weixinpay; |
| | | |
| | | }else{ |
| | | // 平台发布 |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpay(body, "", code, cash.toString(), |
| | | "/base/coupon/weChatPaymentCouponCallback", "APP", ""); |
| | | return weixinpay; |
| | | } |
| | | } |
| | | return weixinpay; |
| | | |
| | | return ResultUtil.error("支付失败!"); |
| | | } |
| | | |
| | | |
| | |
| | | public ResultUtil aliPaymentCoupon(String body, UserCouponPayment userCouponPayment) throws Exception { |
| | | String code = userCouponPayment.getCode(); |
| | | Double cash = userCouponPayment.getCash(); |
| | | Integer couponId = userCouponPayment.getCouponId(); |
| | | Coupon coupon = userConponClient.queryCouponById(couponId); |
| | | List<Integer> couponStoreIds = userConponClient.getCouponStoreIds(couponId); |
| | | if (coupon!=null){ |
| | | if (!couponStoreIds.isEmpty()&&!couponStoreIds.contains(-1)){ |
| | | // 门店 向上查询运营商 |
| | | Store store = storeClient.queryStoreById(couponStoreIds.get(0)); |
| | | if (store.getOperatorId()==null || store.getOperatorId()==0){ |
| | | // 平台 |
| | | ResultUtil alipay = payMoneyUtil.alipay(smid, body, "",String.valueOf(userCouponPayment.getId()), code, cash.toString(), |
| | | "/base/coupon/aliPaymentCouponCallback"); |
| | | return alipay; |
| | | }else{ |
| | | // 支付宝商户号 |
| | | String s2 = storeClient.getmerchantNumberAliByOperatorId(store.getOperatorId()); |
| | | System.err.println("支付宝商户号"+s2); |
| | | |
| | | ResultUtil alipay = payMoneyUtil.alipay(smid, body, "",String.valueOf(userCouponPayment.getId()), code, cash.toString(), |
| | | "/base/coupon/aliPaymentCouponCallback"); |
| | | if (alipay.getCode() == 200) { |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | Thread.sleep(1000); |
| | | |
| | | int num = 1; |
| | | int wait = 0; |
| | | while (num <= 10) { |
| | | int min = 5000; |
| | | wait += (min * num); |
| | | Thread.sleep(wait); |
| | | UserCouponPayment userCouponPayment1 = userCouponPaymentClient.getUserCouponPayment(code); |
| | | if (userCouponPayment1.getStatus() == 2) { |
| | | break; |
| | | } |
| | | AlipayTradeQueryResponse alipayTradeQueryResponse = payMoneyUtil.queryALIOrder(code); |
| | | if (null != alipayTradeQueryResponse) { |
| | | /** |
| | | * WAIT_BUYER_PAY(交易创建,等待买家付款)、 |
| | | * TRADE_CLOSED(未付款交易超时关闭,或支付完成后全额退款)、 |
| | | * TRADE_SUCCESS(交易支付成功)、 |
| | | * TRADE_FINISHED(交易结束,不可退款) |
| | | */ |
| | | String s = alipayTradeQueryResponse.getTradeStatus(); |
| | | |
| | | String tradeNo = alipayTradeQueryResponse.getTradeNo(); |
| | | if ("TRADE_CLOSED".equals(s) || "TRADE_FINISHED".equals(s) || num == 10) { |
| | | //有待支付的订单,这里不处理 |
| | | userCouponPayment1.setStatus(-1); |
| | | userCouponPaymentClient.updateUserCouponPayment(userCouponPayment1); |
| | | if ("TRADE_FINISHED".equals(s)) { |
| | | // todo 资金结算 |
| | | |
| | | } |
| | | break; |
| | | } |
| | | if ("TRADE_SUCCESS".equals(s)) { |
| | | userCouponPayment1.setStatus(2); |
| | | userCouponPayment1.setPaymentTime(new Date()); |
| | | userCouponPayment1.setOrderNumber(tradeNo); |
| | | userCouponPaymentClient.updateUserCouponPayment(userCouponPayment1); |
| | | UserCoupon userCoupon = new UserCoupon(); |
| | | userCoupon.setCouponId(userCouponPayment1.getCouponId()); |
| | | userCoupon.setUserId(userCouponPayment1.getUserId()); |
| | | userCoupon.setStatus(1); |
| | | userCoupon.setInsertTime(new Date()); |
| | | userConponClient.insertToAppuserCoupon(userCoupon); |
| | | if(null != userCouponPayment1.getIntegral() && 0 != userCouponPayment1.getIntegral()){ |
| | | //扣积分 |
| | | TAppUser user = appUserService.getById(userCouponPayment1.getUserId()); |
| | | user.setIntegral(user.getIntegral() - userCouponPayment1.getIntegral().intValue()); |
| | | appUserService.updateById(user); |
| | | } |
| | | payMoneyUtil.confirm(smid,code,tradeNo,cash.toString()); |
| | | break; |
| | | |
| | | } |
| | | |
| | | if ("WAIT_BUYER_PAY".equals(s)) { |
| | | num++; |
| | | } |
| | | } |
| | | if(!StringUtils.hasLength(s2)){ |
| | | return ResultUtil.error("运营商未配置支付宝商户号,获取支付失败!"); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | ResultUtil alipay = payMoneyUtil.alipay(s2, body, "",String.valueOf(userCouponPayment.getId()), code, cash.toString(), |
| | | "/base/coupon/aliPaymentCouponCallback"); |
| | | return alipay; |
| | | } |
| | | } |
| | | }).start(); |
| | | }else { |
| | | // 平台发布 |
| | | ResultUtil alipay = payMoneyUtil.alipay(smid, body, "",String.valueOf(userCouponPayment.getId()), code, cash.toString(), |
| | | "/base/coupon/aliPaymentCouponCallback"); |
| | | return alipay; |
| | | } |
| | | } |
| | | return alipay; |
| | | // ResultUtil alipay = payMoneyUtil.alipay(smid, body, "",String.valueOf(userCouponPayment.getId()), code, cash.toString(), |
| | | // "/base/coupon/aliPaymentCouponCallback"); |
| | | // if (alipay.getCode() == 200) { |
| | | // new Thread(new Runnable() { |
| | | // @Override |
| | | // public void run() { |
| | | // try { |
| | | // Thread.sleep(1000); |
| | | // |
| | | // int num = 1; |
| | | // int wait = 0; |
| | | // while (num <= 10) { |
| | | // int min = 5000; |
| | | // wait += (min * num); |
| | | // Thread.sleep(wait); |
| | | // UserCouponPayment userCouponPayment1 = userCouponPaymentClient.getUserCouponPayment(code); |
| | | // if (userCouponPayment1.getStatus() == 2) { |
| | | // break; |
| | | // } |
| | | // AlipayTradeQueryResponse alipayTradeQueryResponse = payMoneyUtil.queryALIOrder(code); |
| | | // if (null != alipayTradeQueryResponse) { |
| | | // /** |
| | | // * WAIT_BUYER_PAY(交易创建,等待买家付款)、 |
| | | // * TRADE_CLOSED(未付款交易超时关闭,或支付完成后全额退款)、 |
| | | // * TRADE_SUCCESS(交易支付成功)、 |
| | | // * TRADE_FINISHED(交易结束,不可退款) |
| | | // */ |
| | | // String s = alipayTradeQueryResponse.getTradeStatus(); |
| | | // |
| | | // String tradeNo = alipayTradeQueryResponse.getTradeNo(); |
| | | // if ("TRADE_CLOSED".equals(s) || "TRADE_FINISHED".equals(s) || num == 10) { |
| | | // //有待支付的订单,这里不处理 |
| | | // userCouponPayment1.setStatus(-1); |
| | | // userCouponPaymentClient.updateUserCouponPayment(userCouponPayment1); |
| | | // if ("TRADE_FINISHED".equals(s)) { |
| | | // // todo 资金结算 |
| | | // |
| | | // } |
| | | // break; |
| | | // } |
| | | // if ("TRADE_SUCCESS".equals(s)) { |
| | | // userCouponPayment1.setStatus(2); |
| | | // userCouponPayment1.setPaymentTime(new Date()); |
| | | // userCouponPayment1.setOrderNumber(tradeNo); |
| | | // userCouponPaymentClient.updateUserCouponPayment(userCouponPayment1); |
| | | // UserCoupon userCoupon = new UserCoupon(); |
| | | // userCoupon.setCouponId(userCouponPayment1.getCouponId()); |
| | | // userCoupon.setUserId(userCouponPayment1.getUserId()); |
| | | // userCoupon.setStatus(1); |
| | | // userCoupon.setInsertTime(new Date()); |
| | | // userConponClient.insertToAppuserCoupon(userCoupon); |
| | | // if(null != userCouponPayment1.getIntegral() && 0 != userCouponPayment1.getIntegral()){ |
| | | // //扣积分 |
| | | // TAppUser user = appUserService.getById(userCouponPayment1.getUserId()); |
| | | // user.setIntegral(user.getIntegral() - userCouponPayment1.getIntegral().intValue()); |
| | | // appUserService.updateById(user); |
| | | // } |
| | | //// payMoneyUtil.confirm(smid,code,tradeNo,cash.toString()); |
| | | // break; |
| | | // |
| | | // } |
| | | // |
| | | // if ("WAIT_BUYER_PAY".equals(s)) { |
| | | // num++; |
| | | // } |
| | | // } |
| | | // } |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // } |
| | | // }).start(); |
| | | // } |
| | | return ResultUtil.error("支付失败"); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ResultUtil paymentCouponCallback(String code, String orderNumber) { |
| | | public ResultUtil paymentCouponCallback(String code, String orderNumber) throws Exception { |
| | | System.err.println("进入回调"); |
| | | UserCouponPayment userCouponPayment1 = userCouponPaymentClient.getUserCouponPayment(code); |
| | | if (userCouponPayment1.getStatus() == 2) { |
| | | return ResultUtil.success(); |
| | |
| | | vo.setRemark("兑换优惠券"); |
| | | vo.setType(2); |
| | | userIntegralChangesService.saveUserIntegralChanges(vo); |
| | | |
| | | } |
| | | Coupon coupon = ucponClient.queryCouponById(userCouponPayment1.getCouponId()); |
| | | // 创建一个两分钟后执行的线程 |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | private ResultUtil AlipayPayment(Integer type, BigDecimal cash, String code, Long returnId) { |
| | | private ResultUtil AlipayPayment(Integer type, BigDecimal cash, String code, Integer returnId) { |
| | | PointsMerchandise pointsMerchandise = mcClient.selectPointsMerchandiseById(returnId); |
| | | System.err.println("查询积分商品"+pointsMerchandise); |
| | | List<Integer> integers = mcsClient.queryPointMerStoreIds(pointsMerchandise.getId()); |
| | | String name = (type == 1 ? "购买实体商品" : type == 2 ? "报名运动营": type == 3 ? "购买门票" : "购买优惠券"); |
| | | ResultUtil alipay = payMoneyUtil.alipay(smid,name, name, String.valueOf(returnId), code, cash.toString(), |
| | | "/base/pointMer/exchangeGoodPaymentAliCallback"); |
| | | if (alipay.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); |
| | | Thread.sleep(wait); |
| | | System.out.println("code:" + code); |
| | | List<UserPointsMerchandise> userPointsMerchandises = mcClient.queryUserPointMerchaseByCode(code); |
| | | System.out.println("list-----" + userPointsMerchandises); |
| | | if (userPointsMerchandises.get(0).getPayStatus() == 2) { |
| | | break; |
| | | } |
| | | // ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryALIOrder(code); |
| | | AlipayTradeQueryResponse resultUtil = payMoneyUtil.queryALIOrder(code); |
| | | if (resultUtil.getCode().equals("10000") && userPointsMerchandises.get(0).getPayStatus() == 1) { |
| | | /** |
| | | * WAIT_BUYER_PAY(交易创建,等待买家付款)、 |
| | | * TRADE_CLOSED(未付款交易超时关闭,或支付完成后全额退款)、 |
| | | * TRADE_SUCCESS(交易支付成功)、 |
| | | * TRADE_FINISHED(交易结束,不可退款) |
| | | */ |
| | | // Map<String, String> data1 = resultUtil.getData(); |
| | | // String s = data1.get("tradeStatus"); |
| | | // String tradeNo = data1.get("tradeNo"); |
| | | switch (type) { |
| | | case 1: |
| | | if (!integers.isEmpty()) { |
| | | Store store1 = storeClient.queryStoreById(integers.get(0)); |
| | | if (store1.getOperatorId() == null || store1.getOperatorId() == 0) { |
| | | // 平台门票 |
| | | ResultUtil alipay = payMoneyUtil.alipay(smid, name, name, String.valueOf(returnId), code, cash.toString(), |
| | | "/base/pointMer/exchangeGoodPaymentAliCallback"); |
| | | return alipay; |
| | | } else { |
| | | String s2 = storeClient.getmerchantNumberAliByOperatorId(store1.getOperatorId()); |
| | | System.err.println("支付宝商户号" + s2); |
| | | |
| | | String tradeNo = resultUtil.getTradeNo(); |
| | | String tradeStatus = resultUtil.getTradeStatus(); |
| | | System.out.println("ssssss" + tradeStatus); |
| | | |
| | | if ("TRADE_SUCCESS".equals(tradeStatus)) { |
| | | for (UserPointsMerchandise userPointsMerchandise : userPointsMerchandises) { |
| | | userPointsMerchandise.setPayStatus(2); |
| | | userPointsMerchandise.setOrderNumber(tradeNo); |
| | | userPointsMerchandise.setPayType(2); |
| | | userPointsMerchandise.setInsertTime(null); |
| | | userPointsMerchandise.setUserId(null); |
| | | mcClient.updateDetailsUserPointMercase(userPointsMerchandise); |
| | | } |
| | | moneyOut(tradeNo, tradeNo); |
| | | break; |
| | | } |
| | | if ("TRADE_FINISHED".equals(tradeStatus)) { |
| | | // todo 资金结算 |
| | | payMoneyUtil.confirm(smid,code,tradeNo,cash.toString()); |
| | | break; |
| | | } |
| | | // if("REFUND".equals(tradeStatus) || "NOTPAY".equals(tradeStatus) || "CLOSED".equals(tradeStatus) || "REVOKED".equals(tradeStatus) || "PAYERROR".equals(tradeStatus) || num == 10){ |
| | | // mcClient.deletePaymentRecord(code); |
| | | // break; |
| | | // } |
| | | |
| | | if ("WAIT_BUYER_PAY".equals(tradeStatus)) { |
| | | num++; |
| | | } |
| | | } |
| | | if (!StringUtils.hasLength(s2)) { |
| | | return ResultUtil.error("运营商未配置支付宝商户号,获取支付失败!"); |
| | | } |
| | | } catch (Exception e) { |
| | | mcClient.deletePaymentRecord(code); |
| | | e.printStackTrace(); |
| | | ResultUtil alipay = payMoneyUtil.alipay(s2, name, name, String.valueOf(returnId), code, cash.toString(), |
| | | "/base/pointMer/exchangeGoodPaymentAliCallback"); |
| | | return alipay; |
| | | } |
| | | }else{ |
| | | // 平台门票 |
| | | ResultUtil alipay = payMoneyUtil.alipay(smid, name, name, String.valueOf(returnId), code, cash.toString(), |
| | | "/base/pointMer/exchangeGoodPaymentAliCallback"); |
| | | return alipay; |
| | | |
| | | } |
| | | }).start(); |
| | | } |
| | | return alipay; |
| | | case 2: |
| | | // 判断课包属于平台还是运营商 |
| | | CoursePackage coursePackage = cpageClient.queryCoursePackageById(pointsMerchandise.getCoursePackageId()); |
| | | Store store = storeClient.queryStoreById(coursePackage.getStoreId()); |
| | | if (store.getOperatorId() == null || store.getOperatorId() == 0) { |
| | | // 平台课包 |
| | | ResultUtil alipay = payMoneyUtil.alipay(smid, name, name, String.valueOf(returnId), code, cash.toString(), |
| | | "/base/pointMer/exchangeGoodPaymentAliCallback"); |
| | | return alipay; |
| | | } else { |
| | | String s2 = storeClient.getmerchantNumberAliByOperatorId(store.getOperatorId()); |
| | | System.err.println("支付宝商户号" + s2); |
| | | |
| | | if (!StringUtils.hasLength(s2)) { |
| | | return ResultUtil.error("运营商未配置支付宝商户号,获取支付失败!"); |
| | | } |
| | | ResultUtil alipay = payMoneyUtil.alipay(s2, name, name, String.valueOf(returnId), code, cash.toString(), |
| | | "/base/pointMer/exchangeGoodPaymentAliCallback"); |
| | | return alipay; |
| | | } |
| | | case 3: |
| | | if (!integers.isEmpty()) { |
| | | Store store1 = storeClient.queryStoreById(integers.get(0)); |
| | | if (store1.getOperatorId() == null || store1.getOperatorId() == 0) { |
| | | // 平台门票 |
| | | ResultUtil alipay = payMoneyUtil.alipay(smid, name, name, String.valueOf(returnId), code, cash.toString(), |
| | | "/base/pointMer/exchangeGoodPaymentAliCallback"); |
| | | return alipay; |
| | | } else { |
| | | String s2 = storeClient.getmerchantNumberAliByOperatorId(store1.getOperatorId()); |
| | | System.err.println("支付宝商户号" + s2); |
| | | if (!StringUtils.hasLength(s2)) { |
| | | return ResultUtil.error("运营商未配置支付宝商户号,获取支付失败!"); |
| | | } |
| | | ResultUtil alipay = payMoneyUtil.alipay(s2, name, name, String.valueOf(returnId), code, cash.toString(), |
| | | "/base/pointMer/exchangeGoodPaymentAliCallback"); |
| | | return alipay; |
| | | } |
| | | }else{ |
| | | // 平台门票 |
| | | ResultUtil alipay = payMoneyUtil.alipay(smid, name, name, String.valueOf(returnId), code, cash.toString(), |
| | | "/base/pointMer/exchangeGoodPaymentAliCallback"); |
| | | return alipay; |
| | | } |
| | | } |
| | | return ResultUtil.error("获取支付失败!"); |
| | | |
| | | } |
| | | |
| | | public void moneyOut(String outNum, String tradeNo) throws AlipayApiException { |
| | |
| | | } |
| | | |
| | | |
| | | private ResultUtil WechatPayment(Integer type, BigDecimal cash, String code) throws Exception { |
| | | private ResultUtil WechatPayment(Integer type, BigDecimal cash, String code,Integer id) throws Exception { |
| | | String name = (type == 1 ? "购买实体商品" : type == 2 ? "报名运动营": type == 3 ? "购买门票" : "购买优惠券"); |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpay(name, "", code, cash.toString(), |
| | | "/base/pointMer/exchangeGoodPaymentWeChatCallback", "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); |
| | | Thread.sleep(wait); |
| | | UserPointsMerchandise userPointsMerchandise = mcClient.queryUserPointMerchaseByCode(code).get(0); |
| | | if (userPointsMerchandise.getPayStatus() == 2) { |
| | | break; |
| | | } |
| | | ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryWXOrder(code, ""); |
| | | if (resultUtil.getCode() == 200 && userPointsMerchandise.getPayStatus() == 1) { |
| | | /** |
| | | * SUCCESS—支付成功, |
| | | * REFUND—转入退款, |
| | | * NOTPAY—未支付, |
| | | * CLOSED—已关闭, |
| | | * REVOKED—已撤销(刷卡支付), |
| | | * USERPAYING--用户支付中, |
| | | * PAYERROR--支付失败(其他原因,如银行返回失败) |
| | | */ |
| | | Map<String, String> data1 = resultUtil.getData(); |
| | | String s = data1.get("trade_state"); |
| | | String transaction_id = data1.get("transaction_id"); |
| | | if ("REFUND".equals(s) || "CLOSED".equals(s) || "REVOKED".equals(s) || "PAYERROR".equals(s) || num == 10) { |
| | | mcClient.deletePaymentRecord(code); |
| | | break; |
| | | } |
| | | if ("SUCCESS".equals(s)) { |
| | | userPointsMerchandise.setPayStatus(2); |
| | | userPointsMerchandise.setOrderNumber(transaction_id); |
| | | userPointsMerchandise.setPayType(1); |
| | | mcClient.updateDetailsUserPointMercase(userPointsMerchandise); |
| | | System.err.println("微信支付:"+name); |
| | | |
| | | TAppUser tAppUser = baseMapper.selectById(userPointsMerchandise.getUserId()); |
| | | dealAppUserIntegral(userPointsMerchandise.getUserId(), tAppUser, userPointsMerchandise.getIntegral()); |
| | | PointsMerchandise pointsMerchandise = mcClient.selectPointsMerchandiseById(id); |
| | | System.err.println("查询积分商品"+pointsMerchandise); |
| | | List<Integer> integers = mcsClient.queryPointMerStoreIds(pointsMerchandise.getId()); |
| | | |
| | | //课程 |
| | | if(type == 2){ |
| | | CoursePackageOrder coursePackageOrder1 = paymentClient.getCoursePackageOrderByCode(code); |
| | | if(null != coursePackageOrder1){ |
| | | coursePackageOrder1.setPayStatus(2); |
| | | coursePackageOrder1.setOrderNumber(transaction_id); |
| | | coursePackageOrder1.setAppUserId(null); |
| | | paymentClient.updateCoursePackageOrder(coursePackageOrder1); |
| | | switch (type){ |
| | | case 1: |
| | | if (!integers.isEmpty()){ |
| | | Store store1 = storeClient.queryStoreById(integers.get(0)); |
| | | if (store1.getOperatorId() ==null || store1.getOperatorId() == 0){ |
| | | // 平台门票 |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpay(name, "", code, cash.toString(), |
| | | "/base/pointMer/exchangeGoodPaymentWeChatCallback", "APP", ""); |
| | | return weixinpay; |
| | | }else{ |
| | | String s2 = storeClient.getmerchantNumberByOperatorId(store1.getOperatorId()); |
| | | System.err.println("微信商户号"+s2); |
| | | |
| | | GetCoursePackagePaymentConfig getCoursePackagePaymentConfig = new GetCoursePackagePaymentConfig(); |
| | | getCoursePackagePaymentConfig.setCoursePackageId(coursePackageOrder1.getCoursePackageId()); |
| | | getCoursePackagePaymentConfig.setClassHours(coursePackageOrder1.getClassHours()); |
| | | CoursePackagePaymentConfig coursePackagePaymentConfig = paymentClient.getCoursePackagePaymentConfig(getCoursePackagePaymentConfig); |
| | | |
| | | AddCoursePackageOrderStudent addCoursePackageOrderStudent = new AddCoursePackageOrderStudent(); |
| | | addCoursePackageOrderStudent.setCoursePackageOrderId(coursePackageOrder1.getId()); |
| | | addCoursePackageOrderStudent.setCoursePackagePaymentConfig(coursePackagePaymentConfig); |
| | | paymentClient.addCoursePackageOrderStudent(addCoursePackageOrderStudent); |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | if ("USERPAYING".equals(s) || "NOTPAY".equals(s)) { |
| | | num++; |
| | | } |
| | | } |
| | | if(!StringUtils.hasLength(s2)){ |
| | | return ResultUtil.error("运营商未配置微信商户号,获取支付失败!"); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpayV3(s2,name, code, |
| | | "/base/pointMer/exchangeGoodPaymentWeChatCallback1", |
| | | cash.toString()); |
| | | return weixinpay; |
| | | } |
| | | } |
| | | }).start(); |
| | | break; |
| | | case 2: |
| | | // 判断课包属于平台还是运营商 |
| | | CoursePackage coursePackage = cpageClient.queryCoursePackageById(pointsMerchandise.getCoursePackageId()); |
| | | Store store = storeClient.queryStoreById(coursePackage.getStoreId()); |
| | | if (store.getOperatorId() ==null || store.getOperatorId() == 0){ |
| | | // 平台课包 |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpay(name, "", code, cash.toString(), |
| | | "/base/pointMer/exchangeGoodPaymentWeChatCallback", "APP", ""); |
| | | return weixinpay; |
| | | }else{ |
| | | String s2 = storeClient.getmerchantNumberByOperatorId(store.getOperatorId()); |
| | | System.err.println("微信商户号"+s2); |
| | | |
| | | if(!StringUtils.hasLength(s2)){ |
| | | return ResultUtil.error("运营商未配置微信商户号,获取支付失败!"); |
| | | } |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpayV3(s2,name, code, |
| | | "/base/pointMer/exchangeGoodPaymentWeChatCallback1", |
| | | cash.toString()); |
| | | return weixinpay; |
| | | } |
| | | case 3: |
| | | if (!integers.isEmpty()){ |
| | | Store store1 = storeClient.queryStoreById(integers.get(0)); |
| | | if (store1.getOperatorId() ==null || store1.getOperatorId() == 0){ |
| | | // 平台门票 |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpay(name, "", code, cash.toString(), |
| | | "/base/pointMer/exchangeGoodPaymentWeChatCallback", "APP", ""); |
| | | return weixinpay; |
| | | }else{ |
| | | String s2 = storeClient.getmerchantNumberByOperatorId(store1.getOperatorId()); |
| | | System.err.println("微信商户号"+s2); |
| | | |
| | | if(!StringUtils.hasLength(s2)){ |
| | | return ResultUtil.error("运营商未配置微信商户号,获取支付失败!"); |
| | | } |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpayV3(s2,name, code, |
| | | "/base/pointMer/exchangeGoodPaymentWeChatCallback1", |
| | | cash.toString()); |
| | | return weixinpay; |
| | | } |
| | | }else{ |
| | | // 平台门票 |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpay(name, "", code, cash.toString(), |
| | | "/base/pointMer/exchangeGoodPaymentWeChatCallback", "APP", ""); |
| | | return weixinpay; |
| | | |
| | | } |
| | | } |
| | | return weixinpay; |
| | | |
| | | return ResultUtil.error("支付失败"); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public ResultUtil exchangeAddPaymentCallback(String code, String orderNumber) { |
| | | System.err.println("进入回调"+code); |
| | | UserPointsMerchandise userPointsMerchandise = mcClient.queryUserPointMerchaseByCode(code).get(0); |
| | | System.err.println("商品"+userPointsMerchandise); |
| | | if (userPointsMerchandise.getPayStatus() == 2) { |
| | | return ResultUtil.success(); |
| | | } |
| | |
| | | paymentClient.addCoursePackageOrderStudent(addCoursePackageOrderStudent); |
| | | } |
| | | } |
| | | |
| | | return ResultUtil.success(); |
| | | } |
| | | |