mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 19:15:35 +08:00
update 修改余额支付订单
This commit is contained in:
@@ -4,6 +4,8 @@ import com.jsowell.common.constant.Constants;
|
|||||||
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
|
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
|
||||||
import com.jsowell.common.exception.BusinessException;
|
import com.jsowell.common.exception.BusinessException;
|
||||||
import io.jsonwebtoken.*;
|
import io.jsonwebtoken.*;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -14,6 +16,7 @@ import java.util.Date;
|
|||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class JWTUtils {
|
public class JWTUtils {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(JWTUtils.class);
|
||||||
// 令牌自定义标识
|
// 令牌自定义标识
|
||||||
private static String header;
|
private static String header;
|
||||||
|
|
||||||
@@ -94,6 +97,7 @@ public class JWTUtils {
|
|||||||
.parseClaimsJws(token)
|
.parseClaimsJws(token)
|
||||||
.getBody();
|
.getBody();
|
||||||
} catch (ExpiredJwtException e) {
|
} catch (ExpiredJwtException e) {
|
||||||
|
logger.error("parseToken error", e);
|
||||||
throw new BusinessException(ReturnCodeEnum.CODE_TOKEN_ERROR);
|
throw new BusinessException(ReturnCodeEnum.CODE_TOKEN_ERROR);
|
||||||
}
|
}
|
||||||
return claims;
|
return claims;
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ package com.jsowell.common.util.file;
|
|||||||
import com.aliyun.oss.OSS;
|
import com.aliyun.oss.OSS;
|
||||||
import com.aliyun.oss.OSSClientBuilder;
|
import com.aliyun.oss.OSSClientBuilder;
|
||||||
import com.jsowell.common.config.AliyunOssConfig;
|
import com.jsowell.common.config.AliyunOssConfig;
|
||||||
|
import com.jsowell.common.util.RandomUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class AliyunOssUploadUtils {
|
public class AliyunOssUploadUtils {
|
||||||
@@ -39,8 +41,16 @@ public class AliyunOssUploadUtils {
|
|||||||
|
|
||||||
// 编码文件名
|
// 编码文件名
|
||||||
String filePathName = FileUploadUtils.extractFilename(file);
|
String filePathName = FileUploadUtils.extractFilename(file);
|
||||||
|
|
||||||
|
//获取当前时间
|
||||||
|
LocalDateTime currentDate = LocalDateTime.now();
|
||||||
|
String dir_name = currentDate.getYear() + "/" + currentDate.getMonthValue() + "/";
|
||||||
|
|
||||||
|
// 随机数
|
||||||
|
String randomNumber = RandomUtil.getRandomNumber(5) + "-";
|
||||||
|
|
||||||
// 文件路径名称
|
// 文件路径名称
|
||||||
filePathName = aliyunOssConfig.getFilehost() + "/" + filePathName;
|
filePathName = aliyunOssConfig.getFilehost() + "/" + dir_name + randomNumber + filePathName;
|
||||||
try {
|
try {
|
||||||
ossClient.putObject(aliyunOssConfig.getBucketName(), filePathName, file.getInputStream());
|
ossClient.putObject(aliyunOssConfig.getBucketName(), filePathName, file.getInputStream());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|||||||
@@ -99,6 +99,9 @@ public abstract class AbstractOrderLogic implements InitializingBean {
|
|||||||
@Autowired
|
@Autowired
|
||||||
protected OrderMonitorDataService orderMonitorDataService;
|
protected OrderMonitorDataService orderMonitorDataService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected MemberWalletInfoService memberWalletInfoService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
protected RedisCache redisCache;
|
protected RedisCache redisCache;
|
||||||
|
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ public class DelayMerchantOrderLogic extends AbstractOrderLogic {
|
|||||||
Map<String, Object> resultMap = Maps.newHashMap();
|
Map<String, Object> resultMap = Maps.newHashMap();
|
||||||
if (StringUtils.equals(dto.getPayMode(), OrderPayModeEnum.PAYMENT_OF_BALANCE.getValue())) {
|
if (StringUtils.equals(dto.getPayMode(), OrderPayModeEnum.PAYMENT_OF_BALANCE.getValue())) {
|
||||||
// 余额支付
|
// 余额支付
|
||||||
balancePayOrder(dto);
|
balancePayOrderV2(dto);
|
||||||
} else if (StringUtils.equals(dto.getPayMode(), OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())) {
|
} else if (StringUtils.equals(dto.getPayMode(), OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())) {
|
||||||
// 2023-07-11 全部改为汇付支付
|
// 2023-07-11 全部改为汇付支付
|
||||||
dto.setGoodsTitle("充电费用");
|
dto.setGoodsTitle("充电费用");
|
||||||
@@ -265,7 +265,6 @@ public class DelayMerchantOrderLogic extends AbstractOrderLogic {
|
|||||||
.payMode(OrderPayRecordEnum.PRINCIPAL_BALANCE_PAYMENT.getValue())
|
.payMode(OrderPayRecordEnum.PRINCIPAL_BALANCE_PAYMENT.getValue())
|
||||||
.payAmount(payAmt)
|
.payAmount(payAmt)
|
||||||
.acquirer(AcquirerEnum.LOCAL.getValue())
|
.acquirer(AcquirerEnum.LOCAL.getValue())
|
||||||
// .deductionRecord(jsonArray.toJSONString())
|
|
||||||
.deductionRecord(JSON.toJSONString(paymentInfos))
|
.deductionRecord(JSON.toJSONString(paymentInfos))
|
||||||
.createBy(dto.getMemberId())
|
.createBy(dto.getMemberId())
|
||||||
.delFlag(DelFlagEnum.NORMAL.getValue())
|
.delFlag(DelFlagEnum.NORMAL.getValue())
|
||||||
@@ -310,6 +309,110 @@ public class DelayMerchantOrderLogic extends AbstractOrderLogic {
|
|||||||
memberTransactionRecordService.insertSelective(record);
|
memberTransactionRecordService.insertSelective(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 余额支付订单
|
||||||
|
*/
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void balancePayOrderV2(PayOrderDTO dto) {
|
||||||
|
logger.info("【{}】-余额支付订单V2start, param:{}", this.getClass().getSimpleName(), JSON.toJSONString(dto));
|
||||||
|
// 订单编号
|
||||||
|
String orderCode = dto.getOrderCode();
|
||||||
|
// 查订单详情
|
||||||
|
OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByOrderCode(orderCode);
|
||||||
|
// 订单所属运营商id
|
||||||
|
String merchantId = orderBasicInfo.getMerchantId();
|
||||||
|
// 支付金额
|
||||||
|
BigDecimal chargeAmount = dto.getPayAmount();
|
||||||
|
// 会员id
|
||||||
|
String memberId = dto.getMemberId();
|
||||||
|
// 查询该会员的余额 在所属运营商的余额
|
||||||
|
// MemberVO memberVO = memberBasicInfoService.queryMemberInfoByMemberId(dto.getMemberId());
|
||||||
|
MemberWalletInfo memberWalletInfo = memberWalletInfoService.selectByMemberId(memberId, merchantId);
|
||||||
|
BigDecimal totalAccountAmount = memberWalletInfo.getPrincipalBalance(); // 总余额
|
||||||
|
|
||||||
|
if (totalAccountAmount.compareTo(chargeAmount) < 0) {
|
||||||
|
// 总余额小于充电金额
|
||||||
|
throw new BusinessException(ReturnCodeEnum.CODE_BALANCE_IS_INSUFFICIENT);
|
||||||
|
}
|
||||||
|
BigDecimal principalPay = chargeAmount;
|
||||||
|
|
||||||
|
// 更新会员钱包
|
||||||
|
UpdateMemberBalanceDTO updateMemberBalanceDTO = UpdateMemberBalanceDTO.builder()
|
||||||
|
.memberId(memberId)
|
||||||
|
.targetMerchantId(merchantId)
|
||||||
|
.type(MemberWalletEnum.TYPE_OUT.getValue())
|
||||||
|
.subType(MemberWalletEnum.SUBTYPE_PAYMENT_FOR_ORDER.getValue())
|
||||||
|
.updatePrincipalBalance(principalPay) // 使用本金支付的金额
|
||||||
|
.relatedOrderCode(orderCode)
|
||||||
|
.build();
|
||||||
|
memberBasicInfoService.updateMemberBalance(updateMemberBalanceDTO);
|
||||||
|
|
||||||
|
// 查询余额充值有剩余的记录
|
||||||
|
// List<BalanceDeductionAmountVO> list = calculateTheBalanceDeductionAmount(memberId, chargeAmount);
|
||||||
|
|
||||||
|
// 记录订单支付流水
|
||||||
|
BigDecimal payAmt = BigDecimal.ZERO;
|
||||||
|
List<PaymentInfo> paymentInfos = Lists.newArrayList();
|
||||||
|
// for (BalanceDeductionAmountVO balanceDeductionAmountVO : list) {
|
||||||
|
// String paymentId = balanceDeductionAmountVO.getPaymentId();
|
||||||
|
// // 此交易单扣除金额
|
||||||
|
// BigDecimal deductionAmount = balanceDeductionAmountVO.getDeductionAmount();
|
||||||
|
// payAmt = payAmt.add(deductionAmount);
|
||||||
|
//
|
||||||
|
// PaymentInfo paymentInfo = new PaymentInfo();
|
||||||
|
// paymentInfo.setPaymentId(paymentId);
|
||||||
|
// paymentInfo.setAmount(deductionAmount.toString());
|
||||||
|
// paymentInfos.add(paymentInfo);
|
||||||
|
// }
|
||||||
|
OrderPayRecord build = OrderPayRecord.builder()
|
||||||
|
.orderCode(orderCode)
|
||||||
|
.payMode(OrderPayRecordEnum.PRINCIPAL_BALANCE_PAYMENT.getValue())
|
||||||
|
.payAmount(principalPay)
|
||||||
|
.acquirer(AcquirerEnum.LOCAL.getValue())
|
||||||
|
.deductionRecord(JSON.toJSONString(paymentInfos))
|
||||||
|
.createBy(memberId)
|
||||||
|
.delFlag(DelFlagEnum.NORMAL.getValue())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
// 记录支订单付流水
|
||||||
|
List<OrderPayRecord> payRecordList = Lists.newArrayList(build);
|
||||||
|
orderPayRecordService.batchInsert(payRecordList);
|
||||||
|
|
||||||
|
// 把消费金额冻结
|
||||||
|
// for (OrderPayRecord record : payRecordList) {
|
||||||
|
// List<PaymentInfo> paymentInfoList = parseDeductionRecord(record.getDeductionRecord());
|
||||||
|
// // 循环冻结金额
|
||||||
|
// for (PaymentInfo paymentInfo : paymentInfoList) {
|
||||||
|
// String paymentId = paymentInfo.getPaymentId();
|
||||||
|
// BigDecimal amount = new BigDecimal(paymentInfo.getAmount());
|
||||||
|
// // 余额支付 临时冻结金额
|
||||||
|
// memberAdapayRecordService.updateFreezeAmount(paymentId, amount);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 余额支付可以直接调支付回调方法
|
||||||
|
PayOrderSuccessCallbackDTO callbackDTO = PayOrderSuccessCallbackDTO.builder()
|
||||||
|
.orderCode(orderCode)
|
||||||
|
.payAmount(chargeAmount)
|
||||||
|
.payMode(dto.getPayMode())
|
||||||
|
.startMode(dto.getStartMode())
|
||||||
|
.acquirer(AcquirerEnum.LOCAL.getValue())
|
||||||
|
.build();
|
||||||
|
payOrderSuccessCallback(callbackDTO);
|
||||||
|
|
||||||
|
// 余额支付订单 记录会员交易流水
|
||||||
|
MemberTransactionRecord record = MemberTransactionRecord.builder()
|
||||||
|
.orderCode(orderCode)
|
||||||
|
.scenarioType(ScenarioEnum.ORDER.getValue())
|
||||||
|
.memberId(memberId)
|
||||||
|
.actionType(ActionTypeEnum.FORWARD.getValue())
|
||||||
|
.payMode(PayModeEnum.PAYMENT_OF_BALANCE.getValue())
|
||||||
|
.paymentInstitutions(PaymentInstitutionsEnum.LOCAL_ACCOUNTS.getValue())
|
||||||
|
.amount(dto.getPayAmount()) // 单位元
|
||||||
|
.build();
|
||||||
|
memberTransactionRecordService.insertSelective(record);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在线支付订单
|
* 在线支付订单
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user