| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | import com.stylefeng.guns.modular.system.dao.UserInfoMapper; |
| | | import com.stylefeng.guns.modular.system.dao.WithdrawalMapper; |
| | | import com.stylefeng.guns.modular.system.model.BankCard; |
| | | import com.stylefeng.guns.modular.system.model.Driver; |
| | | import com.stylefeng.guns.modular.system.model.SysWithdrawalPoundage; |
| | | import com.stylefeng.guns.modular.system.model.UserInfo; |
| | | import com.stylefeng.guns.modular.system.model.Withdrawal; |
| | | import com.stylefeng.guns.modular.system.service.IBankCardService; |
| | | import com.stylefeng.guns.modular.system.service.IDriverService; |
| | | import com.stylefeng.guns.modular.system.service.ISysWithdrawalPoundageService; |
| | | import com.stylefeng.guns.modular.system.service.IWithdrawalService; |
| | | import com.stylefeng.guns.modular.system.util.ICBCPayUtil; |
| | | import com.stylefeng.guns.modular.system.util.PayMoneyUtil; |
| | | import com.stylefeng.guns.modular.system.util.LiuZhouBank.ProtocolSignUtil; |
| | | import com.stylefeng.guns.modular.system.util.ResultUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpEntity; |
| | |
| | | private ICBCPayUtil icbcPayUtil; |
| | | |
| | | @Autowired |
| | | private PayMoneyUtil payMoneyUtil; |
| | | |
| | | |
| | | @Autowired |
| | | private RestTemplate internalRestTemplate; |
| | | |
| | | @Autowired |
| | | private ISysWithdrawalPoundageService sysWithdrawalPoundageService; |
| | | private IBankCardService bankCardService; |
| | | |
| | | |
| | | |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public ResultUtil withdrawal(Double money, String bankName, String code, String name, Integer uid, Integer type) throws Exception { |
| | | public ResultUtil withdrawal(Double money, Integer bankCardId, String name, Integer uid, Integer type) throws Exception { |
| | | if(money.compareTo(0D) <= 0){ |
| | | return ResultUtil.error("提现金额必须大于0"); |
| | | } |
| | |
| | | } |
| | | withdrawal.setBalance(driver.getLaveBusinessMoney()); |
| | | } |
| | | withdrawal.setBankName(bankName); |
| | | withdrawal.setCode(code); |
| | | BankCard bankCard = bankCardService.selectById(bankCardId); |
| | | withdrawal.setCode(bankCard.getCode()); |
| | | withdrawal.setFlag(1); |
| | | withdrawal.setInsertTime(new Date()); |
| | | withdrawal.setMoney(money); |
| | |
| | | withdrawal.setUserType(2); |
| | | withdrawal.setType(type); |
| | | withdrawal.setWithdrawalType(1);//线上 |
| | | withdrawal.setRealGetMoney(money*(sysWithdrawalPoundageService.selectOne(null).getPercentage()/100)); |
| | | |
| | | if(type == 1){ |
| | | double v = new BigDecimal(driver.getLaveActivityMoney()).subtract(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue(); |
| | |
| | | } |
| | | |
| | | if(withdrawal.getUserType() == 1){//用户 |
| | | UserInfo userInfo = userInfoMapper.selectById(withdrawal.getUserId()); |
| | | if(state == 2){//审核拒绝 |
| | | UserInfo userInfo = userInfoMapper.selectById(withdrawal.getUserId()); |
| | | userInfo.setBalance(new BigDecimal(userInfo.getBalance()).add(new BigDecimal(withdrawal.getMoney())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | userInfoMapper.updateById(userInfo); |
| | | |
| | | withdrawal.setState(3); |
| | | this.updateById(withdrawal); |
| | | }else{ |
| | | //调用银行转账申请(客户要求提交申请就成功了,剩下的他们自己处理) |
| | | Map<String, String> map = payMoneyUtil.wxPayBank("用户提现", withdrawal.getMoney().toString(), withdrawal.getId().toString(), withdrawal.getCode(), withdrawal.getName(), withdrawal.getBankName()); |
| | | if("SUCCESS".equals(map.get("return_code"))){ |
| | | withdrawal.setSerialNo(map.get("payment_no"));//交易序列号 |
| | | withdrawal.setState(2); |
| | | this.updateById(withdrawal); |
| | | }else{ |
| | | return ResultUtil.error(map.get("err_code_des")); |
| | | String code = withdrawal.getCode(); |
| | | BankCard bankCard = bankCardService.selectOne(new EntityWrapper<BankCard>().eq("code", code).eq("userType", 1).eq("userId", userInfo.getId())); |
| | | if(null == bankCard){ |
| | | return ResultUtil.error("请先绑定该银行卡"); |
| | | } |
| | | |
| | | |
| | | // TimerTask timerTask = new TimerTask() { |
| | | // @Override |
| | | // public void run() { |
| | | // Integer integer = icbcPayUtil.queryTransfer(withdrawal.getSerialNo()); |
| | | // if(integer == 0){//交易成功 |
| | | // withdrawal.setState(2); |
| | | // WithdrawalServiceImpl.this.updateById(withdrawal); |
| | | // |
| | | // Timer timer = timerMap.get(withdrawal.getSerialNo()); |
| | | // timer.cancel(); |
| | | // } |
| | | // if(integer == 2){//交易拒绝/失败 |
| | | // //还原余额 |
| | | // if(withdrawal.getUserType() == 1){//用户 |
| | | // withdrawal.setState(3); |
| | | // WithdrawalServiceImpl.this.updateById(withdrawal); |
| | | // |
| | | // UserInfo userInfo = userInfoMapper.selectById(withdrawal.getUserId()); |
| | | // userInfo.setBalance(new BigDecimal(userInfo.getBalance()).add(new BigDecimal(withdrawal.getMoney())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | // userInfoMapper.updateById(userInfo); |
| | | // |
| | | // Timer timer = timerMap.get(withdrawal.getSerialNo()); |
| | | // timer.cancel(); |
| | | // } |
| | | // |
| | | // } |
| | | // } |
| | | // }; |
| | | // Timer timer = new Timer(); |
| | | // timer.schedule(timerTask, 1000, 10000);//1秒钟后间隔10秒钟查询交易结果 |
| | | // timerMap.put(withdrawal.getSerialNo(), timer); |
| | | // Map<String, String> map = ProtocolSignUtil.queryProtocolSign(bankCard.getSignNum(), bankCard.getCode()); |
| | | // String code2 = map.get("code"); |
| | | // if("01".equals(code2)){ |
| | | // String msg = map.get("msg"); |
| | | // return ResultUtil.error(msg); |
| | | // } |
| | | // String signStatus = map.get("SignStatus"); |
| | | // if("02".equals(signStatus)){ |
| | | // return ResultUtil.error("该银行卡已解约,请先进行签约"); |
| | | // } |
| | | // if("03".equals(signStatus)){ |
| | | // return ResultUtil.error("该银行卡客户黑名单"); |
| | | // } |
| | | // if("04".equals(signStatus)){ |
| | | // return ResultUtil.error("垫资超限冻结"); |
| | | // } |
| | | // Map<String, Object> map1 = ProtocolSignUtil.protocolAgentPay(bankCard.getSignNum(), withdrawal.getMoney(), "用户提现"); |
| | | // String code1 = map1.get("code").toString(); |
| | | // if("01".equals(code1)){ |
| | | // return ResultUtil.error(map1.get("msg").toString()); |
| | | // } |
| | | // withdrawal.setSerialNo(map1.get("TransSeq").toString());//交易序列号 |
| | | // withdrawal.setState(2); |
| | | // this.updateById(withdrawal); |
| | | } |
| | | }else{//司机 |
| | | Driver driver = driverService.selectById(withdrawal.getUserId()); |
| | | if(state == 2){//拒绝 |
| | | Driver driver = driverService.selectById(withdrawal.getUserId()); |
| | | driver.setBalance(new BigDecimal(driver.getBalance()).add(new BigDecimal(withdrawal.getMoney())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | driver.setLaveActivityMoney(new BigDecimal(driver.getLaveActivityMoney()).add(new BigDecimal(withdrawal.getMoney())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | driverService.updateById(driver); |
| | | }else{ |
| | | //调用银行转账申请(客户要求提交申请就成功了,剩下的他们自己处理) |
| | | Map<String, String> map = payMoneyUtil.wxPayBank("司机提现", withdrawal.getMoney().toString(), withdrawal.getId().toString(), withdrawal.getCode(), withdrawal.getName(), withdrawal.getBankName()); |
| | | if("SUCCESS".equals(map.get("return_code"))){ |
| | | withdrawal.setSerialNo(map.get("payment_no"));//交易序列号 |
| | | withdrawal.setState(2); |
| | | this.updateById(withdrawal); |
| | | }else{ |
| | | return ResultUtil.error(map.get("err_code_des")); |
| | | String code = withdrawal.getCode(); |
| | | BankCard bankCard = bankCardService.selectOne(new EntityWrapper<BankCard>().eq("code", code).eq("userType", 2).eq("userId", driver.getId())); |
| | | if(null == bankCard){ |
| | | return ResultUtil.error("请先绑定该银行卡"); |
| | | } |
| | | |
| | | // TimerTask timerTask = new TimerTask() { |
| | | // @Override |
| | | // public void run() { |
| | | // Integer integer = icbcPayUtil.queryTransfer(withdrawal.getSerialNo()); |
| | | // if(integer == 0){//交易成功 |
| | | // withdrawal.setState(2); |
| | | // WithdrawalServiceImpl.this.updateById(withdrawal); |
| | | // |
| | | // Timer timer = timerMap.get(withdrawal.getSerialNo()); |
| | | // timer.cancel(); |
| | | // } |
| | | // if(integer == 2){//交易拒绝/失败 |
| | | // withdrawal.setState(3); |
| | | // WithdrawalServiceImpl.this.updateById(withdrawal); |
| | | // |
| | | // //还原余额 |
| | | // Driver driver = driverService.selectById(withdrawal.getUserId()); |
| | | // driver.setBalance(new BigDecimal(driver.getBalance()).add(new BigDecimal(withdrawal.getMoney())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | // driver.setLaveActivityMoney(new BigDecimal(driver.getLaveActivityMoney()).add(new BigDecimal(withdrawal.getMoney())).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue()); |
| | | // driverService.updateById(driver); |
| | | // |
| | | // Timer timer = timerMap.get(withdrawal.getSerialNo()); |
| | | // timer.cancel(); |
| | | // } |
| | | // } |
| | | // }; |
| | | // Timer timer = new Timer(); |
| | | // timer.schedule(timerTask, 1000, 10000);//1秒钟后间隔10秒钟查询交易结果 |
| | | // timerMap.put(withdrawal.getSerialNo(), timer); |
| | | // Map<String, String> map = ProtocolSignUtil.queryProtocolSign(bankCard.getSignNum(), bankCard.getCode()); |
| | | // String code2 = map.get("code"); |
| | | // if("01".equals(code2)){ |
| | | // String msg = map.get("msg"); |
| | | // return ResultUtil.error(msg); |
| | | // } |
| | | // String signStatus = map.get("SignStatus"); |
| | | // if("02".equals(signStatus)){ |
| | | // return ResultUtil.error("该银行卡已解约,请先进行签约"); |
| | | // } |
| | | // if("03".equals(signStatus)){ |
| | | // return ResultUtil.error("该银行卡客户黑名单"); |
| | | // } |
| | | // if("04".equals(signStatus)){ |
| | | // return ResultUtil.error("垫资超限冻结"); |
| | | // } |
| | | // Map<String, Object> map1 = ProtocolSignUtil.protocolAgentPay(bankCard.getSignNum(), withdrawal.getMoney(), "司机提现"); |
| | | // String code1 = map1.get("code").toString(); |
| | | // if("01".equals(code1)){ |
| | | // return ResultUtil.error(map1.get("msg").toString()); |
| | | // } |
| | | // withdrawal.setSerialNo(map1.get("TransSeq").toString());//交易序列号 |
| | | // withdrawal.setState(2); |
| | | // this.updateById(withdrawal); |
| | | } |
| | | } |
| | | return ResultUtil.success(); |