Exemple #1
0
        public JsonResult SaveModulesProduct(string modulesProduct)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            ModulesProduct       model      = serializer.Deserialize <ModulesProduct>(modulesProduct);

            bool flag = false;

            if (model.AutoID == 0)
            {
                model.CreateUserID = string.Empty;
                flag = ModulesProductBusiness.InsertModulesProduct(model);
            }
            else
            {
                model.CreateUserID = string.Empty;
                flag = ModulesProductBusiness.UpdateModulesProduct(model);
            }
            JsonDictionary.Add("Result", flag ? 1 : 0);

            return(new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Exemple #2
0
        /// <summary>
        /// 根据人数、年数获取最佳产品组合
        /// </summary>
        public JsonResult GetBestWay(int quantity, int years, int type)
        {
            int remainderMonths = 12;//剩余月份
            int pageCount       = 0;
            int totalCount      = 0;

            //购买人数
            if (type == 2)
            {
                remainderMonths = (CurrentClient.EndTime.Year - DateTime.Now.Year) * 12 + (CurrentClient.EndTime.Month - DateTime.Now.Month) - 1;
                if (CurrentClient.EndTime.Day >= DateTime.Now.Day)
                {
                    remainderMonths += 1;
                }

                years = remainderMonths / 12 == 0 ? 1 : remainderMonths / 12;
                JsonDictionary.Add("PeriodQuantity", years);
            }

            List <ModulesProduct> list = ModulesProductBusiness.GetModulesProducts(string.Empty, int.MaxValue, 1, ref totalCount, ref pageCount);
            var way = ModulesProductBusiness.GetBestWay(quantity, list.OrderByDescending(m => m.UserQuantity).Where(m => m.PeriodQuantity == years).ToList());

            List <Dictionary <string, string> > products = new List <Dictionary <string, string> >();

            foreach (var p in way.Products)
            {
                Dictionary <string, string> product = new Dictionary <string, string>();
                product.Add("id", p.Key);
                product.Add("count", p.Value.ToString());
                products.Add(product);
            }

            JsonDictionary.Add("Items", products);
            JsonDictionary.Add("TotalMoney", way.TotalMoney);
            JsonDictionary.Add("TotalQuantity", way.TotalQuantity);


            //购买人数
            if (type == 2)
            {
                float remainderYears = (float)remainderMonths / (12 * years);
                JsonDictionary.Add("Amount", (float.Parse(way.TotalMoney.ToString()) * remainderYears).ToString("f2"));
            }

            //if (type == 1 || type == 2)
            //{
            //    discount = 0.5F;
            //}
            //else
            //{
            //    discount = 0.88F;
            //}
            JsonDictionary.Add("Discount", ProductDiscount);

            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Exemple #3
0
        public JsonResult DeleteModulesProduct(int id)
        {
            bool flag = ModulesProductBusiness.DeleteModulesProduct(id);

            JsonDictionary.Add("Result", flag ? 1 : 0);
            return(new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Exemple #4
0
        public JsonResult GetModulesProductDetail(int id)
        {
            var item = ModulesProductBusiness.GetModulesProductDetail(id);

            JsonDictionary.Add("Item", item);
            JsonDictionary.Add("Result", 1);
            return(new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Exemple #5
0
        public JsonResult GetModulesProducts(int pageIndex, string keyWords)
        {
            int totalCount = 0, pageCount = 0;
            var list = ModulesProductBusiness.GetModulesProducts(keyWords, PageSize, pageIndex, ref totalCount, ref pageCount);

            JsonDictionary.Add("Items", list);
            JsonDictionary.Add("TotalCount", totalCount);
            JsonDictionary.Add("PageCount", pageCount);
            return(new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Exemple #6
0
        /// <summary>
        /// 获取产品列表
        /// </summary>
        public JsonResult GetProductList()
        {
            int pageCount  = 0;
            int totalCount = 0;

            List <ModulesProduct> list = ModulesProductBusiness.GetModulesProducts(string.Empty, int.MaxValue, 1, ref totalCount, ref pageCount);

            JsonDictionary.Add("Items", list);
            JsonDictionary.Add("TotalCount", totalCount);
            JsonDictionary.Add("PageCount", pageCount);

            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Exemple #7
0
        /// <summary>
        /// 根据人数、年数生成客户订单
        /// </summary>
        public JsonResult AddClientOrder(int quantity, int years, int type)
        {
            int remainderMonths = 12;//剩余月份

            //购买人数
            if (type == 2)
            {
                remainderMonths = (CurrentClient.EndTime.Year - DateTime.Now.Year) * 12 + (CurrentClient.EndTime.Month - DateTime.Now.Month) - 1;
                if (CurrentClient.EndTime.Day >= DateTime.Now.Day)
                {
                    remainderMonths += 1;
                }

                years = remainderMonths / 12 == 0 ? 1 : remainderMonths / 12;
            }

            int pageCount              = 0;
            int totalCount             = 0;
            List <ModulesProduct> list = ModulesProductBusiness.GetModulesProducts(string.Empty, int.MaxValue, 1, ref totalCount, ref pageCount);

            //获取订单产品的最佳组合
            var way = ModulesProductBusiness.GetBestWay(quantity, list.OrderByDescending(m => m.UserQuantity).Where(m => m.PeriodQuantity == years).ToList());

            //获取订单参数
            ClientOrder model = new ClientOrder();

            model.UserQuantity = way.TotalQuantity;
            model.Type         = type;
            model.Years        = years;
            model.Amount       = way.TotalMoney;
            //if (!string.IsNullOrEmpty(CurrentUser.Client.AliMemberID))
            //{
            //    if (type == 1 || type == 2)
            //    {
            //        discount = 0.50M;
            //    }
            //    else
            //    {
            //        discount = 0.88M;
            //    }

            //}
            //else
            //{
            //    if (type == 1 || type == 2)
            //    {
            //        discount = 0.5M;
            //    }
            //}
            model.RealAmount = way.TotalMoney * OrderDiscount;

            //购买人数
            float remainderYears = 1;

            if (type == 2)
            {
                remainderYears   = (float)remainderMonths / (12 * years);
                model.Amount     = decimal.Parse((float.Parse(model.Amount.ToString()) * remainderYears).ToString("f2"));
                model.RealAmount = decimal.Parse((float.Parse(model.RealAmount.ToString()) * remainderYears).ToString("f2"));
            }
            model.ClientID     = CurrentUser.ClientID;
            model.CreateUserID = CurrentUser.UserID;
            model.SourceType   = 0;
            model.Details      = new List <ClientOrderDetail>();
            foreach (var p in way.Products)
            {
                ClientOrderDetail detail = new ClientOrderDetail();
                detail.ProductID    = p.Key;
                detail.Qunatity     = p.Value;
                detail.CreateUserID = CurrentUser.CreateUserID;
                detail.Price        = list.Find(m => m.ProductID == p.Key).Price;
                //购买人数
                if (type == 2)
                {
                    detail.Price = decimal.Parse((float.Parse(detail.Price.ToString()) * remainderYears).ToString("f2"));
                }
                model.Details.Add(detail);
            }

            string orderID = ClientOrderBusiness.AddClientOrder(model);

            JsonDictionary.Add("ID", orderID);
            JsonDictionary.Add("RealAmount", model.RealAmount);

            return(new JsonResult
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Exemple #8
0
        /// <summary>
        /// 升级客户服务
        /// </summary>
        /// <param name="client"></param>
        public JsonResult SaveClientAuthorize(string clientID, int serviceType, int giveType, int userQuantity, string endTime, int buyType, int buyUserQuantity, int buyUserYears)
        {
            bool flag              = false;
            var  client            = ClientBusiness.GetClientDetail(clientID);
            ClientAuthorizeLog log = new ClientAuthorizeLog();

            log.CreateUserID = CurrentUser.UserID;
            log.ClientID     = clientID;
            log.OrderID      = string.Empty;

            if (serviceType == 1)  //赠送
            {
                if (giveType == 1) //赠送人数
                {
                    flag = ClientBusiness.AddClientUserQuantity(client.ClientID, userQuantity);

                    log.BeginTime    = client.EndTime;
                    log.EndTime      = client.EndTime;
                    log.UserQuantity = userQuantity;
                    log.Type         = 2;
                }
                else//赠送时间
                {
                    log.BeginTime = client.EndTime;
                    flag          = ClientBusiness.SetClientEndTime(client.ClientID, DateTime.Parse(endTime));

                    log.EndTime      = DateTime.Parse(endTime);
                    log.UserQuantity = client.UserQuantity;
                    log.Type         = 3;
                }
                ClientBusiness.UpdateClientCache(client.ClientID);
                ClientBusiness.InsertClientAuthorizeLog(log);
                ClearClientCache(client.ClientID);
            }
            else//购买生成订单
            {
                log.Type = buyType;
                int remainderMonths = 0;//剩余月份
                int years           = 1;

                if (buyType == 2)//购买人数
                {
                    remainderMonths = (client.EndTime.Year - DateTime.Now.Year) * 12 + (client.EndTime.Month - DateTime.Now.Month) - 1;
                    if (client.EndTime.Day >= DateTime.Now.Day)
                    {
                        remainderMonths += 1;
                    }

                    years = remainderMonths / 12 == 0 ? 1 : remainderMonths / 12;

                    log.BeginTime    = client.EndTime;
                    log.EndTime      = client.EndTime;
                    log.UserQuantity = userQuantity;
                }
                else
                {
                    years = buyUserYears;

                    log.BeginTime    = client.EndTime;
                    log.EndTime      = client.EndTime.AddYears(years);
                    log.UserQuantity = client.UserQuantity;
                }

                int pageCount              = 0;
                int totalCount             = 0;
                List <ModulesProduct> list = ModulesProductBusiness.GetModulesProducts(string.Empty, int.MaxValue, 1, ref totalCount, ref pageCount);

                //获取订单产品的最佳组合
                var way = ModulesProductBusiness.GetBestWay(buyUserQuantity, list.OrderByDescending(m => m.UserQuantity).Where(m => m.PeriodQuantity == years).ToList());

                //获取订单参数
                ClientOrder model = new ClientOrder();
                model.UserQuantity = way.TotalQuantity;
                model.Type         = buyType;
                model.Years        = years;
                model.Amount       = way.TotalMoney;
                model.RealAmount   = way.TotalMoney;
                model.SourceType   = 1;
                //购买人数
                float remainderYears = 1;
                if (buyType == 2)
                {
                    remainderYears   = (float)remainderMonths / (12 * years);
                    model.Amount     = decimal.Parse((float.Parse(model.Amount.ToString()) * remainderYears).ToString("f2"));
                    model.RealAmount = model.Amount;
                }
                model.ClientID     = client.ClientID;
                model.CreateUserID = CurrentUser.UserID;

                model.Details = new List <ClientOrderDetail>();
                foreach (var p in way.Products)
                {
                    ClientOrderDetail detail = new ClientOrderDetail();
                    detail.ProductID    = p.Key;
                    detail.Qunatity     = p.Value;
                    detail.CreateUserID = CurrentUser.CreateUserID;
                    detail.Price        = list.Find(m => m.ProductID == p.Key).Price;
                    //购买人数
                    if (buyType == 2)
                    {
                        detail.Price = decimal.Parse((float.Parse(detail.Price.ToString()) * remainderYears).ToString("f2"));
                    }
                    model.Details.Add(detail);
                }

                string orderID = ClientOrderBusiness.AddClientOrder(model);
                log.OrderID = orderID;

                flag = string.IsNullOrEmpty(orderID) ? false : true;
            }

            JsonDictionary.Add("Result", flag ? 1 : 0);

            return(new JsonResult()
            {
                Data = JsonDictionary,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }