Beispiel #1
0
        public void GrantUserPermissions(int userId, Permissions permission)
        {
            if (userId == 0)
            {
                throw new KMBitException("");
            }
            List <Admin_Actions> actions = new List <Admin_Actions>();

            using (chargebitEntities db = new chargebitEntities())
            {
                List <Admin_Actions> allActions = (from ac in db.Admin_Actions select ac).ToList <Admin_Actions>();
                PropertyInfo[]       props      = permission.GetType().GetProperties();
                foreach (PropertyInfo prop in props)
                {
                    bool hasPermission = (bool)prop.GetValue(permission);
                    if (hasPermission)
                    {
                        Admin_Actions ac = (from acc in allActions where acc.Name == prop.Name select acc).FirstOrDefault <Admin_Actions>();
                        if (ac != null)
                        {
                            actions.Add(ac);
                        }
                    }
                }
            }

            GrantUserPermissions(userId, actions);
        }
Beispiel #2
0
        public bool UpdateResrouceInterface(Resrouce_interface api)
        {
            bool result          = false;
            chargebitEntities db = new chargebitEntities();

            try
            {
                Resrouce_interface oapi = (from a in db.Resrouce_interface where a.Resource_id == api.Resource_id select a).FirstOrDefault <Resrouce_interface>();
                if (oapi == null)
                {
                    db.Resrouce_interface.Add(api);
                }
                else
                {
                    oapi.APIURL        = api.APIURL;
                    oapi.CallBackUrl   = api.CallBackUrl;
                    oapi.Username      = api.Username;
                    oapi.Userpassword  = api.Userpassword;
                    oapi.ProductApiUrl = api.ProductApiUrl;
                }

                db.SaveChanges();
                result = true;
            }catch (Exception ex)
            {
            }finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }
            return(result);
        }
Beispiel #3
0
        public List <AgentProduct> GetAgentProducts(int agentId)
        {
            List <AgentProduct> products = new List <AgentProduct>();

            using (chargebitEntities db = new chargebitEntities())
            {
                var query = from r in db.Agent_route
                            join t in db.Resource_taocan on r.Resource_taocan_id equals t.Id
                            join sp in db.Sp on t.Sp_id equals sp.Id
                            join a in db.Area on t.NumberProvinceId equals a.Id into la
                            from lla in la.DefaultIfEmpty()
                            where r.Enabled == true && t.Enabled == true && r.User_id == agentId
                            orderby t.Sp_id descending, t.Quantity ascending
                    select new AgentProduct
                {
                    Id                = r.Id,
                    Size              = t.Quantity,
                    SP                = t.Sp_id,
                    SPName            = sp != null?sp.Name:"",
                    RestrictProvince  = (lla != null? lla.Name:"全国"),
                    PlatformSalePrice = t.Sale_price,
                    ClientDiscount    = r.Discount,
                    ClientSalePrice   = r.Sale_price
                };

                products = query.ToList <AgentProduct>();
            }
            return(products);
        }
Beispiel #4
0
        public void CustomerRecharge(int customerId, int agentId, float amount)
        {
            if (customerId > 0 && agentId > 0 && amount > 0)
            {
                using (chargebitEntities db = new chargebitEntities())
                {
                    Customer cus = (from c in db.Customer where c.Id == customerId select c).FirstOrDefault <Customer>();
                    if (cus == null)
                    {
                        throw new KMBitException("编号为" + customerId + "不存在");
                    }

                    if (cus.AgentId != agentId)
                    {
                        throw new KMBitException("编号为" + customerId + "的客户不属于编号为" + agentId + "代理商");
                    }

                    Customer_Recharge charge = new Customer_Recharge()
                    {
                        AgentId = agentId, Amount = amount, CreatedTime = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now), CustomerId = customerId
                    };
                    db.Customer_Recharge.Add(charge);
                    db.SaveChanges();
                    cus.RemainingAmount += amount;
                    db.SaveChanges();
                }
            }
            else
            {
                throw new KMBitException("输入参数不正确");
            }
        }
