public static Task <bool> UpdateGroupBuyingProductConfig(
     GroupBuyingProductConfigEntity productConfigEntity)
 => DalGroupBuyingProductGroupConfig.UpdateGroupBuyingProductConfig(productConfigEntity);
        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());
        }