protected override GetHelperListRD ProcessRequest(APIRequest <GetHelperListRP> pRequest) { GetHelperListRP rp = pRequest.Parameters; GetHelperListRD rd = new GetHelperListRD(); PanicbuyingKJEventJoinDetailBLL panicbuyingKJEventJoinDetailBll = new PanicbuyingKJEventJoinDetailBLL(CurrentUserInfo); DataSet ds = panicbuyingKJEventJoinDetailBll.GetHelperList(rp.EventId, rp.KJEventJoinId, rp.SkuId, rp.PageSize, rp.PageIndex); if (ds.Tables.Count > 0) { rd.HelperList = DataTableToObject.ConvertToList <Helper>(ds.Tables[0]); rd.TotalCount = Convert.ToInt32(ds.Tables[1].Rows[0][0]); rd.TotalPage = Convert.ToInt32(ds.Tables[1].Rows[0][0]); } return(rd); }
protected override AddKJEventJoinDetailRD ProcessRequest(APIRequest <AddKJEventJoinDetailRP> pRequest) { var rp = pRequest.Parameters; var rd = new AddKJEventJoinDetailRD(); var Bll = new PanicbuyingKJEventJoinDetailBLL(CurrentUserInfo); var PanicbuyingEventBll = new PanicbuyingEventBLL(CurrentUserInfo); var EventSkuMappingBll = new PanicbuyingKJEventSkuMappingBLL(CurrentUserInfo); var KJEventJoinBll = new PanicbuyingKJEventJoinBLL(CurrentUserInfo); var KJEventItemMappingBll = new PanicbuyingKJEventItemMappingBLL(CurrentUserInfo); var pTran = Bll.GetTran(); // var EventData = PanicbuyingEventBll.GetByID(rp.EventId); if (EventData == null) { throw new APIException("找不到砍价活动对象!") { ErrorCode = ERROR_CODES.INVALID_BUSINESS } } ; // var EventItemData = KJEventItemMappingBll.QueryByEntity(new PanicbuyingKJEventItemMappingEntity() { EventId = new System.Guid(rp.EventId), ItemID = rp.ItemId }, null).FirstOrDefault(); if (EventData == null) { throw new APIException("找不到砍价活动商品对象!") { ErrorCode = ERROR_CODES.INVALID_BUSINESS } } ; // var EventSkuMappingData = EventSkuMappingBll.QueryByEntity(new PanicbuyingKJEventSkuMappingEntity() { EventItemMappingID = EventItemData.EventItemMappingID.ToString(), SkuID = rp.SkuId }, null).FirstOrDefault(); if (EventSkuMappingData == null) { throw new APIException("找不到砍价活动商品Sku关系对象!") { ErrorCode = ERROR_CODES.INVALID_BUSINESS } } ; // var KJEventJoinData = KJEventJoinBll.GetByID(rp.KJEventJoinId); if (KJEventJoinData == null) { throw new APIException("找不到砍价参与主表对象!") { ErrorCode = ERROR_CODES.INVALID_BUSINESS } } ; //判断重复帮砍 var Collection = Bll.QueryByEntity(new PanicbuyingKJEventJoinDetailEntity() { KJEventJoinId = KJEventJoinData.KJEventJoinId, VipId = pRequest.UserID }, null).ToList(); if (Collection.Count > 0) { throw new APIException("您已经帮砍过了,不能重复帮砍!") { ErrorCode = ERROR_CODES.INVALID_BUSINESS } } ; #region 价业务处理 //当前成交价 decimal NowMoney = KJEventJoinData.SalesPrice.Value; if (NowMoney == EventSkuMappingData.BasePrice) { throw new APIException("已经砍到底价,不能继续砍价!") { ErrorCode = ERROR_CODES.INVALID_BUSINESS } } ; if (EventSkuMappingData.BargainStartPrice == null || EventSkuMappingData.BargainEndPrice == null) { throw new APIException("砍价起始、结束区间值不能为Null,错误数据!") { ErrorCode = ERROR_CODES.INVALID_BUSINESS } } ; // Random ran = new Random(); int start = Convert.ToInt32(EventSkuMappingData.BargainStartPrice); int End = Convert.ToInt32(EventSkuMappingData.BargainEndPrice); int math = ran.Next(start, End); //砍价后的价格 decimal Result = NowMoney - Convert.ToDecimal(math); if (Result < EventSkuMappingData.BasePrice) {//如果Result小于底价,那Result赋值为底价金额值 Result = EventSkuMappingData.BasePrice.Value; } //砍了多少 decimal BargainPrice = NowMoney - Result; //赋值 rd.BargainPrice = BargainPrice; #endregion using (pTran.Connection) { try { //添加砍价参与者信息 var AddData = new PanicbuyingKJEventJoinDetailEntity(); AddData.KJEventJoinDetailId = System.Guid.NewGuid(); AddData.KJEventJoinId = KJEventJoinData.KJEventJoinId; AddData.EventId = new System.Guid(rp.EventId); AddData.ItemId = rp.ItemId; AddData.SkuId = rp.SkuId; AddData.VipId = pRequest.UserID; AddData.BargainPrice = BargainPrice; AddData.MomentSalesPrice = Result; AddData.CustomerId = CurrentUserInfo.ClientID; // Bll.Create(AddData, pTran); //更新参与主表帮砍统计、成交价 KJEventJoinData.BargainPersonCount = KJEventJoinData.BargainPersonCount ?? 0; KJEventJoinData.BargainPersonCount += 1; KJEventJoinData.SalesPrice = KJEventJoinData.SalesPrice ?? 0; KJEventJoinData.SalesPrice = Result; KJEventJoinBll.Update(KJEventJoinData, pTran); //更新砍价活动表帮砍人数统记 EventData.BargainPersonCount += 1; PanicbuyingEventBll.Update(EventData, pTran); //更新活动商品帮砍人数统计 EventItemData.BargainPersonCount = EventItemData.BargainPersonCount ?? 0; EventItemData.BargainPersonCount += 1; KJEventItemMappingBll.Update(EventItemData, pTran); //提交 pTran.Commit(); } catch (APIException ex) { pTran.Rollback(); throw ex; } } return(rd); } } }
protected override GetPanicbuyingKJItemDetailRD ProcessRequest(APIRequest <GetPanicBuyingKJItemDetailRP> pRequest) { GetPanicBuyingKJItemDetailRP rp = pRequest.Parameters; GetPanicbuyingKJItemDetailRD rd = new GetPanicbuyingKJItemDetailRD(); OnlineShoppingItemBLL itemService = new OnlineShoppingItemBLL(CurrentUserInfo); ItemService itemServiceBll = new ItemService(CurrentUserInfo); var customerBasicSettingBll = new CustomerBasicSettingBLL(CurrentUserInfo); var panicbuyingEventBll = new PanicbuyingEventBLL(CurrentUserInfo); var panicbuyingKJEventItemMappingBll = new PanicbuyingKJEventItemMappingBLL(CurrentUserInfo); var panicbuyingKJEventSkuMappingBll = new PanicbuyingKJEventSkuMappingBLL(CurrentUserInfo); var panicbuyingKJEventJoinBll = new PanicbuyingKJEventJoinBLL(CurrentUserInfo); var panicbuyingKJEventJoinDetailBll = new PanicbuyingKJEventJoinDetailBLL(CurrentUserInfo); var vipBll = new VipBLL(CurrentUserInfo); var vipEntity = vipBll.GetByID(pRequest.UserID); if (vipEntity != null) { rd.HeadImageUrl = vipEntity.HeadImgUrl; } #region 判断是否已经参与 rd.isPromoted = 0; if (!string.IsNullOrEmpty(rp.KJEventJoinId)) { var panicbuyingKJEventJoinEntity = panicbuyingKJEventJoinBll.GetByID(rp.KJEventJoinId); if (panicbuyingKJEventJoinEntity == null) { rd.isPromoted = 0; } else { rd.isPromoted = 1; var VipData = vipBll.GetByID(panicbuyingKJEventJoinEntity.VipId); rd.HeadImageUrl = VipData.HeadImgUrl; } } #endregion //为复用原来接口所设置参数 DateTime dtBeginTime = Convert.ToDateTime("9999/01/01"); DateTime dtEndTime = Convert.ToDateTime("9999/01/01"); #region 价活动商品基本信息 KJEventItemDetailInfo eventItemInfo = panicbuyingEventBll.GetKJEventWithItemDetail(rp.EventId, rp.ItemId); if (eventItemInfo != null) { rd.ItemId = eventItemInfo.ItemId; rd.ItemName = eventItemInfo.ItemName; rd.MinPrice = eventItemInfo.MinPrice; rd.MinBasePrice = eventItemInfo.MinBasePrice; rd.SinglePurchaseQty = eventItemInfo.SinglePurchaseQty; rd.PromotePersonCount = eventItemInfo.PromotePersonCount; rd.CurrentQty = eventItemInfo.CurrentQty; rd.SoldQty = eventItemInfo.SoldQty; rd.EventEndTime = eventItemInfo.EventEndTime.ToString("yyyy-MM-dd HH:mm:ss"); rd.Seconds = Convert.ToInt64(eventItemInfo.EventEndTime.Subtract(DateTime.Now).TotalSeconds < 0 ? 0 : eventItemInfo.EventEndTime.Subtract(DateTime.Now).TotalSeconds); rd.PropName1 = eventItemInfo.Prop1Name; rd.PropName2 = eventItemInfo.Prop2Name; rd.ItemIntroduce = eventItemInfo.ItemIntroduce; #endregion #region if (eventItemInfo.EventEndTime < DateTime.Now) { rd.isEventEnd = 0; } else if (eventItemInfo.EventBeginTime > DateTime.Now) {//活动未开始 rd.isEventEnd = 2; rd.Seconds = Convert.ToInt64(eventItemInfo.EventBeginTime.Subtract(DateTime.Now).TotalSeconds < 0 ? 0 : eventItemInfo.EventBeginTime.Subtract(DateTime.Now).TotalSeconds); } else { rd.isEventEnd = 1; } #endregion #region 商品图片 var dsImages = itemService.GetItemImageList(rp.ItemId); if (dsImages != null && dsImages.Tables.Count > 0 && dsImages.Tables[0].Rows.Count > 0) { rd.ImageList = DataTableToObject.ConvertToList <ImageInfo>(dsImages.Tables[0]); } #endregion #region 商品详情页 if (rp.type == 1) { #region 关于商品所有Sku信息 var dsSkus = itemServiceBll.GetItemSkuList(rp.ItemId, pRequest.UserID, pRequest.CustomerID, dtBeginTime, dtEndTime); var panicbuyingKJEventSkuMappingList = panicbuyingKJEventSkuMappingBll.QueryByEntity(new PanicbuyingKJEventSkuMappingEntity() { EventItemMappingID = eventItemInfo.EventItemMappingID }, null).ToList(); if (dsSkus != null && dsSkus.Tables.Count > 0 && dsSkus.Tables[0].Rows.Count > 0) { rd.SkuInfoList = DataTableToObject.ConvertToList <ItemSkuInfo>(dsSkus.Tables[0]); } rd.SkuInfoList = rd.SkuInfoList.Join(panicbuyingKJEventSkuMappingList, n => n.skuId, m => m.SkuID, (n, m) => new ItemSkuInfo() { skuId = n.skuId, skuProp1 = n.skuProp1, skuProp2 = n.skuProp2, BasePrice = m.BasePrice.ToString(), price = m.Price.ToString(), SalesCount = m.SoldQty.ToString(), Stock = (m.Qty - m.SoldQty).ToString(), }).Distinct().ToList(); #endregion #region 商品属性 var dsProp1 = panicbuyingKJEventItemMappingBll.GetKJItemProp1List(rp.ItemId, rp.EventId); if (dsProp1 != null && dsProp1.Tables.Count > 0 && dsProp1.Tables[0].Rows.Count > 0) { rd.Prop1List = DataTableToObject.ConvertToList <SkuProp1>(dsProp1.Tables[0]); } #endregion rd.status = 1; } #endregion #region 帮砍页面 if (rp.type == 2 && rd.isPromoted == 1) { if (!string.IsNullOrEmpty(rp.SkuId)) { KJItemSkuInfo kJItemSkuInfo = panicbuyingKJEventSkuMappingBll.GetKJItemSkuInfo(rp.EventId, rp.SkuId, rp.KJEventJoinId); rd.SkuInfoList = new List <ItemSkuInfo>(); ItemSkuInfo itemSkuInfo = new ItemSkuInfo(); itemSkuInfo.skuId = kJItemSkuInfo.skuId; itemSkuInfo.skuProp1 = kJItemSkuInfo.skuProp1; itemSkuInfo.skuProp2 = kJItemSkuInfo.skuProp2; itemSkuInfo.price = kJItemSkuInfo.price.ToString(); itemSkuInfo.Stock = kJItemSkuInfo.Stock; rd.SkuInfoList.Add(itemSkuInfo); rd.BargainedPrice = kJItemSkuInfo.price - kJItemSkuInfo.SalesPrice; rd.MinPrice = kJItemSkuInfo.price; rd.MinBasePrice = kJItemSkuInfo.BasePrice; rd.EventSKUMappingId = kJItemSkuInfo.EventSKUMappingId; double EventTime = Convert.ToInt64(eventItemInfo.EventEndTime.Subtract(DateTime.Now).TotalSeconds < 0 ? 0 : eventItemInfo.EventEndTime.Subtract(DateTime.Now).TotalSeconds); double tempTime = (kJItemSkuInfo.CreateTime.AddHours(Convert.ToDouble(eventItemInfo.BargaingingInterval)) - DateTime.Now).TotalSeconds; if (EventTime > tempTime) { rd.Seconds = Convert.ToInt64(tempTime < 0 ? 0 : tempTime); } else { rd.Seconds = Convert.ToInt64(EventTime < 0 ? 0 : EventTime); } decimal tempPrice = rd.MinPrice - rd.MinBasePrice; if (tempPrice != 0) { rd.BargainedRate = Math.Round(rd.BargainedPrice / (tempPrice), 2); } else { rd.BargainedRate = 0; } if (!string.IsNullOrEmpty(rp.KJEventJoinId)) { var panicbuyingKJEventJoinDetailEntity = panicbuyingKJEventJoinDetailBll.QueryByEntity(new PanicbuyingKJEventJoinDetailEntity() { KJEventJoinId = new Guid(rp.KJEventJoinId), VipId = pRequest.UserID }, null).FirstOrDefault(); if (panicbuyingKJEventJoinDetailEntity == null) { rd.status = 2; } else { rd.status = 3; } } else { rd.status = 2; } } } #endregion rd.DeliveryDesc = customerBasicSettingBll.GetSettingValueByCode("DeliveryStrategy"); rd.CustomerShortName = customerBasicSettingBll.GetSettingValueByCode("CustomerShortName"); rd.WebLogo = customerBasicSettingBll.GetSettingValueByCode("WebLogo"); rd.QRCodeURL = customerBasicSettingBll.GetSettingValueByCode("GuideQRCode"); } else { throw new APIException("此活动已不存在") { ErrorCode = 100 }; } return(rd); }