예제 #1
0
        public ActionResult NotStart(long id)  //未开始
        {
            ShopBonusModel model = new ShopBonusModel(this._bonusService.GetShopBonus(id));

            model.ShareImg = CurrentUrlHelper.CurrentUrlNoPort() + model.ShareImg;
            return(View(model));
        }
예제 #2
0
        public ActionResult Completed(long id, string openId = "", [DecimalConstant(0, 0, 0, 0, 0)] decimal price = default(decimal), string user = "", long grantid = 0L, long rid = 0L, string wxhead = "", string host = "")
        {
            SetShareData();
            ShopBonusModel shopBonusModel = new ShopBonusModel(_bonusService.Get(id));

            ViewBag.GrantId          = grantid;
            ViewBag.ShareHref        = string.Concat(host, "/m-weixin/shopbonus/index/", grantid.ToString());
            ViewBag.HeadImg          = wxhead;
            ViewBag.ShopAddress      = GetShopAddress(shopBonusModel.ShopId);
            ViewBag.UserName         = user;
            ViewBag.Price            = price;
            ViewBag.HighPrice        = price + 60;
            ViewBag.OpenId           = openId;
            ViewBag.ShopName         = ServiceHelper.Create <IShopService>().GetShopName(shopBonusModel.ShopId);
            shopBonusModel.ShareImg  = string.Concat("http://", host, shopBonusModel.ShareImg);
            shopBonusModel.ReceiveId = rid;
            if (shopBonusModel.SynchronizeCard && base.PlatformType == Himall.Core.PlatformType.WeiXin)
            {
                shopBonusModel.WXJSInfo = ser_wxcard.GetSyncWeiXin(id, rid, ThisCouponType, base.Request.Url.AbsoluteUri);
                if (shopBonusModel.WXJSInfo != null)
                {
                    shopBonusModel.IsShowSyncWeiXin = true;
                }
            }
            return(View(shopBonusModel));
        }
예제 #3
0
        public ActionResult Edit(long id)
        {
            var            obj   = this._bonusService.GetShopBonus(id);
            ShopBonusModel model = new ShopBonusModel(obj);

            return(View(model));
        }
예제 #4
0
        public ActionResult NotStart(long id)
        {
            ShopBonusModel shopBonusModel = new ShopBonusModel(_bonusService.Get(id));

            shopBonusModel.ShareImg = string.Concat("http://", base.Request.Url.Host.ToString(), shopBonusModel.ShareImg);
            return(View(shopBonusModel));
        }
예제 #5
0
        public ActionResult NotStart(long id)  //未开始
        {
            ShopBonusModel model = new ShopBonusModel(this._bonusService.Get(id));

            model.ShareImg = "http://" + Request.Url.Host.ToString() + model.ShareImg;
            return(View(model));
        }
예제 #6
0
        public ActionResult EditData(ShopBonusModel model)
        {
            var market = this._bonusService.GetShopBonusService(CurrentSellerManager.ShopId);
            var time   = ((Himall.Model.ActiveMarketServiceInfo)market).MarketServiceRecordInfo.Max(a => a.EndTime);

            if (model.BonusDateEnd > time || model.DateEnd > time)
            {
                throw new HimallException("随机红包截止日期不允许超过您购买的服务到期时间。");
            }
            if (model.Count < 1 || model.Count > 1000)
            {
                throw new HimallException("红包个数请控制在1-1000个!");
            }
            string image     = model.ShareImg;
            string imageName = Guid.NewGuid().ToString() + ".png";
            string moveDir   = "/Storage/Shop/Bonus/";

            if (image.Contains("/temp/"))
            {
                var source = image.Substring(image.LastIndexOf("/temp"));
                Core.HimallIO.CopyFile(source, moveDir + imageName);
                model.ShareImg = "/Storage/Shop/Bonus/" + imageName;
            }
            else if (image.Contains("/Storage/"))
            {
                model.ShareImg = image.Substring(image.LastIndexOf("/Storage/"));
            }
            else
            {
                model.ShareImg = "";
            }
            this._bonusService.Update(model);
            return(RedirectToAction("Management"));
        }
