Bläddra i källkod

眼科医保结算流程

wangzhinan 1 år sedan
förälder
incheckning
b1e28291d4

+ 4 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/PrescriptionService.java

@ -8396,6 +8396,10 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            } else {
                System.out.println("获取顺丰物流面单信息:1");
                sfexpress_obj = expressageDOList.get(0);
                List<WlyyPrescriptionDO> wlyyPrescriptionDOS1 = prescriptionDao.findByOutpatientId(wlyyPrescriptionDOS.getOutpatientId());
                if (StringUtils.isNoneBlank(sfexpress_obj.getMailno())&&wlyyPrescriptionDOS1.size()>1){
                    throw new Exception("已存在地址"+sfexpress_obj.getAddress()+"、电话"+sfexpress_obj.getMobile()+"的快递单(单号"+sfexpress_obj.getMailno()+"),请将此处方与其打包一起。");
                }
                String sql = "SELECT\n" +
                        "\tpe.outpatient_id as outpatientId,\n" +
                        "\tpe.mailno as mailno,\n" +

+ 1 - 1
business/base-service/src/main/java/com/yihu/jw/order/BusinessOrderService.java

@ -1360,7 +1360,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
        BusinessOrderDO businessOrderDO = businessOrderDao.selectByRelationCode(relationCode);
        return businessOrderDO;
    }
    public BusinessOrderDO selectStatusById(Integer id){
    public BusinessOrderDO selectStatusById(String id){
        BusinessOrderDO businessOrderDO = businessOrderDao.findOne(id);
        return businessOrderDO;
    }

+ 1 - 1
business/base-service/src/main/java/com/yihu/jw/order/dao/BusinessOrderDao.java

@ -10,7 +10,7 @@ import java.util.Date;
import java.util.List;
public interface BusinessOrderDao extends PagingAndSortingRepository<BusinessOrderDO, Integer>, JpaSpecificationExecutor<BusinessOrderDO>  {
public interface BusinessOrderDao extends PagingAndSortingRepository<BusinessOrderDO, String>, JpaSpecificationExecutor<BusinessOrderDO>  {
    @Query("from BusinessOrderDO w where w.traceNo = ?1 and w.orderNo=?2")

+ 53 - 5
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/patient/PayEndpoint.java

@ -90,7 +90,7 @@ public class PayEndpoint extends EnvelopRestEndpoint {
    @GetMapping("orderInfo")
    @ApiOperation(value = "订单详情")
    public ObjEnvelop orderInfo(@ApiParam(name = "id", value = "订单id")
                                    @RequestParam(value = "id", required = false) Integer id,
                                    @RequestParam(value = "id", required = false) String id,
                                @ApiParam(name = "orderId", value = "工单id")
                                @RequestParam(value = "orderId", required = false) String orderId) {
        try {
@ -110,7 +110,7 @@ public class PayEndpoint extends EnvelopRestEndpoint {
    @ObserverRequired
    public Envelop cancleOrder(
            @ApiParam(name = "id", value = "订单id")
            @RequestParam(value = "id", required = true) Integer id) {
            @RequestParam(value = "id", required = true) String id) {
        try{
            String res = payService.cancleOrder(id);
            if(StringUtil.isBlank(res)){
@ -163,7 +163,7 @@ public class PayEndpoint extends EnvelopRestEndpoint {
            @ApiParam(name = "relationId", value = "业务id,如生活照料id 上面辅导id")
            @RequestParam(value = "relationId", required = false) String relationId,
            @ApiParam(name = "orderId", value = "订单id")
            @RequestParam(value = "orderId", required = false) Integer orderId,HttpServletRequest request) {
            @RequestParam(value = "orderId", required = false) String orderId,HttpServletRequest request) {
        try{
            return payService.wxWapPay(relationId, orderId, request);
        }catch (Exception e){
@ -171,6 +171,54 @@ public class PayEndpoint extends EnvelopRestEndpoint {
        }
    }
    @PostMapping(value = "cloudWxPay")
    @ApiOperation(value = "云照护支付")
    @ObserverRequired
    public ObjEnvelop wxWapPay(
            @ApiParam(name = "relationCode", value = "关联表id")
            @RequestParam(value = "relationCode", required = false) String relationCode,
            @ApiParam(name = "relationName", value = "关联表名称")
            @RequestParam(value = "relationName", required = false) String relationName,
            @ApiParam(name = "orderType", value = "订单类型")
            @RequestParam(value = "orderType", required = false) String orderType,
            @ApiParam(name = "patient", value = "居民code")
            @RequestParam(value = "patient", required = false) String patient,
            @ApiParam(name = "doctor", value = "医生code")
            @RequestParam(value = "doctor", required = false) String doctor,
            @ApiParam(name = "fee", value = "费用金额")
            @RequestParam(value = "fee", required = false) String fee,
            @ApiParam(name = "depositType", value = "支付类型")
            @RequestParam(value = "depositType", required = false) String depositType,
            @ApiParam(name = "appletCode", value = "费用金额")
            @RequestParam(value = "appletCode", required = false) String appletCode) {
        try{
            return ObjEnvelop.getSuccess("请求成功",payService.cloudWxPay(relationCode,relationName,orderType,patient,doctor,fee,depositType, appletCode));
        }catch (Exception e){
            return failedObjEnvelopException2(e);
        }
    }
    @PostMapping(value = "cloudWxRefund")
    @ApiOperation(value = "云照护支付退款")
    @ObserverRequired
    public ObjEnvelop wxWapPay(
            @ApiParam(name = "orderNo", value = "订单号码")
            @RequestParam(value = "orderNo", required = false) String orderNo,
            @ApiParam(name = "refundPrice", value = "退款金额")
            @RequestParam(value = "refundPrice", required = false) Double refundPrice,
            @ApiParam(name = "description", value = "退款描述")
            @RequestParam(value = "description", required = false) String description,
            @ApiParam(name = "patient", value = "居民code")
            @RequestParam(value = "patient", required = false) String patient) {
        try{
            return ObjEnvelop.getSuccess("请求成功",payService.cloudWxRefund(patient,orderNo,refundPrice,description));
        }catch (Exception e){
            return failedObjEnvelopException2(e);
        }
    }
    @PostMapping(value = "applyRefund")
    @ApiOperation(value = "申请退款")
    @ObserverRequired
@ -180,7 +228,7 @@ public class PayEndpoint extends EnvelopRestEndpoint {
            @ApiParam(name = "enclosure", value = "退款附件")
            @RequestParam(value = "enclosure", required = false) String enclosure,
            @ApiParam(name = "id", value = "订单id")
            @RequestParam(value = "id", required = true) Integer id) {
            @RequestParam(value = "id", required = true) String id) {
        try{
            String res = payService.applyRefund(id, description, enclosure);
            if(StringUtil.isBlank(res)){
@ -199,7 +247,7 @@ public class PayEndpoint extends EnvelopRestEndpoint {
            @ApiParam(name = "relationId", value = "业务id,如生活照料id 上门辅导id")
            @RequestParam(value = "relationId", required = false) String relationId,
            @ApiParam(name = "orderId", value = "订单id")
            @RequestParam(value = "orderId", required = false) Integer orderId,HttpServletRequest request) {
            @RequestParam(value = "orderId", required = false) String orderId,HttpServletRequest request) {
        try{
            return  payService.wxNativePay(relationId, orderId, request);
        }catch (Exception e){

+ 170 - 5
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/pay/PayService.java

@ -1,6 +1,7 @@
package com.yihu.jw.care.service.pay;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.fastdfs.FastDFSUtil;
@ -13,12 +14,19 @@ import com.yihu.jw.care.service.lifeCare.LifeCareOrderService;
import com.yihu.jw.care.util.WxpayUtil;
import com.yihu.jw.care.util.XMLUtil;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.base.wx.BasePatientWechatDo;
import com.yihu.jw.entity.base.wx.WxWechatDO;
import com.yihu.jw.entity.care.common.WxPayHttpLogDO;
import com.yihu.jw.entity.care.doorCoach.BaseDoorCoachFeeDetailDO;
import com.yihu.jw.entity.care.doorCoach.BaseDoorCoachOrderDO;
import com.yihu.jw.entity.care.lifeCare.LifeCareFeeDetailDO;
import com.yihu.jw.entity.care.lifeCare.LifeCareOrderDO;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import com.yihu.jw.entity.hospital.healthCare.YlzMedicalRelationDO;
import com.yihu.jw.entity.hospital.mapping.DoctorMappingDO;
import com.yihu.jw.entity.hospital.prescription.WlyyOutpatientDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionInfoDO;
import com.yihu.jw.entity.order.BusinessOrderDO;
import com.yihu.jw.entity.order.BusinessOrderRefundDO;
import com.yihu.jw.order.BusinessOrderService;
@ -33,6 +41,8 @@ import com.yihu.jw.util.common.QrcodeUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.utils.StringUtil;
import com.yihu.jw.wechat.dao.WechatDao;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -189,7 +199,7 @@ public class PayService {
     * 订单详情接口
     * @param id
     */
    public JSONObject orderInfo(Integer id,String orderId){
    public JSONObject orderInfo(String id,String orderId){
        JSONObject resJson = new JSONObject();
        BusinessOrderDO businessOrderDO;
        if(StringUtil.isBlank(orderId)){
@ -237,7 +247,7 @@ public class PayService {
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public String applyRefund(Integer id,String description,String enclosure){
    public String applyRefund(String id,String description,String enclosure){
        BusinessOrderDO businessOrderDO = businessOrderDao.findOne(id);
        String type = businessOrderDO.getOrderCategory();
        String orderId = businessOrderDO.getRelationCode();
@ -286,7 +296,7 @@ public class PayService {
     * 取消订单
     * @param id
     */
    public String cancleOrder(Integer id){
    public String cancleOrder(String id){
        BusinessOrderDO businessOrderDO = businessOrderDao.findOne(id);
        if(businessOrderDO.getStatus()==0){
            String type = businessOrderDO.getOrderCategory();
@ -578,7 +588,7 @@ public class PayService {
     * @throws Exception
     */
    @Transactional(rollbackFor = Exception.class)
    public ObjEnvelop wxNativePay(String relationId,Integer orderId,HttpServletRequest request) throws Exception {
    public ObjEnvelop wxNativePay(String relationId,String orderId,HttpServletRequest request) throws Exception {
        BusinessOrderDO businessOrderDO;
        if(StringUtil.isBlank(relationId)){
            businessOrderDO = businessOrderDao.findOne(orderId);
@ -656,7 +666,7 @@ public class PayService {
     * @throws Exception
     */
    @Transactional(rollbackFor = Exception.class)
    public ObjEnvelop wxWapPay(String relationId,Integer orderId,HttpServletRequest request) throws Exception {
    public ObjEnvelop wxWapPay(String relationId,String orderId,HttpServletRequest request) throws Exception {
        BusinessOrderDO businessOrderDO;
        if(StringUtil.isBlank(relationId)){
            businessOrderDO = businessOrderDao.findOne(orderId);
@ -797,6 +807,161 @@ public class PayService {
        return businessOrderDO;
    }
    /**
     * 云照护微信支付
     *
     * @param relationCode
     * @param relationName
     * @param orderType
     * @param depositType
     * @return
     * @throws Exception
     */
    public Map<String,Object> cloudWxPay(String relationCode,String relationName,String orderType,String patient,String doctor,
                                         String fee,String depositType,String appletCode) throws Exception {
        try {
            WxWechatDO wxWechatDO = wechatDao.findById(wechatId);
            if(wxWechatDO==null){
                throw new Exception("can't find wechat:the wxId is "+wechatId);
            }
            BusinessOrderDO businessOrderDO = businessOrderDao.selectByRelationCode(relationCode);
            BasePatientDO patientDO = new BasePatientDO();
            if (StringUtils.isNoneBlank(patient)){
                patientDO = patientDao.findOne(patient);
            }
            if (businessOrderDO==null) {
                businessOrderDO = new BusinessOrderDO();
                businessOrderDO.setCreateTime(new Date());
                businessOrderDO.setUpdateTime(new Date());
                businessOrderDO.setStatus(0);
                businessOrderDO.setOrderNo(getOrderNo());
                businessOrderDO.setUploadStatus(0);
                businessOrderDO.setPayType(1);
                businessOrderDO.setRelationCode(relationCode);
                businessOrderDO.setRelationName(relationName);
                businessOrderDO.setOrderCategory(orderType);
                businessOrderDO.setOrderType(Integer.parseInt(orderType));
                businessOrderDO.setDoctor(doctor);
                businessOrderDO.setPatient(patient);
                businessOrderDO.setPatientName(patientDO.getName());
                String a = String.valueOf(String.format("%.2f",Double.parseDouble(fee)));
                BigDecimal b = new BigDecimal(a);
                BigDecimal c = new BigDecimal(String.valueOf(100));
                BigDecimal bc = b.multiply(c);
                businessOrderDO.setPayPrice(bc.doubleValue());
                businessOrderDO.setDescription(relationName);
                businessOrderDO = businessOrderDao.save(businessOrderDO);
            }else {
                if (businessOrderDO.getStatus()==1){
                    throw new Exception("该订单已支付过");
                }
                String a = String.valueOf(String.format("%.2f",Double.parseDouble(fee)));
                BigDecimal b = new BigDecimal(a);
                BigDecimal c = new BigDecimal(String.valueOf(100));
                BigDecimal bc = b.multiply(c);
                businessOrderDO.setPayPrice(bc.doubleValue());
                businessOrderDO = businessOrderDao.save(businessOrderDO);
            }
            Map<String,Object> map = new HashedMap();
            if(wxWechatDO==null){
                throw new Exception("can't find wechat:the wxId is "+wechatId);
            }
            if (businessOrderDO!=null){
                if (businessOrderDO.getStatus()==1){
                    throw new Exception("该处方已支付过");
                }
                String openId = "";
                if (StringUtils.isNotBlank(appletCode)){
                    log.info("appletCode不为空"+appletCode);
                    Map<String,Object> objectMap = businessOrderService.checkApplets(appletCode,wxWechatDO.getApplets(),wxWechatDO.getAppletsSecret());
                    if (objectMap!=null){
                        openId = objectMap.get("openid").toString();
                        log.info("appletCode"+appletCode);
                        log.info("openid"+openId);
                    }
                }else {
                    log.info("appletCode为空"+appletCode);
                    openId = patientDO.getOpenid();
                }
                businessOrderDO.setOrderNo(getOrderNo());
                businessOrderDO= businessOrderDao.save(businessOrderDO);
                String url = wxWechatDO.getBaseUrl();
                String notifyUrl =url;
                String totalFee =businessOrderDO.getPayPrice().intValue()+"";
                map = businessOrderService.unifiedorder(wechatId,businessOrderDO.getDescription(),totalFee, depositType,openId,businessOrderDO.getOrderNo(),notifyUrl,businessOrderDO.getPatient());
            }
            return map;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
    /**
     * 云照护支付退款
     * @param wechatId
     * @param patient
     * @param orderNo
     * @param refundPrice
     * @param description
     * @return
     * @throws Exception
     */
    public Map<String,Object> cloudWxRefund(String patient,String orderNo,Double refundPrice,String description) throws Exception {
        WxWechatDO wxWechatDO = wechatDao.findById(wechatId);
        if (wxWechatDO==null){
            throw new Exception("this wechatId is null");
        }
        BusinessOrderDO businessOrderDO = businessOrderDao.selectByOrderNo(orderNo);
        if (businessOrderDO==null){
            throw new Exception("this orderId not exit");
        }
        BasePatientDO patientDO = patientDao.findById(patient);
        if (patientDO==null){
            throw new Exception("this patient not exit");
        }
        BusinessOrderRefundDO orderRefundDO = orderRefundDao.selectByOrderNo(orderNo);
        if (orderRefundDO==null){
            orderRefundDO = new BusinessOrderRefundDO();
        }
        orderRefundDO.setCreateTime(new Date());
        orderRefundDO.setUpdateTime(new Date());
        orderRefundDO.setStatus(1);
        orderRefundDO.setOrderNo(orderNo);
        orderRefundDO.setOrderPrice(businessOrderDO.getPayPrice());
        orderRefundDO.setRefundPrice(refundPrice);
        orderRefundDO.setAppId(wxWechatDO.getAppId());
        orderRefundDO.setMchId(wxWechatDO.getMchId());
        orderRefundDO.setOutRefundNo("HLWYY"+businessOrderDO.getOrderType()+System.currentTimeMillis()+(int)(Math.random()*900)+100);
        orderRefundDO.setPatient(patient);
        orderRefundDO.setPatientName(patientDO.getName());
        orderRefundDO.setRefundDesc(description);
        orderRefundDO = orderRefundDao.save(orderRefundDO);
        Integer orderPrice = orderRefundDO.getOrderPrice().intValue();
        Integer refundPrice1 = orderRefundDO.getRefundPrice().intValue();
        Map<String,Object> map = businessOrderService.refund(wechatId,orderRefundDO.getOrderNo(),orderRefundDO.getOutRefundNo(),orderPrice.toString(),refundPrice1.toString(),orderRefundDO.getRefundDesc());
        log.info("map"+map);
        if (map.get("return_code").toString().equalsIgnoreCase("SUCCESS")){
            if (map.get("result_code").toString().equalsIgnoreCase("FAIL")){
                orderRefundDO.setStatus(10);
                orderRefundDO.setRefundTime(new Date());
                orderRefundDO.setRefundDesc(map.get("err_code_des").toString());
                orderRefundDao.save(orderRefundDO);
            }else {
                orderRefundDO.setStatus(2);
                orderRefundDO.setRefundTime(new Date());
                orderRefundDao.save(orderRefundDO);
            }
        }else if (map.get("return_code").toString().equalsIgnoreCase("CLOSED")||map.get("return_code").toString().equalsIgnoreCase("ABNORMAL")||map.get("return_code").toString().equalsIgnoreCase("PROCESSING")){
            orderRefundDO.setStatus(10);
            orderRefundDO.setRefundTime(new Date());
            orderRefundDao.save(orderRefundDO);
        }
        return map;
    }
    public String getOrderNo(){
        return ""+System.currentTimeMillis()+(int)(Math.random()*900)+100;
    }

+ 1 - 1
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/prescription/PrescriptionEndpoint.java

@ -2266,7 +2266,7 @@ public class PrescriptionEndpoint extends EnvelopRestEndpoint {
    @ApiOperation("查询支付状态")
    public ObjEnvelop selectOrderStatusById(
            @ApiParam(name = "id", value = "订单id", required = true)
            @RequestParam(required = true) Integer id) throws Exception {
            @RequestParam(required = true) String id) throws Exception {
        try {
            return ObjEnvelop.getSuccess("ok", businessOrderService.selectStatusById(id));
        } catch (Exception e) {