Exemplo n.º 1
0
        public IHttpActionResult EditSchedule(int word_time_id, string week, string on_work, string off_work)
        {
            try
            {
                if (string.IsNullOrEmpty(week) || string.IsNullOrEmpty(on_work) || string.IsNullOrEmpty(off_work))
                {
                    return(Json(new { result = "请求参数错误" }));
                }

                using (ERPDBEntities db = new ERPDBEntities())
                {
                    var work_time = db.WorkTime.FirstOrDefault(a => a.id == word_time_id);
                    if (work_time == null)
                    {
                        return(Json(new { result = "排班信息异常" }));
                    }

                    work_time.week            = week;
                    work_time.on_work         = on_work;
                    work_time.off_work        = off_work;
                    work_time.update_time     = DateTime.Now;
                    db.Entry(work_time).State = System.Data.Entity.EntityState.Modified;
                    if (db.SaveChanges() < 0)
                    {
                        return(Json(new { result = "修改失败" }));
                    }

                    return(Json(new { result = "修改成功" }));
                }
            }
            catch (Exception ex)
            {
            }
            return(Json(new { result = "系统异常" }));
        }
Exemplo n.º 2
0
        public IHttpActionResult ChangeStaffLeader(int user_id, int leader_id)
        {
            try
            {
                using (ERPDBEntities db = new ERPDBEntities())
                {
                    var staff = db.Staff.FirstOrDefault(a => a.id == user_id);
                    if (staff == null)
                    {
                        return(Json(new { result = "员工信息不存在" }));
                    }

                    var leader = db.Staff.FirstOrDefault(a => a.id == leader_id);
                    if (leader == null)
                    {
                        return(Json(new { result = "主管信息不存在" }));
                    }

                    staff.leader_id   = leader.id;
                    staff.update_time = DateTime.Now;

                    db.Entry(staff).State = System.Data.Entity.EntityState.Added;
                    if (db.SaveChanges() > 0)
                    {
                        return(Json(new { result = "操作成功" }));
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(Json(new { result = "操作失败" }));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 3.4 鲜度检查
        /// </summary>
        /// <returns></returns>
        public IHttpActionResult CheckProductShelfLife()
        {
            try
            {
                using (ERPDBEntities db = new ERPDBEntities())
                {
                    var query = db.Product.AsQueryable();
                    //日配过期时间提前一小时
                    var ripei = query.Where(a => a.product_category == (int)Product_Category_Enum.RiPei && (a.production_date - DateTime.Now).TotalMilliseconds <= 60).ToList();

                    //非日配过期时间提前一月推送
                    var noripei = query.Where(a => a.product_category == (int)Product_Category_Enum.NoRiPei && (a.production_date - DateTime.Now).TotalDays <= 30).ToList();

                    List <Product> list = new List <Product>();
                    list.AddRange(ripei);
                    list.AddRange(noripei);

                    var data = list.Select(a => new { a.product_id, a.product_name });
                    return(Json(new { result = data }));
                }
            }
            catch (Exception ex)
            {
            }

            return(Json(new { result = "系统异常" }));
        }
Exemplo n.º 4
0
        public IHttpActionResult ChangeStaffProductType(int user_id, List <int> product_type)
        {
            try
            {
                if (product_type == null || !product_type.Any())
                {
                    return(Json(new { result = "请求参数错误" }));
                }

                using (ERPDBEntities db = new ERPDBEntities())
                {
                    var staff = db.Staff.FirstOrDefault(a => a.id == user_id);
                    if (staff == null)
                    {
                        return(Json(new { result = "员工信息异常" }));
                    }

                    staff.sell_product_type = string.Join(",", product_type);
                    db.Entry(staff).State   = System.Data.Entity.EntityState.Added;
                    if (db.SaveChanges() > 0)
                    {
                        return(Json(new { result = "操作成功" }));
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(Json(new { result = "操作失败" }));
        }
Exemplo n.º 5
0
        /// <summary>
        /// The GetProductExpendRate.
        /// </summary>
        /// <param name="category">The category<see cref="int?"/>.</param>
        /// <param name="time">The time<see cref="DateTime?"/>.</param>
        /// <returns>The <see cref="List{ProductExpendModel}"/>.</returns>
        private static List <ProductExpendModel> GetProductExpendRate(int?category = null, DateTime?time = null)
        {
            List <ProductExpendModel> list = new List <ProductExpendModel>();

            try
            {
                using (ERPDBEntities db = new ERPDBEntities())
                {
                    if (category.HasValue)
                    {
                        var query = (from a in db.Product join b in db.Sell_Record on a.product_id equals b.product_id where a.product_category == category.Value select new { a.product_id, a.product_name, a.stock_count, b.sell_count, b.create_time }).ToList();
                        if (time.HasValue)
                        {
                            query = query.Where(a => a.create_time.ToString("yyyy-MM-dd") == time.Value.ToString("yyyy-MM-dd")).Select(a => a).ToList();
                        }
                        foreach (var item in query)
                        {
                            ProductExpendModel pro = new ProductExpendModel();
                            pro.product_id   = item.product_id;
                            pro.product_name = item.product_name;
                            pro.stock_count  = item.stock_count;
                            pro.sell_count   = item.sell_count;
                            pro.expend_rate  = (((double)item.sell_count / (double)item.stock_count) * 100).ToString("f2") + "%";
                            list.Add(pro);
                        }
                        List <ProductExpendModel> temp = new List <ProductExpendModel>();
                        temp.AddRange(list.OrderBy(a => a.sell_count).Take(5));
                        temp.AddRange(list.OrderByDescending(a => a.sell_count).Take(5));
                        return(temp.OrderBy(a => a.sell_count).ToList());
                    }
                    else
                    {
                        var query = (from a in db.Product join b in db.Sell_Record on a.product_id equals b.product_id select new { a.product_id, a.product_name, a.stock_count, b.sell_count, b.create_time }).ToList();
                        if (time.HasValue)
                        {
                            query = query.Where(a => a.create_time.ToString("yyyy-MM-dd") == time.Value.ToString("yyyy-MM-dd")).Select(a => a).ToList();
                        }
                        //var query = (from a in db.Product join b in db.Sell_Record on a.product_id equals b.product_id select new { a.product_id, a.product_name, a.stock_count, b.sell_count }).ToList();
                        foreach (var item in query)
                        {
                            ProductExpendModel pro = new ProductExpendModel();
                            pro.product_id   = item.product_id;
                            pro.product_name = item.product_name;
                            pro.stock_count  = item.stock_count;
                            pro.sell_count   = item.sell_count;
                            pro.expend_rate  = (((double)item.sell_count / (double)item.stock_count) * 100).ToString("f2") + "%";
                            list.Add(pro);
                        }
                        return(list.OrderBy(a => a.sell_count).ToList());
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(null);;
        }
Exemplo n.º 6
0
        /// <summary>
        /// 获取消耗率.
        /// </summary>
        /// <param name="product_id">.</param>
        /// <param name="product_category">.</param>
        /// <param name="expend_rate_type">.</param>
        /// <returns>.</returns>
        public static double GetExpendRate(string product_id, int product_category, int expend_rate_type)
        {
            double expend_rate = 0;

            try
            {
                using (ERPDBEntities db = new ERPDBEntities())
                {
                    var rate_config = db.Product_Expend_Rate_Config.FirstOrDefault(a => a.product_id == product_id);
                    if (rate_config != null)
                    {
                        if (product_category == (int)Product_Category_Enum.NoRiPei)
                        {
                            if (expend_rate_type == (int)Enum_Product_Expend_Rate_Type.High_Expend_Rate)
                            {
                                expend_rate = SystemCommon.No_Ri_Pei_High_Expend_Rate - 5; //非日配商品消化率过高,消化率30 %,上下五个点
                            }
                            else if (expend_rate_type == (int)Enum_Product_Expend_Rate_Type.Low_Expend_Rate)
                            {
                                expend_rate = SystemCommon.No_Ri_Pei_Low_Expend_Rate;
                            }
                        }
                        else if (product_category == (int)Product_Category_Enum.RiPei)
                        {
                            if (expend_rate_type == (int)Enum_Product_Expend_Rate_Type.High_Expend_Rate)
                            {
                                expend_rate = SystemCommon.Ri_Pei_High_Expend_Rate - 2;   //日配商品消化率过高,消化率90%,上下两个点
                            }
                            else if (expend_rate_type == (int)Enum_Product_Expend_Rate_Type.Low_Expend_Rate)
                            {
                                expend_rate = SystemCommon.Ri_Pei_Low_Expend_Rate;
                            }
                        }
                    }
                    else
                    {
                        if (expend_rate_type == (int)Enum_Product_Expend_Rate_Type.High_Expend_Rate)
                        {
                            expend_rate = rate_config.high_expend_rate;
                        }
                        else if (expend_rate_type == (int)Enum_Product_Expend_Rate_Type.Low_Expend_Rate)
                        {
                            expend_rate = rate_config.low_expend_rate;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(expend_rate);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 默认根据最近7天的销售情况,用标准差公式计算消化率稳定产品.
        /// </summary>
        /// <returns>.</returns>
        private static List <ProductExpendRateStandardDeviationModel> GetStableExpendRate()
        {
            try
            {
                List <ProductExpendRateStandardDeviationModel> list = new List <ProductExpendRateStandardDeviationModel>();
                using (ERPDBEntities db = new ERPDBEntities())
                {
                    DateTime start_time = DateTime.Now; DateTime end_time = start_time.AddDays(7);
                    var      query = (from a in db.Product
                                      join b in db.Sell_Record on a.product_id equals b.product_id
                                      where b.create_time >= start_time && b.create_time <= end_time
                                      select new
                                      { a.product_id, a.product_name, a.stock_count, b.sell_count, b.create_time, a.product_category }).ToList();
                    if (query.Any())
                    {
                        var product = query.GroupBy(a => new { a.product_id, a.product_name });
                        if (product.Any())
                        {
                            foreach (var item in product)
                            {
                                List <double> expend_rate = new List <double>();
                                foreach (var info in item)
                                {
                                    double rate = ((double)info.sell_count / (double)info.stock_count) * 100;
                                    expend_rate.Add(rate);
                                }

                                ProductExpendRateStandardDeviationModel model = new ProductExpendRateStandardDeviationModel();
                                model.product_id     = item.Key.product_id;
                                model.product_name   = item.Key.product_name;
                                model.expend_rate_sd = SystemCommon.GetStdDev(expend_rate, false);
                                list.Add(model);
                            }
                        }
                    }

                    if (list.Any())
                    {
                        list = list.OrderBy(a => a.expend_rate_sd).Take(5).ToList();
                    }
                }

                return(list);
            }
            catch (Exception ex)
            {
            }

            return(null);
        }
Exemplo n.º 8
0
        public IHttpActionResult CheckHighProductPrice()
        {
            try
            {
                using (ERPDBEntities db = new ERPDBEntities())
                {
                    var data = db.Product.Where(a => a.price > 50).OrderByDescending(a => a.price).Take(20).ToList();
                    return(Json(new { result = data }));
                }
            }
            catch (Exception ex)
            {
            }

            return(Json(new { result = "系统异常" }));
        }
Exemplo n.º 9
0
        /// <summary>
        /// The GetProductExpendRate.
        /// </summary>
        /// <param name="time">The time<see cref="DateTime?"/>.</param>
        /// <returns>The <see cref="List{ProductExpendModel}"/>.</returns>
        private static List <ProductExpendModel> GetProductExpendRate(DateTime?time = null)
        {
            List <ProductExpendModel> list = new List <ProductExpendModel>();

            try
            {
                DateTime start_time = time.HasValue ? time.Value.Date : DateTime.Now.Date;
                DateTime end_time   = start_time.AddDays(1);

                using (ERPDBEntities db = new ERPDBEntities())
                {
                    var query = (from a in db.Product
                                 join b in db.Sell_Record on a.product_id equals b.product_id
                                 where b.create_time >= start_time && b.create_time < end_time
                                 select new { a.product_id, a.product_name, a.stock_count, b.sell_count, b.create_time }).AsQueryable();

                    if (query.Any())
                    {
                        var product = query.GroupBy(a => new { a.product_id, a.product_name });
                        foreach (var item in product)
                        {
                            List <double> expend_rate = new List <double>();
                            foreach (var info in item)
                            {
                                double rate = ((double)info.sell_count / (double)info.stock_count) * 100;
                                expend_rate.Add(rate);
                            }

                            double             average_expend_rate = expend_rate.Average();
                            ProductExpendModel pro = new ProductExpendModel();
                            pro.product_id          = item.Key.product_id;
                            pro.product_name        = item.Key.product_name;
                            pro.average_expend_rate = average_expend_rate;
                            pro.expend_rate         = average_expend_rate.ToString("f2") + "%";
                            list.Add(pro);
                        }
                    }

                    return(list.OrderBy(a => a.average_expend_rate).ToList());
                }
            }
            catch (Exception ex)
            {
            }
            return(null);;
        }
Exemplo n.º 10
0
        public IHttpActionResult GetSchedule()
        {
            try
            {
                using (ERPDBEntities db = new ERPDBEntities())
                {
                    string          week = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(DateTime.Now.DayOfWeek);
                    List <WorkTime> work = db.WorkTime.Where(a => a.week == week).ToList();
                    return(Json(new { result = work }));
                }
            }
            catch (Exception ex)
            {
            }

            return(Json(new { result = "系统异常" }));
        }
Exemplo n.º 11
0
        /// <summary>
        /// 初始化数据.
        /// </summary>
        /// <returns>.</returns>
        public void InitDB()
        {
            try
            {
                using (ERPDBEntities db = new ERPDBEntities())
                {
                    if (!db.Product.Any())
                    {
                        DBInit.InitProduct();
                    }

                    if (!db.Staff.Any())
                    {
                        DBInit.InitStaff();
                    }

                    if (!db.WorkTime.Any())
                    {
                        DBInit.InitWorkTime();
                    }

                    if (!db.Sell_Record.Any())
                    {
                        DBInit.InitSellRecord();
                    }

                    if (!db.Inventory.Any())
                    {
                        DBInit.InitInventory();
                    }

                    if (!db.Product_Expend_Rate_Config.Any())
                    {
                        DBInit.InitProductExpendRateConfig();
                    }
                }

                Response.Write("ok");
                return;
            }
            catch (Exception ex)
            {
            }

            Response.Write("error");
        }
Exemplo n.º 12
0
        public IHttpActionResult UserLogin(string name, string password)
        {
            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(password))
            {
                return(Json(new { result = "用户名或密码错误" }));
            }

            using (ERPDBEntities db = new ERPDBEntities())
            {
                var encode_pass = SystemCommon.GetMD5Str(password);
                var user        = db.Staff.FirstOrDefault(a => a.name == name && a.password == encode_pass);
                if (user == null)
                {
                    return(Json(new { result = "用户不存在" }));
                }

                return(Json(new { result = "登陆成功", data = user.id }));
            }
        }
Exemplo n.º 13
0
        public IHttpActionResult AddUser(string name, string password, int leader_id, string user_type, decimal salary, string sell_product_type)
        {
            try
            {
                if (string.IsNullOrEmpty(name))
                {
                    return(Json(new { result = "用户名不能为空" }));
                }

                Enum_User_Type userType;
                bool           convertResult = Enum.TryParse(user_type, out userType);
                if (convertResult == false)
                {
                    return(Json(new { result = "用户类型异常" }));
                }

                Staff user = new Staff();
                user.name              = name;
                user.password          = string.IsNullOrEmpty(password) ? SystemCommon.GetMD5Str(SystemCommon.Default_Password) : SystemCommon.GetMD5Str(password);
                user.leader_id         = leader_id;
                user.user_type         = user_type;
                user.salary            = salary;
                user.sell_product_type = sell_product_type;
                user.create_time       = DateTime.Now;
                user.update_time       = DateTime.Now;

                using (ERPDBEntities db = new ERPDBEntities())
                {
                    db.Entry(user).State = System.Data.Entity.EntityState.Added;
                    if (db.SaveChanges() < 0)
                    {
                        return(Json(new { result = "用户添加失败" }));
                    }
                }

                return(Json(new { result = "用户添加成功" }));
            }
            catch (Exception ex)
            {
            }

            return(Json(new { result = "系统异常" }));
        }
Exemplo n.º 14
0
        public JsonResult ChangeStaffLeader(int user_id, int leader_id)
        {
            try
            {
                using (ERPDBEntities db = new ERPDBEntities())
                {
                    var staff = db.Staff.FirstOrDefault(a => a.id == user_id);
                    if (staff == null)
                    {
                        return(Json("员工不存在", JsonRequestBehavior.AllowGet));
                    }

                    var leader = (from a in db.Staff
                                  join b in db.Staff_Auth on a.id equals b.staff_id
                                  select new { a.id, b.sell_product_type }).FirstOrDefault();

                    if (leader == null)
                    {
                        return(Json("主管不存在", JsonRequestBehavior.AllowGet));
                    }

                    Staff_Auth auth = new Staff_Auth();
                    auth.leader_id         = leader.id;
                    auth.staff_id          = staff.id;
                    auth.sell_product_type = leader.sell_product_type.Split(',').FirstOrDefault();
                    auth.create_time       = DateTime.Now;
                    auth.update_time       = DateTime.Now;

                    db.Entry(auth).State = System.Data.Entity.EntityState.Added;
                    if (db.SaveChanges() > 0)
                    {
                        return(Json("操作成功", JsonRequestBehavior.AllowGet));
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(Json("操作失败", JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 15
0
        /// <summary>
        /// The Index.
        /// </summary>
        /// <returns>The <see cref="ActionResult"/>.</returns>
        public ActionResult Index()
        {
            using (ERPDBEntities db = new ERPDBEntities())
            {
                if (!db.Product.Any())
                {
                    InitDB.InitProduct();
                }

                if (!db.Staff.Any())
                {
                    InitDB.InitStaff();
                }

                if (!db.schedule.Any())
                {
                    InitDB.InitSchedule();
                }

                if (!db.WorkTime.Any())
                {
                    InitDB.InitWorkTime();
                }

                if (!db.Sell_Record.Any())
                {
                    InitDB.InitSellRecord();
                }

                if (!db.Inventory.Any())
                {
                    InitDB.InitInventory();
                }

                if (!db.Staff_Auth.Any())
                {
                    InitDB.InitStaffAuth();
                }
            }
            return(View());
        }
Exemplo n.º 16
0
        public IHttpActionResult AddSchedule(int user_id, string week, string on_work, string off_work)
        {
            try
            {
                if (string.IsNullOrEmpty(week) || string.IsNullOrEmpty(on_work) || string.IsNullOrEmpty(off_work))
                {
                    return(Json(new { result = "请求参数错误" }));
                }

                using (ERPDBEntities db = new ERPDBEntities())
                {
                    var staff = db.Staff.FirstOrDefault(a => a.id == user_id);
                    if (staff == null)
                    {
                        return(Json(new { result = "员工信息异常" }));
                    }

                    WorkTime work_time = new WorkTime();
                    work_time.staff_id        = staff.id;
                    work_time.staff_name      = staff.name;
                    work_time.week            = week;
                    work_time.on_work         = on_work;
                    work_time.off_work        = off_work;
                    work_time.create_time     = DateTime.Now;
                    work_time.update_time     = DateTime.Now;
                    db.Entry(work_time).State = System.Data.Entity.EntityState.Added;
                    if (db.SaveChanges() < 0)
                    {
                        return(Json(new { result = "添加失败" }));
                    }

                    return(Json(new { result = "添加成功" }));
                }
            }
            catch (Exception ex)
            {
            }
            return(Json(new { result = "系统异常" }));
        }
Exemplo n.º 17
0
        public IHttpActionResult GetHomeInfo()
        {
            try
            {
                HomeInfoData model = new HomeInfoData();
                using (ERPDBEntities db = new ERPDBEntities())
                {
                    DateTime        now  = DateTime.Now;
                    string          week = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(now.DayOfWeek);
                    List <WorkTime> work = db.WorkTime.Where(a => a.week == week).ToList();
                    model.staff = work.Select(a => a.staff_name).ToList();

                    model.ri_pei_count = db.Product.Where(a => a.product_category == (int)Product_Category_Enum.RiPei).Sum(a => a.stock_count);
                    model.ri_pei_count = db.Product.Where(a => a.product_category == (int)Product_Category_Enum.NoRiPei).Sum(a => a.stock_count);
                    model.current_date = now.ToString("yyyy.MM.dd") + "(" + week + ")";
                    model.sell_target  = SystemCommon.Default_Sell_Target;
                }
            }
            catch (Exception ex)
            {
            }

            return(Json(new { result = "系统异常" }));
        }
Exemplo n.º 18
0
        /// <summary>
        /// 获取商品消耗率过高和过低的5个产品.
        /// </summary>
        /// <param name="category">.</param>
        /// <param name="time">.</param>
        /// <returns>.</returns>
        private static ExpendModel GetProductExpendRate(int category, DateTime?time = null)
        {
            ExpendModel model = new ExpendModel();

            try
            {
                DateTime start_time = time.HasValue ? time.Value.Date : DateTime.Now.Date;
                DateTime end_time   = start_time.AddDays(1);

                using (ERPDBEntities db = new ERPDBEntities())
                {
                    var query = (from a in db.Product
                                 join b in db.Sell_Record on a.product_id equals b.product_id
                                 where a.product_category == category && b.create_time >= start_time && b.create_time < end_time
                                 select new { a.product_id, a.product_name, a.stock_count, b.sell_count, b.create_time }).AsQueryable();

                    if (query.Any())
                    {
                        var product = query.GroupBy(a => new { a.product_id, a.product_name });
                        foreach (var item in product)
                        {
                            List <double> expend_rate = new List <double>();
                            foreach (var info in item)
                            {
                                double rate = ((double)info.sell_count / (double)info.stock_count) * 100;
                                expend_rate.Add(rate);
                            }

                            double average_expend_rate = expend_rate.Average();
                            if (category == (int)Product_Category_Enum.RiPei)
                            {
                                //日配商品消化率过高,消化率90%,上下两个点
                                if (average_expend_rate >= SystemCommon.GetExpendRate(item.Key.product_id, (int)Product_Category_Enum.RiPei, (int)Enum_Product_Expend_Rate_Type.High_Expend_Rate))
                                {
                                    ProductExpendModel high_model = new ProductExpendModel();
                                    high_model.product_id          = item.Key.product_id;
                                    high_model.product_name        = item.Key.product_name;
                                    high_model.average_expend_rate = average_expend_rate;
                                    high_model.expend_rate         = average_expend_rate.ToString("f2") + "%";
                                    model.High_Rate.Add(high_model);
                                }

                                //日配商品消化率过低,消化率50%
                                if (average_expend_rate < SystemCommon.GetExpendRate(item.Key.product_id, (int)Product_Category_Enum.RiPei, (int)Enum_Product_Expend_Rate_Type.Low_Expend_Rate))
                                {
                                    ProductExpendModel high_model = new ProductExpendModel();
                                    high_model.product_id          = item.Key.product_id;
                                    high_model.product_name        = item.Key.product_name;
                                    high_model.average_expend_rate = average_expend_rate;
                                    high_model.expend_rate         = average_expend_rate.ToString("f2") + "%";
                                    model.Low_Rate.Add(high_model);
                                }
                            }
                            else if (category == (int)Product_Category_Enum.NoRiPei)
                            {
                                //非日配商品消化率过高,消化率30%,上下五个点
                                if (average_expend_rate >= SystemCommon.GetExpendRate(item.Key.product_id, (int)Product_Category_Enum.NoRiPei, (int)Enum_Product_Expend_Rate_Type.High_Expend_Rate))
                                {
                                    ProductExpendModel high_model = new ProductExpendModel();
                                    high_model.product_id          = item.Key.product_id;
                                    high_model.product_name        = item.Key.product_name;
                                    high_model.average_expend_rate = average_expend_rate;
                                    high_model.expend_rate         = average_expend_rate.ToString("f2") + "%";
                                    model.High_Rate.Add(high_model);
                                }

                                //非日配商品消化率过低,消化率10%
                                if (average_expend_rate < SystemCommon.GetExpendRate(item.Key.product_id, (int)Product_Category_Enum.NoRiPei, (int)Enum_Product_Expend_Rate_Type.Low_Expend_Rate))
                                {
                                    ProductExpendModel high_model = new ProductExpendModel();
                                    high_model.product_id          = item.Key.product_id;
                                    high_model.product_name        = item.Key.product_name;
                                    high_model.average_expend_rate = average_expend_rate;
                                    high_model.expend_rate         = average_expend_rate.ToString("f2") + "%";
                                    model.Low_Rate.Add(high_model);
                                }
                            }
                        }

                        if (model.High_Rate.Any() && model.High_Rate.Count > 5)
                        {
                            model.High_Rate = model.High_Rate.OrderByDescending(a => a.average_expend_rate).Take(5).ToList();
                        }

                        if (model.Low_Rate.Any() && model.Low_Rate.Count > 5)
                        {
                            model.Low_Rate = model.Low_Rate.OrderByDescending(a => a.average_expend_rate).Take(5).ToList();
                        }
                    }

                    return(model);
                }
            }
            catch (Exception ex)
            {
            }

            return(null);
        }
Exemplo n.º 19
0
        public IHttpActionResult GetUserTradeData(int user_id)
        {
            try
            {
                using (ERPDBEntities db = new ERPDBEntities())
                {
                    Staff staff_auth = db.Staff.FirstOrDefault(a => a.id == user_id);
                    if (staff_auth == null)
                    {
                        return(Json(new { result = "员工不存在" }));
                    }

                    DateTime   start_time   = DateTime.Now.Date;
                    DateTime   end_time     = start_time.AddDays(1);
                    List <int> product_type = staff_auth.sell_product_type.Split(',').Select(a => int.Parse(a)).ToList();

                    var query = (from a in db.Sell_Record
                                 join b in db.Product on a.product_id equals b.product_id
                                 where a.create_time >= start_time && a.create_time < end_time && product_type.Contains(b.product_type)
                                 select new
                    {
                        a.product_id,
                        a.product_name,
                        a.sell_count,
                        a.delivery_count,
                        a.trash_count,
                        b.product_type,
                        b.stock_count,
                        b.price
                    }).ToList();

                    List <UserTradeDataModel> list = new List <UserTradeDataModel>();
                    var group_data = query.GroupBy(a => a.product_type);
                    foreach (var item in group_data)
                    {
                        UserTradeDataModel model = new UserTradeDataModel();
                        model.product_type = SystemCommon.GetDescription((Product_Type_Enum)Enum.ToObject(typeof(Product_Type_Enum), item.Key));
                        foreach (var pro in item)
                        {
                            ProductSellModel sell_model = new ProductSellModel();
                            sell_model.product_id     = pro.product_id;
                            sell_model.product_name   = pro.product_name;
                            sell_model.delivery_count = pro.delivery_count;     //交货
                            sell_model.sell_count     = pro.sell_count;
                            sell_model.product_price  = pro.price;
                            sell_model.sell_amount    = pro.sell_count * pro.price;
                            model.sell_info.Add(sell_model);
                        }

                        model.total_sell_amount    = model.sell_info.Sum(a => a.sell_amount);
                        model.total_sell_count     = model.sell_info.Sum(a => a.sell_count);
                        model.total_delivery_count = model.sell_info.Sum(a => a.delivery_count);
                        list.Add(model);
                    }

                    return(Json(new { result = list }));
                }
            }
            catch (Exception ex)
            {
            }
            return(NotFound());
        }
Exemplo n.º 20
0
        public IHttpActionResult GetLowExpendRateProduct()
        {
            try
            {
                List <ProductExpendRateStandardDeviationModel> list = new List <ProductExpendRateStandardDeviationModel>();
                using (ERPDBEntities db = new ERPDBEntities())
                {
                    var query = (from a in db.Product join b in db.Sell_Record on a.product_id equals b.product_id select new { a.product_id, a.product_name, a.stock_count, b.sell_count, a.product_category }).ToList();
                    if (query.Any())
                    {
                        var ri_pei    = query.Where(a => a.product_category == (int)Product_Category_Enum.RiPei).GroupBy(a => new { a.product_id, a.product_name });
                        var no_ri_pei = query.Where(a => a.product_category == (int)Product_Category_Enum.NoRiPei).GroupBy(a => new { a.product_id, a.product_name });

                        if (ri_pei.Any())
                        {
                            foreach (var item in ri_pei)
                            {
                                List <double> expend_rate = new List <double>();
                                foreach (var info in item)
                                {
                                    double rate = ((double)info.sell_count / (double)info.stock_count) * 100;
                                    expend_rate.Add(rate);
                                }

                                double expent_rate_sd = SystemCommon.GetStdDev(expend_rate, false);
                                if (expent_rate_sd < 50) //日配商品消化率低于50%
                                {
                                    ProductExpendRateStandardDeviationModel model = new ProductExpendRateStandardDeviationModel();
                                    model.product_id     = item.Key.product_id;
                                    model.product_name   = item.Key.product_name;
                                    model.expend_rate_sd = SystemCommon.GetStdDev(expend_rate, false);
                                    list.Add(model);
                                }
                            }
                        }

                        if (no_ri_pei.Any())
                        {
                            foreach (var item in ri_pei)
                            {
                                List <double> expend_rate = new List <double>();
                                foreach (var info in item)
                                {
                                    double rate = ((double)info.sell_count / (double)info.stock_count) * 100;
                                    expend_rate.Add(rate);
                                }

                                double expent_rate_sd = SystemCommon.GetStdDev(expend_rate, false);
                                if (expent_rate_sd < 10) //非日配商品消化率低于10%
                                {
                                    ProductExpendRateStandardDeviationModel model = new ProductExpendRateStandardDeviationModel();
                                    model.product_id     = item.Key.product_id;
                                    model.product_name   = item.Key.product_name;
                                    model.expend_rate_sd = SystemCommon.GetStdDev(expend_rate, false);
                                    list.Add(model);
                                }
                            }
                        }
                    }

                    return(Json(new { result = list }));
                }
            }
            catch (Exception ex)
            {
            }

            return(Json(new { result = "系统异常" }));
        }
Exemplo n.º 21
0
        public IHttpActionResult ChangeProductExpendRate(string product_id, double rate)
        {
            try
            {
                if (string.IsNullOrEmpty(product_id))
                {
                    return(Json(new { result = "参数错误" }));
                }

                using (ERPDBEntities db = new ERPDBEntities())
                {
                    var expend_rate = db.Product_Expend_Rate_Config.FirstOrDefault(a => a.product_id == product_id);
                    if (expend_rate == null)
                    {
                        var product_info = db.Product.FirstOrDefault(a => a.product_id == product_id);
                        if (product_info == null)
                        {
                            return(Json(new { result = "商品信息异常" }));
                        }

                        expend_rate                  = new Product_Expend_Rate_Config();
                        expend_rate.product_id       = product_info.product_id;
                        expend_rate.product_name     = product_info.product_name;
                        expend_rate.product_type     = product_info.product_type;
                        expend_rate.product_category = product_info.product_category;
                        expend_rate.high_expend_rate = product_info.product_category == (int)Product_Category_Enum.RiPei ? SystemCommon.Ri_Pei_High_Expend_Rate : SystemCommon.No_Ri_Pei_High_Expend_Rate;

                        if (rate > 0)
                        {
                            expend_rate.low_expend_rate = rate;
                        }
                        else
                        {
                            expend_rate.low_expend_rate = product_info.product_category == (int)Product_Category_Enum.RiPei ? SystemCommon.Ri_Pei_Low_Expend_Rate : SystemCommon.No_Ri_Pei_Low_Expend_Rate;
                        }

                        expend_rate.create_time     = DateTime.Now;
                        expend_rate.update_time     = DateTime.Now;
                        db.Entry(expend_rate).State = System.Data.Entity.EntityState.Added;
                        if (db.SaveChanges() < 0)
                        {
                            return(Json(new { result = "设置失败" }));
                        }

                        return(Json(new { result = "设置成功" }));
                    }

                    expend_rate.low_expend_rate = rate;
                    expend_rate.update_time     = DateTime.Now;
                    db.Entry(expend_rate).State = System.Data.Entity.EntityState.Modified;
                    if (db.SaveChanges() < 0)
                    {
                        return(Json(new { result = "设置失败" }));
                    }

                    return(Json(new { result = "设置成功" }));
                }
            }
            catch (Exception ex)
            {
            }

            return(Json(new { result = "系统异常" }));
        }