| 
					
				 | 
			
			
				@ -0,0 +1,555 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				package com.yihu.jw.care.service.pay; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.fasterxml.jackson.databind.node.ObjectNode; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.fastdfs.FastDFSUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.doorCoach.BaseDoorCoachFeeDetailDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.doorCoach.BaseDoorCoachOrderDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.lifeCare.LifeCareFeeDetailDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.lifeCare.LifeCareOrderDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.pay.WxPayHttpLogDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.service.doorCoach.PatientDoorCoachOrderService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				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.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.order.BusinessOrderDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.order.BusinessOrderRefundDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.order.BusinessOrderService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.order.dao.BusinessOrderDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.order.dao.BusinessOrderRefundDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.patient.dao.BasePatientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.restmodel.ResponseContant; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.restmodel.web.ObjEnvelop; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.common.IpUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				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.slf4j.Logger; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.LoggerFactory; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Value; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.jdbc.core.JdbcTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.transaction.annotation.Transactional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.util.Assert; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import javax.servlet.http.HttpServletRequest; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.io.InputStream; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import static jxl.biff.FormatRecord.logger; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * Created with IntelliJ IDEA. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * 支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * @Author: yeshijie 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * @Date: 2021/6/28 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * @Description: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				@Service 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				public class PayService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private Logger log = LoggerFactory.getLogger(PatientDoorCoachOrderService.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BasePatientDao patientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BusinessOrderDao businessOrderDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Value("${wechat.id}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String wechatId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Value("${wechat.appId}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String appId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Value("${wechat.mchId}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String mchId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Value("${wechat.apiKey}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String apiKey; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Value("${wechat.wechat_base_url}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String serverUrl; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private WxPayHttpLogDao wxPayHttpLogDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private FastDFSUtil fastDFSUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BusinessOrderService businessOrderService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private WechatDao wechatDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BusinessOrderRefundDao orderRefundDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private LifeCareOrderService lifeCareOrderService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private LifeCareOrderDao lifeCareOrderDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private PatientDoorCoachOrderService doorCoachOrderService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BaseDoorCoachOrderDao baseDoorCoachOrderDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Value("${fastDFS.fastdfs_file_url}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String fastdfs_file_url; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private JdbcTemplate jdbcTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private LifeCareFeeDetailDao lifeCareFeeDetailDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BaseDoorCoachFeeDetailDao doorCoachFeeDetailDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 顶部状态栏订单各分类总条数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 0待支付、1已支付、2已取消、3申请退款中、4已售后 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param patient 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public Map<String, Integer> topStatusBarNum(String patient) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "SELECT a.`status`,COUNT(*) num from base_business_order_pay a  where patient = '"+patient+"' " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "GROUP BY a.`status` " ; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Map<String, Integer> map = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //状态 0待支付、1已支付、2已取消、3申请退款中、4已售后 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        map.put("0",0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        map.put("1",0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        map.put("2",0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        map.put("3",0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        map.put("4",0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        int total = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(list.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (Map<String, Object> one:list){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                map.put(String.valueOf(one.get("status")), Integer.valueOf(String.valueOf(one.get("num")))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                total+=Integer.valueOf(String.valueOf(one.get("num"))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        map.put("total", total); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 居民我的订单列表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param patient 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param status 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param page 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param size 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject orderList(String patient, String status, int page, int size) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject result = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        int start = 0 == page ? page++ : (page - 1) * size; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        int end = 0 == size ? 15 : size; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String filter = " where patient = '"+patient+"' "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(!StringUtil.isEmpty(status)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            filter += " and status = "+ status +" "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "select a.id,a.patient,a.patient_name patientName,a.order_no orderNo,a.status, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "DATE_FORMAT(a.create_time,'%Y-%m-%d %H:%i:%s') createTime " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ",a.order_category orderCategory,a.relation_code relationCode,a.relation_name relationName " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ",a.pay_type payType,a.pay_price payPrice from base_business_order_pay a " + filter ; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         sql += " ORDER BY a.create_time desc " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " LIMIT {start},{end};"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String finalSql = sql.replace("{start}", String.valueOf(start)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                .replace("{end}", String.valueOf(end)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String countSql = "SELECT  count(a.id)  FROM  base_business_order_pay a" + filter ; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String,Object>> sqlResultlist; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sqlResultlist = jdbcTemplate.queryForList(finalSql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put(ResponseContant.resultFlag, ResponseContant.fail); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put(ResponseContant.resultMsg, "从数据库查询工单列表信息失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Long count; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            count = jdbcTemplate.queryForObject(countSql, Long.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put(ResponseContant.resultFlag, ResponseContant.fail); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put(ResponseContant.resultMsg, "从数据库统计工单数量失败" ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put(ResponseContant.resultFlag, ResponseContant.success); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put(ResponseContant.resultMsg, sqlResultlist); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject countItem = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        countItem.put("count", count); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.putAll(countItem); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 订单详情接口 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject orderInfo(Integer id){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject resJson = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        resJson.put("id",id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BusinessOrderDO businessOrderDO = businessOrderDao.findOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String type = businessOrderDO.getOrderCategory(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        resJson.put("orderCategory",type); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        resJson.put("orderNo",businessOrderDO.getOrderNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        resJson.put("payPrice",businessOrderDO.getPayPrice()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        resJson.put("payTime", DateUtil.dateToStrLong(businessOrderDO.getPayTime())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        resJson.put("createTime",DateUtil.dateToStrLong(businessOrderDO.getCreateTime())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        resJson.put("status",businessOrderDO.getStatus()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        resJson.put("updateTime",DateUtil.dateToStrLong(businessOrderDO.getUpdateTime())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if("3".equals(type)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<BaseDoorCoachFeeDetailDO> feeDetailDOList = doorCoachFeeDetailDao.findByOrderId(businessOrderDO.getRelationCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            resJson.put("fees",feeDetailDOList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else if("4".equals(type)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<LifeCareFeeDetailDO> feeDetailDOList = lifeCareFeeDetailDao.findByOrderId(businessOrderDO.getRelationCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            resJson.put("fees",feeDetailDOList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return resJson; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void applyRefund(Integer id,String content,String imgs){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 取消订单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String cancleOrder(Integer id){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BusinessOrderDO businessOrderDO = businessOrderDao.findOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(businessOrderDO.getStatus()==0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String type = businessOrderDO.getOrderCategory(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String orderId = businessOrderDO.getRelationCode(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if("3".equals(type)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                BaseDoorCoachOrderDO orderDO = baseDoorCoachOrderDao.findOne(orderId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if(orderDO.getStatus()==0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    orderDO.setStatus(-1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    baseDoorCoachOrderDao.save(orderDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            }else if("4".equals(type)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                LifeCareOrderDO orderDO = lifeCareOrderDao.findOne(orderId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if(orderDO.getStatus()==0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    orderDO.setStatus(-1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    lifeCareOrderDao.save(orderDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            businessOrderDO.setUpdateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            businessOrderDao.save(businessOrderDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return "只有待支付的订单才能取消"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 微信退款 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param orderNo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param description 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @throws Exception 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void orderRefund(String orderNo,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(businessOrderDO.getPatient()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        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(businessOrderDO.getPayPrice()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        orderRefundDO.setAppId(wxWechatDO.getAppId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        orderRefundDO.setMchId(wxWechatDO.getMchId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        orderRefundDO.setOutRefundNo("CARE"+businessOrderDO.getOrderType()+System.currentTimeMillis()+(int)(Math.random()*900)+100); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        orderRefundDO.setPatient(businessOrderDO.getPatient()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        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()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        logger.info("map"+map); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        addHttpLog("1",businessOrderDO.getOrderNo(),null,map.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (map.get("return_code").toString().equalsIgnoreCase("SUCCESS")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //退款申请提交成功 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new Exception(map.get("return_msg").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 添加支付日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param type 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param orderNo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param res 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param req 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void addHttpLog(String type,String orderNo,String res,String req){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        WxPayHttpLogDO logDO = new WxPayHttpLogDO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        logDO.setType(type); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        logDO.setOrderNo(orderNo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        logDO.setOrderReq(req); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        logDO.setOrderRes(res); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        wxPayHttpLogDao.save(logDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 支付成功处理 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void payNotify(BusinessOrderDO orderDO) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        log.error("【支付通知】请求,payWater:{}", orderDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String type = orderDO.getOrderCategory(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //防止重复支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (orderDO.getStatus()!=0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        switch (type){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            case "1": 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //desc = "招生报名"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            case "2": 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //desc = "课程报名"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            case "3": 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //desc = "上门辅导"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                doorCoachOrderService.payOrderAfter(orderDO.getRelationCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            case "4": 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //desc = "生活照料服务"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                lifeCareOrderService.payOrderAfter(orderDO.getRelationCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            default: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        orderDO.setStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        orderDO.setPayType(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        orderDO.setPayTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        businessOrderDao.save(orderDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 微信navite统一下单接口 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return prepayId 微信预支付交易会话标识,该值有效期为2小时 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @throws Exception 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public ObjEnvelop wxNativePay(String relationId,Integer orderId,HttpServletRequest request) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BusinessOrderDO businessOrderDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtil.isBlank(relationId)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            businessOrderDO = businessOrderDao.findOne(orderId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            businessOrderDO = businessOrderDao.selectByRelationCode(relationId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Assert.notNull(businessOrderDO, "支付流水不存在"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (businessOrderDO.getStatus()!=0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return ObjEnvelop.getError("待支付订单才能支付",-1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        businessOrderDO.setOrderNo(getOrderNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String noceStr = WxpayUtil.getNonceStr(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 组装统一下单信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        SortedMap<String, String> reqMap = new TreeMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String title = businessOrderDO.getDescription(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        reqMap.put("appid", appId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        reqMap.put("attach", title); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        reqMap.put("body", title); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 微信支付分配的商户号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        reqMap.put("mch_id", mchId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        reqMap.put("nonce_str", noceStr); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 此路径是微信服务器调用支付结果通知路径 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        reqMap.put("notify_url", serverUrl+"pay/open/wxPayNotify"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        reqMap.put("out_trade_no", businessOrderDO.getOrderNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        reqMap.put("spbill_create_ip", IpUtil.getIpAddr(request)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        reqMap.put("product_id", businessOrderDO.getOrderNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 订单总金额,单位为分 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Double payAmountIntValue = businessOrderDO.getPayPrice() * 100; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        reqMap.put("total_fee", String.valueOf(payAmountIntValue.intValue())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        reqMap.put("trade_type", "NATIVE"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 创建第一次签名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        log.error("第一次签名: " + reqMap.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sign = WxpayUtil.createSign(reqMap, apiKey); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        log.error("【微信支付】签名:{}", sign); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        reqMap.put("sign", sign); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 调用微信统一下单返回的值 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        log.error("第二次签名: " + reqMap.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String result = WxpayUtil.createUnifiedorder(reqMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        log.error("【微信支付】统一下单响应:{}", result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //调用统一接口返回的值转换为XML格式 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Map<String, String> map = XMLUtil.doXMLParse(result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        addHttpLog("1",businessOrderDO.getOrderNo(),reqMap.toString(),result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if ("SUCCESS".equals(map.get("return_code"))) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String code_url = map.get("code_url"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //生成二维码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            InputStream ipt = QrcodeUtil.createQrcode(code_url, 300, "png"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String fileUrl=""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ObjectNode imgNode = fastDFSUtil.upload(ipt, "png", "wx_pay_qrcode" + System.currentTimeMillis()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject json = JSONObject.parseObject(imgNode.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                fileUrl = json.getString("fileId"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            businessOrderDao.save(businessOrderDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return ObjEnvelop.getSuccess("下单成功",fastdfs_file_url+fileUrl); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return ObjEnvelop.getError(map.get("return_msg"),-1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 微信统一下单接口 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return prepayId 微信预支付交易会话标识,该值有效期为2小时 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @throws Exception 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public ObjEnvelop wxWapPay(String relationId,Integer orderId,HttpServletRequest request) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BusinessOrderDO businessOrderDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtil.isBlank(relationId)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            businessOrderDO = businessOrderDao.findOne(orderId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            businessOrderDO = businessOrderDao.selectByRelationCode(relationId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Assert.notNull(businessOrderDO, "支付流水不存在"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (businessOrderDO.getStatus()!=0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return ObjEnvelop.getError("待支付订单才能支付",-1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BasePatientDO patientDO = patientDao.findById(businessOrderDO.getPatient()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        businessOrderDO.setOrderNo(getOrderNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String noceStr = WxpayUtil.getNonceStr(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 组装统一下单信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        SortedMap<String, String> reqMap = new TreeMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String title = businessOrderDO.getDescription(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        reqMap.put("appid", appId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        reqMap.put("attach", title); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        reqMap.put("body", title); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 微信支付分配的商户号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        reqMap.put("mch_id", mchId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        reqMap.put("nonce_str", noceStr); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 此路径是微信服务器调用支付结果通知路径 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        reqMap.put("notify_url", serverUrl+"pay/open/wxPayNotify"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        reqMap.put("out_trade_no", businessOrderDO.getOrderNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        reqMap.put("spbill_create_ip", IpUtil.getIpAddr(request)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        reqMap.put("product_id", businessOrderDO.getOrderNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 订单总金额,单位为分 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Double payAmountIntValue = businessOrderDO.getPayPrice() * 100; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        reqMap.put("total_fee", String.valueOf(payAmountIntValue.intValue())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        reqMap.put("trade_type", "JSAPI"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        reqMap.put("openid", patientDO.getOpenid()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 创建第一次签名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        log.error("第一次签名: " + reqMap.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sign = WxpayUtil.createSign(reqMap, apiKey); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        log.error("【微信支付】签名:{}", sign); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        reqMap.put("sign", sign); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 调用微信统一下单返回的值 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        log.error("第二次签名: " + reqMap.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String result = WxpayUtil.createUnifiedorder(reqMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        addHttpLog("1",businessOrderDO.getOrderNo(),reqMap.toString(),result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        log.error("【微信支付】统一下单响应:{}", result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //调用统一接口返回的值转换为XML格式 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Map<String, String> map = XMLUtil.doXMLParse(result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (!"SUCCESS".equals(map.get("return_code"))) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return ObjEnvelop.getError(map.get("return_msg"),-1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        log.error("【微信支付】统一下单成功:" + map); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 下单返回预支付交易会话标识 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String prepayId = map.get("prepay_id"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 返回app调起支付订单信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        TreeMap<String, String> payMap = new TreeMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        payMap.put("appId", appId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        payMap.put("package", "prepay_id=" + prepayId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        payMap.put("signType", "MD5"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        payMap.put("nonceStr", noceStr); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        payMap.put("timeStamp", WxpayUtil.getTimeStamp()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 二次签名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String paySign = WxpayUtil.createSign(payMap, apiKey); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        payMap.put("paySign", paySign); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        log.error("【微信支付】WAP支付订单信息:{}", payMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        businessOrderDao.save(businessOrderDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return ObjEnvelop.getSuccess("下单成功",payMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 提交支付订单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 订单类型 1招生,2 课程,3 上门辅导托幼) 4 生活照料 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public BusinessOrderDO submitOrder(String patientId,String type,String relationCode,Double price){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BasePatientDO pateint = patientDao.findById(patientId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BusinessOrderDO businessOrderDO = new BusinessOrderDO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        businessOrderDO.setPatient(pateint.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //支付账号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        businessOrderDO.setYkOrderId(pateint.getMobile()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        businessOrderDO.setPatientName(pateint.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        businessOrderDO.setOrderType(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        businessOrderDO.setOrderCategory(type); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String desc; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String relateName; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        switch (type){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            case "1": 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                desc = "招生报名费"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                relateName = "招生报名"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            case "2": 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                desc = "课程报名费"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                relateName = "课程报名"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            case "3": 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                desc = "上门辅导服务项目费"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                relateName = "上门辅导"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            case "4": 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                desc = "生活照料服务项目费"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                relateName = "生活照料"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            default: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                desc = "服务费"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                relateName = "服务"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        businessOrderDO.setDescription(desc); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        businessOrderDO.setRelationCode(relationCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        businessOrderDO.setRelationName(relateName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        businessOrderDO.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        businessOrderDO.setUpdateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        businessOrderDO.setStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        businessOrderDO.setOrderNo(getOrderNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        businessOrderDO.setUploadStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        businessOrderDO.setPayType(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        businessOrderDO.setPayPrice(Double.valueOf(price)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        businessOrderService.save(businessOrderDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return businessOrderDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String getOrderNo(){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return ""+System.currentTimeMillis()+(int)(Math.random()*900)+100; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |