public int CreateVerificationCode(int memberId, string phoneNumber) { if (memberId <= 0) { throw new BusinessException("用户ID不正确"); } if (string.IsNullOrWhiteSpace(phoneNumber)) { throw new BusinessException("电话号码为空"); } if (!phoneNumber.IsMobilePhone()) { throw new BusinessException("电话号码格式不正确"); } CMemberWeiXinPO memberWeiXinPO = CMemberWeiXinManager.Instance.GetById(memberId); if (memberWeiXinPO == null) { throw new BusinessException("此微信用户不存在"); } CVerificationCodePO epo1 = new CVerificationCodePO { Code = HelperTool.GenerateRandomNumberNew(6), EffectiveEndTime = new DateTime?(DateTime.Now.AddMinutes(10.0)), MemberUUID = memberWeiXinPO.MemberUUID, PhoneNumber = phoneNumber, VerificationState = 0, WeiXinOpenId = memberWeiXinPO.WeiXinOpenId }; CVerificationCodePO po = epo1; List <int> verificationState = new List <int> { 0 }; Core.Data.QueryResult <CVerificationCodePO> verificationCodeQuery = this.GetVerificationCodes(memberWeiXinPO.MemberUUID, null, null, null, verificationState, new DateTime?(DateTime.Now), null, 1, 1000); if ((verificationCodeQuery.Items != null) && (verificationCodeQuery.Items.Length > 0)) { while (true) { if (verificationCodeQuery.Items.Count <CVerificationCodePO>(x => x.Code == po.Code) == 0) { break; } po.Code = HelperTool.GenerateRandomNumberNew(6); } } int id = CVerificationCodePOManager.Instance.Add(po); HttpHelper.SendSms(phoneNumber, string.Format("您好!你的验证码为{0},请在十分钟内完成验证。", po.Code)); return(id); }
/// <summary> /// 判断餐厅时候在指定坐标内 /// </summary> /// <param name="listResCoordinate"></param> /// <param name="rest"></param> /// <returns></returns> public bool Contains(List <CResCoordinatePO> listResCoordinate, decimal?longitude, decimal?latitude) { if (listResCoordinate == null || listResCoordinate.Count < 3) { return(false); } //decimal? value = rest.Latitude; //rest.Latitude = rest.Longitude; //rest.Longitude = value; //int i; //int j; //bool result = false; //for (i = 0, j = listResCoordinate.Count - 1; i < listResCoordinate.Count; j = i++) //{ // if ((listResCoordinate[i].Latitude > rest.Latitude) != (listResCoordinate[j].Latitude > rest.Latitude) && // (rest.Longitude < (listResCoordinate[j].Longitude - listResCoordinate[i].Longitude) * (rest.Latitude - listResCoordinate[i].Latitude) / (listResCoordinate[j].Latitude - listResCoordinate[i].Latitude) + listResCoordinate[i].Longitude)) // { // result = !result; // } //} //return result; if (!longitude.HasValue || !latitude.HasValue) { return(false); } PointF checkPoint = new PointF() { X = (float)longitude.Value, Y = (float)latitude.Value }; List <PointF> polygonPoints = new List <PointF>(); listResCoordinate.ForEach(item => { polygonPoints.Add(new PointF() { X = (float)item.Longitude, Y = (float)item.Latitude }); }); //List< PointF > polygonPoints return(HelperTool.IsInPolygon(checkPoint, polygonPoints)); }
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); }