|
|
@@ -3,6 +3,7 @@ package com.fs.live.service.impl;
|
|
|
import java.lang.reflect.Field;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.sql.Timestamp;
|
|
|
+import java.text.DecimalFormat;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
|
@@ -689,7 +690,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Throwable.class,propagation = Propagation.REQUIRED)
|
|
|
+ @Transactional
|
|
|
public String payConfirm(Integer type,Long orderId,String payCode,String tradeNo,String bankTransactionId,String bankSerialNo) {
|
|
|
Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint();
|
|
|
try {
|
|
|
@@ -709,7 +710,12 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
liveOrderPaymentMapper.updateLiveOrderPayment(paymentMap);
|
|
|
order = baseMapper.selectFsUserVipOrderByOrderCode(storePayment.getBusinessCode());
|
|
|
if(order==null || !order.getStatus().equals(OrderInfoEnum.STATUS_0.getValue())){
|
|
|
- throw new CustomException("当前订单未找到或者订单状态不为待支付! paycode:"+payCode);
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ if (order != null && !order.getIsPay().equals(0)) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return "";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1389,6 +1395,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public R refundOrderMoney(Long orderId, LiveAfterSales liveAfterSales) {
|
|
|
+ BigDecimal refundAmount = liveAfterSales.getRefundAmount();
|
|
|
IErpOrderService erpOrderService = getErpService();
|
|
|
FsErpConfig erpConfig = configUtil.generateStructConfigByKey("his.config", FsErpConfig.class);
|
|
|
LiveOrder order = baseMapper.selectLiveOrderByOrderId(String.valueOf(orderId));
|
|
|
@@ -1407,43 +1414,49 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
&& !CloudHostUtils.hasCloudHostName("康年堂")) {
|
|
|
return R.error("暂未推送至erp,请稍后再试!");
|
|
|
}
|
|
|
- liveAfterSales.setRefundAmount(order.getPayPrice());
|
|
|
+ if (Objects.isNull(refundAmount)) {
|
|
|
+ throw new CustomException("退款金额不能为空");
|
|
|
+ }
|
|
|
+ if (order.getPayMoney().compareTo(refundAmount) < 0) {
|
|
|
+ throw new CustomException("退款金额不能大于支付金额");
|
|
|
+ }
|
|
|
+ liveAfterSales.setRefundAmount(liveAfterSales.getRefundAmount());
|
|
|
liveAfterSales.setStatus(4);
|
|
|
liveAfterSales.setSalesStatus(3);
|
|
|
liveAfterSalesService.updateLiveAfterSales(liveAfterSales);
|
|
|
- if (StringUtils.isNotEmpty(order.getExtendOrderId())) {
|
|
|
- ErpRefundUpdateRequest request = new ErpRefundUpdateRequest();
|
|
|
- request.setTid(order.getOrderCode());
|
|
|
- request.setOid(order.getOrderCode());
|
|
|
- request.setRefund_state(1);
|
|
|
- request.setOrderStatus(order.getStatus());
|
|
|
- if (ObjectUtils.equals(order.getStatus(), 2)) {
|
|
|
- LiveAfterSalesParam param = new LiveAfterSalesParam();
|
|
|
- param.setOrderCode(order.getOrderCode());
|
|
|
- param.setRefundAmount(order.getPayMoney());
|
|
|
- param.setServiceType(1);
|
|
|
- param.setReasons("后台手动退款流程");
|
|
|
- param.setExplainImg(null);
|
|
|
- List<FsStoreAfterSalesProductParam> productParams = new ArrayList<>();
|
|
|
- List <LiveOrderItem> items = liveOrderItemMapper.selectLiveOrderItemByOrderId(order.getOrderId());
|
|
|
- for (LiveOrderItem item : items){
|
|
|
- FsStoreAfterSalesProductParam param1 = new FsStoreAfterSalesProductParam();
|
|
|
- param1.setProductId(item.getProductId());
|
|
|
- param1.setNum(Math.toIntExact(item.getNum()));
|
|
|
- productParams.add(param1);
|
|
|
- }
|
|
|
- return liveAfterSalesService.applyForAfterSales(order.getUserId(), param);
|
|
|
- } else {
|
|
|
- ErpOrderQueryRequert queryRequest = new ErpOrderQueryRequert();
|
|
|
- queryRequest.setCode(order.getExtendOrderId());
|
|
|
- ErpOrderQueryResponse response = erpOrderService.getLiveOrder(queryRequest);
|
|
|
- if (response.getOrders() != null && response.getOrders().size() > 0) {
|
|
|
- if (response.getOrders().get(0).getCancle() != null && !response.getOrders().get(0).getCancle()) {
|
|
|
- jSTOrderService.refundUpdateLive(request);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+// if (StringUtils.isNotEmpty(order.getExtendOrderId())) {
|
|
|
+// ErpRefundUpdateRequest request = new ErpRefundUpdateRequest();
|
|
|
+// request.setTid(order.getOrderCode());
|
|
|
+// request.setOid(order.getOrderCode());
|
|
|
+// request.setRefund_state(1);
|
|
|
+// request.setOrderStatus(order.getStatus());
|
|
|
+// if (ObjectUtils.equals(order.getStatus(), 2)) {
|
|
|
+// LiveAfterSalesParam param = new LiveAfterSalesParam();
|
|
|
+// param.setOrderCode(order.getOrderCode());
|
|
|
+// param.setRefundAmount(order.getPayMoney());
|
|
|
+// param.setServiceType(1);
|
|
|
+// param.setReasons("后台手动退款流程");
|
|
|
+// param.setExplainImg(null);
|
|
|
+// List<FsStoreAfterSalesProductParam> productParams = new ArrayList<>();
|
|
|
+// List <LiveOrderItem> items = liveOrderItemMapper.selectLiveOrderItemByOrderId(order.getOrderId());
|
|
|
+// for (LiveOrderItem item : items){
|
|
|
+// FsStoreAfterSalesProductParam param1 = new FsStoreAfterSalesProductParam();
|
|
|
+// param1.setProductId(item.getProductId());
|
|
|
+// param1.setNum(Math.toIntExact(item.getNum()));
|
|
|
+// productParams.add(param1);
|
|
|
+// }
|
|
|
+// return liveAfterSalesService.applyForAfterSales(order.getUserId(), param);
|
|
|
+// } else {
|
|
|
+// ErpOrderQueryRequert queryRequest = new ErpOrderQueryRequert();
|
|
|
+// queryRequest.setCode(order.getExtendOrderId());
|
|
|
+// ErpOrderQueryResponse response = erpOrderService.getLiveOrder(queryRequest);
|
|
|
+// if (response.getOrders() != null && response.getOrders().size() > 0) {
|
|
|
+// if (response.getOrders().get(0).getCancle() != null && !response.getOrders().get(0).getCancle()) {
|
|
|
+// jSTOrderService.refundUpdateLive(request);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
order.setStatus(OrderInfoEnum.STATUS_NE2.getValue());
|
|
|
order.setRefundMoney(order.getPayMoney());
|
|
|
order.setRefundStatus(String.valueOf(OrderInfoEnum.REFUND_STATUS_2.getValue()));
|
|
|
@@ -1494,7 +1507,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
refundRequest.setOutTradeNo("live-" + payment.getPayCode());
|
|
|
refundRequest.setOutRefundNo("live-" + payment.getPayCode());
|
|
|
refundRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(payment.getPayMoney().toString()));
|
|
|
- refundRequest.setRefundFee(WxPayUnifiedOrderRequest.yuanToFen(payment.getPayMoney().toString()));
|
|
|
+ refundRequest.setRefundFee(WxPayUnifiedOrderRequest.yuanToFen(refundAmount.toString()));
|
|
|
try {
|
|
|
WxPayRefundResult refundResult = wxPayService.refund(refundRequest);
|
|
|
WxPayRefundQueryResult refundQueryResult = wxPayService.refundQuery("", refundResult.getOutTradeNo(), refundResult.getOutRefundNo(), refundResult.getRefundId());
|
|
|
@@ -1503,14 +1516,12 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
paymentMap.setPaymentId(payment.getPaymentId());
|
|
|
paymentMap.setStatus(-1);
|
|
|
paymentMap.setRefundTime(DateUtils.getNowDate());
|
|
|
- paymentMap.setRefundMoney(payment.getPayMoney());
|
|
|
+ paymentMap.setRefundMoney(refundAmount);
|
|
|
liveOrderPaymentMapper.updateLiveOrderPayment(paymentMap);
|
|
|
} else {
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
return R.error("退款请求失败" + (refundQueryResult != null ? refundQueryResult.getErrCodeDes() : ""));
|
|
|
}
|
|
|
} catch (WxPayException e) {
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
return R.error("退款请求失败" + e.getErrCodeDes());
|
|
|
}
|
|
|
} else if (payment.getPayMode() != null && "hf".equals(payment.getPayMode())) {
|
|
|
@@ -1518,25 +1529,26 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
FsHfpayConfigMapper fsHfpayConfigMapper = SpringUtils.getBean(FsHfpayConfigMapper.class);
|
|
|
if (payment.getAppId() != null) {
|
|
|
FsHfpayConfig fsHfpayConfig = fsHfpayConfigMapper.selectByAppId(payment.getAppId());
|
|
|
- if (fsHfpayConfig != null) {
|
|
|
+ if (fsHfpayConfig == null){
|
|
|
+ huifuId = fsPayConfig.getHuifuId();
|
|
|
+ }else {
|
|
|
huifuId = fsHfpayConfig.getHuifuId();
|
|
|
}
|
|
|
} else {
|
|
|
CloudHostProper cloudHostProper = SpringUtils.getBean(CloudHostProper.class);
|
|
|
if ("益善缘".equals(cloudHostProper.getCompanyName())) {
|
|
|
FsHfpayConfig fsPayConfig2 = fsHfpayConfigMapper.selectByAppId("wx0d1a3dd485268521");
|
|
|
- if (fsPayConfig2 != null) {
|
|
|
- huifuId = fsPayConfig2.getHuifuId();
|
|
|
- }
|
|
|
+ huifuId = fsPayConfig2.getHuifuId();
|
|
|
} else {
|
|
|
huifuId = fsPayConfig.getHuifuId();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
V2TradePaymentScanpayRefundRequest request = new V2TradePaymentScanpayRefundRequest();
|
|
|
+ DecimalFormat df = new DecimalFormat("0.00");
|
|
|
request.setOrgHfSeqId(payment.getTradeNo());
|
|
|
request.setHuifuId(huifuId);
|
|
|
- request.setOrdAmt(payment.getPayMoney().toString());
|
|
|
+ request.setOrdAmt(df.format(refundAmount));
|
|
|
request.setOrgReqDate(new SimpleDateFormat("yyyyMMdd").format(payment.getCreateTime()));
|
|
|
request.setReqSeqId("refund-" + payment.getPayCode());
|
|
|
Map<String, Object> extendInfoMap = new HashMap<>();
|
|
|
@@ -3118,6 +3130,17 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
if (amount != null){
|
|
|
payMoney=amount;
|
|
|
}
|
|
|
+ //运费
|
|
|
+ BigDecimal payPostage = order.getPayPostage();
|
|
|
+ if (payPostage == null || payPostage.compareTo(BigDecimal.ZERO) <= 0){
|
|
|
+ payPostage = storeConfig.getPayPostage();
|
|
|
+ if (payPostage == null){
|
|
|
+ payPostage = BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ order.setPayPrice(order.getPayPrice().add(payPostage));
|
|
|
+ }
|
|
|
+ order.setPayPostage(payPostage);
|
|
|
+ payMoney = payMoney.add(payPostage);
|
|
|
order.setPayMoney(payMoney);
|
|
|
order.setPayDelivery(order.getPayPrice().subtract(payMoney) );
|
|
|
// order.setPayMoney(BigDecimal.ZERO);
|
|
|
@@ -3131,8 +3154,8 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
String payCode = OrderCodeUtils.getOrderSn();
|
|
|
// order.setOrderCode(orderCode);
|
|
|
// if(order.getPayType().equals("1")||order.getPayType().equals("2")){
|
|
|
- if((order.getPayType().equals("1")||order.getPayType().equals("2")||order.getPayType().equals("3")) && order.getPayMoney().compareTo(new BigDecimal(0))>0){
|
|
|
- LiveOrderPayment storePayment=new LiveOrderPayment();
|
|
|
+ if ((order.getPayType().equals("1") || order.getPayType().equals("2") || order.getPayType().equals("3")) && order.getPayMoney().compareTo(new BigDecimal(0)) > 0) {
|
|
|
+ LiveOrderPayment storePayment = new LiveOrderPayment();
|
|
|
storePayment.setCompanyId(order.getCompanyId());
|
|
|
storePayment.setCompanyUserId(order.getCompanyUserId());
|
|
|
storePayment.setPayMode(fsPayConfig.getType());
|
|
|
@@ -3149,35 +3172,35 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
storePayment.setAppId(param.getAppId());
|
|
|
liveOrderPaymentMapper.insertLiveOrderPayment(storePayment);
|
|
|
|
|
|
- if (fsPayConfig.getType().equals("hf")){
|
|
|
+ if (fsPayConfig.getType().equals("hf")) {
|
|
|
HuiFuCreateOrder o = new HuiFuCreateOrder();
|
|
|
o.setTradeType("T_MINIAPP");
|
|
|
o.setOpenid(storePayment.getOpenId());
|
|
|
- o.setReqSeqId("live-"+storePayment.getPayCode());
|
|
|
+ o.setReqSeqId("live-" + storePayment.getPayCode());
|
|
|
o.setTransAmt(storePayment.getPayMoney().toString());
|
|
|
o.setGoodsDesc("直播订单支付");
|
|
|
if (StringUtils.isNotBlank(param.getAppId())) {
|
|
|
o.setAppId(param.getAppId());
|
|
|
}
|
|
|
HuifuCreateOrderResult result = huiFuService.createOrder(o);
|
|
|
- if(result.getResp_code()!=null&&(result.getResp_code().equals("00000000")||result.getResp_code().equals("00000100"))){
|
|
|
- LiveOrderPayment mt=new LiveOrderPayment();
|
|
|
+ if (result.getResp_code() != null && (result.getResp_code().equals("00000000") || result.getResp_code().equals("00000100"))) {
|
|
|
+ LiveOrderPayment mt = new LiveOrderPayment();
|
|
|
mt.setPaymentId(storePayment.getPaymentId());
|
|
|
mt.setTradeNo(result.getHf_seq_id());
|
|
|
mt.setAppId(param.getAppId());
|
|
|
mt.setBusinessCode(order.getOrderCode());
|
|
|
liveOrderPaymentMapper.updateLiveOrderPayment(mt);
|
|
|
- redisCache.setCacheObject("isPaying:"+order.getOrderId(),order.getOrderId().toString(),1, TimeUnit.MINUTES);
|
|
|
+ redisCache.setCacheObject("isPaying:" + order.getOrderId(), order.getOrderId().toString(), 1, TimeUnit.MINUTES);
|
|
|
log.info("汇付支付");
|
|
|
- Map<String, Object> resultMap = JSON.parseObject(result.getPay_info(), new TypeReference<Map<String, Object>>() {});
|
|
|
+ Map<String, Object> resultMap = JSON.parseObject(result.getPay_info(), new TypeReference<Map<String, Object>>() {
|
|
|
+ });
|
|
|
String s = (String) resultMap.get("package");
|
|
|
- resultMap.put("packageValue",s);
|
|
|
- return R.ok().put("payType",param.getPayType()).put("result",resultMap);
|
|
|
- }
|
|
|
- else{
|
|
|
+ resultMap.put("packageValue", s);
|
|
|
+ return R.ok().put("payType", param.getPayType()).put("result", resultMap);
|
|
|
+ } else {
|
|
|
return R.error(result.getResp_desc());
|
|
|
}
|
|
|
- }else if (fsPayConfig.getType().equals("wx")){
|
|
|
+ } else if (fsPayConfig.getType().equals("wx")) {
|
|
|
WxPayConfig payConfig = new WxPayConfig();
|
|
|
payConfig.setAppId(fsPayConfig.getAppId());
|
|
|
payConfig.setMchId(fsPayConfig.getWxMchId());
|
|
|
@@ -3198,7 +3221,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
//调用统一下单接口,获取"预支付交易会话标识"
|
|
|
try {
|
|
|
WxPayMpOrderResult orderResult = wxPayService.createOrder(orderRequest);
|
|
|
- return R.ok().put("result", orderResult).put("type", "wx").put("isPay", 0).put("payType",param.getPayType());
|
|
|
+ return R.ok().put("result", orderResult).put("type", "wx").put("isPay", 0).put("payType", param.getPayType());
|
|
|
} catch (WxPayException e) {
|
|
|
e.printStackTrace();
|
|
|
throw new CustomException("支付失败" + e.getMessage());
|
|
|
@@ -3206,10 +3229,10 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
}
|
|
|
}
|
|
|
// else if(order.getPayType().equals("3")){
|
|
|
- else if(order.getPayType().equals("3") && order.getPayMoney().compareTo(new BigDecimal(0))<=0){
|
|
|
+ else if (order.getPayType().equals("3") && order.getPayMoney().compareTo(new BigDecimal(0)) <= 0) {
|
|
|
//货到付款
|
|
|
- this.payConfirm(2,order.getOrderId(),null,null,null,null);
|
|
|
- return R.ok().put("payType",param.getPayType());
|
|
|
+ this.payConfirm(2, order.getOrderId(), null, null, null, null);
|
|
|
+ return R.ok().put("payType", param.getPayType());
|
|
|
}
|
|
|
return R.error();
|
|
|
}
|
|
|
@@ -3661,7 +3684,6 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
liveOrder.setStatus(OrderInfoEnum.STATUS_0.getValue());
|
|
|
liveOrder.setPayType("1");
|
|
|
liveOrder.setTotalPrice(payPrice);
|
|
|
- liveOrder.setPayMoney(BigDecimal.ZERO);
|
|
|
liveOrder.setPayPrice(payPrice.subtract(liveOrder.getDiscountMoney()));
|
|
|
try {
|
|
|
if (baseMapper.insertLiveOrder(liveOrder) > 0) {
|