Esempio n. 1
0
        private void SetExpire()
        {
            DateTime date = DateTime.Now.Date;
            ActiveMarketServiceInfo marketService = service.GetMarketService(base.CurrentSellerManager.ShopId, MarketType.Collocation);
            bool flag = false;

            if (marketService != null)
            {
                ViewBag.IsBuy = true;
                DateTime dateTime = marketService.MarketServiceRecordInfo.Max <MarketServiceRecordInfo, DateTime>((MarketServiceRecordInfo item) => item.EndTime);
                if (dateTime <= date)
                {
                    flag = true;
                    ViewBag.EndDateInfo = "您的优惠券服务已经过期,您可以续费。";
                }
                else
                {
                    ViewBag.EndDateInfo = dateTime.ToString("yyyy年MM月dd日");
                }
            }
            else
            {
                ViewBag.IsBuy = false;
                flag          = true;
            }
            ViewBag.Expire = flag;
        }
Esempio n. 2
0
        public ActionResult BuyService()
        {
            ActiveMarketServiceInfo shopBonusService = _bonusService.GetShopBonusService(base.CurrentSellerManager.ShopId);
            MarketSettingInfo       serviceSetting   = ServiceHelper.Create <IMarketService>().GetServiceSetting((MarketType)4);

            ((dynamic)base.ViewBag).Market = shopBonusService;
            ((dynamic)base.ViewBag).IsNo   = true;
            string   str  = null;
            DateTime date = DateTime.Now.Date;

            if ((shopBonusService != null) && (shopBonusService.MarketServiceRecordInfo.Max <MarketServiceRecordInfo, DateTime>(item => item.EndTime) < date))
            {
                str = "您的随机红包服务已经过期,您可以续费。";
            }
            else if ((shopBonusService != null) && (shopBonusService.MarketServiceRecordInfo.Max <MarketServiceRecordInfo, DateTime>(item => item.EndTime) >= date))
            {
                DateTime time2 = shopBonusService.MarketServiceRecordInfo.Max <MarketServiceRecordInfo, DateTime>(item => item.EndTime);
                str = string.Format("{0} 年 {1} 月 {2} 日", time2.Year, time2.Month, time2.Day);
            }
            else if (serviceSetting == null)
            {
                ((dynamic)base.ViewBag).IsNo = false;
                return(View());
            }
            ViewBag.EndDate = str;
            ViewBag.Price   = serviceSetting.Price;
            return(View());
        }
Esempio n. 3
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"));
        }
Esempio n. 4
0
        public void AddCoupon(CouponInfo info)
        {
            CanAddOrEditCoupon(info);
            ActiveMarketServiceInfo activeMarketServiceInfo = context.ActiveMarketServiceInfo.FirstOrDefault((ActiveMarketServiceInfo a) => (int)a.TypeId == 2 && a.ShopId == info.ShopId);

            if (activeMarketServiceInfo == null)
            {
                throw new HimallException("您没有订购此服务");
            }
            if (activeMarketServiceInfo.MarketServiceRecordInfo.Max <MarketServiceRecordInfo, DateTime>((MarketServiceRecordInfo item) => item.EndTime.Date) < info.EndTime)
            {
                throw new HimallException("结束日期不能大于订购的日期");
            }
            info.WXAuditStatus = 1;
            if (info.IsSyncWeiXin == 1)
            {
                info.WXAuditStatus = 0;
            }
            context.CouponInfo.Add(info);
            context.SaveChanges();
            if (info.IsSyncWeiXin == 1)
            {
                WXCardLogInfo wXCardLogInfo = new WXCardLogInfo()
                {
                    CardColor    = info.FormWXColor,
                    CardTitle    = info.FormWXCTit,
                    CardSubTitle = info.FormWXCSubTit,
                    CouponType   = new WXCardLogInfo.CouponTypeEnum?(ThisCouponType),
                    CouponId     = new long?(info.Id),
                    ShopId       = info.ShopId,
                    ShopName     = info.ShopName,
                    ReduceCost   = (int)(info.Price * new decimal(100)),
                    LeastCost    = (int)(info.OrderAmount * new decimal(100)),
                    Quantity     = info.Num,
                    GetLimit     = info.PerMax
                };
                decimal price = info.Price;
                wXCardLogInfo.DefaultDetail = string.Concat(price.ToString("F2"), "元优惠券1张");
                wXCardLogInfo.BeginTime     = info.StartTime.Date;
                DateTime dateTime = info.EndTime.AddDays(1);
                wXCardLogInfo.EndTime = dateTime.AddMinutes(-1);
                if (!ser_wxcard.Add(wXCardLogInfo))
                {
                    context.CouponInfo.Remove(info);
                    context.SaveChanges();
                    throw new HimallException("同步微信卡券失败,请检查参数是否有错!");
                }
                info.CardLogId = new long?(wXCardLogInfo.Id);
                context.SaveChanges();
            }
            SaveCover(info);
        }
