package org.tio.sitexxx.server.controller;

/**
 * <pre>
 *    @author : vagrancy
 *    e-mail : 18050829067@163.com
 *    time   : 2025-11-24 15:27
 *    desc   :
 * </pre>
 */

import cn.hutool.core.util.StrUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.redisson.api.RBucket;
import org.redisson.api.RList;
import org.redisson.api.RedissonClient;
import org.tio.http.common.HttpRequest;
import org.tio.http.server.annotation.RequestPath;
import org.tio.jfinal.kit.Ret;
import org.tio.jfinal.plugin.activerecord.Db;
import org.tio.jfinal.plugin.activerecord.Record;
import org.tio.sitexxx.im.server.vo.*;
import org.tio.sitexxx.server.utils.WebUtils;
import org.tio.sitexxx.service.init.RedisInit;
import org.tio.sitexxx.service.model.main.*;
import org.tio.sitexxx.service.service.ConfService;
import org.tio.sitexxx.service.service.chat.ChatIndexService;
import org.tio.sitexxx.service.service.chat.ChatService;
import org.tio.sitexxx.service.service.chat.GroupService;
import org.tio.sitexxx.service.service.pay.BasePayService;
import org.tio.sitexxx.service.service.pay.PayService;
import org.tio.sitexxx.service.utils.RetUtils;
import org.tio.sitexxx.service.vo.Const;
import org.tio.sitexxx.service.vo.PayConst;
import org.tio.utils.resp.Resp;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.*;
import java.util.concurrent.TimeUnit;

/**
 * 支付
 */
@RequestPath(value = "/pay")
public class PayController {
    private static BasePayService payService = new PayService();

    /**
     * 初始化红包
     */
    @RequestPath(value = "/initredpacket")
    public Resp initRedPacket(HttpRequest request, SendRedpacketVo redPacketVo) {
        Long chatLinkId = redPacketVo.getChatlinkid();
        User curr = WebUtils.currUser(request);
        if (curr == null) {
            return Resp.fail("未登录");
        }
        if (redPacketVo.getChatlinkid() <= 0) {
            Ret check = GroupService.checkGroupMsg(-chatLinkId, curr.getId());
            if (check.isFail()) {
                return Resp.fail(RetUtils.getRetMsg(check));
            }
        }
        Double _amount = Double.parseDouble(redPacketVo.getCny());
        String singleCny = redPacketVo.getSinglecny();
        if(StringUtils.isNotEmpty(singleCny) && Long.parseLong(singleCny)<0) {
            return Resp.fail("红包金额最小为0.01元");
        }
        if (_amount <= 0) {
            return Resp.fail("红包金额最小为0.01元");
        }
        Integer min = ConfService.getInt(Const.ConfMapping.WX_WALLET_SENDREDPACKET_MIN_AMOUNT, 10);
        if (_amount < min) {
            return Resp.fail("红包金额最小为" + new Double(min) / 100 + "元");
        }
        Integer sendRedpacketLimit = ConfService.getInt(Const.ConfMapping.WX_WALLET_SENDREDPACKET_MAX_AMOUNT, 10);
        if (_amount > sendRedpacketLimit) {
            return Resp.fail("红包金额最大为" + new Double(sendRedpacketLimit) / 100 + "元");
        }
        if (redPacketVo.getUid() == null) {
            redPacketVo.setUid(curr.getId());
        }
        Ret wret = payService.getWalletInfo(curr.getId());
        WxWalletCoin wxWalletCoin = (WxWalletCoin) wret.get("data");
        Long cny = wxWalletCoin.getCny();
        if(cny<_amount) {
            return Resp.fail("余额不足");
        }
        short chatmode = Const.ChatMode.P2P;
        Long groupid;
        if (chatLinkId <= 0) {
            chatmode = Const.ChatMode.GROUP;
            groupid = -chatLinkId;
            WxChatGroupItem groupItem = ChatIndexService.chatGroupIndex(curr.getId(), groupid);
            if (!ChatService.groupExistChat(groupItem)) {
                return Resp.fail("不是群成员");
            }
            redPacketVo.setBizid(groupid);
        } else {
            WxChatUserItem userItem = ChatIndexService.chatUserIndex(chatLinkId);
            if (!ChatService.existTwoFriend(userItem)) {
                return Resp.fail("你们不是互相不是好友");
            }
            redPacketVo.setBizid(userItem.getBizid());
        }
        redPacketVo.setChatmode(chatmode);
        Ret ret = payService.initRedPacket(redPacketVo);
        if (ret.isFail()) {
            return Resp.fail(RetUtils.getRetMsg(ret));
        }
        return Resp.ok(RetUtils.getOkData(ret));
    }