예제 #7
0
        public ActionResult Expired(long id, string openId = "", long grantid = 0L, string wxhead = "")
        {
            ViewBag.GrantId = grantid;
            ViewBag.HeadImg = wxhead;
            ShopBonusModel shopBonusModel = new ShopBonusModel(_bonusService.Get(id));

            ViewBag.ShopAddress     = GetShopAddress(shopBonusModel.ShopId);
            shopBonusModel.ShareImg = string.Concat("http://", base.Request.Url.Host.ToString(), shopBonusModel.ShareImg);
            return(View(shopBonusModel));
        }
예제 #8
0
        public ActionResult EditData(ShopBonusModel model)
        {
            ActiveMarketServiceInfo shopBonusService = _bonusService.GetShopBonusService(base.CurrentSellerManager.ShopId);
            DateTime dateTime = shopBonusService.MarketServiceRecordInfo.Max <MarketServiceRecordInfo, DateTime>((MarketServiceRecordInfo a) => a.EndTime);

            if (model.BonusDateEnd > dateTime || model.DateEnd > dateTime)
            {
                throw new HimallException("随机红包截止日期不允许超过您购买的服务到期时间。");
            }
            _bonusService.Update(model);
            return(RedirectToAction("Management"));
        }
예제 #9
0
        public ActionResult Expired(long id, string openId = "", long grantid = 0, string wxhead = "")  //已过期
        {
            ShopBonusDataModel dataModel = new ShopBonusDataModel();

            dataModel.GrantId = grantid;
            dataModel.HeadImg = wxhead;
            ShopBonusModel model = new ShopBonusModel(this._bonusService.Get(id));

            dataModel.ShopAddress = GetShopAddress(model.ShopId);
            ViewBag.DataModel     = dataModel;
            model.ShareImg        = "http://" + Request.Url.Host.ToString() + model.ShareImg;
            return(View(model));
        }
예제 #10
0
        public ActionResult Expired(long id, string openId = "", long grantid = 0, string wxhead = "")  //已过期
        {
            ShopBonusDataModel dataModel = new ShopBonusDataModel();

            dataModel.GrantId = grantid;
            dataModel.HeadImg = wxhead;
            ShopBonusModel model = new ShopBonusModel(this._bonusService.GetShopBonus(id));

            dataModel.ShopAddress = GetShopAddress(model.ShopId);
            ViewBag.DataModel     = dataModel;
            model.ShareImg        = CurrentUrlHelper.CurrentUrlNoPort() + model.ShareImg;
            return(View(model));
        }
예제 #11
0
        public ActionResult HasReceive(long id, string openId = "", long grantid = 0L, string wxhead = "", string host = "")
        {
            SetShareData();
            ViewBag.GrantId   = grantid;
            ViewBag.ShareHref = string.Concat(host, "/m-weixin/shopbonus/index/", grantid.ToString());
            ViewBag.OpenId    = openId;
            ViewBag.HeadImg   = wxhead;
            ShopBonusModel shopBonusModel = new ShopBonusModel(_bonusService.Get(id));

            ViewBag.ShopAddress     = GetShopAddress(shopBonusModel.ShopId);
            shopBonusModel.ShareImg = string.Concat("http://", host, shopBonusModel.ShareImg);
            return(View(shopBonusModel));
        }