Esempio n. 5
0
        public void OrderMarketService(int monthCount, long shopId, MarketType type)
        {
            if (shopId <= 0)
            {
                throw new HimallException("ShopId不能识别");
            }
            if (monthCount <= 0)
            {
                throw new HimallException("购买服务时长必须大于零");
            }
            ShopInfo shopInfo = context.ShopInfo.FindById <ShopInfo>(shopId);

            if (shopInfo == null || shopId <= 0)
            {
                throw new HimallException("ShopId不能识别");
            }
            ActiveMarketServiceInfo activeMarketServiceInfo = context.ActiveMarketServiceInfo.FirstOrDefault((ActiveMarketServiceInfo a) => a.ShopId == shopId && (int)a.TypeId == (int)type);

            if (activeMarketServiceInfo == null)
            {
                DbSet <ActiveMarketServiceInfo> activeMarketServiceInfos = context.ActiveMarketServiceInfo;
                ActiveMarketServiceInfo         activeMarketServiceInfo1 = new ActiveMarketServiceInfo()
                {
                    ShopId   = shopId,
                    ShopName = shopInfo.ShopName,
                    TypeId   = type
                };
                List <MarketServiceRecordInfo> marketServiceRecordInfos = new List <MarketServiceRecordInfo>();
                MarketServiceRecordInfo        marketServiceRecordInfo  = new MarketServiceRecordInfo()
                {
                    StartTime = DateTime.Now.Date,
                    EndTime   = DateTime.Now.AddMonths(monthCount)
                };
                marketServiceRecordInfos.Add(marketServiceRecordInfo);
                activeMarketServiceInfo1.MarketServiceRecordInfo = marketServiceRecordInfos;
                activeMarketServiceInfos.Add(activeMarketServiceInfo1);
            }
            else
            {
                DateTime dateTime = activeMarketServiceInfo.MarketServiceRecordInfo.Max <MarketServiceRecordInfo, DateTime>((MarketServiceRecordInfo item) => item.EndTime);
                ICollection <MarketServiceRecordInfo> marketServiceRecordInfo1 = activeMarketServiceInfo.MarketServiceRecordInfo;
                MarketServiceRecordInfo marketServiceRecordInfo2 = new MarketServiceRecordInfo()
                {
                    StartTime = dateTime,
                    EndTime   = dateTime.AddMonths(monthCount)
                };
                marketServiceRecordInfo1.Add(marketServiceRecordInfo2);
            }
            context.SaveChanges();
        }
Esempio n. 6
0
        public ActiveMarketServiceInfo GetMarketService(long shopId, MarketType type)
        {
            var market = DbFactory.Default.Get <ActiveMarketServiceInfo>().Where(m => m.TypeId == type && m.ShopId == shopId).FirstOrDefault();

            if (market == null)
            {
                market = new ActiveMarketServiceInfo
                {
                    ShopId = shopId,
                    TypeId = type,
                };
            }
            return(market);
        }
