public bool CheckCode(int memberId, string code) { if (memberId <= 0) { throw new BusinessException("用户ID不正确"); } if (string.IsNullOrWhiteSpace(code)) { throw new BusinessException("请输入验证码"); } CMemberWeiXinPO memberWeiXinPO = CMemberWeiXinManager.Instance.GetById(memberId); if (memberWeiXinPO == null) { throw new BusinessException("此微信用户不存在"); } List <int> verificationState = new List <int> { 0 }; Core.Data.QueryResult <CVerificationCodePO> verificationCodeQuery = this.GetVerificationCodes(memberWeiXinPO.MemberUUID, null, null, code, verificationState, new DateTime?(DateTime.Now), null, 1, 0x3e8); if ((verificationCodeQuery.Items == null) || (verificationCodeQuery.Items.Length == 0)) { throw new BusinessException("无效验证码"); } foreach (CVerificationCodePO item in verificationCodeQuery.Items) { item.VerificationState = 1; CVerificationCodePOManager.Instance.Update(item); } memberWeiXinPO.PhoneNumber = verificationCodeQuery.Items[0].PhoneNumber; CMemberWeiXinManager.Instance.Update(memberWeiXinPO, "验证验证码"); return(true); }
public CMemberAddressDTO GetLastMemberAddress(int weixinMemberId) { if (weixinMemberId == 0) { throw new ArgumentNullException("用户ID不能为空"); } CMemberWeiXinPO memberWeiXinPO = CMemberWeiXinManager.Instance.GetById(weixinMemberId); if (memberWeiXinPO == null) { throw new ArgumentNullException("微信用户不存在"); } int?id = null; Core.Data.QueryResult <COrderPO> QueryOrderPO = COrderManager.Instance.GetOrders(id, null, null, memberWeiXinPO.MemberUUID, null, null, null, null, null, null, null, null, null, null, null, 1, 1); if (((QueryOrderPO == null) || (QueryOrderPO.Items == null)) || (QueryOrderPO.Items.Length == 0)) { return(null); } Core.Data.QueryResult <CMemberAddressPO> addressResult = this.GetMemberAddress(null, QueryOrderPO.Items[0].MemberAddressUUID, null, null, null, null, null, null, 1, 1); if (((addressResult == null) || (addressResult.Items == null)) || (addressResult.Items.Length == 0)) { return(null); } return(base.PoToDto(addressResult.Items[0])); }
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); }
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 bool DeleteMemberAddress(int memberAddressId, int memberWeiXinId) { CMemberAddressPO memberAddressPO = GetById(memberAddressId); if (memberAddressPO == null) { throw new BusinessException("会员地址不存在"); } CMemberWeiXinPO memberWeiXinPO = CMemberWeiXinManager.Instance.GetById(memberWeiXinId); if (memberWeiXinPO == null) { throw new BusinessException("微信会员不存在"); } if (memberWeiXinPO.MemberUUID != memberAddressPO.MemberUUID) { throw new BusinessException("会员和订单不一致"); } memberAddressPO.IsDelete = true; CMemberAddressManager.Instance.Update(memberAddressPO, memberWeiXinPO.Id.ToString()); return(true); }
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); }