public ActionResult SendBag()
        {
            if (WorkContext.UserLevel <= 0)
            {
                return(PromptView("请先提升您的等级!"));
            }
            Core.BLL.SendBag sendBll = new Core.BLL.SendBag();

            if (WebHelper.IsGet())
            {
                int type  = WebHelper.GetQueryInt("Sendtype", 1);
                int page  = WebHelper.GetQueryInt("page");
                int count = 0;

                List <Core.Model.SendBag> list = sendBll.GetModelList(20, page, " Receiverid=" + WorkContext.Uid + " and status=0 and Sendtype=" + type, "id", out count);
                PageModel    pageModel         = new PageModel(20, page, count);
                SendBagModel model             = new SendBagModel
                {
                    PageModel   = pageModel,
                    SendBagList = list,
                    Sendtype    = type
                };
                return(View(model));
            }
            else
            {
                try
                {
                    lock (this)
                    {
                        WeiXinConfig wxconfig = BMAConfig.WeiXinConfig;
                        int          sendid   = WebHelper.GetFormInt("sendid");
                        List <Core.Model.SendBag> listsendbag = sendBll.GetModelList(" status=0 and id=" + sendid);
                        if (listsendbag.Count > 0 && listsendbag[0].ReceiverID == WorkContext.Uid)
                        {
                            string Noncestr = "";
                            string paysign  = "";
                            try
                            {
                                int bcount = sendBll.GetRecordCount(" status=1 and ReceiverID=" + WorkContext.Uid + " and sendtype=" + WorkContext.UserLevel);
                                if (WorkContext.UserLevel == 1)
                                {
                                    if (bcount >= 3)
                                    {
                                        return(AjaxResult("error", "您领取的红包已达到上限,请先提升您的等级!"));
                                    }
                                }
                                if (WorkContext.UserLevel == 2)
                                {
                                    if (bcount >= 9)
                                    {
                                        return(AjaxResult("error", "您领取的红包已达到上限,请先提升您的等级!"));
                                    }
                                }

                                if (listsendbag[0].IsNotSend == 0)
                                {
                                    NormalRedPackResult nop = RedPackApi.SendNormalRedPack(listsendbag[0].Mchbillno, wxconfig.AppID, wxconfig.Mch_id, wxconfig.PartnerKey, Server.MapPath(wxconfig.SSLCERT_PATH), WorkContext.Openid, "创梦星火", wxconfig.Spbill_create_ip, listsendbag[0].Pice.Value * 100,
                                                                                           "更上一层楼", "创梦帮扶活动", "祝您更上一层楼", out Noncestr, out paysign);

                                    if (nop.err_code_des == "")
                                    {
                                        listsendbag[0].Status   = 1;
                                        listsendbag[0].SendTime = DateTime.Now;
                                        sendBll.Update(listsendbag[0]);
                                        return(AjaxResult("success", "发送成功"));
                                    }
                                    else
                                    {
                                        return(AjaxResult("error", nop.err_code_des));
                                    }
                                }
                                else
                                {
                                    return(AjaxResult("error", "该红包处于冻结状态,暂时无法领取."));
                                }
                            }
                            catch (Exception ex)
                            {
                                return(AjaxResult("error", ex.ToString()));
                            }
                        }
                        else
                        {
                            return(AjaxResult("error", "红包不存在或已发送"));
                        }
                    }
                }
                catch (Exception ex)
                {
                    return(AjaxResult("error", ex.ToString()));
                }
            }
        }