    /**
     * 开户状态
     */
    @RequestPath(value = "/openflag")
    public Resp openFlag(HttpRequest request) {
        User curr = WebUtils.currUser(request);
        if (curr == null) {
            return Resp.fail("未登录");
        }
        Map<String, Object> ret = new HashMap<>();
        ret.put("uid", curr.getId());
        return Resp.ok(ret);
    }


    /**
     * 充值接口
     */
    @RequestPath(value = "/recharge")
    public Resp recharge() throws Exception {
        return Resp.fail("请联系客服");
    }

    /**
     * 充值提交
     */
    @RequestPath(value = "/rechargeconfirm")
    public Resp rechargeConfirm() {
        return Resp.fail("请联系客服");
    }

    /**
     * 获取汇率
     */
    @RequestPath(value = "/getRate")
    public Resp getRate() {
        RedissonClient redissonClient = RedisInit.get();
        RBucket<Object> rBucket = redissonClient.getBucket("usdt_rate");
        Object object = rBucket.get();
        Double rate = Double.valueOf(object.toString());
        return Resp.ok(rate);
    }

    /**
     * 提现接口
     */
    @RequestPath(value = "/withhold")
    public Resp withhold(HttpRequest request, WithholdVo withholdVo) throws Exception {
        User curr = WebUtils.currUser(request);
        if (curr == null) {
            return Resp.fail("未登录");
        }
        if (withholdVo == null) {
            return Resp.fail("提现金额参数为空");
        }
        String type = withholdVo.getType();
        //支付宝得
        LocalDate now = LocalDate.now();
        DayOfWeek week = now.getDayOfWeek();
        Double _amount = Double.parseDouble(withholdVo.getAmount());
        if(type != null && type .equals("1")) {
            //非周一到周五 劝退
            if(week.getValue()>5) {
                return Resp.fail("支付宝提现时间为周一到周五 请在规定时间提现");
            }
            Integer withholdlimit = ConfService.getInt(Const.ConfMapping.WX_WALLET_WITHHOLD_MAX_AMOUNT_ZHIFU, 10);
            if (_amount > withholdlimit) {
                return Resp.fail("提现金额最大为" + new Double(withholdlimit) / 100 + "元");
            }
            Integer minAmount = ConfService.getInt(Const.ConfMapping.WX_WALLET_WITHHOLD_MIN_AMOUT_ZHIFU, 10000);
            if (_amount < minAmount) {
                return Resp.fail("单次提现金额不低于" + ((double) minAmount) / 100 + "元");
            }
            withholdVo.setRemark("支付宝提现");
        }else {
            Integer txBank = ConfService.getInt(Const.ConfMapping.TX_BANK, 10);
            if(week.getValue()!=1 && txBank != 10) {
                return Resp.fail("银行卡提现时间为每周一 请在规定时间提现");
            }
            Integer withholdlimit = ConfService.getInt(Const.ConfMapping.WX_WALLET_WITHHOLD_MAX_AMOUNT, 10);
            if (_amount > withholdlimit) {
                return Resp.fail("提现金额最大为" + new Double(withholdlimit) / 100 + "元");
            }
            Integer minAmount = ConfService.getInt(Const.ConfMapping.WX_WALLET_WITHHOLD_MIN_AMOUT, 10000);
            if (_amount < minAmount) {
                return Resp.fail("单次提现金额不低于" + ((double) minAmount) / 100 + "元");
            }
            withholdVo.setRemark("银行卡提现");
        }

        withholdVo.setUser(curr);
        if (StrUtil.isBlank(withholdVo.getAmount())) {
            return Resp.fail("提现金额为空");
        }
        if (_amount <= 0) {
            return Resp.fail("提现金额为负");
        }
        withholdVo.setUid(curr.getId());
        synchronized (curr) {
            Ret wret = payService.getWalletInfo(curr.getId());
            WxWalletCoin wxWalletCoin =(WxWalletCoin)wret.get("data");
            Long cny = wxWalletCoin.getCny();
            String app_name = ConfService.getString(Const.APP_NAME,"");
            if(app_name.equals("启盛")) {
                Date date = new Date();
                Date endDate = DateUtils.addDays(date,-7);
                Integer weekCny = Db.use(Const.Db.TIO_SITE_MAIN).queryInt("select ifnull(sum(amount),0) from wx_wallet_recharge_item where createtime BETWEEN ? and ? and uid = ?",endDate,date,curr.getId()) ;
                if(weekCny == null) {
                    weekCny = 0;
                }
                cny = cny - weekCny;
            }
            if(cny<_amount) {
                return Resp.fail("余额不足");
            }
        }
        RedissonClient redissonClient = RedisInit.get();
        RBucket<Object> bucket = redissonClient.getBucket("user_with_num"+curr.getId());
        Object userNum = bucket.get();
        Integer maxCount = ConfService.getInt(Const.ConfMapping.WX_WALLET_WITHHOLD_MAX_COUNT, 1);
        if(userNum != null) {
            int num = Integer.parseInt(userNum.toString());
            if(num>=maxCount) {
                return Resp.fail("24小时内只能提现"+maxCount+"次");
            }
        }

        Ret ret = payService.withhold(withholdVo, request);
        if (ret.isFail()) {
            return Resp.fail().msg(RetUtils.getRetMsg(ret));
        }
        if(userNum != null) {
            int num = Integer.parseInt(userNum.toString());
            bucket.set(num+1);
        }else {
            bucket.set(1);
        }
        bucket.expire(24, TimeUnit.HOURS);
        return Resp.ok(RetUtils.getOkData(ret));
    }

