yeguodong 3 months ago
parent
commit
e5dedc63a0

+ 20 - 0
src/main/java/cn/hnthyy/thmz/controller/pay/NongPayController.java

@@ -26,6 +26,16 @@ public class NongPayController {
         return nongPayService.unifiedOrder(body);
     }
 
+    /**
+     * 通过收费凭条上的二维码进行扫码支付
+     * @param body
+     * @return
+     */
+    @RequestMapping(value = "/unifiedOrderByCodeImgUrl", method = RequestMethod.POST)
+    public JSONObject unifiedOrderByCodeImgUrl(@RequestBody Map<String, String> body) {
+        return nongPayService.unifiedOrderByCodeImgUrl(body);
+    }
+
     /**
      * 查询支付订单
      * @param mchOrderNo
@@ -35,4 +45,14 @@ public class NongPayController {
     public JSONObject query(@RequestParam String mchOrderNo, @RequestParam String type) {
         return nongPayService.query(mchOrderNo, type);
     }
+
+    /**
+     * 通过收费凭条上的二维码进行扫码支付后的通知回调接口
+     * @param body
+     * @return
+     */
+    @RequestMapping(value = "/notifyCodeImg", method = RequestMethod.POST)
+    public String notifyCodeImg(@RequestBody Map<String, Object> body) {
+        return nongPayService.notifyCodeImg(body);
+    }
 }

+ 83 - 3
src/main/java/cn/hnthyy/thmz/service/pay/NongPayService.java

@@ -2,6 +2,8 @@ package cn.hnthyy.thmz.service.pay;
 
 import cn.hnthyy.thmz.common.RestApiUtil;
 import cn.hnthyy.thmz.common.model.ResultCode;
+import cn.hnthyy.thmz.entity.his.mz.MzDepositFile;
+import cn.hnthyy.thmz.vo.MzDepositFileVo;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
@@ -10,9 +12,7 @@ import org.springframework.stereotype.Service;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 
 @Slf4j
 @Service
@@ -54,6 +54,49 @@ public class NongPayService {
         return result;
     }
 