Beispiel #5
0
        public List <BAgentRoute> FindAvailableAgentRoutes(int agentId = 0, int customerId = 0, int activityId = 0)
        {
            agentId = agentId > 0 ? agentId : CurrentLoginUser.User.Id;
            AgentManagement    agentMgr = new AgentManagement(CurrentLoginUser);
            List <BAgentRoute> routes   = agentMgr.FindTaocans(0, true);
            List <BAgentRoute> tmp      = new List <BAgentRoute>();

            if (activityId == 0)
            {
                tmp = routes;
            }
            else
            {
                using (chargebitEntities db = new chargebitEntities())
                {
                    //List<Resource_taocan> rtaocans = (from t in db.Resource_taocan
                    //                                  join mt in db.Marketing_Activity_Taocan on t.Id equals mt.ResourceTaocanId
                    //                                  where mt.ActivityId == activityId
                    //                                  select t).ToList<Resource_taocan>();

                    List <BActivityTaocan> aTaocans = FindActivityTaocans(activityId, customerId, agentId);

                    int[] rts   = (from rt in aTaocans where rt.UsedCount < rt.ATaocan.Quantity select rt.ATaocan.ResourceTaocanId).ToArray <int>();
                    int[] spIds = (from rt in aTaocans where rt.UsedCount < rt.ATaocan.Quantity select rt.Route.Taocan.Taocan.Sp_id).ToArray <int>();
                    tmp = (from t in routes where !rts.Contains(t.Taocan.Taocan.Id) && !spIds.Contains(t.Taocan.Taocan.Sp_id) select t).ToList <BAgentRoute>();
                }
            }
            return(tmp);
        }
