/// <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);
        }
Ejemplo n.º 2
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));
        }