余额结算:允许本次支付后余额为负数,但仅限于余额首次变为负数
parent
e681b925b5
commit
e4e35ed286
|
|
@ -1,6 +1,5 @@
|
|||
package com.njzscloud.supervisory.order.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.google.common.base.Strings;
|
||||
import com.njzscloud.common.core.ex.ExceptionMsg;
|
||||
import com.njzscloud.common.core.ex.Exceptions;
|
||||
|
|
@ -26,8 +25,6 @@ import com.njzscloud.supervisory.order.pojo.result.PaymentContextResult;
|
|||
import com.njzscloud.supervisory.order.service.OrderExpenseItemsService;
|
||||
import com.njzscloud.supervisory.order.service.OrderInfoService;
|
||||
import com.njzscloud.supervisory.order.service.WechatPayService;
|
||||
import com.njzscloud.supervisory.sys.user.pojo.entity.UserAccountEntity;
|
||||
import com.njzscloud.supervisory.sys.user.service.UserAccountService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
|
@ -52,8 +49,6 @@ public class PaymentController {
|
|||
private final MoneyAccountService moneyAccountService;
|
||||
private final MoneyChangeDetailService moneyChangeDetailService;
|
||||
private final WechatPayService wechatPayService;
|
||||
private final UserAccountService userAccountService;
|
||||
|
||||
|
||||
/**
|
||||
* 发起支付(占位接口,当前返回空支付内容)
|
||||
|
|
@ -127,15 +122,18 @@ public class PaymentController {
|
|||
if (ctx.getTransCompanyId() == null || ctx.getCompanyUserId() == null) {
|
||||
throw Exceptions.clierr("订单未关联清运公司,无法公司支付");
|
||||
}
|
||||
|
||||
|
||||
// 根据结算方式判断是否需要检查余额
|
||||
if (SettlementWay.BALANCE.getVal().equals(ctx.getSettlementWay())) {
|
||||
// 余额结算:需要检查余额是否充足
|
||||
if (ctx.getCompanyBalance() == null || ctx.getCompanyBalance().compareTo(ctx.getSettleMoney()) < 0) {
|
||||
// 余额结算:允许本次支付后余额为负数,但仅限于余额首次变为负数
|
||||
if (ctx.getCompanyBalance() == null) {
|
||||
ctx.setCompanyBalance(BigDecimal.ZERO);
|
||||
}
|
||||
if (ctx.getCompanyBalance().compareTo(BigDecimal.ZERO) < 0) {
|
||||
// 已经是负数,禁止再次支付
|
||||
throw Exceptions.clierr("公司账户余额不足");
|
||||
}
|
||||
}
|
||||
// 月结方式:不需要检查余额,允许余额为负数
|
||||
|
||||
// 直接扣减公司账户余额
|
||||
deductCompanyBalance(ctx, ctx.getSettleMoney(), paymentParam.getOrderId());
|
||||
|
|
@ -145,7 +143,7 @@ public class PaymentController {
|
|||
orderDto.setOutTradeNo("ORDER_" + ctx.getSn() + "_" + System.currentTimeMillis());
|
||||
orderDto.setDescription("订单支付-" + ctx.getSn());
|
||||
orderDto.setTotal(ctx.getSettleMoney().multiply(new BigDecimal("100")).longValue()); // 转换为分
|
||||
orderDto.setOpenid(ctx.getWechatOpenid());
|
||||
orderDto.setOpenid(getOpenId(paymentParam.getWxCode()));
|
||||
|
||||
WechatPayJsapiOrderResponseDto response = wechatPayService.createMiniProgramOrder(orderDto);
|
||||
|
||||
|
|
@ -456,38 +454,16 @@ public class PaymentController {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定微信账号信息
|
||||
*/
|
||||
@PostMapping("/wechat/bind")
|
||||
public R<?> bindWechatAccount(@RequestBody BindParam param) {
|
||||
// 通过userId查询用户账号信息
|
||||
UserAccountEntity userAccount = userAccountService.getOne(
|
||||
Wrappers.<UserAccountEntity>lambdaQuery()
|
||||
.eq(UserAccountEntity::getUserId, param.getUserId())
|
||||
);
|
||||
|
||||
if (userAccount == null) {
|
||||
throw new UserLoginException(ExceptionMsg.CLI_ERR_MSG, "用户不存在");
|
||||
}
|
||||
|
||||
public String getOpenId(String wxCode) {
|
||||
// 调用微信API获取openId和unionId
|
||||
Code2SessionResult code2SessionResult = WechatUtil.code2Session(new Code2SessionParam().setJs_code(param.getWxCode()));
|
||||
Code2SessionResult code2SessionResult = WechatUtil.code2Session(new Code2SessionParam().setJs_code(wxCode));
|
||||
Integer errcode = code2SessionResult.getErrcode();
|
||||
if (errcode != null && errcode != 0) {
|
||||
log.error("微信登录失败, errcode: {}, errmsg: {}", errcode, code2SessionResult.getErrmsg());
|
||||
throw new UserLoginException(ExceptionMsg.CLI_ERR_MSG, "微信登录失败");
|
||||
}
|
||||
|
||||
String openid = code2SessionResult.getOpenid();
|
||||
String unionid = code2SessionResult.getUnionid();
|
||||
|
||||
// 更新用户账号的微信信息
|
||||
userAccount.setWechatOpenid(openid);
|
||||
userAccount.setWechatUnionid(unionid);
|
||||
// userAccountService.updateById(userAccount);
|
||||
|
||||
return R.success("微信账号绑定成功");
|
||||
|
||||
return code2SessionResult.getOpenid();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue