| | |
| | | "}"; |
| | | |
| | | String authorization = getAuthorization(body); |
| | | System.err.println("支付请求"+body); |
| | | org.apache.http.HttpResponse response = post(LakalaConfig.getServerUrl() + apiPath, body, authorization); |
| | | if (response.getStatusLine().getStatusCode() != 200) { |
| | | return R.fail(500, "请求失败,statusCode " + response.getStatusLine() |
| | | + IOUtils.toString(response.getEntity().getContent(), ENCODING)); |
| | | } |
| | | String responseStr = IOUtils.toString(response.getEntity().getContent(), ENCODING); |
| | | System.err.println("支付结果"+responseStr); |
| | | |
| | | |
| | | erpProcurement.setPayNumber(outTradeNo); |
| | |
| | | map.put("merchant_no", erpProcurement.getMerchantNo()); |
| | | map.put("log_no", erpProcurement.getPayTransactionId()); |
| | | map.put("log_date", DateUtils.dateTime()); |
| | | map.put("cal_type", "0"); |
| | | map.put("notify_url", "http://221.182.45.100:8089/t-sys-order/messageSeparateHandle"); |
| | | String time = DateUtils.dateTimeNow(); |
| | | |
| | |
| | | // 平台应得分账 |
| | | BigDecimal payMoney = erpProcurement.getMoney(); |
| | | ArrayList<HashMap<String, Object>> objects = new ArrayList<>(); |
| | | // 根据供应商id分组 |
| | | Map<String, List<TErpProcurementGoods>> collect = list.stream().collect(Collectors.groupingBy(TErpProcurementGoods::getSupplierId)); |
| | | // for (Map.Entry<String, List<TErpProcurementGoods>> entry : collect.entrySet()) { |
| | | // HashMap<String, Object> map1 = new HashMap<>(); |
| | | // String supplierId = entry.getKey(); |
| | | // TCrmSupplier supplier = crmSupplierService.getById(supplierId); |
| | | // List<TErpProcurementGoods> value = entry.getValue(); |
| | | // BigDecimal reduce = value.stream().map(TErpProcurementGoods::getSupplierMoney).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // payMoney = payMoney.subtract(reduce); |
| | | // map1.put("recv_no", supplier.getRecvMerchantNo()); |
| | | // map1.put("separate_value", reduce.multiply(BigDecimal.valueOf(100)).intValue() + ""); |
| | | //// objects.add(map1); |
| | | // } |
| | | |
| | | HashMap<String, Object> map1 = new HashMap<>(); |
| | | //TODO hzt |
| | | map1.put("recv_no", "SR2024000006413"); |
| | | map1.put("recv_no", "SR2024017174604"); |
| | | // 手续费 |
| | | BigDecimal bigDecimal = allMoney.multiply(new BigDecimal("0.038")).setScale(2, RoundingMode.HALF_UP); |
| | | payMoney = payMoney.subtract(bigDecimal); |
| | |
| | | if(payMoney.doubleValue()>0){ |
| | | objects.add(map1); |
| | | } |
| | | |
| | | // 根据供应商id分组 |
| | | Map<String, List<TErpProcurementGoods>> collect = list.stream().collect(Collectors.groupingBy(TErpProcurementGoods::getSupplierId)); |
| | | for (Map.Entry<String, List<TErpProcurementGoods>> entry : collect.entrySet()) { |
| | | HashMap<String, Object> map2 = new HashMap<>(); |
| | | String supplierId = entry.getKey(); |
| | | TCrmSupplier supplier = crmSupplierService.getById(supplierId); |
| | | // List<TErpProcurementGoods> value = entry.getValue(); |
| | | // BigDecimal reduce = value.stream().map(TErpProcurementGoods::getSupplierMoney).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // payMoney = payMoney.subtract(reduce); |
| | | map2.put("recv_merchant_no", supplier.getRecvMerchantNo()); |
| | | int count = allMoney.subtract(payMoney).multiply(BigDecimal.valueOf(100)).intValue(); |
| | | if(count>0){ |
| | | map2.put("separate_value", count+ ""); |
| | | |
| | | objects.add(map2); |
| | | } |
| | | } |
| | | |
| | | erpProcurement.setMoney(payMoney); |
| | | erpProcurement.setOutSeparateNo(outTradeNo); |
| | | erpProcurementService.updateById(erpProcurement); |
| | |
| | | org.apache.http.HttpResponse response1 = post(LakalaConfig.getServerUrl() + "sit/api/v3/sacs/separate", jsonString, authorization1); |
| | | String responseStr = IOUtils.toString(response1.getEntity().getContent(), ENCODING); |
| | | |
| | | System.err.println("分佣!!!!"+responseStr); |
| | | |
| | | JSONObject jsonObject = JSONObject.parseObject(responseStr); |
| | | if ("成功".equals(jsonObject.getString("msg"))) { |
| | |
| | | @RequestMapping("/messageSeparateHandle") |
| | | @ApiOperation(value = "拉卡拉分账信息回调接口") |
| | | public Object messageSeparateHandle(HttpServletRequest request) throws Exception { |
| | | |
| | | System.err.println("拉卡拉分账信息回调接口---------进入"); |
| | | String body = this.getBody(request); |
| | | // 先处理支付完成 修改状态 后处理分账 后走分账回调 |
| | | JSONObject jsonObject1 = JSONObject.parseObject(body); |
| | |
| | | JSONArray jsonArray = JSONArray.parseArray(detail_datas.toString()); |
| | | if("SEPARATE".equals(cmd_type.toString())){ |
| | | TErpProcurement erpProcurement = erpProcurementService.getOne(new LambdaQueryWrapper<TErpProcurement>().eq(TErpProcurement::getOutSeparateNo, o.toString())); |
| | | if ( erpProcurement!=null && "SUCCESS".equals(status)) { |
| | | if ( erpProcurement!=null && "SUCCESS".equals(status) && erpProcurement.getRefundStatus()==1) { |
| | | erpProcurement.setRefundStatus(1); |
| | | erpProcurement.setIsPlatformCommission(1); |
| | | erpProcurementService.updateById(erpProcurement); |
| | | // 修改分账状态 |
| | | List<TErpProcurementGoods> list1 = erpProcurementGoodsService.list(new LambdaQueryWrapper<TErpProcurementGoods>().eq(TErpProcurementGoods::getProcurementId, erpProcurement.getId())); |
| | |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("code", "SUCCESS"); |
| | | jsonObject.put("message", "执行成功"); |
| | | System.err.println("拉卡拉分账信息回调接口---------完成"); |
| | | return jsonObject; |
| | | } |
| | | }else if("FALLBACK".equals(cmd_type.toString())){ |
| | | TErpProcurement erpProcurement = erpProcurementService.getOne(new LambdaQueryWrapper<TErpProcurement>().eq(TErpProcurement::getRefundOutSeparateNo, o.toString())); |
| | | if ( erpProcurement!=null && "SUCCESS".equals(status) && erpProcurement.getRefundStatus()==1) { |
| | | if ( erpProcurement!=null && "SUCCESS".equals(status) && erpProcurement.getRefundStatus()!=2) { |
| | | erpProcurement.setRefundStatus(2); |
| | | erpProcurementService.updateById(erpProcurement); |
| | | List<TErpProcurementGoods> list1 = erpProcurementGoodsService.list(new LambdaQueryWrapper<TErpProcurementGoods>().eq(TErpProcurementGoods::getProcurementId, erpProcurement.getId())); |
| | |
| | | |
| | | String apiPath = "sit/api/v3/rfd/refund_front/refund"; |
| | | String body1 = "{\n" + |
| | | "\t\"req_time\": \"" + time + "\",\n" + |
| | | "\t\"version\": \"3.0\",\n" + |
| | | "\t\"req_data\": {\n" + |
| | | "\t\t\"merchant_no\": \""+erpProcurement.getMerchantNo()+"\",\n" + |
| | | "\t\t\"term_no\": \""+erpProcurement.getTermNo()+"\",\n" + |
| | | "\t\t\"refund_amount\": " + refund_amount + ",\n" + |
| | | "\t\t\"out_trade_no\": \"" + outTradeNo + "\",\n" + |
| | | "\t\t\"refund_amount\": \"" + refund_amount + "\",\n" + |
| | | "\t\t\"refund_reason\": \"退款\",\n" + |
| | | "\t\t\"notify_url\": \"" + "http://221.182.45.100:8089/t-sys-order/messageRefundHandle" + "\",\n" + |
| | | "\t\t\"origin_log_no\": \"" + erpProcurement.getPayTransactionId() + "\",\n" + |
| | | "\t\t\"origin_out_trade_no\": \"" + erpProcurement.getPayNumber() + "\",\n" + |
| | | "\t\t\"refund_acc_mode\": \"00\",\n" + |
| | | "\t\t\"refund_amt_sts\": \"00\",\n" + |
| | | "\t\t\"location_info\": {\n" + |
| | | "\t\t\t\"request_ip\": \"" + ipAddr + "\"\n" + |
| | | "\t\t\t\"request_ip\": \"" + ipAddr + "\",\n" + |
| | | "\t\t\t\"location\": \"\"\n" + |
| | | "\t\t}\n" + |
| | | "\t\t},\n" + |
| | | "\t\"version\": \"3.0\",\n" + |
| | | "\t\"req_time\": \"" + time + "\"\n" + |
| | | "\t}\n" + |
| | | "}"; |
| | | String authorization = getAuthorization(body1); |
| | | |
| | | org.apache.http.HttpResponse response = post(LakalaConfig.getServerUrl() + apiPath, body1, authorization); |
| | | if (response.getStatusLine().getStatusCode() != 200) { |
| | | return R.fail(500, "请求失败,statusCode " + response.getStatusLine() |
| | |
| | | erpProcurement.setRefundNo(outTradeNo); |
| | | erpProcurementService.updateById(erpProcurement); |
| | | |
| | | |
| | | System.err.println("拉卡拉分账信息回调接口---------完成"+responseStr); |
| | | |
| | | |
| | | // 响应success |
| | |
| | | @RequestMapping("/messageRefundHandle") |
| | | @ApiOperation(value = "拉卡拉退款信息回调接口") |
| | | public Object messageRefundHandle(HttpServletRequest request) throws Exception { |
| | | System.err.println("拉卡拉退款信息回调接口---------进入"); |
| | | String body = this.getBody(request); |
| | | // 先处理支付完成 修改状态 后处理分账 后走分账回调 |
| | | JSONObject jsonObject1 = JSONObject.parseObject(body); |
| | |
| | | @ApiOperation(value = "退款") |
| | | @PostMapping(value = "/refundOrder") |
| | | @SneakyThrows |
| | | public R<?> refundOrder(@RequestParam String id, HttpServletRequest request) { |
| | | public synchronized R<?> refundOrder(@RequestParam String id, HttpServletRequest request) { |
| | | SysUser user = tokenService.getLoginUser().getUser(); |
| | | try { |
| | | // 先退分账 在退订单 |
| | | // 查出采购单 算出价格 下单 算出应该分佣金额 应该分给谁 |
| | | TErpProcurement erpProcurement = erpProcurementService.getById(id); |
| | | // 还未分账成功不能退款 |
| | | if(erpProcurement.getStatus()==2){ |
| | | erpProcurement.setStatus(6); |
| | | erpProcurementService.updateById(erpProcurement); |
| | | return R.ok("操作成功"); |
| | | } |
| | | |
| | | if(erpProcurement.getStatus()==null || erpProcurement.getStatus()!=1){ |
| | | return R.fail("订单处理中,请稍后操作"); |
| | | } |
| | | // 判断回退没有回退了直接退款 |
| | | long count = erpProcurementGoodsService.count(new LambdaQueryWrapper<TErpProcurementGoods>().eq(TErpProcurementGoods::getProcurementId, id).eq(TErpProcurementGoods::getStatus, 1)); |
| | | if(count==0){ |
| | | // 发起退款 |
| | | String time = DateUtils.dateTimeNow(); |
| | | String ipAddr = IpUtils.getIpAddr(request); |
| | | // SYMBOLS 随机取4位数 |
| | | String str = ""; |
| | | for (int i = 0; i < 6; i++) { |
| | | str += SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length())); |
| | | } |
| | | String outTradeNo = time + str; |
| | | String refund_amount = erpProcurement.getPayMoney().multiply(BigDecimal.valueOf(100)).intValue() + ""; |
| | | String apiPath = "sit/api/v3/rfd/refund_front/refund"; |
| | | String body1 = "{\n" + |
| | | |
| | | "\t\"req_data\": {\n" + |
| | | "\t\t\"merchant_no\": \""+erpProcurement.getMerchantNo()+"\",\n" + |
| | | "\t\t\"term_no\": \""+erpProcurement.getTermNo()+"\",\n" + |
| | | "\t\t\"out_trade_no\": \"" + outTradeNo + "\",\n" + |
| | | "\t\t\"refund_amount\": \"" + refund_amount + "\",\n" + |
| | | "\t\t\"refund_reason\": \"退款\",\n" + |
| | | "\t\t\"notify_url\": \"" + "http://221.182.45.100:8089/t-sys-order/messageRefundHandle" + "\",\n" + |
| | | "\t\t\"origin_out_trade_no\": \"" + erpProcurement.getPayNumber() + "\",\n" + |
| | | "\t\t\"refund_acc_mode\": \"00\",\n" + |
| | | "\t\t\"refund_amt_sts\": \"00\",\n" + |
| | | "\t\t\"location_info\": {\n" + |
| | | "\t\t\t\"request_ip\": \"" + ipAddr + "\",\n" + |
| | | "\t\t\t\"location\": \"\"\n" + |
| | | "\t\t}\n" + |
| | | "\t\t},\n" + |
| | | "\t\"version\": \"3.0\",\n" + |
| | | "\t\"req_time\": \"" + time + "\"\n" + |
| | | "\t}\n" + |
| | | "}"; |
| | | |
| | | String authorization = getAuthorization(body1); |
| | | |
| | | org.apache.http.HttpResponse response = post(LakalaConfig.getServerUrl() + apiPath, body1, authorization); |
| | | if (response.getStatusLine().getStatusCode() != 200) { |
| | | return R.fail(500, "请求失败,statusCode " + response.getStatusLine() |
| | | + IOUtils.toString(response.getEntity().getContent(), ENCODING)); |
| | | } |
| | | String responseStr = IOUtils.toString(response.getEntity().getContent(), ENCODING); |
| | | JSONObject jsonObject = JSONObject.parseObject(responseStr); |
| | | JSONObject jsonObject2 = jsonObject.getJSONObject("resp_data"); |
| | | String code = jsonObject2.getString("log_no"); |
| | | erpProcurement.setRefundLogNo(code); |
| | | erpProcurement.setRefundNo(outTradeNo); |
| | | erpProcurementService.updateById(erpProcurement); |
| | | return R.ok("操作成功"); |
| | | } |
| | | // 还未分账成功不能退款 |
| | | if(erpProcurement.getIsPlatformCommission()==2){ |
| | | return R.fail("订单处理中,请稍后操作"); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | String time = DateUtils.dateTimeNow(); |
| | |
| | | // } |
| | | HashMap<String, Object> map1 = new HashMap<>(); |
| | | // TODO hzt |
| | | map1.put("recv_no", "SR2024000006413"); |
| | | map1.put("recv_no", "SR2024017174604"); |
| | | map1.put("amt", erpProcurement.getMoney().multiply(BigDecimal.valueOf(100)).intValue() + ""); |
| | | objects.add(map1); |
| | | map.put("total_amt",erpProcurement.getMoney().multiply(BigDecimal.valueOf(100)).intValue() + ""); |
| | |
| | | String responseStr = IOUtils.toString(response1.getEntity().getContent(), ENCODING); |
| | | |
| | | |
| | | |
| | | // post.body(jsonString); |
| | | // HttpResponse response = post.execute(); |
| | | // String responseStr = response.body(); |