/// <summary> /// 添加餐厅坐标 /// </summary> /// <returns></returns> public bool AddResCoordinate(AddResCoordinateDTO addResCoordinate, string operatorName) { if (addResCoordinate == null) { ErrorCodeHelper.AddResCoordinateNull.ToException(); } if (addResCoordinate.ResId <= 0) { ErrorCodeHelper.CRestaurantNotExist.ToException(); } CRestaurantPO restaurant = CRestaurantManager.Instance.GetById(addResCoordinate.ResId); if (restaurant == null) { ErrorCodeHelper.CRestaurantNotExist.ToException(); } if (addResCoordinate.ListCoordinateInfo != null || addResCoordinate.ListCoordinateInfo.Count < 3) { ErrorCodeHelper.CoordinateInfoErr.ToException(); } List <CResCoordinatePO> listResCoordinate = GetCResCoordinateList(null, restaurant.ResUUID, null, null, null); if (listResCoordinate != null && listResCoordinate.Count > 0) { listResCoordinate.ForEach(item => { item.IsDelete = true; Update(item, operatorName); }); } string uuid = System.Guid.NewGuid().ToString(); addResCoordinate.ListCoordinateInfo.ForEach(item => { CResCoordinatePO po = new CResCoordinatePO { CreateName = operatorName, CreateTime = DateTime.Now, IsDelete = false, Latitude = item.Latitude, Longitude = item.Longitude, MarkUUID = uuid, ResUUID = restaurant.ResUUID, }; Add(po, operatorName); }); return(true); }
public List <CCouponDTO> GetNoUseCouponDTOById(int resId, int memberId) { CRestaurantPO restaurantPO = CRestaurantManager.Instance.GetById(resId); if (restaurantPO == null) { throw new BusinessException("此餐厅不存在"); } CMemberWeiXinPO memberWeiXinPO = CMemberWeiXinManager.Instance.GetById(memberId); if (memberWeiXinPO == null) { throw new BusinessException("此微信用户不存在"); } return(this.GetNoUseCouponDTO(restaurantPO.ResUUID, memberWeiXinPO.MemberUUID)); }
public int AddOrUpdateCommodityCategory(AddOrUpdateCommodityCategoryDTO commodityCategory, string operatorName) { if (commodityCategory == null) { throw new ArgumentNullException("商品类别必须设定"); } if (string.IsNullOrWhiteSpace(operatorName)) { throw new ArgumentNullException("操作人必须设定"); } CRestaurantPO restaurant = CRestaurantManager.Instance.GetById(commodityCategory.ResId); if (restaurant == null) { throw new BusinessException("此餐厅不存在"); } CCommodityCategoryPO commodityCategoryPO = null; if (commodityCategory.Id > 0) { commodityCategoryPO = Instance.GetById(commodityCategory.Id); if (commodityCategoryPO == null) { throw new BusinessException("商品类别不存在"); } } else { commodityCategoryPO = new CCommodityCategoryPO(); } commodityCategoryPO.ChineseName = commodityCategory.ChineseName; commodityCategoryPO.EnglishName = commodityCategory.EnglishName; commodityCategoryPO.PicPath = commodityCategory.PicPath; commodityCategoryPO.Remark = commodityCategory.Remark; commodityCategoryPO.ResUUID = restaurant.ResUUID; commodityCategoryPO.Sort = commodityCategory.Sort; commodityCategoryPO.IsDelete = commodityCategory.IsDelete; if (commodityCategoryPO.Id > 0) { return(this.Update(commodityCategoryPO, operatorName)); } return(this.Add(commodityCategoryPO, operatorName)); }
public int AddOrUpdatetPropertyCategory(AddOrUpdatetPropertyCategoryDTO propertyCategory, string operatorName) { if (propertyCategory == null) { throw new ArgumentNullException("商品类别必须设定"); } if (string.IsNullOrWhiteSpace(operatorName)) { throw new ArgumentNullException("操作人必须设定"); } CRestaurantPO restaurant = CRestaurantManager.Instance.GetById(propertyCategory.ResId); if (restaurant == null) { throw new BusinessException("此餐厅不存在"); } CPropertyCategoryPO propertyCategoryPO = null; if (propertyCategory.Id > 0) { propertyCategoryPO = Instance.GetById(propertyCategory.Id); if (propertyCategoryPO == null) { throw new BusinessException("商品类别不存在"); } } else { propertyCategoryPO = new CPropertyCategoryPO(); } propertyCategoryPO.ChineseName = propertyCategory.ChineseName; propertyCategoryPO.EnableMultiple = propertyCategory.EnableMultiple; propertyCategoryPO.EnglishName = propertyCategory.EnglishName; propertyCategoryPO.IsDelete = propertyCategory.IsDelete; propertyCategoryPO.ResUUID = restaurant.ResUUID; propertyCategoryPO.Sort = propertyCategory.Sort; propertyCategoryPO.Type = propertyCategory.Type; if (propertyCategoryPO.Id > 0) { return(this.Update(propertyCategoryPO, operatorName)); } return(this.Add(propertyCategoryPO, operatorName)); }
public List <CPropertyCategoryDTO> GetPropertyCategoryDTO(int resId) { if (resId <= 0) { throw new BusinessException("餐厅ID不正确"); } CRestaurantPO restaurant = CRestaurantManager.Instance.GetById(resId); if (restaurant == null) { throw new BusinessException("餐厅不存在"); } List <CPropertyCategoryDTO> list = new List <CPropertyCategoryDTO>(); Core.Data.QueryResult <CPropertyCategoryPO> queryPropertyCategory = this.GetPropertyCategorys(restaurant.ResUUID, null, 1, 0x3e8); if ((queryPropertyCategory.TotalCount != 0) && ((queryPropertyCategory.Items != null) && (queryPropertyCategory.Items.Length > 0))) { list.AddRange(base.PoToDtoList(queryPropertyCategory.Items.ToList <CPropertyCategoryPO>())); } return(list); }
/// <summary> /// 获取地址 /// </summary> /// <param name="id"></param> /// <param name="memberAddressUUID"></param> /// <param name="memberUUID"></param> /// <param name="name"></param> /// <param name="telephone"></param> /// <param name="cityId"></param> /// <param name="address"></param> /// <param name="houseNumber"></param> /// <param name="latitude"></param> /// <param name="longitude"></param> /// <returns></returns> public List <CMemberAddressDTO> GetAllMemberAddress(int?id, string memberAddressUUID, string memberUUID, string name, string telephone, string cityId, string address, string houseNumber, int?shopId) { List <CMemberAddressDTO> listMemeberAddress = new List <CMemberAddressDTO>(); List <CMemberAddressDTO> memberAddresResult = GetMemberAddressDTOList(id, memberAddressUUID, memberUUID, name, telephone, cityId, address, houseNumber); if (memberAddresResult == null || memberAddresResult.Count == 0) { return(listMemeberAddress); } if (!shopId.HasValue) { return(memberAddresResult); } CRestaurantPO restaurant = CRestaurantManager.Instance.GetById(shopId.Value); if (restaurant == null) { return(new List <CMemberAddressDTO>()); } memberAddresResult.ForEach(item => { List <CResCoordinatePO> listResCoordinate = CResCoordinateManager.Instance.GetCResCoordinateList(null, restaurant.ResUUID, null, null, null); if (CRestaurantManager.Instance.Contains(listResCoordinate, item.Longitude, item.Latitude) == true) { item.IsOutRange = false; } else { item.IsOutRange = true; } listMemeberAddress.Add(item); }); return(listMemeberAddress); }
public List <GoodsClassifyDTO> GetGoodsClassifyDTO(int resId) { if (resId <= 0) { throw new BusinessException("餐厅ID不正确"); } CRestaurantPO restaurant = CRestaurantManager.Instance.GetById(resId); if (restaurant == null) { throw new BusinessException("餐厅不存在"); } List <GoodsClassifyDTO> list = new List <GoodsClassifyDTO>(); Core.Data.QueryResult <CCommodityCategoryPO> queryCommodityCategory = this.GetCommodityCategorys(restaurant.ResUUID, null, 1, 1); if (queryCommodityCategory.TotalCount != 0) { if (queryCommodityCategory.TotalCount > 1) { queryCommodityCategory = this.GetCommodityCategorys(restaurant.ResUUID, null, 1, (int)queryCommodityCategory.TotalCount); } foreach (CCommodityCategoryPO item in queryCommodityCategory.Items) { GoodsClassifyDTO ydto1 = new GoodsClassifyDTO { ChineseName = item.ChineseName, EnglishName = item.EnglishName, Id = item.Id, PicPath = item.PicPath }; GoodsClassifyDTO goodsClassifyDTO = ydto1; list.Add(goodsClassifyDTO); } } return(list); }
public List <CommodityCategoryInfoDTO> GetCommodityCategory(int resId) { Core.Data.QueryResult <CCommodityPropertyPO> resultCCommodityProperty; Core.Data.QueryResult <CPropertyCategoryPO> resultPropertyCategory; if (resId <= 0) { throw new BusinessException("餐厅ID不正确"); } CRestaurantPO restaurant = CRestaurantManager.Instance.GetById(resId); if (restaurant == null) { throw new BusinessException("餐厅不存在"); } List <CommodityCategoryInfoDTO> listCommodityCategoryInfo = new List <CommodityCategoryInfoDTO>(); Core.Data.QueryResult <CCommodityCategoryPO> queryCommodityCategory = this.GetCommodityCategorys(restaurant.ResUUID, null, 1, 1); if (queryCommodityCategory.TotalCount != 0) { queryCommodityCategory = this.GetCommodityCategorys(restaurant.ResUUID, null, 1, (int)queryCommodityCategory.TotalCount); List <string> listCommodityCategory = new List <string>(); if ((queryCommodityCategory.Items != null) && (queryCommodityCategory.Items.Length > 0)) { listCommodityCategory = queryCommodityCategory.Items.Select(x => x.CommodityCategoryUUID).Distinct <string>().ToList <string>(); } int? id = null; List <int> states = new List <int> { 1 }; Core.Data.QueryResult <CCommodityPO> resultCommodity = CCommodityManager.Instance.GetCCommoditys(id, restaurant.ResUUID, null, listCommodityCategory, states, 1, 1, null); if (((resultCommodity == null) || (resultCommodity.Items == null)) || (resultCommodity.Items.Length == 0)) { return(listCommodityCategoryInfo); } if (resultCommodity.TotalCount > 1) { List <int> list2 = new List <int> { 1 }; resultCommodity = CCommodityManager.Instance.GetCCommoditys(null, restaurant.ResUUID, null, listCommodityCategory, list2, 1, (int)resultCommodity.TotalCount, null); } List <string> commodityUUIDs = new List <string>(); if ((resultCommodity.Items != null) && (resultCommodity.Items.Length > 0)) { commodityUUIDs = resultCommodity.Items.Select(x => x.CommodityUUID).Distinct <string>().ToList <string>(); } resultCCommodityProperty = CCommodityPropertyManager.Instance.GetCommodityPropertys(null, restaurant.ResUUID, null, commodityUUIDs, null, 1, 1); if (((resultCCommodityProperty != null) && (resultCCommodityProperty.Items != null)) && (resultCCommodityProperty.TotalCount > 1)) { resultCCommodityProperty = CCommodityPropertyManager.Instance.GetCommodityPropertys(null, restaurant.ResUUID, null, commodityUUIDs, null, 1, (int)resultCCommodityProperty.TotalCount); } List <string> listPropertyCategory = new List <string>(); if (((resultCCommodityProperty != null) && (resultCCommodityProperty.Items != null)) && (resultCCommodityProperty.Items.Length > 0)) { listPropertyCategory = resultCCommodityProperty.Items.Select(x => x.PropertyCategoryUUID).Distinct <string>().ToList <string>(); } resultPropertyCategory = new Core.Data.QueryResult <CPropertyCategoryPO>(); if ((listPropertyCategory != null) && (listPropertyCategory.Count > 0)) { resultPropertyCategory = CPropertyCategoryManager.Instance.GetPropertyCategorys(restaurant.ResUUID, listPropertyCategory, 1, 1); } if (((resultPropertyCategory != null) && (resultPropertyCategory.Items != null)) && (resultPropertyCategory.TotalCount > 1)) { resultPropertyCategory = CPropertyCategoryManager.Instance.GetPropertyCategorys(restaurant.ResUUID, listPropertyCategory, 1, (int)resultPropertyCategory.TotalCount); } CCommodityCategoryPO[] items = queryCommodityCategory.Items; for (int i = 0; i < items.Length; i++) { CCommodityCategoryPO itemCommodityCategory = items[i]; List <CommodityInfoDTO> listCommodityInfoD; if (itemCommodityCategory != null) { CommodityCategoryInfoDTO odto1 = new CommodityCategoryInfoDTO { Id = itemCommodityCategory.Id, ChineseName = itemCommodityCategory.ChineseName, EnglishName = itemCommodityCategory.EnglishName, PicPath = itemCommodityCategory.PicPath }; CommodityCategoryInfoDTO commodityCategoryInfo = odto1; listCommodityCategoryInfo.Add(commodityCategoryInfo); List <CCommodityPO> listCCommodity = resultCommodity.Items.Where(x => x.CommodityCategoryUUID == itemCommodityCategory.CommodityCategoryUUID).ToList(); if (listCCommodity != null) { listCommodityInfoD = new List <CommodityInfoDTO>(); commodityCategoryInfo.GoodsList = listCommodityInfoD; listCCommodity.ForEach(delegate(CCommodityPO itemCommodity) { if (itemCommodity != null) { CommodityInfoDTO odto2 = new CommodityInfoDTO { ChineseName = itemCommodity.ChineseName, EnglishName = itemCommodity.EnglishName, Id = itemCommodity.Id, Price = itemCommodity.Price.HasValue ? itemCommodity.Price.Value : decimal.Zero, ShowRemark = itemCommodity.ShowRemark, Type = itemCommodity.Type, PicPath = itemCommodity.PicPath }; CommodityInfoDTO commodityInfoDTO = odto2; listCommodityInfoD.Add(commodityInfoDTO); List <CCommodityPropertyPO> listCommodityProperty = (from x in resultCCommodityProperty.Items where x.CommodityUUID == itemCommodity.CommodityUUID select x).ToList <CCommodityPropertyPO>(); if ((listCommodityProperty != null) && (listCommodityProperty.Count != 0)) { List <string> listPropertyCategoryUUID = listCommodityProperty.Select(x => x.PropertyCategoryUUID).Distinct <string>().ToList <string>(); List <PropertyCategoryInfoDTO> listPropertyCategoryInfo = new List <PropertyCategoryInfoDTO>(); commodityInfoDTO.SkuInfo = listPropertyCategoryInfo; listPropertyCategoryUUID.ForEach(delegate(string itemPropertyCategoryUUID) { if (!string.IsNullOrWhiteSpace(itemPropertyCategoryUUID)) { CPropertyCategoryPO propertyCategoryPO = resultPropertyCategory.Items.FirstOrDefault <CPropertyCategoryPO>(x => x.PropertyCategoryUUID == itemPropertyCategoryUUID); if (propertyCategoryPO != null) { PropertyCategoryInfoDTO odto3 = new PropertyCategoryInfoDTO { ChineseName = propertyCategoryPO.ChineseName, EnableMultiple = propertyCategoryPO.EnableMultiple, EnglishName = propertyCategoryPO.EnglishName, Id = propertyCategoryPO.Id, Type = propertyCategoryPO.Type }; PropertyCategoryInfoDTO propertyCategoryInfoDTO = odto3; listPropertyCategoryInfo.Add(propertyCategoryInfoDTO); List <CCommodityPropertyPO> listCommodityPropertyOther = (from x in listCommodityProperty where x.PropertyCategoryUUID == itemPropertyCategoryUUID select x).ToList <CCommodityPropertyPO>(); if (listCommodityPropertyOther != null) { List <CCommodityPropertyInfoDTO> commodityPropertyInfos = new List <CCommodityPropertyInfoDTO>(); propertyCategoryInfoDTO.List = commodityPropertyInfos; listCommodityPropertyOther.ForEach(delegate(CCommodityPropertyPO x) { if (x != null) { CCommodityPropertyInfoDTO odto4 = new CCommodityPropertyInfoDTO { AddPrice = x.AddPrice.HasValue ? x.AddPrice.Value : decimal.Zero, ChineseName = x.ChineseName, EnglishName = x.EnglishName, Id = x.Id }; CCommodityPropertyInfoDTO commodityPropertyInfo = odto4; commodityPropertyInfos.Add(commodityPropertyInfo); } }); } } } }); } } }); } } } } return(listCommodityCategoryInfo); }
/// <summary> /// 获取有效的时间段 /// </summary> /// <param name="resId"></param> public List <EffectivePeriodDTO> GetEffectivePeriod(int resId) { CRestaurantPO restaurant = CRestaurantManager.Instance.GetById(resId); if (restaurant == null) { throw ErrorCodeHelper.CRestaurantNotExist.ToException(); } List <EffectivePeriodDTO> listEffectivePeriodDTO = new List <EffectivePeriodDTO>(); List <BusinessHourWeekPO> listBusinessHourWeek = GetBusinessHourWeekList(null, null, new List <string> { restaurant.ResUUID }, null, new List <int> { 0 }); if (listBusinessHourWeek == null) { return(listEffectivePeriodDTO); } List <COrderPO> listOrder = new List <COrderPO>(); Core.Data.QueryResult <COrderPO> result = COrderManager.Instance.GetOrders(null, null, restaurant.ResUUID, null, null, null, null, null, new List <int> { 1, 2 }, null, null, null, null, null, null, 1, 1000); if (result.Items != null) { listOrder.AddRange(result.Items); } DateTime now = DateTime.Now; listOrder = listOrder.Where(x => x.DeliveryMaxTime.HasValue && x.DeliveryMaxTime.Value > now && x.DeliveryMinTime.HasValue).ToList(); List <PeriodOrder> listPeriodOrder = new List <PeriodOrder>(); for (int i = 0; i < AppSettingHelper.EffectivePeriodDay; i++) { int weekFlag = now.Date.AddDays(i).DayOfWeek == DayOfWeek.Sunday ? 7 : (int)now.Date.AddDays(i).DayOfWeek; List <BusinessHourWeekPO> listBusinessHourWeekOrderByWeekFlag = listBusinessHourWeek.Where(x => x.WeekDay == weekFlag).ToList(); if (listBusinessHourWeekOrderByWeekFlag == null || listBusinessHourWeekOrderByWeekFlag.Count == 0) { continue; } listBusinessHourWeekOrderByWeekFlag = listBusinessHourWeekOrderByWeekFlag.OrderBy(x => x.StartTime).ToList(); listBusinessHourWeekOrderByWeekFlag.ForEach(item => { PeriodOrder periodOrder = new PeriodOrder() { BusinessHourWeekId = item.Id, StartTime = now.Date.AddDays(i).AddMilliseconds(item.StartTime), EndTime = now.Date.AddDays(i).AddMilliseconds(item.EndTime), }; listPeriodOrder.Add(periodOrder); }); } //判断订单属于哪个时间段 listOrder.ForEach(x => { PeriodOrder maxItem = null; double maxperod = 0; listPeriodOrder.ForEach(item => { double perid = GetPeriodLong(x.DeliveryMinTime.Value, x.DeliveryMaxTime.Value, item.StartTime, item.EndTime); if (perid > maxperod) { maxperod = perid; maxItem = item; } }); if (maxItem != null) { maxItem.ListOrder.Add(x); } }); string[] Day = new string[] { "周日", "周一", "周二", "周三", "周四", "周五", "周六" }; for (int i = 0; i < AppSettingHelper.EffectivePeriodDay; i++) { string showName = "{0}"; switch (i) { case 0: showName = "今天({0})"; break; case 1: showName = "明天({0})"; break; case 2: showName = "后天({0})"; break; default: showName = "{0}"; break; } EffectivePeriodDTO effectivePeriod = new EffectivePeriodDTO() { Date = now.Date.AddDays(i), ShowName = string.Format(showName, Day[(int)now.Date.AddDays(i).DayOfWeek]), WeekFlag = now.Date.AddDays(i).DayOfWeek == DayOfWeek.Sunday ? 7 : (int)now.Date.AddDays(i).DayOfWeek }; List <BusinessHourWeekPO> listBusinessHourWeekOrderByWeekFlag = listBusinessHourWeek.Where(x => x.WeekDay == effectivePeriod.WeekFlag).ToList(); if (listBusinessHourWeekOrderByWeekFlag == null || listBusinessHourWeekOrderByWeekFlag.Count == 0) { continue; } listBusinessHourWeekOrderByWeekFlag = listBusinessHourWeekOrderByWeekFlag.OrderBy(x => x.StartTime).ToList(); listBusinessHourWeekOrderByWeekFlag.ForEach(item => { if (!item.AllowOrderNumber.HasValue || item.AllowOrderNumber.Value <= 0) { return; } if (item.LatestOrderTime.HasValue && effectivePeriod.Date.AddMilliseconds(item.LatestOrderTime.Value) < now) { return; } if (item.InAdvance.HasValue && effectivePeriod.Date.AddMilliseconds(item.StartTime).AddHours(-(double)item.InAdvance.Value) < now) { return; } //if (effectivePeriod.Date.AddMilliseconds(item.StartTime) < now) // return; //List<COrderPO> listOrderInfo = listOrder.Where(order => (order.DeliveryMaxTime.Value < effectivePeriod.Date.AddMilliseconds(item.StartTime) || //order.DeliveryMinTime.Value > effectivePeriod.Date.AddMilliseconds(item.EndTime)) == false).OrderBy(order=>order.DeliveryMinTime.Value).ToList(); //listOrderInfo = listOrderInfo.Take((int)item.AllowOrderNumber.Value).ToList(); //listOrderInfo.ForEach(item1 => //{ // listOrder.Remove(item1); //}); //if (listOrderInfo.Count == (int)item.AllowOrderNumber.Value) // return; PeriodOrder periodOrder = listPeriodOrder.FirstOrDefault(x => x.BusinessHourWeekId == item.Id && x.StartTime.Date == effectivePeriod.Date); if (periodOrder == null) { return; } if (periodOrder.ListOrder.Count > 0) { string dd = string.Empty; } EffectivePeriodInfo effectivePeriodInfo = new EffectivePeriodInfo() { EndTime = item.EndTime, StartTime = item.StartTime, Available = true }; if (periodOrder.ListOrder.Count >= (int)item.AllowOrderNumber.Value) { effectivePeriodInfo.Available = false; } effectivePeriod.EffectivePeriod.Add(effectivePeriodInfo); }); if (effectivePeriod.EffectivePeriod.Count > 0) { listEffectivePeriodDTO.Add(effectivePeriod); } } return(listEffectivePeriodDTO); }
public int AddOrUpdateCommodityProperty(AddOrUpdateCommodityPropertyDTO commodityProperty, string operatorName) { if (commodityProperty == null) { throw new BusinessException("商品对象未设定"); } if (string.IsNullOrWhiteSpace(operatorName)) { throw new BusinessException("操作人未设定"); } if (string.IsNullOrWhiteSpace(commodityProperty.PropertyCategoryUUID)) { throw new BusinessException("请设定属性类别"); } if (string.IsNullOrWhiteSpace(commodityProperty.CommodityUUID)) { throw new BusinessException("请设定商品"); } CRestaurantPO restaurant = CRestaurantManager.Instance.GetById(commodityProperty.ResId); if (restaurant == null) { throw new BusinessException("此餐厅不存在"); } Core.Data.QueryResult <CCommodityPO> commodityResult = CCommodityManager.Instance.GetCCommoditys(null, null, commodityProperty.CommodityUUID, null, null, 1, 1, null); if (commodityResult == null || commodityResult.Items == null || commodityResult.Items.Length == 0) { throw new BusinessException("此商品不存在"); } Core.Data.QueryResult <CPropertyCategoryPO> propertyCategoryResult = CPropertyCategoryManager.Instance.GetPropertyCategorys(null, new List <string> { commodityProperty.PropertyCategoryUUID }, 1, 1); if (propertyCategoryResult == null || propertyCategoryResult.Items == null || propertyCategoryResult.Items.Length == 0) { throw new BusinessException("此属性类别不存在"); } CCommodityPropertyPO commodityPropertyPO = null; if (commodityProperty.Id > 0) { commodityPropertyPO = CCommodityPropertyManager.Instance.GetById(commodityProperty.Id); if (commodityPropertyPO == null) { throw new BusinessException("商品不存在"); } } else { commodityPropertyPO = new CCommodityPropertyPO(); } commodityPropertyPO.AddPrice = commodityProperty.AddPrice; commodityPropertyPO.ChineseName = commodityProperty.ChineseName; commodityPropertyPO.CommodityUUID = commodityProperty.CommodityUUID; commodityPropertyPO.EnglishName = commodityProperty.EnglishName; commodityPropertyPO.IsDelete = commodityProperty.IsDelete; commodityPropertyPO.PropertyCategoryUUID = commodityProperty.PropertyCategoryUUID; commodityPropertyPO.ResUUID = restaurant.ResUUID; commodityPropertyPO.Sort = commodityProperty.Sort; if (commodityPropertyPO.Id > 0) { return(Update(commodityPropertyPO, operatorName)); } else { return(Add(commodityPropertyPO, operatorName)); } }
public int AddOrUpdateCommodity(AddOrUpdateCommodityDTO commodity, string operatorName) { if (commodity == null) { throw new BusinessException("商品对象未设定"); } if (string.IsNullOrWhiteSpace(operatorName)) { throw new BusinessException("操作人未设定"); } CRestaurantPO restaurant = CRestaurantManager.Instance.GetById(commodity.ResId); if (restaurant == null) { throw new BusinessException("此餐厅不存在"); } List <string> commodityCategoryUUIDs = new List <string> { commodity.CommodityCategoryUUID }; Core.Data.QueryResult <CCommodityCategoryPO> commodityCategoryResult = CCommodityCategoryManager.Instance.GetCommodityCategorys(restaurant.ResUUID, commodityCategoryUUIDs, 1, 1); if (((commodityCategoryResult == null) || (commodityCategoryResult.Items == null)) || (commodityCategoryResult.Items.Length == 0)) { throw new BusinessException("商品类别不存在"); } CCommodityCategoryPO commodityCategoryPO = commodityCategoryResult.Items[0]; CCommodityPO commodityPO = null; if (commodity.Id > 0) { commodityPO = Instance.GetById(commodity.Id); if (commodityPO == null) { throw new BusinessException("商品不存在"); } } else { commodityPO = new CCommodityPO(); } commodityPO.ChineseName = commodity.ChineseName; commodityPO.ResUUID = restaurant.ResUUID; commodityPO.CommodityCategoryUUID = commodityCategoryPO.CommodityCategoryUUID; commodityPO.EnglishName = commodity.EnglishName; commodityPO.IsDelete = commodity.IsDelete; commodityPO.PicPath = commodity.PicPath; commodityPO.PreferentialFlag = commodity.PreferentialFlag; commodityPO.PreferentialProportion = commodity.PreferentialProportion; commodityPO.PreferentialQuantity = commodity.PreferentialQuantity; commodityPO.Price = new decimal?(commodity.Price); commodityPO.Remark = commodity.Remark; commodityPO.ShowRemark = commodity.ShowRemark; commodityPO.Sort = new int?(commodity.Sort); commodityPO.State = commodity.State; commodityPO.Type = commodity.Type; if (commodityPO.Id > 0) { return(this.Update(commodityPO, operatorName)); } return(this.Add(commodityPO, operatorName)); }
public int AddOrUpdateCoupon(AddOrUpdateCouponDTO coupon, string operatorName) { if (coupon == null) { throw new BusinessException("优惠卷未设定"); } if (string.IsNullOrWhiteSpace(operatorName)) { throw new BusinessException("操作人未设定"); } CRestaurantPO restaurant = CRestaurantManager.Instance.GetById(coupon.ResId); if (restaurant == null) { throw new BusinessException("此餐厅不存在"); } CCouponPO couponPO = null; if (coupon.Id > 0) { couponPO = Instance.GetById(coupon.Id); if (couponPO == null) { throw new BusinessException("优惠卷不存在"); } } else { CCouponPO npo1 = new CCouponPO { CouponName = coupon.CouponName, ResUUID = restaurant.ResUUID, CouponType = coupon.CouponType, EffectiveEndTime = coupon.EffectiveEndTime, EffectiveStartTime = coupon.EffectiveStartTime, IsDelete = coupon.IsDelete, OfferAmount = coupon.OfferAmount, Preferential = coupon.Preferential, PreferentialType = coupon.PreferentialType, Remark = coupon.Remark, State = coupon.State }; couponPO = npo1; } couponPO.CouponName = coupon.CouponName; couponPO.ResUUID = restaurant.ResUUID; couponPO.CouponType = coupon.CouponType; couponPO.EffectiveEndTime = coupon.EffectiveEndTime; couponPO.EffectiveStartTime = coupon.EffectiveStartTime; couponPO.IsDelete = coupon.IsDelete; couponPO.OfferAmount = coupon.OfferAmount; couponPO.Preferential = coupon.Preferential; couponPO.PreferentialType = coupon.PreferentialType; couponPO.Remark = coupon.Remark; couponPO.State = coupon.State; if (couponPO.Id > 0) { return(this.Update(couponPO, operatorName)); } return(this.Add(couponPO, operatorName)); }
public List <CCouponDTO> GetAvailableCouponDTO(GetAvailableCouponDTO getAvailableCoupon, int memberId) { if (((getAvailableCoupon == null) || (getAvailableCoupon.Commodity == null)) || (getAvailableCoupon.Commodity.Count == 0)) { throw new BusinessException("商品信息为空"); } if (CMemberWeiXinManager.Instance.GetById(memberId) == null) { throw new BusinessException("此微信用户不存在"); } if (getAvailableCoupon.ResId <= 0) { throw new BusinessException("餐厅ID不正确"); } CRestaurantPO restaurant = CRestaurantManager.Instance.GetById(getAvailableCoupon.ResId); if (restaurant == null) { throw new BusinessException("此餐厅不存在"); } if (restaurant.IsDelete) { throw new BusinessException("此餐厅已被删除"); } decimal orderMomey = new decimal(); //decimal preferentialMomey = new decimal(); List <string> remark = new List <string>(); List <Commodity> listCommodity = new List <Model.Commodity>(); getAvailableCoupon.Commodity.ForEach(delegate(Commodity item) { Commodity commodity = listCommodity.FirstOrDefault(x => x.CommodityId == item.CommodityId); if (commodity == null) { commodity = new Commodity { CommodityId = item.CommodityId, Quantity = item.Quantity }; listCommodity.Add(commodity); } else { commodity.Quantity = commodity.Quantity + item.Quantity; } //bool preferentialFlag = false; if (item != null) { decimal commityMomey = new decimal(); List <int> states = new List <int> { 1 }; Core.Data.QueryResult <CCommodityPO> commodityQuery = CCommodityManager.Instance.GetCCommoditys(new int?(item.CommodityId), restaurant.ResUUID, null, null, states, 1, 1, null); if ((commodityQuery.Items == null) || (commodityQuery.Items.Length == 0)) { throw new BusinessException("商品信息错误,请重新选择"); } commityMomey += commodityQuery.Items[0].Price.HasValue ? commodityQuery.Items[0].Price.Value : decimal.Zero; //if (commodityQuery.Items[0].PreferentialFlag && (item.Quantity >= (commodityQuery.Items[0].PreferentialQuantity.HasValue ? commodityQuery.Items[0].PreferentialQuantity.Value : 1))) //{ // preferentialFlag = true; //} if ((item.SkuList == null) || (item.SkuList.Count == 0)) { //if (preferentialFlag) //{ // preferentialMomey += this.GetPreferentialMomey(item.Quantity, commodityQuery.Items[0].PreferentialQuantity, commodityQuery.Items[0].PreferentialProportion, commityMomey); // remark.Add(string.Format("商品({0})满{1}享{2}优惠", commodityQuery.Items[0].ChineseName, commodityQuery.Items[0].PreferentialQuantity.HasValue ? commodityQuery.Items[0].PreferentialQuantity.Value : 1, commodityQuery.Items[0].PreferentialProportion.HasValue ? (commodityQuery.Items[0].PreferentialProportion.Value.ToString("#0.00") + "%") : "0%")); //} //orderMomey += commityMomey * item.Quantity; } else { Core.Data.QueryResult <CCommodityPropertyPO> commodityPropertyResult = CCommodityPropertyManager.Instance.GetCommodityPropertys(item.SkuList, restaurant.ResUUID, null, null, null, 1, item.SkuList.Count); if (((commodityPropertyResult.Items == null) || (commodityPropertyResult.Items.Length == 0)) || (commodityPropertyResult.Items.Length != item.SkuList.Count)) { throw new BusinessException("商品信息错误,请重新选择"); } foreach (CCommodityPropertyPO propertyItem in commodityPropertyResult.Items) { if (propertyItem != null) { commityMomey += propertyItem.AddPrice.HasValue ? propertyItem.AddPrice.Value : decimal.Zero; } } //if (preferentialFlag) //{ // preferentialMomey += this.GetPreferentialMomey(item.Quantity, commodityQuery.Items[0].PreferentialQuantity, commodityQuery.Items[0].PreferentialProportion, commityMomey); // remark.Add(string.Format("商品({0})满{1}享{2}折", commodityQuery.Items[0].ChineseName, commodityQuery.Items[0].PreferentialQuantity.HasValue ? commodityQuery.Items[0].PreferentialQuantity.Value : 1, commodityQuery.Items[0].PreferentialProportion.HasValue ? commodityQuery.Items[0].PreferentialProportion.Value : 10M)); //} //orderMomey += commityMomey * item.Quantity; } //if (preferentialFlag) //{ // preferentialMomey += this.GetPreferentialMomey(item.Quantity, commodityQuery.Items[0].PreferentialQuantity, commodityQuery.Items[0].PreferentialProportion, commityMomey); // remark.Add(string.Format("商品({0})满{1}享{2}优惠", commodityQuery.Items[0].ChineseName, commodityQuery.Items[0].PreferentialQuantity.HasValue ? commodityQuery.Items[0].PreferentialQuantity.Value : 1, commodityQuery.Items[0].PreferentialProportion.HasValue ? (commodityQuery.Items[0].PreferentialProportion.Value.ToString("#0.00") + "%") : "0%")); //} orderMomey += commityMomey * item.Quantity; } }); decimal preferentialMomey = new decimal(); listCommodity.ForEach(item => { bool preferentialFlag = false; if (item != null) { decimal commityMomey = new decimal(); List <int> states = new List <int> { 1 }; Core.Data.QueryResult <CCommodityPO> commodityQuery = CCommodityManager.Instance.GetCCommoditys(new int?(item.CommodityId), restaurant.ResUUID, null, null, states, 1, 1, null); if ((commodityQuery.Items == null) || (commodityQuery.Items.Length == 0)) { throw new BusinessException("商品信息错误,请重新选择"); } commityMomey += commodityQuery.Items[0].Price.HasValue ? commodityQuery.Items[0].Price.Value : decimal.Zero; if (commodityQuery.Items[0].PreferentialFlag && (item.Quantity >= (commodityQuery.Items[0].PreferentialQuantity.HasValue ? commodityQuery.Items[0].PreferentialQuantity.Value : 1))) { preferentialFlag = true; } if (preferentialFlag) { preferentialMomey += this.GetPreferentialMomey(item.Quantity, commodityQuery.Items[0].PreferentialQuantity, commodityQuery.Items[0].PreferentialProportion, commityMomey); remark.Add(string.Format("商品({0})满{1}享{2}优惠", commodityQuery.Items[0].ChineseName, commodityQuery.Items[0].PreferentialQuantity.HasValue ? commodityQuery.Items[0].PreferentialQuantity.Value : 1, commodityQuery.Items[0].PreferentialProportion.HasValue ? ((100 - commodityQuery.Items[0].PreferentialProportion.Value).ToString("#0.00") + "%") : "0%")); } } }); List <CCouponDTO> listCoupon = this.GetNoUseCouponDTOById(restaurant.Id, memberId); if (listCoupon == null) { listCoupon = new List <CCouponDTO>(); } //2017.03.13 修改 开始 listCoupon = (from x in listCoupon where (x.CouponType != 3) || (x.OfferAmount <= orderMomey) select x).ToList <CCouponDTO>(); //listCoupon = (from x in listCoupon // where (x.CouponType != 3) || (x.Preferential <= orderMomey) // select x).ToList<CCouponDTO>(); //2017.03.13 修改 结束 #region 配送时间也要满足有效时间 if (getAvailableCoupon.DeliveryMinTime.HasValue) { listCoupon = listCoupon.Where(couponItem => !couponItem.EffectiveStartTime.HasValue || couponItem.EffectiveStartTime <= getAvailableCoupon.DeliveryMinTime).ToList(); } if (getAvailableCoupon.DeliveryMaxTime.HasValue) { listCoupon = listCoupon.Where(couponItem => !couponItem.EffectiveEndTime.HasValue || couponItem.EffectiveEndTime >= getAvailableCoupon.DeliveryMaxTime).ToList(); } #endregion if (preferentialMomey > decimal.Zero) { CCouponDTO ndto1 = new CCouponDTO { Id = -1, CouponType = 4 }; TimeSpan span = (TimeSpan)(DateTime.Now - DateTime.Parse("2016-1-1")); ndto1.CouponUUID = "GoodsOffer" + span.Minutes + HelperTool.GenerateRandomNumber(10); ndto1.EffectiveEndTime = new DateTime?(DateTime.Now.AddDays(-100.0)); ndto1.CreateName = "自动"; ndto1.CreateTime = DateTime.Now; ndto1.EffectiveStartTime = new DateTime?(DateTime.Now.AddDays(100.0)); ndto1.IsDelete = false; ndto1.OfferAmount = decimal.Zero; ndto1.Preferential = new decimal?(decimal.Parse(preferentialMomey.ToString("#0.00"))); ndto1.PreferentialType = 1; ndto1.Remark = string.Join(";", remark); ndto1.ResUUID = restaurant.ResUUID; ndto1.State = 1; ndto1.UpdateName = "自动"; ndto1.UpdateTime = DateTime.Now; ndto1.CouponName = "商品满数量有折扣"; listCoupon.Add(ndto1); } #region 积分抵用券 CMemberWeiXinPO memberWeiXinPO = CMemberWeiXinManager.Instance.GetById(memberId); if (memberWeiXinPO == null || !memberWeiXinPO.Integral.HasValue || memberWeiXinPO.Integral.Value <= 0) { return(listCoupon); } List <CCashCouponPO> listCashCoupon = CCashCouponManager.Instance.GetCCashCouponList(null, null, null, DateTime.Now, DateTime.Now, new List <int> { 1 }, memberWeiXinPO.Integral, DateTime.Now, DateTime.Now); if (listCashCoupon == null || listCashCoupon.Count == 0) { return(listCoupon); } listCashCoupon.ForEach(item => { if (item.ValAmount > orderMomey) { return; } CCashCouponDetailPO cashCouponDetail = new CCashCouponDetailPO() { AssetName = item.AssetName, AssetProperty = item.AssetProperty, AssetStatus = 1, CreateName = memberWeiXinPO.Id.ToString(), CreateTime = DateTime.Now, Description = item.Description, IsDelete = false, MemberWeiXinId = memberWeiXinPO.Id, SaleAmount = item.SaleAmount, SaleEndTime = item.SaleEndTime, SaleStartTime = item.SaleStartTime, UpdateName = item.UpdateName, UpdateTime = DateTime.Now, UseState = 0, ValAmount = item.ValAmount, ValidEndTime = item.ValidEndTime, ValidStartTime = item.ValidStartTime, }; int detailId = CCashCouponDetailManager.Instance.Add(cashCouponDetail, "系统"); if (detailId <= 0) { return; } CCouponDTO ndto1 = new CCouponDTO { Id = -100 - detailId, CouponType = 4 }; TimeSpan span = (TimeSpan)(DateTime.Now - DateTime.Parse("2016-1-1")); ndto1.CouponUUID = "CouponDetail-" + detailId.ToString() + "-" + span.Minutes; ndto1.EffectiveEndTime = cashCouponDetail.ValidStartTime; ndto1.CreateName = "自动"; ndto1.CreateTime = DateTime.Now; ndto1.EffectiveStartTime = cashCouponDetail.ValidEndTime; ndto1.IsDelete = false; ndto1.OfferAmount = decimal.Zero; ndto1.Preferential = cashCouponDetail.ValAmount; ndto1.PreferentialType = 1; ndto1.Remark = cashCouponDetail.Description; ndto1.ResUUID = restaurant.ResUUID; ndto1.State = 1; ndto1.UpdateName = "自动"; ndto1.UpdateTime = DateTime.Now; ndto1.CouponName = cashCouponDetail.AssetName; listCoupon.Add(ndto1); }); #endregion return(listCoupon); }