    /**
     * 提现查询
     */
    @RequestPath(value = "/withholdQuery")
    public Resp withholdQuery(HttpRequest request, WithholdQueryVo queryVo) {
        User curr = WebUtils.currUser(request);
        if (curr == null) {
            return Resp.fail("未登录");
        }
        if (queryVo == null || StrUtil.isBlank(queryVo.getReqid())) {
            return Resp.fail("提现查询参数为空");
        }
        if (queryVo.getUid() == null) {
            queryVo.setUid(curr.getId());
        }
        Ret ret = payService.withholdQuery(queryVo, request);
        if (ret.isFail()) {
            return Resp.fail().msg(RetUtils.getRetMsg(ret));
        }
        return Resp.ok(RetUtils.getOkData(ret));
    }

    /**
     * 提现记录
     */
    @RequestPath(value = "/withholdlist")
    public Resp withholdList(HttpRequest request, Integer pageNumber) {
        User curr = WebUtils.currUser(request);
        if (curr == null) {
            return Resp.fail("未登录");
        }
        Ret ret = payService.withholdList(curr.getId(), pageNumber);
        if (ret.isFail()) {
            return Resp.fail().msg(RetUtils.getRetMsg(ret));
        }
        return Resp.ok(RetUtils.getOkPage(ret));
    }

    /**
     * 发红包接口
     */
    @RequestPath(value = "/sendRedpacket")
    public Resp sendRedPacket(HttpRequest request, SendRedpacketVo redPacketVo) throws Exception {
        User curr = WebUtils.currUser(request);
        if (curr == null) {
            return Resp.fail("未登录");
        }
        if (redPacketVo == null || redPacketVo.getChatlinkid() == null) {
            return Resp.fail("钱包参数为空");
        }
        Double _amount = Double.parseDouble(redPacketVo.getCny());
        if (_amount <= 0) {
            return Resp.fail("红包金额最小为0.01元");
        }
        Integer sendRedpacketLimit = ConfService.getInt(Const.ConfMapping.WX_WALLET_SENDREDPACKET_MAX_AMOUNT, 10);
        if (_amount > sendRedpacketLimit) {
            return Resp.fail("红包金额最大为" + new Double(sendRedpacketLimit) / 100 + "元");
        }
        if (redPacketVo.getUid() == null) {
            redPacketVo.setUid(curr.getId());
        }
        Ret wret = payService.getWalletInfo(curr.getId());
        WxWalletCoin wxWalletCoin =(WxWalletCoin)wret.get("data");
        Long cny = wxWalletCoin.getCny();
        if(cny<_amount) {
            return Resp.fail("余额不足");
        }
        Long chatlinkid = redPacketVo.getChatlinkid();
        short chatmode = Const.ChatMode.P2P;
        Long groupid;
        if (chatlinkid <= 0) {
            chatmode = Const.ChatMode.GROUP;
            groupid = -chatlinkid;
            WxChatGroupItem groupItem = ChatIndexService.chatGroupIndex(curr.getId(), groupid);
            if (!ChatService.groupExistChat(groupItem)) {
                return Resp.fail("不是群成员");
            }
            redPacketVo.setBizid(groupid);
        } else {
            WxChatUserItem userItem = ChatIndexService.chatUserIndex(chatlinkid);
            if (!ChatService.existTwoFriend(userItem)) {
                return Resp.fail("你们不是互相不是好友");
            }
            redPacketVo.setBizid(userItem.getBizid());
        }
        redPacketVo.setChatmode(chatmode);
        Ret ret = payService.sendRedPacket(redPacketVo, request);
        if (ret.isFail()) {
            return Resp.fail().msg(RetUtils.getRetMsg(ret));
        }
        return Resp.ok(RetUtils.getOkData(ret));
    }


    /**
     * 快捷支付红包-预下单-发短信
     */
    @RequestPath(value = "/quickredpacket")
    public Resp quickRedPacket(HttpRequest request, SendRedpacketVo redPacketVo) {
        User curr = WebUtils.currUser(request);
        if (curr == null) {
            return Resp.fail("未登录");
        }
        if (redPacketVo.getRid() == null || StrUtil.isBlank(redPacketVo.getAgrno())) {
            return Resp.fail("钱包参数为空");
        }
        synchronized (redPacketVo) {
            List<WxWalletRedPacketRandom> find = WxWalletRedPacketRandom.dao.find("select uid from wx_wallet_red_packet_random  where  rid = ? ",redPacketVo.getRid());
            if(find == null || find.size()==0) {
                return Resp.fail("用户未实名认证");
            }
            Ret wret = payService.getWalletInfo(curr.getId());
            WxWalletCoin wxWalletCoin =(WxWalletCoin)wret.get("data");
            Long cny = wxWalletCoin.getCny();
            Integer rid = redPacketVo.getRid();
            WxWalletSendRedPacket findById = WxWalletSendRedPacket.dao.dao().findById(rid);
            Long cny2 = findById.getCny();
            if(cny<cny2) {
                return Resp.fail("余额不足");
            }
            if (redPacketVo.getUid() == null) {
                redPacketVo.setUid(curr.getId());
            }

            Ret ret = payService.quickRedPacket(redPacketVo, request);
            if (ret.isFail()) {
                return Resp.fail(RetUtils.getRetMsg(ret));
            }
            return Resp.ok(RetUtils.getOkData(ret));

        }
    }

    /**
     * 红包支付
     */
    @RequestPath(value = "/payredpacket")
    public Resp payRedPacket(HttpRequest request, SendRedpacketVo redPacketVo) {
        User curr = WebUtils.currUser(request);
        if (curr == null) {
            return Resp.fail("未登录");
        }
        if (redPacketVo.getPaytype() == null || redPacketVo.getRid() == null) {
            return Resp.fail("钱包参数为空");
        }
        synchronized (redPacketVo) {
            List<WxWalletRedPacketRandom> find = WxWalletRedPacketRandom.dao.find("select uid from wx_wallet_red_packet_random  where rid = ? ",redPacketVo.getRid());
            if(find == null || find.size()==0) {
                return Resp.fail("用户未实名认证");
            }
            Integer rid = redPacketVo.getRid();
            if (redPacketVo.getUid() == null) {
                redPacketVo.setUid(curr.getId());
            }
            if (Objects.equals(redPacketVo.getPaytype(), PayConst.RedPayType.CNY)) {
                if (StrUtil.isBlank(redPacketVo.getPaypwd())) {
                    return Resp.fail("支付密码为空");
                }
            } else {
                if (StrUtil.isBlank(redPacketVo.getMerorderid()) || StrUtil.isBlank(redPacketVo.getSmscode())) {
                    return Resp.fail("快捷支付参数为空");
                }
            }
            Ret wret = payService.getWalletInfo(curr.getId());
            WxWalletCoin wxWalletCoin =(WxWalletCoin)wret.get("data");
            Long cny = wxWalletCoin.getCny();
            WxWalletSendRedPacket findById = WxWalletSendRedPacket.dao.dao().findById(rid);
            Long cny2 = findById.getCny();
            if(cny<cny2) {
                return Resp.fail("余额不足");
            }
            Ret ret = payService.payRedPacket(redPacketVo, request, curr);
            if (ret.isFail()) {
                return Resp.fail(RetUtils.getRetMsg(ret));
            }
            return Resp.ok(RetUtils.getOkData(ret));
        }
    }

    /**
     * 发红包列表
     */
    @RequestPath(value = "/sendRedpacketlist")
    public Resp sendRedPacketList(HttpRequest request, Integer pageNumber, String period) {
        User curr = WebUtils.currUser(request);
        if (curr == null) {
            return Resp.fail("未登录");
        }
        Ret ret = payService.sendRedPacketList(curr.getId(), pageNumber, period);
        if (ret.isFail()) {
            return Resp.fail().msg(RetUtils.getRetMsg(ret));
        }
        return Resp.ok(RetUtils.getOkPage(ret));
    }

    /**
     * 发送红包状态
     */
    @RequestPath(value = "/sendredpacketstat")
    public Resp sendRedPacketStat(HttpRequest request, String period) {
        User curr = WebUtils.currUser(request);
        if (curr == null) {
            return Resp.fail("未登录");
        }
        Ret ret = payService.sendRedPacketStat(curr.getId(), period);
        if (ret.isFail()) {
            return Resp.fail().msg(RetUtils.getRetMsg(ret));
        }
        Record record = RetUtils.getOkTData(ret);
        if (record != null) {
            record.set("nick", curr.getNick());
            record.set("avatar", curr.getAvatar());
        }
        return Resp.ok(record);
    }

    /**
     * 抢红包
     */
    @RequestPath(value = "/grabRedpacket")
    public Resp grabRedPacket(HttpRequest request, GrabRedpacketVo grabRedpacketVo) {
        System.out.println("开始执行抢红包");
        //先看红包是否还存在 如果不存在了直接返回
        RedissonClient redissonClient = RedisInit.get();
        RBucket<Object> rbucket = redissonClient.getBucket("redInfo_"+grabRedpacketVo.getRid());
        //改为缓存里拿取红包信息
        WxWalletSendRedPacket redPacket =(WxWalletSendRedPacket)rbucket.get();
        if (redPacket == null) {
            return Resp.fail("红包不存在");
        }
        if (Objects.equals(redPacket.getStatus(), PayConst.RedPacketStatus.SUCCESS)) {
            return Resp.fail("红包已抢完");
        }

        User curr = WebUtils.currUser(request);
        if (curr == null) {
            return Resp.fail("未登录");
        }
        RBucket<Object> bucket = redissonClient.getBucket(curr.getId()+"_redUser");
        if(bucket.get()!= null) {
            return Resp.fail("正在处理");
        }
        bucket.set("1");
        bucket.expire(5, TimeUnit.SECONDS);
        grabRedpacketVo.setUid(curr.getId());
        Long chatlinkid = grabRedpacketVo.getChatlinkid();
        short chatmode = Const.ChatMode.P2P;
        Long groupid;
        if (chatlinkid <= 0) {
            chatmode = Const.ChatMode.GROUP;
            groupid = -chatlinkid;
            WxChatGroupItem groupItem = ChatIndexService.chatGroupIndex(curr.getId(), groupid);
            if (!ChatService.groupExistChat(groupItem)) {
                return Resp.fail("不是群成员");
            }
            grabRedpacketVo.setBizid(groupid);
            if(!redPacket.getChatbizid().equals(groupid)) {
                return Resp.fail("不是群成员");
            }
        } else {
            WxChatUserItem userItem = ChatIndexService.chatUserIndex(chatlinkid);
            if (!ChatService.existTwoFriend(userItem)) {
                return Resp.fail("你们不是互相不是好友");
            }
            grabRedpacketVo.setBizid(userItem.getBizid());
            Integer uid = redPacket.getAcceptuid();

            if(!uid.equals(curr.getId())) {
                RedissonClient client = RedisInit.get();
                RList<Object> rList = client.getList("blackIp");
                rList.add(curr.getId());
                return Resp.fail("");
            }
        }
        grabRedpacketVo.setChatmode(chatmode);
        Ret ret = payService.grabRedPacket(grabRedpacketVo, curr);
        if (ret.isFail()) {
            return Resp.fail().msg(RetUtils.getRetMsg(ret));
        }
        return Resp.ok(RetUtils.getOkData(ret));
    }