예제 #12
0
        public ActionResult Add(ShopBonusModel model)
        {
            string image     = model.ShareImg;
            string imageName = Guid.NewGuid().ToString() + ".png";
            string moveDir   = "/Storage/Shop/Bonus/";

            if (image.Contains("/temp/"))
            {
                var source = image.Substring(image.LastIndexOf("/temp"));
                Core.HimallIO.CopyFile(source, moveDir + imageName, true);
                model.ShareImg = "/Storage/Shop/Bonus/" + imageName;
            }
            else
            {
                model.ShareImg = "";
            }
            var market = this._bonusService.GetShopBonusService(CurrentSellerManager.ShopId);
            var time   = MarketApplication.GetServiceEndTime(market.Id);

            if (model.BonusDateEnd > time || model.DateEnd > time)
            {
                throw new HimallException("随机红包截止日期不允许超过您购买的服务到期时间。");
            }
            if (model.Count < 1 || model.Count > 1000)
            {
                throw new HimallException("红包个数请控制在1-1000个!");
            }
            if (model.IsShowSyncWeiXin && string.IsNullOrWhiteSpace(model.CardTitle))
            {
                throw new HimallException("同步卡券时,请填写卡券必填项");
            }
            if (!string.IsNullOrWhiteSpace(model.CardTitle))
            {
                //判断字符长度
                var enc = System.Text.Encoding.Default;
                if (enc.GetBytes(model.CardTitle).Count() > 18)
                {
                    throw new HimallException("卡券标题不得超过9个汉字。");
                }
                if (!string.IsNullOrWhiteSpace(model.CardSubtitle))
                {
                    if (enc.GetBytes(model.CardSubtitle).Count() > 36)
                    {
                        throw new HimallException("卡券副标题不得超过18个汉字。");
                    }
                }
            }
            this._bonusService.Add(model, CurrentSellerManager.ShopId);
            return(RedirectToAction("Management"));
        }
예제 #13
0
        public ActionResult HasReceive(long id, string openId = "", long grantid = 0, string wxhead = "", string host = "")  //已领取过
        {
            ShopBonusDataModel dataModel = new ShopBonusDataModel();

            dataModel.GrantId   = grantid;
            dataModel.ShareHref = host + "/m-weixin/shopbonus/index/" + grantid.ToString();
            dataModel.OpenId    = openId;
            dataModel.HeadImg   = wxhead;
            ShopBonusModel model = new ShopBonusModel(this._bonusService.Get(id));

            dataModel.ShopAddress = GetShopAddress(model.ShopId);
            ViewBag.DataModel     = dataModel;
            model.ShareImg        = "http://" + host + model.ShareImg;
            return(View(model));
        }
예제 #14
0
        public ActionResult EditData(ShopBonusModel datamodel)
        {
            var market  = this._bonusService.GetShopBonusService(CurrentSellerManager.ShopId);
            var olddata = _bonusService.GetShopBonus(datamodel.Id);

            Mapper.CreateMap <Entities.ShopBonusInfo, ShopBonusModel>();
            ShopBonusModel model = Mapper.Map <Entities.ShopBonusInfo, ShopBonusModel>(olddata);

            UpdateModel(model);
            if (olddata == null)
            {
                throw new HimallException("错误的参数!");
            }
            var time = MarketApplication.GetServiceEndTime(market.Id);

            if (model.BonusDateEnd > time || model.DateEnd > time)
            {
                throw new HimallException("随机红包截止日期不允许超过您购买的服务到期时间。");
            }
            if (model.Count < 1 || model.Count > 1000)
            {
                throw new HimallException("红包个数请控制在1-1000个!");
            }
            string image     = model.ShareImg;
            string imageName = Guid.NewGuid().ToString() + ".png";
            string moveDir   = "/Storage/Shop/Bonus/";

            if (image.Contains("/temp/"))
            {
                var source = image.Substring(image.LastIndexOf("/temp"));
                Core.HimallIO.CopyFile(source, moveDir + imageName);
                model.ShareImg = "/Storage/Shop/Bonus/" + imageName;
            }
            else if (image.Contains("/Storage/"))
            {
                model.ShareImg = image.Substring(image.LastIndexOf("/Storage/"));
            }
            else
            {
                model.ShareImg = "";
            }
            if (string.IsNullOrEmpty(model.QRPath))
            {
                model.QRPath = "";
            }
            this._bonusService.Update(model);
            return(RedirectToAction("Management"));
        }
