Exemplo n.º 1
0
        public object PostApplyWithDraw(MemberCapitalApplyWithDrawModel para)
        {
            CheckUserLogin();
            if (para == null)
            {
                para = new MemberCapitalApplyWithDrawModel();
            }
            var success     = MemberApplication.VerificationPayPwd(CurrentUser.Id, para.pwd);
            var sitesetting = SiteSettingApplication.SiteSettings;

            if (para.applyType == CommonModel.UserWithdrawType.ALiPay.GetHashCode() && !sitesetting.Withdraw_AlipayEnable)
            {
                return(Json(ErrorResult <bool>("不支持支付宝提现方式")));
            }

            if (!success)
            {
                return(Json(ErrorResult <bool>("支付密码不对,请重新输入")));
            }

            var balance = MemberCapitalApplication.GetBalanceByUserId(CurrentUser.Id);

            if (para.amount > balance)
            {
                return(Json(ErrorResult <bool>("提现金额不能超出可用金额!")));
            }

            if (para.amount <= 0)
            {
                return(Json(ErrorResult <bool>("提现金额不能小于等于0!")));
            }
            if (string.IsNullOrWhiteSpace(para.openId) && para.applyType == CommonModel.UserWithdrawType.WeiChat.GetHashCode())
            {
                var mo = MemberApplication.GetMemberOpenIdInfoByuserId(CurrentUser.Id, Entities.MemberOpenIdInfo.AppIdTypeEnum.Payment, PLUGIN_OAUTH_WEIXIN);
                if (mo != null && !string.IsNullOrWhiteSpace(mo.OpenId))
                {
                    para.openId = mo.OpenId;
                }
            }
            if (string.IsNullOrWhiteSpace(para.nickname) && para.applyType == CommonModel.UserWithdrawType.ALiPay.GetHashCode())
            {
                return(Json(ErrorResult <bool>("数据异常,真实姓名不可为空!")));
            }
            if (!string.IsNullOrWhiteSpace(para.openId) && para.applyType == CommonModel.UserWithdrawType.WeiChat.GetHashCode())
            {
                //para.openid = Core.Helper.SecureHelper.AESDecrypt(para.openid, "Mobile");
                if (!string.IsNullOrWhiteSpace(sitesetting.WeixinAppletId) && !string.IsNullOrWhiteSpace(sitesetting.WeixinAppletSecret))
                {
                    string token    = AccessTokenContainer.TryGetAccessToken(sitesetting.WeixinAppletId, sitesetting.WeixinAppletSecret);
                    var    userinfo = Senparc.Weixin.MP.CommonAPIs.CommonApi.GetUserInfo(token, para.openId);
                    if (userinfo != null)
                    {
                        para.nickname = userinfo.nickname;
                    }
                }
            }
            if (string.IsNullOrWhiteSpace(para.openId))
            {
                return(Json(ErrorResult <bool>("数据异常,OpenId或收款账号不可为空!")));
            }

            Mall.Entities.ApplyWithdrawInfo model = new Mall.Entities.ApplyWithdrawInfo()
            {
                ApplyAmount = para.amount,
                ApplyStatus = Mall.Entities.ApplyWithdrawInfo.ApplyWithdrawStatus.WaitConfirm,
                ApplyTime   = DateTime.Now,
                MemId       = CurrentUser.Id,
                OpenId      = para.openId,
                NickName    = para.nickname,
                ApplyType   = (CommonModel.UserWithdrawType)para.applyType
            };
            MemberCapitalApplication.AddWithDrawApply(model);
            return(Json(true));
        }