Exemple #2
0
        public ActionResult SendBagList(string userName = "", int sentype = 0, int pageNumber = 1, int status = -1, int pageSize = 15)
        {
            StringBuilder sbwhere = new StringBuilder();

            sbwhere.Append(" 1=1 ");
            if (userName != "")
            {
                sbwhere.AppendFormat(" and ( username like '%{0}%' or userno like '%{0}%') ", userName);
            }
            List <SelectListItem> sentypeList = new List <SelectListItem>();

            sentypeList.Add(new SelectListItem()
            {
                Text = "全部", Value = "0"
            });
            sentypeList.Add(new SelectListItem()
            {
                Text = "1级", Value = "1"
            });
            sentypeList.Add(new SelectListItem()
            {
                Text = "2级", Value = "2"
            });
            sentypeList.Add(new SelectListItem()
            {
                Text = "3级", Value = "3"
            });
            List <SelectListItem> statusList = new List <SelectListItem>();

            statusList.Add(new SelectListItem()
            {
                Text = "全部", Value = "-1"
            });
            statusList.Add(new SelectListItem()
            {
                Text = "未领取", Value = "0"
            });
            statusList.Add(new SelectListItem()
            {
                Text = "已领取", Value = "1"
            });
            if (sentype > 0)
            {
                sbwhere.AppendFormat(" and Sendtype={0} ", sentype);
            }
            if (status >= 0)
            {
                sbwhere.AppendFormat(" and status={0} ", status);
            }
            int count = 0;

            Core.BLL.SendBag          BagBll  = new Core.BLL.SendBag();
            List <Core.Model.SendBag> Baglist = BagBll.GetModelListByS(pageSize, pageNumber, sbwhere.ToString(), "id desc", out count);
            PageModel        pageModel        = new PageModel(pageSize, pageNumber, count);
            SendBagListModel model            = new SendBagListModel()
            {
                SBagList    = Baglist,
                PageModel   = pageModel,
                Sentype     = sentype,
                Status      = status,
                PageNumber  = pageNumber,
                sentypeList = sentypeList,
                statusList  = statusList,
                UserName    = userName
            };

            return(View(model));
        }
        protected override void Initialize(RequestContext requestContext)
        {
            base.Initialize(requestContext);
            this.ValidateRequest = false;

            WorkContext.IsHttpAjax  = WebHelper.IsAjax();
            WorkContext.IP          = WebHelper.GetIP();
            WorkContext.RegionInfo  = Regions.GetRegionByIP(WorkContext.IP);
            WorkContext.RegionId    = WorkContext.RegionInfo.RegionId;
            WorkContext.Url         = WebHelper.GetUrl();
            WorkContext.UrlReferrer = WebHelper.GetUrlReferrer();

            //获得用户唯一标示符sid
            WorkContext.Sid    = MallUtils.GetSidCookie();
            WorkContext.Openid = "";
            if (WorkContext.Sid.Length == 0)
            {
                //生成sid
                WorkContext.Sid = Sessions.GenerateSid();
                //将sid保存到cookie中
                MallUtils.SetSidCookie(WorkContext.Sid);
            }

            PartUserInfo partUserInfo;

            //获得用户id
            int uid = MallUtils.GetUidCookie();

            if (uid < 1)//当用户为游客时
            {
                //创建游客
                partUserInfo = Users.CreatePartGuest();
                BrnMall.Core.WeiXinConfig wxconfig = BrnMall.Core.BMAConfig.WeiXinConfig;
                #region 获取用户openid
                //if (Request.QueryString["code"] == null)
                //{
                //    string host = Request.Url.Host;
                //    string path = Request.Path;
                //    string url = string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect", wxconfig.AppID, System.Web.HttpUtility.UrlEncode("http://" + host + path));

                //    Response.Redirect(url);
                //}
                //else
                //{

                //    //BrnMall.Core.WeiXinConfig wxconfig = BrnMall.Core.BMAConfig.WeiXinConfig;
                //    string code = Request.QueryString["code"];//获取授权code
                //                                              // string openIdUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + wxconfig.AppID + "&secret=" + wxconfig.AppSecret + "&code=" + code + "&grant_type=authorization_code";
                //    string openIdUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + wxconfig.AppID + "&secret=" + wxconfig.AppSecret + "&code=" + code + "&grant_type=authorization_code";
                //    string content = "";
                //    try
                //    {
                //        content = BrnMall.Core.WeiXinHelp.GetPage(openIdUrl, "");

                //    }
                //    catch
                //    {
                //        Response.Write("code:" + code + "这边错了");
                //    }

                //    string openid = "";//根据授权  获取当前人的openid
                //    try
                //    {
                //        openid = BrnMall.Core.WeiXinHelp.GetJsonValue(content, "openid");

                //    }
                //    catch
                //    {
                //        Response.Write("code:" + code + "||||content" + content);
                //    }
                //    Senparc.Weixin.MP.AdvancedAPIs.User.UserInfoJson dic = null;

                //    dic = Senparc.Weixin.MP.AdvancedAPIs.UserApi.Info(WeiXinHelp.IsExistAccess_Token2(), openid);

                //    if (dic.subscribe == 1)
                //    {
                //        //获取用户
                //        //try
                //        //{
                //        //BMALog.Instance.Write("openid:" + openid);
                //        partUserInfo = Users.GetPartUserByOpenid(openid);

                //        if (partUserInfo != null)
                //        {


                //            MallUtils.SetUserCookie(partUserInfo, 30);
                //            //WorkContext.EncryptPwd= MallUtils.GetCookiePassword();
                //        }
                //        else//不存在
                //        {
                //            //partUserInfo = Users.CreatePartGuest();
                //            //WorkContext.EncryptPwd = string.Empty;
                //            //MallUtils.SetUidCookie(-1);
                //            //MallUtils.SetCookiePassword("");
                //            UserInfo userinfo = new UserInfo();

                //            userinfo.Pid = 3;
                //            userinfo.Openid = dic.openid;
                //            userinfo.NickName = dic.nickname;
                //            userinfo.UserName = dic.nickname;
                //            userinfo.Password = Users.CreateUserPassword("Migewan123", "1");
                //            userinfo.Avatar = dic.headimgurl;
                //            userinfo.UserLevel = 0;
                //            userinfo.PayCredits = 0;
                //            userinfo.RankCredits = 0;
                //            userinfo.VerifyEmail = 0;
                //            userinfo.VerifyMobile = 0;
                //            userinfo.Salt = Randoms.CreateRandomValue(6);
                //            userinfo.LastVisitIP = WebHelper.GetIP();
                //            userinfo.MallAGid = 1;//非管理员组
                //                                  //userinfo.LastVisitRgId = Regions.GetRegionByIP(userinfo.LastVisitIP);
                //            userinfo.LastVisitTime = DateTime.Now;
                //            userinfo.RegisterIP = WebHelper.GetIP();

                //            userinfo.RegisterTime = DateTime.Now;
                //            Users.CreateUser(userinfo);
                //            partUserInfo = Users.GetPartUserByOpenid(openid);
                //            MallUtils.SetUserCookie(partUserInfo, 30);
                //        }
                //    }
                //}


                #endregion
                #region 测试
                ////string openid = "oD-R9wWHGhJ3rcRgX7sbU5W0s9sU";
                string openid = "oD-R9wbVoaX-B-7kmk7sz1nz_-bc";
                partUserInfo = Users.GetPartUserByOpenid(openid);
                if (partUserInfo != null)
                {
                    MallUtils.SetUserCookie(partUserInfo, 30);
                    //WorkContext.EncryptPwd= MallUtils.GetCookiePassword();
                }
                else//不存在
                {
                    partUserInfo           = Users.CreatePartGuest();
                    WorkContext.EncryptPwd = string.Empty;
                    MallUtils.SetUidCookie(-1);
                    MallUtils.SetCookiePassword("");
                }
                #endregion
            }
            else//当用户为会员时
            {
                //获得保存在cookie中的密码
                string encryptPwd = MallUtils.GetCookiePassword();
                //防止用户密码被篡改为危险字符
                if (encryptPwd.Length == 0 || !SecureHelper.IsBase64String(encryptPwd))
                {
                    //创建游客
                    partUserInfo = Users.CreatePartGuest();
                    encryptPwd   = string.Empty;
                    MallUtils.SetUidCookie(-1);
                    MallUtils.SetCookiePassword("");
                }
                else
                {
                    partUserInfo = Users.GetPartUserByUidAndPwd(uid, MallUtils.DecryptCookiePassword(encryptPwd));
                    if (partUserInfo != null)
                    {
                        //发放登陆积分
                        // Credits.SendLoginCredits(ref partUserInfo, DateTime.Now);
                    }
                    else//当会员的账号或密码不正确时,将用户置为游客
                    {
                        partUserInfo = Users.CreatePartGuest();
                        encryptPwd   = string.Empty;
                        MallUtils.SetUidCookie(-1);
                        MallUtils.SetCookiePassword("");
                    }
                }
                WorkContext.EncryptPwd = encryptPwd;
            }
            //try
            //{
            //设置用户等级
            if (UserRanks.IsBanUserRank(partUserInfo.UserRid) && partUserInfo.LiftBanTime <= DateTime.Now)
            {
                UserRankInfo userRankInfo = UserRanks.GetUserRankByCredits(partUserInfo.PayCredits);
                Users.UpdateUserRankByUid(partUserInfo.Uid, userRankInfo.UserRid);
                partUserInfo.UserRid = userRankInfo.UserRid;
            }

            //当用户被禁止访问时重置用户为游客
            if (partUserInfo.UserRid == 1)
            {
                partUserInfo           = Users.CreatePartGuest();
                WorkContext.EncryptPwd = string.Empty;
                MallUtils.SetUidCookie(-1);
                MallUtils.SetCookiePassword("");
            }
            //}
            //catch
            //{
            //    Response.Write("我的错");
            //}
            //try
            //{
            WorkContext.PartUserInfo = partUserInfo;
            WorkContext.Pid          = partUserInfo.Pid;
            WorkContext.Userno       = partUserInfo.Userno;
            WorkContext.UserLevel    = partUserInfo.UserLevel;
            WorkContext.Openid       = partUserInfo.Openid;
            WorkContext.Addtime      = partUserInfo.Addtime;
            WorkContext.IsReal       = partUserInfo.IsReal;


            WorkContext.Uid             = partUserInfo.Uid;
            WorkContext.UserName        = partUserInfo.UserName;
            WorkContext.UserEmail       = partUserInfo.Email;
            WorkContext.UserMobile      = partUserInfo.Mobile;
            WorkContext.Password        = partUserInfo.Password;
            WorkContext.NickName        = partUserInfo.NickName;
            WorkContext.Avatar          = partUserInfo.Avatar;
            WorkContext.PayCreditName   = Credits.PayCreditName;
            WorkContext.PayCreditCount  = partUserInfo.PayCredits;
            WorkContext.RankCreditName  = Credits.RankCreditName;
            WorkContext.RankCreditCount = partUserInfo.RankCredits;
            Core.BLL.SendBag bllsendbag = new Core.BLL.SendBag();
            //全部红包
            //WorkContext.CollarBag = bllsendbag.GetRecordSum(" Receiverid="+ partUserInfo.Uid );


            //已领红包
            WorkContext.NoCollarBag = bllsendbag.GetRecordSum(" Receiverid=" + partUserInfo.Uid + " and Status=0");;
            //未领红包
            WorkContext.HaCollarBag  = 0;
            WorkContext.UserRid      = partUserInfo.UserRid;
            WorkContext.UserRankInfo = UserRanks.GetUserRankById(partUserInfo.UserRid);
            //WorkContext.UserRTitle = WorkContext.UserRankInfo.Title;
            switch (WorkContext.UserLevel)
            {
            case 1:
                WorkContext.UserRTitle = "银卡会员";
                break;

            case 2:
                WorkContext.UserRTitle = "金卡会员";
                break;

            case 3:
                WorkContext.UserRTitle = "钻石会员";
                break;

            default:
                WorkContext.UserRTitle = "普通会员";
                break;
            }
            //设置用户商城管理员组
            WorkContext.MallAGid           = partUserInfo.MallAGid;
            WorkContext.MallAdminGroupInfo = MallAdminGroups.GetMallAdminGroupById(partUserInfo.MallAGid);
            WorkContext.MallAGTitle        = WorkContext.MallAdminGroupInfo.Title;

            //设置当前控制器类名
            WorkContext.Controller = RouteData.Values["controller"].ToString().ToLower();
            //设置当前动作方法名
            WorkContext.Action  = RouteData.Values["action"].ToString().ToLower();
            WorkContext.PageKey = string.Format("/{0}/{1}", WorkContext.Controller, WorkContext.Action);

            WorkContext.ImageCDN  = WorkContext.MallConfig.ImageCDN;
            WorkContext.CSSCDN    = WorkContext.MallConfig.CSSCDN;
            WorkContext.ScriptCDN = WorkContext.MallConfig.ScriptCDN;

            //在线总人数
            WorkContext.OnlineUserCount = OnlineUsers.GetOnlineUserCount();
            //在线游客数
            WorkContext.OnlineGuestCount = OnlineUsers.GetOnlineGuestCount();
            //在线会员数
            WorkContext.OnlineMemberCount = WorkContext.OnlineUserCount - WorkContext.OnlineGuestCount;
            //搜索词
            WorkContext.SearchWord = string.Empty;
            //购物车中商品数量
            WorkContext.CartProductCount = Carts.GetCartProductCountCookie();
            //}
            //catch (Exception ex)
            //{
            //    Response.Write("赋值时:"+ex.ToString());
            //}
        }