微信支付调整

This commit is contained in:
Hawking 2023-06-01 15:50:31 +08:00
parent 8df08d1ff1
commit 84bbf53ea4
5 changed files with 114 additions and 20 deletions

View File

@ -1,12 +1,12 @@
package com.ghy.web.controller.pay;
import com.alibaba.fastjson.JSONObject;
import com.ghy.common.adapay.model.PayParam;
import com.ghy.common.adapay.model.WxpayExpend;
import com.ghy.common.config.WxConfig;
import com.ghy.common.core.controller.BaseController;
import com.ghy.common.core.domain.AjaxResult;
import com.ghy.common.enums.PayStatus;
import com.ghy.common.json.JSONObject;
import com.ghy.common.utils.StringUtils;
import com.ghy.order.domain.OrderDetail;
import com.ghy.order.domain.OrderMaster;
@ -14,9 +14,11 @@ import com.ghy.order.service.OrderDetailService;
import com.ghy.order.service.OrderMasterService;
import com.ghy.payment.domain.FinancialChangeRecord;
import com.ghy.payment.domain.FinancialMaster;
import com.ghy.payment.domain.PaymentRelation;
import com.ghy.payment.service.AdapayService;
import com.ghy.payment.service.FinancialChangeRecordService;
import com.ghy.payment.service.FinancialMasterService;
import com.ghy.payment.service.IPaymentRelationService;
import com.huifu.adapay.core.exception.BaseAdaPayException;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
@ -30,7 +32,6 @@ import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Controller
@ -47,7 +48,8 @@ public class WxPayController extends BaseController {
private FinancialMasterService financialMasterService;
@Resource
private OrderDetailService orderDetailService;
@Resource
private IPaymentRelationService paymentRelationService;
@Resource
private FinancialChangeRecordService financialChangeRecordService;
@ -56,11 +58,11 @@ public class WxPayController extends BaseController {
public AjaxResult drawCash(@RequestBody JSONObject object) {
try {
Long deptId = object.getLong("deptId");
String orderNo = object.getStr("orderNo");
String cashType = object.getStr("cashType");
String cashAmt = object.getStr("cashAmt");
String memberId = object.getStr("memberId");
String remark = object.getStr("remark");
String orderNo = object.getString("orderNo");
String cashType = object.getString("cashType");
String cashAmt = object.getString("cashAmt");
String memberId = object.getString("memberId");
String remark = object.getString("remark");
adapayService.drawCash(deptId, orderNo, cashType, cashAmt, memberId, remark, null);
return AjaxResult.success("操作成功");
} catch (Exception e) {
@ -80,33 +82,41 @@ public class WxPayController extends BaseController {
Assert.notNull(orderMaster, "找不到对应的订单");
FinancialMaster financialMaster = financialMasterService.selectByOrderMasterId(orderMaster.getId());
BigDecimal payMoney = BigDecimal.ZERO;
if(PayStatus.WAIT_PAY.getCode().equals(financialMaster.getPayStatus())){
ArrayList<PaymentRelation> relations = new ArrayList<>();
if (PayStatus.WAIT_PAY.getCode().equals(financialMaster.getPayStatus())) {
payMoney = financialMaster.getPayMoney();
relations.add(new PaymentRelation(null, financialMaster.getId(), PaymentRelation.FINANCIAL_MASTER, financialMaster.getPayMoney()));
}
List<Long> idList = orderDetailService.selectByOrderMasterId(orderMaster.getId()).stream().map(OrderDetail::getId).collect(Collectors.toList());
List<FinancialChangeRecord> financialChangeRecords = financialChangeRecordService.selectByDetailIds(StringUtils.join(idList, ","));
List<Long> financialChangeRecordIds = new ArrayList<>();
for (FinancialChangeRecord financialChangeRecord : financialChangeRecords) {
if (PayStatus.WAIT_PAY.getCode().equals(financialChangeRecord.getPayStatus())) {
payMoney = payMoney.add(financialChangeRecord.getChangeMoney());
financialChangeRecordIds.add(financialChangeRecord.getId());
for (FinancialChangeRecord fcr : financialChangeRecords) {
if (PayStatus.WAIT_PAY.getCode().equals(fcr.getPayStatus())) {
payMoney = payMoney.add(fcr.getChangeMoney());
financialChangeRecordIds.add(fcr.getId());
relations.add(new PaymentRelation(null, fcr.getId(), PaymentRelation.FINANCIAL_CHANGE, fcr.getChangeMoney()));
}
}
//调用adapay微信公众号支付.
WxpayExpend expend = new WxpayExpend();
expend.setOpenId(openId);
Map<String, Object> map;
try {
// TODO 订单里需要补充支付金额tittle简要描述分账信息description
String changeRecordIdStr = financialChangeRecordIds.size() > 0 ? StringUtils.join(financialChangeRecordIds, ",") + "_" : "";
PayParam payParam = PayParam.delayPayParam(orderMaster.getCode() + "_" + changeRecordIdStr + System.currentTimeMillis(),
String.valueOf(payMoney), "工圈子居家设备", "工圈子居家设备购买付费");
map = adapayService.wxLitePay(orderMaster.getDeptId(), payParam, expend, null, null);
JSONObject response = adapayService.wxLitePay(orderMaster.getDeptId(), payParam, expend, null, null);
String paymentId = response.getString("id");
// 保存支付ID与订单ID到关系表
for (PaymentRelation relation : relations) {
relation.setPaymentId(paymentId);
paymentRelationService.insert(relation);
}
return AjaxResult.success(response);
} catch (BaseAdaPayException e) {
logger.error("获取微信用户信息失败", e);
return AjaxResult.error();
}
return AjaxResult.success(map);
}
// /**

View File

@ -2,12 +2,16 @@ package com.ghy.payment.domain;
import lombok.Data;
import java.math.BigDecimal;
/**
* 支付单关联表
*/
@Data
public class PaymentRelation {
private Long id;
/**
* 支付ID
*/
@ -26,6 +30,20 @@ public class PaymentRelation {
*/
private String relationIdType;
/**
* 流水分担金额
*/
private BigDecimal payAmt;
public PaymentRelation() {
}
public PaymentRelation(String paymentId, Long relationId, String relationIdType, BigDecimal payAmt) {
this.paymentId = paymentId;
this.relationId = relationId;
this.relationIdType = relationIdType;
this.payAmt = payAmt;
}
public static final String FINANCIAL_MASTER = "financial_master";
public static final String FINANCIAL_CHANGE = "financial_change";

View File

@ -0,0 +1,17 @@
package com.ghy.payment.service;
import com.ghy.payment.domain.PaymentRelation;
import java.util.Collection;
import java.util.List;
public interface IPaymentRelationService {
int insert(PaymentRelation record);
int batchInsert(Collection<PaymentRelation> record);
List<PaymentRelation> select(String paymentId, Long relationId, String relationIdType);
List<PaymentRelation> selectByPaymentId(String paymentId);
}

View File

@ -0,0 +1,46 @@
package com.ghy.payment.service.impl;
import com.ghy.payment.domain.PaymentRelation;
import com.ghy.payment.mapper.PaymentRelationMapper;
import com.ghy.payment.service.IPaymentRelationService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
@Service
public class PaymentRelationServiceImpl implements IPaymentRelationService {
@Resource
private PaymentRelationMapper paymentRelationMapper;
@Override
public int insert(PaymentRelation record) {
return paymentRelationMapper.insert(record);
}
@Override
public int batchInsert(Collection<PaymentRelation> records) {
if (CollectionUtils.isEmpty(records)) {
return 0;
} else {
int i = 0;
for (PaymentRelation record : records) {
i += paymentRelationMapper.insert(record);
}
return i;
}
}
@Override
public List<PaymentRelation> select(String paymentId, Long relationId, String relationIdType) {
return null;
}
@Override
public List<PaymentRelation> selectByPaymentId(String paymentId) {
return null;
}
}

View File

@ -3,13 +3,16 @@
<mapper namespace="com.ghy.payment.mapper.PaymentRelationMapper">
<sql id="select_columns">
SELECT payment_id AS paymentId, relation_id AS relationId, relation_type AS relationIdType
SELECT payment_id AS paymentId, relation_id AS relationId, relation_type AS relationIdType, pay_amt AS payAmt
FROM payment_relation
</sql>
<insert id="insert" parameterType="com.ghy.payment.domain.DrawCashRecord">
INSERT INTO payment_relation(payment_id, relation_id, relation_type)
VALUES (#{paymentId}, #{relationId}, #{relationIdType})
<insert id="insert" parameterType="com.ghy.payment.domain.PaymentRelation">
INSERT INTO payment_relation( payment_id, relation_id, relation_type
<if test="payAmt != null">, pay_amt</if>
)
VALUES (#{paymentId}, #{relationId}, #{relationIdType}
<if test="payAmt != null">, #{payAmt}</if>)
</insert>
<select id="selectByPaymentId" resultType="com.ghy.payment.domain.PaymentRelation">