Beispiel #1
0
        public JsonHelp FenXiang(DbMallEntities db, Member_Info member)
        {
            JsonHelp json = new JsonHelp()
            {
                IsSuccess = true, Msg = ""
            };
            var Recommend = db.Member_Info.Where(p => p.MemberId == member.RecommendId).FirstOrDefault();

            for (int i = 1; i <= 2; i++)
            {
                if (Recommend == null)
                {
                    return(json);
                }
                decimal?amount = 0;
                if (i == 1)
                {
                    amount = System.DB.XmlConfig.XmlSite.FenXiang1;
                }
                else if (i == 2)
                {
                    amount = System.DB.XmlConfig.XmlSite.FenXiang1;
                }
                if (amount > 0)
                {
                    InsertFin(db, Recommend, member, amount.Value, "分享消费奖", "分享消费奖");
                    FuDaoJ(db, Recommend, amount.Value);
                }
                Recommend = db.Member_Info.Where(p => p.MemberId == Recommend.RecommendId).FirstOrDefault();
            }
            return(json);
        }
Beispiel #2
0
 public List <Sys_BasicData> getBasicDataByType(string type)
 {
     using (var db = new DbMallEntities())
     {
         var list = from a in db.Sys_BasicData
                    join b in db.Sys_BasicType.Where(a => a.TypeName == type) on a.TypeId equals b.Id
                    orderby a.SortValue
                    select a;
         return(list.ToList());
     }
 }
Beispiel #3
0
        public JsonHelp Delete(string idList)
        {
            JsonHelp json = new JsonHelp()
            {
                Status = "n", Msg = "删除数据失败"
            };

            try
            {
                //是否为空
                if (string.IsNullOrEmpty(idList))
                {
                    json.Msg = "未找到要删除的数据"; return(json);
                }
                var id = idList.TrimEnd(',').Split(',').Select(a => Convert.ToInt32(a)).ToList();

                try
                {
                    using (var db = new DbMallEntities())
                    {
                        //删除订单的同时,奖下单时产生的电子币加回去
                        var list = db.Bill_Info.Where(a => id.Contains(a.BillId));
                        if (list.Any(a => a.State == "已发货"))
                        {
                            json.Msg = "选择订单中包含已发货订单,请重新选择;";
                            return(json);
                        }
                        foreach (var item in list)
                        {
                            var member = db.Member_Info.Find(item.MemberId);
                            member.Coins += item.TotalPrice;
                            db.Bill_Info.Remove(item);
                        }
                        //删除这些对象
                        var r = db.SaveChanges();
                        if (r > 0)
                        {
                            json.Status = "y";
                            json.Msg    = "删除数据成功";
                            //添加操作日志
                            DB.SysLogs.setAdminLog(Enums.EventType.Delete, "删除 ID为【" + idList + "】的订单信息");
                        }
                    }
                }
                catch
                {
                    throw;
                }
                return(json);
            }
            catch (Exception e) { throw e.InnerException; }
        }
Beispiel #4
0
 public ActionResult ResetRPosition(string q)
 {
     if (q == "zhijukejixsy888")
     {
         using (var db = new DbMallEntities())
         {
             var list  = db.Member_Info.ToList();
             var admin = list.FirstOrDefault(a => a.Code == "admin");
             admin.RPosition = "0|";
             updatechild_rposition(admin, list);
             db.SaveChanges();
         }
         return(Content(DateTime.Now + "_succss"));
     }
     return(View());
 }
Beispiel #5
0
        /// <summary>
        /// 收益结算
        /// </summary>
        /// <param name="date"></param>
        /// <param name="db"></param>
        /// <param name="curPrice"></param>
        /// <param name="isBefore">是否结算date以前的</param>
        public void ToSettlement(DateTime date, DbMallEntities db, bool isBefore)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            int count = 0;
            var start = date.Date;
            var end   = start.AddDays(1);
            var query = db.Fin_Info.Where(a => true && a.CreateTime < end);

            if (isBefore == false)
            {
                query = query.Where(a => a.CreateTime >= start);
            }
            var list = query.ToList();

            var memberids = list.GroupBy(a => a.MemberId).Select(a => a.Key).ToList();
            var members   = db.Member_Info.Where(a => memberids.Contains(a.MemberId)).ToList();

            foreach (var item in members)
            {
                #region 更新收益
                var comList = list.Where(a => a.MemberId == item.MemberId).ToList();
                if (comList.Count > 0)
                {
                    foreach (var citem in comList)
                    {
                        citem.IsSettlement   = true;
                        citem.SettlementTime = DateTime.Now;
                    }
                    //更新会员收益
                    var realAmount = comList.Sum(a => a.RealAmount) ?? 0;
                    item.Commission    += realAmount;
                    item.CommissionSum += realAmount;
                    count++;
                }
                #endregion
            }
            db.SaveChanges();
            sw.Stop();
            LogHelper.Info(string.Format("收益结算 日期:{2},会员[{0}]个,分配奖[{3}]个,用时:[{1}]]", list.Count, sw.Elapsed, date.ToString("yyyy-MM-dd"), count));
        }
Beispiel #6
0
        public JsonHelp FuDaoJ(DbMallEntities db, Member_Info member, decimal Money)
        {
            JsonHelp json = new JsonHelp()
            {
                IsSuccess = true, Msg = ""
            };
            var Recommend = DB.Member_Info.FindEntity(member.RecommendId);

            if (Recommend != null)
            {
                var count = DB.Member_Info.Count(p => p.RecommendId == Recommend.MemberId && p.IsActive == "已激活");
                if (count >= 3)
                {
                    decimal?amount = Money * System.DB.XmlConfig.XmlSite.FuDao / 100m;
                    if (amount > 0)
                    {
                        InsertFin(db, Recommend, member, amount.Value, "辅导奖", "辅导奖");
                    }
                }
            }
            return(json);
        }
Beispiel #7
0
 /// <summary>
 /// 定时任务执行的内容
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="ex"></param>
 public void TimerHanlder()
 {
     #region 这里写你的定时任务要执行的程序代码(数据库操作,不要使用 Business.DB,请重新自定义个上下文)
     using (var DB = new DbMallEntities())
     {
         var list = DB.ShopOrders.Where(p => p.Type == "未挂卖").ToList();
         foreach (var item in list)
         {
             if ((int)Math.Floor((DateTime.Now - item.SubmitTime).TotalHours) >= 48)
             {
                 item.State = ShopEnum.OrderState.Cancel.GetHashCode();
                 item.Type  = "已超时";
                 var member = DB.Member_Info.Where(p => p.MemberId == item.MemberID).FirstOrDefault();
                 member.Commission    = member.Commission + item.RealScore;
                 member.CommissionSum = member.CommissionSum + item.RealScore;
                 member.Scores        = member.Scores + item.RealCongXiao;
             }
         }
         var listMember = DB.ShopOrders.Where(p => p.Type == "挂卖中" && p.State == 40).ToList();
         foreach (var item in listMember)
         {
             if ((int)Math.Floor((DateTime.Now - item.SubmitTime).TotalHours) >= 168)
             {
                 item.State      = ShopEnum.OrderState.Finish.GetHashCode();
                 item.Type       = "挂卖成功";
                 item.FinishTime = DateTime.Now;
                 var member = DB.Member_Info.Where(p => p.MemberId == item.MemberID).FirstOrDefault();
                 //DB.Jiang.InsertFin(member, member, 800, "挂卖奖励积分", "挂卖奖励积分");//积分
                 InsertFin(DB, member, member, 2100, "委托奖励收益", "委托奖励收益");//收益
                 //分享消费奖
                 FenXiang(DB, member);
                 //辅导奖
             }
         }
         DB.SaveChanges();
     }
     #endregion
 }
