public EntityComView(string comName, FieldInfo[] fieldInfos, BaseCom baseCom) { ComName = comName; ComAttribute comAttribute = LCReflect.GetTypeAttr <ComAttribute>(baseCom.GetType()); if (comAttribute != null) { ComName = comAttribute.ViewName; } for (int i = 0; i < fieldInfos.Length; i++) { FieldInfo info = fieldInfos[i]; ComKeyValueView keyValue = new ComKeyValueView(info.Name, info, baseCom); ComValueAttribute comValueAttribute = LCReflect.GetFieldAttr <ComValueAttribute>(info); if (comValueAttribute != null) { if (comValueAttribute.ViewEditor) { EditorValueList.Add(keyValue); } else { if (comValueAttribute.ShowView) { ValueList.Add(keyValue); } } } } }
/// <summary> /// 检测组件是否是全局单一 /// </summary> /// <param name="comType"></param> /// <returns></returns> public static bool CheckComIsGlobal(Type comType) { if (comType == null) { return(false); } ComAttribute comAttribute = LCReflect.GetTypeAttr <ComAttribute>(comType); if (comAttribute == null) { return(false); } return(comAttribute.IsGlobal); }
//实体编辑界面 private void ShowSelEntityWindow(float width) { //基础配置只读 EDTypeField.CreateLableField("实体名:", SelEntity.EntityName, width, 20); object tipobj = SelEntity.TipStr; EDTypeField.CreateTypeField("描述信息:", ref tipobj, typeof(string), width, 20); SelEntity.TipStr = tipobj.ToString(); //决策分组 SelEntity.Group = (EntityDecGroup)EditorGUILayout.EnumPopup("实体决策分组", SelEntity.Group); EditorGUILayout.Space(); //预制体路径 EditorGUILayout.LabelField("选择预制体:"); GameObject prefab = null; prefab = EditorGUILayout.ObjectField(prefab, typeof(GameObject), false) as GameObject; if (prefab != null) { SelEntity.PrefabPath = AssetDatabase.GetAssetPath(prefab); } EditorGUILayout.LabelField("预制体路径:"); EditorGUILayout.LabelField(SelEntity.PrefabPath, "", "box"); EditorGUILayout.Space(); //组件列表 EditorGUILayout.LabelField("组件列表:"); EDLayout.CreateScrollView(ref ComListPos, "box", width, 150, () => { for (int i = 0; i < SelEntity.Coms.Count; i++) { //按钮名 string btnName = SelEntity.Coms[i].ComName; Type comType = LCReflect.GetType(SelEntity.Coms[i].ComName); if (comType != null) { ComAttribute comAttribute = LCReflect.GetTypeAttr <ComAttribute>(comType); if (comAttribute != null) { btnName = comAttribute.ViewName; } } else { SelEntity.Coms.RemoveAt(i); continue; } EDButton.CreateBtn(btnName, width * 0.8f, 20, () => { int comIndex = i; EDPopMenu.CreatePopMenu(new List <string>() { "编辑组件", "删除组件" }, (int index) => { if (index == 0) { SelCom = LCReflect.GetType(SelEntity.Coms[comIndex].ComName); } else if (index == 1) { SelEntity.Coms.RemoveAt(comIndex); } }); }); EditorGUILayout.Space(); } }); //添加组件 EDButton.CreateBtn("添加组件", 200, 50, () => { List <Type> comTyps = LCReflect.GetClassByType <BaseCom>(); List <string> showList = new List <string>(); List <Type> showTyps = new List <Type>(); for (int j = 0; j < comTyps.Count; j++) { if (CheckContainCom(comTyps[j].FullName)) { continue; } showTyps.Add(comTyps[j]); ComAttribute comAttribute = LCReflect.GetTypeAttr <ComAttribute>(comTyps[j]); if (comAttribute != null) { if (comAttribute.GroupName == "") { comAttribute.GroupName = "Default"; } showList.Add(comAttribute.GroupName + "/" + comAttribute.ViewName); } else { showList.Add(comTyps[j].FullName); } } EDPopMenu.CreatePopMenu(showList, (int index) => { Type comType = showTyps[index]; if (CheckContainCom(comType.FullName)) { Debug.LogError("重复的组件>>>>>>>>" + comType.FullName); return; } EntityComJson comJson = new EntityComJson() { ComName = comType.FullName, }; SelEntity.Coms.Add(comJson); }); }); //保存配置 EDButton.CreateBtn("保存配置", 200, 50, SaveEntityJsonList); //删除实体 EDButton.CreateBtn("删除实体", 200, 30, () => { EDDialog.CreateDialog("删除", "确认删除该实体吗?", (() => { MEntityJsonList.List.Remove(SelEntity); SelEntityChange(null); })); }); }
/// <summary> /// 自动同步严选商品信息 /// </summary> /// <param name="AppId"></param> /// <param name="Ids"></param> /// <returns></returns> public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.YJEmployee.JdCommoditySearchDTO> AutoSyncYXCommodityInfoExt(System.Guid AppId, System.Collections.Generic.List <System.Guid> Ids) { try { Jinher.AMP.App.Deploy.CustomDTO.AppIdOwnerIdTypeDTO appModel = APPSV.Instance.GetAppOwnerInfo(AppId); bool isFnull = true; if (appModel.OwnerType == 0) { CBC.Deploy.CustomDTO.OrgInfoNewDTO orgInfoDTO = CBCSV.Instance.GetOrgInfoNewBySubId(appModel.OwnerId); if (orgInfoDTO == null || string.IsNullOrEmpty(orgInfoDTO.CompanyPhone)) { isFnull = false; } } JdCommoditySearchDTO JdComDTO = new JdCommoditySearchDTO(); Guid userId = this.ContextDTO.LoginUserID; ContextSession contextSession = ContextFactory.CurrentThreadContext; if (isFnull) { //取出补全的商品信息 var YXComList = JdCommodity.ObjectSet().Where(p => p.AppId == AppId && Ids.Contains(p.Id)).ToList(); List <string> skuIds = YXComList.Select(s => s.JDCode).ToList(); List <YXComDetailDTO> YXComDetailList = new List <YXComDetailDTO>(); for (int i = 0; i < skuIds.Count; i += 30) { YXComDetailList.AddRange(YXSV.GetComDetailList(skuIds.Skip(i).Take(30).ToList())); } if (!YXComDetailList.Any()) { return(new ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.YJEmployee.JdCommoditySearchDTO> { Data = JdComDTO, ResultCode = 1, isSuccess = false, Message = "未获取到严选商品信息" }); } #region 获取所有skuid库存 处理严选商品属性 List <StockDTO> YXstockNumList = new List <StockDTO>(); //库存信息 List <itemSkuSpecValueList> skuAttr = new List <itemSkuSpecValueList>(); //商品属性 if (YXComDetailList.Any()) { List <string> Sku = new List <string>(); foreach (var item in YXComDetailList) { Sku.AddRange(item.skuList.Select(s => s.id).ToList()); foreach (var it in item.skuList) { skuAttr.AddRange(it.itemSkuSpecValueList); } } //批量获取严选库存信息 for (int i = 0; i < Sku.Count; i += 90) { YXstockNumList.AddRange(YXSV.GetStockNum(Sku.Skip(i).Take(90).ToList())); //Thread.Sleep(1000); } //写入严选商品属性 List <ComAttribute> ComAttr = new List <ComAttribute>(); foreach (var item in skuAttr) { ComAttribute Com = new ComAttribute(); Com.AttrName = item.skuSpec.name; Com.Attrvalue = item.skuSpecValue.value; ComAttr.Add(Com); } var firstAttributeName = ComAttr.Select(s => s.AttrName).ToList(); //写入不存在的商品属性 List <string> colorAndSize = new List <string>() { "颜色", "尺寸" }; var NoExistAttr = firstAttributeName.Except(Jinher.AMP.BTP.BE.Attribute.ObjectSet().Where(p => p.AppId == AppId && p.IsDel == false).Select(s => s.Name).ToList().Union(colorAndSize)).ToList(); if (NoExistAttr.Any()) { foreach (var item in NoExistAttr) { AttributeDTO attrDTO = new AttributeDTO(); attrDTO.Id = Guid.NewGuid(); attrDTO.Name = item; attrDTO.AppId = AppId; attrDTO.EntityState = System.Data.EntityState.Added; Jinher.AMP.BTP.BE.Attribute attribute = new Jinher.AMP.BTP.BE.Attribute().FromEntityData(attrDTO); attribute.SubId = userId; attribute.SubTime = DateTime.Now; contextSession.SaveObject(attribute); } } } #endregion #region 获取所有的商城分类 商品类目 //获取商城品类 var InnerCategoryNameList = YXComList.Select(s => s.VideoName.Trim()).ToList(); //获取商品分类 var CategoryNameList = YXComList.Select(s => s.CategoryName).ToList();//获取所有的商品分类 string ggg = string.Join(",", CategoryNameList.ToArray()); List <string> list = new List <string>(ggg.Split(',')); //易捷北京 var CategoryList = Category.ObjectSet().Where(p => p.AppId == new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6") && !p.IsDel && CategoryNameList.Contains(p.Name)).ToList(); var categoryList = InnerCategory.ObjectSet().Where(p => InnerCategoryNameList.Contains(p.Name) && p.AppId == new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6") && !p.IsDel).ToList(); //本地调试 //var categoryList = InnerCategory.ObjectSet().Where(p => InnerCategoryNameList.Contains(p.Name) && p.AppId == AppId && !p.IsDel).ToList(); //var CategoryList = Category.ObjectSet().Where(p => p.AppId == AppId && !p.IsDel && list.Distinct().Contains(p.Name)).ToList(); #endregion //获取不到商品类目的 List <string> NoCategoryData = new List <string>(); //店铺中存在的备注编码进行更新 不存在则插入 var ExistCommodity = Commodity.ObjectSet().Where(p => skuIds.Contains(p.Barcode) && !p.IsDel && p.AppId == AppId).ToList(); JdComDTO.RepeatData = ExistCommodity.Select(s => s.Barcode).ToList(); foreach (var item in ExistCommodity) { var YXCom = YXComList.FirstOrDefault(p => p.JDCode == item.Barcode); var YXComDetailInfo = YXComDetailList.Where(p => p.id == item.Barcode).FirstOrDefault(); var minSortValueQuery = (from m in Commodity.ObjectSet() where m.AppId == AppId && m.CommodityType == 0 select m); int?minSort = minSortValueQuery.Min(m => (int?)m.SortValue); int minSortValue = 2; if (minSort.HasValue) { minSortValue = minSort.Value; } item.Name = "网易严选 " + YXComDetailInfo.name; item.SubId = userId; item.No_Number = YXCom.No_Number ?? 0; item.Price = YXComDetailInfo.skuList.Min(p => p.channelPrice); item.Stock = YXCom.Stock; item.PicturesPath = YXComDetailInfo.listPicUrl; item.Description = "<div class=\"JD-goods\">" + YXComDetailInfo.itemDetail.detailHtml + "</div>"; //Com.State = 1; 只更新商品信息,不更新商品上下架状态 item.IsDel = false; item.AppId = YXCom.AppId; item.TotalCollection = 0; item.TotalReview = 0; item.Salesvolume = 0; item.ModifiedOn = DateTime.Now; item.ComAttribute = YXCom.ComAttribute; item.CategoryName = YXCom.CategoryName; item.SortValue = minSortValue - 1; item.FreightTemplateId = YXCom.FreightTemplateId; //99元以下商品8元运费 item.MarketPrice = YXCom.MarketPrice; //Com.Weight = YXComDetailInfo.; //Com.SaleService = JdComDetailInfo.wareQD + "<br>" + JdComDetailInfo.shouhou; item.SaleAreas = YXCom.SaleAreas; item.SharePercent = YXCom.SharePercent; item.CommodityType = 0; item.Duty = YXCom.Duty; item.TaxRate = YXCom.TaxRate; item.TaxClassCode = YXCom.TaxClassCode; item.Unit = "件"; item.InputRax = YXCom.InputRax; if (YXComDetailInfo.skuList.Count() == 1) { //单条属性与库存表保持一致 item.JDCode = YXComDetailInfo.skuList.FirstOrDefault().id; item.Code = item.JDCode; item.Barcode = YXComDetailInfo.id; item.No_Code = item.JDCode; } else { //多条属性存储SPU item.JDCode = YXComDetailInfo.skuList.OrderBy(p => p.channelPrice).FirstOrDefault().id; item.Code = item.JDCode; item.Barcode = YXComDetailInfo.id; //存严选商品的SPU item.No_Code = item.JDCode; } item.CostPrice = item.Price * Convert.ToDecimal(0.8); item.ServiceSettingId = YXCom.ServiceSettingId; //Com.TechSpecs = JdComDetailInfo.param; item.SaleService = YXCom.SaleService; item.Type = 0; item.YJCouponActivityId = ""; item.YJCouponType = ""; item.ModifieId = userId; List <ComAttributeDTO> ComAttr = new List <ComAttributeDTO>(); foreach (var skuitem in YXComDetailInfo.skuList) { foreach (var it in skuitem.itemSkuSpecValueList) { ComAttributeDTO ComAtt = new ComAttributeDTO(); ComAtt.Attribute = it.skuSpec.name; ComAtt.SecondAttribute = it.skuSpecValue.value; ComAttr.Add(ComAtt); } } item.ComAttribute = JsonHelper.JsonSerializer <List <ComAttributeDTO> >(ComAttr); item.RefreshCache(EntityState.Modified); //更新库存表 UpdateCommodityStock(item, YXComDetailInfo, YXstockNumList, contextSession); int count1 = contextSession.SaveChanges(); //更新JdCommodity表中状态 YXCom.State = 1; #region 商品图片 //删除图片 ProductDetailsPictureBP pdpbp = new ProductDetailsPictureBP(); pdpbp.DeletePictures(item.Id); List <string> PicList = new List <string>(); PicList.Add(YXComDetailInfo.itemDetail.picUrl1); PicList.Add(YXComDetailInfo.itemDetail.picUrl2); PicList.Add(YXComDetailInfo.itemDetail.picUrl3); PicList.Add(YXComDetailInfo.itemDetail.picUrl4); //添加图片 int sort = 1; foreach (var itempic in PicList) { if (!string.IsNullOrWhiteSpace(itempic) && itempic.Length >= 50) { ProductDetailsPicture pic = ProductDetailsPicture.CreateProductDetailsPicture(); pic.Name = "商品图片"; pic.SubId = userId; pic.SubTime = DateTime.Now; pic.PicturesPath = itempic; pic.CommodityId = item.Id; pic.Sort = sort; contextSession.SaveObject(pic); sort++; } } #endregion #region 商品分类 //删除商品分类 var catList = CommodityCategory.ObjectSet().Where(c => c.CommodityId == item.Id).ToList(); foreach (var commodityCategory in catList) { contextSession.Delete(commodityCategory); } //添加商品分类 var ComCategory = CategoryList.Where(p => YXCom.CategoryName.Contains(p.Name)).ToList(); if (ComCategory.Any()) { foreach (var itemcate in ComCategory) { CommodityCategory comcate = CommodityCategory.CreateCommodityCategory(); comcate.CategoryId = itemcate.Id; comcate.CommodityId = item.Id; comcate.SubId = userId; comcate.SubTime = DateTime.Now; comcate.Name = "商品分类"; comcate.IsDel = false; #region 本地测试 //comcate.SubId = AppId; //comcate.AppId = AppId; //comcate.CrcAppId = Jinher.JAP.Common.Crc64.ComputeAsAsciiGuid(AppId); #endregion //正式环境 comcate.SubId = new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6"); comcate.AppId = new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6"); comcate.CrcAppId = Jinher.JAP.Common.Crc64.ComputeAsAsciiGuid(new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6")); contextSession.SaveObject(comcate); } } else { NoCategoryData.Add(YXCom.JDCode); } #endregion #region 商城分类 //删除商城分类 var oldCCs = CommodityInnerCategory.ObjectSet().Where(c => c.CommodityId == item.Id).ToList(); foreach (var commodityCategory in oldCCs) { contextSession.Delete(commodityCategory); } //添加商城分类 var innerCateid = categoryList.Where(p => p.Name == YXCom.VideoName.Trim()).FirstOrDefault(); if (innerCateid != null) { CommodityInnerCategory comInnerCate = CommodityInnerCategory.CreateCommodityInnerCategory(); comInnerCate.CategoryId = innerCateid.Id; comInnerCate.CommodityId = item.Id; comInnerCate.SubId = userId; comInnerCate.SubTime = DateTime.Now; comInnerCate.Name = "商品分类"; comInnerCate.IsDel = false; comInnerCate.SubId = AppId; comInnerCate.AppId = AppId; comInnerCate.CrcAppId = Jinher.JAP.Common.Crc64.ComputeAsAsciiGuid(AppId); contextSession.SaveObject(comInnerCate); } #endregion } #region 商品中不存在的插入 var NoExist = YXComList.Where(p => !JdComDTO.RepeatData.Contains(p.Barcode)).ToList(); foreach (var item in NoExist) { var YXComDetailInfo = YXComDetailList.Where(p => p.id == item.JDCode).FirstOrDefault(); var minSortValueQuery = (from m in Commodity.ObjectSet() where m.AppId == AppId && m.CommodityType == 0 select m); int?minSort = minSortValueQuery.Min(m => (int?)m.SortValue); int minSortValue = 2; if (minSort.HasValue) { minSortValue = minSort.Value; } Commodity Com = Commodity.CreateCommodity(); Com.Id = Guid.NewGuid(); Com.Name = "网易严选 " + YXComDetailInfo.name; Com.SubTime = DateTime.Now; Com.SubId = userId; Com.No_Number = item.No_Number ?? 0; Com.Price = YXComDetailInfo.skuList.Min(p => p.channelPrice); Com.Stock = item.Stock; Com.PicturesPath = YXComDetailInfo.listPicUrl; Com.Description = "<div class=\"JD-goods\">" + YXComDetailInfo.itemDetail.detailHtml + "</div>"; Com.State = 1; //只更新商品信息,不更新商品上下架状态 Com.IsDel = false; Com.AppId = item.AppId; Com.TotalCollection = 0; Com.TotalReview = 0; Com.Salesvolume = 0; Com.ModifiedOn = DateTime.Now; Com.ComAttribute = item.ComAttribute; Com.CategoryName = item.CategoryName; Com.SortValue = minSortValue - 1; Com.FreightTemplateId = item.FreightTemplateId; //99元以下商品8元运费 Com.MarketPrice = item.MarketPrice; //Com.Weight = YXComDetailInfo.; //Com.SaleService = JdComDetailInfo.wareQD + "<br>" + JdComDetailInfo.shouhou; Com.SaleAreas = item.SaleAreas; Com.SharePercent = item.SharePercent; Com.CommodityType = 0; Com.Duty = item.Duty; Com.TaxRate = item.TaxRate; Com.TaxClassCode = item.TaxClassCode; Com.Unit = "件"; Com.InputRax = item.InputRax; if (YXComDetailInfo.skuList.Count() == 1) { //单条属性与库存表保持一致 Com.JDCode = YXComDetailInfo.skuList.FirstOrDefault().id; Com.Code = Com.JDCode; Com.Barcode = YXComDetailInfo.id; Com.No_Code = Com.JDCode; } else { //多条属性存储SPU Com.JDCode = YXComDetailInfo.skuList.OrderBy(p => p.channelPrice).FirstOrDefault().id; Com.Code = Com.JDCode; Com.Barcode = YXComDetailInfo.id; //存严选商品的SPU Com.No_Code = Com.JDCode; } Com.CostPrice = Com.Price * Convert.ToDecimal(0.8); Com.ServiceSettingId = item.ServiceSettingId; //Com.TechSpecs = JdComDetailInfo.param; Com.SaleService = item.SaleService; Com.Type = 0; Com.YJCouponActivityId = ""; Com.YJCouponType = ""; Com.ModifieId = userId; List <ComAttributeDTO> ComAttr = new List <ComAttributeDTO>(); foreach (var skuitem in YXComDetailInfo.skuList) { foreach (var it in skuitem.itemSkuSpecValueList) { ComAttributeDTO ComAtt = new ComAttributeDTO(); ComAtt.Attribute = it.skuSpec.name; ComAtt.SecondAttribute = it.skuSpecValue.value; ComAttr.Add(ComAtt); } } Com.ComAttribute = JsonHelper.JsonSerializer <List <ComAttributeDTO> >(ComAttr); contextSession.SaveObject(Com); SaveCommodityStock(Com, YXComDetailInfo, YXstockNumList, contextSession); //更新JdCommodity表中状态 item.State = 1; #region 商品图片 List <string> PicList = new List <string>(); PicList.Add(YXComDetailInfo.itemDetail.picUrl1); PicList.Add(YXComDetailInfo.itemDetail.picUrl2); PicList.Add(YXComDetailInfo.itemDetail.picUrl3); PicList.Add(YXComDetailInfo.itemDetail.picUrl4); //添加图片 int sort = 1; foreach (var itempic in PicList) { if (!string.IsNullOrEmpty(itempic)) { ProductDetailsPicture pic = ProductDetailsPicture.CreateProductDetailsPicture(); pic.Name = "商品图片"; pic.SubId = userId; pic.SubTime = DateTime.Now; pic.PicturesPath = itempic; pic.CommodityId = Com.Id; pic.Sort = sort; contextSession.SaveObject(pic); sort++; } } #endregion #region 商品分类 var ComCategory = CategoryList.Where(p => item.CategoryName.Contains(p.Name)).ToList(); if (ComCategory.Any()) { foreach (var itemcate in ComCategory) { CommodityCategory comcate = CommodityCategory.CreateCommodityCategory(); comcate.CategoryId = itemcate.Id; comcate.CommodityId = Com.Id; comcate.SubId = userId; comcate.SubTime = DateTime.Now; comcate.Name = "商品分类"; comcate.IsDel = false; #region 本地测试 //comcate.SubId = AppId; //comcate.AppId = AppId; //comcate.CrcAppId = Jinher.JAP.Common.Crc64.ComputeAsAsciiGuid(AppId); #endregion comcate.SubId = new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6"); comcate.AppId = new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6"); comcate.CrcAppId = Jinher.JAP.Common.Crc64.ComputeAsAsciiGuid(new Guid("8B4D3317-6562-4D51-BEF1-0C05694AC3A6")); contextSession.SaveObject(comcate); } } else { NoCategoryData.Add(item.JDCode); } #endregion #region 商城分类 var innerCateid = categoryList.Where(p => p.Name == item.VideoName.Trim()).FirstOrDefault(); if (innerCateid != null) { CommodityInnerCategory comInnerCate = CommodityInnerCategory.CreateCommodityInnerCategory(); comInnerCate.CategoryId = innerCateid.Id; comInnerCate.CommodityId = Com.Id; comInnerCate.SubId = userId; comInnerCate.SubTime = DateTime.Now; comInnerCate.Name = "商品分类"; comInnerCate.IsDel = false; comInnerCate.SubId = AppId; comInnerCate.AppId = AppId; comInnerCate.CrcAppId = Jinher.JAP.Common.Crc64.ComputeAsAsciiGuid(AppId); contextSession.SaveObject(comInnerCate); } #endregion } #endregion int count = contextSession.SaveChanges(); JdComDTO.NoCategoryData = NoCategoryData; } return(new ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.YJEmployee.JdCommoditySearchDTO> { Data = JdComDTO, ResultCode = 0, isSuccess = true, Message = "自动同步成功" }); } catch (Exception ex) { LogHelper.Error("YJEmployeeBP.AutoSyncCommodityInfoExt 异常", ex); return(new ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.YJEmployee.JdCommoditySearchDTO> { ResultCode = 1, isSuccess = false, Message = ex.Message }); } }