예제 #15
0
        public ActionResult Add(ShopBonusModel model)
        {
            string mapPath  = IOHelper.GetMapPath(model.ShareImg);
            Guid   guid     = Guid.NewGuid();
            string str      = string.Concat(guid.ToString(), (new FileInfo(mapPath)).Extension);
            string mapPath1 = IOHelper.GetMapPath("/Storage/Shop/Bonus");

            if (!Directory.Exists(mapPath1))
            {
                Directory.CreateDirectory(mapPath1);
            }
            IOHelper.CopyFile(mapPath, mapPath1, false, str);
            model.ShareImg = string.Concat("/Storage/Shop/Bonus/", str);
            _bonusService.Add(model, base.CurrentSellerManager.ShopId);
            return(RedirectToAction("Management"));
        }
예제 #16
0
        public ActionResult Completed(long id, string openId = "", decimal price = 0, string user = "", long grantid = 0, long rid = 0, string wxhead = "", string host = "")
        {
            host = CurrentUrlHelper.CurrentUrl();
            ShopBonusDataModel dataModel = new ShopBonusDataModel();
            ShopBonusModel     model     = new ShopBonusModel(this._bonusService.GetShopBonus(id));
            var shop = ShopApplication.GetShop(model.ShopId);

            dataModel.GrantId   = grantid;
            dataModel.ShareHref = host + "/m-weixin/shopbonus/index/" + grantid.ToString();
            dataModel.HeadImg   = wxhead;
            //dataModel.HeadImg = Mall.Core.MallIO.GetImagePath(dataModel.HeadImg);
            dataModel.ShopAddress = GetShopAddress(model.ShopId);
            dataModel.UserName    = user;
            dataModel.Price       = price;
            dataModel.OpenId      = openId;
            dataModel.ShopName    = shop.ShopName;
            ViewBag.DataModel     = dataModel;
            model.ShareImg        = MallIO.GetRomoteImagePath(model.ShareImg);
            if (!string.IsNullOrWhiteSpace(model.ShareImg))
            {
                if (model.ShareImg.Substring(0, 4) != "http")
                {
                    model.ShareImg = host + model.ShareImg;
                }
            }
            model.ReceiveId = rid;

            #region  步微信前信息准备
            if (model.SynchronizeCard == true && this.PlatformType == PlatformType.WeiXin)
            {
                model.WXJSInfo = _iWXCardService.GetSyncWeiXin(id, rid, ThisCouponType, Request.GetDisplayUrl());
                if (model.WXJSInfo != null)
                {
                    model.IsShowSyncWeiXin = true;
                    //model.WXJSCardInfo = ser_wxcard.GetJSWeiXinCard(id, rid, ThisCouponType);    //同步方式有重复留的Bug
                }
            }
            #endregion

            return(View(model));
        }
