Browse Source

家庭签约按月缴费

wujunjie 7 years ago
parent
commit
dacafb4146

+ 57 - 6
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/weixin/wxpay/service/OnePayService.java

@ -227,6 +227,17 @@ public class OnePayService {
            OnepayDefaultClient onepayClient = new OnepayDefaultClient(config.getOnepayApi(), appId, appSecret, signType, encryptType);
            String uuid = format.format(new Date()) + UUID.randomUUID().toString().replaceAll("-", "").substring(0, 4);
            //      根据签约code查询签约信息
            SignFamily signFamily = signFamilyDao.findByCode(chargeRelation);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date begin = signFamily.getBegin();
            Date end = signFamily.getEnd();
            if (begin != null && end != null) {
                totalAmount = getTotalAmount(sdf.format(begin), sdf.format(end), "yyyy-MM-dd");
            } else {
                return "-2";
            }
            charge.setChargeType(chargeType);   //交易类型
            charge.setChargeRelation(chargeRelation);  //交易关联代码 wlyy_sign_family字段code
            charge.setCode(uuid);  //  接入应用支付业务流水号
@ -285,8 +296,6 @@ public class OnePayService {
            params.put("subject", subject);  //订单名称
            params.put("wxToken", accessToken);
            //      根据签约code查询签约信息
            SignFamily signFamily = signFamilyDao.findByCode(chargeRelation);
            if (signFamily != null) {
//                //签约人Code
                String signDoctorCode = signFamily.getSignDoctorCode();
@ -334,10 +343,10 @@ public class OnePayService {
                        principalCardNo = repSsc;
                    }
                }
                if (StringUtils.isNotEmpty(principalCardNo)){
                if (StringUtils.isNotEmpty(principalCardNo)) {
                    map.put("principalCardNo", principalCardNo); //实际签约卡号( 默认为绑卡主体卡号)
                    charge.setPrincipalSsc(principalCardNo);
                }else {
                } else {
                    return "-1";
                }
@ -453,7 +462,7 @@ public class OnePayService {
                WlyyCharge chargePay = chargeDao.findByCode(outChargeNo);
                if (request.containsKey("responseContent")){
                if (request.containsKey("responseContent")) {
                    JSONObject responseContents = request.getJSONObject("responseContent");//医保结构体
                    if (responseContents != null) {
                        String miRegisterNo = null;//医保挂号
@ -523,7 +532,7 @@ public class OnePayService {
                        chargePay.setAccountPay(accountPay);
                        chargePay.setSelfPay(selfPay);
                        chargePay.setCivilPay(civilPay);
                }
                    }
                }
@ -709,4 +718,46 @@ public class OnePayService {
        }
    }
    /**
     * 按月缴费获取签约月数
     *
     * @param fromStr
     * @param toStr
     * @param formatStr
     * @return
     */
    public static int monthBetween(String fromStr, String toStr, String formatStr) {
        try {
            SimpleDateFormat format = new SimpleDateFormat(formatStr);
            Calendar bef = Calendar.getInstance();
            Calendar aft = Calendar.getInstance();
            bef.setTime(format.parse(fromStr));
            aft.setTime(format.parse(toStr));
            int result = aft.get(Calendar.MONTH) - bef.get(Calendar.MONTH);
            int month = (aft.get(Calendar.YEAR) - bef.get(Calendar.YEAR)) * 12;
            return Math.abs(month + result);
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
    }
    /**
     * 按月缴费获取总金额
     *
     * @param fromStr
     * @param toStr
     * @param formatStr
     * @return
     */
    public static String getTotalAmount(String fromStr, String toStr, String formatStr) {
        try {
            Double amount = monthBetween(fromStr, toStr, formatStr) * 7.5;
            return "" + (int) (amount * 100);
        } catch (Exception e) {
            e.printStackTrace();
            return "0";
        }
    }
}

+ 29 - 4
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/wx/OnePayController.java

@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.wlyy.entity.charge.WlyyCharge;
import com.yihu.wlyy.entity.organization.HospitalMapping;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.entity.ylz.PayConfigura;
import com.yihu.wlyy.repository.charge.ChargeDao;
import com.yihu.wlyy.repository.organization.HospitalMappingDao;
@ -126,7 +127,7 @@ public class OnePayController extends WeixinBaseController {
                    msg = "生成电子社保卡成功!";
                }
            }
            if(bindCard.size()==0||bindCard==null){
            if (bindCard.size() == 0 || bindCard == null) {
                json.put("sicardUrl", sicardUrl);
                json.put("bindStatus", "030007");
                msg = "生成电子社保卡成功!";
@ -165,15 +166,16 @@ public class OnePayController extends WeixinBaseController {
            @RequestParam String totalAmount) throws Exception {
        try {
            //            获取居民个人信息
            totalAmount = "9000";
            String patient = getUID();
            String openId = getOpenid();
            String repUid = getRepUID();
            if (StringUtils.isNotEmpty(openId)) {
                String settleNo = pay.charge(orgCode, chargeType, chargeRelation, totalAmount, patient, repUid, openId, getAccessToken());
                if ("-1".equals(settleNo)){
                if ("-1".equals(settleNo)) {
                    return write(-1, "附属卡未绑定!");
                } else if ("-2".equals(settleNo)) {
                    return write(-1, "查询签约时间失败!");
                }
                return write(200, "家庭医生签约支付成功!", "data", settleNo);
            } else {
@ -612,5 +614,28 @@ public class OnePayController extends WeixinBaseController {
        logService.saveHttpLog(isSuccess, config.getReceiveNotify(), "异步支付通知", "POST", null, params, responses, error, logService.onepayType);
    }
    /**
     * 获取按月缴费总金额
     *
     * @throws IOException
     * @throws PayException
     */
    @RequestMapping(value = "/getTotalAmount", method = RequestMethod.POST)
    @ApiOperation("获取按月缴费总金额")
    @ResponseBody
    public String getTotalAmount(@RequestParam(defaultValue = "0447066a-5b23-11e6-8344-fa163e8aee56") String signCode) throws IOException, PayException {
        try {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            SignFamily signFamily = signFamilyDao.findByCode(signCode);
            Date begin = signFamily.getBegin();
            Date end = signFamily.getEnd();
            if (begin != null && end != null) {
                String totalAmount = pay.getTotalAmount(format.format(begin), format.format(end), "yyyy-MM-dd");
                return write(200, "查询签约金额成功!", "totalAmount", totalAmount);
            }
            return write(-1, "查询签约时间失败!");
        } catch (Exception e) {
            return write(-1, "查询签约金额失败!");
        }
    }
}