mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-07-15 03:27:59 +08:00
update订单逻辑改造工厂模式
This commit is contained in:
@@ -22,6 +22,7 @@ import com.jsowell.common.constant.Constants;
|
|||||||
import com.jsowell.common.core.redis.RedisCache;
|
import com.jsowell.common.core.redis.RedisCache;
|
||||||
import com.jsowell.common.enums.DelFlagEnum;
|
import com.jsowell.common.enums.DelFlagEnum;
|
||||||
import com.jsowell.common.enums.adapay.AdapayStatusEnum;
|
import com.jsowell.common.enums.adapay.AdapayStatusEnum;
|
||||||
|
import com.jsowell.common.enums.adapay.MerchantDelayModeEnum;
|
||||||
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 com.jsowell.common.util.AdapayUtil;
|
import com.jsowell.common.util.AdapayUtil;
|
||||||
@@ -105,7 +106,8 @@ public class AdapayService {
|
|||||||
// 封装对象
|
// 封装对象
|
||||||
String amount = AdapayUtil.formatAmount(dto.getPayAmount()); // 用户支付金额
|
String amount = AdapayUtil.formatAmount(dto.getPayAmount()); // 用户支付金额
|
||||||
// String payMode = Constants.ADAPAY_PAY_MODE_DELAY; // 汇付延时分账
|
// String payMode = Constants.ADAPAY_PAY_MODE_DELAY; // 汇付延时分账
|
||||||
// String payMode = pileMerchantInfoService.getDelayModeByWechatAppId(dto.getWechatAppId());
|
String delayMode = pileMerchantInfoService.getDelayModeByWechatAppId(dto.getWechatAppId());
|
||||||
|
String payMode = MerchantDelayModeEnum.getAdapayPayMode(delayMode);
|
||||||
CreateAdaPaymentParam createAdaPaymentParam = new CreateAdaPaymentParam();
|
CreateAdaPaymentParam createAdaPaymentParam = new CreateAdaPaymentParam();
|
||||||
createAdaPaymentParam.setOrder_no(dto.getOrderCode());
|
createAdaPaymentParam.setOrder_no(dto.getOrderCode());
|
||||||
createAdaPaymentParam.setPay_amt(amount);
|
createAdaPaymentParam.setPay_amt(amount);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.jsowell.pile.service.orderlogic;
|
package com.jsowell.pile.service.orderlogic;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.alibaba.fastjson2.JSONArray;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
@@ -27,6 +28,7 @@ import com.jsowell.pile.vo.web.UpdateMemberBalanceDTO;
|
|||||||
import com.jsowell.wxpay.dto.WechatSendMsgDTO;
|
import com.jsowell.wxpay.dto.WechatSendMsgDTO;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -80,9 +82,12 @@ public class DelayMerchantOrderLogic extends AbstractOrderLogic {
|
|||||||
/**
|
/**
|
||||||
* 余额支付订单
|
* 余额支付订单
|
||||||
*/
|
*/
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void balancePayOrder(PayOrderDTO dto) {
|
public void balancePayOrder(PayOrderDTO dto) {
|
||||||
String orderCode = dto.getOrderCode(); // 订单编号
|
// 订单编号
|
||||||
BigDecimal chargeAmount = dto.getPayAmount(); // 支付金额
|
String orderCode = dto.getOrderCode();
|
||||||
|
// 支付金额
|
||||||
|
BigDecimal chargeAmount = dto.getPayAmount();
|
||||||
// 查询该会员的余额
|
// 查询该会员的余额
|
||||||
MemberVO memberVO = memberBasicInfoService.queryMemberInfoByMemberId(dto.getMemberId());
|
MemberVO memberVO = memberBasicInfoService.queryMemberInfoByMemberId(dto.getMemberId());
|
||||||
BigDecimal totalAccountAmount = memberVO.getPrincipalBalance();
|
BigDecimal totalAccountAmount = memberVO.getPrincipalBalance();
|
||||||
@@ -105,37 +110,59 @@ public class DelayMerchantOrderLogic extends AbstractOrderLogic {
|
|||||||
|
|
||||||
// 查询余额充值有剩余的记录
|
// 查询余额充值有剩余的记录
|
||||||
List<BalanceDeductionAmountVO> list = calculateTheBalanceDeductionAmount(dto.getMemberId(), chargeAmount);
|
List<BalanceDeductionAmountVO> list = calculateTheBalanceDeductionAmount(dto.getMemberId(), chargeAmount);
|
||||||
// 记录支订单付流水
|
|
||||||
List<OrderPayRecord> payRecordList = Lists.newArrayList();
|
// 记录订单支付流水
|
||||||
|
JSONArray jsonArray = new JSONArray();
|
||||||
|
BigDecimal payAmt = BigDecimal.ZERO;
|
||||||
for (BalanceDeductionAmountVO balanceDeductionAmountVO : list) {
|
for (BalanceDeductionAmountVO balanceDeductionAmountVO : list) {
|
||||||
String paymentId = balanceDeductionAmountVO.getPaymentId();
|
String paymentId = balanceDeductionAmountVO.getPaymentId();
|
||||||
|
// 此交易单扣除金额
|
||||||
BigDecimal deductionAmount = balanceDeductionAmountVO.getDeductionAmount();
|
BigDecimal deductionAmount = balanceDeductionAmountVO.getDeductionAmount();
|
||||||
|
payAmt = payAmt.add(deductionAmount);
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
json.put("paymentId", paymentId);
|
json.put("paymentId", paymentId);
|
||||||
json.put("amount", deductionAmount);
|
json.put("amount", deductionAmount);
|
||||||
// 记录流水
|
jsonArray.add(json);
|
||||||
payRecordList.add(OrderPayRecord.builder()
|
}
|
||||||
|
OrderPayRecord build = OrderPayRecord.builder()
|
||||||
.orderCode(orderCode)
|
.orderCode(orderCode)
|
||||||
.payMode(OrderPayRecordEnum.PRINCIPAL_BALANCE_PAYMENT.getValue())
|
.payMode(OrderPayRecordEnum.PRINCIPAL_BALANCE_PAYMENT.getValue())
|
||||||
.payAmount(deductionAmount)
|
.payAmount(payAmt)
|
||||||
.acquirer(AcquirerEnum.LOCAL.getValue())
|
.acquirer(AcquirerEnum.LOCAL.getValue())
|
||||||
.deductionRecord(json.toJSONString())
|
.deductionRecord(jsonArray.toJSONString())
|
||||||
.createBy(dto.getMemberId())
|
.createBy(dto.getMemberId())
|
||||||
.delFlag(DelFlagEnum.NORMAL.getValue())
|
.delFlag(DelFlagEnum.NORMAL.getValue())
|
||||||
.build());
|
.build();
|
||||||
}
|
|
||||||
|
// 记录支订单付流水
|
||||||
|
List<OrderPayRecord> payRecordList = Lists.newArrayList(build);
|
||||||
|
|
||||||
// 订单支付流水入库
|
// 订单支付流水入库
|
||||||
if (CollectionUtils.isNotEmpty(payRecordList)) {
|
if (CollectionUtils.isNotEmpty(payRecordList)) {
|
||||||
orderPayRecordService.batchInsert(payRecordList);
|
orderPayRecordService.batchInsert(payRecordList);
|
||||||
|
|
||||||
|
// 把消费金额冻结
|
||||||
for (OrderPayRecord record : payRecordList) {
|
for (OrderPayRecord record : payRecordList) {
|
||||||
String deductionRecord = record.getDeductionRecord();
|
String deductionRecord = record.getDeductionRecord();
|
||||||
JSONObject jsonObject = JSON.parseObject(deductionRecord);
|
Object object = JSON.parse(deductionRecord);
|
||||||
|
|
||||||
|
// 都放入list里
|
||||||
|
List<JSONObject> arr = Lists.newArrayList();
|
||||||
|
if (object instanceof JSONArray) {
|
||||||
|
arr.addAll(((JSONArray) object).toList(JSONObject.class));
|
||||||
|
} else {
|
||||||
|
arr.add((JSONObject) object);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 循环冻结金额
|
||||||
|
for (JSONObject jsonObject : arr) {
|
||||||
String paymentId = jsonObject.getString("paymentId");
|
String paymentId = jsonObject.getString("paymentId");
|
||||||
BigDecimal amount = jsonObject.getBigDecimal("amount");
|
BigDecimal amount = jsonObject.getBigDecimal("amount");
|
||||||
// 余额支付 临时冻结金额
|
// 余额支付 临时冻结金额
|
||||||
memberAdapayRecordService.updateFreezeAmount(paymentId, amount);
|
memberAdapayRecordService.updateFreezeAmount(paymentId, amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 余额支付可以直接调支付回调方法
|
// 余额支付可以直接调支付回调方法
|
||||||
PayOrderSuccessCallbackDTO callbackDTO = PayOrderSuccessCallbackDTO.builder()
|
PayOrderSuccessCallbackDTO callbackDTO = PayOrderSuccessCallbackDTO.builder()
|
||||||
|
|||||||
Reference in New Issue
Block a user