| | |
| | | package com.stylefeng.guns.modular.system.controller.general; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.stylefeng.guns.core.base.controller.BaseController; |
| | | import com.stylefeng.guns.core.base.tips.ErrorTip; |
| | | import com.stylefeng.guns.core.shiro.ShiroKit; |
| | | import com.stylefeng.guns.core.util.RequestSeqUtil; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | import com.stylefeng.guns.modular.cloudPayment.example.BalanceAcctExample; |
| | | import com.stylefeng.guns.modular.cloudPayment.example.WithdrawalExample; |
| | | import com.stylefeng.guns.modular.cloudPayment.req.BalanceAcctReq; |
| | | import com.stylefeng.guns.modular.cloudPayment.req.WithdrawalReq; |
| | | import com.stylefeng.guns.modular.huifu.biz.DouGongBasicDataBiz; |
| | | import com.stylefeng.guns.modular.huifu.biz.DouGongWithdrawBiz; |
| | | import com.stylefeng.guns.modular.system.controller.util.Base64Util; |
| | | import com.stylefeng.guns.modular.system.model.TEnterpriseWithdrawal; |
| | | import com.stylefeng.guns.modular.system.model.User; |
| | | import com.stylefeng.guns.modular.system.service.ITEnterpriseWithdrawalService; |
| | | import com.stylefeng.guns.modular.system.service.IUserService; |
| | | import com.unionpay.upyzt.exception.UpyztException; |
| | | import com.unionpay.upyzt.resp.BalanceAcctListResp; |
| | | import com.unionpay.upyzt.resp.BalanceAcctResp; |
| | | import com.unionpay.upyzt.resp.WithdrawalResp; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | * @author fengshuonan |
| | | * @Date 2023-03-17 14:18:09 |
| | | */ |
| | | @Slf4j |
| | | @Controller |
| | | @RequestMapping("/tCompanyWithdraw") |
| | | public class TCompanyWithdrawController extends BaseController { |
| | |
| | | @Resource |
| | | private ITEnterpriseWithdrawalService enterpriseWithdrawalService; |
| | | |
| | | @Autowired |
| | | private DouGongBasicDataBiz douGongBasicDataBiz; |
| | | |
| | | @Autowired |
| | | private DouGongWithdrawBiz douGongWithdrawBiz; |
| | | |
| | | /** |
| | | * 跳转到首页 |
| | | */ |
| | |
| | | List<TEnterpriseWithdrawal> companyId = enterpriseWithdrawalService.selectList(new EntityWrapper<TEnterpriseWithdrawal>().eq("companyId", id)); |
| | | if(companyId.size()>0){ |
| | | try { |
| | | BalanceAcctReq balanceAcctReq = new BalanceAcctReq(); |
| | | balanceAcctReq.setMchId(companyId.get(0).getMchId()); |
| | | BalanceAcctListResp balanceAcctListResp = BalanceAcctExample.retrieveByUserId(balanceAcctReq); |
| | | Long settledAmount = balanceAcctListResp.getBalanceAccts().get(0).getSettledAmount(); |
| | | String money = settledAmount.toString(); |
| | | model.addAttribute("money",new BigDecimal(money).divide(new BigDecimal(100)).toString()); |
| | | } catch (UpyztException e) { |
| | | e.printStackTrace(); |
| | | //BalanceAcctReq balanceAcctReq = new BalanceAcctReq(); |
| | | //balanceAcctReq.setMchId(companyId.get(0).getMchId()); |
| | | //BalanceAcctListResp balanceAcctListResp = BalanceAcctExample.retrieveByUserId(balanceAcctReq); |
| | | //Long settledAmount = balanceAcctListResp.getBalanceAccts().get(0).getSettledAmount(); |
| | | //String money = settledAmount.toString(); |
| | | BigDecimal money = douGongBasicDataBiz.balanceQuery(companyId.get(0).getHuifuId()); |
| | | model.addAttribute("money",money.divide(new BigDecimal(100)).toString()); |
| | | } catch (Exception e) { |
| | | log.error("查询企业用户汇付余额异常", e); |
| | | model.addAttribute("money",0); |
| | | } |
| | | |
| | |
| | | List<TEnterpriseWithdrawal> companyId = enterpriseWithdrawalService.selectList(new EntityWrapper<TEnterpriseWithdrawal>().eq("companyId", ShiroKit.getUser().getObjectId())); |
| | | if(companyId.size()>0){ |
| | | try { |
| | | BalanceAcctReq balanceAcctReq = new BalanceAcctReq(); |
| | | balanceAcctReq.setMchId(companyId.get(0).getMchId()); |
| | | BalanceAcctListResp balanceAcctListResp = BalanceAcctExample.retrieveByUserId(balanceAcctReq); |
| | | Long settledAmount = balanceAcctListResp.getBalanceAccts().get(0).getSettledAmount(); |
| | | if(settledAmount<money){ |
| | | //BalanceAcctReq balanceAcctReq = new BalanceAcctReq(); |
| | | //balanceAcctReq.setMchId(companyId.get(0).getMchId()); |
| | | //BalanceAcctListResp balanceAcctListResp = BalanceAcctExample.retrieveByUserId(balanceAcctReq); |
| | | //Long settledAmount = balanceAcctListResp.getBalanceAccts().get(0).getSettledAmount(); |
| | | BigDecimal settledAmount = douGongBasicDataBiz.balanceQuery(companyId.get(0).getHuifuId()); |
| | | if(settledAmount.compareTo(BigDecimal.valueOf(money))<0){ |
| | | return "5001"; |
| | | } |
| | | } catch (UpyztException e) { |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | |
| | | withdrawalReq.setPassword(Base64Util.decode(enterpriseWithdrawal.getTransactionAuthorizationCode())); |
| | | |
| | | } |
| | | WithdrawalResp withdrawalResp = WithdrawalExample.create(withdrawalReq); |
| | | String reqSeqId = RequestSeqUtil.extractPrefix("TX"); |
| | | JSONObject result = douGongWithdrawBiz.encashment(reqSeqId, BigDecimal.valueOf(withdrawalReq.getAmount()), companyId.get(0).getHuifuId(), companyId.get(0).getTokenNo(), 1); |
| | | if (!result.get("resp_code").equals("00000000") || !result.getBoolean("success")) { |
| | | return new ErrorTip(500, "操作失败,异常原因:"+result.get("resp_desc")); |
| | | } |
| | | tCompanyWithdraw.setReqSeqId(reqSeqId); |
| | | String hfSeqId = (String) result.get("hf_seq_id"); |
| | | tCompanyWithdraw.setHfSeqId(hfSeqId); |
| | | |
| | | System.out.println("公司添加提现:"+withdrawalResp); |
| | | tCompanyWithdraw.setWithdrawId(withdrawalResp.getWithdrawalId()); |
| | | //WithdrawalResp withdrawalResp = WithdrawalExample.create(withdrawalReq); |
| | | |
| | | } catch (UpyztException e) { |
| | | e.printStackTrace(); |
| | | System.out.println("公司添加提现失败:"+e.getIssue()); |
| | | //System.out.println("公司添加提现:"+withdrawalResp); |
| | | //tCompanyWithdraw.setWithdrawId(withdrawalResp.getWithdrawalId()); |
| | | |
| | | } catch (Exception e) { |
| | | log.error("公司添加提现异常", e); |
| | | return new ErrorTip(500, "公司添加提现异常"); |
| | | } |
| | | tCompanyWithdrawService.insert(tCompanyWithdraw); |
| | | return SUCCESS_TIP; |