Beispiel #1
0
        public ActionResult Add(UserRankModel model)
        {
            if (AdminUserRanks.GetUserRidByTitle(model.UserRankTitle) > 0)
            {
                ModelState.AddModelError("UserRankTitle", "名称已经存在");
            }

            if (ModelState.IsValid)
            {
                UserRankInfo userRankInfo = new UserRankInfo()
                {
                    System       = 0,
                    Title        = model.UserRankTitle,
                    Avatar       = model.Avatar ?? "",
                    CreditsLower = model.CreditsLower,
                    CreditsUpper = model.CreditsUpper,
                    LimitDays    = 0
                };

                AdminUserRanks.CreateUserRank(userRankInfo);
                AddMallAdminLog("添加会员等级", "添加会员等级,会员等级为:" + model.UserRankTitle);
                return(PromptView("会员等级添加成功"));
            }
            Load();
            return(View(model));
        }
        /// <summary>
        /// 订阅宝SSO登录
        /// </summary>
        public ActionResult DybLogin()
        {
            try
            {
                LogUtil.WriteLog($"开始登陆 url:{WebHelper.GetRawUrl()}");
                if (WorkContext.Uid > 0)
                {
                    WebHelper.DeleteCookie("bma");
                    Sessions.RemoverSession(WorkContext.Sid);
                    OnlineUsers.DeleteOnlineUserBySid(WorkContext.Sid);
                }
                string username    = WebHelper.GetQueryString("username");
                string agentname   = WebHelper.GetQueryString("agentname");
                string redirectUrl = WebHelper.GetQueryString("redirect");
                string ak          = WebHelper.GetQueryString("ak");
                if (string.IsNullOrEmpty(username))
                {
                    return(PromptView("该单点登录链接缺少用户信息"));
                }

                var storepid = 0;
                if (!string.IsNullOrEmpty(agentname))
                {
                    var agentUid = OAuths.GetUidByOpenIdAndServer(agentname, "dyb");
                    if (agentUid > 0)
                    {
                        var agentUser = Users.GetPartUserById(agentUid);
                        storepid = agentUser.StoreId;
                    }
                }
                var uid = OAuths.GetUidByOpenIdAndServer(username, "dyb");
                if (uid < 1)
                {
                    //创建用户
                    var userInfo = OAuths.CreateOAuthUser(DateTime.Now.ToString("yyMMddHHmmssms"), "dyb", username, "dyb",
                                                          WorkContext.RegionId);
                    uid = userInfo.Uid;
                }
                var partUserInfo = Users.GetPartUserById(uid);
                if (partUserInfo.StoreId == 0)
                {
                    //创建店铺
                    var storeId = AdminStores.CreateStore(new StoreInfo
                    {
                        Announcement = "",
                        Banner       = "",
                        CreateTime   = DateTime.Now,
                        DePoint      = 10,
                        Description  = "",
                        Honesties    = 0,
                        Logo         = "",
                        Mobile       = "",
                        Name         = "微信小程序",
                        Phone        = "",
                        QQ           = "",
                        RegionId     = 0,
                        SePoint      = 10,
                        ShPoint      = 10,
                        State        = 0,
                        StateEndTime = DateTime.Now.AddYears(1),
                        StoreIid     = 0,
                        StoreRid     = 1,
                        Theme        = "default",
                        WW           = "",
                        StorePid     = storepid
                    }, new StoreKeeperInfo
                    {
                        Address = username,
                        IdCard  = username,
                        Name    = partUserInfo.UserName,
                        Type    = 0
                    });

                    AdminStores.CreateStoreShipTemplate(new StoreShipTemplateInfo
                    {
                        Free    = 1,
                        StoreId = storeId,
                        Title   = "全场包邮",
                        Type    = 0
                    });

                    //创建会员等级
                    AdminUserRanks.CreateUserRank(new UserRankInfo
                    {
                        Avatar       = string.Empty,
                        CreditsLower = 0,
                        CreditsUpper = -1,
                        LimitDays    = 0,
                        StoreId      = storeId,
                        System       = 0,
                        Title        = "初级会员"
                    });
                    partUserInfo.StoreId = storeId;
                    partUserInfo.UserRid = UserRanks.GetLowestUserRank(storeId).UserRid;
                    WorkContext.StoreId  = storeId;

                    Users.UpdatePartUser(partUserInfo);
                }
                //如果对应的店铺没有平台ID,则可以更改storepid,否则不行
                if (storepid > 0)
                {
                    var store = Stores.GetStoreById(partUserInfo.StoreId);
                    if (store != null && store.StorePid == 0 && store.StoreId != storepid)
                    {
                        AdminStores.UpdateStorePId(store.StoreId, storepid);
                    }
                }

                //将用户信息写入cookie中
                MallUtils.SetUserCookie(partUserInfo, 365);
                StoreInfoManager.UpdateDistributor(partUserInfo.StoreId,
                                                   ak.Equals("dis", StringComparison.InvariantCultureIgnoreCase));
                LogUtil.WriteLog($"开始登陆 开始跳转");
                if (string.IsNullOrEmpty(redirectUrl))
                {
                    return(RedirectToAction("index", "home", new RouteValueDictionary {
                        { "area", "storeadmin" }
                    }));
                }
                else
                {
                    return(Redirect(redirectUrl));
                }
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                throw;
            }
        }