Beispiel #8
0
        /// <summary>
        /// 增加奖金
        /// </summary>
        /// <param name="member">要增加奖金的会员,</param>
        /// <param name="refMember">相关的会员,</param>
        /// <param name="amount">金额</param>
        /// <param name="db">数据库连接实例</param>
        /// <param name="typeName">奖金类型名称</param>
        /// <param name="Comment">奖金描述</param>
        /// <returns></returns>
        public JsonHelp InsertFin(DbMallEntities db, Member_Info member, Member_Info refMember, decimal amount, string typeName, string Comment)
        {
            JsonHelp json = new JsonHelp(true);

            if (amount < 0)
            {
                json.Msg = "奖金不能小于0";
                return(json);
            }
            else if (amount == 0)
            {
                //奖金为0,直接返回,不向数据库增加数据
                json.Msg = "奖金为0";
                return(json);
            }
            //检查是否锁定此会员不得奖
            if (member.IsLockCommission == true)
            {
                json.Msg = "此会员已锁定得奖,奖金不能分配";
                return(json);
            }
            var Poundage  = System.DB.XmlConfig.XmlSite.Poundage;
            var ChongXiao = System.DB.XmlConfig.XmlSite.ChongXiao;


            //插入费用明细
            var mFin = new Fin_Info();

            mFin.MemberId   = member.MemberId;
            mFin.MemberCode = member.Code;
            mFin.NickName   = member.NickName;
            mFin.Amount     = amount;
            if (typeName == "挂卖奖励收益")
            {
                mFin.Poundage = 0;
                mFin.CongXiao = 0;
                if (typeName == "挂卖奖励收益")
                {
                    mFin.RealAmount = 2100;
                }
            }
            else
            {
                mFin.Poundage   = 0;
                mFin.CongXiao   = 0;
                mFin.RealAmount = mFin.Amount;
            }
            mFin.TypeName       = typeName;
            mFin.Comment        = string.IsNullOrEmpty(Comment) ? typeName : Comment;
            mFin.RefMemberId    = refMember.MemberId;
            mFin.RefMemberCode  = refMember.Code;
            mFin.RefNickName    = refMember.NickName;
            mFin.CreateTime     = DateTime.Now;
            mFin.IsSettlement   = true;
            mFin.SettlementTime = mFin.CreateTime;
            db.Fin_Info.Add(mFin);
            if (typeName == "挂卖奖励收益")
            {
                if (typeName == "挂卖奖励收益")
                {
                    member.Commission    += Convert.ToDecimal(mFin.RealAmount);
                    member.CommissionSum += Convert.ToDecimal(mFin.RealAmount);
                    Fin_LiuShui _liushui = new Fin_LiuShui();
                    //收益
                    _liushui.MemberId   = member.MemberId;
                    _liushui.Code       = member.Code;
                    _liushui.NickName   = member.NickName;
                    _liushui.Type       = "流水账单";
                    _liushui.Comment    = "收益(+)";
                    _liushui.Amount     = mFin.RealAmount;
                    _liushui.CreateTime = DateTime.Now;
                    DB.Fin_LiuShui.Insert(_liushui);
                    //累计收益
                    _liushui.MemberId   = member.MemberId;
                    _liushui.Code       = member.Code;
                    _liushui.NickName   = member.NickName;
                    _liushui.Type       = "流水账单";
                    _liushui.Comment    = "累计收益(+)";
                    _liushui.Amount     = mFin.RealAmount;
                    _liushui.CreateTime = DateTime.Now;
                }
            }
            else
            {
                member.Commission    += mFin.RealAmount;
                member.CommissionSum += mFin.RealAmount;
                //收益
                Fin_LiuShui _liushui = new Fin_LiuShui();
                _liushui.MemberId   = member.MemberId;
                _liushui.Code       = member.Code;
                _liushui.NickName   = member.NickName;
                _liushui.Type       = "流水账单";
                _liushui.Comment    = "收益(+)";
                _liushui.Amount     = mFin.RealAmount;
                _liushui.CreateTime = DateTime.Now;
                //累计收益
                _liushui.MemberId   = member.MemberId;
                _liushui.Code       = member.Code;
                _liushui.NickName   = member.NickName;
                _liushui.Type       = "流水账单";
                _liushui.Comment    = "累计收益(+)";
                _liushui.Amount     = mFin.RealAmount;
                _liushui.CreateTime = DateTime.Now;
            }
            json.Msg = "插入奖金成功";
            return(json);
        }