예제 #17
0
        public ActionResult Index(long id)
        {
            ActionResult actionResult;

            Log.Info("进入ShopBonus Index");
            if (base.PlatformType != Himall.Core.PlatformType.WeiXin)
            {
                Log.Info(base.PlatformType.ToString());
                return(base.Content("只能在微信端访问"));
            }
            ShopBonusInfo byGrantId = _bonusService.GetByGrantId(id);

            if (byGrantId == null)
            {
                Log.Info(string.Concat("红包失踪,id = ", id));
                return(Redirect("/m-weixin/ShopBonus/Invalidtwo"));
            }
            string item = base.HttpContext.Request["code"];
            OAuthAccessTokenResult accessToken = null;

            if (string.IsNullOrEmpty(item))
            {
                string absoluteUri  = base.Request.Url.AbsoluteUri;
                string authorizeUrl = OAuthApi.GetAuthorizeUrl(_siteSetting.WeixinAppId.Trim(), absoluteUri, "STATE#wechat_redirect", OAuthScope.snsapi_userinfo, "code");
                return(Redirect(authorizeUrl));
            }
            try
            {
                accessToken = OAuthApi.GetAccessToken(_siteSetting.WeixinAppId.Trim(), _siteSetting.WeixinAppSecret.Trim(), item, "authorization_code");
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                actionResult = base.Content(((exception.InnerException == null ? exception : exception.InnerException)).Message);
                return(actionResult);
            }
            Log.Info("------------------------------");
            OAuthUserInfo  userInfo       = OAuthApi.GetUserInfo(accessToken.access_token, accessToken.openid, Language.zh_CN);
            ShopBonusModel shopBonusModel = new ShopBonusModel(byGrantId);

            if (shopBonusModel.DateEnd <= DateTime.Now || shopBonusModel.IsInvalid || shopBonusModel.BonusDateEnd <= DateTime.Now)
            {
                object[] objArray = new object[] { "/m-weixin/ShopBonus/Expired/", shopBonusModel.Id, "?openId=", accessToken.openid, "&grantid=", id, "&wxhead=", userInfo.headimgurl };
                return(Redirect(string.Concat(objArray)));
            }
            if (shopBonusModel.DateStart > DateTime.Now)
            {
                return(Redirect(string.Concat("/m-weixin/ShopBonus/NotStart/", shopBonusModel.Id)));
            }
            ShopReceiveModel shopReceiveModel = (ShopReceiveModel)_bonusService.Receive(id, userInfo.openid, userInfo.headimgurl, userInfo.nickname);

            Log.Info(string.Concat("获取State=", shopReceiveModel.State.ToString()));
            if (shopReceiveModel.State == ShopReceiveStatus.CanReceive)
            {
                object[] objArray1 = new object[] { "/m-weixin/ShopBonus/Completed/", shopBonusModel.Id, "?openId=", userInfo.openid, "&price=", shopReceiveModel.Price, "&user="******"&grantid=", id, "&rid=", shopReceiveModel.Id, "&wxhead=", userInfo.headimgurl, "&host=", base.Request.Url.Host };
                return(Redirect(string.Concat(objArray1)));
            }
            if (shopReceiveModel.State == ShopReceiveStatus.CanReceiveNotUser)
            {
                object[] objArray2 = new object[] { "/m-weixin/ShopBonus/CompletedNotUser/", shopBonusModel.Id, "?openId=", userInfo.openid, "&price=", shopReceiveModel.Price, "&grantid=", id, "&rid=", shopReceiveModel.Id, "&wxhead=", userInfo.headimgurl, "&host=", base.Request.Url.Host };
                return(Redirect(string.Concat(objArray2)));
            }
            if (shopReceiveModel.State == ShopReceiveStatus.Receive)
            {
                object[] objArray3 = new object[] { "/m-weixin/ShopBonus/HasReceive/", shopBonusModel.Id, "?openId=", userInfo.openid, "&grantid=", id, "&wxhead=", userInfo.headimgurl, "&host=", base.Request.Url.Host };
                return(Redirect(string.Concat(objArray3)));
            }
            if (shopReceiveModel.State == ShopReceiveStatus.HaveNot)
            {
                object[] objArray4 = new object[] { "/m-weixin/ShopBonus/HaveNot/", shopBonusModel.Id, "?openId=", userInfo.openid, "&grantid=", id, "&wxhead=", userInfo.headimgurl };
                return(Redirect(string.Concat(objArray4)));
            }
            if (shopReceiveModel.State != ShopReceiveStatus.Invalid)
            {
                throw new Exception("领取发生异常");
            }
            object[] objArray5 = new object[] { "/m-weixin/ShopBonus/Expired/", shopBonusModel.Id, "?openId=", userInfo.openid, "&grantid=", id, "&wxhead=", userInfo.headimgurl };
            return(Redirect(string.Concat(objArray5)));
        }
