|
|
@ -1,11 +1,27 @@ |
|
|
|
package com.ynxbd.common.service; |
|
|
|
package com.ynxbd.common.service; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
|
|
|
import com.ynxbd.common.bean.enums.MerchantEnum; |
|
|
|
|
|
|
|
import com.ynxbd.common.bean.pay.Order; |
|
|
|
import com.ynxbd.common.bean.pay.Recipe; |
|
|
|
import com.ynxbd.common.bean.pay.Recipe; |
|
|
|
import com.ynxbd.common.dao.peis.PeisDao; |
|
|
|
import com.ynxbd.common.dao.peis.PeisDao; |
|
|
|
|
|
|
|
import com.ynxbd.common.helper.common.JsonHelper; |
|
|
|
|
|
|
|
import com.ynxbd.common.helper.http.OkHttpHelper; |
|
|
|
|
|
|
|
import com.ynxbd.common.helper.xbd.HttpHelper; |
|
|
|
|
|
|
|
import com.ynxbd.common.helper.xbd.XBDHelper; |
|
|
|
|
|
|
|
import com.ynxbd.common.result.JsonResult; |
|
|
|
|
|
|
|
import com.ynxbd.common.result.JsonResultEnum; |
|
|
|
import com.ynxbd.common.result.Result; |
|
|
|
import com.ynxbd.common.result.Result; |
|
|
|
|
|
|
|
import com.ynxbd.common.result.ServiceException; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
import okhttp3.FormBody; |
|
|
|
|
|
|
|
import okhttp3.RequestBody; |
|
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.BigDecimal; |
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @author 李进才 |
|
|
|
* @author 李进才 |
|
|
@ -34,17 +50,135 @@ public class PeisService { |
|
|
|
} |
|
|
|
} |
|
|
|
return new PeisDao().insert(recipe); |
|
|
|
return new PeisDao().insert(recipe); |
|
|
|
} |
|
|
|
} |
|
|
|
public void payNotify(String outTradeNo, String bankTransNo){ |
|
|
|
public void payNotify(MerchantEnum merchantEnum, String openid, BigDecimal totalFee, String outTradeNo, String bankTransNo, String payInfo,Date tradeDate){ |
|
|
|
PeisDao peisDao = new PeisDao(); |
|
|
|
PeisDao peisDao = new PeisDao(); |
|
|
|
Recipe recipe = peisDao.selectByOutTradeNo(outTradeNo); |
|
|
|
Recipe recipe = peisDao.selectByOutTradeNo(outTradeNo); |
|
|
|
String recipeId = recipe.getRecipeId(); |
|
|
|
String recipeId = recipe.getRecipeId(); |
|
|
|
Integer payStates = recipe.getPayStatus(); |
|
|
|
Integer payStates = recipe.getPayStatus(); |
|
|
|
if (payStates == 0) { |
|
|
|
if (payStates == 0) { |
|
|
|
log.error("[体检预约]订单已支付 outTradeNo={}, bankTransNo={}, recipeId={}", outTradeNo, bankTransNo, recipeId); |
|
|
|
log.error("[体检预约] 拒绝支付-订单已支付 outTradeNo={}, bankTransNo={}, recipeId={}", outTradeNo, bankTransNo, recipeId); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!peisDao.updatePayStateOk(outTradeNo, bankTransNo)) { |
|
|
|
if (!peisDao.updatePayStateOk(outTradeNo, bankTransNo)) { |
|
|
|
log.info("[体检预约]修改支付状态失败 outTradeNo={}, bankTransNo={}", outTradeNo, bankTransNo); |
|
|
|
log.info("[体检预约]修改支付状态失败 outTradeNo={}, bankTransNo={}", outTradeNo, bankTransNo); |
|
|
|
|
|
|
|
RequestBody formBody = new FormBody.Builder(). |
|
|
|
|
|
|
|
add("orderNo", recipeId) |
|
|
|
|
|
|
|
.add("payStatus","FAIL") |
|
|
|
|
|
|
|
.add("payFailReason","修改支付状态失败") |
|
|
|
|
|
|
|
.add("bankTransNo",bankTransNo) |
|
|
|
|
|
|
|
.add("outTradeNo",outTradeNo) |
|
|
|
|
|
|
|
.build(); |
|
|
|
|
|
|
|
String result = OkHttpHelper.post(XBDHelper.XBD_PEIS+"/wxUse/wxPay",formBody); |
|
|
|
|
|
|
|
JSONObject jsonResult = JsonHelper.parseObject(result); |
|
|
|
|
|
|
|
log.info("[体检预约]缴费失败回调体检系统计费 recipeId={}, bankTransNo-{}, 计费状态-{}, 计费信息-{}",recipeId,bankTransNo,jsonResult.get("code"),jsonResult.get("message")); |
|
|
|
|
|
|
|
String pushMessage = "体检预约失败已申请退款,原因:修改支付状态失败,订单号:" + outTradeNo+"orderNo:"+ recipeId;; |
|
|
|
|
|
|
|
peisAutoRefund(recipeId,merchantEnum,outTradeNo,totalFee,pushMessage,tradeDate,openid); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
RequestBody formBody = new FormBody.Builder(). |
|
|
|
|
|
|
|
add("orderNo", recipeId) |
|
|
|
|
|
|
|
.add("payStatus", "OK") |
|
|
|
|
|
|
|
.add("payFailReason", "") |
|
|
|
|
|
|
|
.add("bankTransNo", bankTransNo) |
|
|
|
|
|
|
|
.add("outTradeNo",outTradeNo) |
|
|
|
|
|
|
|
.build(); |
|
|
|
|
|
|
|
String result = OkHttpHelper.post(XBDHelper.XBD_PEIS + "/wxUse/wxPay", formBody); |
|
|
|
|
|
|
|
JSONObject jsonResult = JsonHelper.parseObject(result); |
|
|
|
|
|
|
|
log.info("[体检预约]缴费成功回调体检系统计费 recipeId={}, bankTransNo-{}, 计费状态-{}, 计费信息-{}", recipeId, bankTransNo, jsonResult.get("code"), jsonResult.get("message")); |
|
|
|
|
|
|
|
if(result==null){ |
|
|
|
|
|
|
|
String pushMessage = "体检预约失败已申请退款,原因:体检系统计费失败,订单号:" + outTradeNo+"orderNo:"+ recipeId; |
|
|
|
|
|
|
|
peisAutoRefund(recipeId,merchantEnum,outTradeNo,totalFee,pushMessage,tradeDate,openid); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if("200".equals(jsonResult.get("code"))){ |
|
|
|
|
|
|
|
if(!peisDao.updatePeisStateOk(outTradeNo, bankTransNo)){ |
|
|
|
|
|
|
|
log.info("[体检预约]修改体检系统支付状态失败 outTradeNo={}, bankTransNo={}", outTradeNo, bankTransNo); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 体检退费接口 |
|
|
|
|
|
|
|
* @param recipeId 订单号 |
|
|
|
|
|
|
|
* @param merchantEnum 支付方式 |
|
|
|
|
|
|
|
* @param outTradeNo outTradeNo |
|
|
|
|
|
|
|
* @param totalFee 总金额 |
|
|
|
|
|
|
|
* @param pushInfo 提示信息 |
|
|
|
|
|
|
|
* @param tradeDate 退费时间 |
|
|
|
|
|
|
|
* @param openid openid |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public Result peisAutoRefund(String recipeId, MerchantEnum merchantEnum, String outTradeNo, BigDecimal totalFee, String pushInfo, Date tradeDate, String openid){ |
|
|
|
|
|
|
|
PeisDao peisDao = new PeisDao(); |
|
|
|
|
|
|
|
String result = OkHttpHelper.get(XBDHelper.XBD_PEIS+"/wxUse/GetOrder",params -> { |
|
|
|
|
|
|
|
params.put("orderNo",recipeId); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
JSONObject jsonResult = JsonHelper.parseObject(result); |
|
|
|
|
|
|
|
if(result==null){ |
|
|
|
|
|
|
|
log.info("{} [体检预约][退费错误,计费信息查询失败] recipeId-{}, outTradeNo={}, recipeId={}, totalFee={}",recipeId, merchantEnum.NAME, outTradeNo, recipeId, totalFee); |
|
|
|
|
|
|
|
return Result.error("退费错误,计费信息查询失败"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
String fee = jsonResult.getJSONObject("data").get("fee").toString(); |
|
|
|
|
|
|
|
boolean isWxPay = Boolean.parseBoolean(jsonResult.getJSONObject("data").get("isWxPay").toString()); |
|
|
|
|
|
|
|
boolean isCost = Boolean.parseBoolean(jsonResult.getJSONObject("data").get("isCost").toString()); |
|
|
|
|
|
|
|
if(totalFee.compareTo(BigDecimal.ZERO)==0||"0".equals(fee)){ |
|
|
|
|
|
|
|
log.info("{} [体检预约][退费错误,退费金额为0] recipeId-{}, outTradeNo={}, recipeId={}, totalFee={}",recipeId, merchantEnum.NAME, outTradeNo, recipeId, totalFee); |
|
|
|
|
|
|
|
return Result.error("退费错误,退费金额为0"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(totalFee.equals(new BigDecimal(String.valueOf(fee)))){ |
|
|
|
|
|
|
|
log.info("{} [体检预约][退费错误,退费金额跟订单金额不符] recipeId-{}, outTradeNo={}, recipeId={}, totalFee={}",recipeId, merchantEnum.NAME, outTradeNo, recipeId, totalFee); |
|
|
|
|
|
|
|
return Result.error("退费错误,退费金额跟订单金额不符"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(isWxPay){ |
|
|
|
|
|
|
|
log.info("{} [体检预约][退费错误,体检显示已计费,不允许退费] recipeId-{}, outTradeNo={}, recipeId={}, totalFee={}", recipeId, merchantEnum.NAME, outTradeNo, recipeId, totalFee); |
|
|
|
|
|
|
|
return Result.error("退费错误,体检显示已计费,不允许退费"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(isCost){ |
|
|
|
|
|
|
|
log.info("{} [体检预约][退费错误,his显示已计费,不允许退费] recipeId-{}, outTradeNo={}, recipeId={}, totalFee={}", recipeId, merchantEnum.NAME, outTradeNo, recipeId, totalFee); |
|
|
|
|
|
|
|
return Result.error("退费错误,his显示已计费,不允许退费"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
String refundResult; |
|
|
|
|
|
|
|
Order orderRefund = PayService.refund(merchantEnum, outTradeNo, recipeId, totalFee, totalFee, pushInfo, tradeDate, openid, null, pushInfo); |
|
|
|
|
|
|
|
if (!orderRefund.isSuccess()) { |
|
|
|
|
|
|
|
log.info("{} [体检预约][退费错误] outTradeNo={}, recipeId={}, totalFee={},recipeId-{}", merchantEnum.NAME, outTradeNo, recipeId, totalFee,recipeId); |
|
|
|
|
|
|
|
refundResult = orderRefund.getRefundResult(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
refundResult = "OK"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
boolean isUpdate = peisDao.updateRefundResult(outTradeNo, recipeId, refundResult); |
|
|
|
|
|
|
|
if (!isUpdate) { |
|
|
|
|
|
|
|
log.info("{} [体检预约][退费错误]退费信息更新失败 recipeId={}", merchantEnum.NAME, recipeId); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return Result.success(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean peisRefund(String recipeId, String refundStatus, String refundFailReason){ |
|
|
|
|
|
|
|
RequestBody formBody = new FormBody.Builder(). |
|
|
|
|
|
|
|
add("orderNo", recipeId) |
|
|
|
|
|
|
|
.add("refundStatus",refundStatus) |
|
|
|
|
|
|
|
.add("refundFailReason",refundFailReason) |
|
|
|
|
|
|
|
.build(); |
|
|
|
|
|
|
|
String result = OkHttpHelper.post(XBDHelper.XBD_PEIS+"/wxUse/wxRefund",formBody); |
|
|
|
|
|
|
|
JSONObject jsonResult = JsonHelper.parseObject(result); |
|
|
|
|
|
|
|
return "200".equals(jsonResult.get("code")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
|
|
|
RequestBody formBody = new FormBody.Builder(). |
|
|
|
|
|
|
|
add("orderNo", "Fee2023112900000001") |
|
|
|
|
|
|
|
.add("payStatus","OK") |
|
|
|
|
|
|
|
.add("payFailReason","") |
|
|
|
|
|
|
|
.add("bankTransNo","4200001809202305012522296970") |
|
|
|
|
|
|
|
.build(); |
|
|
|
|
|
|
|
String result = OkHttpHelper.post(XBDHelper.XBD_PEIS+"/wxUse/wxPay",formBody); |
|
|
|
|
|
|
|
System.out.println(result); |
|
|
|
|
|
|
|
// String result = OkHttpHelper.get(XBDHelper.XBD_PEIS+"/wxUse/GetOrder",params -> {
|
|
|
|
|
|
|
|
// params.put("orderNo","Fee2023112900000001");
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// JSONObject jsonResult = JsonHelper.parseObject(result);
|
|
|
|
|
|
|
|
// System.out.println(result);
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|