Esempio n. 7
0
        // Methods
        public void AddCoupon(CouponInfo info)
        {
            this.CanAddOrEditCoupon(info);
            ActiveMarketServiceInfo info2 = base.Context.ActiveMarketServiceInfo.FirstOrDefault <ActiveMarketServiceInfo>(a => (((int)a.TypeId) == 2) && (a.ShopId == info.ShopId));

            if (info2 == null)
            {
                throw new HimallException("您没有订购此服务");
            }
            if (info2.MarketServiceRecordInfo.Max <MarketServiceRecordInfo, DateTime>(item => item.EndTime.Date) < info.EndTime)
            {
                throw new HimallException("结束日期已经超过购买优惠券服务的日期");
            }
            info.WXAuditStatus = 1;
            if (info.IsSyncWeiXin == 1)
            {
                info.WXAuditStatus = 0;
            }
            base.Context.CouponInfo.Add(info);
            base.Context.SaveChanges();
            if (info.IsSyncWeiXin == 1)
            {
                WXCardLogInfo info3 = new WXCardLogInfo
                {
                    CardColor     = info.FormWXColor,
                    CardTitle     = info.FormWXCTit,
                    CardSubTitle  = info.FormWXCSubTit,
                    CouponType    = new WXCardLogInfo.CouponTypeEnum?(this.ThisCouponType),
                    CouponId      = new long?(info.Id),
                    ShopId        = info.ShopId,
                    ShopName      = info.ShopName,
                    ReduceCost    = (int)(info.Price * 100M),
                    LeastCost     = (int)(info.OrderAmount * 100M),
                    Quantity      = info.Num,
                    GetLimit      = info.PerMax,
                    DefaultDetail = info.Price.ToString("F2") + "元优惠券1张",
                    BeginTime     = info.StartTime.Date,
                    EndTime       = info.EndTime.AddDays(1.0).AddMinutes(-1.0)
                };
                if (!this.ser_wxcard.Add(info3))
                {
                    base.Context.CouponInfo.Remove(info);
                    base.Context.SaveChanges();
                    throw new HimallException("同步微信卡券失败,请检查参数是否有错!");
                }
                info.CardLogId = new long?(info3.Id);
                base.Context.SaveChanges();
            }
            this.SaveCover(info);
        }
        public void EnableMarketService(int monthCount, long shopId)
        {
            if (shopId <= 0)
            {
                throw new HimallException("ShopId不能识别");
            }
            if (monthCount <= 0)
            {
                throw new HimallException("购买服务时长必须大于零");
            }
            ShopInfo shopInfo = context.ShopInfo.FindById <ShopInfo>(shopId);

            if (shopInfo == null || shopId <= 0)
            {
                throw new HimallException("ShopId不能识别");
            }
            if (!context.ActiveMarketServiceInfo.Any((ActiveMarketServiceInfo a) => a.ShopId == shopId && (int)a.TypeId == 1))
            {
                DbSet <ActiveMarketServiceInfo> activeMarketServiceInfo  = context.ActiveMarketServiceInfo;
                ActiveMarketServiceInfo         activeMarketServiceInfo1 = new ActiveMarketServiceInfo()
                {
                    ShopId   = shopId,
                    ShopName = shopInfo.ShopName,
                    TypeId   = MarketType.LimitTimeBuy
                };
                List <MarketServiceRecordInfo> marketServiceRecordInfos = new List <MarketServiceRecordInfo>();
                MarketServiceRecordInfo        marketServiceRecordInfo  = new MarketServiceRecordInfo()
                {
                    StartTime = DateTime.Now.Date,
                    EndTime   = DateTime.Now.Date.AddMonths(monthCount)
                };
                marketServiceRecordInfos.Add(marketServiceRecordInfo);
                activeMarketServiceInfo1.MarketServiceRecordInfo = marketServiceRecordInfos;
                activeMarketServiceInfo.Add(activeMarketServiceInfo1);
            }
            else
            {
                ActiveMarketServiceInfo activeMarketServiceInfo2 = context.ActiveMarketServiceInfo.FirstOrDefault((ActiveMarketServiceInfo a) => a.ShopId == shopId && (int)a.TypeId == 1);
                long     id       = activeMarketServiceInfo2.Id;
                DateTime date     = DateTime.Now.Date;
                DateTime dateTime = DateTime.Now.Date;
                AddMarketServiceRecord(id, date, dateTime.AddMonths(monthCount));
            }
            context.SaveChanges();
        }
Esempio n. 9
0
        public ActionResult Management()
        {
            var settings = _iLimitTimeBuyService.GetServiceSetting();

            if (settings == null)
            {
                return(View("Nosetting"));
            }

            bool expired = false;
            ActiveMarketServiceInfo market = _iLimitTimeBuyService.GetMarketService(CurrentSellerManager.ShopId);

            if (market == null || market != null && ((Himall.Model.ActiveMarketServiceInfo)market).MarketServiceRecordInfo.Max(a => a.EndTime) < DateTime.Now.Date)
            {
                expired = true;
            }
            ViewBag.IsExpired = expired;
            return(View());
        }
