|  | @ -1,8 +1,9 @@
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | package com.yihu.jw.order;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONArray;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.patient.BasePatientDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.servicePackage.ServicePackageSignRecordDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.wx.BasePatientWechatDo;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.wx.WxPayLogDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.wx.WxWechatDO;
 | 
	
	
		
			
				|  | @ -17,24 +18,18 @@ import com.yihu.jw.order.dao.BusinessOrderDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.order.dao.BusinessOrderRefundDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.order.pay.wx.WeChatConfig;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.dao.BasePatientDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.rm.base.BaseRequestMapping;
 | 
	
		
			
				|  |  | import com.yihu.jw.rm.hospital.BaseHospitalRequestMapping;
 | 
	
		
			
				|  |  | import com.yihu.jw.rm.patient.PatientRequestMapping;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.yihu.jw.util.common.XMLUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.date.DateUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.wechat.WeiXinPayUtils;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.wechat.wxhttp.HttpUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.utils.StringUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.wechat.dao.BasePatientWechatDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.wechat.dao.WechatDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.wechat.dao.WxPayLogDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.wechat.service.WxPayLogService;
 | 
	
		
			
				|  |  | import org.apache.commons.collections.map.HashedMap;
 | 
	
		
			
				|  |  | import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | import org.checkerframework.checker.units.qual.A;
 | 
	
		
			
				|  |  | import org.json.JSONObject;
 | 
	
		
			
				|  |  | 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.stereotype.Service;
 | 
	
		
			
				|  |  | import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -49,6 +44,8 @@ import java.util.*;
 | 
	
		
			
				|  |  | @Service
 | 
	
		
			
				|  |  | public class BusinessOrderService {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private Logger logger = LoggerFactory.getLogger(BusinessOrderService.class);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BusinessOrderDao businessOrderDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
	
		
			
				|  | @ -79,6 +76,7 @@ public class BusinessOrderService {
 | 
	
		
			
				|  |  |         businessOrderDO.setUpdateTime(new Date());
 | 
	
		
			
				|  |  |         businessOrderDO.setStatus(0);
 | 
	
		
			
				|  |  |         businessOrderDO.setOrderNo("VAS"+businessOrderDO.getOrderType()+System.currentTimeMillis());
 | 
	
		
			
				|  |  |         businessOrderDO.setUploadStatus(0);
 | 
	
		
			
				|  |  |         businessOrderDO = businessOrderDao.save(businessOrderDO);
 | 
	
		
			
				|  |  |         String patient = businessOrderDO.getPatient();
 | 
	
		
			
				|  |  |         BasePatientDO basePatientDO = patientDao.findById(patient);
 | 
	
	
		
			
				|  | @ -94,7 +92,21 @@ public class BusinessOrderService {
 | 
	
		
			
				|  |  |         String orderCatagrate = businessOrderDO.getOrderCategory();
 | 
	
		
			
				|  |  |         String pcCallBack=businessOrderDO.getPcCallbackUrl();
 | 
	
		
			
				|  |  |         String appCallBack = businessOrderDO.getAppCallbackUrl();
 | 
	
		
			
				|  |  |         ykyyService.addYktOrder(orderNo,patientId,orderAmout,description,state,orderType,doctorMappingDO.getMappingCode(),payType,null,patientTel,orderCatagrate,pcCallBack,appCallBack);
 | 
	
		
			
				|  |  |         String doctorResponse = ykyyService.getYktDoctor(doctorMappingDO.getMappingCode());
 | 
	
		
			
				|  |  |         String yktDoctor ="";
 | 
	
		
			
				|  |  |         JSONObject jsonObject = JSONObject.parseObject(doctorResponse);
 | 
	
		
			
				|  |  |         if (jsonObject.getInteger("code")==200){
 | 
	
		
			
				|  |  |             JSONArray array = jsonObject.getJSONArray("data");
 | 
	
		
			
				|  |  |             if (array!=null&&array.size()!=0){
 | 
	
		
			
				|  |  |                 yktDoctor=array.getJSONObject(0).getString("DOCTORUSERID");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String response=ykyyService.addYktOrder(orderNo,patientId,orderAmout,description,state,orderType,yktDoctor,payType,null,patientTel,orderCatagrate,pcCallBack,appCallBack);
 | 
	
		
			
				|  |  |         JSONObject object = JSONObject.parseObject(response);
 | 
	
		
			
				|  |  |         if (object.getInteger("code")==200){
 | 
	
		
			
				|  |  |             businessOrderDO.setUploadStatus(1);
 | 
	
		
			
				|  |  |             businessOrderDao.save(businessOrderDO);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return businessOrderDO;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -136,7 +148,7 @@ public class BusinessOrderService {
 | 
	
		
			
				|  |  |         String pcCallBack=businessOrderDO.getPcCallbackUrl();
 | 
	
		
			
				|  |  |         String appCallBack = businessOrderDO.getAppCallbackUrl();
 | 
	
		
			
				|  |  |         String url = wxWechatDO.getBaseUrl();
 | 
	
		
			
				|  |  |         String notifyUrl =url+"/ykyy"+BaseHospitalRequestMapping.WxPay.Notify;
 | 
	
		
			
				|  |  |         String notifyUrl =url;
 | 
	
		
			
				|  |  |         Map<String,Object> map = unifiedorder(wechatId,description,businessOrderDO.getPayPrice().toString(),WeChatConfig.TRADE_TYPE_JSAPI,openId,orderNo,notifyUrl);
 | 
	
		
			
				|  |  |         String doctorId = "";
 | 
	
		
			
				|  |  |         if (doctorMappingDO!=null){
 | 
	
	
		
			
				|  | @ -197,7 +209,7 @@ public class BusinessOrderService {
 | 
	
		
			
				|  |  |         String ourTradeNo = businessOrderDO.getOrderNo();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String url = wxWechatDO.getBaseUrl();
 | 
	
		
			
				|  |  |         String notifyUrl =url+"/ykyy"+BaseHospitalRequestMapping.WxPay.Notify;
 | 
	
		
			
				|  |  |         String notifyUrl =url;
 | 
	
		
			
				|  |  |         Map<String,Object> map = unifiedorder(wechatId,body,totalFee,WeChatConfig.TRADE_TYPE_JSAPI,openid,ourTradeNo,notifyUrl);
 | 
	
		
			
				|  |  |         return map;
 | 
	
		
			
				|  |  |     }
 | 
	
	
		
			
				|  | @ -214,7 +226,6 @@ public class BusinessOrderService {
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      * @throws Exception
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |     public  Map<String,Object> unifiedorder(String wechatId,String body,String totalFee,String tradeType,String openId,String ourTradeNo,String notifyUrl) throws Exception {
 | 
	
		
			
				|  |  |         WxWechatDO wxWechatDO = wechatDao.findById(wechatId);
 | 
	
		
			
				|  |  |         if(wxWechatDO==null){
 | 
	
	
		
			
				|  | @ -240,6 +251,7 @@ public class BusinessOrderService {
 | 
	
		
			
				|  |  |         map.put("mch_id",wxWechatDO.getMchId());
 | 
	
		
			
				|  |  |         map.put("body",body);
 | 
	
		
			
				|  |  |         map.put("out_trade_no",ourTradeNo);
 | 
	
		
			
				|  |  |         map.put("fee_type","CNY");
 | 
	
		
			
				|  |  |         map.put("total_fee",totalFee);
 | 
	
		
			
				|  |  |         map.put("spbill_create_ip",getServerIp());
 | 
	
		
			
				|  |  |         map.put("notify_url",notifyUrl);
 | 
	
	
		
			
				|  | @ -257,6 +269,7 @@ public class BusinessOrderService {
 | 
	
		
			
				|  |  |             String result1 = HttpUtil.sendGet(openidList_url, params1);
 | 
	
		
			
				|  |  |             JSONObject json1 = new JSONObject(result1);
 | 
	
		
			
				|  |  |         }*/
 | 
	
		
			
				|  |  |         logger.info("map:"+map.toString());
 | 
	
		
			
				|  |  |         Map<String, Object> pay = unifiedorder(map, wxWechatDO.getAppKey());
 | 
	
		
			
				|  |  |         String returnCode = pay.get("return_code").toString();
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -267,12 +280,11 @@ public class BusinessOrderService {
 | 
	
		
			
				|  |  |             String prepayId = pay.get("prepay_id").toString();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             Map<String,String> param = new HashedMap();
 | 
	
		
			
				|  |  |             param.put("appid",appid);
 | 
	
		
			
				|  |  |             param.put("partnerid",mchId);
 | 
	
		
			
				|  |  |             param.put("prepayid",prepayId);
 | 
	
		
			
				|  |  |             param.put("package","Sign=WXPay");
 | 
	
		
			
				|  |  |             param.put("noncestr",nonceStr);
 | 
	
		
			
				|  |  |             param.put("timestamp",getTimeStamp());
 | 
	
		
			
				|  |  |             param.put("appId",appid);
 | 
	
		
			
				|  |  |             param.put("package","prepay_id="+prepayId);
 | 
	
		
			
				|  |  |             param.put("nonceStr",nonceStr);
 | 
	
		
			
				|  |  |             param.put("signType","MD5");
 | 
	
		
			
				|  |  |             param.put("timeStamp",getTimeStamp());
 | 
	
		
			
				|  |  |             param = WeiXinPayUtils.getMapAfterUnifiedorder(param,wxWechatDO.getAppKey());
 | 
	
		
			
				|  |  |             pay.put("jsapi",param);
 | 
	
		
			
				|  |  |         }
 |