public List <GroupBuyingProductConfigEntity> GetGroupBuyingV2ProductConfigByGroupId(string productGroupId)
        {
            List <GroupBuyingProductConfigEntity> result = new List <GroupBuyingProductConfigEntity>();

            try
            {
                result = dbScopeReadManager.Execute(conn => DalGroupBuyingProductGroupConfig.GetGroupBuyingV2ProductConfigByGroupId(conn, new List <string> {
                    productGroupId
                }));
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
            return(result);
        }
        /// <summary>
        /// 通过GroupId获取团购信息
        /// </summary>
        /// <param name="ProductGroupId"></param>
        /// <returns></returns>
        public GroupBuyingProductGroupConfigEntity SelectGroupBuyingV2ConfigByGroupId(string productGroupId)
        {
            GroupBuyingProductGroupConfigEntity result = null;

            try
            {
                dbScopeReadManager.Execute(conn =>
                {
                    result = DalGroupBuyingProductGroupConfig.GetGroupBuyingV2ConfigByGroupId(conn, productGroupId);
                    result.GroupProductDetails = DalGroupBuyingProductGroupConfig.GetGroupBuyingV2ProductConfigByGroupId(conn, new List <string> {
                        productGroupId
                    });
                    var purchaseInfo = PurchaseService.SelectPurchaseInfoByPID(result.GroupProductDetails.Select(x => x.PID).ToList());
                    if (purchaseInfo != null && purchaseInfo.Any())
                    {
                        purchaseInfo = from c in purchaseInfo
                                       group c by c.PID into g
                                       select g.OrderByDescending(x => x.CreatedDate).FirstOrDefault();
                        result.GroupProductDetails.ForEach(x =>
                        {
                            var pidItem = purchaseInfo.Where(y => String.Equals(x.PID, y.PID)).FirstOrDefault();
                            if (pidItem != null)
                            {
                                if (pidItem.OfferContractPrice > 0 || pidItem.OfferPurchasePrice > 0)
                                {
                                    x.CostPrice = pidItem.OfferPurchasePrice >= pidItem.OfferContractPrice ? pidItem.OfferContractPrice : pidItem.OfferPurchasePrice;
                                }
                                else if (pidItem.PurchasePrice > 0 && pidItem.ContractPrice > 0)
                                {
                                    x.CostPrice = pidItem.PurchasePrice >= pidItem.ContractPrice ? pidItem.ContractPrice : pidItem.PurchasePrice;
                                }
                                else if (pidItem.PurchasePrice > 0 || pidItem.ContractPrice > 0)
                                {
                                    x.CostPrice = pidItem.PurchasePrice > 0 ? pidItem.PurchasePrice : pidItem.ContractPrice;
                                }
                            }
                        });
                    }
                });
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
            return(result);
        }
        /// <summary>
        /// 获取团购商品信息
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="activityStatus"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public List <GroupBuyingProductGroupConfigEntity> SelectGroupBuyingV2Config(GroupBuyingProductGroupConfigEntity filter, string activityStatus, int pageIndex, int pageSize)
        {
            List <GroupBuyingProductGroupConfigEntity> result = new List <GroupBuyingProductGroupConfigEntity>();

            try
            {
                List <GroupBuyingStockModel> stockInfo = new List <GroupBuyingStockModel>();
                dbScopeReadManager.Execute(conn =>
                {
                    if (!string.IsNullOrEmpty(filter.PID) || !string.IsNullOrEmpty(filter.ProductName))
                    {
                        var filterData = DalGroupBuyingProductGroupConfig.GetGroupBuyingProductConfig(conn,
                                                                                                      filter.PID, filter.ProductName);
                        if (filterData != null && filterData.Any())
                        {
                            result = DalGroupBuyingProductGroupConfig.GetGroupBuyingV2Config(conn, filter,
                                                                                             activityStatus, filterData.Select(x => x.ProductGroupId).ToList(), pageIndex, pageSize);
                        }
                    }
                    else
                    {
                        result = DalGroupBuyingProductGroupConfig.GetGroupBuyingV2Config(conn, filter,
                                                                                         activityStatus, new List <string> {
                            filter.ProductGroupId
                        }, pageIndex, pageSize);
                    }
                    if (result != null && result.Any())
                    {
                        result.ForEach(x =>
                        {
                            x.GroupProductDetails = DalGroupBuyingProductGroupConfig.GetGroupBuyingV2ProductConfigByGroupId(conn, new List <string> {
                                x.ProductGroupId
                            });
                        });
                    }
                });
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
            return(result);
        }
예제 #4
0
        /// <summary>
        /// 通过GroupId获取团购信息
        /// </summary>
        /// <param name="ProductGroupId"></param>
        /// <returns></returns>
        public GroupBuyingProductGroupConfigEntity SelectGroupBuyingV2ConfigByGroupId(string productGroupId)
        {
            GroupBuyingProductGroupConfigEntity result = null;

            try
            {
                dbScopeReadManager.Execute(conn =>
                {
                    result = DalGroupBuyingProductGroupConfig.GetGroupBuyingV2ConfigByGroupId(conn, productGroupId);
                    result.GroupProductDetails = DalGroupBuyingProductGroupConfig.GetGroupBuyingV2ProductConfigByGroupId(conn, new List <string> {
                        productGroupId
                    });
                });
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
            return(result);
        }
        /// <summary>
        /// 编辑团购信息
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public Tuple <bool, string> UpsertGroupBuyingConfig(GroupBuyingProductGroupConfigEntity data)
        {
            var result = false;
            var msg    = "操作失败";
            GroupBuyingProductGroupConfigEntity oldData = null;

            try
            {
                dbScopeManager.CreateTransaction(conn =>
                {
                    if (string.IsNullOrWhiteSpace(data.ProductGroupId))
                    {
                        data.ProductGroupId = $"PT{DateTime.Now.GetHashCode()}".Substring(0, 10);
                        if (DalGroupBuyingProductGroupConfig.IsExistProductGroupId(conn, data.ProductGroupId) > 0)
                        {
                            data.ProductGroupId = $"PT{DateTime.Now.GetHashCode()}".Substring(0, 10);
                        }
                        DalGroupBuyingProductGroupConfig.InsertGroupBuyingGroupConfig(conn, data);
                        foreach (var item in data.GroupProductDetails)
                        {
                            item.ProductGroupId = data.ProductGroupId;
                            item.Creator        = data.Creator;
                            DalGroupBuyingProductGroupConfig.InsertGroupBuyingProductConfig(conn, item);
                        }
                    }
                    else
                    {
                        oldData = DalGroupBuyingProductGroupConfig.GetGroupBuyingV2ConfigByGroupId(conn, data.ProductGroupId);
                        if (oldData != null)
                        {
                            oldData.GroupProductDetails = DalGroupBuyingProductGroupConfig.GetGroupBuyingV2ProductConfigByGroupId(conn, new List <string> {
                                data.ProductGroupId
                            });
                        }

                        DalGroupBuyingProductGroupConfig.UpdateGroupBuyingGroupConfig(conn, data);
                        DalGroupBuyingProductGroupConfig.DeleteGroupBuyingProductConfig(conn, data.ProductGroupId);
                        foreach (var item in data.GroupProductDetails)
                        {
                            item.ProductGroupId = data.ProductGroupId;
                            item.Creator        = data.Creator;
                            DalGroupBuyingProductGroupConfig.InsertGroupBuyingProductConfig(conn, item);
                        }
                    }
                    result = true;
                });
            }
            catch (Exception ex)
            {
                msg = "系统异常";
                logger.Error(ex);
            }
            if (result)
            {
                ThreadPool.QueueUserWorkItem(o =>
                {
                    foreach (var item in data.GroupProductDetails)
                    {
                        TuhuNotification.SendNotification("#.PinTuanProductStatusSyncQueue.#",
                                                          new Dictionary <string, object>
                        {
                            ["PId"]            = item.PID,
                            ["ProductGroupId"] = data.ProductGroupId
                        }, 3000);
                    }
                    InsertLog(data.ProductGroupId, "GroupBuyingProductConfig", "UpsertGroupBuyingConfig", result ? "操作成功" : msg, JsonConvert.SerializeObject(oldData), JsonConvert.SerializeObject(data), data.Creator);
                    ActivityService.RefrestPTCache(data.ProductGroupId);
                });
            }
            return(Tuple.Create(result, msg));
        }
        public List <GroupBuyingProductConfigEntity> RefreshProductConfigByGroupId(string productGroupId, bool isLottery)
        {
            List <GroupBuyingProductConfigEntity> result = new List <GroupBuyingProductConfigEntity>();

            try
            {
                dbScopeReadManager.Execute(conn =>
                {
                    var data = DalGroupBuyingProductGroupConfig.GetGroupBuyingV2ProductConfigByGroupId(conn, new List <string> {
                        productGroupId
                    });
                    var products = DalGroupBuyingProductGroupConfig.GetProductsByPIDAndIsLottery(conn, data.Where(x => x.DisPlay == true).FirstOrDefault()?.PID, isLottery);
                    if (products != null && products.Any())
                    {
                        var purchaseInfo = PurchaseService.SelectPurchaseInfoByPID(products.Select(x => x.PID).ToList());
                        purchaseInfo     = from c in purchaseInfo
                                           group c by c.PID into g
                                           select g.OrderByDescending(x => x.CreatedDate).FirstOrDefault();
                        products.ForEach(x =>
                        {
                            GroupBuyingProductConfigEntity item = new GroupBuyingProductConfigEntity();
                            var existItem = data.Where(_ => String.Equals(_.PID, x.PID)).FirstOrDefault();
                            var pidItem   = purchaseInfo?.Where(y => String.Equals(x.PID, y.PID))?.FirstOrDefault();
                            if (pidItem != null)
                            {
                                if (pidItem?.OfferContractPrice > 0 || pidItem?.OfferPurchasePrice > 0)
                                {
                                    item.CostPrice = pidItem.OfferPurchasePrice >= pidItem.OfferContractPrice ? pidItem.OfferContractPrice : pidItem.OfferPurchasePrice;
                                }
                                else if (pidItem.PurchasePrice > 0 && pidItem.ContractPrice > 0)
                                {
                                    x.CostPrice = pidItem.PurchasePrice >= pidItem.ContractPrice ? pidItem.ContractPrice : pidItem.PurchasePrice;
                                }
                                else if (pidItem.PurchasePrice > 0 || pidItem.ContractPrice > 0)
                                {
                                    x.CostPrice = pidItem.PurchasePrice > 0 ? pidItem.PurchasePrice : pidItem.ContractPrice;
                                }
                            }
                            item.PID                = x.PID;
                            item.ProductName        = x.DisplayName;
                            item.UpperLimitPerOrder = existItem?.UpperLimitPerOrder ?? 1;
                            item.BuyLimitCount      = existItem?.BuyLimitCount ?? 0;
                            item.DisPlay            = existItem?.DisPlay ?? false;
                            item.UseCoupon          = existItem?.UseCoupon ?? true;
                            item.IsShow             = existItem?.IsShow ?? true;
                            item.OriginalPrice      = existItem?.OriginalPrice ?? decimal.Parse(x.CY_List_Price.ToString());
                            item.FinalPrice         = existItem?.FinalPrice ?? decimal.Parse(x.CY_List_Price.ToString());
                            item.SpecialPrice       = existItem?.SpecialPrice ?? decimal.Parse(x.CY_List_Price.ToString());
                            item.TotalStockCount    = existItem?.TotalStockCount ?? 1000000;
                            item.CurrentSoldCount   = existItem?.CurrentSoldCount ?? 0;
                            item.IsAutoStock        = existItem?.IsAutoStock ?? false;
                            item.IsShowApp          = existItem?.IsShowApp ?? false;
                            result.Add(item);
                        });
                    }
                });
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
            return(result.OrderByDescending(x => x.DisPlay).ToList());
        }