liujie
3 天以前 87dc04e8ef1580218961acbda378f0fd0e5bec89
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TSysOrderController.java
@@ -126,6 +126,10 @@
            String amount = String.valueOf(erpProcurement.getPayMoney().multiply(new BigDecimal("100")).intValue());
            TCrmSupplier supplier = crmSupplierService.getById(erpProcurement.getSupplierId());
            String trans_type ="41";
            if("WECHAT".equals(type)){
                trans_type= "51";
            }
            String apiPath = "sit/api/v3/labs/trans/preorder";
@@ -144,9 +148,10 @@
                    "\t\t\"settle_type\": \"1\",\n" +
                    "\t\t\"total_amount\": " + amount + ",\n" +
                    "\t\t\"account_type\": \"" + type + "\",\n" +
                    "\t\t\"trans_type\": \"41\"\n" +
                    "\t\t\"trans_type\": \""+trans_type+"\"\n" +
                    "\t}\n" +
                    "}";
            String authorization = getAuthorization(body);
            org.apache.http.HttpResponse response = post(LakalaConfig.getServerUrl() + apiPath, body, authorization);
            if (response.getStatusLine().getStatusCode() != 200) {
@@ -164,7 +169,7 @@
            erpProcurement.setStatus(2);
            erpProcurement.setTermNo(supplier.getTermNo());
            erpProcurement.setAccountType(type);
            erpProcurement.setTransType("41");
            erpProcurement.setTransType(trans_type);
            erpProcurementService.updateById(erpProcurement);
            return R.ok(responseStr);
@@ -240,24 +245,24 @@
            BigDecimal allMoney = erpProcurement.getPayMoney();
            // 平台应得分账
            BigDecimal payMoney = erpProcurement.getPayMoney();
            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);
            }
//            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", "822641048160MMJ");
            map1.put("recv_no", "SR2024000006413");
            // 手续费
            BigDecimal bigDecimal = allMoney.multiply(new BigDecimal("0.038")).setScale(2, RoundingMode.HALF_UP);
            payMoney = payMoney.subtract(bigDecimal);
@@ -276,9 +281,18 @@
            String jsonString = JSON.toJSONString(reqMap);
            post.body(jsonString);
            HttpResponse response = post.execute();
            String responseStr = response.body();
//            String authorization1 = getAuthorization(jsonString);
//            post.header("Authorization", SCHEMA + " " + authorization);
//
//            post.body(jsonString);
//            HttpResponse response = post.execute();
//            String responseStr = response.body();
            String authorization1 = getAuthorization(jsonString);
            org.apache.http.HttpResponse response1 = post(LakalaConfig.getServerUrl() + "sit/api/v3/sacs/separate", jsonString, authorization1);
            String responseStr = IOUtils.toString(response1.getEntity().getContent(), ENCODING);
            JSONObject jsonObject = JSONObject.parseObject(responseStr);
            if ("成功".equals(jsonObject.getString("msg"))) {
                Object o1 = jsonObject.get("resp_data");
@@ -409,7 +423,6 @@
                return jsonObject;
            }
        }
        return null;
    }
@@ -419,7 +432,7 @@
    @ApiOperation(value = "退款")
    @PostMapping(value = "/refundOrder")
    @SneakyThrows
    public R<?> refundOrder(@RequestParam String id, String type, HttpServletRequest request) {
    public R<?> refundOrder(@RequestParam String id, HttpServletRequest request) {
        SysUser user = tokenService.getLoginUser().getUser();
        try {
            // 先退分账  在退订单
@@ -442,7 +455,7 @@
            String outTradeNo = time + str;
            // 操作分账
            HttpRequest post = HttpUtil.createPost(LakalaConfig.getServerUrl() + "sit/api/v3/sacs/fallback");
//            HttpRequest post = HttpUtil.createPost(LakalaConfig.getServerUrl() + "sit/api/v3/sacs/fallback");
            HashMap<String, Object> reqMap = new HashMap<>();
            reqMap.put("version", "3.0");
            reqMap.put("req_time", DateUtils.dateTimeNow());
@@ -468,7 +481,7 @@
//            }
            HashMap<String, Object> map1 = new HashMap<>();
            // TODO hzt
            map1.put("recv_no", "dsadasda");
            map1.put("recv_no", "SR2024000006413");
            map1.put("amt", erpProcurement.getMoney().multiply(BigDecimal.valueOf(100)).intValue() + "");
            objects.add(map1);
            map.put("total_amt",erpProcurement.getMoney().multiply(BigDecimal.valueOf(100)).intValue() + "");
@@ -477,16 +490,22 @@
            String jsonString = JSON.toJSONString(reqMap);
            post.body(jsonString);
            HttpResponse response = post.execute();
            String responseStr = response.body();
            String authorization1 = getAuthorization(jsonString);
            org.apache.http.HttpResponse response1 = post(LakalaConfig.getServerUrl() + "sit/api/v3/sacs/fallback", jsonString, authorization1);
            String responseStr = IOUtils.toString(response1.getEntity().getContent(), ENCODING);
//            post.body(jsonString);
//            HttpResponse response = post.execute();
//            String responseStr = response.body();
            return R.ok(responseStr);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return R.fail(500, "调用支付宝支付预下单接口错误");
        return R.fail(500, "退款失败请联系平台管理员");
    }