| 
					
				 | 
			
			
				@ -2,11 +2,14 @@ package com.yihu.jw.base.service.order; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.patient.BasePatientDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.common.WxPayHttpLogDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				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.pay.dao.WxPayHttpLogDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.pay.service.CloudCarePayService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.restmodel.ResponseContant; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.restmodel.web.PageEnvelop; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -14,10 +17,12 @@ import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				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 java.math.BigDecimal; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -38,6 +43,12 @@ public class PayService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BasePatientDao patientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private CloudCarePayService payService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BusinessOrderService businessOrderService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Value("${wechat.id}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String wechatId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private WxPayHttpLogDao wxPayHttpLogDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 订单列表 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -99,8 +110,8 @@ public class PayService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    Integer page,Integer pageSize){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        page = page>0?page-1:0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = " select pay.patient,pay.patient_name,pay.order_no,pay.order_type,pay.order_category,pay.relation_code, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " pay.relation_name,pay.description,pay.pay_type,pay.pay_price,pay.yk_order_id,DATE_FORMAT(re.create_time,'%Y-%m-%d %H:%i:%S') create_time, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " re.enclosure,re.refund_desc,re.`status` from base_business_order_pay pay inner JOIN base_business_order_refund re on  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " pay.relation_name,pay.description payDescription,pay.pay_type,pay.pay_price,pay.yk_order_id,DATE_FORMAT(re.create_time,'%Y-%m-%d %H:%i:%S') create_time, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " re.enclosure,re.refund_desc description,re.refuse_desc,re.`status` from base_business_order_pay pay inner JOIN base_business_order_refund re on  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " pay.order_no = re.order_no where pay.status>=3  "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sqlCount = "select count(re.id) from base_business_order_pay pay inner JOIN " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " base_business_order_refund re on pay.order_no = re.order_no where pay.status>=3 "; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -205,16 +216,37 @@ public class PayService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        businessOrderDO.setStatus(4); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        businessOrderRefundDO.setStatus(3); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //退款流程 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        payService.orderRefund(orderNo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        businessOrderRefundDO.setStatus(2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        businessOrderDao.save(businessOrderDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        businessOrderRefundDao.save(businessOrderRefundDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //退款流程 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Integer orderPrice = new BigDecimal(businessOrderRefundDO.getOrderPrice()*100).intValue(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Integer refundPrice1 = new BigDecimal(businessOrderRefundDO.getRefundPrice()*100).intValue(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Map<String,Object> map = businessOrderService.refund(wechatId,businessOrderRefundDO.getOrderNo(),businessOrderRefundDO.getOutRefundNo(),orderPrice.toString(),refundPrice1.toString(),businessOrderRefundDO.getRefundDesc()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        log.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()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put(ResponseContant.resultFlag, ResponseContant.fail); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put(ResponseContant.resultMsg, "success"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 添加支付日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |