/// <summary>
        /// 申请提现
        /// </summary>
        /// <param name="post"></param>
        /// <returns></returns>
        public JsonResult <Result <bool> > PostWithdraw(DistributionApplyWithdraw post)
        {
            CheckUserLogin();
            var sitesettings = SiteSettingApplication.SiteSettings;

            post.MemberId = CurrentUser.Id;
            if (post.Type == DistributionWithdrawType.WeChat) //获取用户微信账户
            {
                var mo = MemberApplication.GetMemberOpenIdInfoByuserId(CurrentUser.Id, Entities.MemberOpenIdInfo.AppIdTypeEnum.Payment, "Himall.Plugin.OAuth.WeiXin");
                if (mo == null)
                {
                    return(Json(ErrorResult <bool>("无法获取微信账号,请先在微信端绑定账号!")));
                }
                var openid = mo.OpenId;
                post.WithdrawAccount = openid;
                if (!(string.IsNullOrWhiteSpace(sitesettings.WeixinAppId) || string.IsNullOrWhiteSpace(sitesettings.WeixinAppSecret)))
                {
                    string token = AccessTokenContainer.TryGetToken(sitesettings.WeixinAppId, sitesettings.WeixinAppSecret);
                    var    user  = CommonApi.GetUserInfo(token, openid);
                    post.WithdrawName = user?.nickname ?? string.Empty;
                }
            }
            DistributionApplication.ApplyWithdraw(post);
            return(JsonResult(true));
        }
 public ActionResult PostWithdraw(DistributionApplyWithdraw post)
 {
     post.MemberId = CurrentUser.Id;
     if (post.Type == DistributionWithdrawType.WeChat) //获取用户微信账户
     {
         var openid = WebHelper.GetCookie(CookieKeysCollection.Mall_USER_OpenID);
         post.WithdrawAccount = openid = SecureHelper.AESDecrypt(openid, "Mobile");
         if (!(string.IsNullOrWhiteSpace(SiteSettings.WeixinAppId) || string.IsNullOrWhiteSpace(SiteSettings.WeixinAppSecret)))
         {
             string token = AccessTokenContainer.TryGetAccessToken(SiteSettings.WeixinAppId, SiteSettings.WeixinAppSecret);
             var    user  = CommonApi.GetUserInfo(token, openid);
             post.WithdrawName = user?.nickname ?? string.Empty;
         }
     }
     DistributionApplication.ApplyWithdraw(post);
     return(Json(new { success = true }, true));
 }
Exemple #3
0
        /// <summary>
        /// 提现申请
        /// </summary>
        /// <param name="apply"></param>
        public static void ApplyWithdraw(DistributionApplyWithdraw apply)
        {
            if (!MemberApplication.VerificationPayPwd(apply.MemberId, apply.Password))
            {
                throw new MallException("交易密码错误");
            }

            if (apply.Amount > SiteSettingApplication.SiteSettings.DistributorWithdrawMaxLimit)
            {
                throw new MallException("超过最大提现额限");
            }

            if (apply.Amount < SiteSettingApplication.SiteSettings.DistributorWithdrawMinLimit)
            {
                throw new MallException("小于最低提现额限");
            }

            var distributor = Service.GetDistributor(apply.MemberId);

            if (apply.Amount > distributor.Balance)
            {
                throw new MallException("超过最多提现金额");
            }

            var settings = SiteSettingApplication.SiteSettings;

            if (apply.Type == DistributionWithdrawType.Alipay)
            {
                if (!settings.DistributorWithdrawTypes.ToLower().Contains("alipay"))
                {
                    throw new MallException("暂不支持支付宝提现");
                }
                if (string.IsNullOrEmpty(apply.WithdrawAccount))
                {
                    throw new MallException("支付宝账户不可为空");
                }
                if (string.IsNullOrEmpty(apply.WithdrawName))
                {
                    throw new MallException("真实姓名不可为空");
                }
            }
            else if (apply.Type == DistributionWithdrawType.WeChat)
            {
                if (!settings.DistributorWithdrawTypes.ToLower().Contains("wechat"))
                {
                    throw new MallException("暂不支持微信提现");
                }
                if (string.IsNullOrEmpty(apply.WithdrawAccount))
                {
                    throw new MallException("尚未绑定微信,请先绑定微信账户");
                }
            }

            var info = new DistributionWithdrawInfo
            {
                Amount          = apply.Amount,
                WithdrawType    = apply.Type,
                MemberId        = apply.MemberId,
                WithdrawAccount = apply.WithdrawAccount,
                WithdrawName    = apply.WithdrawName
            };

            Service.ApplyWithdraw(info);

            //发送消息
            var member  = MemberApplication.GetMember(apply.MemberId);
            var message = new MessageWithDrawInfo();

            message.UserName  = member != null ? member.UserName : "";
            message.Amount    = info.Amount;
            message.ApplyType = info.WithdrawType.GetHashCode();
            message.ApplyTime = info.ApplyTime;
            message.Remark    = info.Remark;
            message.SiteName  = SiteSettingApplication.SiteSettings.SiteName;
            Task.Factory.StartNew(() => MessageApplication.SendMessageOnDistributionMemberWithDrawApply(apply.MemberId, message));

            //预付款提现,自动审核
            if (info.WithdrawType == DistributionWithdrawType.Capital)
            {
                AuditingWithdraw(info.Id, "System", "预存款提现,自动审核");
            }
        }