| | |
| | | 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 GameRecordClient gameRecordClient; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | // 对数据进行分页处理的方法 |
| | |
| | | List<WorldCupPayment> worldCupPayment = worldCupPaymentClinet.getWorldCupPayment(getWorldCupPayment); |
| | | for (WorldCupPayment cupPayment : worldCupPayment) { |
| | | ConsumeDetail consumeDetail = new ConsumeDetail(); |
| | | if(cupPayment.getPayStatus() != 3){ |
| | | if (cupPayment.getPayStatus() != 3) { |
| | | consumeDetail.setConsumeName(RechargeRecordEnum.WORLD_CIP_PAYMENT.getMsg()); |
| | | consumeDetail.setConsumeTime(simpleDateFormat.format(cupPayment.getCreateTime())); |
| | | consumeDetail.setConsumeAmount("-" + cupPayment.getAmount()); |
| | | consumeDetail.setType(2); |
| | | consumeDetail.setDateTime(cupPayment.getPayTime().getTime()); |
| | | details.add(consumeDetail); |
| | | }else{ |
| | | } else { |
| | | consumeDetail = new ConsumeDetail(); |
| | | consumeDetail.setConsumeName(RechargeRecordEnum.WORLD_CIP_PAYMENT.getMsg()); |
| | | consumeDetail.setConsumeTime(simpleDateFormat.format(cupPayment.getCreateTime())); |
| | |
| | | } |
| | | TAppUser tAppUser1 = appUserMapper.selectOne(new LambdaQueryWrapper<TAppUser>() |
| | | .eq(TAppUser::getPhone, dto.getInvitePhone()).eq(TAppUser::getState, 1)); |
| | | if(null == tAppUser1){ |
| | | if (null == tAppUser1) { |
| | | return ResultUtil.error("邀请人还未注册账号"); |
| | | } |
| | | Map<String, String> geocode = null; |
| | |
| | | } |
| | | //查询该用户是否超出限领数量 |
| | | 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); |
| | | //生成支付订单 |
| | |
| | | userCouponPayment.setInsertTime(new Date()); |
| | | |
| | | //积分兑换 |
| | | if(coupon.getRedemptionMethod() == 1){ |
| | | if (coupon.getRedemptionMethod() == 1) { |
| | | UserCoupon userCoupon = new UserCoupon(); |
| | | userCoupon.setCouponId(exchangeType.getGoodId()); |
| | | userCoupon.setUserId(userIdFormRedis); |
| | |
| | | return ResultUtil.success(returnId); |
| | | } |
| | | //积分+现金 |
| | | if(coupon.getRedemptionMethod() == 2){ |
| | | if (coupon.getRedemptionMethod() == 2) { |
| | | userCouponPaymentClient.addUserCouponPayment(userCouponPayment); |
| | | try { |
| | | if(exchangeType.getPayType() == 1){ |
| | | String temp = "0"; |
| | | if (coupon.getPublisherType()!=null && coupon.getPublisherType() != 2){ |
| | | // 做分账 |
| | | temp = "1"; |
| | | } |
| | | return weChatPaymentCoupon("购买优惠券-"+temp, userCouponPayment); |
| | | if (exchangeType.getPayType() == 1) { |
| | | return weChatPaymentCoupon("购买优惠券", userCouponPayment); |
| | | } |
| | | if(exchangeType.getPayType() == 2){ |
| | | if (exchangeType.getPayType() == 2) { |
| | | return aliPaymentCoupon("购买优惠券", userCouponPayment); |
| | | } |
| | | } catch (Exception e) { |
| | |
| | | } |
| | | } |
| | | } |
| | | System.out.println(exchangeType); |
| | | System.out.println("兑换积分商品" + exchangeType); |
| | | try { |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5); |
| | | PointsMerchandise merchandise = new PointsMerchandise(); |
| | | if(exchangeType.getGoodsType() != 4){ |
| | | if (exchangeType.getGoodsType() != 4) { |
| | | merchandise = mcClient.selectPointsMerchandiseById(exchangeType.getGoodId()); |
| | | }else{ |
| | | } else { |
| | | Coupon coupon = ucponClient.queryCouponById(exchangeType.getGoodId()); |
| | | merchandise.setId(coupon.getId()); |
| | | merchandise.setUserPopulation(coupon.getUserPopulation()); |
| | |
| | | pointsMerchandise.setCode(code); |
| | | pointsMerchandise.setInsertTime(new Date()); |
| | | pointsMerchandise.setPayType(exchangeType.getExchangeType()); |
| | | if(null != merchandise.getIntegral()){ |
| | | 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) { |
| | | if ((m * goodsNums) == 0) { |
| | | pointsMerchandise.setPayStatus(2); |
| | | pointsMerchandise.setPaymentTime(new Date()); |
| | | } |
| | | returnId = mcClient.saveDetailsUserPointMercase(pointsMerchandise); |
| | | if((m * goodsNums) == 0 && pointsMerchandise.getPayStatus() == 2){ |
| | | 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,merchandise.getId()); |
| | | } else if (merchandise.getType() == 1){ |
| | | return WechatPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(goodsNums)), code,merchandise.getId()); |
| | | 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,merchandise.getId()); |
| | | 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,merchandise.getId()); |
| | | 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 |
| | | * @param userCouponPayment |
| | | * @return |
| | |
| | | Double cash = userCouponPayment.getCash(); |
| | | Integer couponId = userCouponPayment.getCouponId(); |
| | | Coupon coupon = userConponClient.queryCouponById(couponId); |
| | | String temp ="0"; |
| | | if (coupon.getPublisherType()!=null&&coupon.getPublisherType()!=2){ |
| | | temp = "1"; |
| | | } |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpay(body+"-"+temp, "", 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) { |
| | | List<Integer> couponStoreIds = userConponClient.getCouponStoreIds(couponId); |
| | | System.err.println("购买优惠券"); |
| | | if (coupon != null) { |
| | | if (!couponStoreIds.isEmpty() && !couponStoreIds.contains(-1)) { |
| | | Store store = storeClient.queryStoreById(couponStoreIds.get(0)); |
| | | // 微信商户号 |
| | | String s2 = storeClient.getmerchantNumberByOperatorId(store.getOperatorId()); |
| | | System.err.println("微信商户号" + s2); |
| | | |
| | | 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); |
| | | |
| | | 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); |
| | | } |
| | | // 休眠两分钟后再调用分账接口 避免提示订单正在处理中 |
| | | Thread.sleep(120000); |
| | | if (coupon!=null){ |
| | | if (coupon.getPublisherType()!=null&&coupon.getPublisherType()!=2){ |
| | | if (coupon.getPublisherType() == 3){ |
| | | // 门店 向上查询运营商 |
| | | Store store = storeClient.queryStoreById(coupon.getCityManagerId()); |
| | | if (store.getOperatorId()==null || store.getOperatorId()==0){ |
| | | // 平台不分账 |
| | | break; |
| | | }else{ |
| | | // 根据运营商id获取对应运营商分账比例 返回格式: 微信分账比例,支付宝分账比例 |
| | | String proportionByOperatorId = storeClient.getProportionByOperatorId(store.getOperatorId()); |
| | | String[] split = proportionByOperatorId.split(","); |
| | | String s1 = split[0]; |
| | | if (!s1.equals("未设置")){ |
| | | BigDecimal bigDecimal = new BigDecimal(s1); |
| | | // 分账比例 |
| | | BigDecimal bigDecimal1 = bigDecimal.divide(new BigDecimal(100)).setScale(2); |
| | | // 微信商户号 |
| | | String s2 = storeClient.getmerchantNumberByOperatorId(store.getOperatorId()); |
| | | BigDecimal bigDecimal2 = new BigDecimal(cash); |
| | | ResultUtil fenzhang = payMoneyUtil.fenzhang(userCouponPayment1.getOrderNumber(), bigDecimal2.multiply(bigDecimal1), s2); |
| | | if (!fenzhang.getCode().equals(500)){ |
| | | System.err.println("分账失败 原因是:"+fenzhang.getMsg()); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | if ("USERPAYING".equals(s) || "NOTPAY".equals(s)) { |
| | | num++; |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | if (!StringUtils.hasLength(s2)) { |
| | | return ResultUtil.error("运营商未配置微信商户号,获取支付失败!"); |
| | | } |
| | | }).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("支付失败!"); |
| | | } |
| | | |
| | | |
| | |
| | | * @throws Exception |
| | | */ |
| | | private String smid = "2088330203191220";//平台支付宝商户号 |
| | | |
| | | public ResultUtil aliPaymentCoupon(String body, UserCouponPayment userCouponPayment) throws Exception { |
| | | ResultUtil alipay= ResultUtil.error(""); |
| | | String smidRes = smid;// 结算资金到商户号 |
| | | 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(), |
| | | } else { |
| | | // 支付宝商户号 |
| | | String s2 = storeClient.getmerchantNumberAliByOperatorId(store.getOperatorId()); |
| | | System.err.println("支付宝商户号" + s2); |
| | | |
| | | if (!StringUtils.hasLength(s2)) { |
| | | return ResultUtil.error("运营商未配置支付宝商户号,获取支付失败!"); |
| | | } |
| | | smidRes = s2; |
| | | } |
| | | } |
| | | } |
| | | alipay = payMoneyUtil.alipay(smidRes, body, "",String.valueOf(userCouponPayment.getId()), code, cash.toString(), |
| | | "/base/coupon/aliPaymentCouponCallback"); |
| | | if (alipay.getCode() == 200) { |
| | | String finalSmidRes = smidRes; |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | |
| | | //有待支付的订单,这里不处理 |
| | | userCouponPayment1.setStatus(-1); |
| | | userCouponPaymentClient.updateUserCouponPayment(userCouponPayment1); |
| | | if ("TRADE_FINISHED".equals(s)) { |
| | | // todo 资金结算 |
| | | |
| | | } |
| | | break; |
| | | } |
| | | if ("TRADE_SUCCESS".equals(s)) { |
| | |
| | | user.setIntegral(user.getIntegral() - userCouponPayment1.getIntegral().intValue()); |
| | | appUserService.updateById(user); |
| | | } |
| | | payMoneyUtil.confirm(smid,code,tradeNo,cash.toString()); |
| | | Thread.sleep(30000); |
| | | payMoneyUtil.confirm(finalSmidRes,code,tradeNo,cash.toString()); |
| | | break; |
| | | |
| | | } |
| | | |
| | | if ("WAIT_BUYER_PAY".equals(s)) { |
| | |
| | | |
| | | /** |
| | | * 支付回调 |
| | | * |
| | | * @param code |
| | | * @param orderNumber |
| | | * @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(); |
| | |
| | | userCoupon.setInsertTime(new Date()); |
| | | userConponClient.insertToAppuserCoupon(userCoupon); |
| | | |
| | | if(null != userCouponPayment1.getIntegral() && 0 != userCouponPayment1.getIntegral()){ |
| | | if (null != userCouponPayment1.getIntegral() && 0 != userCouponPayment1.getIntegral()) { |
| | | //扣积分 |
| | | SaveUserIntegralChangesVo vo = new SaveUserIntegralChangesVo(); |
| | | vo.setAppUserId(userCouponPayment1.getUserId()); |
| | |
| | | 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) { |
| | | String name = (type == 1 ? "购买实体商品" : type == 2 ? "报名运动营": type == 3 ? "购买门票" : "购买优惠券"); |
| | | ResultUtil alipay = payMoneyUtil.alipay(smid,name, name, String.valueOf(returnId), code, cash.toString(), |
| | | private ResultUtil AlipayPayment(Integer type, BigDecimal cash, String code, Integer returnId) { |
| | | ResultUtil alipay= ResultUtil.error(""); |
| | | String smidRes = smid;// 结算资金到商户号 |
| | | PointsMerchandise pointsMerchandise = mcClient.selectPointsMerchandiseById(returnId); |
| | | System.err.println("查询积分商品" + pointsMerchandise); |
| | | List<Integer> integers = mcsClient.queryPointMerStoreIds(pointsMerchandise.getId()); |
| | | String name = (type == 1 ? "购买实体商品" : type == 2 ? "报名运动营" : type == 3 ? "购买门票" : "购买优惠券"); |
| | | switch (type) { |
| | | case 1: |
| | | if (!integers.isEmpty()) { |
| | | Store store1 = storeClient.queryStoreById(integers.get(0)); |
| | | if (store1.getOperatorId() == null || store1.getOperatorId() == 0) { |
| | | |
| | | } else { |
| | | String s2 = storeClient.getmerchantNumberAliByOperatorId(store1.getOperatorId()); |
| | | System.err.println("支付宝商户号" + s2); |
| | | |
| | | if (!StringUtils.hasLength(s2)) { |
| | | return ResultUtil.error("运营商未配置支付宝商户号,获取支付失败!"); |
| | | } |
| | | smidRes = s2; |
| | | } |
| | | } |
| | | break; |
| | | case 2: |
| | | // 判断课包属于平台还是运营商 |
| | | CoursePackage coursePackage = cpageClient.queryCoursePackageById(pointsMerchandise.getCoursePackageId()); |
| | | Store store = storeClient.queryStoreById(coursePackage.getStoreId()); |
| | | if (store.getOperatorId() == null || store.getOperatorId() == 0) { |
| | | } else { |
| | | String s2 = storeClient.getmerchantNumberAliByOperatorId(store.getOperatorId()); |
| | | System.err.println("支付宝商户号" + s2); |
| | | |
| | | if (!StringUtils.hasLength(s2)) { |
| | | return ResultUtil.error("运营商未配置支付宝商户号,获取支付失败!"); |
| | | } |
| | | smidRes = s2; |
| | | } |
| | | break; |
| | | case 3: |
| | | if (!integers.isEmpty()) { |
| | | Store store1 = storeClient.queryStoreById(integers.get(0)); |
| | | if (store1.getOperatorId() == null || store1.getOperatorId() == 0) { |
| | | |
| | | } else { |
| | | String s2 = storeClient.getmerchantNumberAliByOperatorId(store1.getOperatorId()); |
| | | System.err.println("支付宝商户号" + s2); |
| | | if (!StringUtils.hasLength(s2)) { |
| | | return ResultUtil.error("运营商未配置支付宝商户号,获取支付失败!"); |
| | | } |
| | | smidRes = s2; |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | alipay = payMoneyUtil.alipay(smidRes, name, name, String.valueOf(returnId), code, cash.toString(), |
| | | "/base/pointMer/exchangeGoodPaymentAliCallback"); |
| | | if (alipay.getCode() == 200) { |
| | | new Thread(new Runnable() { |
| | |
| | | int min = 5000; |
| | | wait += (min * num); |
| | | Thread.sleep(wait); |
| | | System.out.println("code:" + code); |
| | | System.out.println("支付宝查询code:" + code); |
| | | List<UserPointsMerchandise> userPointsMerchandises = mcClient.queryUserPointMerchaseByCode(code); |
| | | System.out.println("list-----" + userPointsMerchandises); |
| | | if (userPointsMerchandises.get(0).getPayStatus() == 2) { |
| | |
| | | userPointsMerchandise.setUserId(null); |
| | | mcClient.updateDetailsUserPointMercase(userPointsMerchandise); |
| | | } |
| | | moneyOut(tradeNo, tradeNo); |
| | | List<Integer> integers = mcsClient.queryPointMerStoreIds(pointsMerchandise.getId()); |
| | | Store store1 = storeClient.queryStoreById(integers.get(0)); |
| | | if (store1.getOperatorId()!=null && store1.getOperatorId() != 0){ |
| | | String s2 = storeClient.getmerchantNumberAliByOperatorId(store1.getOperatorId()); |
| | | System.err.println("查询支付宝商户号"+s2); |
| | | // todo 资金结算 支付宝推荐30s之后再进行结算 |
| | | Thread.sleep(30000); |
| | | payMoneyUtil.confirm(s2,code, tradeNo,cash.toString()); |
| | | } |
| | | 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){ |
| | |
| | | |
| | | List<UserPointsMerchandise> userPointsMerchandises = merChandiseClient.queryUserPointMerchaseByCode(outNum); |
| | | // PaymentCompetition code = paymentCompetitionService.getOne(new QueryWrapper<PaymentCompetition>().eq("code", outNum)); |
| | | if(userPointsMerchandises.size() > 0){ |
| | | if (userPointsMerchandises.size() > 0) { |
| | | Integer storeId = userPointsMerchandises.get(0).getStoreId(); |
| | | |
| | | // Competition byId1 = competitionService.getById(code.getCompetitionId()); |
| | |
| | | } |
| | | |
| | | |
| | | private ResultUtil WechatPayment(Integer type, BigDecimal cash, String code,Integer id) throws Exception { |
| | | String name = (type == 1 ? "购买实体商品" : type == 2 ? "报名运动营": type == 3 ? "购买门票" : "购买优惠券"); |
| | | private ResultUtil WechatPayment(Integer type, BigDecimal cash, String code, Integer id) throws Exception { |
| | | String name = (type == 1 ? "购买实体商品" : type == 2 ? "报名运动营" : type == 3 ? "购买门票" : "购买优惠券"); |
| | | System.err.println("微信支付:" + name); |
| | | |
| | | PointsMerchandise pointsMerchandise = mcClient.selectPointsMerchandiseById(id); |
| | | // 分账表示 0否1是 |
| | | String temp = "0"; |
| | | switch (type){ |
| | | System.err.println("查询积分商品" + pointsMerchandise); |
| | | List<Integer> integers = mcsClient.queryPointMerStoreIds(pointsMerchandise.getId()); |
| | | |
| | | switch (type) { |
| | | case 1: |
| | | temp = "0"; |
| | | 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; |
| | | } |
| | | } |
| | | break; |
| | | case 2: |
| | | // 判断课包属于平台还是运营商 |
| | | CoursePackage coursePackage = cpageClient.queryCoursePackageById(pointsMerchandise.getCoursePackageId()); |
| | | Store store = storeClient.queryStoreById(coursePackage.getStoreId()); |
| | | if (store.getOperatorId() ==null || store.getOperatorId() == 0){ |
| | | // 平台课包 不分账 |
| | | }else{ |
| | | temp = "1"; |
| | | 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; |
| | | } |
| | | break; |
| | | case 3: |
| | | List<Integer> integers = mcsClient.queryPointMerStoreIds(pointsMerchandise.getId()); |
| | | if (!integers.isEmpty()){ |
| | | if (!integers.isEmpty()) { |
| | | Store store1 = storeClient.queryStoreById(integers.get(0)); |
| | | if (store1.getOperatorId() ==null || store1.getOperatorId() == 0){ |
| | | // 平台门票 不分账 |
| | | }else{ |
| | | temp = "1"; |
| | | } |
| | | } |
| | | // 查询门票指定的门店 属于平台还是运营商 |
| | | break; |
| | | } |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpay(name+"-"+temp, "", 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) { |
| | | 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); |
| | | |
| | | |
| | | 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.setPaymentTime(new Date()); |
| | | userPointsMerchandise.setOrderNumber(transaction_id); |
| | | userPointsMerchandise.setCashPayType(1); |
| | | mcClient.updateDetailsUserPointMercase(userPointsMerchandise); |
| | | |
| | | TAppUser tAppUser = baseMapper.selectById(userPointsMerchandise.getUserId()); |
| | | dealAppUserIntegral(userPointsMerchandise.getUserId(), tAppUser, userPointsMerchandise.getIntegral()); |
| | | |
| | | //课程 |
| | | if(type == 2){ |
| | | CoursePackageOrder coursePackageOrder1 = paymentClient.getCoursePackageOrderByCode(code); |
| | | if(null != coursePackageOrder1){ |
| | | coursePackageOrder1.setPayStatus(2); |
| | | coursePackageOrder1.setOrderNumber(transaction_id); |
| | | coursePackageOrder1.setAppUserId(null); |
| | | paymentClient.updateCoursePackageOrder(coursePackageOrder1); |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | // 休眠两分钟后再调用分账接口 避免提示订单正在处理中 |
| | | Thread.sleep(120000); |
| | | // 分账表示 0否1是 |
| | | String temp = "0"; |
| | | // 运营商id |
| | | Integer operatorId = 0; |
| | | switch (type){ |
| | | case 1: |
| | | temp = "0"; |
| | | break; |
| | | case 2: |
| | | // 判断课包属于平台还是运营商 |
| | | CoursePackage coursePackage = cpageClient.queryCoursePackageById(pointsMerchandise.getCoursePackageId()); |
| | | Store store = storeClient.queryStoreById(coursePackage.getStoreId()); |
| | | if (store.getOperatorId() ==null || store.getOperatorId() == 0){ |
| | | // 平台课包 不分账 |
| | | }else{ |
| | | temp = "1"; |
| | | operatorId = store.getOperatorId(); |
| | | } |
| | | break; |
| | | case 3: |
| | | List<Integer> integers = mcsClient.queryPointMerStoreIds(pointsMerchandise.getId()); |
| | | if (!integers.isEmpty()){ |
| | | Store store1 = storeClient.queryStoreById(integers.get(0)); |
| | | if (store1.getOperatorId() ==null || store1.getOperatorId() == 0){ |
| | | // 平台门票 不分账 |
| | | }else{ |
| | | temp = "1"; |
| | | operatorId = store1.getOperatorId(); |
| | | } |
| | | } |
| | | // 查询门票指定的门店 属于平台还是运营商 |
| | | break; |
| | | } |
| | | if (operatorId != 0) { |
| | | // 根据运营商id获取对应运营商分账比例 返回格式: 微信分账比例,支付宝分账比例 |
| | | String proportionByOperatorId = storeClient.getProportionByOperatorId(operatorId); |
| | | String[] split = proportionByOperatorId.split(","); |
| | | String s1 = split[0]; |
| | | if (!s1.equals("未设置")){ |
| | | BigDecimal bigDecimal = new BigDecimal(s1); |
| | | // 分账比例 |
| | | BigDecimal bigDecimal1 = bigDecimal.divide(new BigDecimal(100)).setScale(2); |
| | | // 微信商户号 |
| | | String s2 = storeClient.getmerchantNumberByOperatorId(operatorId); |
| | | |
| | | ResultUtil fenzhang = payMoneyUtil.fenzhang(transaction_id, cash.multiply(bigDecimal1), s2); |
| | | if (!fenzhang.getCode().equals(500)){ |
| | | System.err.println("分账失败 原因是:"+fenzhang.getMsg()); |
| | | } |
| | | } |
| | | } |
| | | 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; |
| | | } |
| | | } else { |
| | | // 平台门票 |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpay(name, "", code, cash.toString(), |
| | | "/base/pointMer/exchangeGoodPaymentWeChatCallback", "APP", ""); |
| | | return weixinpay; |
| | | |
| | | } |
| | | }).start(); |
| | | } |
| | | return weixinpay; |
| | | |
| | | return ResultUtil.error("支付失败"); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public ResultUtil exchangeAddPaymentCallback(String code, String orderNumber) { |
| | | public ResultUtil exchangeAddPaymentCallback(String code, String orderNumber) throws AlipayApiException { |
| | | System.err.println("进入回调" + code); |
| | | UserPointsMerchandise userPointsMerchandise = mcClient.queryUserPointMerchaseByCode(code).get(0); |
| | | System.err.println("商品" + userPointsMerchandise); |
| | | if (userPointsMerchandise.getPayStatus() == 2) { |
| | | return ResultUtil.success(); |
| | | } |
| | |
| | | |
| | | Integer pointsMerchandiseId = userPointsMerchandise.getPointsMerchandiseId(); |
| | | PointsMerchandise pointsMerchandise = mcClient.selectPointsMerchandiseById(pointsMerchandiseId); |
| | | if(pointsMerchandise.getType() == 2){ |
| | | if (pointsMerchandise.getType() == 2) { |
| | | //课程 |
| | | CoursePackageOrder coursePackageOrder1 = paymentClient.getCoursePackageOrderByCode(code); |
| | | if(null != coursePackageOrder1){ |
| | | if (null != coursePackageOrder1) { |
| | | coursePackageOrder1.setPayStatus(2); |
| | | coursePackageOrder1.setOrderNumber(orderNumber); |
| | | coursePackageOrder1.setAppUserId(null); |
| | |
| | | paymentClient.addCoursePackageOrderStudent(addCoursePackageOrderStudent); |
| | | } |
| | | } |
| | | |
| | | List<Integer> integers = mcsClient.queryPointMerStoreIds(pointsMerchandise.getId()); |
| | | Store store1 = storeClient.queryStoreById(integers.get(0)); |
| | | if (store1.getOperatorId() != null && store1.getOperatorId() != 0) { |
| | | String s2 = storeClient.getmerchantNumberAliByOperatorId(store1.getOperatorId()); |
| | | System.err.println("支付宝商户号" + s2); |
| | | payMoneyUtil.confirm(s2, code, orderNumber, userPointsMerchandise.getCash().toString()); |
| | | } |
| | | return ResultUtil.success(); |
| | | } |
| | | |