| | |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.stylefeng.guns.core.util.DateUtil; |
| | | import com.stylefeng.guns.core.util.RequestSeqUtil; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | import com.stylefeng.guns.modular.account.model.TBankNext; |
| | | import com.stylefeng.guns.modular.account.model.TEnterpriseWithdrawal; |
| | | import com.stylefeng.guns.modular.account.req.UserWithdrawalReq; |
| | | import com.stylefeng.guns.modular.account.service.*; |
| | | import com.stylefeng.guns.modular.account.util.Base64Util; |
| | |
| | | import com.stylefeng.guns.modular.cloudPayment.req.BalanceAcctReq; |
| | | import com.stylefeng.guns.modular.cloudPayment.req.UserBankAccountReq; |
| | | import com.stylefeng.guns.modular.huifu.biz.DouGongBasicDataBiz; |
| | | import com.stylefeng.guns.modular.huifu.biz.DouGongWithdrawBiz; |
| | | import com.stylefeng.guns.modular.huifu.biz.FenZhangUtil; |
| | | import com.stylefeng.guns.modular.system.model.*; |
| | | import com.stylefeng.guns.modular.system.service.IBankCardService; |
| | | import com.stylefeng.guns.modular.system.service.ICompanyService; |
| | | import com.stylefeng.guns.modular.system.service.IDriverService; |
| | | import com.stylefeng.guns.modular.system.service.IRegionService; |
| | | import com.stylefeng.guns.modular.system.service.ISysWithdrawalPoundageService; |
| | | import com.stylefeng.guns.modular.system.service.IWithdrawalService; |
| | | import com.stylefeng.guns.modular.system.service.impl.WithdrawalServiceImpl; |
| | | import com.stylefeng.guns.modular.system.util.ResultUtil; |
| | | import com.unionpay.upyzt.exception.InvalidRequestException; |
| | | import com.unionpay.upyzt.exception.UpyztException; |
| | |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import net.bytebuddy.asm.Advice; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.BeanUtils; |
| | |
| | | private final ITBankNextService bankNextService; |
| | | private final DouGongBasicDataBiz douGongBasicDataBiz; |
| | | private final IRegionService regionService; |
| | | private final ITEnterpriseWithdrawalService enterpriseWithdrawalService; |
| | | private final DouGongWithdrawBiz douGongWithdrawBiz; |
| | | private final ISysWithdrawalPoundageService sysWithdrawalPoundageService; |
| | | private final IWithdrawalService withdrawalService; |
| | | |
| | | @Autowired |
| | | public UserWithdrawalController(ElectronicLedgerService electronicLedgerService, |
| | | UserWithdrawalService userWithdrawalService, UserBankAccountService userBankAccountService, |
| | | IBankCardService bankCardService, IDriverService driverService, ICompanyService companyService, |
| | | ITBankNextService bankNextService, DouGongBasicDataBiz douGongBasicDataBiz,IRegionService regionService) { |
| | | ITBankNextService bankNextService, DouGongBasicDataBiz douGongBasicDataBiz,IRegionService regionService, |
| | | ITEnterpriseWithdrawalService enterpriseWithdrawalService,DouGongWithdrawBiz douGongWithdrawBiz, |
| | | ISysWithdrawalPoundageService sysWithdrawalPoundageService,IWithdrawalService withdrawalService) { |
| | | this.electronicLedgerService = electronicLedgerService; |
| | | this.userWithdrawalService = userWithdrawalService; |
| | | this.userBankAccountService = userBankAccountService; |
| | |
| | | this.bankNextService = bankNextService; |
| | | this.douGongBasicDataBiz = douGongBasicDataBiz; |
| | | this.regionService = regionService; |
| | | this.enterpriseWithdrawalService = enterpriseWithdrawalService; |
| | | this.douGongWithdrawBiz = douGongWithdrawBiz; |
| | | this.sysWithdrawalPoundageService = sysWithdrawalPoundageService; |
| | | this.withdrawalService = withdrawalService; |
| | | } |
| | | |
| | | |
| | |
| | | // 查询当前操作电子用户 |
| | | // 司机进件信息 |
| | | UserWithdrawal userWithdrawal = userWithdrawalService.selectOne(new EntityWrapper<UserWithdrawal>() |
| | | .eq("phone",driver.getPhone()) |
| | | .eq("applicationStatus","succeeded") |
| | | .eq("phone",driver.getPhone()).eq("type", 1) |
| | | //.eq("applicationStatus","succeeded") |
| | | .last("LIMIT 1")); |
| | | |
| | | System.out.println("司机电子账簿信息====:"+userWithdrawal); |
| | |
| | | // 查询平台账户 |
| | | Company company = companyService.selectOne(new EntityWrapper<Company>() |
| | | .eq("type", 1)); |
| | | TEnterpriseWithdrawal tEnterpriseWithdrawal = enterpriseWithdrawalService.selectOne(new EntityWrapper<TEnterpriseWithdrawal>().eq("companyId", company.getId()) |
| | | .eq("type", 1).last("LIMIT 1")); |
| | | if (Objects.isNull(tEnterpriseWithdrawal)) { |
| | | return ResultUtil.error("分公司未配置账户信息"); |
| | | } |
| | | // 查询平台开户信息 |
| | | ElectronicLedger electronicLedger = electronicLedgerService.selectOne(new EntityWrapper<ElectronicLedger>() |
| | | .eq("userId", company.getId()) |
| | | .eq("userType", 3) |
| | | .last("LIMIT 1")); |
| | | //ElectronicLedger electronicLedger = electronicLedgerService.selectOne(new EntityWrapper<ElectronicLedger>() |
| | | // .eq("userId", company.getId()) |
| | | // .eq("userType", 3) |
| | | // .last("LIMIT 1")); |
| | | try { |
| | | // 进行平台分账到司机电子账簿 |
| | | System.out.println("平台分账到司机电子账簿========="); |
| | | AllocationReq allocationReq = userWithdrawalService.createAllocationReq(userWithdrawal.getBalanceAcctId(), electronicLedger.getBalanceAcctId(), amount,userWithdrawal.getTransactionAuthorizationCode()); |
| | | AllocationResp allocationResp = AllocationExample.create(allocationReq); |
| | | System.out.println("平台分账到司机电子账簿完成=========:{}"+allocationResp); |
| | | System.out.println("平台分a账到司机电子账簿========="); |
| | | String fzReqSeqId = RequestSeqUtil.generate("FZ"); |
| | | Map<String, Object> fenzhng = FenZhangUtil.fenzhang(fzReqSeqId, DateUtil.format(new Date(), "yyyyMMdd"), amount.toString(), userWithdrawal.getHuifuId()); |
| | | if (!"00000000".equals(fenzhng.get("resp_code"))){ |
| | | System.err.println("平台分a账到司机电子账簿" + fenzhng); |
| | | return ResultUtil.error("提现失败:"+fenzhng.get("resp_desc")); |
| | | } |
| | | Withdrawal withdrawal = new Withdrawal(); |
| | | withdrawal.setBankName(userWithdrawal.getBankName()); |
| | | withdrawal.setCode(userWithdrawal.getBankCode()); |
| | | withdrawal.setFlag(1); |
| | | withdrawal.setInsertTime(new Date()); |
| | | withdrawal.setMoney(amount.doubleValue()); |
| | | withdrawal.setName(userWithdrawal.getOpenAccountName()); |
| | | withdrawal.setState(1); |
| | | withdrawal.setUserId(userWithdrawal.getUserId()); |
| | | withdrawal.setUserType(2); |
| | | withdrawal.setType(2); |
| | | withdrawal.setWithdrawalType(1);//线上 |
| | | withdrawal.setRealGetMoney(amount - (amount*(sysWithdrawalPoundageService.selectOne(null).getPercentage()/100))); |
| | | withdrawal.setFzReqSeqId(fzReqSeqId); |
| | | withdrawalService.insert(withdrawal); |
| | | if ("00000000".equals(fenzhng.get("resp_code")) && "S".equals(fenzhng.get("trans_stat"))){ |
| | | String txReqSeqId = RequestSeqUtil.generate("TX"); |
| | | withdrawal.setReqSeqId(txReqSeqId); |
| | | Map<String, Object> tx = douGongWithdrawBiz.encashment(txReqSeqId, BigDecimal.valueOf(amount), userWithdrawal.getHuifuId(), userWithdrawal.getTokenNo(), 2); |
| | | withdrawal.setHfSeqId(tx.get("huifu_id").toString()); |
| | | if (!"00000000".equals(tx.get("resp_code"))){ |
| | | System.err.println("平台分a账到司机电子账簿" + tx); |
| | | return ResultUtil.error("提现失败:"+tx.get("resp_desc")); |
| | | } |
| | | if ("00000000".equals(tx.get("resp_code")) && "S".equals(tx.get("trans_stat"))){ |
| | | withdrawal.setState(2); |
| | | } |
| | | withdrawalService.updateById(withdrawal); |
| | | } |
| | | //AllocationReq allocationReq = userWithdrawalService.createAllocationReq(userWithdrawal.getBalanceAcctId(), electronicLedger.getBalanceAcctId(), amount,userWithdrawal.getTransactionAuthorizationCode()); |
| | | //AllocationResp allocationResp = AllocationExample.create(allocationReq); |
| | | //System.out.println("平台分账到司机电子账簿完成=========:{}"+allocationResp); |
| | | |
| | | // 用户电子账簿进行提现操作 |
| | | WithdrawalResp withdrawalResp = WithdrawalExample.create(userWithdrawalService.createWithdrawalReq(userWithdrawal.getBalanceAcctId(), amount, userWithdrawal.getTransactionAuthorizationCode(), bankAcctNo)); |
| | | System.out.println("司机电子账簿提现完成=========:{}"+withdrawalResp); |
| | | //WithdrawalResp withdrawalResp = WithdrawalExample.create(userWithdrawalService.createWithdrawalReq(userWithdrawal.getBalanceAcctId(), amount, userWithdrawal.getTransactionAuthorizationCode(), bankAcctNo)); |
| | | //System.out.println("司机电子账簿提现完成=========:{}"+withdrawalResp); |
| | | return ResultUtil.success(); |
| | | }catch (Exception e){ |
| | | System.out.println("司机提现失败=========:{}"+e.getMessage()); |
| | |
| | | // .eq("userId", driverId) |
| | | // .eq("userType", 2)); |
| | | userWithdrawal = userWithdrawalService.selectOne(new EntityWrapper<UserWithdrawal>() |
| | | .eq("userId", driver.getId()) |
| | | .eq("userType", 2) |
| | | .eq("applicationStatus","succeeded") |
| | | .eq("phone", driver.getPhone()) |
| | | .eq("type", 1) |
| | | .last("LIMIT 1")); |
| | | if(Objects.isNull(userWithdrawal)){ |
| | | return ResultUtil.error("该司机开户信息为空"); |
| | | } |
| | | BalanceAcctReq balanceAcctReq = new BalanceAcctReq(); |
| | | balanceAcctReq.setCusId(userWithdrawal.getCusId()); |
| | | balanceAcctListResp = BalanceAcctExample.retrieveByUserId(balanceAcctReq); |
| | | System.err.println(balanceAcctListResp); |
| | | BigDecimal balance = douGongBasicDataBiz.balanceQuery(userWithdrawal.getHuifuId()); |
| | | //System.err.println(balance); |
| | | return ResultUtil.success(balance); |
| | | //BalanceAcctReq balanceAcctReq = new BalanceAcctReq(); |
| | | //balanceAcctReq.setCusId(userWithdrawal.getCusId()); |
| | | //balanceAcctListResp = BalanceAcctExample.retrieveByUserId(balanceAcctReq); |
| | | } catch (Exception e) { |
| | | log.error("电子账簿可提现余额查询失败:{}",e.getMessage()); |
| | | e.printStackTrace(); |
| | | } |
| | | if(Objects.isNull(balanceAcctListResp)){ |
| | | /* if(Objects.isNull(balanceAcctListResp)){ |
| | | log.error("电子账簿可提现余额查询失败"); |
| | | return ResultUtil.error("电子账簿可提现余额查询失败"); |
| | | } |
| | |
| | | if(userWithdrawal.getBalanceAcctId().equals(balanceAcct.getBalanceAcctId())){ |
| | | return ResultUtil.success(new BigDecimal(balanceAcct.getSettledAmount()).divide(new BigDecimal(100))); |
| | | } |
| | | } |
| | | }*/ |
| | | return ResultUtil.success(BigDecimal.ZERO); |
| | | } |
| | | |