Esempio n. 1
0
        /// <summary>
        /// 同步正式环境历史数据使用 勿调用
        /// </summary>
        /// <returns></returns>
        private ResultDTO SaveMicroshopExt()
        {
            var result = new ResultDTO {
                isSuccess = false
            };
            var query = from d in Distributor.ObjectSet() select d;

            foreach (var distributor in query)
            {
                var isE = Microshop.ObjectSet().FirstOrDefault(t => t.Key == distributor.Id);
                if (isE != null && isE.QRCodeUrl == "")
                {
                    var             id = Guid.NewGuid();
                    MicroshopTypeVO mv = new MicroshopTypeVO()
                    {
                        Value = 1
                    };
                    var url = BTP.Common.CustomConfig.BtpDomain + string.Format("/Distribute/MicroshopIndex?appid={0}&microshopId={1}&distributorId={2}",
                                                                                distributor.EsAppId, id, distributor.Id) + "&type=tuwen&source=share&SrcType=34&isshowsharebenefitbtn=1";

                    List <Guid> users = new List <Guid> {
                        distributor.UserId
                    };
                    var user     = CBCSV.Instance.GetUserInfoWithAccountList(users)[0];
                    var logo     = user.HeadIcon;
                    var userName = user.Name;

                    var qRCodeUrl = CreateQrCode(logo, url);
                    var ms        = new Microshop
                    {
                        Id          = id,
                        SubTime     = DateTime.Now,
                        ModifiedOn  = DateTime.Now,
                        AppId       = distributor.EsAppId,
                        UserId      = distributor.UserId,
                        Logo        = logo,
                        Name        = userName + "的小店",
                        Url         = url,
                        Type        = mv,
                        Key         = distributor.Id,
                        QRCodeUrl   = qRCodeUrl,
                        EntityState = EntityState.Added
                    };
                    ContextFactory.CurrentThreadContext.SaveObject(ms);
                }
            }

            int msCount = ContextFactory.CurrentThreadContext.SaveChanges();

            if (msCount > 0)
            {
                result.isSuccess = true;
                result.Message   = "添加成功";
            }
            else
            {
                result.Message = "添加失败";
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// 修改微小店信息
        /// </summary>
        public ResultDTO UpdateDistributionMicroShopExt(MicroshopDTO microshopDto)
        {
            var result = new ResultDTO {
                isSuccess = true
            };

            var microshop = Microshop.ObjectSet().FirstOrDefault(t => t.Id == microshopDto.Id);

            if (microshop == null)
            {
                result.isSuccess = true;
                result.Message   = "获取数据失败";
                return(result);
            }

            if (!string.IsNullOrEmpty(microshopDto.Logo))
            {
                microshop.Logo      = microshopDto.Logo;
                microshop.QRCodeUrl = microshopDto.QRCodeUrl;
            }
            if (!string.IsNullOrEmpty(microshopDto.Name))
            {
                microshop.Name = microshopDto.Name;
            }
            microshop.ModifiedOn  = DateTime.Now;
            microshop.EntityState = EntityState.Modified;
            ContextFactory.CurrentThreadContext.SaveObject(microshop);

            int mcCount = ContextFactory.CurrentThreadContext.SaveChanges();

            if (mcCount > 0)
            {
                result.isSuccess = true;
                result.Message   = "修改成功";
            }
            else
            {
                result.Message = "修改失败";
            }
            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// 更新微小店QrCode
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public ResultDTO UpdateMicroshopQrCodeExt(UpdateQrCodeRequestDTO dto)
        {
            ContextSession contextSession = ContextFactory.CurrentThreadContext;

            var microShop = Microshop.ObjectSet().FirstOrDefault(t => t.Id == dto.MicroShopId);

            if (microShop == null)
            {
                return(new ResultDTO {
                    isSuccess = false, ResultCode = 0, Message = "没有找到ID='" + dto.MicroShopId + "'的数据"
                });
            }

            microShop.QRCodeUrl   = dto.QRCodeUrl;
            microShop.EntityState = EntityState.Modified;

            contextSession.SaveChanges();

            return(new ResultDTO {
                isSuccess = true, ResultCode = 1, Message = "OK"
            });
        }
Esempio n. 4
0
        /// <summary>
        /// 获取分销商微小店信息
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public DistributionMicroShopDTO GetDistributionMicroShopExt(Guid appId, Guid userId)
        {
            DistributionMicroShopDTO distributionMicroShopDto = new DistributionMicroShopDTO();

            try
            {
                var temp = (from ms in Microshop.ObjectSet()
                            where ms.AppId == appId && ms.UserId == userId
                            select new DistributionMicroShopDTO
                {
                    Id = ms.Id,
                    SubTime = ms.SubTime,
                    ModifiedOn = ms.ModifiedOn,
                    AppId = ms.AppId,
                    UserId = ms.UserId,
                    Logo = ms.Logo,
                    QRCodeUrl = ms.QRCodeUrl,
                    Name = ms.Name,
                    Url = ms.Url,
                    Type = (MicroshopTypeEnum)ms.Type.Value,
                    Key = ms.Key
                });
                distributionMicroShopDto = temp.FirstOrDefault();
                if (distributionMicroShopDto != null)
                {
                    //获取下架商品
                    var commodityIds = MicroshopCom.ObjectSet().Where(t => !t.IsDel && t.MicroshopId == distributionMicroShopDto.AppId).Select(c => c.CommodityId).Distinct().ToArray();
                    var dc           = (from cd in CommodityDistribution.ObjectSet()
                                        join c in Commodity.ObjectSet() on cd.Id equals c.Id
                                        where commodityIds.Contains(c.Id)
                                        select new CommodityVM
                    {
                        Id = c.Id,
                        Name = c.Name,
                        Price = c.Price,
                        MarketPrice = c.MarketPrice,
                        Pic = c.PicturesPath,
                        L1Percent = Math.Round((decimal)(cd.L1Percent * c.Price), 2),
                        L2Percent = Math.Round((decimal)(cd.L2Percent * c.Price), 2),
                        L3Percent = Math.Round((decimal)(cd.L3Percent * c.Price), 2)
                    });
                    List <CommodityVM> commodityVmsD = new List <CommodityVM>();
                    foreach (var commodityVm in dc)
                    {
                        if (commodityVm.L1Percent == null || commodityVm.L2Percent == null || commodityVm.L3Percent == null)
                        {
                            var model = AppExtension.ObjectSet().FirstOrDefault(t => t.Id == appId);
                            commodityVm.L1Percent = Math.Round((decimal)(model.DistributeL1Percent * commodityVm.Price), 2);
                            commodityVm.L2Percent = Math.Round((decimal)(model.DistributeL2Percent * commodityVm.Price), 2);
                            commodityVm.L3Percent = Math.Round((decimal)(model.DistributeL3Percent * commodityVm.Price), 2);
                        }
                        commodityVmsD.Add(commodityVm);
                    }
                    distributionMicroShopDto.DownCommodityDtos = commodityVmsD.ToList();

                    //获取符合条件的上架商品
                    var uc = (from cd in CommodityDistribution.ObjectSet()
                              join c in Commodity.ObjectSet() on cd.Id equals c.Id
                              where c.AppId == appId && !c.IsDel && c.CommodityType == 0 && c.State == 0 && !commodityIds.Contains(c.Id)
                              select new CommodityVM
                    {
                        Id = c.Id,
                        Name = c.Name,
                        Price = c.Price,
                        MarketPrice = c.MarketPrice,
                        Pic = c.PicturesPath,
                        L1Percent = Math.Round((decimal)(cd.L1Percent * c.Price), 2),
                        L2Percent = Math.Round((decimal)(cd.L2Percent * c.Price), 2),
                        L3Percent = Math.Round((decimal)(cd.L3Percent * c.Price), 2)
                    });
                    List <CommodityVM> commodityVmsU = new List <CommodityVM>();
                    foreach (var commodityVm in uc)
                    {
                        if (commodityVm.L1Percent == null || commodityVm.L2Percent == null || commodityVm.L3Percent == null)
                        {
                            var model = AppExtension.ObjectSet().FirstOrDefault(t => t.Id == appId);
                            commodityVm.L1Percent = Math.Round((decimal)(model.DistributeL1Percent * commodityVm.Price), 2);
                            commodityVm.L2Percent = Math.Round((decimal)(model.DistributeL2Percent * commodityVm.Price), 2);
                            commodityVm.L3Percent = Math.Round((decimal)(model.DistributeL3Percent * commodityVm.Price), 2);
                        }
                        commodityVmsU.Add(commodityVm);
                    }
                    distributionMicroShopDto.UpCommodityDtos = commodityVmsU.ToList();
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.ToString());
            }
            return(distributionMicroShopDto);
        }
Esempio n. 5
0
        /// <summary>
        /// 获取微小店
        /// </summary>
        /// <param name="appId"></param>
        /// /// <param name="userId"></param>
        /// <returns></returns>
        public MicroshopDTO GetMicroshopExt(Guid appId, Guid userId)
        {
            var entity = Microshop.ObjectSet().FirstOrDefault(x => x.AppId == appId && x.UserId == userId);

            return(entity == null ? null : entity.ToEntityData());
        }
Esempio n. 6
0
        /// <summary>
        /// 根据Id获取微小店
        /// </summary>
        /// <param name="microshopId"></param>
        /// <returns></returns>
        public MicroshopDTO GetMicroshopExt(Guid microshopId)
        {
            var entity = Microshop.ObjectSet().FirstOrDefault(x => x.Id == microshopId);

            return(entity == null ? null : entity.ToEntityData());
        }
Esempio n. 7
0
        private Tuple <Distributor, Microshop> PassAuditing_DistributorAndMicroshop(DistributionApply apply)
        {
            ContextSession contextSession = ContextFactory.CurrentThreadContext;
            var            now            = DateTime.Now;

            var appId            = apply.RuleId;//Apply的RuleId是DistributionRule的Id,而它就是AppId
            var newDistributorId = Guid.NewGuid();

            var level = apply.ParentId.Equals(Guid.Empty) ? 1
                : Distributor.ObjectSet().First(x => x.Id == apply.ParentId).Level + 1;
            var parentDistributorIds = new List <Guid>
            {
                GetDistributorGrandFatherId(apply.ParentId),
                apply.ParentId,
                newDistributorId
            }.Where(x => !x.Equals(Guid.Empty))
            .Select(x => x.ToString()).ToArray();

            var distributorKey = string.Join(",", parentDistributorIds);
            var remarks        = "";
            var distributor    = new Distributor
            {
                Id          = newDistributorId,
                UserId      = apply.UserId,
                UserName    = apply.UserName,
                UserCode    = apply.UserCode,
                SubTime     = now,
                ModifiedOn  = now,
                EsAppId     = appId,
                ParentId    = apply.ParentId,
                Level       = level,
                Key         = distributorKey,
                UserSubTime = apply.SubTime,
                PicturePath = apply.PicturePath,
                Remarks     = remarks,
                EntityState = EntityState.Added
            };

            contextSession.SaveObject(distributor);

            var logo     = "";
            var userInfo = CBCSV.Instance.GetUserInfoWithAccountList(new List <Guid> {
                apply.UserId
            });

            if (userInfo != null && userInfo.Count > 0)
            {
                logo = userInfo[0].HeadIcon;
            }
            else
            {
                LogHelper.Error(string.Format("调用CBCSV.Instance.GetUserInfoWithAccountList({0}),没有返回有效值值!", apply.UserId));
            }

            var qrCodeUrl      = "";//暂时为空,后续通过update动作赋值
            var newMicroshopId = Guid.NewGuid();
            var microshopType  = MicroshopTypeEnum.Distribution;
            var microshopUrl   = CreateMicroShopUrl(appId, newMicroshopId, distributor.Id);
            var microshop      = new Microshop
            {
                Id          = newMicroshopId,
                SubTime     = now,
                ModifiedOn  = now,
                AppId       = appId,
                UserId      = apply.UserId,
                Logo        = logo,
                QRCodeUrl   = qrCodeUrl,
                Name        = string.Format("{0}的小店", apply.UserName),
                Url         = microshopUrl,
                Type        = microshopType,
                Key         = distributor.Id,
                EntityState = EntityState.Added
            };

            contextSession.SaveObject(microshop);

            contextSession.SaveChanges();

            return(new Tuple <Distributor, Microshop>(distributor, microshop));
        }