| | |
| | | import com.doumee.dao.business.model.ShopInfo; |
| | | import com.doumee.dao.business.model.WithdrawalOrders; |
| | | import com.doumee.dao.dto.WithdrawalApproveDTO; |
| | | import com.doumee.config.alipay.AlipayFundTransUniTransfer; |
| | | import com.doumee.dao.dto.AlipayTransferDTO; |
| | | import com.doumee.dao.dto.WithdrawalDTO; |
| | | import com.doumee.dao.system.SystemUserMapper; |
| | | import com.doumee.dao.system.model.SystemUser; |
| | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void approve(WithdrawalApproveDTO dto) { |
| | | if (dto == null || dto.getId() == null || dto.getStatus() == null) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "审批参数不完整"); |
| | |
| | | Integer currentUserId = getCurrentUserId(); |
| | | Date now = new Date(); |
| | | |
| | | // 审批通过时,调用支付宝打款 |
| | | Integer finalStatus = dto.getStatus(); |
| | | String doneInfo = null; |
| | | if (Constants.ONE.equals(dto.getStatus())) { |
| | | String aliAccount = order.getAliAccount(); |
| | | String aliName = null; |
| | | |
| | | // 从司机或门店获取支付宝账户和实名姓名 |
| | | if (StringUtils.isBlank(aliAccount)) { |
| | | if (Constants.equalsInteger(order.getMemberType(), Constants.ONE)) { |
| | | DriverInfo driver = driverInfoMapper.selectOne(new QueryWrapper<DriverInfo>().lambda() |
| | | .eq(DriverInfo::getMemberId, order.getMemberId()) |
| | | .eq(DriverInfo::getDeleted, Constants.ZERO) |
| | | .last("limit 1")); |
| | | if (driver != null) { |
| | | aliAccount = driver.getAliAccount(); |
| | | aliName = driver.getAliName(); |
| | | } |
| | | } else if (Constants.equalsInteger(order.getMemberType(), Constants.TWO)) { |
| | | ShopInfo shop = shopInfoMapper.selectOne(new QueryWrapper<ShopInfo>().lambda() |
| | | .eq(ShopInfo::getRegionMemberId, order.getMemberId()) |
| | | .eq(ShopInfo::getDeleted, Constants.ZERO) |
| | | .last("limit 1")); |
| | | if (shop != null) { |
| | | aliAccount = shop.getAliAccount(); |
| | | aliName = shop.getAliName(); |
| | | } |
| | | } |
| | | } else { |
| | | // 从 WithdrawalOrders 的 aliAccount 查对应姓名 |
| | | if (Constants.equalsInteger(order.getMemberType(), Constants.ONE)) { |
| | | DriverInfo driver = driverInfoMapper.selectOne(new QueryWrapper<DriverInfo>().lambda() |
| | | .eq(DriverInfo::getMemberId, order.getMemberId()) |
| | | .eq(DriverInfo::getDeleted, Constants.ZERO) |
| | | .last("limit 1")); |
| | | if (driver != null) { |
| | | aliName = driver.getAliName(); |
| | | } |
| | | } else if (Constants.equalsInteger(order.getMemberType(), Constants.TWO)) { |
| | | ShopInfo shop = shopInfoMapper.selectOne(new QueryWrapper<ShopInfo>().lambda() |
| | | .eq(ShopInfo::getRegionMemberId, order.getMemberId()) |
| | | .eq(ShopInfo::getDeleted, Constants.ZERO) |
| | | .last("limit 1")); |
| | | if (shop != null) { |
| | | aliName = shop.getAliName(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (StringUtils.isBlank(aliAccount)) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "支付宝提现账户未配置,无法打款"); |
| | | } |
| | | |
| | | // 金额转换:分 → 元 |
| | | Long amountFen = order.getAmount() != null ? order.getAmount() : 0L; |
| | | BigDecimal transAmount = new BigDecimal(amountFen).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP); |
| | | |
| | | AlipayTransferDTO transferDTO = new AlipayTransferDTO(); |
| | | transferDTO.setOutBizNo(order.getOutBillNo()); |
| | | transferDTO.setTransAmount(transAmount); |
| | | transferDTO.setPayeeAccount(aliAccount); |
| | | transferDTO.setPayeeName(aliName); |
| | | transferDTO.setRemark("提现打款"); |
| | | |
| | | String alipayOrderId; |
| | | try { |
| | | alipayOrderId = AlipayFundTransUniTransfer.transfer(transferDTO); |
| | | } catch (BusinessException e) { |
| | | throw e; |
| | | } catch (Exception e) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "支付宝打款失败:" + e.getMessage()); |
| | | } |
| | | doneInfo = "支付宝转账单号:" + alipayOrderId; |
| | | } |
| | | |
| | | WithdrawalOrders update = new WithdrawalOrders(); |
| | | update.setId(dto.getId()); |
| | | update.setStatus(dto.getStatus()); |
| | | update.setStatus(finalStatus); |
| | | update.setUserId(currentUserId); |
| | | update.setApproveTime(now); |
| | | update.setApproveRemark(dto.getApproveRemark()); |
| | | update.setUpdateTime(now); |
| | | if (Constants.ONE.equals(finalStatus)) { |
| | | update.setDoneTime(now); |
| | | update.setDoneInfo(doneInfo); |
| | | } else if (doneInfo != null) { |
| | | update.setDoneTime(now); |
| | | update.setDoneInfo(doneInfo); |
| | | } |
| | | withdrawalOrdersMapper.updateById(update); |
| | | |
| | | // 更新关联的提现 Revenue 记录状态 |
| | |
| | | .eq(Revenue::getDeleted, Constants.ZERO) |
| | | .last("limit 1")); |
| | | if (withdrawalRevenue != null) { |
| | | Integer revenueStatus = Constants.ONE.equals(dto.getStatus()) ? Constants.ZERO : Constants.ONE; // 通过=0成功, 驳回=1失败 |
| | | Integer revenueStatus = Constants.ONE.equals(finalStatus) ? Constants.ZERO : Constants.ONE; // 通过=0成功, 驳回=1失败 |
| | | revenueMapper.update(new UpdateWrapper<Revenue>().lambda() |
| | | .set(Revenue::getStatus, revenueStatus) |
| | | .set(Revenue::getUpdateTime, now) |
| | | .eq(Revenue::getId, withdrawalRevenue.getId())); |
| | | } |
| | | |
| | | // 驳回时退回余额 |
| | | if (Constants.TWO.equals(dto.getStatus())) { |
| | | // 驳回或打款失败时退回余额 |
| | | if (Constants.TWO.equals(finalStatus)) { |
| | | Long amountFen = order.getAmount() != null ? order.getAmount() : 0L; |
| | | if (amountFen > 0 && order.getMemberId() != null) { |
| | | if (Constants.equalsInteger(order.getMemberType(), Constants.ONE)) { |