Ejemplo n.º 1
0
        public JsonResult ApplyWithDrawSubmit(string openid, string nickname, decimal amount, string pwd, int applyType = 1)
        {
            var success = MemberApplication.VerificationPayPwd(CurrentUser.Id, pwd);

            if (!success)
            {
                throw new HimallException("支付密码不对,请重新输入!");
            }
            if (applyType == CommonModel.UserWithdrawType.ALiPay.GetHashCode() && !SiteSettings.Withdraw_AlipayEnable)
            {
                throw new HimallException("不支持支付宝提现方式!");
            }

            var balance = MemberCapitalApplication.GetBalanceByUserId(UserId);

            if (amount > balance)
            {
                throw new HimallException("提现金额不能超出可用金额!");
            }
            if (amount <= 0)
            {
                throw new HimallException("提现金额不能小于等于0!");
            }
            if (string.IsNullOrWhiteSpace(openid) && applyType == CommonModel.UserWithdrawType.WeiChat.GetHashCode())
            {
                openid = Core.Helper.WebHelper.GetCookie(CookieKeysCollection.HIMALL_USER_OpenID);
            }
            if (string.IsNullOrWhiteSpace(nickname) && applyType == CommonModel.UserWithdrawType.ALiPay.GetHashCode())
            {
                throw new HimallException("数据异常,真实姓名不可为空!");
            }
            if (!string.IsNullOrWhiteSpace(openid) && applyType == CommonModel.UserWithdrawType.WeiChat.GetHashCode())
            {
                openid = Core.Helper.SecureHelper.AESDecrypt(openid, "Mobile");
                var siteSetting = SiteSettingApplication.SiteSettings;
                if (!(string.IsNullOrWhiteSpace(siteSetting.WeixinAppId) || string.IsNullOrWhiteSpace(siteSetting.WeixinAppSecret)))
                {
                    string token    = AccessTokenContainer.TryGetToken(siteSetting.WeixinAppId, siteSetting.WeixinAppSecret);
                    var    userinfo = Senparc.Weixin.MP.CommonAPIs.CommonApi.GetUserInfo(token, openid);
                    if (userinfo != null)
                    {
                        nickname = userinfo.nickname;
                    }
                }
            }
            if (string.IsNullOrWhiteSpace(openid))
            {
                throw new HimallException("数据异常,OpenId或收款账号不可为空!");
            }

            Himall.Entities.ApplyWithDrawInfo model = new Himall.Entities.ApplyWithDrawInfo()
            {
                ApplyAmount = amount,
                ApplyStatus = Himall.Entities.ApplyWithDrawInfo.ApplyWithDrawStatus.WaitConfirm,
                ApplyTime   = DateTime.Now,
                MemId       = CurrentUser.Id,
                OpenId      = openid,
                NickName    = nickname,
                ApplyType   = (CommonModel.UserWithdrawType)applyType
            };
            _iMemberCapitalService.AddWithDrawApply(model);
            return(Json(new { success = true }));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 申请提现
        /// </summary>
        /// <param name="openid"></param>
        /// <param name="nickname"></param>
        /// <param name="amount"></param>
        /// <param name="pwd"></param>
        /// <param name="applyType"></param>
        /// <returns></returns>
        public object PostApplyWithDraw(MemberCapitalApplyWithDrawModel para)
        {
            CheckUserLogin();
            if (para == null)
            {
                para = new MemberCapitalApplyWithDrawModel();
            }
            if (string.IsNullOrEmpty(para.pwd))
            {
                throw new HimallException("请输入密码!");
            }
            if (para.amount <= 0)
            {
                throw new HimallException("提现金额不能小于等于0!");
            }
            var success     = MemberApplication.VerificationPayPwd(CurrentUser.Id, para.pwd);
            var sitesetting = SiteSettingApplication.SiteSettings;

            if (para.applyType == CommonModel.UserWithdrawType.ALiPay.GetHashCode() && !sitesetting.Withdraw_AlipayEnable)
            {
                throw new HimallException("不支持支付宝提现方式!");
            }
            var _iMemberCapitalService = ServiceApplication.Create <IMemberCapitalService>();

            if (!success)
            {
                throw new HimallException("支付密码不对,请重新输入!");
            }
            var balance = MemberCapitalApplication.GetBalanceByUserId(CurrentUser.Id);

            if (para.amount > balance)
            {
                throw new HimallException("提现金额不能超出可用金额!");
            }

            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())
            {
                throw new HimallException("数据异常,真实姓名不可为空!");
            }
            if (!string.IsNullOrWhiteSpace(para.openid) && para.applyType == CommonModel.UserWithdrawType.WeiChat.GetHashCode())
            {
                //para.openid = Core.Helper.SecureHelper.AESDecrypt(para.openid, "Mobile");
                if (!(string.IsNullOrWhiteSpace(sitesetting.WeixinAppId) || string.IsNullOrWhiteSpace(sitesetting.WeixinAppSecret)))
                {
                    string token    = AccessTokenContainer.TryGetToken(sitesetting.WeixinAppId, sitesetting.WeixinAppSecret);
                    var    userinfo = Senparc.Weixin.MP.CommonAPIs.CommonApi.GetUserInfo(token, para.openid);
                    if (userinfo != null)
                    {
                        para.nickname = userinfo.nickname;
                    }
                }
            }
            if (string.IsNullOrWhiteSpace(para.openid))
            {
                throw new HimallException("数据异常,OpenId或收款账号不可为空!");
            }

            Himall.Entities.ApplyWithDrawInfo model = new Himall.Entities.ApplyWithDrawInfo()
            {
                ApplyAmount = para.amount,
                ApplyStatus = Himall.Entities.ApplyWithDrawInfo.ApplyWithDrawStatus.WaitConfirm,
                ApplyTime   = DateTime.Now,
                MemId       = CurrentUser.Id,
                OpenId      = para.openid,
                NickName    = para.nickname,
                ApplyType   = (CommonModel.UserWithdrawType)para.applyType
            };
            _iMemberCapitalService.AddWithDrawApply(model);
            return(SuccessResult());
        }