You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					
					
						
							299 lines
						
					
					
						
							12 KiB
						
					
					
				
			
		
		
	
	
							299 lines
						
					
					
						
							12 KiB
						
					
					
				| package com.ynxbd.common.action.pay;
 | |
| 
 | |
| import com.ynxbd.ali.helper.AliHelper;
 | |
| import com.ynxbd.common.action.base.BaseAction;
 | |
| import com.ynxbd.common.bean.enums.MerchantEnum;
 | |
| import com.ynxbd.common.bean.pay.Order;
 | |
| import com.ynxbd.common.helper.common.DateHelper;
 | |
| import com.ynxbd.common.result.Result;
 | |
| import com.ynxbd.common.result.ServiceException;
 | |
| import com.ynxbd.common.service.InHospService;
 | |
| import com.ynxbd.common.service.RecipeService;
 | |
| import com.ynxbd.common.service.RegService;
 | |
| import lombok.extern.slf4j.Slf4j;
 | |
| import org.apache.struts2.convention.annotation.Action;
 | |
| import org.apache.struts2.convention.annotation.Namespace;
 | |
| 
 | |
| import java.math.BigDecimal;
 | |
| import java.util.Date;
 | |
| 
 | |
| /**
 | |
|  * @Author wsq
 | |
|  * @Date 2021/2/26 12:50
 | |
|  * @Copyright @ 2020 云南新八达科技有限公司 All rights reserved.
 | |
|  */
 | |
| 
 | |
| @Slf4j
 | |
| @Namespace("/ali_pay")
 | |
| public class AliPayAction extends BaseAction {
 | |
| 
 | |
|     /**
 | |
|      * [支付宝]处方支付通知
 | |
|      *
 | |
|      * @return 是否成功
 | |
|      */
 | |
|     @Action("notify")
 | |
|     public Result notify(String outTradeNo, String notifyType) {
 | |
|         log.info("【支付宝】[收到通知] outTradeNo={}, notifyType={}", outTradeNo, notifyType);
 | |
|         if (outTradeNo == null || notifyType == null) {
 | |
|             return Result.respStr();
 | |
|         }
 | |
| 
 | |
|         Order order = AliHelper.payNotify(outTradeNo);
 | |
|         if (!order.isSuccess()) {
 | |
|             log.info(order.getErrorMsg());
 | |
|             return Result.error(order.getErrorMsg());
 | |
|         }
 | |
| 
 | |
|         String openid = order.getOpenid();
 | |
|         String bankTransNo = order.getBankTransNo();
 | |
|         String payInfo = order.getInfo();
 | |
|         BigDecimal totalFee = order.getTotalFee();
 | |
|         String payDate = DateHelper.getCurDate();
 | |
|         String payTime = DateHelper.getCurTime();
 | |
| 
 | |
|         switch (PEnum.toEnum(notifyType)) {
 | |
|             case RECIPE:
 | |
|                 new RecipeService().recipeListPay(MerchantEnum.ALI, totalFee.toString(), openid, outTradeNo, bankTransNo, null, payDate, payTime, payInfo);
 | |
|                 break;
 | |
| 
 | |
|             case REG: // 挂号
 | |
|                 try {
 | |
|                     new RegService().regPaidNotify(MerchantEnum.ALI, totalFee, openid, bankTransNo, outTradeNo, null, payDate, payTime, payInfo, new Date());
 | |
|                 } catch (ServiceException e) {
 | |
|                     log.info("【支付宝]挂号通知错误 outTradeNo={}, bankTransNo={}, message={}", outTradeNo, bankTransNo, e.getMessage());
 | |
|                 }
 | |
|                 break;
 | |
| 
 | |
|             case IN_HOSP:
 | |
|                 boolean isInsert = new InHospService().inHospNotify(MerchantEnum.WX, openid, totalFee, outTradeNo, bankTransNo, payDate, payTime, payInfo);
 | |
|                 log.info("【微信】[住院预交金] 预存{}", (isInsert ? "成功" : "失败"));
 | |
|                 break;
 | |
| 
 | |
|             default:
 | |
|                 log.info("【支付宝】通知类型错误,结束请求");
 | |
|                 break;
 | |
|         }
 | |
|         return Result.respStr();
 | |
|     }
 | |
| 
 | |
| //    /**
 | |
| //     * [支付宝]分时段挂号支付通知
 | |
| //     *
 | |
| //     * @return 是否成功
 | |
| //     */
 | |
| //    @Action("regPayNotify")
 | |
| //    public Result regPayNotify() {
 | |
| //        String outTradeNo = getString("outTradeNo");
 | |
| //        log.info("【支付宝】[挂号通知] outTradeNo={}", outTradeNo);
 | |
| //        if (outTradeNo == null) {
 | |
| //            return Result.respStr();
 | |
| //        }
 | |
| //
 | |
| //        Order order = AliHelper.payNotify(outTradeNo);
 | |
| //        if (!order.isSuccess()) {
 | |
| //            log.info(order.getErrorMsg());
 | |
| //            return Result.error(order.getErrorMsg());
 | |
| //        }
 | |
| //
 | |
| //        String openid = order.getOpenid();
 | |
| //        String bankTransNo = order.getBankTransNo();
 | |
| //        String payInfo = order.getInfo();
 | |
| //        BigDecimal totalFee = order.getTotalFee();
 | |
| //
 | |
| //        String payDate = DateHelper.getCurDate();
 | |
| //        String payTime = DateHelper.getCurTime();
 | |
| //        try {
 | |
| //            new RegService().regPaidNotify(MerchantEnum.ALI, totalFee, openid, bankTransNo, outTradeNo, null, payDate, payTime, payInfo, new Date());
 | |
| //            return Result.respStr();
 | |
| //        } catch (ServiceException e) {
 | |
| //            return Result.error(e);
 | |
| //        }
 | |
| //    }
 | |
| //
 | |
| //
 | |
| //    /**
 | |
| //     * [支付宝]处方支付通知
 | |
| //     *
 | |
| //     * @return 是否成功
 | |
| //     */
 | |
| //    @Action("recipePayNotify")
 | |
| //    public Result recipePayNotify() {
 | |
| //        String outTradeNo = getString("outTradeNo");
 | |
| //        log.info("【支付宝】[处方通知] outTradeNo={}", outTradeNo);
 | |
| //
 | |
| //        if (outTradeNo == null) {
 | |
| //            return Result.respStr();
 | |
| //        }
 | |
| //
 | |
| //        Order order = AliHelper.payNotify(outTradeNo);
 | |
| //        if (!order.isSuccess()) {
 | |
| //            log.info(order.getErrorMsg());
 | |
| //            return Result.error(order.getErrorMsg());
 | |
| //        }
 | |
| //
 | |
| //        String openid = order.getOpenid();
 | |
| //        String bankTransNo = order.getBankTransNo();
 | |
| //        String payInfo = order.getInfo();
 | |
| //        BigDecimal totalFee = order.getTotalFee();
 | |
| //
 | |
| //        String payDate = DateHelper.getCurDate();
 | |
| //        String payTime = DateHelper.getCurTime();
 | |
| //
 | |
| //        // 和HIS交互
 | |
| //        new RecipeService().recipeListPay(MerchantEnum.ALI, totalFee.toString(), openid, outTradeNo, bankTransNo, null, payDate, payTime, payInfo);
 | |
| //        return Result.respStr();
 | |
| //    }
 | |
| 
 | |
| 
 | |
| //
 | |
| //    /**
 | |
| //     * [支付宝]处方支付
 | |
| //     *
 | |
| //     * @return 订单数据
 | |
| //     */
 | |
| //    @Action("recipeNewPay")
 | |
| //    public String recipeNewPay() {
 | |
| //        // payPackage 的商品信息
 | |
| //        String openid = getString("openid");
 | |
| //        String patientId = getString("patientId");
 | |
| //        String treatNum = getString("treatNum");
 | |
| //        String totalFee = getString("totalFee");
 | |
| //        String recipeJson = getString("recipeJson");
 | |
| //        String payWay = getString("payWay");
 | |
| //        Integer awaitSecond = getInteger("awaitSecond"); // 等待秒数,0继续执行不等待
 | |
| //
 | |
| //        log.info("【支付宝】openid={}, patientId={}, treatNum={}, totalFee={}, recipeJson={},payWay={}", openid, patientId, treatNum, totalFee, recipeJson, payWay);
 | |
| //        if (openid == null || patientId == null || treatNum == null || totalFee == null) {
 | |
| //            return Result.error(ResultEnum.PARAM_NOT_COMPLETE); // 参数缺失
 | |
| //        }
 | |
| //
 | |
| //        RecipeService recipeService = new RecipeService();
 | |
| //        if (awaitSecond == null) awaitSecond = 0;
 | |
| //        if (awaitSecond != 0) {
 | |
| //            Long second = recipeService.isRepeatPay(treatNum, awaitSecond);
 | |
| //            if (second != null) { // 是否 awaitSecond s内重复支付
 | |
| //                log.info("[处方] 下单等待 {} s 确定", second);
 | |
| //                return Result.error(ResultEnum.PAY_AWAIT, second);
 | |
| //            }
 | |
| //        }
 | |
| //
 | |
| //        String outTradeNo =PayTypeEnum.createOutTradeNo(PayTypeEnum.ALI); // 创建订单号
 | |
| //
 | |
| //        // 金额为0的处方不进行调用通知
 | |
| //        if ("0".equals(totalFee)) {
 | |
| //            Date date = new Date();
 | |
| //            String payDate = DateHelper.getCurDate(date);
 | |
| //            String payTime = DateHelper.getCurTime(date);
 | |
| //
 | |
| //            recipeService.saveRecipePrepay(recipeJson, payWay, openid, patientId, treatNum, outTradeNo, totalFee);
 | |
| //            recipeService.recipeListPay(PayTypeEnum.ALI, totalFee, openid, outTradeNo, outTradeNo, payDate, payTime, null);
 | |
| //
 | |
| //            Map<String, Object> map = new HashMap<>();
 | |
| //            map.put("totalFee", 0);
 | |
| //            return Result.success(map);
 | |
| //        }
 | |
| //
 | |
| //
 | |
| //        String title = "诊间支付 门诊号:" + treatNum;
 | |
| //
 | |
| //        // 下单
 | |
| //        JSONObject respJson = AliConfig.createTransaction(title, outTradeNo, totalFee, openid, "aliPay/recipePayNotify.do");
 | |
| //        log.info("【支付宝】下单:treatNum={}, respJson={}", treatNum, respJson);
 | |
| //        if (respJson == null) {
 | |
| //            return Result.error(ResultEnum.PAY_ERROR_ORDER); // 微信支付调用错误
 | |
| //        }
 | |
| //
 | |
| //        // 订单信息预存
 | |
| //        recipeService.saveRecipePrepay(recipeJson, payWay, openid, patientId, treatNum, outTradeNo, totalFee);
 | |
| //        return Result.success(JSONObject.toJSONString(respJson));
 | |
| //    }
 | |
| 
 | |
| 
 | |
|     //    /**
 | |
| //     * [支付宝]分时段挂号支付
 | |
| //     *
 | |
| //     * @return 订单数据
 | |
| //     */
 | |
| //    @Action("timeRegNewPay")
 | |
| //    public String timeRegNewPay() {
 | |
| //        // 金额
 | |
| //        BigDecimal regFee = getBigDecimal("regFee");
 | |
| //        BigDecimal clinicFee = getBigDecimal("clinicFee");
 | |
| //        BigDecimal payMoney = getBigDecimal("payMoney");
 | |
| //        // 信息
 | |
| //        String tel = getString("tel");
 | |
| //        String openid = getString("openid");
 | |
| //        String idCardNo = getString("idCardNo");
 | |
| //        String patientId = getString("patientId");
 | |
| //        // 号源
 | |
| //        String tid = getString("tid");
 | |
| //        String tName = getString("tName");
 | |
| //        String deptCode = getString("deptCode");
 | |
| //        String deptName = getString("deptName");
 | |
| //        String doctCode = getString("doctCode");
 | |
| //        String doctName = getString("doctName");
 | |
| //        String begTime = getString("begTime");
 | |
| //        String endTime = getString("endTime");
 | |
| //        String regCode = getString("regCode");
 | |
| //        String regDate = getString("regDate");
 | |
| //        String sourceId = getString("sourceId");
 | |
| //        String queueNum = getString("queueNum");
 | |
| //        String address = getString("address");
 | |
| //
 | |
| //        if (regFee == null || clinicFee == null || payMoney == null
 | |
| //                || openid == null || patientId == null || tid == null || tName == null
 | |
| //                || deptCode == null || deptName == null || doctCode == null || doctName == null
 | |
| //                || regCode == null || regDate == null || begTime == null || endTime == null
 | |
| //                || queueNum == null || sourceId == null) {
 | |
| //            return outResp(Result.error(ResultEnum.PARAM_NOT_COMPLETE));
 | |
| //        }
 | |
| //
 | |
| //
 | |
| //        Register reg = new Register();
 | |
| //        reg.setRegFee(regFee);
 | |
| //        reg.setClinicFee(clinicFee);
 | |
| //        reg.setPayMoney(payMoney);
 | |
| //        // 信息
 | |
| //        reg.setPatientId(patientId);
 | |
| //        reg.setOpenid(openid);
 | |
| //        reg.setIdCardNo(idCardNo);
 | |
| //        reg.setTel(tel);
 | |
| //
 | |
| //        reg.setTid(tid);
 | |
| //        reg.settName(tName);
 | |
| //        reg.setDeptCode(deptCode);
 | |
| //        reg.setDeptName(deptName);
 | |
| //        reg.setDoctCode(doctCode);
 | |
| //        reg.setDoctName(doctName);
 | |
| //        reg.setBegTime(begTime);
 | |
| //        reg.setEndTime(endTime);
 | |
| //        reg.setRegDate(regDate);
 | |
| //        reg.setSourceId(sourceId);
 | |
| //        reg.setQueueNum(queueNum);
 | |
| //        reg.setAddress(address);
 | |
| //        reg.setRegCode(regCode);
 | |
| //        reg.setPayDeviceId("mobile");
 | |
| //        reg.setPayWay(PayTypeEnum.ALI.getPayWay_in());
 | |
| //
 | |
| //        String outTradeNo = PayTypeEnum.createOutTradeNo(PayTypeEnum.ALI);
 | |
| //        reg.setoutTradeNo(outTradeNo);
 | |
| //
 | |
| //        log.info("【支付宝】[分时段挂号]生成的outTradeNo:" + outTradeNo);
 | |
| //        String title = deptName + " 挂号(" + regDate + ")";
 | |
| //
 | |
| //        // 预存挂号信息
 | |
| //        if (!new RegService().saveRegPrepay(reg, true)) {
 | |
| //            return Result.error(ResultEnum.PAY_PREPAY_SAVE_ERROR);
 | |
| //        }
 | |
| //
 | |
| //        // 下单
 | |
| //        JSONObject respJson = AliConfig.createTransaction(title, outTradeNo, payMoney.toString(), openid, "aliPay/regPayNotify.do");
 | |
| //        if (respJson == null) {
 | |
| //            return Result.error(ResultEnum.PAY_ERROR_ORDER); // 微信支付调用错误
 | |
| //        }
 | |
| //        return Result.success(JSONObject.toJSONString(respJson));
 | |
| //    }
 | |
| 
 | |
| 
 | |
| }
 | |
| 
 |