Pu Zhibing
3 天以前 25cf266e99714ac5d428e66b40ce272325c91dd8
ManagementQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/controller/general/TCompanyWithdrawController.java
@@ -2,33 +2,25 @@
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.beetl.ShiroExtUtil;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.core.shiro.ShiroKit;
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.system.controller.util.Base64Util;
import com.stylefeng.guns.modular.system.model.TCompanyWithdraw;
import com.stylefeng.guns.modular.system.model.TEnterpriseWithdrawal;
import com.stylefeng.guns.modular.system.model.User;
import com.stylefeng.guns.modular.system.service.ITCompanyWithdrawService;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.TCompanyWithdraw;
import com.stylefeng.guns.modular.system.service.ITCompanyWithdrawService;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.math.BigDecimal;
@@ -58,21 +50,9 @@
     */
    @RequestMapping("")
    public String index(Model model) {
        Integer id = ShiroKit.getUser().getObjectId();
        Integer id = ShiroExtUtil.getUser().getObjectId();
        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();
                model.addAttribute("money",0);
            }
        }else {
            model.addAttribute("money",0);
        }
@@ -105,7 +85,7 @@
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String createTime,Integer state) {
        Integer id = ShiroKit.getUser().getObjectId();
        Integer id = ShiroExtUtil.getUser().getObjectId();
        EntityWrapper<TCompanyWithdraw> withdrawEntityWrapper = new EntityWrapper<>();
        String sTime=null;
        String eTime=null;
@@ -134,54 +114,21 @@
    @ResponseBody
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRES_NEW)
    public Object add(Double money,String type,String remark) {
        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){
                    return "5001";
                }
            } catch (UpyztException e) {
                e.printStackTrace();
            }
        List<TEnterpriseWithdrawal> companyId = enterpriseWithdrawalService.selectList(new EntityWrapper<TEnterpriseWithdrawal>().eq("companyId", ShiroExtUtil.getUser().getObjectId()));
        if (companyId.size() > 0) {
        }
        TCompanyWithdraw tCompanyWithdraw = new TCompanyWithdraw();
        tCompanyWithdraw.setWithdrawMoney(new BigDecimal(money));
        tCompanyWithdraw.setCompanyId(ShiroKit.getUser().getObjectId());
        tCompanyWithdraw.setCreateId(ShiroKit.getUser().getId());
        tCompanyWithdraw.setCompanyId(ShiroExtUtil.getUser().getObjectId());
        tCompanyWithdraw.setCreateId(ShiroExtUtil.getUser().getId());
        tCompanyWithdraw.setCreateTime(new Date());
        if("提现".equals(type)){
        if ("提现".equals(type)) {
            tCompanyWithdraw.setType(1);
        }
        tCompanyWithdraw.setRemark(remark);
        tCompanyWithdraw.setStatus(0);
        // TODO 创建提现  需要回调进行提现状态查询
        try {
            WithdrawalReq withdrawalReq = new WithdrawalReq();
            if(companyId.size()>0){
                TEnterpriseWithdrawal enterpriseWithdrawal = companyId.get(0);
                withdrawalReq.setOutOrderNo(ToolUtil.getRandomString(32));
                int total = new BigDecimal(money).multiply(new BigDecimal(100)).intValue();
                withdrawalReq.setAmount(total);
                withdrawalReq.setBalanceAcctId(enterpriseWithdrawal.getBalanceAcctId());
                withdrawalReq.setBankAcctNo(enterpriseWithdrawal.getBankAccount());
                withdrawalReq.setPassword(Base64Util.decode(enterpriseWithdrawal.getTransactionAuthorizationCode()));
            }
            WithdrawalResp withdrawalResp = WithdrawalExample.create(withdrawalReq);
            System.out.println("公司添加提现:"+withdrawalResp);
            tCompanyWithdraw.setWithdrawId(withdrawalResp.getWithdrawalId());
        } catch (UpyztException e) {
            e.printStackTrace();
            System.out.println("公司添加提现失败:"+e.getIssue());
        }
        tCompanyWithdrawService.insert(tCompanyWithdraw);
        return SUCCESS_TIP;
    }