微信支付调整
This commit is contained in:
parent
8df08d1ff1
commit
84bbf53ea4
|
|
@ -1,12 +1,12 @@
|
||||||
package com.ghy.web.controller.pay;
|
package com.ghy.web.controller.pay;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.ghy.common.adapay.model.PayParam;
|
import com.ghy.common.adapay.model.PayParam;
|
||||||
import com.ghy.common.adapay.model.WxpayExpend;
|
import com.ghy.common.adapay.model.WxpayExpend;
|
||||||
import com.ghy.common.config.WxConfig;
|
import com.ghy.common.config.WxConfig;
|
||||||
import com.ghy.common.core.controller.BaseController;
|
import com.ghy.common.core.controller.BaseController;
|
||||||
import com.ghy.common.core.domain.AjaxResult;
|
import com.ghy.common.core.domain.AjaxResult;
|
||||||
import com.ghy.common.enums.PayStatus;
|
import com.ghy.common.enums.PayStatus;
|
||||||
import com.ghy.common.json.JSONObject;
|
|
||||||
import com.ghy.common.utils.StringUtils;
|
import com.ghy.common.utils.StringUtils;
|
||||||
import com.ghy.order.domain.OrderDetail;
|
import com.ghy.order.domain.OrderDetail;
|
||||||
import com.ghy.order.domain.OrderMaster;
|
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.order.service.OrderMasterService;
|
||||||
import com.ghy.payment.domain.FinancialChangeRecord;
|
import com.ghy.payment.domain.FinancialChangeRecord;
|
||||||
import com.ghy.payment.domain.FinancialMaster;
|
import com.ghy.payment.domain.FinancialMaster;
|
||||||
|
import com.ghy.payment.domain.PaymentRelation;
|
||||||
import com.ghy.payment.service.AdapayService;
|
import com.ghy.payment.service.AdapayService;
|
||||||
import com.ghy.payment.service.FinancialChangeRecordService;
|
import com.ghy.payment.service.FinancialChangeRecordService;
|
||||||
import com.ghy.payment.service.FinancialMasterService;
|
import com.ghy.payment.service.FinancialMasterService;
|
||||||
|
import com.ghy.payment.service.IPaymentRelationService;
|
||||||
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
@ -30,7 +32,6 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
|
|
@ -47,7 +48,8 @@ public class WxPayController extends BaseController {
|
||||||
private FinancialMasterService financialMasterService;
|
private FinancialMasterService financialMasterService;
|
||||||
@Resource
|
@Resource
|
||||||
private OrderDetailService orderDetailService;
|
private OrderDetailService orderDetailService;
|
||||||
|
@Resource
|
||||||
|
private IPaymentRelationService paymentRelationService;
|
||||||
@Resource
|
@Resource
|
||||||
private FinancialChangeRecordService financialChangeRecordService;
|
private FinancialChangeRecordService financialChangeRecordService;
|
||||||
|
|
||||||
|
|
@ -56,11 +58,11 @@ public class WxPayController extends BaseController {
|
||||||
public AjaxResult drawCash(@RequestBody JSONObject object) {
|
public AjaxResult drawCash(@RequestBody JSONObject object) {
|
||||||
try {
|
try {
|
||||||
Long deptId = object.getLong("deptId");
|
Long deptId = object.getLong("deptId");
|
||||||
String orderNo = object.getStr("orderNo");
|
String orderNo = object.getString("orderNo");
|
||||||
String cashType = object.getStr("cashType");
|
String cashType = object.getString("cashType");
|
||||||
String cashAmt = object.getStr("cashAmt");
|
String cashAmt = object.getString("cashAmt");
|
||||||
String memberId = object.getStr("memberId");
|
String memberId = object.getString("memberId");
|
||||||
String remark = object.getStr("remark");
|
String remark = object.getString("remark");
|
||||||
adapayService.drawCash(deptId, orderNo, cashType, cashAmt, memberId, remark, null);
|
adapayService.drawCash(deptId, orderNo, cashType, cashAmt, memberId, remark, null);
|
||||||
return AjaxResult.success("操作成功");
|
return AjaxResult.success("操作成功");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
@ -80,33 +82,41 @@ public class WxPayController extends BaseController {
|
||||||
Assert.notNull(orderMaster, "找不到对应的订单");
|
Assert.notNull(orderMaster, "找不到对应的订单");
|
||||||
FinancialMaster financialMaster = financialMasterService.selectByOrderMasterId(orderMaster.getId());
|
FinancialMaster financialMaster = financialMasterService.selectByOrderMasterId(orderMaster.getId());
|
||||||
BigDecimal payMoney = BigDecimal.ZERO;
|
BigDecimal payMoney = BigDecimal.ZERO;
|
||||||
|
ArrayList<PaymentRelation> relations = new ArrayList<>();
|
||||||
if (PayStatus.WAIT_PAY.getCode().equals(financialMaster.getPayStatus())) {
|
if (PayStatus.WAIT_PAY.getCode().equals(financialMaster.getPayStatus())) {
|
||||||
payMoney = financialMaster.getPayMoney();
|
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<Long> idList = orderDetailService.selectByOrderMasterId(orderMaster.getId()).stream().map(OrderDetail::getId).collect(Collectors.toList());
|
||||||
List<FinancialChangeRecord> financialChangeRecords = financialChangeRecordService.selectByDetailIds(StringUtils.join(idList, ","));
|
List<FinancialChangeRecord> financialChangeRecords = financialChangeRecordService.selectByDetailIds(StringUtils.join(idList, ","));
|
||||||
List<Long> financialChangeRecordIds = new ArrayList<>();
|
List<Long> financialChangeRecordIds = new ArrayList<>();
|
||||||
for (FinancialChangeRecord financialChangeRecord : financialChangeRecords) {
|
for (FinancialChangeRecord fcr : financialChangeRecords) {
|
||||||
if (PayStatus.WAIT_PAY.getCode().equals(financialChangeRecord.getPayStatus())) {
|
if (PayStatus.WAIT_PAY.getCode().equals(fcr.getPayStatus())) {
|
||||||
payMoney = payMoney.add(financialChangeRecord.getChangeMoney());
|
payMoney = payMoney.add(fcr.getChangeMoney());
|
||||||
financialChangeRecordIds.add(financialChangeRecord.getId());
|
financialChangeRecordIds.add(fcr.getId());
|
||||||
|
relations.add(new PaymentRelation(null, fcr.getId(), PaymentRelation.FINANCIAL_CHANGE, fcr.getChangeMoney()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//调用adapay微信公众号支付.
|
//调用adapay微信公众号支付.
|
||||||
WxpayExpend expend = new WxpayExpend();
|
WxpayExpend expend = new WxpayExpend();
|
||||||
expend.setOpenId(openId);
|
expend.setOpenId(openId);
|
||||||
Map<String, Object> map;
|
|
||||||
try {
|
try {
|
||||||
// TODO 订单里需要补充支付金额、tittle、简要描述、分账信息、description
|
// TODO 订单里需要补充支付金额、tittle、简要描述、分账信息、description
|
||||||
String changeRecordIdStr = financialChangeRecordIds.size() > 0 ? StringUtils.join(financialChangeRecordIds, ",") + "_" : "";
|
String changeRecordIdStr = financialChangeRecordIds.size() > 0 ? StringUtils.join(financialChangeRecordIds, ",") + "_" : "";
|
||||||
PayParam payParam = PayParam.delayPayParam(orderMaster.getCode() + "_" + changeRecordIdStr + System.currentTimeMillis(),
|
PayParam payParam = PayParam.delayPayParam(orderMaster.getCode() + "_" + changeRecordIdStr + System.currentTimeMillis(),
|
||||||
String.valueOf(payMoney), "工圈子居家设备", "工圈子居家设备购买付费");
|
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) {
|
} catch (BaseAdaPayException e) {
|
||||||
logger.error("获取微信用户信息失败", e);
|
logger.error("获取微信用户信息失败", e);
|
||||||
return AjaxResult.error();
|
return AjaxResult.error();
|
||||||
}
|
}
|
||||||
return AjaxResult.success(map);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,16 @@ package com.ghy.payment.domain;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付单关联表
|
* 支付单关联表
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class PaymentRelation {
|
public class PaymentRelation {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付ID
|
* 支付ID
|
||||||
*/
|
*/
|
||||||
|
|
@ -26,6 +30,20 @@ public class PaymentRelation {
|
||||||
*/
|
*/
|
||||||
private String relationIdType;
|
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_MASTER = "financial_master";
|
||||||
public static final String FINANCIAL_CHANGE = "financial_change";
|
public static final String FINANCIAL_CHANGE = "financial_change";
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,13 +3,16 @@
|
||||||
<mapper namespace="com.ghy.payment.mapper.PaymentRelationMapper">
|
<mapper namespace="com.ghy.payment.mapper.PaymentRelationMapper">
|
||||||
|
|
||||||
<sql id="select_columns">
|
<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
|
FROM payment_relation
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<insert id="insert" parameterType="com.ghy.payment.domain.DrawCashRecord">
|
<insert id="insert" parameterType="com.ghy.payment.domain.PaymentRelation">
|
||||||
INSERT INTO payment_relation(payment_id, relation_id, relation_type)
|
INSERT INTO payment_relation( payment_id, relation_id, relation_type
|
||||||
VALUES (#{paymentId}, #{relationId}, #{relationIdType})
|
<if test="payAmt != null">, pay_amt</if>
|
||||||
|
)
|
||||||
|
VALUES (#{paymentId}, #{relationId}, #{relationIdType}
|
||||||
|
<if test="payAmt != null">, #{payAmt}</if>)
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<select id="selectByPaymentId" resultType="com.ghy.payment.domain.PaymentRelation">
|
<select id="selectByPaymentId" resultType="com.ghy.payment.domain.PaymentRelation">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue