提交 c80cd47c authored 作者: huningning's avatar huningning

增加司机接单钱包限制

上级 9e4e1b08
...@@ -94,6 +94,9 @@ public enum PerformanceResultEnum implements ResultEnum { ...@@ -94,6 +94,9 @@ public enum PerformanceResultEnum implements ResultEnum {
INTEGRAL_RULE_RATIO_ALL_EMPTY(1702, "层级划分范围不能全为空"), INTEGRAL_RULE_RATIO_ALL_EMPTY(1702, "层级划分范围不能全为空"),
INTEGRAL_RULE_NAME_EXIST(1703, "层级名称已存在"), INTEGRAL_RULE_NAME_EXIST(1703, "层级名称已存在"),
APP_POP_UP_ERROR(-1000, "app弹窗提示"),
WALLET_CODE_IS_NULL(1704, "用户钱包不存在"),
; ;
private final int code; private final int code;
private final String msg; private final String msg;
......
package com.clx.performance.dto.payment;
import com.fasterxml.jackson.annotation.JsonGetter;
import io.swagger.annotations.ApiModelProperty;
import java.math.BigDecimal;
/**
*
* @author 胡宁宁
* @date 2023年11月12日
* @description
*/
public class WalletResidueCardDTO extends WalletResidueDTO{
@ApiModelProperty(value = "消费卡余额", dataType = "double", example = "11.10")
private Long cardResidue;
@ApiModelProperty(value = "消费卡总数", dataType = "int", example = "1")
private Integer cardSum;
@ApiModelProperty(value = "昨天收益", dataType = "double", example = "11.10")
private BigDecimal yesterdayIncome;
@ApiModelProperty(value = "今日收益", dataType = "double", example = "11.10")
private BigDecimal todayIncome;
@ApiModelProperty(value = "本月收益", dataType = "double", example = "11.10")
private BigDecimal monthIncome;
@ApiModelProperty(value = "消费卡冻结余额", dataType = "double", example = "11.10")
private Long cardFrozen;
@ApiModelProperty(value = "绑定的银行卡数量", dataType = "int", example = "0")
private int cardCount;
@ApiModelProperty(value = "总资产", dataType = "double", example = "0.00")
private BigDecimal assetSum = BigDecimal.ZERO;
public BigDecimal getAssetSum() {
return assetSum;
}
public void setAssetSum(BigDecimal assetSum) {
this.assetSum = assetSum;
}
public int getCardCount() { return cardCount; }
public void setCardCount(int cardCount) { this.cardCount = cardCount; }
@JsonGetter(value="cardResidue")
public Double cardResidueFormat() {
if(cardResidue == null ) return 0D;
return new Double(this.cardResidue)/100;
}
@JsonGetter(value="cardFrozen")
public Double cardFrozenFormat() {
if(cardFrozen == null ) return 0D;
return new Double(this.cardFrozen)/100;
}
public Long getCardResidue() {
return cardResidue;
}
public void setCardResidue(Long cardResidue) {
this.cardResidue = cardResidue;
}
public Integer getCardSum() {
return cardSum;
}
public void setCardSum(Integer cardSum) {
this.cardSum = cardSum;
}
public BigDecimal getYesterdayIncome() {
return yesterdayIncome;
}
public void setYesterdayIncome(BigDecimal yesterdayIncome) {
this.yesterdayIncome = yesterdayIncome;
}
public BigDecimal getMonthIncome() {
return monthIncome;
}
public void setMonthIncome(BigDecimal monthIncome) {
this.monthIncome = monthIncome;
}
public BigDecimal getTodayIncome() {
return todayIncome;
}
public void setTodayIncome(BigDecimal todayIncome) {
this.todayIncome = todayIncome;
}
public Long getCardFrozen() {
return cardFrozen;
}
public void setCardFrozen(Long cardFrozen) {
this.cardFrozen = cardFrozen;
}
}
package com.clx.performance.dto.payment;
import com.fasterxml.jackson.annotation.JsonGetter;
import io.swagger.annotations.ApiModelProperty;
import java.math.BigDecimal;
/**
*
* @author 胡宁宁
* @date 2023年11月12日
* @description
*/
public class WalletResidueDTO {
//余额
@ApiModelProperty(value = "余额", dataType = "double", example = "11.10")
private Long residue;
//冻结的资金
@ApiModelProperty(value = "冻结的资金", dataType = "double", example = "11.10")
private Long frozen;
//保证金
@ApiModelProperty(value = "保证金", dataType = "double", example = "11.10")
private Double deposit;
//状态0锁定1正常2异常
@ApiModelProperty(value = "状态0锁定1正常2异常", dataType = "int", example = "1")
private Integer status;
//是否设置交易密码0没有1有
@ApiModelProperty(value = "是否设置交易密码0没有1有", dataType = "String", example = "1")
private String pwd;
public Long getResidue() {
return residue;
}
public void setResidue(Long residue) {
this.residue = residue;
}
public Long getFrozen() {
return frozen;
}
public void setFrozen(Long frozen) {
this.frozen = frozen;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
@JsonGetter(value="frozen")
public BigDecimal frozenFormat() {
return new BigDecimal(new Double(this.frozen)/100);
}
@JsonGetter(value="residue")
public Double residueFormat() {
return new Double(this.residue)/100;
}
@JsonGetter(value="deposit")
public Double depositFormat() {
return new Double(this.deposit)/100;
}
public Double getDeposit() {
return deposit;
}
public void setDeposit(Double deposit) {
this.deposit = deposit;
}
@Override
public String toString() {
return "WalletDTO [residue=" + residue + ", frozen=" + frozen
+ ", status=" + status + "]";
}
}
package com.clx.performance.feign;
import com.clx.performance.dto.payment.WalletResidueCardDTO;
import com.clx.user.param.thirdparty.payment.CarrierWalletSaveDTO;
import com.msl.common.result.Result;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@FeignClient(name = "payment-service")
@RequestMapping(value = "/payment-service")
public interface FeignPaymentService {
/**
* 获取钱包信息
* @param wallet
* @return
*/
@GetMapping(value = "/walletCard/getWallet")
Result<WalletResidueCardDTO> getWallet(Integer userCode);
}
package com.clx.performance.feign;
import com.clx.performance.interceptor.FeignInterceptor;
import com.msl.common.result.Result;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@FeignClient(name = "user-service", configuration = {FeignInterceptor.class})
@RequestMapping(value = "/user-service/feign/carrier/driver/user")
public interface FeignUserService {
/**
* 调用支付FeignAuth
* @return
*/
@GetMapping(value = "/getPaymentServiceAuth")
Result<String> getPaymentServiceAuth();
}
package com.clx.performance.interceptor;
import com.clx.performance.feign.FeignUserService;
import com.msl.common.result.Result;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import java.util.Objects;
/**
* @describe: 重写 feign调用的鉴权码
*/
@Configuration
@Slf4j
public class FeignConfiguration implements RequestInterceptor {
@Autowired
private FeignUserService feignUserService;
@Override
public void apply(RequestTemplate requestTemplate) {
String url = requestTemplate.url();
if (StringUtils.isBlank(url)){
return;
}
if (url.startsWith("payment-service") || url.startsWith("/payment-service")) {
Result<String> paymentServiceAuth = feignUserService.getPaymentServiceAuth();
log.info("====feign服务调用,请求头信息重写=====feignAuth={}", paymentServiceAuth);
if(paymentServiceAuth != null && Objects.equals(paymentServiceAuth.getCode(),0) && paymentServiceAuth.getData() !=null){
requestTemplate.header("feignAuth", paymentServiceAuth.getData());
}
}
}
}
package com.clx.performance.interceptor;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.beans.factory.annotation.Value;
public class FeignInterceptor implements RequestInterceptor {
@Value("${spring.application.name}")
private String serviceName;
@Override
public void apply(RequestTemplate requestTemplate) {
requestTemplate.header("feignAuth", "6265696a696e676368656e676c69616e");
requestTemplate.header("feignService", serviceName);
}
}
\ No newline at end of file
...@@ -14,12 +14,14 @@ import com.clx.performance.dao.*; ...@@ -14,12 +14,14 @@ import com.clx.performance.dao.*;
import com.clx.performance.dao.breakcontract.BreakContractDriverRecordDao; import com.clx.performance.dao.breakcontract.BreakContractDriverRecordDao;
import com.clx.performance.dto.OrderChildExpectDTO; import com.clx.performance.dto.OrderChildExpectDTO;
import com.clx.performance.dto.gd.GdRouteDTO; import com.clx.performance.dto.gd.GdRouteDTO;
import com.clx.performance.dto.payment.WalletResidueCardDTO;
import com.clx.performance.dto.zjxl.TruckTraceDTO; import com.clx.performance.dto.zjxl.TruckTraceDTO;
import com.clx.performance.enums.*; import com.clx.performance.enums.*;
import com.clx.performance.extranal.user.AddressService; import com.clx.performance.extranal.user.AddressService;
import com.clx.performance.extranal.user.DriverService; import com.clx.performance.extranal.user.DriverService;
import com.clx.performance.extranal.user.OrderService; import com.clx.performance.extranal.user.OrderService;
import com.clx.performance.extranal.user.OwnerInfoService; import com.clx.performance.extranal.user.OwnerInfoService;
import com.clx.performance.feign.FeignPaymentService;
import com.clx.performance.model.*; import com.clx.performance.model.*;
import com.clx.performance.model.breakcontract.BreakContractDriverRecord; import com.clx.performance.model.breakcontract.BreakContractDriverRecord;
import com.clx.performance.param.app.*; import com.clx.performance.param.app.*;
...@@ -44,6 +46,7 @@ import com.clx.user.vo.feign.OwnerInfoFeignVO; ...@@ -44,6 +46,7 @@ import com.clx.user.vo.feign.OwnerInfoFeignVO;
import com.msl.common.base.Optional; import com.msl.common.base.Optional;
import com.msl.common.enums.ResultCodeEnum; import com.msl.common.enums.ResultCodeEnum;
import com.msl.common.exception.ServiceSystemException; import com.msl.common.exception.ServiceSystemException;
import com.msl.common.result.Result;
import com.msl.common.utils.DateUtils; import com.msl.common.utils.DateUtils;
import com.msl.common.utils.LocalDateTimeUtils; import com.msl.common.utils.LocalDateTimeUtils;
import com.msl.common.utils.gps.GpsUtil; import com.msl.common.utils.gps.GpsUtil;
...@@ -148,6 +151,9 @@ public class OrderChildServiceImpl implements OrderChildService { ...@@ -148,6 +151,9 @@ public class OrderChildServiceImpl implements OrderChildService {
@Autowired @Autowired
private OrderChildPostService orderChildPostService; private OrderChildPostService orderChildPostService;
@Autowired
private FeignPaymentService feignPaymentService;
@Override @Override
public SaveOrderChildVO saveOrderChild(OrderChildSaveParam param) { public SaveOrderChildVO saveOrderChild(OrderChildSaveParam param) {
...@@ -227,6 +233,9 @@ public class OrderChildServiceImpl implements OrderChildService { ...@@ -227,6 +233,9 @@ public class OrderChildServiceImpl implements OrderChildService {
// 司机接单限制 // 司机接单限制
driverTakeOrderLimit(driverTruckInfo.getUserNo()); driverTakeOrderLimit(driverTruckInfo.getUserNo());
//接单钱包限制
driverTakeOrderPaymentLimit(driverTruckInfo.getWalletCode(),driverTruckInfo.getTruckOwnWalletCode());
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
OrderGoods orderGoods = orderGoodsDao.getByOrderGoodsNo(param.getOrderGoodsNo()).orElseThrow( OrderGoods orderGoods = orderGoodsDao.getByOrderGoodsNo(param.getOrderGoodsNo()).orElseThrow(
PerformanceResultEnum.ORDER_INVALID); PerformanceResultEnum.ORDER_INVALID);
...@@ -1489,11 +1498,49 @@ public class OrderChildServiceImpl implements OrderChildService { ...@@ -1489,11 +1498,49 @@ public class OrderChildServiceImpl implements OrderChildService {
private void driverTakeOrderLimit(Long driverUserNo){ private void driverTakeOrderLimit(Long driverUserNo){
Optional<BreakContractDriverRecord> limitOptional = breakContractDriverRecordDao.selectLastLimitTimeByDriverUserNo(driverUserNo, LocalDateTime.now()); Optional<BreakContractDriverRecord> limitOptional = breakContractDriverRecordDao.selectLastLimitTimeByDriverUserNo(driverUserNo, LocalDateTime.now());
if (limitOptional.isPresent()){ if (limitOptional.isPresent()){
throw new ServiceSystemException(PerformanceResultEnum.ORDER_CHILD_DRIVER_TAKE_ORDER_TIME_LIMIT, throw new ServiceSystemException(PerformanceResultEnum.APP_POP_UP_ERROR,
PerformanceResultEnum.ORDER_CHILD_DRIVER_TAKE_ORDER_TIME_LIMIT.getMsg()+LocalDateTimeUtils.convertLocalDateTimeToString(limitOptional.get().getLimitTime(), "yyyy-MM-dd HH:mm")); PerformanceResultEnum.ORDER_CHILD_DRIVER_TAKE_ORDER_TIME_LIMIT.getMsg()+LocalDateTimeUtils.convertLocalDateTimeToString(limitOptional.get().getLimitTime(), "yyyy-MM-dd HH:mm"));
} }
} }
/**
* 司机接单支付校验
*/
private void driverTakeOrderPaymentLimit(Integer driverWallCode, Integer truckWalletCode) {
//判断是司机还是车主 接单校验 必须两个都有钱包
if (Objects.isNull(driverWallCode) || Objects.isNull(truckWalletCode)) {
throw new ServiceSystemException(PerformanceResultEnum.WALLET_CODE_IS_NULL);
}
boolean truckOwnerFlag = Objects.equals(driverWallCode, truckWalletCode);
Integer checkWalletCode = truckOwnerFlag ? driverWallCode : truckWalletCode;
Result<WalletResidueCardDTO> result = feignPaymentService.getWallet(checkWalletCode);
if (result != null && Objects.equals(result.getCode(), 0) && result.getData() != null) {
WalletResidueCardDTO data = result.getData();
//钱包不能为负
if (Objects.isNull(data.getResidue()) || data.getResidue() < 0L) {
String remark = truckOwnerFlag ? "钱包余额不足" : "车主钱包余额不足";
throw new ServiceSystemException(PerformanceResultEnum.APP_POP_UP_ERROR, remark);
}
//有效银行卡数量 不能为空
if (Objects.isNull(data.getCardCount()) || data.getCardCount() <= 0) {
String remark = truckOwnerFlag ? "还没有绑定银行卡,请先绑定银行卡" : "车主还没有绑定银行卡,请先绑定银行卡";
throw new ServiceSystemException(PerformanceResultEnum.APP_POP_UP_ERROR, remark);
}
//必须设置交易密码 是否设置交易密码0没有1有
if (Objects.isNull(data.getPwd()) || Objects.equals(data.getPwd(), "0")) {
String remark = truckOwnerFlag ? "还没有设置交易密码,请先设置交易密码" : "车主还没有设置交易密码,请先设置交易密码";
throw new ServiceSystemException(PerformanceResultEnum.APP_POP_UP_ERROR, remark);
}
} else {
//用户钱包不存在
throw new ServiceSystemException(PerformanceResultEnum.WALLET_CODE_IS_NULL);
}
}
/** /**
* 拉运吨数检测 * 拉运吨数检测
*/ */
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论