예제 #18
0
        public ActionResult Index(long id)
        {
            if (this.PlatformType != Core.PlatformType.WeiXin)
            {
                Log.Info(this.PlatformType.ToString());
                return(Content("只能在微信端访问"));
            }

            var bonus = this._bonusService.GetByGrantId(id);

            if (bonus == null)
            {
                Log.Info("红包失踪,id = " + id);
                return(Redirect("/m-weixin/ShopBonus/Invalidtwo"));
            }

            //授权获取openid相关
            string code = HttpContext.Request["code"];
            OAuthAccessTokenResult wxOpenInfo = null;

            if (string.IsNullOrEmpty(code))
            {
                string selfAddress = Request.Url.ToString();
                string url         = OAuthApi.GetAuthorizeUrl(this._siteSetting.WeixinAppId.Trim(), selfAddress, "STATE", Senparc.Weixin.MP.OAuthScope.snsapi_userinfo, "code");
                return(Redirect(url));
            }
            else
            {
                try
                {
                    wxOpenInfo = OAuthApi.GetAccessToken(this._siteSetting.WeixinAppId.Trim(), this._siteSetting.WeixinAppSecret.Trim(), code, "authorization_code");
                }
                catch (Exception e)
                {
                    Exception innerEx = e.InnerException == null ? e : e.InnerException;
                    return(Content(innerEx.Message));
                }
            }

            OAuthUserInfo  wxUserInfo = OAuthApi.GetUserInfo(wxOpenInfo.access_token, wxOpenInfo.openid);
            ShopBonusModel model      = new ShopBonusModel(bonus);

            if (model.DateEnd <= DateTime.Now || model.IsInvalid || model.BonusDateEnd <= DateTime.Now)  //过期、失效
            {
                return(Redirect("/m-weixin/ShopBonus/Expired/" + model.Id + "?openId=" + wxOpenInfo.openid + "&grantid=" + id + "&wxhead=" + wxUserInfo.headimgurl));
            }
            else if (model.DateStart > DateTime.Now) // 未开始
            {
                return(Redirect("/m-weixin/ShopBonus/NotStart/" + model.Id));
            }
            ShopReceiveModel obj = (ShopReceiveModel)this._bonusService.Receive(id, wxUserInfo.openid, wxUserInfo.headimgurl, wxUserInfo.nickname);

            //防两次刷新
            string cacheDName = "WXSB_U" + wxOpenInfo.openid + "_D" + id.ToString();

            if (obj.State == ShopReceiveStatus.Receive)
            {
                var _tmp = Cache.Get <ShopReceiveModel>(cacheDName);
                if (_tmp != null && _tmp.State == ShopReceiveStatus.CanReceive)
                {
                    obj = _tmp;
                }
            }

            if (obj.State == ShopReceiveStatus.CanReceive)
            {
                Cache.Insert <ShopReceiveModel>(cacheDName, obj, 2);
                return(Redirect("/m-weixin/ShopBonus/Completed/" + model.Id + "?openId=" + wxUserInfo.openid + "&price=" + obj.Price + "&user="******"&grantid=" + id + "&rid=" + obj.Id + "&wxhead=" + wxUserInfo.headimgurl + "&host=" + Request.Url.Host));
            }
            else if (obj.State == ShopReceiveStatus.CanReceiveNotUser)
            {
                return(Redirect("/m-weixin/ShopBonus/CompletedNotUser/" + model.Id + "?openId=" + wxUserInfo.openid + "&price=" + obj.Price + "&grantid=" + id + "&rid=" + obj.Id + "&wxhead=" + wxUserInfo.headimgurl + "&host=" + Request.Url.Host));
            }
            else if (obj.State == ShopReceiveStatus.Receive)
            {
                return(Redirect("/m-weixin/ShopBonus/HasReceive/" + model.Id + "?openId=" + wxUserInfo.openid + "&grantid=" + id + "&wxhead=" + wxUserInfo.headimgurl + "&host=" + Request.Url.Host));
            }
            else if (obj.State == ShopReceiveStatus.HaveNot)
            {
                return(Redirect("/m-weixin/ShopBonus/HaveNot/" + model.Id + "?openId=" + wxUserInfo.openid + "&grantid=" + id + "&wxhead=" + wxUserInfo.headimgurl));
            }
            else if (obj.State == ShopReceiveStatus.Invalid)
            {
                return(Redirect("/m-weixin/ShopBonus/Expired/" + model.Id + "?openId=" + wxUserInfo.openid + "&grantid=" + id + "&wxhead=" + wxUserInfo.headimgurl));
            }
            else
            {
                throw new Exception("领取发生异常");
            }
        }