| | |
| | | |
| | | @Override |
| | | public ResultUtil ContinuationOrpaymentCourse(Integer userId, ClasspaymentRequest request) { |
| | | System.err.println("请求参数"+request); |
| | | AppUser appUser = appuClient.queryAppUser(userId); |
| | | CoursePackageOrder coursePackageOrder = coursePackageOrderService.getById(request.getCoursePayId()); |
| | | System.err.println("上次支付记录"+coursePackageOrder); |
| | | String code = ""; |
| | | BigDecimal money = coursePackageOrder.getCashPayment(); |
| | | Integer wpGold = coursePackageOrder.getPlayPaiCoin(); |
| | | BigDecimal money = BigDecimal.valueOf(request.getCash()); |
| | | Integer wpGold = request.getPlayPaiCoin(); |
| | | if (coursePackageOrder.getPayStatus() == 1) { |
| | | code = coursePackageOrder.getCode(); |
| | | coursePackageOrder.setPayType(request.getPayType()); |
| | |
| | | CoursePackagePaymentConfig paymentConfig = cpConfigMapper.selectOne(new QueryWrapper<CoursePackagePaymentConfig>() |
| | | .eq("coursePackageId", request.getLessonId()) |
| | | .eq("classHours", request.getCourseHoursNum())); |
| | | System.err.println("价格配置"+paymentConfig); |
| | | TCoursePackageDiscount coursePackageDiscount = tcpdMapper.selectOne(new QueryWrapper<TCoursePackageDiscount>() |
| | | .eq("coursePackageId", request.getLessonId()) |
| | | .eq("type", 2) |
| | | .eq("auditStatus", 1) |
| | | .eq("coursePackagePaymentConfigId", paymentConfig.getCoursePackageId())); |
| | | System.err.println("折扣"+coursePackageDiscount); |
| | | if (ToolUtil.isNotEmpty(coursePackageDiscount)) { |
| | | String content = coursePackageDiscount.getContent(); |
| | | JSONObject jsonObject = JSON.parseObject(content); |
| | |
| | | newPayment.setAppUserId(appUser.getId()); |
| | | newPayment.setStudentIds(request.getStuId().toString()); |
| | | newPayment.setCoursePackageId(request.getLessonId()); |
| | | newPayment.setClassHours(coursePackageOrder.getClassHours()); |
| | | newPayment.setClassHours(request.getCourseHoursNum()); |
| | | newPayment.setOriginalPrice(coursePackageOrder.getOriginalPrice()); |
| | | if (request.getUseConpon() == 1) { |
| | | newPayment.setUserCouponId(Long.valueOf(request.getUseConpon())); |
| | |
| | | newPayment.setPayType(request.getPayType()); |
| | | newPayment.setState(1); |
| | | newPayment.setInsertTime(new Date()); |
| | | if (request.getCash()!=null && request.getCash()!=0){ |
| | | newPayment.setCashPayment(BigDecimal.valueOf(request.getCash())); |
| | | } |
| | | newPayment.setPlayPaiCoin(request.getPlayPaiCoin()); |
| | | newPayment.setOrderType(1); |
| | | newPayment.setUserCouponId(request.getConponId()); |
| | | coursePackageOrderService.save(newPayment); |
| | | code = newPayment.getCode(); |
| | | } |
| | | System.err.println("选择"); |
| | | switch (request.getPayType()) { |
| | | case 1: |
| | | if (request.getUseConpon() == 1) { |
| | | Coupon coupon = client.queryCouponById(request.getConponId()); |
| | | if (coupon.getType() == 1) { |
| | | Map<String, Object> couponRules = client.getCouponRules(coupon.getId()); |
| | | Double conditionalAmount = (Double) couponRules.get("conditionalAmount"); |
| | | Double deductionAmount = (Double) couponRules.get("deductionAmount"); |
| | | if (money.compareTo(BigDecimal.valueOf(conditionalAmount)) >= 0) { |
| | | money = BigDecimal.valueOf(deductionAmount); |
| | | } |
| | | } |
| | | if (coupon.getType() == 2) { |
| | | Map<String, Object> couponRules = client.getCouponRules(coupon.getId()); |
| | | Object amount = couponRules.get("deductionAmount"); |
| | | money = BigDecimal.valueOf((Double) amount); |
| | | } |
| | | Integer coupon1 = client.queryUserCouponById(request.getConponId()); |
| | | System.err.println("优惠券id"+coupon1); |
| | | Coupon coupon = client.queryCouponById(coupon1); |
| | | System.err.println("优惠券信息"+coupon); |
| | | // if (coupon.getType() == 1) { |
| | | // Map<String, Object> couponRules = client.getCouponRules(coupon.getId()); |
| | | // Double conditionalAmount = (Double) couponRules.get("conditionalAmount"); |
| | | // Double deductionAmount = (Double) couponRules.get("deductionAmount"); |
| | | // if (money.compareTo(BigDecimal.valueOf(conditionalAmount)) >= 0) { |
| | | // money = BigDecimal.valueOf(deductionAmount); |
| | | // } |
| | | // } |
| | | // if (coupon.getType() == 2) { |
| | | // Map<String, Object> couponRules = client.getCouponRules(coupon.getId()); |
| | | // System.err.println("优惠券规则"+couponRules); |
| | | // Object amount = couponRules.get("conditionalAmount"); |
| | | // money = BigDecimal.valueOf((Double) amount); |
| | | // } |
| | | } |
| | | try { |
| | | return WeChatPayment(code, money); |
| | | return WeChatPayment(code, money,request.getLessonId()); |
| | | } catch (Exception e) { |
| | | return ResultUtil.runErr(); |
| | | } |
| | | case 2: |
| | | if (request.getUseConpon() == 1) { |
| | | Coupon coupon = client.queryCouponById(request.getConponId()); |
| | | Integer coupon1 = client.queryUserCouponById(request.getConponId()); |
| | | Coupon coupon = client.queryCouponById(coupon1); |
| | | if (coupon.getType() == 1) { |
| | | Map<String, Object> couponRules = client.getCouponRules(coupon.getId()); |
| | | Double conditionalAmount = (Double) couponRules.get("conditionalAmount"); |
| | |
| | | money = BigDecimal.valueOf((Double) amount); |
| | | } |
| | | } |
| | | |
| | | return AlipayPayment(code, money); |
| | | case 3: |
| | | System.err.println("选择"); |
| | | PlaypaiGoldPayment(appUser, code, wpGold); |
| | | break; |
| | | default: |
| | |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | |
| | | public ResultUtil WeChatPayment(String code, BigDecimal request) throws Exception { |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpay("课包续费", "", code, request.toString(), |
| | | public ResultUtil WeChatPayment(String code, BigDecimal request,Integer coursePackageId) throws Exception { |
| | | System.err.println("code-------------"+code); |
| | | System.err.println("request---------------"+request); |
| | | System.err.println("coursePackageId-------------"+coursePackageId); |
| | | TCoursePackage byId = coursePackageService.getById(coursePackageId); |
| | | System.err.println("课包"+coursePackageId); |
| | | Integer storeId = byId.getStoreId(); |
| | | Store store = storeClient.queryStoreById(storeId); |
| | | System.err.println("门店查询"+store); |
| | | // 是否分账 0否1是 |
| | | int isFenZhang= 1; |
| | | String merchantNumber = ""; |
| | | if (store.getOperatorId()==null || store.getOperatorId()==0){ |
| | | // 平台 |
| | | isFenZhang = 0; |
| | | } |
| | | System.err.println("拉起支付"); |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpay("课包续费"+"-"+isFenZhang, "", code, request.toString(), |
| | | "/base/coursePackage/wechatRegisteredCoursesCallback", "APP", ""); |
| | | if (weixinpay.getCode() == 200) { |
| | | String finalCode = code; |
| | |
| | | .eq("classHours", coursePackageOrder1.getClassHours()) |
| | | ); |
| | | coursePackageService.addCoursePackageOrderStudent(coursePackageOrder1.getId(), coursePackagePaymentConfig); |
| | | |
| | | break; |
| | | } |
| | | if ("USERPAYING".equals(s) || "NOTPAY".equals(s)) { |
| | |
| | | } |
| | | private String smid = "2088330203191220";//平台支付宝商户号 |
| | | |
| | | // public static void main(String[] args) { |
| | | // BigDecimal bigDecimal = new BigDecimal("100"); |
| | | // |
| | | // |
| | | // String s = "1"; |
| | | // double v = Double.parseDouble(s); |
| | | // double v1 = v * 0.01; |
| | | // |
| | | // BigDecimal bigDecimal1 = new BigDecimal(String.valueOf(v1)); |
| | | // BigDecimal multiply = bigDecimal1.multiply(bigDecimal); |
| | | // System.err.println(v); |
| | | // System.err.println(v1); |
| | | // System.err.println(multiply); |
| | | // } |
| | | public ResultUtil AlipayPayment(String code, BigDecimal request) { |
| | | // 二级商户商户号 |
| | | String smidUser; |
| | | TCoursePackagePaymentMapper baseMapper1 = this.baseMapper; |
| | | TCoursePackagePayment coursePackagePayment = baseMapper1.getCoursePackagePaymentByCode(code); |
| | | // 判断这个课包属于哪个门店 属于哪个运营商 根据运营商 id 获取对应的商户号 |
| | |
| | | TCoursePackage byId = coursePackageService.getById(coursePackageId); |
| | | Store store = storeClient.queryStoreById(byId.getStoreId()); |
| | | if (store.getOperatorId() == null ){ |
| | | // 说明是平台的门店 |
| | | payMoneyUtil.confirm(smid,code,tradeNo,request.toString()); |
| | | // 说明是平台的门店 无需冻结资金 不走分账 |
| | | payMoneyUtil.confirm1(smid,code,tradeNo,request.toString()); |
| | | }else if (store.getOperatorId() == 0){ |
| | | payMoneyUtil.confirm(smid,code,tradeNo,request.toString()); |
| | | // 说明是平台的门店 |
| | | payMoneyUtil.confirm1(smid,code,tradeNo,request.toString()); |
| | | // 发起分账 |
| | | extracted(store, coursePackageOrder1, tradeNo); |
| | | }else{ |
| | | String smid = storeClient.getSMIDByOperatorId(store.getOperatorId()); |
| | | payMoneyUtil.confirm(smid,code,tradeNo,request.toString()); |
| | | payMoneyUtil.confirm(storeClient.getSMIDByOperatorId(store.getOperatorId()),code,tradeNo,request.toString()); |
| | | // 发起分账 |
| | | extracted(store, coursePackageOrder1, tradeNo); |
| | | } |
| | | break; |
| | | } |
| | |
| | | return alipay; |
| | | } |
| | | |
| | | private void extracted(Store store, CoursePackageOrder coursePackageOrder1, String tradeNo) throws Exception { |
| | | // 分账 |
| | | AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", |
| | | "2021004105665036", |
| | | "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCi5i9nW/hGLJ3A06cZxTQdviFC7THpdSihoTYGLr9q006hu0V26ecBMY/o4w5bvIX0Ok/yofmZsVcCJpAPvbXL/uqVrIjnRRxXiaeBFThlxoBUTdunvbUSDYfzlEhJr5NvUKI6H6lz2niXlQGx4qy8Hau4ccWit9kM8jwUvsBVQoFgJA+xrjMvooA7YLopQtpOD+UJr5thApTSf1xrnr1W12yolTLEH15JmNV372cqXrYUuqnY0QsaPtxeqJUGAOcGdVLllQ7easEznP8DFBvDdHATcmp2SHNQDUEWN6MCVPbMgY06NQVqAXxqjTAYSVh+6TRu6bofPmpYC3TZB003AgMBAAECggEBAJAcR2+PA3NBYUYHeFrqBRMS8uX8ZR19kjZ7IgoSLTFaQsP9opRylPSPXhrPVBKAE5leRQAHn4MCSlESwHvMfxo7KFjFTFAc6dffZZpipYQUOc9bGampwJh58/3e/pyBgVMG6J23CPf/HJQtNFSkjd/V9+ayb/9l2dUEL3bC0fAZ/dbx8HsxdLw8wn3fLlWLj68hOMqa2deCZe3JdSVsPbeWqkh56FFsM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Nc9OsLtDL1bEQ8gC1dHkj8Wy5z0mkaOsjJRIG/28ze12M0V8jdCKuuDr5Z1OPKiqf+XO3ypguEh+mYUVMBM/cZodDFQfTY1TKLWjvQCuaqlA+QUTCK6f7T7stsgyQ1o9Jj0rXZDz6PM4QHSTzjrLIBaeqM5WIBvH+fy/X+QG5Utd+/UT0kc0JyvuKhZ65yVUd/C9VcwJJAPliRsAQNrqYterwAJ9zvw9tF11wj9W0XgJ8Ccu4x3gR1vrlLRJJo/OA97RmxPQ+5hSacWQZCUd1dwiBq+YCrKVHGTj14izRHXrLc0yBlRXo7tBOIqcy3IsvKVthQIDAQAB", |
| | | "RSA2"); |
| | | AlipayTradeOrderSettleRequest request = new AlipayTradeOrderSettleRequest(); |
| | | String randomCode = UUIDUtil.getRandomCode(16); |
| | | String proportionByOperatorId = storeClient.getProportionByOperatorId(store.getOperatorId()); |
| | | // 支付宝分账比例 |
| | | String s1 = proportionByOperatorId.split(",")[1]; |
| | | double i = Double.parseDouble(s1); |
| | | double v = i * 0.01; |
| | | BigDecimal bigDecimal1 = new BigDecimal(String.valueOf(v)); |
| | | BigDecimal cashPayment = coursePackageOrder1.getCashPayment(); |
| | | // 分账金额 |
| | | BigDecimal bigDecimal2 = cashPayment.multiply(bigDecimal1).setScale(2, RoundingMode.DOWN); |
| | | request.setBizContent("{" + |
| | | " \"out_request_no\":\"" + randomCode + "\"," + |
| | | " \"trade_no\":\"" + tradeNo + "\"," + |
| | | " \"royalty_parameters\":[" + |
| | | " {" + |
| | | " \"royalty_type\":\"transfer\"," + |
| | | " \"trans_out\":\"" + storeClient.getSMIDByOperatorId(store.getOperatorId()) + "\"," + |
| | | " \"trans_out_type\":\"userId\"," + |
| | | " \"trans_in_type\":\"userId\"," + |
| | | " \"trans_in\":\"" + smid + "\"," + |
| | | " \"amount\":" + bigDecimal2 + "," + |
| | | " \"desc\":\"平台服务费\"," + |
| | | " \"royalty_scene\":\"平台服务费\"," + |
| | | " }" + |
| | | " ]," + |
| | | " \"extend_params\":{" + |
| | | " \"royalty_finish\":\"true\"" + |
| | | " }," + |
| | | " \"royalty_mode\":\"async\"" + |
| | | "}"); |
| | | AlipayTradeOrderSettleResponse response = alipayClient.execute(request); |
| | | if (response.isSuccess()) { |
| | | System.out.println("调用成功"); |
| | | } else { |
| | | System.out.println("调用失败"); |
| | | } |
| | | } |
| | | |
| | | public ResultUtil PlaypaiGoldPayment(AppUser appUser, String code, Integer wpGold) { |
| | | TCoursePackagePayment packagePayment = this.baseMapper.selectOne(new QueryWrapper<TCoursePackagePayment>() |
| | | System.err.println("进入玩湃支付"); |
| | | CoursePackageOrder packagePayment = coursePackageOrderService.getOne(new QueryWrapper<CoursePackageOrder>() |
| | | .eq("code", code)); |
| | | System.err.println("支付"+packagePayment); |
| | | System.err.println("用户信息"+appUser); |
| | | System.err.println("code"+code); |
| | | System.err.println("wpGold"+wpGold); |
| | | if (appUser.getPlayPaiCoins() < wpGold) { |
| | | return ResultUtil.error("玩湃币不足!"); |
| | | } |
| | | packagePayment.setPayStatus(2); |
| | | packagePayment.setPayUserId(appUser.getId()); |
| | | packagePayment.setPlayPaiCoin(wpGold); |
| | | this.baseMapper.updateById(packagePayment); |
| | | System.err.println("扣去玩湃币"); |
| | | try { |
| | | System.err.println("修改"); |
| | | boolean b = coursePackageOrderService.updateById(packagePayment); |
| | | |
| | | }catch (Exception e){ |
| | | System.err.println("报错"+e.getCause()); |
| | | System.err.println("报错"+e.getMessage()); |
| | | e.printStackTrace(); |
| | | } |
| | | appUser.setPlayPaiCoins(ToolUtil.isNotEmpty(appUser.getPlayPaiCoins()) ? appUser.getPlayPaiCoins() - wpGold : wpGold); |
| | | |
| | | appuClient.updateAppUser(appUser); |
| | | return ResultUtil.success(); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public ResultUtil insertVipPaymentCallback(String code, String orderNumber) { |
| | | public ResultUtil insertVipPaymentCallback(String code, String orderNumber) throws Exception { |
| | | CoursePackageOrder coursePackageOrder1 = coursePackageOrderService.getOne(new QueryWrapper<CoursePackageOrder>() |
| | | .eq("code", code).eq("state", 1)); |
| | | if (coursePackageOrder1.getPayStatus() == 2) { |
| | |
| | | .eq("classHours", coursePackageOrder1.getClassHours()) |
| | | ); |
| | | coursePackageService.addCoursePackageOrderStudent(coursePackageOrder1.getId(), coursePackagePaymentConfig); |
| | | try { |
| | | coursePackageService.moneyOut(orderNumber,orderNumber,code); |
| | | } catch (AlipayApiException e) { |
| | | e.printStackTrace(); |
| | | TCoursePackage byId = coursePackageService.getById(coursePackageOrder1.getCoursePackageId()); |
| | | Integer storeId = byId.getStoreId(); |
| | | Store store = storeClient.queryStoreById(storeId); |
| | | |
| | | if (store.getOperatorId()!=null && store.getOperatorId()!=0){ |
| | | // 休眠两分钟后再调用分账接口 避免提示订单正在处理中 |
| | | Thread.sleep(120000); |
| | | // 根据运营商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()); |
| | | String nonce_str = UUIDUtil.getRandomCode(16); |
| | | |
| | | ResultUtil fenzhang = payMoneyUtil.fenzhang(orderNumber, coursePackageOrder1.getCashPayment().multiply(bigDecimal1), s2,nonce_str); |
| | | if (!fenzhang.getCode().equals(200)){ |
| | | System.err.println("分账失败 原因是:"+fenzhang.getData()); |
| | | } |
| | | } |
| | | } |
| | | return ResultUtil.success(); |
| | | } |
| | |
| | | @Autowired |
| | | private TCoursePackageService packageService; |
| | | |
| | | |
| | | @Autowired |
| | | private TCoursePackagePaymentService packagePaymentService; |
| | | @Autowired |
| | | private CoursePackageStudentService coursePackageStudentService; |
| | | |