Esempio n. 10
0
        public ActionResult BuyService()
        {
            ActiveMarketServiceInfo marketService = ServiceHelper.Create <ILimitTimeBuyService>().GetMarketService(base.CurrentSellerManager.ShopId);

            ((dynamic)base.ViewBag).Market = marketService;
            string str = null;

            if ((marketService != null) && (marketService.MarketServiceRecordInfo.Max <MarketServiceRecordInfo, DateTime>(m => m.EndTime) < DateTime.Now))
            {
                str = "您的限时购服务已经过期,您可以续费。";
            }
            else if ((marketService != null) && (marketService.MarketServiceRecordInfo.Max <MarketServiceRecordInfo, DateTime>(m => m.EndTime) > DateTime.Now))
            {
                DateTime time = marketService.MarketServiceRecordInfo.Max <MarketServiceRecordInfo, DateTime>(m => m.EndTime);
                str = string.Format("{0} 年 {1} 月 {2} 日", time.Year, time.Month, time.Day);
            }
            ViewBag.EndDate = str;
            ViewBag.Price   = ServiceHelper.Create <ILimitTimeBuyService>().GetServiceSetting().Price;
            return(View());
        }
Esempio n. 11
0
        public ActionResult BuyService()
        {
            ActiveMarketServiceInfo couponService = ServiceHelper.Create <ICouponService>().GetCouponService(base.CurrentSellerManager.ShopId);

            ((dynamic)base.ViewBag).Market = couponService;
            string   str  = null;
            DateTime date = DateTime.Now.Date;

            if ((couponService != null) && (couponService.MarketServiceRecordInfo.Max <MarketServiceRecordInfo, DateTime>(item => item.EndTime) < date))
            {
                str = "您的优惠券服务已经过期,您可以续费。";
            }
            else if ((couponService != null) && (couponService.MarketServiceRecordInfo.Max <MarketServiceRecordInfo, DateTime>(item => item.EndTime) >= date))
            {
                DateTime time2 = couponService.MarketServiceRecordInfo.Max <MarketServiceRecordInfo, DateTime>(item => item.EndTime);
                str = string.Format("{0} 年 {1} 月 {2} 日", time2.Year, time2.Month, time2.Day);
            }
            ViewBag.EndDate = str;
            ViewBag.Price   = ServiceHelper.Create <IMarketService>().GetServiceSetting(MarketType.Coupon).Price;
            return(View());
        }
Esempio n. 12
0
        public ActionResult Management()
        {
            if (ServiceHelper.Create <IMarketService>().GetServiceSetting(MarketType.Coupon) == null)
            {
                throw new HimallException("平台未配置随机红包");
            }
            ActiveMarketServiceInfo shopBonusService = _bonusService.GetShopBonusService(base.CurrentSellerManager.ShopId);

            if (shopBonusService != null)
            {
                if (shopBonusService != null)
                {
                    if (shopBonusService.MarketServiceRecordInfo.Max <MarketServiceRecordInfo, DateTime>((MarketServiceRecordInfo a) => a.EndTime) < DateTime.Now.Date)
                    {
                        return(RedirectToAction("BuyService"));
                    }
                }
                ViewBag.Market = shopBonusService;
                return(View());
            }
            return(RedirectToAction("BuyService"));
        }
