private static IOrderNOSQLStrategy _ordernosql = BMAData.OrderNOSQL;//订单非关系型数据库 #region 辅助方法 /// <summary> /// 从IDataReader创建OrderProductInfo /// </summary> public static OrderProductInfo BuildOrderProductFromReader(IDataReader reader) { OrderProductInfo orderProductInfo = new OrderProductInfo(); orderProductInfo.RecordId = TypeHelper.ObjectToInt(reader["recordid"]); orderProductInfo.Oid = TypeHelper.ObjectToInt(reader["oid"]); orderProductInfo.Uid = TypeHelper.ObjectToInt(reader["uid"]); orderProductInfo.Sid = reader["sid"].ToString(); orderProductInfo.Pid = TypeHelper.ObjectToInt(reader["pid"]); orderProductInfo.PSN = reader["psn"].ToString(); orderProductInfo.CateId = TypeHelper.ObjectToInt(reader["cateid"]); orderProductInfo.BrandId = TypeHelper.ObjectToInt(reader["brandid"]); orderProductInfo.StoreId = TypeHelper.ObjectToInt(reader["storeid"]); orderProductInfo.StoreCid = TypeHelper.ObjectToInt(reader["storecid"]); orderProductInfo.StoreSTid = TypeHelper.ObjectToInt(reader["storestid"]); orderProductInfo.Name = reader["name"].ToString(); orderProductInfo.ShowImg = reader["showimg"].ToString(); orderProductInfo.DiscountPrice = TypeHelper.ObjectToDecimal(reader["discountprice"]); orderProductInfo.ShopPrice = TypeHelper.ObjectToDecimal(reader["shopprice"]); orderProductInfo.CostPrice = TypeHelper.ObjectToDecimal(reader["costprice"]); orderProductInfo.MarketPrice = TypeHelper.ObjectToDecimal(reader["marketprice"]); orderProductInfo.Weight = TypeHelper.ObjectToInt(reader["weight"]); orderProductInfo.IsReview = TypeHelper.ObjectToInt(reader["isreview"]); orderProductInfo.RealCount = TypeHelper.ObjectToInt(reader["realcount"]); orderProductInfo.BuyCount = TypeHelper.ObjectToInt(reader["buycount"]); orderProductInfo.SendCount = TypeHelper.ObjectToInt(reader["sendcount"]); orderProductInfo.Type = TypeHelper.ObjectToInt(reader["type"]); orderProductInfo.PayCredits = TypeHelper.ObjectToInt(reader["paycredits"]); orderProductInfo.CouponTypeId = TypeHelper.ObjectToInt(reader["coupontypeid"]); orderProductInfo.ExtCode1 = TypeHelper.ObjectToInt(reader["extcode1"]); orderProductInfo.ExtCode2 = TypeHelper.ObjectToInt(reader["extcode2"]); orderProductInfo.ExtCode3 = TypeHelper.ObjectToInt(reader["extcode3"]); orderProductInfo.ExtCode4 = TypeHelper.ObjectToInt(reader["extcode4"]); orderProductInfo.ExtCode5 = TypeHelper.ObjectToInt(reader["extcode5"]); orderProductInfo.AddTime = TypeHelper.ObjectToDateTime(reader["addtime"]); return orderProductInfo; }
/// <summary> /// 初始化订单商品 /// </summary> private static void InitOrderProduct(OrderProductInfo orderProductInfo, int buyCount, string sid, int uid, DateTime buyTime) { if (uid > 0) orderProductInfo.Sid = ""; else orderProductInfo.Sid = sid; orderProductInfo.Uid = uid; orderProductInfo.RealCount = buyCount; orderProductInfo.BuyCount = buyCount; orderProductInfo.AddTime = buyTime; }
/// <summary> /// 创建OrderProductInfo /// </summary> public static OrderProductInfo BuildOrderProduct(ExtSuitProductInfo extSuitProductInfo) { OrderProductInfo orderProductInfo = new OrderProductInfo(); orderProductInfo.Pid = extSuitProductInfo.Pid; orderProductInfo.PSN = extSuitProductInfo.PSN; orderProductInfo.CateId = extSuitProductInfo.CateId; orderProductInfo.BrandId = extSuitProductInfo.BrandId; orderProductInfo.StoreId = extSuitProductInfo.StoreId; orderProductInfo.StoreCid = extSuitProductInfo.StoreCid; orderProductInfo.StoreSTid = extSuitProductInfo.StoreSTid; orderProductInfo.Name = extSuitProductInfo.Name; orderProductInfo.DiscountPrice = extSuitProductInfo.ShopPrice; orderProductInfo.ShopPrice = extSuitProductInfo.ShopPrice; orderProductInfo.MarketPrice = extSuitProductInfo.MarketPrice; orderProductInfo.CostPrice = extSuitProductInfo.CostPrice; orderProductInfo.Weight = extSuitProductInfo.Weight; orderProductInfo.ShowImg = extSuitProductInfo.ShowImg; return orderProductInfo; }
/// <summary> /// 删除购物车中的满赠 /// </summary> /// <param name="orderProductList">购物车商品列表</param> /// <param name="fullSendMinorOrderProductInfo">赠送商品</param> public static void DeleteCartFullSend(ref List<OrderProductInfo> orderProductList, OrderProductInfo fullSendMinorOrderProductInfo) { orderProductList.Remove(fullSendMinorOrderProductInfo); DeleteOrderProductList(new List<OrderProductInfo>() { fullSendMinorOrderProductInfo }); }
/// <summary> /// 添加已经存在的商品到购物车中 /// </summary> /// <param name="orderProductList">订单商品列表</param> /// <param name="buyCount">购买数量</param> /// <param name="orderProductInfo">订单商品信息</param> /// <param name="buyTime">购买时间</param> public static void AddExistProductToCart(ref List<OrderProductInfo> orderProductList, int buyCount, OrderProductInfo orderProductInfo, DateTime buyTime) { List<OrderProductInfo> updateOrderProductList = new List<OrderProductInfo>(); //更新买送促销活动 UpdateBuySendPromotionOfOrderProduct(orderProductInfo, buyCount, buyTime); //更新订单商品的赠品促销活动 List<OrderProductInfo> giftOrderProductList = UpdateGiftOrderProduct(orderProductList, orderProductInfo, buyCount); updateOrderProductList.Add(orderProductInfo); updateOrderProductList.AddRange(giftOrderProductList); UpdateOrderProductCount(updateOrderProductList); }
/// <summary> /// 删除购物车中的商品 /// </summary> /// <param name="orderProductList">购物车中商品列表</param> /// <param name="orderProductInfo">删除商品</param> public static void DeleteCartProduct(ref List<OrderProductInfo> orderProductList, OrderProductInfo orderProductInfo) { //需要删除的商品列表 List<OrderProductInfo> delOrderProductList = new List<OrderProductInfo>(); //将主商品添加到需要删除的商品列表中 delOrderProductList.Add(orderProductInfo); if (orderProductInfo.ExtCode3 > 0) { //赠品商品列表 List<OrderProductInfo> giftOrderProductList = GetGiftOrderProductList(1, orderProductInfo.ExtCode3, orderProductList); //将赠品添加到需要删除的商品列表中 delOrderProductList.AddRange(giftOrderProductList); } if (orderProductInfo.ExtCode4 > 0) { //满赠赠品 OrderProductInfo fullSendMinorOrderProductInfo = GetFullSendMinorOrderProduct(orderProductInfo.ExtCode4, orderProductList); if (fullSendMinorOrderProductInfo != null) { FullSendPromotionInfo fullSendPromotionInfo = Promotions.GetFullSendPromotionByPmIdAndTime(orderProductInfo.ExtCode4, DateTime.Now); if (fullSendPromotionInfo != null) { List<OrderProductInfo> fullSendMainOrderProductList = GetFullSendMainOrderProductList(orderProductInfo.ExtCode4, orderProductList); decimal amount = SumOrderProductAmount(fullSendMainOrderProductList) - orderProductInfo.DiscountPrice * orderProductInfo.BuyCount; if (amount < fullSendPromotionInfo.LimitMoney || fullSendMinorOrderProductInfo.DiscountPrice != fullSendPromotionInfo.AddMoney) delOrderProductList.Add(fullSendMinorOrderProductInfo); } else { delOrderProductList.Add(fullSendMinorOrderProductInfo); } } } //删除商品 DeleteOrderProductList(delOrderProductList); foreach (OrderProductInfo item in delOrderProductList) orderProductList.Remove(item); }
/// <summary> /// 设置满赠订单商品 /// </summary> /// <param name="orderProductInfo">订单商品</param> /// <param name="fullSendPromotionInfo">满赠促销活动</param> public static void SetFullSendOrderProduct(OrderProductInfo orderProductInfo, FullSendPromotionInfo fullSendPromotionInfo) { orderProductInfo.RealCount = 1; orderProductInfo.BuyCount = 1; orderProductInfo.DiscountPrice = fullSendPromotionInfo.AddMoney; orderProductInfo.Type = 4; orderProductInfo.ExtCode1 = fullSendPromotionInfo.PmId; }
/// <summary> /// 设置套装订单商品 /// </summary> /// <param name="orderProductInfo">订单商品</param> /// <param name="buyCount">购买数量</param> /// <param name="number">数量</param> /// <param name="discount">折扣值</param> /// <param name="suitPromotionInfo">套装促销活动</param> public static void SetSuitOrderProduct(OrderProductInfo orderProductInfo, int buyCount, int number, int discount, SuitPromotionInfo suitPromotionInfo) { orderProductInfo.Type = 3; orderProductInfo.ExtCode1 = suitPromotionInfo.PmId; orderProductInfo.ExtCode2 = number; orderProductInfo.RealCount = number * buyCount; orderProductInfo.BuyCount = number * buyCount; orderProductInfo.DiscountPrice = orderProductInfo.ShopPrice - discount; }
/// <summary> /// 更新赠品订单商品 /// </summary> /// <param name="orderProductList">订单商品列表</param> /// <param name="orderProductInfo">订单商品</param> /// <param name="buyCount">购买数量</param> /// <returns></returns> public static List<OrderProductInfo> UpdateGiftOrderProduct(List<OrderProductInfo> orderProductList, OrderProductInfo orderProductInfo, int buyCount) { if (orderProductInfo.ExtCode3 < 1) return new List<OrderProductInfo>(); //获得赠品订单商品列表 List<OrderProductInfo> giftOrderProductList = GetGiftOrderProductList(1, orderProductInfo.ExtCode3, orderProductList); foreach (OrderProductInfo item in giftOrderProductList) item.RealCount = buyCount * item.ExtCode2; return giftOrderProductList; }
/// <summary> /// 更新订单商品的买送促销活动 /// </summary> /// <param name="orderProductInfo">订单商品</param> /// <param name="buyCount">购买数量</param> /// <param name="buyTime">购买时间</param> public static void UpdateBuySendPromotionOfOrderProduct(OrderProductInfo orderProductInfo, int buyCount, DateTime buyTime) { //获得商品的买送促销活动 BuySendPromotionInfo buySendPromotionInfo = Promotions.GetBuySendPromotion(buyCount, orderProductInfo.StoreId, orderProductInfo.Pid, buyTime); if (buySendPromotionInfo == null && orderProductInfo.ExtCode2 > 0)//当商品存在买送促销活动但添加后不存在买送促销活动时 { orderProductInfo.RealCount = buyCount; orderProductInfo.BuyCount = buyCount; orderProductInfo.ExtCode2 = 0; } else if (buySendPromotionInfo != null && orderProductInfo.ExtCode2 <= 0)//当商品不存在买送促销活动但添加后存在买送促销活动时 { SetBuySendPromotionOfOrderProduct(orderProductInfo, buyCount, buySendPromotionInfo); } else if (buySendPromotionInfo != null && orderProductInfo.ExtCode2 > 0)//当商品存在买送促销活动但添加后仍然满足买送促销活动时 { SetBuySendPromotionOfOrderProduct(orderProductInfo, buyCount, buySendPromotionInfo); } else { orderProductInfo.RealCount = buyCount; orderProductInfo.BuyCount = buyCount; } }
/// <summary> /// 设置订单商品的满减促销活动 /// </summary> /// <param name="orderProductInfo">订单商品</param> /// <param name="fullCutPromotionInfo">满减促销活动</param> public static void SetFullCutPromotionOfOrderProduct(OrderProductInfo orderProductInfo, FullCutPromotionInfo fullCutPromotionInfo) { orderProductInfo.ExtCode5 = fullCutPromotionInfo.PmId; }
/// <summary> /// 设置赠品订单商品 /// </summary> /// <param name="orderProductInfo">订单商品</param> /// <param name="type">类型</param> /// <param name="buyCount">购买数量</param> /// <param name="number">赠送数量</param> /// <param name="pmId">赠品促销活动id</param> public static void SetGiftOrderProduct(OrderProductInfo orderProductInfo, int type, int buyCount, int number, int pmId) { orderProductInfo.DiscountPrice = 0M; orderProductInfo.RealCount = buyCount * number; orderProductInfo.BuyCount = 0; orderProductInfo.Type = type; orderProductInfo.ExtCode1 = pmId; orderProductInfo.ExtCode2 = number; }
/// <summary> /// 设置订单商品的单品促销活动 /// </summary> /// <param name="orderProductInfo">订单商品</param> /// <param name="singlePromotionInfo">单品促销活动</param> public static void SetSinglePromotionOfOrderProduct(OrderProductInfo orderProductInfo, SinglePromotionInfo singlePromotionInfo) { orderProductInfo.ExtCode1 = singlePromotionInfo.PmId; switch (singlePromotionInfo.DiscountType) { case 0://折扣 { decimal temp = Math.Ceiling((orderProductInfo.ShopPrice * singlePromotionInfo.DiscountValue) / 10); orderProductInfo.DiscountPrice = temp < 0 ? orderProductInfo.ShopPrice : temp; break; } case 1://直降 { decimal temp = orderProductInfo.ShopPrice - singlePromotionInfo.DiscountValue; orderProductInfo.DiscountPrice = temp < 0 ? orderProductInfo.ShopPrice : temp; break; } case 2://折后价 { orderProductInfo.DiscountPrice = singlePromotionInfo.DiscountValue; break; } } //设置赠送积分 if (singlePromotionInfo.PayCredits > 0) orderProductInfo.PayCredits = singlePromotionInfo.PayCredits; //设置赠送优惠劵 if (singlePromotionInfo.CouponTypeId > 0) orderProductInfo.CouponTypeId = singlePromotionInfo.CouponTypeId; }
/// <summary> /// 设置订单商品的买送促销活动 /// </summary> /// <param name="orderProductInfo">订单商品</param> /// <param name="buyCount">购买数量</param> /// <param name="buySendPromotionInfo">买送优惠活动</param> public static void SetBuySendPromotionOfOrderProduct(OrderProductInfo orderProductInfo, int buyCount, BuySendPromotionInfo buySendPromotionInfo) { orderProductInfo.RealCount = buyCount + (buyCount / buySendPromotionInfo.BuyCount) * buySendPromotionInfo.SendCount; orderProductInfo.BuyCount = buyCount; orderProductInfo.ExtCode2 = buySendPromotionInfo.PmId; }
/// <summary> /// 发放评价商品积分 /// </summary> /// <param name="partUserInfo">用户信息</param> /// <param name="orderProductInfo">订单商品</param> /// <param name="reviewTime">评价时间</param> public static int SendReviewProductCredits(ref PartUserInfo partUserInfo, OrderProductInfo orderProductInfo, DateTime reviewTime) { if (_creditconfiginfo.ReviewProductPayCredits > 0 || _creditconfiginfo.ReviewProductRankCredits > 0) { int surplusPayCredits = GetDaySurplusPayCredits(partUserInfo.Uid, reviewTime.Date); int surplusRankCredits = GetDaySurplusRankCredits(partUserInfo.Uid, reviewTime.Date); if (surplusPayCredits == 0 && surplusRankCredits == 0) return 0; int payCredits = 0; int rankCredits = 0; if (surplusPayCredits > 0) payCredits = surplusPayCredits < _creditconfiginfo.ReviewProductPayCredits ? surplusPayCredits : _creditconfiginfo.ReviewProductPayCredits; else if (surplusPayCredits == -1) payCredits = _creditconfiginfo.ReviewProductPayCredits; if (surplusRankCredits > 0) rankCredits = surplusRankCredits < _creditconfiginfo.ReviewProductRankCredits ? surplusRankCredits : _creditconfiginfo.ReviewProductRankCredits; else if (surplusRankCredits == -1) rankCredits = _creditconfiginfo.ReviewProductRankCredits; partUserInfo.PayCredits += payCredits; partUserInfo.RankCredits += rankCredits; int userRid = UserRanks.GetUserRankByCredits(partUserInfo.RankCredits).UserRid; if (userRid != partUserInfo.UserRid) partUserInfo.UserRid = userRid; else userRid = 0; CreditLogInfo creditLogInfo = new CreditLogInfo(); creditLogInfo.Uid = partUserInfo.Uid; creditLogInfo.PayCredits = payCredits; creditLogInfo.RankCredits = rankCredits; creditLogInfo.Action = (int)CreditAction.ReviewProduct; creditLogInfo.ActionCode = orderProductInfo.Oid; creditLogInfo.ActionTime = reviewTime; creditLogInfo.ActionDes = "评价商品:" + orderProductInfo.Name; creditLogInfo.Operator = 0; SendCredits(userRid, creditLogInfo); return payCredits; } return 0; }