+    /**
+     * 通过收费凭条上的二维码进行扫码支付
+     * @param body
+     * @return
+     */
+    public JSONObject unifiedOrderByCodeImgUrl(Map<String, String> body) {
+        JSONObject result = new JSONObject();
+        result.put("code", ResultCode.pay_error.getCode());
+        body.put("payType", "1");
+        String amount = body.get("amount");
+        BigDecimal amountBigDecimal = new BigDecimal(amount);
+        String payAmount = String.valueOf(amountBigDecimal.multiply(new BigDecimal(100)).setScale(0, RoundingMode.HALF_UP));
+        // todo 测试写死1分钱
+        body.put("amount", "1");
+//        body.put("amount", payAmount);
+        body.put("subject", body.get("subject"));
+        body.put("body", body.get("body"));
+        JSONObject channelExtra = new JSONObject();
+        channelExtra.put("payDataType", body.get("codeImgUrl"));
+        body.put("channelExtra", JSONObject.toJSONString(channelExtra));
+        JSONObject extParam = new JSONObject();
+        extParam.put("patientId", body.get("patientId"));
+        extParam.put("times", body.get("times"));
+        extParam.put("amount", body.get("amount"));
+        body.put("extParam", JSONObject.toJSONString(extParam));
+
+        try {
+            log.info("--------------------门诊收费开始-------------------------");
+            log.info("param={}", JSONObject.toJSONString(body));
+            String postResponse = RestApiUtil.doPost(payUrl + "/unifiedOrder", JSONObject.toJSONString(body));
+            JSONObject response = JSONObject.parseObject(postResponse);
+            log.info("response={}", response);
+            if(Objects.equals(response.getInteger("code"), ResultCode.pay_success.getCode())) {
+                result.put("code", ResultCode.pay_success.getCode());
+                result.put("data", response.getJSONObject("data"));
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+            log.error("支付失败:" + e.getMessage());
+        }
+        return result;
+    }
+
     public JSONObject query(String mchOrderNo, String type) {
         JSONObject result = new JSONObject();
         result.put("code", ResultCode.pay_error.getCode());
@@ -74,6 +117,43 @@ public class NongPayService {
         return result;
     }
 
+    public String notifyCodeImg(Map<String, Object> body) {
+        String payOrderId = (String) body.get("payOrderId");
+        String mchOrderNo = (String) body.get("mchOrderNo");
+        String extParam = (String) body.get("extParam");
+        int amount = (Integer) body.get("amount");
+        int state = (Integer) body.get("state");
+        if(state == 2) {
+            JSONObject extraParam = JSONObject.parseObject(extParam);
+            List<MzDepositFile> mzDepositFiles = new ArrayList<>();
+            MzDepositFile mzDepositFile = new MzDepositFile();
+            mzDepositFile.setChequeType("O");
+            mzDepositFile.setAmount(extraParam.getBigDecimal("amount"));
+            mzDepositFile.setTraceNo(mchOrderNo);
+            mzDepositFiles.add(mzDepositFile);
+            MzDepositFileVo mzDepositFileVo = new MzDepositFileVo();
+            mzDepositFileVo.setPatientId(extraParam.getString("patientId"));
+            mzDepositFileVo.setTimes(Integer.valueOf(extraParam.getString("times")));
+            mzDepositFileVo.setReceiptNo(1);
+            mzDepositFileVo.setMzDepositFiles(mzDepositFiles);
+            Map<String, Object> fee = chargeFee(mzDepositFileVo);
+            Integer code = (Integer) fee.get("code");
+            if(code == 0) {
+
+            }
+
+            return "success";
+        } else {
+            return "fail";
+        }
+
+    }
+
+    private Map<String, Object> chargeFee(MzDepositFileVo mzDepositFileVo) {
+        Map<String, Object> result = new HashMap<>();
+        return result;
+    }
+
     public static void main(String[] args) {
         String amount = "10";
         BigDecimal amountBigDecimal = new BigDecimal(amount);

+ 65 - 66
src/main/resources/static/js/mz/toll_administration.js

@@ -1762,6 +1762,71 @@ function initTallyDetailTable() {
     });
 }
 
+function queryCodePay() {
+    $.ajax({
+        type: "GET",
+        url: '/thmz/NongPay/query?mchOrderNo=202507221753175802948&type=0',
+        dataType: "json",
+        headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
+        success: function (res) {
+            if (res == '401' || res == 401) {
+                window.location.href = '/thmz/login/view'
+                return;
+            }
+
+        }
+    });
+}
+
+function codePay() {
+    const moneyValues = [];
+
+    $('.pay-item').each(function() {
+        const $this = $(this);
+        const $select = $this.find('select');
+        const isAggregatePay = $select.find('option:selected').text() === '聚合支付';
+
+        if (isAggregatePay) {
+            const $moneyInput = $this.find('input.money');
+            const moneyValue = parseFloat($moneyInput.val()) || 0;
+            moneyValues.push(moneyValue);
+        }
+    });
+
+    var authCode = $('#paymentCode').val();
+    $.ajax({
+        type: "POST",
+        url: '/thmz/NongPay/unifiedOrder',
+        contentType: "application/json;charset=UTF-8",
+        dataType: "json",
+        data: JSON.stringify({
+            "amount": moneyValues[0],
+            "authCode": authCode,
+            "subject": "门诊收费",
+            "body": "门诊收费"
+        }),
+        headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
+        success: function (res) {
+            if (res.code === 9000) {
+                if(res.data && (res.data.state === 2 || res.data.orderState === 2)) {
+                    alert("付款成功");
+                }
+            }
+        }
+    });
+}
+
+/*function debounce(func, delay = 500) {
+    let timer = null;
+    return function(...args) {
+        clearTimeout(timer);
+        timer = setTimeout(() => {
+            func.apply(this, args); // 执行目标方法
+        }, delay);
+    };
+}
+
+$('#paymentCode').on('input', debounce(codePay, 500));*/
 
 /**
  * 提交缴费申请
@@ -3755,72 +3820,6 @@ function clearMztcbl() {
     $("#mzblReceiptNo").val(null);
 }
 
-function queryCodePay() {
-    $.ajax({
-        type: "GET",
-        url: '/thmz/NongPay/query?mchOrderNo=202507221753175802948&type=0',
-        dataType: "json",
-        headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
-        success: function (res) {
-            if (res == '401' || res == 401) {
-                window.location.href = '/thmz/login/view'
-                return;
-            }
-
-        }
-    });
-}
-
-function codePay() {
-    const moneyValues = [];
-
-    $('.pay-item').each(function() {
-        const $this = $(this);
-        const $select = $this.find('select');
-        const isAggregatePay = $select.find('option:selected').text() === '聚合支付';
-
-        if (isAggregatePay) {
-            const $moneyInput = $this.find('input.money');
-            const moneyValue = parseFloat($moneyInput.val()) || 0;
-            moneyValues.push(moneyValue);
-        }
-    });
-
-    var authCode = $('#paymentCode').val();
-    $.ajax({
-        type: "POST",
-        url: '/thmz/NongPay/unifiedOrder',
-        contentType: "application/json;charset=UTF-8",
-        dataType: "json",
-        data: JSON.stringify({
-            "amount": moneyValues[0],
-            "authCode": authCode,
-            "subject": "门诊收费",
-            "body": "门诊收费"
-        }),
-        headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
-        success: function (res) {
-            if (res.code === 9000) {
-                if(res.data && (res.data.state === 2 || res.data.orderState === 2)) {
-                    alert("付款成功");
-                }
-            }
-        }
-    });
-}
-
-/*function debounce(func, delay = 500) {
-    let timer = null;
-    return function(...args) {
-        clearTimeout(timer);
-        timer = setTimeout(() => {
-            func.apply(this, args); // 执行目标方法
-        }, delay);
-    };
-}
-
-$('#paymentCode').on('input', debounce(codePay, 500));*/
-
 /**
  * 刷卡/扫码,正常收费的的接口
  */