Exemplo n.º 1
0
        /// <summary>
        ///     获取时间方式的表达式
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <typeparam name="TKey"></typeparam>
        /// <param name="timeType"></param>
        /// <param name="dateTime"></param>
        /// <param name="predicate"></param>
        public static Expression <Func <TEntity, bool> > GetPredicate <TEntity, TKey>(this TimeType timeType,
                                                                                      DateTime dateTime, Expression <Func <TEntity, bool> > predicate)
            where TEntity : class, IAggregateRoot <TEntity, TKey>
        {
            var query = new ExpressionQuery <TEntity>();

            if (predicate != null)
            {
                query.And(predicate);
            }

            query.OrderByAscending(e => e.Id);
            switch (timeType)
            {
            case TimeType.Day:
                query.And(r =>
                          r.CreateTime.Day == dateTime.Day && r.CreateTime.Month == dateTime.Month &&
                          r.CreateTime.Year == dateTime.Year);
                break;

            case TimeType.Month:
                query.And(r => r.CreateTime.Month == dateTime.Month && r.CreateTime.Year == dateTime.Year);
                break;

            case TimeType.Year:
                query.And(r => r.CreateTime.Year == dateTime.Year);
                break;
            }

            var result = query.BuildExpression();

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Page table
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public PageResult <MerchantOrderList> PageTable(object query, AutoBaseModel autoModel)
        {
            var tenant = TenantContext.CurrentTenant;
            var dic    = HttpWeb.HttpContext.ToDictionary();

            dic = dic.RemoveKey("type");
            //express
            var model           = ToQuery <MerchantOrderList>();
            var expressionQuery = new ExpressionQuery <MerchantOrder>();

            if (model.MerchantOrderStatus > 0)
            {
                expressionQuery.And(e => e.OrderStatus == model.MerchantOrderStatus);
            }
            //all stores
            var merchantStores = Resolve <IMerchantStoreService>().GetList().ToList();

            //query
            var result     = new List <MerchantOrderList>();
            var apiService = Resolve <IApiService>();
            var orders     = Resolve <IMerchantOrderService>()
                             .GetPagedList <MerchantOrder>(dic.ToJson(), expressionQuery.BuildExpression());

            orders.ForEach(item =>
            {
                var store = merchantStores.Find(s => s.Id == item.MerchantStoreId.ToObjectId());
                if (store == null)
                {
                    return;
                }

                var extension = item.Extension.DeserializeJson <MerchantOrderExtension>();
                var temp      = new MerchantOrderList();
                temp          = AutoMapping.SetValue(item, temp);
                //user
                var user = Resolve <IUserService>().GetSingle(item.UserId);
                if (user != null)
                {
                    temp.BuyUser = AutoMapping.SetValue <UserOutput>(user);
                }

                temp.MerchantOrderStatus = item.OrderStatus;
                temp.MerchantStoreName   = store.Name;
                temp.ThumbnailUrl        = apiService.ApiImageUrl(store.Logo);
                temp.Products            = extension?.MerchantProducts;
                temp.Products?.ForEach(product =>
                {
                    product.ThumbnailUrl = apiService.ApiImageUrl(product.ThumbnailUrl);
                });
                result.Add(temp);
            });

            var pageList =
                PagedList <MerchantOrderList> .Create(result, orders.RecordCount, orders.PageSize, orders.PageIndex);

            return(ToPageResult(pageList));
        }
Exemplo n.º 3
0
        public PagedList <ApiOrderListOutput> GetPageList(object query, ExpressionQuery <Order> expressionQuery)
        {
            //query.PageIndex = (int)orderInput.PageIndex;
            // query.PageSize = (int)orderInput.PageSize;
            expressionQuery.OrderByDescending(e => e.Id);
            //所有的绑定都使用快照数据,而不是使用当前数据库中的数据
            var orders = Resolve <IOrderService>().GetPagedList(query, expressionQuery.BuildExpression());

            var model = new List <ApiOrderListOutput>();

            if (orders.Count < 0)
            {
                return(new PagedList <ApiOrderListOutput>());
            }

            foreach (var item in orders)
            {
                var listOutput = new ApiOrderListOutput
                {
                    CreateTime     = item?.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
                    Id             = item.Id,
                    OrderStatuName = item?.OrderStatus.GetDisplayName(),
                    User           = item?.OrderExtension?.User,
                    Address        = item?.OrderExtension?.UserAddress?.Address
                };
                if (item.OrderExtension != null)
                {
                    if (item.OrderExtension.UserAddress != null)
                    {
                        listOutput.RegionName = Resolve <IRegionService>()
                                                .GetRegionNameById(item.OrderExtension.UserAddress.RegionId);
                    }
                }
                else
                {
                    listOutput.RegionName = null;
                }

                listOutput = AutoMapping.SetValue(item, listOutput);
                var orderExtension = item.Extension.DeserializeJson <OrderExtension>();
                if (orderExtension != null && orderExtension.Store != null)
                {
                    listOutput.StoreName     = orderExtension.Store.Name;
                    listOutput.ExpressAmount = orderExtension.OrderAmount.ExpressAmount;
                }

                listOutput.OutOrderProducts = orderExtension.ProductSkuItems;
                listOutput.OutOrderProducts?.ToList().ForEach(c =>
                {
                    c.ThumbnailUrl = Resolve <IApiService>().ApiImageUrl(c.ThumbnailUrl);
                });
                model.Add(listOutput);
            }

            return(PagedList <ApiOrderListOutput> .Create(model, orders.RecordCount, orders.PageSize, orders.PageIndex));
        }
Exemplo n.º 4
0
        /// <summary>
        ///     page table
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public PageResult <MerchantProductList> PageTable(object query, AutoBaseModel autoModel)
        {
            var dic = HttpWeb.HttpContext.ToDictionary();

            dic = dic.RemoveKey("userId");
            dic = dic.RemoveKey("type");
            //express
            var allStores    = Resolve <IMerchantStoreService>().GetList().ToList();
            var allRelations = Resolve <IRelationService>().GetClass(typeof(MerchantProductClassRelation).FullName)
                               .ToList();
            var model           = ToQuery <MerchantProductList>();
            var expressionQuery = new ExpressionQuery <MerchantProduct>();

            if (!string.IsNullOrWhiteSpace(model.ClassName))
            {
                var relation = allRelations.Find(r => r.Name.Contains(model.ClassName));
                if (relation != null)
                {
                    expressionQuery.And(e => e.ClassId == relation.Id);
                }
            }

            //query
            var apiService = Resolve <IApiService>();
            var list       = Resolve <IMerchantProductService>()
                             .GetPagedList <MerchantProductList>(dic.ToJson(), expressionQuery.BuildExpression());

            list.ForEach(item =>
            {
                //store
                var store = allStores.Find(s => s.Id == item.MerchantStoreId.ToObjectId());
                item.MerchantStoreName = store?.Name;
                item.ThumbnailUrl      = apiService.ApiImageUrl(item.ThumbnailUrl);

                //relation
                var relation   = allRelations.Find(r => r.Id == item.ClassId);
                item.ClassName = relation?.Name;

                //item.sku
                var sku = item.Skus.FirstOrDefault();
                if (sku != null)
                {
                    item.SkuName = sku.Name;
                    item.Price   = sku.Price;
                }

                item.Stock = item.Skus.Sum(s => s.Stock);
            });

            return(ToPageResult(list));
        }
Exemplo n.º 5
0
        public PagedList <RewardRuleTable> GetPageList(object query)
        {
            var expression = new ExpressionQuery <RewardRule>();

            var dic = query.ToObject <Dictionary <string, string> >();

            if (dic.GetValue("Name", out var name))
            {
                if (!name.IsNullOrEmpty())
                {
                    expression.And(r => r.Base.Name.Contains(name, StringComparison.OrdinalIgnoreCase));
                }
            }

            if (dic.GetValue("triggerType", out var triggerType))
            {
                var trigger = Convert.ToInt32(triggerType);
                trigger.IntToEnum(out TriggerType type);
                expression.And(r => r.Limit.TriggerType == type);
            }

            var model  = GetPagedList(query, expression.BuildExpression());
            var result = new List <RewardRuleTable>();

            var moneyTypes = Resolve <IAutoConfigService>().GetList <MoneyTypeConfig>();
            var userTypes  = Resolve <IAutoConfigService>().GetList <UserTypeConfig>();

            foreach (var item in model)
            {
                var ruleTable = item.MapTo <RewardRuleTable>();
                ruleTable.ModuleName      = Resolve <IRuleModuleService>().GetRuleAttribute(item.ModuleId)?.Name;
                ruleTable.Name            = item.Base.Name;
                ruleTable.IsEnable        = item.Base.IsEnable;
                ruleTable.SmsNotification = item.Base.TemplateRule.SmsNotification;

                ruleTable.TriggerType = item.Limit.TriggerType;

                //资产分配
                foreach (var rule in item.AssetsRules)
                {
                    var moneyType = moneyTypes.FirstOrDefault(r => r.Id == rule.MoneyTypeId);
                    ruleTable.RuleItemsIntro += $"{moneyType?.Name}({rule.Ratio})";
                }
                ruleTable.RuleItemsIntro = $"<code>{ruleTable.RuleItemsIntro}</code><br/>";
                //比例
                //var radios = item.DistriRatio?.Split(",");
                //ruleTable.DistriRatio = string.Empty;
                //radios?.Foreach(r => {
                //    ruleTable.DistriRatio += $"<span class='m-badge m-badge--focus '>{r}</span>";
                //});

                //用户类型限制
                if (!item.UserRang.ShareUser.IsLimitShareUserType)
                {
                    ruleTable.ShareUserIntro = "不限类型 不限等级";
                }
                else
                {
                    var userType = userTypes.FirstOrDefault(r => r.Id == item.UserRang.ShareUser.ShareUserTypeId);

                    //等级限制
                    if (!item.UserRang.ShareUser.IsLimitShareUserGrade)
                    {
                        ruleTable.ShareUserIntro = $"限{userType?.Name} 不限等级";
                    }
                    else
                    {
                        var grade = Resolve <IGradeService>().GetGradeByUserTypeIdAndGradeId(item.UserRang.ShareUser.ShareUserTypeId, item.UserRang.ShareUser.ShareUserGradeId);
                        ruleTable.ShareUserIntro = $"限{userType?.Name} {grade?.Name}";
                    }
                }

                if (!item.UserRang.OrderUser.IsLimitOrderUserType)
                {
                    ruleTable.OrderUserIntro = "不限类型 不限等级";
                }
                else
                {
                    var userType = userTypes.FirstOrDefault(r => r.Id == item.UserRang.OrderUser.OrderUserTypeId);

                    //等级限制
                    if (!item.UserRang.OrderUser.IsLimitOrderUserGrade)
                    {
                        ruleTable.OrderUserIntro = $"限{userType?.Name} 不限等级";
                    }
                    else
                    {
                        var grade = Resolve <IGradeService>().GetGradeByUserTypeIdAndGradeId(item.UserRang.OrderUser.OrderUserTypeId, item.UserRang.OrderUser.OrderUserGradeId);
                        ruleTable.OrderUserIntro = $"限{userType?.Name} {grade?.Name}";
                    }
                }
                result.Add(ruleTable);
            }

            return(PagedList <RewardRuleTable> .Create(result, model.RecordCount, model.PageSize, model.PageIndex));
        }