|
@ -1,6 +1,7 @@
|
|
package com.yihu.jw.care.service.pay;
|
|
package com.yihu.jw.care.service.pay;
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
import com.yihu.fastdfs.FastDFSUtil;
|
|
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.WxpayUtil;
|
|
import com.yihu.jw.care.util.XMLUtil;
|
|
import com.yihu.jw.care.util.XMLUtil;
|
|
import com.yihu.jw.entity.base.patient.BasePatientDO;
|
|
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.base.wx.WxWechatDO;
|
|
import com.yihu.jw.entity.care.common.WxPayHttpLogDO;
|
|
import com.yihu.jw.entity.care.common.WxPayHttpLogDO;
|
|
import com.yihu.jw.entity.care.doorCoach.BaseDoorCoachFeeDetailDO;
|
|
import com.yihu.jw.entity.care.doorCoach.BaseDoorCoachFeeDetailDO;
|
|
import com.yihu.jw.entity.care.doorCoach.BaseDoorCoachOrderDO;
|
|
import com.yihu.jw.entity.care.doorCoach.BaseDoorCoachOrderDO;
|
|
import com.yihu.jw.entity.care.lifeCare.LifeCareFeeDetailDO;
|
|
import com.yihu.jw.entity.care.lifeCare.LifeCareFeeDetailDO;
|
|
import com.yihu.jw.entity.care.lifeCare.LifeCareOrderDO;
|
|
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.BusinessOrderDO;
|
|
import com.yihu.jw.entity.order.BusinessOrderRefundDO;
|
|
import com.yihu.jw.entity.order.BusinessOrderRefundDO;
|
|
import com.yihu.jw.order.BusinessOrderService;
|
|
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.util.date.DateUtil;
|
|
import com.yihu.jw.utils.StringUtil;
|
|
import com.yihu.jw.utils.StringUtil;
|
|
import com.yihu.jw.wechat.dao.WechatDao;
|
|
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.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@ -189,7 +199,7 @@ public class PayService {
|
|
* 订单详情接口
|
|
* 订单详情接口
|
|
* @param id
|
|
* @param id
|
|
*/
|
|
*/
|
|
public JSONObject orderInfo(Integer id,String orderId){
|
|
|
|
|
|
public JSONObject orderInfo(String id,String orderId){
|
|
JSONObject resJson = new JSONObject();
|
|
JSONObject resJson = new JSONObject();
|
|
BusinessOrderDO businessOrderDO;
|
|
BusinessOrderDO businessOrderDO;
|
|
if(StringUtil.isBlank(orderId)){
|
|
if(StringUtil.isBlank(orderId)){
|
|
@ -237,7 +247,7 @@ public class PayService {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@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);
|
|
BusinessOrderDO businessOrderDO = businessOrderDao.findOne(id);
|
|
String type = businessOrderDO.getOrderCategory();
|
|
String type = businessOrderDO.getOrderCategory();
|
|
String orderId = businessOrderDO.getRelationCode();
|
|
String orderId = businessOrderDO.getRelationCode();
|
|
@ -286,7 +296,7 @@ public class PayService {
|
|
* 取消订单
|
|
* 取消订单
|
|
* @param id
|
|
* @param id
|
|
*/
|
|
*/
|
|
public String cancleOrder(Integer id){
|
|
|
|
|
|
public String cancleOrder(String id){
|
|
BusinessOrderDO businessOrderDO = businessOrderDao.findOne(id);
|
|
BusinessOrderDO businessOrderDO = businessOrderDao.findOne(id);
|
|
if(businessOrderDO.getStatus()==0){
|
|
if(businessOrderDO.getStatus()==0){
|
|
String type = businessOrderDO.getOrderCategory();
|
|
String type = businessOrderDO.getOrderCategory();
|
|
@ -578,7 +588,7 @@ public class PayService {
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@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;
|
|
BusinessOrderDO businessOrderDO;
|
|
if(StringUtil.isBlank(relationId)){
|
|
if(StringUtil.isBlank(relationId)){
|
|
businessOrderDO = businessOrderDao.findOne(orderId);
|
|
businessOrderDO = businessOrderDao.findOne(orderId);
|
|
@ -656,7 +666,7 @@ public class PayService {
|
|
* @throws Exception
|
|
* @throws Exception
|
|
*/
|
|
*/
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@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;
|
|
BusinessOrderDO businessOrderDO;
|
|
if(StringUtil.isBlank(relationId)){
|
|
if(StringUtil.isBlank(relationId)){
|
|
businessOrderDO = businessOrderDao.findOne(orderId);
|
|
businessOrderDO = businessOrderDao.findOne(orderId);
|
|
@ -797,6 +807,161 @@ public class PayService {
|
|
return businessOrderDO;
|
|
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(){
|
|
public String getOrderNo(){
|
|
return ""+System.currentTimeMillis()+(int)(Math.random()*900)+100;
|
|
return ""+System.currentTimeMillis()+(int)(Math.random()*900)+100;
|
|
}
|
|
}
|