Esempio n. 13
0
        public void OrderMarketService(int monthCount, long shopId, MarketType type)
        {
            if (shopId <= 0)
            {
                throw new HimallException("ShopId不能识别");
            }
            if (monthCount <= 0)
            {
                throw new HimallException("购买服务时长必须大于零");
            }
            var shop = DbFactory.Default.Get <ShopInfo>().Where(p => p.Id == shopId).FirstOrDefault();

            if (shop == null || shopId <= 0)
            {
                throw new HimallException("ShopId不能识别");
            }

            var price     = DbFactory.Default.Get <MarketSettingInfo>().Where(a => a.TypeId == type).Select(a => a.Price).FirstOrDefault <decimal>();
            var StartTime = DateTime.Now;
            MarketServiceRecordInfo model = new MarketServiceRecordInfo();

            model.StartTime = StartTime;
            model.Price     = price * monthCount;
            var shopAccount = DbFactory.Default.Get <ShopAccountInfo>().Where(a => a.ShopId == shopId).FirstOrDefault();//店铺帐户信息

            #region 它下面会取几次只,如为空会报异常,默认存入0的初始值
            if (shopAccount == null)
            {
                shopAccount                   = new ShopAccountInfo();
                shopAccount.ShopId            = shopId;
                shopAccount.ShopName          = shop.ShopName;
                shopAccount.Balance           = 0;
                shopAccount.PendingSettlement = 0;
                shopAccount.Settled           = 0;
                shopAccount.ReMark            = string.Empty;
                DbFactory.Default.Add(shopAccount);
            }
            #endregion

            if (shopAccount.Balance < model.Price) //店铺余额不足以支付服务费用
            {
                throw new HimallException("您的店铺余额为:" + shopAccount.Balance + "元,不足以支付此次营销服务购买费用,请先充值。");
            }

            DbFactory.Default.InTransaction(() =>
            {
                var market = DbFactory.Default.Get <ActiveMarketServiceInfo>().Where(a => a.ShopId == shopId && a.TypeId == type).FirstOrDefault();
                if (market != null)
                {
                    var maxTime = MarketApplication.GetServiceEndTime(market.Id);
                    if (maxTime > DateTime.Now) //如果结束时间大于当前时间,续费从结束时间加上购买月数,否则从当前时间加上购买月数
                    {
                        StartTime = maxTime;
                    }
                    model.StartTime = StartTime;
                    model.BuyTime   = DateTime.Now;
                    model.EndTime   = StartTime.AddMonths(monthCount);
                    // model.MarketServiceId = market.Id;
                    model.SettlementFlag  = 1;
                    model.MarketServiceId = market.Id;

                    DbFactory.Default.Add(model);
                }
                else
                {
                    model.StartTime      = StartTime;
                    model.EndTime        = StartTime.AddMonths(monthCount);
                    model.SettlementFlag = 1;
                    model.BuyTime        = DateTime.Now;

                    ActiveMarketServiceInfo activeMarketServiceInfo = new ActiveMarketServiceInfo();
                    activeMarketServiceInfo.ShopId   = shopId;
                    activeMarketServiceInfo.ShopName = shop.ShopName;
                    activeMarketServiceInfo.TypeId   = type;
                    DbFactory.Default.Add(activeMarketServiceInfo);

                    model.MarketServiceId = activeMarketServiceInfo.Id;
                    DbFactory.Default.Add(model);
                }

                var ShopAccount          = DbFactory.Default.Get <ShopAccountInfo>().Where(a => a.ShopId == shopId).FirstOrDefault();
                ShopAccountItemInfo info = new ShopAccountItemInfo();
                info.IsIncome            = false;
                info.ShopId          = shopId;
                info.DetailId        = model.Id.ToString();
                info.ShopName        = shop.ShopName;
                info.AccountNo       = shopId + info.DetailId + new Random().Next(10000);
                info.ReMark          = "店铺购买" + type.ToDescription() + "服务," + monthCount + "个月";
                info.TradeType       = ShopAccountType.MarketingServices;
                info.CreateTime      = DateTime.Now;
                info.Amount          = price * monthCount;
                info.AccoutID        = ShopAccount.Id;
                ShopAccount.Balance -= info.Amount;         //总余额减钱
                info.Balance         = ShopAccount.Balance; //变动后当前剩余金额

                DbFactory.Default.Add(info);
                DbFactory.Default.Update(ShopAccount);

                var platAccount = DbFactory.Default.Get <PlatAccountInfo>().FirstOrDefault();
                var pinfo       = new PlatAccountItemInfo
                {
                    IsIncome   = true,
                    DetailId   = model.Id.ToString(),
                    AccountNo  = info.AccountNo,
                    ReMark     = "店铺购买" + type.ToDescription() + "服务," + monthCount + "个月",
                    TradeType  = PlatAccountType.MarketingServices,
                    CreateTime = DateTime.Now,
                    Amount     = price * monthCount,
                    AccoutID   = platAccount.Id
                };
                platAccount.Balance += info.Amount;         //总余额加钱
                pinfo.Balance        = platAccount.Balance; //变动后当前剩余金额
                DbFactory.Default.Add(pinfo);
                DbFactory.Default.Update(platAccount);
            });
        }