Beispiel #1
0
        public static List<ClientAuthorizeLog> GetClientAuthorizeLogs(string clientID,string keyWords, int pageSize, int pageIndex, ref int totalCount, ref int pageCount)
        {
            DataTable dt = CommonBusiness.GetPagerData("ClientAuthorizeLog", "*", " Status<>9 and ClientID='" + clientID+"' ", "AutoID", pageSize, pageIndex, out totalCount, out pageCount);
            List<ClientAuthorizeLog> list = new List<ClientAuthorizeLog>();
            ClientAuthorizeLog model;
            foreach (DataRow item in dt.Rows)
            {
                model = new ClientAuthorizeLog();
                model.FillData(item);
                list.Add(model);
            }

            return list;
        }
 /// <summary>
 /// 添加客户授权日志
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static bool InsertClientAuthorizeLog(ClientAuthorizeLog model)
 {
     return ClientDAL.BaseProvider.InsertClientAuthorizeLog(model.ClientID,model.AgentID,model.OrderID,
         model.UserQuantity, model.BeginTime, model.EndTime, model.Type);
 }
        /// <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);
            var agent = AgentsBusiness.GetAgentDetail(client.AgentID);
            ClientAuthorizeLog log = new ClientAuthorizeLog();

            log.CreateUserID = CurrentUser.UserID;
            log.ClientID = clientID;
            log.AgentID = client.AgentID;
            log.OrderID = string.Empty;
            
            if (serviceType == 1)//赠送
            {
                if (giveType == 1)//赠送人数
                {
                    flag = AgentsBusiness.AddClientAgentUserQuantity(client.AgentID, userQuantity);

                    log.BeginTime = agent.EndTime;
                    log.EndTime = agent.EndTime;
                    log.UserQuantity = userQuantity;
                    log.Type = 2;
                }
                else//赠送时间
                {
                    log.BeginTime = agent.EndTime;
                    flag = AgentsBusiness.SetClientAgentEndTime(client.AgentID, DateTime.Parse(endTime));

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

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

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

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

                    log.BeginTime = agent.EndTime;
                    log.EndTime = agent.EndTime.AddYears(years);
                    log.UserQuantity = agent.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;

                //购买人数
                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.AgentID = client.AgentID;
                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
            };
        }