    /**
     * 抢红包列表
     */
    @RequestPath(value = "/grabRedpacketlist")
    public Resp grabRedPacketList(HttpRequest request, Integer pageNumber, String period) {
        System.out.println("开始执行查询红包列表");
        User curr = WebUtils.currUser(request);
        if (curr == null) {
            return Resp.fail("未登录");
        }
        Ret ret = payService.grabRedPacketList(curr.getId(), pageNumber, period);
        if (ret.isFail()) {
            return Resp.fail().msg(RetUtils.getRetMsg(ret));
        }
        return Resp.ok(RetUtils.getOkPage(ret));
    }

    /**
     * 抢红包状态
     */
    @RequestPath(value = "/grabredpacketstat")
    public Resp grabRedPacketStat(HttpRequest request, String period) {
        System.out.println("开始执行抢红包列表状态");
        User curr = WebUtils.currUser(request);
        if (curr == null) {
            return Resp.fail("未登录");
        }
        Ret ret = payService.grabRedPacketStat(curr.getId(), period);
        if (ret.isFail()) {
            return Resp.fail().msg(RetUtils.getRetMsg(ret));
        }
        Record record = RetUtils.getOkTData(ret);
        if (record != null) {
            record.set("nick", curr.getNick());
            record.set("avatar", curr.getAvatar());
        }
        return Resp.ok(record);
    }

    /**
     * 红包状态
     */
    @RequestPath(value = "/redStatus")
    public Resp redStatus(HttpRequest request, Integer rid) {
        System.out.println("开始执行查询红包状态");
        User curr = WebUtils.currUser(request);
        Ret ret = payService.redStatus(curr, rid);
        if (ret.isFail()) {
            return Resp.fail().msg(RetUtils.getRetMsg(ret));
        }
        return Resp.ok(RetUtils.getOkData(ret));
    }

    /**
     * 红包信息
     */
    @RequestPath(value = "/redInfo")
    public Resp redInfo(Integer rid) {
        System.out.println("开始执行查询红包信息");
        Ret ret = payService.redInfo(rid);
        if (ret.isFail()) {
            return Resp.fail().msg(RetUtils.getRetMsg(ret));
        }
        return Resp.ok(RetUtils.getOkData(ret));
    }

    /**
     * 支付列表信息
     */
    @RequestPath(value = "/paylistinfo")
    public Resp payListInfo(HttpRequest request) {
        User curr = WebUtils.currUser(request);
        if (curr == null) {
            return Resp.fail("未登录");
        }
        Ret ret = payService.payListInfo(curr.getId());
        if (ret.isFail()) {
            return Resp.fail().msg(RetUtils.getRetMsg(ret));
        }
        return Resp.ok(RetUtils.getOkData(ret));
    }

    /**
     * 获取钱包信息
     */
    @RequestPath(value = "/getWalletInfo")
    public Resp getWalletInfo(HttpRequest request) {
        User curr = WebUtils.currUser(request);
        if (curr == null) {
            return Resp.fail("未登录");
        }
        Ret ret = payService.getWalletInfo(curr.getId());
        if (ret.isFail()) {
            return Resp.fail().msg(RetUtils.getRetMsg(ret));
        }
        return Resp.ok(RetUtils.getOkData(ret));
    }

    /**
     * 获取钱包明细
     */
    @RequestPath(value = "/getWalletItems")
    public Resp getWalletItems(HttpRequest request, Integer pageNumber, Short mode) {
        User curr = WebUtils.currUser(request);
        if (curr == null) {
            return Resp.fail("未登录");
        }
        Ret ret = payService.getWalletItems(curr.getId(), pageNumber, mode);
        if (ret.isFail()) {
            return Resp.fail().msg(RetUtils.getRetMsg(ret));
        }
        return Resp.ok(RetUtils.getOkPage(ret));
    }

    /**
     * 获取客户端native的token
     */
    @RequestPath(value = "/getClientToken")
    public Resp getClientToken(HttpRequest request, ClientTokenVo tokenVo) {
        User curr = WebUtils.currUser(request);
        if (curr == null) {
            return Resp.fail("未登录");
        }
        if (tokenVo == null) {
            return Resp.fail("token参数为空");
        }
        if (tokenVo.getUid() == null) {
            tokenVo.setUid(curr.getId());
        }
        tokenVo.setUid(curr.getId());
        Ret ret = payService.getClientToken(tokenVo, request);
        if (ret.isFail()) {
            return Resp.fail().msg(RetUtils.getRetMsg(ret));
        }
        return Resp.ok(RetUtils.getOkData(ret));
    }

    /**
     * 实名信息
     */
    @RequestPath(value = "/realinfo")
    public Resp realInfo(HttpRequest request) {
        User curr = WebUtils.currUser(request);
        if (curr == null) {
            return Resp.fail("未登录");
        }
        Ret ret = payService.realInfo(curr.getId());
        if (ret.isFail()) {
            return Resp.fail(RetUtils.getRetMsg(ret));
        }
        return Resp.ok(RetUtils.getOkData(ret));
    }
    /**
     * 银行卡列表
     */
    @RequestPath(value = "/bankcardlist")
    public Resp bankcardList(HttpRequest request) {
        User curr = WebUtils.currUser(request);
        if (curr == null) {
            return Resp.fail("未登录");
        }
        Ret ret = payService.bankcardList(curr.getId());
        if (ret.isFail()) {
            return Resp.fail(RetUtils.getRetMsg(ret));
        }
        return Resp.ok(RetUtils.getOkList(ret));
    }

    /**
     * 绑定银行卡
     */
    @RequestPath(value = "/bindcard")
    public Resp bindCard(HttpRequest request, BindCardVo cardVo) {
        User curr = WebUtils.currUser(request);
        if (curr == null) {
            return Resp.fail("未登录");
        }
        if (cardVo == null) {
            return Resp.fail("参数为空");
        }
        if (cardVo.getUid() == null) {
            cardVo.setUid(curr.getId());
        }
        Ret ret = payService.bindCard(cardVo, request);
        if (ret.isFail()) {
            return Resp.fail(RetUtils.getRetMsg(ret));
        }
        return Resp.ok(RetUtils.getOkData(ret));
    }

    /**
     * 绑定银行卡确定
     */
    @RequestPath(value = "/bindcardconfirm")
    public Resp bindCardConfirm(HttpRequest request, BindCardConfirmVo cardVo) {
        User curr = WebUtils.currUser(request);
        if (curr == null) {
            return Resp.fail("未登录");
        }
        if (cardVo.getUid() == null) {
            cardVo.setUid(curr.getId());
        }
        Ret ret = payService.bindCardConfirm(cardVo, request);
        if (ret.isFail()) {
            return Resp.fail(RetUtils.getRetMsg(ret));
        }
        return Resp.ok(RetUtils.getOkData(ret));
    }

    /**
     * 解除银行卡
     */
    @RequestPath(value = "/unbindcard")
    public Resp unbindCard(HttpRequest request, UnBindCardVo cardVo) {
        User curr = WebUtils.currUser(request);
        if (curr == null) {
            return Resp.fail("未登录");
        }
        if (cardVo == null) {
            return Resp.fail("参数为空");
        }
        Ret ret = payService.unBindCard(curr.getId(), cardVo.getBankcardid());
        if (ret.isFail()) {
            return Resp.fail(RetUtils.getRetMsg(ret));
        }
        return Resp.ok(RetUtils.getOkData(ret));
    }
}
