mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-08-16 11:07:36 +08:00
Merge branch 'dev' into feature-business-minigram
This commit is contained in:
@@ -1345,7 +1345,74 @@ public class AdapayService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询支付退款对象
|
||||
* 按汇付文档查询支付对象详情
|
||||
* Payment.query(paymentId, merchantKey)
|
||||
*/
|
||||
public AdaPayment queryPaymentDetail(String paymentId, String wechatAppId) throws BaseAdaPayException {
|
||||
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
|
||||
if (config == null) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
|
||||
}
|
||||
Map<String, Object> response = Payment.query(paymentId, config.getWechatAppId());
|
||||
if (response == null || response.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
String resultPaymentId = (String) response.get("id");
|
||||
String errorCode = (String) response.get("error_code");
|
||||
if (!StringUtils.equals(paymentId, resultPaymentId) || StringUtils.isNotBlank(errorCode)) {
|
||||
return null;
|
||||
}
|
||||
return JSON.parseObject(JSON.toJSONString(response), AdaPayment.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按汇付文档通过 payment_id 查询支付对象列表
|
||||
* 作为 Payment.query 的补充,用于查询 3 天前的交易
|
||||
*/
|
||||
public List<AdaPayment> queryPaymentListByPaymentId(String paymentId, String wechatAppId) throws BaseAdaPayException {
|
||||
List<AdaPayment> resultList = Lists.newArrayList();
|
||||
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
|
||||
if (config == null) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
|
||||
}
|
||||
Map<String, Object> queryListParam = Maps.newHashMap();
|
||||
queryListParam.put("app_id", config.getAdapayAppId());
|
||||
queryListParam.put("payment_id", paymentId);
|
||||
queryListParam.put("page_index", 1);
|
||||
queryListParam.put("page_size", 1);
|
||||
Map<String, Object> paymentListResult = Payment.queryList(queryListParam, config.getWechatAppId());
|
||||
if (paymentListResult == null || paymentListResult.isEmpty()) {
|
||||
return resultList;
|
||||
}
|
||||
|
||||
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(paymentListResult));
|
||||
List<AdaPayment> payments = jsonObject.getList("payments", AdaPayment.class, JSONReader.Feature.FieldBased);
|
||||
if (CollectionUtils.isNotEmpty(payments)) {
|
||||
resultList.addAll(payments);
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询支付对象详情
|
||||
* 先查 Payment.query,未命中时再按 payment_id 查询列表
|
||||
*/
|
||||
public AdaPayment queryPaymentDetailWithFallback(String paymentId, String wechatAppId) throws BaseAdaPayException {
|
||||
AdaPayment payment = queryPaymentDetail(paymentId, wechatAppId);
|
||||
if (payment != null) {
|
||||
return payment;
|
||||
}
|
||||
|
||||
List<AdaPayment> payments = queryPaymentListByPaymentId(paymentId, wechatAppId);
|
||||
if (CollectionUtils.isEmpty(payments)) {
|
||||
return null;
|
||||
}
|
||||
return payments.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按汇付文档通过 payment_id 查询退款对象
|
||||
* Refund.query({payment_id}, merchantKey)
|
||||
*/
|
||||
public List<RefundInfo> queryPaymentRefund(String paymentId, String wechatAppId) throws BaseAdaPayException {
|
||||
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
|
||||
@@ -1354,7 +1421,6 @@ public class AdapayService {
|
||||
}
|
||||
Map<String, Object> refundParams = Maps.newHashMap();
|
||||
refundParams.put("payment_id", paymentId);
|
||||
refundParams.put("app_id", config.getAdapayAppId());
|
||||
Map<String, Object> response = Refund.query(refundParams, config.getWechatAppId());
|
||||
PaymentRefundResponse paymentRefundResponse = JSON.parseObject(JSON.toJSONString(response), PaymentRefundResponse.class);
|
||||
List<RefundInfo> refunds = paymentRefundResponse.getRefunds();
|
||||
|
||||
@@ -83,6 +83,8 @@ public class QueryOrderDTO extends BaseEntity {
|
||||
*/
|
||||
private String payMode;
|
||||
|
||||
private List<String> payModeList;
|
||||
|
||||
/**
|
||||
* 订单编号列表
|
||||
*/
|
||||
@@ -98,6 +100,11 @@ public class QueryOrderDTO extends BaseEntity {
|
||||
*/
|
||||
private String endSettleTime;
|
||||
|
||||
/**
|
||||
* 审核标志
|
||||
*/
|
||||
private String reviewFlag;
|
||||
|
||||
/**
|
||||
* 会员组编号
|
||||
*/
|
||||
|
||||
@@ -30,4 +30,9 @@ public class UpdateOrderReviewDTO {
|
||||
* 结束日期
|
||||
*/
|
||||
private String endTime;
|
||||
|
||||
/**
|
||||
* 比率
|
||||
*/
|
||||
private Double ratio;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,8 @@ public interface MemberWalletInfoMapper {
|
||||
*/
|
||||
MemberWalletInfo selectByMemberId(@Param("memberId") String memberId, @Param("merchantId") String merchantId);
|
||||
|
||||
List<MemberWalletInfo> selectByMemberIdList(@Param("memberId") String memberId, @Param("merchantId") String merchantId);
|
||||
|
||||
List<MemberWalletInfo> selectByMemberWalletList(@Param("memberId") String memberId);
|
||||
|
||||
MemberWalletInfo selectByWalletCode(@Param("walletCode") String walletCode);
|
||||
|
||||
@@ -636,7 +636,7 @@ public interface OrderBasicInfoService{
|
||||
void checkOrUpdateOrderSplitRecord(AfterSettleOrderDTO afterSettleOrderDTO);
|
||||
|
||||
|
||||
int updateOrderReviewFlagTemp(LocalDateTime start, LocalDateTime end, String stationId);
|
||||
int updateOrderReviewFlagTemp(LocalDateTime start, LocalDateTime end, String stationId, Double ratio);
|
||||
|
||||
List<StationSplitConfig> queryOrderSplitConfigList(String orderCode);
|
||||
|
||||
|
||||
@@ -46,7 +46,15 @@ public class MemberWalletInfoServiceImpl implements MemberWalletInfoService {
|
||||
|
||||
@Override
|
||||
public MemberWalletInfo selectByMemberId(String memberId, String merchantId) {
|
||||
return memberWalletInfoMapper.selectByMemberId(memberId, merchantId);
|
||||
List<MemberWalletInfo> list = memberWalletInfoMapper.selectByMemberIdList(memberId, merchantId);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return null;
|
||||
}
|
||||
// 优先返回 merchantId 不为空的记录,避免脏数据干扰
|
||||
return list.stream()
|
||||
.filter(w -> w.getMerchantId() != null)
|
||||
.findFirst()
|
||||
.orElse(list.get(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1066,7 +1066,8 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
|
||||
QueryOrderDTO dto = QueryOrderDTO.builder()
|
||||
.startTime(DateUtils.formatDateTime(start))
|
||||
.endTime(DateUtils.formatDateTime(end))
|
||||
.payMode(OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())
|
||||
// .payMode(OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())
|
||||
.payModeList(Lists.newArrayList(OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue(), OrderPayModeEnum.PAYMENT_OF_ALIPAY.getValue()))
|
||||
.stationId(stationId)
|
||||
.orderStatus(OrderStatusEnum.ORDER_COMPLETE.getValue())
|
||||
.build();
|
||||
@@ -6327,17 +6328,21 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateOrderReviewFlagTemp(LocalDateTime start, LocalDateTime end, String stationId) {
|
||||
public int updateOrderReviewFlagTemp(LocalDateTime start, LocalDateTime end, String stationId, Double ratio) {
|
||||
if (ratio == null) {
|
||||
ratio = 0.1;
|
||||
logger.info("校验或更新订单分账信息-使用默认比例:{}", ratio);
|
||||
}
|
||||
if (StringUtils.isBlank(stationId)) {
|
||||
stationId = "1003"; // 目前只有 大坡中学举视超充站 这一个站点使用
|
||||
logger.info("校验或更新订单分账信息-使用默认站点id:{}", stationId);
|
||||
}
|
||||
List<OrderListVO> orderList = this.selectOrderListByDateTime(start, end, stationId);
|
||||
if (CollectionUtils.isEmpty(orderList)) {
|
||||
return 0;
|
||||
}
|
||||
List<String> orderCodeList = orderList.stream().map(OrderListVO::getOrderCode).collect(Collectors.toList());
|
||||
UpdateOrderReviewDTO dto = new UpdateOrderReviewDTO();
|
||||
dto.setOrderCodeList(MerchantUtils.getRandomNinetyPercent(orderCodeList));
|
||||
dto.setOrderCodeList(MerchantUtils.getRandomOrderCodes(orderList, ratio));
|
||||
dto.setStationId(stationId);
|
||||
return batchUpdateOrderReview(dto);
|
||||
}
|
||||
|
||||
@@ -676,6 +676,7 @@ public class SettleOrderReportServiceImpl implements SettleOrderReportService {
|
||||
dto.setEndSettleTime(endTime);
|
||||
// 2024年1月30日13点49分 查询订单列表只查对应当前运营商的
|
||||
dto.setMerchantId(stationInfo.getMerchantId());
|
||||
dto.setReviewFlag(Constants.ONE);
|
||||
// 查询结算完成的订单
|
||||
List<OrderListVO> orderListVOS = orderBasicInfoMapper.selectOrderBasicInfoList(dto);
|
||||
// 收集订单编号
|
||||
|
||||
@@ -1084,9 +1084,11 @@ public class DelayMerchantProgramLogic extends AbstractProgramLogic {
|
||||
|
||||
// 需要退回本金的金额
|
||||
BigDecimal returnPrincipal = returnAmountMap.get("returnPrincipal");
|
||||
returnPrincipal = returnPrincipal == null ? BigDecimal.ZERO : returnPrincipal;
|
||||
|
||||
// 需要退回赠送金的金额
|
||||
BigDecimal returnGift = returnAmountMap.get("returnGift");
|
||||
returnGift = returnGift == null ? BigDecimal.ZERO : returnGift;
|
||||
|
||||
// 更新会员钱包/余额退回到钱包
|
||||
UpdateMemberBalanceDTO updateMemberBalanceDTO = UpdateMemberBalanceDTO.builder()
|
||||
@@ -1101,17 +1103,22 @@ public class DelayMerchantProgramLogic extends AbstractProgramLogic {
|
||||
|
||||
// 判断消费金额,如果消费金额 - 折扣金额小于 1 元,则将保险费也进行退回
|
||||
if (orderBasicInfo.getOrderAmount().subtract(orderBasicInfo.getDiscountAmount()).compareTo(BigDecimal.ONE) < 0) {
|
||||
// orderBasicInfoService.refundInsurance(orderBasicInfo);
|
||||
// 判断是否需要退保险费用
|
||||
boolean checkResult = orderBasicInfoService.checkRefundInsuranceAmount(orderBasicInfo);
|
||||
if (checkResult) {
|
||||
// 退保险, 计算退保金额
|
||||
// 退保险, 使用 calculateBalanceRefund 重新计算完整的退款金额(电费退款+保险费退款)
|
||||
// 注意:不能在 calculateReturnAmount 的基础上叠加保险费,因为 calculateReturnAmount 不感知保险费,
|
||||
// 算出的退款金额中已包含保险费部分,叠加会导致保险费被重复退还
|
||||
Map<String, BigDecimal> refundMap = calculateBalanceRefund(principalPay, giftPay, orderBasicInfo.getOrderAmount(), orderBasicInfo.getDiscountAmount(), orderBasicInfo.getInsuranceAmount());
|
||||
BigDecimal refundPrincipal = refundMap.get("returnPrincipal");
|
||||
BigDecimal refundGift = refundMap.get("returnGift");
|
||||
BigDecimal returnPrincipalForInsurance = refundMap.get("returnPrincipalForInsurance");
|
||||
BigDecimal returnGiftForInsurance = refundMap.get("returnGiftForInsurance");
|
||||
refundPrincipal = refundPrincipal == null ? BigDecimal.ZERO : refundPrincipal;
|
||||
refundGift = refundGift == null ? BigDecimal.ZERO : refundGift;
|
||||
|
||||
updateMemberBalanceDTO.setUpdatePrincipalBalance(returnPrincipal.add(returnPrincipalForInsurance));
|
||||
updateMemberBalanceDTO.setUpdateGiftBalance(returnGift.add(returnGiftForInsurance));
|
||||
updateMemberBalanceDTO.setUpdatePrincipalBalance(refundPrincipal.add(returnPrincipalForInsurance));
|
||||
updateMemberBalanceDTO.setUpdateGiftBalance(refundGift.add(returnGiftForInsurance));
|
||||
}
|
||||
}
|
||||
// 统一退款
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.jsowell.pile.util;
|
||||
|
||||
import com.jsowell.common.util.StringUtils;
|
||||
import com.jsowell.pile.vo.web.OrderListVO;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 运营商工具类
|
||||
@@ -73,4 +75,18 @@ public class MerchantUtils {
|
||||
return new ArrayList<>(shuffled.subList(0, keepCount));
|
||||
}
|
||||
|
||||
public static List<String> getRandomOrderCodes(List<OrderListVO> list, double ratio) {
|
||||
if (list == null || list.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
int total = list.size();
|
||||
int removeCount = (int) Math.ceil(total * ratio);
|
||||
int keepCount = Math.max(1, total - removeCount);
|
||||
List<OrderListVO> shuffled = new ArrayList<>(list);
|
||||
Collections.shuffle(shuffled);
|
||||
return shuffled.subList(0, keepCount).stream()
|
||||
.map(OrderListVO::getOrderCode)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user