Beispiel #9
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="role">角色对象</param>
        /// <param name="rolenav">权限集合</param>
        /// <param name="id">权限ID</param>
        /// <returns></returns>
        public JsonHelp Save(int id, string name, byte roletype, string rolenav)
        {
            JsonHelp json = new JsonHelp()
            {
                Status = "n", Msg = "保存失败"
            };
            List <Sys_Role_Nav> role_nav = new List <Sys_Role_Nav>();

            using (var db = new DbMallEntities())
            {
                try
                {
                    if (!Any(p => p.id == id))
                    {
                        Sys_Role entity = new Sys_Role();
                        entity.role_name = name;
                        entity.role_type = roletype;
                        db.Sys_Role.Add(entity);
                        db.SaveChanges();
                        var str = rolenav.Trim(',').Split(',');
                        for (int i = 0; i < str.Length; i++)
                        {
                            var          role_name = str[i].Split('&')[0];
                            var          role_type = str[i].Split('&')[1];
                            Sys_Role_Nav role      = new Sys_Role_Nav();
                            role.role_id     = entity.id;
                            role.nav_name    = role_name.ToString();
                            role.action_type = role_type.ToString();
                            role_nav.Add(role);
                            db.Sys_Role_Nav.Add(role);
                        }
                        db.SaveChanges();
                        json.Status = "y";
                        json.Msg    = "保存成功";
                        DB.CacheRoleId++;
                        //添加操作日志
                        DB.SysLogs.setAdminLog("Add", "新建名称为[" + entity.role_name + "]的角色");
                    }
                    else
                    {
                        var model = db.Sys_Role.Find(id);
                        model.id        = id;
                        model.role_name = name;
                        model.role_type = roletype;

                        var str = rolenav.Trim(',').Split(',');
                        for (int i = 0; i < str.Length; i++)
                        {
                            var role_name = str[i].Split('&')[0];
                            var role_type = str[i].Split('&')[1];

                            Sys_Role_Nav role = new Sys_Role_Nav();
                            role.role_id     = id;
                            role.nav_name    = role_name.ToString();
                            role.action_type = role_type.ToString();
                            role_nav.Add(role);
                        }
                        var oldNav = db.Sys_Role_Nav.Where(p => p.role_id == id);
                        //先删除原来多余的
                        foreach (var item in oldNav)
                        {
                            var exsit = role_nav.Any(a => a.nav_name == item.nav_name && a.action_type == item.action_type);
                            if (exsit == false)
                            {
                                db.Sys_Role_Nav.Remove(item);
                            }
                        }
                        //再添加原来没有的
                        foreach (var item in role_nav)
                        {
                            var exsit = oldNav.FirstOrDefault(a => a.nav_name == item.nav_name && a.action_type == item.action_type);
                            if (exsit == null)
                            {
                                db.Sys_Role_Nav.Add(item);
                            }
                        }

                        db.SaveChanges();
                        json.Status = "y";
                        json.Msg    = "保存成功";
                        DB.CacheRoleId++;
                        //添加操作日志
                        DB.SysLogs.setAdminLog("Edit", "更新名称为[" + name + "]的角色");
                    }
                }
                catch (Exception e)
                {
                    json.IsSuccess = false;
                    LogHelper.Error("角色保存失败:" + e.Message);
                }
            }
            return(json);
        }
Beispiel #10
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public JsonHelp Save(Allocation_Info entity)
        {
            var json = new JsonHelp(true, "分红成功");

            using (var db = new DbMallEntities())
            {
                try
                {
                    if (entity.StartTime != null)
                    {
                        entity.StartTime = entity.StartTime.Value.AddDays(1);
                    }

                    #region 给每个会员分红

                    var     list       = db.Member_Info.Where(a => a.IsActive == "已激活" && a.Code != "admin" && a.IsNullActive != true && a.IsLockFen != true);
                    decimal?sum        = 0M;
                    var     nullMember = new Member_Info();
                    var     comment1   = "分红奖";
                    var     comment2   = "分红奖累计已达到投资额,后面将不再产生分红奖";
                    foreach (var item in list)
                    {
                        //var ReCount = db.Member_Info.Count(p => p.RecommendId == item.MemberId && p.IsActive == "已激活");
                        //decimal? FengD = 0;
                        //if (ReCount >= 2)
                        //{
                        //    FengD = item.ActiveAmount * 2;
                        //}
                        //else if (ReCount >= 1)
                        //{
                        //    FengD = item.ActiveAmount * 1.5m;
                        //}
                        //else if (ReCount < 1)
                        //{
                        //    FengD = item.ActiveAmount;
                        //}
                        decimal?FengD = 0;
                        if (item.MemberLevelId == 1)
                        {
                            FengD = item.ActiveAmount * 1;
                        }
                        else if (item.MemberLevelId == 2)
                        {
                            FengD = item.ActiveAmount * 1.5m;
                        }
                        else if (item.MemberLevelId == 3)
                        {
                            FengD = item.ActiveAmount * 2;
                        }
                        //判断分红金额累计 是否 会超过 投资额(这里的条件是以投资额作为封顶)
                        var realAmount = entity.PerAmount;
                        if (item.MemberLevelId == 1)
                        {
                            realAmount = entity.PerAmount;
                        }
                        else if (item.MemberLevelId == 2)
                        {
                            realAmount = entity.PerAmount2;
                        }
                        else if (item.MemberLevelId == 3)
                        {
                            realAmount = entity.PerAmount3;
                        }
                        string comment = comment1;
                        if (FengD <= realAmount + item.FHSum)
                        {
                            comment    = comment2;
                            realAmount = FengD - item.FHSum;
                            if (realAmount < 0)
                            {
                                realAmount = 0;
                            }
                        }
                        sum       += realAmount; //求总的实发金额
                        item.FHSum = item.FHSum + realAmount;
                        //插入收益
                        json = DB.Jiang.InsertFin(db, item, nullMember, realAmount.Value, "分红", comment);
                    }
                    #endregion

                    #region 更新实际金额(总)
                    entity.RealAmount = sum;
                    db.Allocation_Info.Add(entity);
                    #endregion

                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    json.IsSuccess = false;
                    LogHelper.Error("分红失败:" + WebTools.getFinalException(e));
                }
            }
            return(json);
        }
Beispiel #11
0
        /// <summary>
        /// 增加佣金
        /// </summary>
        /// <param name="db">数据库实体</param>
        /// <param name="member">要增加佣金的会员,</param>
        /// <param name="refMember">相关的会员,</param>
        /// <param name="amount">金额</param>
        /// <param name="db">数据库连接实例</param>
        /// <param name="typeName">佣金类型名称</param>
        /// <param name="Comment">佣金描述</param>
        /// <returns></returns>DbMallEntities
        public JsonHelp InsertFin(DbMallEntities db, Member_Info member, Member_Info refMember, decimal amount, string typeName, string Comment = "")
        {
            JsonHelp json = new JsonHelp(true);

            if (amount < 0)
            {
                json.Msg = "佣金不能小于0";
                return(json);
            }
            else if (amount == 0)
            {
                //佣金为0,直接返回,不向数据库增加数据
                json.Msg = "佣金为0";
                return(json);
            }
            //检查是否锁定此会员不得奖
            if (member.IsLockCommission == true)
            {
                json.Msg = "此会员已锁定得奖,佣金不能分配";
                return(json);
            }

            var Poundage  = DB.XmlConfig.XmlSite.Poundage;
            var ChongXiao = DB.XmlConfig.XmlSite.ChongXiao;
            //插入费用明细
            var mFin = new Fin_Info();

            mFin.MemberId      = member.MemberId;
            mFin.MemberCode    = member.Code;
            mFin.NickName      = member.NickName;
            mFin.Amount        = amount;
            mFin.Poundage      = amount * Poundage / 100m;
            mFin.CongXiao      = amount * ChongXiao / 100m;
            mFin.RealAmount    = mFin.Amount - mFin.Poundage;
            mFin.TypeName      = typeName;
            mFin.Comment       = string.IsNullOrEmpty(Comment) ? typeName : Comment;
            mFin.RefMemberId   = refMember.MemberId;
            mFin.RefMemberCode = refMember.Code;
            mFin.RefNickName   = refMember.NickName;
            mFin.CreateTime    = DateTime.Now;
            if (DB.XmlConfig.XmlSite.IsMiaoJie == true)
            {
                mFin.IsSettlement   = true;
                mFin.SettlementTime = mFin.CreateTime;
            }
            else
            {
                mFin.IsSettlement = false;
            }
            db.Fin_Info.Add(mFin);
            if (DB.XmlConfig.XmlSite.IsMiaoJie == true)
            {
                var Comminssion = mFin.RealAmount * 50 / 100m;
                var Coins       = mFin.RealAmount * 50 / 100m;
                member.Commission    += Comminssion;
                member.CommissionSum += Comminssion;
                member.Coins         += Coins;
                member.ShopCoins     += Convert.ToDecimal(mFin.CongXiao);
            }
            json.Msg = "插入佣金成功";
            return(json);
        }
Beispiel #12
0
        // GET: SysManage/Home
        public ActionResult Index()
        {
            var start_day   = DateTime.Now.Date;
            var end_day     = start_day.AddDays(1);
            var start_week  = getMonday();
            var end_week    = getSunday();
            var start_month = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            var end_month   = start_month.AddMonths(1);
            var start_year  = new DateTime(DateTime.Now.Year, 1, 1);
            var end_year    = start_year.AddYears(1);



            #region 减少数据库查询次数
            using (var db = new DbMallEntities())
            {
                var r = db.Sys_Level.Where(a => true).Select(x => new
                {
                    addMember_dd   = db.Member_Info.Count(a => a.CreateTime >= start_day && a.CreateTime < end_day),
                    addMember_week = db.Member_Info.Count(a => a.CreateTime >= start_week && a.CreateTime < end_week),
                    addMember_mm   = db.Member_Info.Count(a => a.CreateTime >= start_month && a.CreateTime < end_month),
                    addMember_yy   = db.Member_Info.Count(a => a.CreateTime >= start_year && a.CreateTime < end_year),

                    income_dd   = db.ShopOrders.Where(a => a.PayTime >= start_day && a.OrderType != "积分优惠价" && a.PayTime < end_day).Sum(a => (decimal?)a.RealAmount) ?? 0,
                    income_week = db.ShopOrders.Where(a => a.PayTime >= start_week && a.OrderType != "积分优惠价" && a.PayTime < end_day).Sum(a => (decimal?)a.RealAmount) ?? 0,
                    income_mm   = db.ShopOrders.Where(a => a.PayTime >= start_month && a.OrderType != "积分优惠价" && a.PayTime < end_month).Sum(a => (decimal?)a.RealAmount) ?? 0,
                    income_yy   = db.ShopOrders.Where(a => a.PayTime >= start_year && a.OrderType != "积分优惠价" && a.PayTime < end_year).Sum(a => (decimal?)a.RealAmount) ?? 0,

                    income_dds   = db.ShopOrders.Where(a => a.PayTime >= start_day && a.OrderType == "积分优惠价" && a.PayTime < end_day).Sum(a => (decimal?)a.RealAmount) ?? 0,
                    income_weeks = db.ShopOrders.Where(a => a.PayTime >= start_week && a.OrderType == "积分优惠价" && a.PayTime < end_day).Sum(a => (decimal?)a.RealAmount) ?? 0,
                    income_mms   = db.ShopOrders.Where(a => a.PayTime >= start_month && a.OrderType == "积分优惠价" && a.PayTime < end_month).Sum(a => (decimal?)a.RealAmount) ?? 0,
                    income_yys   = db.ShopOrders.Where(a => a.PayTime >= start_year && a.OrderType == "积分优惠价" && a.PayTime < end_year).Sum(a => (decimal?)a.RealAmount) ?? 0,

                    //income_dd = db.ShopOrders.Where(a => a.PayTime >= start_day && a.PayTime < end_day).Sum(a => a.RealAmount),
                    //income_week = db.ShopOrders.Where(a => a.PayTime >= start_week && a.PayTime < end_day).Sum(a => a.RealAmount),
                    //income_mm = db.ShopOrders.Where(a => a.PayTime >= start_month && a.PayTime < end_month).Sum(a => a.RealAmount),
                    //income_yy = db.ShopOrders.Where(a => a.PayTime >= start_year && a.PayTime < end_year).Sum(a => a.RealAmount),

                    expend_dd   = db.Fin_Info.Where(a => a.CreateTime >= start_day && a.CreateTime < end_day).Sum(a => a.RealAmount),
                    expend_week = db.Fin_Info.Where(a => a.CreateTime >= start_week && a.CreateTime < end_week).Sum(a => a.RealAmount),
                    expend_mm   = db.Fin_Info.Where(a => a.CreateTime >= start_month && a.CreateTime < end_month).Sum(a => a.RealAmount),
                    expend_yy   = db.Fin_Info.Where(a => a.CreateTime >= start_year && a.CreateTime < end_year).Sum(a => a.RealAmount),

                    Active_y   = db.Sys_Msg.Count(p => p.State == 0),
                    Active_n   = db.ShopOrders.Count(p => p.State == 2),
                    Drawcount  = db.Fin_Draw.Count(p => p.DrawState == "未发放"),
                    Remitcount = db.Fin_Remit.Count(p => p.RemitState == "申请中")
                }).FirstOrDefault();
                ViewBag.addMember_dd   = r.addMember_dd;
                ViewBag.addMember_week = r.addMember_week;
                ViewBag.addMember_mm   = r.addMember_mm;
                ViewBag.addMember_yy   = r.addMember_yy;

                ViewBag.income_dd   = r.income_dd;
                ViewBag.income_week = r.income_week;
                ViewBag.income_mm   = r.income_mm;
                ViewBag.income_yy   = r.income_yy;

                ViewBag.income_dds   = r.income_dds;
                ViewBag.income_weeks = r.income_weeks;
                ViewBag.income_mms   = r.income_mms;
                ViewBag.income_yys   = r.income_yys;

                ViewBag.expend_dd   = r.expend_dd ?? 0;
                ViewBag.expend_week = r.expend_week ?? 0;
                ViewBag.expend_mm   = r.expend_mm ?? 0;
                ViewBag.expend_yy   = r.expend_yy ?? 0;

                ViewBag.Active_y   = r.Active_y;
                ViewBag.Active_n   = r.Active_n;
                ViewBag.Drawcount  = r.Drawcount;
                ViewBag.Remitcount = r.Remitcount;

                ViewBag.OutIn_dd   = getOutIn(Convert.ToDecimal(ViewBag.income_dd), Convert.ToDecimal(ViewBag.expend_dd));
                ViewBag.OutIn_week = getOutIn(Convert.ToDecimal(ViewBag.income_week), Convert.ToDecimal(ViewBag.expend_week));
                ViewBag.OutIn_mm   = getOutIn(Convert.ToDecimal(ViewBag.income_mm), Convert.ToDecimal(ViewBag.expend_mm));
                ViewBag.OutIn_yy   = getOutIn(Convert.ToDecimal(ViewBag.income_yy), Convert.ToDecimal(ViewBag.expend_yy));
            }
            #endregion

            DB.XmlConfig.AutoSetUrl(Request);

            ViewBag.LingShouQuZongJin = DB.ShopOrder.Where(p => p.PayTime >= start_day && p.PayTime < end_day && p.OrderType == "零售区").Sum(p => (decimal?)p.RealAmount) ?? 0;
            ViewBag.LingShouQuCount   = DB.ShopOrder.Where(p => p.PayTime >= start_day && p.PayTime < end_day && p.OrderType == "零售区").Sum(p => (decimal?)p.Count) ?? 0;
            ViewBag.QiangGou          = DB.ShopOrder.Where(p => p.PayTime >= start_day && p.PayTime < end_day && p.Type == "挂卖中" && p.OrderType == "批发区").Count();;
            return(View());
        }
        public ActionResult Save(ShopProduct entity)
        {
            var json = new JsonHelp();
            //var shangpin = DB.ShopProductCategory.FindEntity(p => p.ID == entity.CategoryID1);
            var shop = DB.Shop.FindEntity(p => p.ID == 1);

            entity.UpdateTime = DateTime.Now;
            var imgs1 = Request["imgpath1"];
            var imgs2 = Request["imgpath2"];

            try
            {
                using (var db = new DbMallEntities())
                {
                    if (entity.ID == 0)
                    {
                        // entity.PriceCongXiao = 0;
                        //if (entity.CategoryID1 == ShopEnum.ShopType.订单商品.GetHashCode())
                        //{
                        //    entity.PriceScore = 0;
                        //    entity.PriceVip = 0;
                        //}
                        if (shop == null)
                        {
                            json.IsSuccess = false;
                            json.Msg       = "添加失败,您暂无商家权限";
                            return(Json(json));
                        }
                        else if (shop.IsCheck != true)
                        {
                            json.IsSuccess = false;
                            json.Msg       = "添加失败,您暂无商家权限";
                            return(Json(json));
                        }
                        //if (shangpin.Name == "优选区")
                        //{
                        //    if (entity.PriceShopping < 1)
                        //    {
                        //        json.IsSuccess = false;
                        //        json.Msg = "添加失败,现金价不准为0";
                        //        return Json(json);
                        //    }
                        //    if (entity.PV < 1)
                        //    {
                        //        json.IsSuccess = false;
                        //        json.Msg = "添加失败,积分价不准为0";
                        //        return Json(json);
                        //    }
                        //}
                        //else if (shangpin.Name == "消费区")
                        //{
                        //    if (entity.PriceShopping < 1)
                        //    {
                        //        json.IsSuccess = false;
                        //        json.Msg = "添加失败,现金价不准为0";
                        //        return Json(json);
                        //    }
                        //    if (entity.PV > 1)
                        //    {
                        //        json.IsSuccess = false;
                        //        json.Msg = "添加失败,积分不需要填写";
                        //        return Json(json);
                        //    }
                        //}
                        db.ShopProducts.Add(entity);
                        db.SaveChanges();
                        #region 添加商品相册图片
                        if (!string.IsNullOrEmpty(imgs1) && imgs1.EndsWith("&"))
                        {
                            var list1 = imgs1.Substring(0, imgs1.Length - 1).Split('&');
                            var list2 = imgs2.Substring(0, imgs2.Length - 1).Split('&');
                            if (list1.Length == list2.Length)
                            {
                                var xlist = new List <ShopProductImage>();
                                for (int i = 0; i < list1.Length; i++)
                                {
                                    var img = new ShopProductImage()
                                    {
                                        CreateTime = DateTime.Now,
                                        ProductID  = entity.ID,
                                        Sort       = i + 1,
                                        URL        = list1[i],
                                        ThumURL    = list2[i]
                                    };
                                    db.ShopProductImages.Add(img);
                                }
                                var first = db.ShopProducts.FirstOrDefault(a => a.ID == entity.ID);
                                first.Image = list1[0];
                            }
                            else
                            {
                                json.IsSuccess = false;
                                json.Msg       = "添加失败,请重试商品图片";
                                return(Json(json));
                            }
                        }
                        #endregion
                        json.Msg = "添加";
                    }
                    else
                    {
                        var first = db.ShopProducts.FirstOrDefault(a => a.ID == entity.ID);
                        WebTools.CopyToObject(entity, first);
                        //json.IsSuccess = DB.ShopProduct.Update(first);
                        #region 修改商品相册图片
                        //if (json.IsSuccess)
                        {
                            if (!string.IsNullOrEmpty(imgs1) && imgs1.EndsWith("&"))
                            {
                                var list1 = imgs1.Substring(0, imgs1.Length - 1).Split('&');
                                var list2 = imgs2.Substring(0, imgs2.Length - 1).Split('&');
                                if (list1.Length == list2.Length)
                                {
                                    var olds = db.ShopProductImages.Where(a => a.ProductID == entity.ID);
                                    #region 先删除多余的图片
                                    foreach (var item in olds)
                                    {
                                        var exsit = list1.Any(a => a == item.URL);
                                        if (exsit == false)
                                        {
                                            db.ShopProductImages.Remove(item);
                                        }
                                    }
                                    #endregion
                                    #region 再添加原来没有的
                                    for (int i = 0; i < list1.Length; i++)
                                    {
                                        var cururl = list1[i];
                                        var exsit  = olds.FirstOrDefault(a => a.URL == cururl);
                                        if (exsit == null)
                                        {
                                            var img = new ShopProductImage()
                                            {
                                                CreateTime = DateTime.Now,
                                                ProductID  = entity.ID,
                                                Sort       = i + 1,
                                                URL        = list1[i],
                                                ThumURL    = list2[i]
                                            };
                                            db.ShopProductImages.Add(img);
                                        }
                                    }
                                    #endregion
                                    if (list1.Length > 0)
                                    {
                                        first.Image = list1[0];
                                    }
                                }
                                else
                                {
                                    json.IsSuccess = false;
                                }
                            }
                        }
                        #endregion
                        json.Msg = "修改";
                    }
                    db.SaveChanges();
                    json.IsSuccess = true;
                }
            }
            catch (Exception e)
            {
                json.IsSuccess = false;
                LogHelper.Error("商品添加失败:" + WebTools.getFinalException(e));
            }
            if (json.IsSuccess)
            {
                json.ReUrl = ControllerPath + "/Index";   //注册成功就跳转到 激活页
                json.Msg  += "成功";
            }
            else
            {
                json.Msg += "失败";
            }
            return(Json(json));
        }