Browse Source

支付集成

wujunjie 7 years ago
parent
commit
dfcbd8d1df

+ 11 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/SignFamilyDao.java

@ -5,6 +5,7 @@
 *******************************************************************************/
package com.yihu.wlyy.repository.patient;
import java.util.Date;
import java.util.List;
import com.yihu.wlyy.entity.patient.Patient;
@ -401,4 +402,14 @@ public interface SignFamilyDao extends PagingAndSortingRepository<SignFamily, Lo
    @Query(value = " select a.*  from wlyy_sign_family a where a.patient = ?1  and a.status = -4 and a.team_code = ?2 order by a.apply_date desc limit 0,1", nativeQuery = true)
    SignFamily findOutTimeSigningByPatientAndTeamCode(String patient,String teamCode);
    //      完成缴费后更新签约开始时间
    @Modifying
    @Query("update SignFamily a set a.begin = ?2 where a.patient = ?1")
    int updatePatientBegin(String patient, Date begin);
    //查询居民的扣费状态
    @Query( " select a from SignFamily a where a.patient = ?1 ")
    SignFamily findPatientExpensesStatus(String patient);
}

+ 2 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java

@ -1067,7 +1067,7 @@ public class FamilyContractService extends BaseService {
            Hospital hos = hospitalDao.findByCode(doc.getHospital());
            String content = sf.getName() + ",您好!祝贺您,成功签约" + sf.getDoctorName() + "医生团队,您已可以享受家庭医生所带来的无微不至的健康保健服务。" +
                    "为了给您提供更好的服务,请尽快到" + (hos != null ? hos.getName() : "") + "社区(地址:" +
                    "为了给您提供更好的服务,请尽快完成缴费。您可点击此条消息,跳转缴费页面完成缴费,或进入签约管理,选择待缴费的签约记录进行缴费操作,如需线下缴费,请尽快到" + (hos != null ? hos.getName() : "") + "社区(地址:" +
                    (hos != null ? hos.getAddress() : "") + ")缴费。";
            JSONObject json = new JSONObject();
            json.put("first", "签约成功通知");
@ -1368,7 +1368,7 @@ public class FamilyContractService extends BaseService {
            Hospital hos = hospitalDao.findByCode(doc.getHospital());
            String content = sf.getName() + ",您好!祝贺您,成功签约" + doc.getName() + "医生团队,您已可以享受家庭医生所带来的无微不至的健康保健服务。" +
                    "为了给您提供更好的服务,请尽快到" + (hos != null ? hos.getName() : "") + "社区(地址:" +
                    "为了给您提供更好的服务,请尽快完成缴费。您可点击此条消息,跳转缴费页面完成缴费,或进入签约管理,选择待缴费的签约记录进行缴费操作,如需线下缴费,请尽快到" + (hos != null ? hos.getName() : "") + "社区(地址:" +
                    (hos != null ? hos.getAddress() : "") + ")缴费。";
            // 同意签约
            JSONObject json = new JSONObject();

+ 112 - 63
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/wx/OnePayController.java

@ -1,6 +1,10 @@
package com.yihu.wlyy.web.wx;
import com.yihu.wlyy.entity.charge.WlyyCharge;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.service.weixin.wxpay.model.BindCard;
import com.yihu.wlyy.service.weixin.wxpay.model.Charge;
import com.yihu.wlyy.service.weixin.wxpay.service.OnePayService;
@ -11,6 +15,7 @@ import com.ylzinfo.onepay.sdk.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
@ -23,6 +28,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLDecoder;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -37,18 +43,55 @@ public class OnePayController extends WeixinBaseController {
    @Autowired
    private OnePayService pay;
    @Autowired
    private PatientDao patientDao;
    @Autowired
    private SignFamilyDao signFamilyDao;
    @RequestMapping(value = "expensesStatus", method = RequestMethod.GET)
    @ApiOperation("居民缴费状态查询")
    @ResponseBody
    public String expensesStatus() throws Exception {
        try {
            //            获取居民个人信息  要根据签约code去查找签约扣费状态
//            String userCode = getUID();
            String userCode = "915cc456-5b1d-11e6-8344-fa163e8aee56";
            SignFamily signFamily = signFamilyDao.findPatientExpensesStatus(userCode);
            String expensesStatus = signFamily.getExpensesStatus();
            if ("0".equals(expensesStatus)){
                return write(200, "未扣费!","expensesStatus",expensesStatus);
            }else if ("1".equals(expensesStatus)){
                return write(200, "已扣费!","expensesStatus",expensesStatus);
            }else if ("2".equals(expensesStatus)){
                return write(200, "已退费!","expensesStatus",expensesStatus);
            }else {
                return write(200, "扣费状态数据有误!","expensesStatus",expensesStatus);
            }
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
    @RequestMapping(value = "bindCard", method = RequestMethod.POST)
    @ApiOperation("查询绑卡信息")
    @ResponseBody
    public String bindCard() throws Exception {
        try {
            //            获取居民个人信息
           /* String userCode = getUID();
            Patient patient = patientDao.findByCode(userCode);
            String openId = patient.getOpenid();
            if (StringUtils.isNotEmpty(openId)) {
                BindCard bindCard = pay.bindCard(userCode, openId);
                return write(200, "查询绑卡信息成功!", "data", bindCard);
            } else {
                return write(-1, "openId为空!");
            }*/
            BindCard bindCard = pay.bindCard("915cc456-5b1d-11e6-8344-fa163e8aee56","o4Ma2t5665rS7uNfA9EF-VnOJx30");         //ohNH9sh4uwuJCxIwcLJtGTX-BaSk  //o4Ma2t5665rS7uNfA9EF-VnOJx30      getUID()getOpenid()
//            BindCard bindCard = pay.bindCard("915cc456-5b1d-11e6-8344-fa163e8aee56","ohNH9sh4uwuJCxIwcLJtGTX-BaSk");         //ohNH9sh4uwuJCxIwcLJtGTX-BaSk  //o4Ma2t5665rS7uNfA9EF-VnOJx30      getUID()getOpenid()
            return write(200, "查询绑卡信息成功!","data",bindCard);
        }
        catch (Exception e)
        {
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
@ -57,26 +100,37 @@ public class OnePayController extends WeixinBaseController {
    @ApiOperation("家庭医生签约支付")
    @ResponseBody
    public String charge(
                         @ApiParam(name="orgCode",value="医疗机构编号",defaultValue = "3502050300")
                         @RequestParam String orgCode,
                         @ApiParam(name="chargeType",value="支付类型",defaultValue = "1")
                         @RequestParam String chargeType,
                         @ApiParam(name="chargeRelation",value="支付关联代码",defaultValue = "044701ea5b2311e68344fa163e8aee56")
                         @RequestParam String chargeRelation,
                         @ApiParam(name="totalAmount",value="交易总金额(分)",defaultValue = "1")
                         @RequestParam Integer totalAmount,
                         @ApiParam(name="selfpayAmount",value="自费金额(分)",defaultValue = "0")
                         @RequestParam Integer selfpayAmount,
                         @ApiParam(name="insuranceAmount",value="医保支付金额(分)",defaultValue = "1")
                         @RequestParam Integer insuranceAmount,
                         @ApiParam(name="feeDetail",value="费用明细",defaultValue = "[{\"itemName\":\"家庭医生签约支付\",\"itemDesc\":\"家庭医生签约支付\",\"itemOrigPrice\":\"1\",\"itemNowPrice\":\"1\",\"itemNum\":\"1\",\"itemTotalAmt\":\"1\"}]")
                         @RequestParam String feeDetail) throws Exception {
            @ApiParam(name = "orgCode", value = "医疗机构编号", defaultValue = "3502050300")
            @RequestParam String orgCode,
            @ApiParam(name = "chargeType", value = "支付类型", defaultValue = "1")
            @RequestParam String chargeType,
            @ApiParam(name = "chargeRelation", value = "支付关联代码", defaultValue = "044701ea5b2311e68344fa163e8aee56")
            @RequestParam String chargeRelation,
            @ApiParam(name = "totalAmount", value = "交易总金额(分)", defaultValue = "1")
            @RequestParam Integer totalAmount,
            @ApiParam(name = "selfpayAmount", value = "自费金额(分)", defaultValue = "0")
            @RequestParam Integer selfpayAmount,
            @ApiParam(name = "insuranceAmount", value = "医保支付金额(分)", defaultValue = "1")
            @RequestParam Integer insuranceAmount,
            @ApiParam(name = "feeDetail", value = "费用明细", defaultValue = "[{\"itemName\":\"家庭医生签约支付\",\"itemDesc\":\"家庭医生签约支付\",\"itemOrigPrice\":\"1\",\"itemNowPrice\":\"1\",\"itemNum\":\"1\",\"itemTotalAmt\":\"1\"}]")
            @RequestParam String feeDetail) throws Exception {
        try {
            String settleNo = pay.charge(orgCode,chargeType,chargeRelation,totalAmount, selfpayAmount, insuranceAmount, feeDetail,"915cc456-5b1d-11e6-8344-fa163e8aee56","o4Ma2t5665rS7uNfA9EF-VnOJx30");  //ohNH9sh4uwuJCxIwcLJtGTX-BaSk    getUID(),getOpenid()
            return write(200, "家庭医生签约支付成功!","data",settleNo);
        }
        catch (Exception e)
        {
            //            获取居民个人信息
            /*String userCode = getUID();
            Patient patient = patientDao.findByCode(userCode);
            String openId = patient.getOpenid();
            if (StringUtils.isNotEmpty(openId)) {
                String settleNo = pay.charge(orgCode, chargeType, chargeRelation, totalAmount, selfpayAmount, insuranceAmount, feeDetail, userCode, openId);  //ohNH9sh4uwuJCxIwcLJtGTX-BaSk    getUID(),getOpenid()
//            更新签约表的缴费状态(begin字段),表示签约正式开始
                signFamilyDao.updatePatientBegin(userCode, new Date());
                return write(200, "家庭医生签约支付成功!", "data", settleNo);
            } else {
                return write(-1, "openId为空!");
            }*/
            String settleNo = pay.charge(orgCode, chargeType, chargeRelation, totalAmount, selfpayAmount, insuranceAmount, feeDetail, "915cc456-5b1d-11e6-8344-fa163e8aee56", "o4Ma2t5665rS7uNfA9EF-VnOJx30");  //ohNH9sh4uwuJCxIwcLJtGTX-BaSk    getUID(),getOpenid()
//            String settleNo = pay.charge(orgCode, chargeType, chargeRelation, totalAmount, selfpayAmount, insuranceAmount, feeDetail, "915cc456-5b1d-11e6-8344-fa163e8aee56", "ohNH9sh4uwuJCxIwcLJtGTX-BaSk");  //ohNH9sh4uwuJCxIwcLJtGTX-BaSk    getUID(),getOpenid()
            return write(200, "家庭医生签约支付成功!", "data", settleNo);
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
@ -85,14 +139,12 @@ public class OnePayController extends WeixinBaseController {
    @RequestMapping(value = "chargeQuery", method = RequestMethod.POST)
    @ApiOperation("家庭医生签约支付查询")
    @ResponseBody
    public String chargeQuery(@ApiParam(name="code",value="支付流水号",defaultValue = "")
                               @RequestParam String code) throws Exception {
    public String chargeQuery(@ApiParam(name = "code", value = "支付流水号", defaultValue = "")
                              @RequestParam String code) throws Exception {
        try {
            Charge charge = pay.chargeQuery(code);
            return write(200, "家庭医生签约支付查询成功!","data",charge);
        }
        catch (Exception e)
        {
            return write(200, "家庭医生签约支付查询成功!", "data", charge);
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
@ -102,11 +154,19 @@ public class OnePayController extends WeixinBaseController {
    @ResponseBody
    public String createSicard() throws Exception {
        try {
            String sicardUrl = pay.createSicard("915cc456-5b1d-11e6-8344-fa163e8aee56","o4Ma2t5665rS7uNfA9EF-VnOJx30");         //ohNH9sh4uwuJCxIwcLJtGTX-BaSk  //o4Ma2t5665rS7uNfA9EF-VnOJx30  getUID(),getOpenid()
            return write(200, "生成电子社保卡成功!","data",sicardUrl);
        }
        catch (Exception e)
        {
            //            获取居民个人信息
            String userCode = getUID();
            Patient patient = patientDao.findByCode(userCode);
            String openId = patient.getOpenid();
            if (StringUtils.isNotEmpty(openId)) {
                String sicardUrl = pay.createSicard(userCode, openId);         //ohNH9sh4uwuJCxIwcLJtGTX-BaSk  //o4Ma2t5665rS7uNfA9EF-VnOJx30  getUID(),getOpenid()
                return write(200, "生成电子社保卡成功!", "data", sicardUrl);
            }else {
                return write(-1, "openId为空!");
            }
//            String sicardUrl = pay.createSicard("915cc456-5b1d-11e6-8344-fa163e8aee56", "o4Ma2t5665rS7uNfA9EF-VnOJx30");         //ohNH9sh4uwuJCxIwcLJtGTX-BaSk  //o4Ma2t5665rS7uNfA9EF-VnOJx30  getUID(),getOpenid()
//            return write(200, "生成电子社保卡成功!", "data", sicardUrl);
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
@ -115,52 +175,40 @@ public class OnePayController extends WeixinBaseController {
    @RequestMapping(value = "chargeList", method = RequestMethod.POST)
    @ApiOperation("获取某次签约的支付记录")
    @ResponseBody
    public String chargeList(@ApiParam(name="chargeType",value="支付类型",defaultValue = "1")
                                  @RequestParam String chargeType,
                                  @ApiParam(name="chargeRelation",value="支付关联代码",defaultValue = "044701ea5b2311e68344fa163e8aee56")
                                  @RequestParam String chargeRelation) throws Exception {
    public String chargeList(@ApiParam(name = "chargeType", value = "支付类型", defaultValue = "1")
                             @RequestParam String chargeType,
                             @ApiParam(name = "chargeRelation", value = "支付关联代码", defaultValue = "044701ea5b2311e68344fa163e8aee56")
                             @RequestParam String chargeRelation) throws Exception {
        try {
            List<WlyyCharge> charge = pay.chargeList(chargeType,chargeRelation);
            return write(200, "获取某次签约的支付记录成功!","data",charge);
        }
        catch (Exception e)
        {
            List<WlyyCharge> charge = pay.chargeList(chargeType, chargeRelation);
            return write(200, "获取某次签约的支付记录成功!", "data", charge);
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
    @RequestMapping(value = "chargeListByPatient", method = RequestMethod.POST)
    @ApiOperation("获取患者的支付记录")
    @ResponseBody
    public String chargeListByPatient(@ApiParam(name="patient",value="患者代码",defaultValue = "")
                             @RequestParam String patient,
                             @ApiParam(name="page",value="第几页,从1开始",defaultValue = "1")
                             @RequestParam Integer page,
                             @ApiParam(name="size",value="每页几行",defaultValue = "10")
                             @RequestParam Integer size) throws Exception {
    public String chargeListByPatient(@ApiParam(name = "patient", value = "患者代码", defaultValue = "")
                                      @RequestParam String patient,
                                      @ApiParam(name = "page", value = "第几页,从1开始", defaultValue = "1")
                                      @RequestParam Integer page,
                                      @ApiParam(name = "size", value = "每页几行", defaultValue = "10")
                                      @RequestParam Integer size) throws Exception {
        try {
            List<WlyyCharge> charge = pay.chargeListByPatient(patient,page,size);
            return write(200, "获取患者的支付记录成功!","data",charge);
        }
        catch (Exception e)
        {
            List<WlyyCharge> charge = pay.chargeListByPatient(patient, page, size);
            return write(200, "获取患者的支付记录成功!", "data", charge);
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
    /**
     * 解析URL参数串
     *
     * @param formContext
     * @param wordFirstsplitRegex
     * @param wordSecondsplitRegex
@ -185,6 +233,7 @@ public class OnePayController extends WeixinBaseController {
    /**
     * 转换URL参数中为Map
     *
     * @param reqQueryString
     * @return
     * @throws PayException
@ -209,7 +258,7 @@ public class OnePayController extends WeixinBaseController {
    @ApiOperation("商户页面跳转(模拟测试)")
    public void testReturnUrl(HttpServletRequest request, HttpServletResponse response) throws IOException, PayException {
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write("返回结果:\n" + request.getQueryString() +"\n");
        response.getWriter().write("返回结果:\n" + request.getQueryString() + "\n");
        String onepayUrl = request.getParameter("onepayUrl");
        String appId = "1BHEOI11C00J7B2CA8C0000071FA53E1";