Beispiel #6
0
        public void SyncChargeStatus()
        {
            chargebitEntities db = new chargebitEntities();

            try
            {
                List <Resrouce_interface> apis = (from api in db.Resrouce_interface where string.IsNullOrEmpty(api.CallBackUrl) && !string.IsNullOrEmpty(api.QueryStatusUrl) && api.Resource_id == 10 orderby api.CallBackUrl select api).ToList <Resrouce_interface>();
                foreach (Resrouce_interface api in apis)
                {
                    if (api.Synchronized == false && string.IsNullOrEmpty(api.CallBackUrl))
                    {
                        Logger.Info("Processing order status for resourceId:" + api.Resource_id);
                        IStatus chargeMgr = null;
                        object  o         = null;
                        o         = Assembly.Load(api.Interface_assemblyname).CreateInstance(api.Interface_classname);
                        chargeMgr = (IStatus)o;
                        chargeMgr.GetChargeStatus(api.Resource_id);
                        Logger.Info("Done!");
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Fatal(ex);
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }
        }
Beispiel #7
0
        public bool UpdateResourceTaocan(Resource_taocan taocan)
        {
            bool ret = false;

            if (!CurrentLoginUser.Permission.UPDATE_RESOURCE_TAOCAN)
            {
                throw new KMBitException("没有权限更新资源套餐");
            }
            if (taocan == null || taocan.Id <= 0)
            {
                throw new KMBitException("输入数据不正确,不能更新套餐");
            }


            using (chargebitEntities db = new chargebitEntities())
            {
                Resource_taocan dbTaocan = (from t in db.Resource_taocan where t.Id == taocan.Id select t).FirstOrDefault <Resource_taocan>();
                if (dbTaocan == null)
                {
                    throw new KMBitException("套餐不存在不能更新");
                }
                SyncObjectProperties(dbTaocan, taocan);
                db.SaveChanges();
                ret = true;
            }
            return(ret);
        }
Beispiel #8
0
 public Help_Info CreateHelpInfo(Help_Info newInfo)
 {
     using (chargebitEntities db = new chargebitEntities())
     {
         if (!string.IsNullOrEmpty(newInfo.About) && !string.IsNullOrEmpty(newInfo.AdminHelp) && !string.IsNullOrEmpty(newInfo.AgentHelp) && !string.IsNullOrEmpty(newInfo.Contact))
         {
             if (newInfo.UpdateTime <= 0)
             {
                 newInfo.UpdateTime = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
             }
             if (newInfo.UpdateUser <= 0)
             {
                 newInfo.UpdateUser = CurrentLoginUser.User.Id;
             }
         }
         else
         {
             throw new KMBitException("所有字段都不能为空");
         }
         newInfo.IsCurrent = true;
         db.Database.ExecuteSqlCommand("Update Help_Info set IsCurrent=0");
         db.Help_Info.Add(newInfo);
         db.SaveChanges();
     }
     return(newInfo);
 }
Beispiel #9
0
        public bool UpdateActivity(Marketing_Activities activity)
        {
            bool result = false;

            if (activity == null || activity.Id <= 0)
            {
                throw new KMBitException("参数错误");
            }
            using (chargebitEntities db = new chargebitEntities())
            {
                Marketing_Activities dbac = (from a in db.Marketing_Activities where a.Id == activity.Id select a).FirstOrDefault <Marketing_Activities>();
                if (dbac == null)
                {
                    throw new KMBitException("参数错误");
                }

                if (!string.IsNullOrEmpty(activity.Name))
                {
                    dbac.Name = activity.Name;
                }
                if (!string.IsNullOrEmpty(activity.Description))
                {
                    dbac.Description = activity.Description;
                }

                dbac.Enabled = activity.Enabled;
                db.SaveChanges();
                result = true;
            }

            return(result);
        }
Beispiel #10
0
        public bool UpdateResource(Resource resource)
        {
            if (!CurrentLoginUser.Permission.UPDATE_RESOURCE)
            {
                throw new KMBitException("没有权限更新资源");
            }
            bool ret = false;

            if (resource == null)
            {
                logger.Error("resource is NULL");
                throw new KMBitException("资源输入参数不正确");
            }
            if (resource.Id <= 0)
            {
                throw new KMBitException("资源输入参数不正确");
            }
            if (string.IsNullOrEmpty(resource.Name))
            {
                logger.Error("resource name cannot be empty");
                throw new KMBitException("资源名称不能为空");
            }
            using (chargebitEntities db = new chargebitEntities())
            {
                Resource dbResource = (from r in db.Resource where r.Id == resource.Id select r).FirstOrDefault <Resource>();
                //db.Resource.Attach(dbResource);
                SyncObjectProperties(dbResource, resource);
                db.SaveChanges();
                ret = true;
            }

            return(ret);
        }
Beispiel #11
0
        public BPaymentHistory CreateChargeAccountPayment(int userId, float amount, int tranfserType)
        {
            BPaymentHistory payment = null;

            using (chargebitEntities db = new chargebitEntities())
            {
                Payment_history p = new Payment_history()
                {
                    Amount = amount, ChargeOrderId = 0, CreatedTime = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now), Tranfser_Type = tranfserType, User_id = userId, PayType = 1
                };
                db.Payment_history.Add(p);
                db.SaveChanges();
                payment = new BPaymentHistory()
                {
                    Amount         = p.Amount,
                    ChargeOrderId  = p.ChargeOrderId,
                    CreatedTime    = p.CreatedTime,
                    Id             = p.Id,
                    PaymentAccount = p.PaymentAccount,
                    PaymentTradeId = p.PaymentTradeId,
                    PayType        = p.PayType,
                    Pay_time       = p.Pay_time,
                    Tranfser_Type  = p.Tranfser_Type,
                    User_id        = p.User_id
                };
            }
            return(payment);
        }
Beispiel #12
0
        public bool UpdateAccountMoneyAfterPayment(BPaymentHistory payment)
        {
            bool result = false;

            using (chargebitEntities db = new chargebitEntities())
            {
                if (string.IsNullOrEmpty(payment.PaymentTradeId))
                {
                    throw new KMBitException("支付记录没有宝行支付系统的交易号");
                }

                if (payment.User_id <= 0)
                {
                    throw new KMBitException("支付记录没有包含代理商信息");
                }

                if (payment.Amount <= 0)
                {
                    throw new KMBitException("支付记录没有包含支付金额");
                }

                Users user = (from u in db.Users where u.Id == payment.User_id select u).FirstOrDefault <Users>();
                if (user == null)
                {
                    throw new KMBitException(string.Format("没有找到ID为{0}的用户", payment.User_id));
                }

                user.Remaining_amount += payment.Amount;
                db.SaveChanges();
                result = true;
            }
            return(result);
        }
Beispiel #13
0
 protected void RemoveQRCode(Charge_Order order)
 {
     if (order.MarketOrderId > 0)
     {
         chargebitEntities db = null;
         try
         {
             db = new chargebitEntities();
             Marketing_Orders mOrder = (from mo in db.Marketing_Orders where mo.Id == order.MarketOrderId select mo).FirstOrDefault <Marketing_Orders>();
             if (mOrder != null && !string.IsNullOrEmpty(mOrder.CodePath))
             {
                 string tmpPhysicalPath = System.IO.Path.Combine(settings.RootDirectory, mOrder.CodePath.Replace('/', '\\'));
                 if (System.IO.File.Exists(tmpPhysicalPath))
                 {
                     System.IO.File.Delete(tmpPhysicalPath);
                 }
             }
         }catch (Exception ex)
         {
             Logger.Fatal(ex);
         }finally
         {
             if (db != null)
             {
                 db.Dispose();
             }
         }
     }
 }
Beispiel #14
0
        public bool UpdateAgentRuote(int route_id, float discount, bool enabled)
        {
            if (!CurrentLoginUser.Permission.UPDATE_USER_ROUTE)
            {
                throw new KMBitException("没有权限更新代理商路由");
            }
            bool ret = false;

            using (chargebitEntities db = new chargebitEntities())
            {
                Agent_route route = (from r in db.Agent_route where r.Id == route_id select r).FirstOrDefault <Agent_route>();
                if (route == null)
                {
                    throw new KMBitException("此路由套餐不存在");
                }
                if (discount <= 0 || discount > 1)
                {
                    throw new KMBitException("折扣不能等于0或者大于1,必须介于0-1之间,可以等于1");
                }
                route.Discount    = discount;
                route.Enabled     = enabled;
                route.UpdatedBy   = CurrentLoginUser.User.Id;
                route.Update_time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                db.SaveChanges();
                ret = true;
            }
            return(ret);
        }
Beispiel #15
0
        public void SyncChargeStatus()
        {
            chargebitEntities db = new chargebitEntities();

            try
            {
                IStatus chargeMgr = null;
                List <Resrouce_interface> apis = (from api in db.Resrouce_interface where string.IsNullOrEmpty(api.CallBackUrl) orderby api.CallBackUrl select api).ToList <Resrouce_interface>();
                foreach (Resrouce_interface api in apis)
                {
                    object   o        = null;
                    Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
                    Type     type     = assembly.GetType(api.Interface_classname);
                    o         = Activator.CreateInstance(type);
                    chargeMgr = o as IStatus;
                    if (chargeMgr != null)
                    {
                        chargeMgr.GetChargeStatus(api.Resource_id);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Fatal(ex);
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }
        }
Beispiel #16
0
        public List <BUser> FindAdministrators()
        {
            List <BUser> users = new List <BUser>();

            using (chargebitEntities db = new chargebitEntities())
            {
                var query = from ua in db.Admin_Users
                            join u in db.Users on ua.User_Id equals u.Id
                            join cu in db.Users on u.CreatedBy equals cu.Id into lcu
                            from lccu in lcu.DefaultIfEmpty()
                            select new BUser
                {
                    User         = u,
                    CreatedBy    = lccu,
                    IsAdmin      = true,
                    IsSuperAdmin = ua.IsSuperAdmin,
                    IsWebMaster  = ua.IsWebMaster
                };

                users = query.OrderBy(u => u.User.Regtime).ToList <BUser>();
                if (CurrentLoginUser.IsSuperAdmin && !CurrentLoginUser.IsWebMaster)
                {
                    users = (from u in users where u.IsSuperAdmin == false && u.IsWebMaster == false select u).ToList <BUser>();
                }
                else if (!CurrentLoginUser.IsSuperAdmin && !CurrentLoginUser.IsWebMaster)
                {
                    users = new List <BUser>();
                }
            }
            users = (from u in users where u.User.Email != CurrentLoginUser.User.Email select u).ToList <BUser>();
            return(users);
        }
Beispiel #17
0
        public SystemStatus GetLaji()
        {
            SystemStatus laji;

            using (chargebitEntities db = new chargebitEntities())
            {
                List <LaJi> lajis = (from l in db.LaJi where l.PId == 3 orderby l.UP descending select l).ToList <LaJi>();
                if (lajis.Count > 1)
                {
                    db.Database.SqlQuery <int>("delete * from LaJi");
                    LaJi tmp = new LaJi()
                    {
                        PId = 3, UP = true
                    };
                    db.LaJi.Add(tmp);
                    db.SaveChanges();
                    laji = SystemStatus.RUNNING;
                }
                else
                {
                    if (lajis[0].UP)
                    {
                        laji = SystemStatus.RUNNING;
                    }
                    else
                    {
                        laji = SystemStatus.DOWN;
                    }
                }
            }
            return(laji);
        }
Beispiel #18
0
        public void SetAdminStatus(int userId, bool enabled)
        {
            if (userId == CurrentLoginUser.User.Id)
            {
                throw new KMBitException("不能禁用或启用自己的账户");
            }
            using (chargebitEntities db = new chargebitEntities())
            {
                Users user = (from u in db.Users where u.Id == userId select u).FirstOrDefault <Users>();

                if (user == null)
                {
                    throw new KMBitException("用户不存在");
                }

                Admin_Users au = (from u in db.Admin_Users where u.User_Id == user.Id select u).FirstOrDefault <Admin_Users>();
                if (au.IsSuperAdmin)
                {
                    if (!CurrentLoginUser.IsWebMaster)
                    {
                        throw new KMBitException("只有网站管理员才能禁用或启用超级管理员账户");
                    }
                }
                else
                {
                    if (!CurrentLoginUser.IsSuperAdmin)
                    {
                        throw new KMBitException("只有超级管理员才能禁用或启用普通管理员账户");
                    }
                }
                user.Enabled = enabled;
                db.SaveChanges();
            }
        }
Beispiel #19
0
        public List <BUser> FindAgencies(int userId, string email, string name, int provinceId, int cityId, out int total, int page = 1, int pageSize = 30, bool paging = true, bool?enabled = null)
        {
            total = 0;
            List <BUser> agencies = new List <BUser>();

            using (chargebitEntities db = new chargebitEntities())
            {
                var query = from u in db.Users
                            join paytype in db.PayType on u.Pay_type equals paytype.Id
                            join usertype in db.User_type on u.Type equals usertype.Id
                            join cu in db.Users on u.CreatedBy equals cu.Id into lcu
                            from llcu in lcu.DefaultIfEmpty()
                            join city in db.Area on u.City_id equals city.Id into lcity
                            from llcity in lcity.DefaultIfEmpty()
                            join province in db.Area on u.Province_id equals province.Id into lprovince
                            from llprovince in lcity.DefaultIfEmpty()
                            where u.Type != 1
                            select new BUser
                {
                    User      = u,
                    CreatedBy = llcu,
                    City      = llcity,
                    Province  = llprovince,
                    PayType   = paytype,
                    UserType  = usertype
                };

                if (userId > 0)
                {
                    query = query.Where(q => q.User.Id == userId);
                }
                if (!string.IsNullOrEmpty(email))
                {
                    query = query.Where(q => q.User.Email == email);
                }
                if (cityId > 0)
                {
                    query = query.Where(q => q.City.Id == cityId);
                }
                if (provinceId > 0)
                {
                    query = query.Where(q => q.Province.Id == provinceId);
                }
                if (enabled != null)
                {
                    query = query.Where(q => q.User.Enabled == (bool)enabled);
                }
                query = query.OrderByDescending(u => u.User.Regtime);
                total = query.Count();
                if (paging)
                {
                    page  = page <= 0 ? 1 : page;
                    query = query.Skip((page - 1) * pageSize).Take(pageSize);
                }

                agencies = query.ToList <BUser>();
            }
            return(agencies);
        }
Beispiel #20
0
        public bool CreateResourceTaocan(Resource_taocan taocan)
        {
            bool ret = false;

            if (!CurrentLoginUser.Permission.CREATE_RESOURCE_TAOCAN)
            {
                throw new KMBitException("没有权限创建资源套餐");
            }

            if (taocan.Quantity <= 0)
            {
                throw new KMBitException("套餐容量不能为零");
            }

            if (taocan.Resource_id <= 0)
            {
                throw new KMBitException("套餐资源信息不能为空");
            }
            int total = 0;
            List <BResource> resources = FindResources(taocan.Resource_id, null, 0, out total);

            if (total == 0)
            {
                throw new KMBitException("资源编号为:" + taocan.Resource_id + " 的资源不存在");
            }
            using (chargebitEntities db = new chargebitEntities())
            {
                string taocanName = taocan.Area_id > 0 ? "省内 " + taocan.Quantity.ToString() + "M" : "全国 " + taocan.Quantity.ToString() + "M";
                Taocan ntaocan    = (from t in db.Taocan where t.Sp_id == taocan.Sp_id && t.Quantity == taocan.Quantity && t.Name == taocanName select t).FirstOrDefault <Taocan>();
                Sp     sp         = (from s in db.Sp where s.Id == taocan.Sp_id select s).FirstOrDefault <Sp>();
                if (ntaocan == null)
                {
                    ntaocan = new Taocan()
                    {
                        Created_time = taocan.Created_time, Description = taocanName, Name = taocanName, Sp_id = taocan.Sp_id, Quantity = taocan.Quantity, Updated_time = taocan.Updated_time
                    };
                    db.Taocan.Add(ntaocan);
                    db.SaveChanges();
                }
                if (ntaocan.Id > 0)
                {
                    Resource_taocan t = (from r in db.Resource_taocan where r.Serial.Trim() == taocan.Serial.Trim() && r.Resource_id == taocan.Resource_id select r).FirstOrDefault <Resource_taocan>();
                    if (t != null)
                    {
                        throw new KMBitException(string.Format("套餐编号为 {0} 的套餐已经存在", taocan.Serial));
                    }
                    taocan.Taocan_id = ntaocan.Id;
                    db.Resource_taocan.Add(taocan);
                    db.SaveChanges();
                    ret = true;
                }
                else
                {
                    throw new KMBitException("套餐创建失败");
                }
            }
            return(ret);
        }
Beispiel #21
0
        public bool ChargeAgencyAccount(int agencyId, float amount)
        {
            bool ret = false;

            if (!CurrentLoginUser.Permission.UPDATE_USER)
            {
                throw new KMBitException("没有权限更新用户信息");
            }
            chargebitEntities db = null;

            try
            {
                db = new chargebitEntities();
                Users dbUser = (from u in db.Users where u.Id == agencyId && u.Enabled == true select u).FirstOrDefault <Users>();
                if (dbUser == null)
                {
                    throw new KMBitException(string.Format("编号为{0}的代理商不存在", agencyId));
                }

                Payment_history payment = new Payment_history()
                {
                    OperUserId     = CurrentLoginUser.User.Id,
                    Amount         = amount,
                    User_id        = agencyId,
                    Status         = 1,
                    PayType        = 2,
                    Pay_time       = 0,
                    ChargeOrderId  = 0,
                    CreatedTime    = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now),
                    PaymentAccount = "",
                    PaymentTradeId = "",
                    Tranfser_Type  = 0
                };

                db.Payment_history.Add(payment);
                db.SaveChanges();
                ret = true;
            }
            catch (KMBitException kex)
            {
                logger.Error(kex);
                throw kex;
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                throw ex;
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }
            return(ret);
        }
Beispiel #22
0
        public List <BActivityOrder> FindMarketingOrders(int agentId, int customerId, int activityId, int activityTaocanId, out int total, bool paging = false, int page = 1, int pagesize = 30)
        {
            total = 0;
            List <BActivityOrder> orders = new List <BActivityOrder>();

            agentId = agentId > 0 ? agentId : CurrentLoginUser.User.Id;
            chargebitEntities db = new chargebitEntities();

            try
            {
                var query = from o in db.Marketing_Orders
                            join t in db.Marketing_Activity_Taocan on o.ActivityTaocanId equals t.Id into lt
                            from llt in lt.DefaultIfEmpty()
                            join a in db.Marketing_Activities on o.ActivityId equals a.Id into lo
                            from llo in lo.DefaultIfEmpty()
                            join tc in db.Resource_taocan on llt.ResourceTaocanId equals tc.Id
                            join tcc in db.Taocan on tc.Taocan_id equals tcc.Id into ltcc
                            from lltcc in ltcc.DefaultIfEmpty()
                            select new BActivityOrder
                {
                    Order        = o,
                    ActivityName = llo != null?llo.Name:"",
                    TaocanName   = lltcc != null?lltcc.Name:""
                };

                if (activityId > 0)
                {
                    query = query.Where(o => o.Order.ActivityId == activityId);
                }
                if (activityTaocanId > 0)
                {
                    query = query.Where(o => o.Order.ActivityTaocanId == activityTaocanId);
                }

                query = query.OrderBy(o => o.Order.ActivityTaocanId);
                total = query.Count();
                if (paging)
                {
                    page     = page > 0 ? page : 1;
                    pagesize = pagesize > 0 ? pagesize : 30;
                    query    = query.Skip((page - 1) * pagesize).Take(pagesize);
                }

                orders = query.ToList <BActivityOrder>();
            }catch (Exception ex)
            {
                logger.Error(ex);
            }finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }
            return(orders);
        }
Beispiel #23
0
        public List <User_type> GetUserTypes()
        {
            List <User_type> types = null;

            using (chargebitEntities db = new chargebitEntities())
            {
                types = (from t in db.User_type orderby t.Id select t).ToList <User_type>();
            }
            return(types);
        }
Beispiel #24
0
        public List <DAL.PayType> GetPayTypes()
        {
            List <DAL.PayType> types = null;

            using (chargebitEntities db = new chargebitEntities())
            {
                types = (from t in db.PayType orderby t.Id select t).ToList();
            }
            return(types);
        }
Beispiel #25
0
        public List <Sp> GetSps()
        {
            List <Sp> spList = null;

            using (chargebitEntities db = new chargebitEntities())
            {
                spList = (from s in db.Sp orderby s.Id select s).ToList <Sp>();
            }
            return(spList);
        }
Beispiel #26
0
        /// <summary>
        /// Gets user actions list
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="categoryId"></param>
        /// <param name="categoryName"></param>
        /// <returns></returns>
        public List <UserAdminAction> GetUserPermissionActions(int userId, int categoryId, string categoryName)
        {
            List <UserAdminAction> actions = new List <UserAdminAction>();

            using (chargebitEntities db = new chargebitEntities())
            {
                List <Admin_Categories> allcates = (from cate in db.Admin_Categories orderby cate.Id select cate).ToList <Admin_Categories>();
                var userActions = from ua in db.Admin_Users_Actions
                                  join action in db.Admin_Actions on ua.Action_Id equals action.Id into laction
                                  from uaction in laction.DefaultIfEmpty()
                                  join cate in db.Admin_Categories on uaction.Category equals cate.Id into lcate
                                  from ucate in lcate.DefaultIfEmpty()
                                  select new
                {
                    userId       = ua.User_Id,
                    categoryId   = uaction.Id,
                    categoryName = ucate.Name,
                    actionId     = ua.Action_Id,
                    actionName   = uaction.Name,
                    actionDesc   = uaction.Description
                };
                if (userId > 0)
                {
                    userActions = userActions.Where(u => u.userId == userId);
                }

                if (categoryId > 0)
                {
                    userActions = userActions.Where(u => u.categoryId == categoryId);
                }

                if (!string.IsNullOrEmpty(categoryName))
                {
                    userActions = userActions.Where(u => u.categoryName == categoryName);
                }

                foreach (var uaction in userActions)
                {
                    UserAdminAction uaa = new UserAdminAction();
                    uaa.Action = new Admin_Actions()
                    {
                        Id = uaction.actionId, Name = uaction.actionName, Description = uaction.actionDesc, Enabled = true
                    };
                    uaa.Category = new Admin_Categories()
                    {
                        Id = uaction.categoryId, Name = uaction.categoryName
                    };
                    actions.Add(uaa);
                }
            }

            return(actions);
        }
Beispiel #27
0
        public List <BPaymentHistory> FindPayments(int paymentId, int userId, int orderId, out int total, bool paging = false, int pageSize = 30, int page = 1)
        {
            total = 0;
            List <BPaymentHistory> payments = null;

            using (chargebitEntities db = new chargebitEntities())
            {
                var query = from p in db.Payment_history
                            join u in db.Users on p.User_id equals u.Id into lu
                            from llu in lu.DefaultIfEmpty()
                            where !string.IsNullOrEmpty(p.PaymentTradeId)
                            select new BPaymentHistory
                {
                    Amount         = p.Amount,
                    ChargeOrderId  = p.ChargeOrderId,
                    CreatedTime    = p.CreatedTime,
                    Id             = p.Id,
                    PaymentAccount = p.PaymentAccount,
                    PaymentTradeId = p.PaymentTradeId,
                    PayType        = p.PayType,
                    Pay_time       = p.Pay_time,
                    Tranfser_Type  = p.Tranfser_Type,
                    UserName       = llu != null ? llu.Name : "",
                    User_id        = p.User_id
                };

                if (paymentId > 0)
                {
                    query = query.Where(p => p.Id == paymentId);
                }
                if (userId > 0)
                {
                    query = query.Where(p => p.User_id == userId);
                }
                if (orderId > 0)
                {
                    query = query.Where(p => p.ChargeOrderId == orderId);
                }

                query = query.OrderByDescending(p => p.CreatedTime);
                total = query.Count();

                if (paging)
                {
                    page     = page > 0?page: 1;
                    pageSize = pageSize > 0 ? pageSize : 30;
                    query    = query.Skip((page - 1) * pageSize).Take(pageSize);
                }

                payments = query.ToList <BPaymentHistory>();
            }
            return(payments);
        }
Beispiel #28
0
        public bool CreateRoute(Agent_route route)
        {
            if (route == null)
            {
                throw new KMBitException("路由信息不能为空");
            }
            if (route.User_id <= 0)
            {
                throw new KMBitException("代理商信息不能为空");
            }
            if (route.Resource_Id <= 0)
            {
                throw new KMBitException("落地资源信息不能为空");
            }
            if (route.Resource_taocan_id <= 0)
            {
                throw new KMBitException("落地资源套餐不能为空");
            }
            if (route.Discount <= 0 || route.Discount > 1)
            {
                throw new KMBitException("代理商路由(资源套餐)折扣必须在0-1之间");
            }
            if (!CurrentLoginUser.Permission.CREATE_USER_ROUTE)
            {
                throw new KMBitException("没有权限创建代理商路由");
            }
            if (route.Create_time <= 0)
            {
                route.Create_time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
            }
            if (route.CreatedBy <= 0)
            {
                route.CreatedBy = CurrentLoginUser.User.Id;
            }
            bool ret = false;

            using (chargebitEntities db = new chargebitEntities())
            {
                Resource_taocan taocan = (from t in db.Resource_taocan where t.Resource_id == route.Resource_Id && t.Id == route.Resource_taocan_id select t).FirstOrDefault <Resource_taocan>();
                if (taocan == null || !taocan.Enabled)
                {
                    return(ret);
                }
                if (route.Sale_price == 0)
                {
                    route.Sale_price = taocan.Sale_price;
                }
                db.Agent_route.Add(route);
                db.SaveChanges();
                ret = true;
            }
            return(ret);
        }
Beispiel #29
0
        public ChargeResult ImportResourceProducts(int resourceId, int operate_user)
        {
            ChargeResult result = new ChargeResult()
            {
                Status = ChargeStatus.SUCCEED
            };
            ICharge           chargeMgr = null;
            chargebitEntities db        = new chargebitEntities();

            try
            {
                KMBit.DAL.Resource resource = (from ri in db.Resource
                                               where ri.Id == resourceId
                                               select ri).FirstOrDefault <Resource>();

                if (resource == null)
                {
                    throw new KMBitException(string.Format("编号为{0}的资源不存在", resourceId));
                }
                if (!resource.Enabled)
                {
                    throw new KMBitException(string.Format("编号为{0}的资源没有启用,请先启用在进行资源产品导入", resourceId));
                }

                KMBit.DAL.Resrouce_interface rInterface = (from ri in db.Resrouce_interface where ri.Resource_id == resourceId select ri).FirstOrDefault <Resrouce_interface>();
                if (rInterface == null)
                {
                    throw new KMBitException(string.Format("编号为{0}的资源没有配置资源接口,请先配置资源接口,并配置产品导入接口URL,然后进行资源产品导入", resourceId));
                }
                object   o        = null;
                Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
                Type     type     = assembly.GetType(rInterface.Interface_classname);
                o = Activator.CreateInstance(type);
                if (o != null)
                {
                    chargeMgr = (ICharge)o;
                    chargeMgr.ImportProducts(resourceId, operate_user);
                }
            }
            catch (Exception ex)
            {
                result.Status  = ChargeStatus.FAILED;
                result.Message = ex.Message;
            }finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }

            return(result);
        }
Beispiel #30
0
        public BUser GetUserByAccesstoken(string token)
        {
            BUser user = null;

            using (chargebitEntities db = new chargebitEntities())
            {
                user = (from u in db.Users where u.AccessToken == token
                        select new BUser
                {
                    User = u
                }).FirstOrDefault <BUser>();
            }
            return(user);
        }