| | |
| | | package com.stylefeng.guns.modular.account.controller; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | import com.stylefeng.guns.modular.account.model.TBankNext; |
| | | 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.example.*; |
| | | import com.stylefeng.guns.modular.cloudPayment.req.AllocationReq; |
| | | import com.stylefeng.guns.modular.cloudPayment.req.BalanceAcctReq; |
| | | import com.stylefeng.guns.modular.cloudPayment.req.UserBankAccountReq; |
| | | import com.stylefeng.guns.modular.system.model.*; |
| | | import com.stylefeng.guns.modular.account.service.ElectronicLedgerService; |
| | | import com.stylefeng.guns.modular.account.service.ITBankNextService; |
| | | import com.stylefeng.guns.modular.account.service.UserBankAccountService; |
| | | import com.stylefeng.guns.modular.account.service.UserWithdrawalService; |
| | | import com.stylefeng.guns.modular.system.model.Company; |
| | | import com.stylefeng.guns.modular.system.model.Driver; |
| | | import com.stylefeng.guns.modular.system.model.ElectronicLedger; |
| | | import com.stylefeng.guns.modular.system.model.UserWithdrawal; |
| | | 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.util.ResultUtil; |
| | | import com.unionpay.upyzt.exception.InvalidRequestException; |
| | | import com.unionpay.upyzt.exception.UpyztException; |
| | | import com.unionpay.upyzt.param.FailureMsgParam; |
| | | import com.unionpay.upyzt.resp.*; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Isolation; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | |
| | | this.bankNextService = bankNextService; |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @RequestMapping(value = "/addElectronicLedger", method = RequestMethod.POST) |
| | | @ApiOperation(value = "司机进件(提现账户设置)", tags = {"司机端-司机进件(提现账户设置)"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | @Transactional(isolation = Isolation.READ_UNCOMMITTED,rollbackFor = Exception.class,propagation = Propagation.REQUIRED) |
| | | public ResultUtil addElectronicLedger(UserWithdrawalReq userWithdrawalReq, HttpServletRequest request){ |
| | | System.out.println(userWithdrawalReq); |
| | | if(StringUtils.hasLength(userWithdrawalReq.getBankName())){ |
| | | userWithdrawalReq.setBankName(userWithdrawalReq.getBankName().replace("& #40;","(")); |
| | | userWithdrawalReq.setBankName(userWithdrawalReq.getBankName().replace("& #41;",")")); |
| | | } |
| | | |
| | | userWithdrawalReq.setCopy1(userWithdrawalReq.getCopy1().replaceAll(" ","+")); |
| | | userWithdrawalReq.setCopy2(userWithdrawalReq.getCopy2().replaceAll(" ","+")); |
| | | // 用户进件 |
| | | // 获取当前用户id |
| | | Integer driverId = null; |
| | | try { |
| | | driverId = driverService.getUserIdFormRedis(request); |
| | | } catch (Exception e) { |
| | | return ResultUtil.error(e.getMessage()); |
| | | } |
| | | if(null == driverId){ |
| | | return ResultUtil.tokenErr(); |
| | | } |
| | | // 查询司机 |
| | | // Driver driver = driverService.selectById(id); |
| | | |
| | | userWithdrawalReq.setOutRequestNo(ToolUtil.getRandomString(32)); |
| | | UserWithdrawal userWithdrawal = new UserWithdrawal(); |
| | | BeanUtils.copyProperties(userWithdrawalReq,userWithdrawal); |
| | | |
| | | String password = userWithdrawal.getTransactionAuthorizationCode(); |
| | | userWithdrawal.setOutRequestNo(ToolUtil.getRandomString(32)); |
| | | try { |
| | | // 司机进件 |
| | | CusApplicationResp cusApplicationResp = CusApplicationExample.create(userWithdrawalReq); |
| | | System.out.println(cusApplicationResp); |
| | | // 交易授权码加密,并保存司机进件信息 |
| | | userWithdrawal.setTransactionAuthorizationCode(Base64Util.encode(userWithdrawal.getTransactionAuthorizationCode())); |
| | | // userWithdrawal.setUserId(userWithdrawal.getUserId()); |
| | | userWithdrawal.setUserId(driverId); |
| | | userWithdrawal.setUserType(2); |
| | | userWithdrawal.setImgUrl(userWithdrawalReq.getIdCardFrontPicture()); |
| | | userWithdrawal.setImgUrlOne(userWithdrawalReq.getIdCardReversePicture()); |
| | | userWithdrawal.setIdCardFrontPicture(userWithdrawalReq.getCopy1()); |
| | | userWithdrawal.setIdCardReversePicture(userWithdrawalReq.getCopy2()); |
| | | userWithdrawalService.insert(userWithdrawal); |
| | | |
| | | // 通过司机进件信息封装银行卡信息进行数据库存储 |
| | | BankCard bankCard = userBankAccountService.userWithdrawalToBankCard(userWithdrawal); |
| | | bankCardService.insert(bankCard); |
| | | // 添加用户银行卡 |
| | | UserBankAccount userBankAccount = userBankAccountService.userWithdrawalToUserBankAccount(userWithdrawal); |
| | | userBankAccountService.insert(userBankAccount); |
| | | |
| | | // 判断是否开户成功 |
| | | if("succeeded".equals(cusApplicationResp.getApplicationStatus())){ |
| | | |
| | | // 开户将司机进件返回的信息进行保存 |
| | | userWithdrawalService.cusApplicationRespToUserWithdrawal(userWithdrawal,cusApplicationResp); |
| | | userWithdrawalService.updateById(userWithdrawal); |
| | | System.out.println("开户将司机进件返回的信息"); |
| | | // 开户成功,开通电子账户,绑定账户 |
| | | // 开通电子账簿 |
| | | // BalanceAcctReq balanceAcctReq = electronicLedgerService.createBalanceAcctReq(userWithdrawal.getCusId(),password); |
| | | // BalanceAcctStoreResp balanceAcctStoreResp = BalanceAcctExample.create(balanceAcctReq); |
| | | |
| | | // 开通电子账簿成功,封装实体 |
| | | ElectronicLedger electronicLedger = electronicLedgerService.createElectronicLedger(cusApplicationResp,userWithdrawal,password); |
| | | System.out.println("开通电子账簿成功,封装实体11111"); |
| | | electronicLedgerService.insert(electronicLedger); |
| | | System.out.println("开通电子账簿成功,封装实体22222"); |
| | | |
| | | // 绑定银行卡 |
| | | // UserBankAccountReq userBankAccountReq = electronicLedgerService.createUserBankAccountReq(bankCard,userWithdrawal.getCusId(),userWithdrawal.getCode()); |
| | | // SettleAcctResp settleAcctResp = SettleAcctExample.create(userBankAccountReq); |
| | | |
| | | // 保存绑定银行卡返回信息 |
| | | // bankCard.setVerifyStatus(settleAcctResp.getVerifyStatus()); |
| | | // bankCard.setSettleAcctId(settleAcctResp.getSettleAcctId()); |
| | | // bankCard.setAcctValidationFailureMsg(settleAcctResp.getAcctValidationFailureMsg()); |
| | | // bankCard.setAcctValidationFinishedAt(settleAcctResp.getAcctValidationFinishedAt()); |
| | | // bankCardService.updateById(bankCard); |
| | | return ResultUtil.success(); |
| | | } |
| | | if("failed".equals(cusApplicationResp.getApplicationStatus())){ |
| | | List<FailureMsgParam> failureMsgs = cusApplicationResp.getFailureMsgs(); |
| | | if(failureMsgs != null && failureMsgs.size()>0){ |
| | | return ResultUtil.error(failureMsgs.get(0).getReason()); |
| | | } |
| | | } |
| | | return ResultUtil.success(); |
| | | }catch (UpyztException e){ |
| | | e.printStackTrace(); |
| | | if(e.getCode().equals("100101")){ |
| | | return ResultUtil.error(e.getIssue()); |
| | | } |
| | | return ResultUtil.error(e.getMessage()); |
| | | } catch (Exception e){ |
| | | return ResultUtil.error(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @ResponseBody |
| | | @RequestMapping(value = "/updateElectronicLedgerInfo", method = RequestMethod.POST) |
| | | @ApiOperation(value = "司机修改进件信息", tags = {"司机端-司机修改进件信息"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | @Transactional(isolation = Isolation.READ_UNCOMMITTED,rollbackFor = Exception.class,propagation = Propagation.REQUIRED) |
| | | public ResultUtil updateElectronicLedgerInfo(String idCardFrontPicture, |
| | | String idCardReversePicture, |
| | | String certificateCode, |
| | | String certificateName, |
| | | String certificateExpireTime, |
| | | String openAccountName, |
| | | String bankCardCode, |
| | | String bankCode, |
| | | String bankBranchCode, |
| | | String phone, |
| | | String code, |
| | | String copy1, |
| | | String copy2, |
| | | HttpServletRequest request){ |
| | | try { |
| | | Integer driverId = driverService.getUserIdFormRedis(request); |
| | | if(null == driverId){ |
| | | return ResultUtil.tokenErr(); |
| | | } |
| | | Driver driver = driverService.selectById(driverId); |
| | | // TODO 司机进件信息 |
| | | UserWithdrawal userWithdrawal1 = userWithdrawalService.selectOne(new EntityWrapper<UserWithdrawal>() |
| | | .eq("phone",driver.getPhone()) |
| | | .last("LIMIT 1")); |
| | | if(Objects.isNull(userWithdrawal1)){ |
| | | return ResultUtil.error("请先进行个人用户进件信息填写"); |
| | | } |
| | | TBankNext bankNext = bankNextService.selectOne(new EntityWrapper<TBankNext>() |
| | | .eq("bankCode", bankBranchCode) |
| | | .last("LIMIT 1")); |
| | | UserWithdrawal userWithdrawal = new UserWithdrawal(); |
| | | if(Objects.nonNull(bankNext)){ |
| | | userWithdrawal1.setBankName(bankNext.getBankName()); |
| | | } |
| | | |
| | | BeanUtils.copyProperties(userWithdrawal1,userWithdrawal); |
| | | |
| | | userWithdrawal.setIdCardFrontPicture(copy1); |
| | | userWithdrawal.setIdCardReversePicture(copy2); |
| | | userWithdrawal.setImgUrl(idCardFrontPicture); |
| | | userWithdrawal.setImgUrlOne(idCardReversePicture); |
| | | userWithdrawal.setCertificateCode(certificateCode); |
| | | userWithdrawal.setCertificateName(certificateName); |
| | | userWithdrawal.setCertificateExpireTime(certificateExpireTime); |
| | | userWithdrawal.setOpenAccountName(openAccountName); |
| | | userWithdrawal.setBankCardCode(bankCardCode); |
| | | userWithdrawal.setCusId(userWithdrawal1.getCusId()); |
| | | userWithdrawal.setPhone(phone); |
| | | userWithdrawal.setBankCode(bankCode); |
| | | userWithdrawal.setBankBranchCode(bankBranchCode); |
| | | userWithdrawal.setCode(code); |
| | | System.out.println(userWithdrawal); |
| | | CusApplicationResp renew = CusApplicationExample.renew(userWithdrawal); |
| | | System.out.println("修改个人用户进件信息返回:{}"+renew); |
| | | if("succeeded".equals(renew.getApplicationStatus())){ |
| | | System.out.println("修改成功"); |
| | | userWithdrawal1.setIdCardFrontPicture(copy1); |
| | | userWithdrawal1.setIdCardReversePicture(copy2); |
| | | userWithdrawal1.setImgUrl(idCardFrontPicture); |
| | | userWithdrawal1.setImgUrlOne(idCardReversePicture); |
| | | userWithdrawal1.setCertificateCode(certificateCode); |
| | | userWithdrawal1.setCertificateName(certificateName); |
| | | userWithdrawal1.setCertificateExpireTime(certificateExpireTime); |
| | | userWithdrawal1.setOpenAccountName(openAccountName); |
| | | userWithdrawal1.setBankCardCode(bankCardCode); |
| | | userWithdrawal1.setBankCode(bankCode); |
| | | userWithdrawal1.setBankBranchCode(bankBranchCode); |
| | | userWithdrawal1.setPhone(phone); |
| | | userWithdrawalService.updateById(userWithdrawal1); |
| | | // 修改成功 查询该银行卡是否存在 如果不存在则添加 |
| | | System.out.println("修改成功"); |
| | | int count = bankCardService.selectCount(new EntityWrapper<BankCard>() |
| | | .eq("code", bankCardCode) |
| | | .eq("status",true)); |
| | | System.out.println("查询该银行卡是否存在 如果不存在则添加"); |
| | | if(count<1){ |
| | | System.out.println("该银行卡不存在则添加"); |
| | | BankCard bankCard = userBankAccountService.userWithdrawalToBankCard(userWithdrawal); |
| | | bankCardService.insert(bankCard); |
| | | System.out.println("该银行卡添加成功"); |
| | | } |
| | | System.out.println("查询该银行卡账户是否存在"); |
| | | int count1 = userBankAccountService.selectCount(new EntityWrapper<UserBankAccount>() |
| | | .eq("bankCardCode", bankCardCode) |
| | | .eq("userType", 1) |
| | | .eq("status",true)); |
| | | if(count1<1){ |
| | | // 添加用户银行卡 |
| | | System.out.println("该银行卡账户不存在则添加"); |
| | | UserBankAccount userBankAccount = userBankAccountService.userWithdrawalToUserBankAccount(userWithdrawal); |
| | | userBankAccountService.insert(userBankAccount); |
| | | System.out.println("该银行卡账户添加成功"); |
| | | } |
| | | } |
| | | if("failed".equals(renew.getApplicationStatus())){ |
| | | List<FailureMsgParam> failureMsgs = renew.getFailureMsgs(); |
| | | if(failureMsgs != null && failureMsgs.size()>0){ |
| | | return ResultUtil.error(failureMsgs.get(0).getReason()); |
| | | } |
| | | } |
| | | return ResultUtil.success(); |
| | | }catch (UpyztException e){ |
| | | e.printStackTrace(); |
| | | if(e.getCode().equals("100101")){ |
| | | return ResultUtil.error(e.getIssue()); |
| | | } |
| | | return ResultUtil.error(e.getMessage()); |
| | | } catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return ResultUtil.error(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | |
| | | .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); |
| | | |
| | | // 用户电子账簿进行提现操作 |
| | | 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()); |
| | | e.printStackTrace(); |
| | | return ResultUtil.error(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @ResponseBody |
| | |
| | | @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public ResultUtil querySettledAmount(HttpServletRequest request){ |
| | | BalanceAcctListResp balanceAcctListResp = null; |
| | | // ElectronicLedger electronicLedger = null; |
| | | UserWithdrawal userWithdrawal = null; |
| | | try { |
| | | Integer driverId = driverService.getUserIdFormRedis(request); |
| | | Driver driver = driverService.selectById(driverId); |
| | | // 通过司机id查询开户信息, |
| | | // 司机进件信息 |
| | | // electronicLedger = electronicLedgerService.selectOne(new EntityWrapper<ElectronicLedger>() |
| | | // .eq("userId", driverId) |
| | | // .eq("userType", 2)); |
| | | userWithdrawal = userWithdrawalService.selectOne(new EntityWrapper<UserWithdrawal>() |
| | | .eq("phone", driver.getPhone()) |
| | | .eq("userType", 2) |
| | | .eq("applicationStatus","succeeded") |
| | | .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); |
| | | } catch (Exception e) { |
| | | log.error("电子账簿可提现余额查询失败:{}",e.getMessage()); |
| | | e.printStackTrace(); |
| | | } |
| | | if(Objects.isNull(balanceAcctListResp)){ |
| | | log.error("电子账簿可提现余额查询失败"); |
| | | return ResultUtil.error("电子账簿可提现余额查询失败"); |
| | | } |
| | | log.info("电子账簿可提现余额查询完成=========:{}",balanceAcctListResp); |
| | | List<BalanceAcctItem> balanceAccts = balanceAcctListResp.getBalanceAccts(); |
| | | if(CollectionUtils.isEmpty(balanceAccts)){ |
| | | log.error("电子账簿可提现余额查询失败"); |
| | | return ResultUtil.error("电子账簿可提现余额查询失败"); |
| | | } |
| | | for (BalanceAcctItem balanceAcct : balanceAccts) { |
| | | if(userWithdrawal.getBalanceAcctId().equals(balanceAcct.getBalanceAcctId())){ |
| | | return ResultUtil.success(new BigDecimal(balanceAcct.getSettledAmount()).divide(new BigDecimal(100))); |
| | | } |
| | | } |
| | | |
| | | return ResultUtil.success(BigDecimal.ZERO); |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @RequestMapping(value = "/uploadImg", method = RequestMethod.POST) |
| | | @ApiOperation(value = "进件上传图片", tags = {"司机端-进件上传图片"}, notes = "") |
| | | @ApiImplicitParams({ |
| | | }) |
| | | @Transactional(isolation = Isolation.READ_UNCOMMITTED,rollbackFor = Exception.class,propagation = Propagation.REQUIRED) |
| | | public ResultUtil uploadImg(MultipartFile multipartFile, HttpServletRequest request){ |
| | | try { |
| | | MediaResp mediaResp = MediaExample.uploadImage(multipartFile); |
| | | System.out.println(mediaResp); |
| | | String mediaId = mediaResp.getMediaId(); |
| | | return ResultUtil.success(mediaId); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return ResultUtil.error(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | } |