| | |
| | | import com.dsh.account.service.TCourseInfoRecordService; |
| | | import com.dsh.account.service.TStudentService; |
| | | import com.dsh.account.util.*; |
| | | import com.dsh.account.util.wx.WxV3PayConfig; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.StringUtils; |
| | |
| | | CoursePackage coursePackage = coursePackageClient.queryCoursePackageById(lessonId); |
| | | Integer storeId = coursePackage.getStoreId(); |
| | | Store store = storeClient.queryStoreById(storeId); |
| | | // 是否分账 0否1是 |
| | | int isFenZhang= 1; |
| | | String merchantNumber = ""; |
| | | if (store.getOperatorId()==null || store.getOperatorId()==0){ |
| | | // 平台 |
| | | isFenZhang = 0; |
| | | } |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpay("课包续费"+"-"+isFenZhang, "", code, amount.toString(), |
| | | "/base/coursePackage/wechatPaymentCallback", "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); |
| | | TCoursePackagePayment coursePackagePayment = couPayClient.getCoursePackagePaymentByCode(code); |
| | | if (coursePackagePayment.getPayStatus() == 2) { |
| | | break; |
| | | } |
| | | ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryWXOrder(code, ""); |
| | | if (resultUtil.getCode() == 200 && coursePackagePayment.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) { |
| | | coursePackagePayment.setState(3); |
| | | couPayClient.delPaymentCoursePackage(coursePackagePayment.getId()); |
| | | break; |
| | | } |
| | | if ("SUCCESS".equals(s)) { |
| | | coursePackagePayment.setPayStatus(2); |
| | | coursePackagePayment.setTotalClassHours(hour); |
| | | coursePackagePayment.setLaveClassHours(hour); |
| | | coursePackagePayment.setOrderNumber(transaction_id); |
| | | couPayClient.updatePaymentCoursePackage(coursePackagePayment); |
| | | 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()); |
| | | if (isFenZhang == 1) { |
| | | String s2 = storeClient.getmerchantNumberByOperatorId(store.getOperatorId()); |
| | | System.err.println("微信商户号"+s2); |
| | | |
| | | ResultUtil fenzhang = payMoneyUtil.fenzhang(transaction_id, amount.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(); |
| | | } |
| | | } |
| | | }).start(); |
| | | if(!StringUtils.hasLength(s2)){ |
| | | return ResultUtil.error("运营商未配置微信商户号,获取支付失败!"); |
| | | } |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpayV3(s2,"课包续费", |
| | | code,"/base/coursePackage/wechatPaymentCallback1", |
| | | amount.toString()); |
| | | return weixinpay; |
| | | |
| | | }else{ |
| | | ResultUtil weixinpay = payMoneyUtil.weixinpay("课包续费", "", code, amount.toString(), |
| | | "/base/coursePackage/wechatPaymentCallback", "APP", ""); |
| | | |
| | | return weixinpay; |
| | | } |
| | | return weixinpay; |
| | | |
| | | } |
| | | private String smid = "2088330203191220";//平台支付宝商户号 |
| | | public ResultUtil AlipayPayment(String code, BigDecimal amount, Integer hour) { |
| | |
| | | Integer storeId = coursePackage.getStoreId(); |
| | | Store store = storeClient.queryStoreById(storeId); |
| | | String smid1= ""; |
| | | if (store.getOperatorId()==null){ |
| | | if (store.getOperatorId()==null || store.getOperatorId()==0){ |
| | | // 平台 |
| | | smid1 = smid; |
| | | }else{ |
| | | String smidByOperatorId = storeClient.getSMIDByOperatorId(store.getOperatorId()); |
| | | smid1 = smidByOperatorId; |
| | | smid1 = storeClient.getmerchantNumberAliByOperatorId(store.getOperatorId()); |
| | | } |
| | | |
| | | if (!StringUtils.hasLength(smid1)){ |
| | | return ResultUtil.error("运营商未配置支付宝商户号,获取支付失败!"); |
| | | } |
| | | ResultUtil alipay = payMoneyUtil.alipay(smid1,"课包续费", "课包续费", "", code, amount.toString(), |
| | | "/base/coursePackage/alipayPaymentCallback"); |
| | | if (alipay.getCode() == 200) { |
| | |
| | | // 平台 |
| | | smid1 = smid; |
| | | // 属于平台 不做资金冻结 不做分账处理 |
| | | payMoneyUtil.confirm(smid1,code,tradeNo,amount.toString()); |
| | | // payMoneyUtil.confirm(smid1,code,tradeNo,amount.toString()); |
| | | }else{ |
| | | String smidByOperatorId = storeClient.getSMIDByOperatorId(store.getOperatorId()); |
| | | smid1 = smidByOperatorId; |