protected override EmptyResponseData ProcessRequest(DTO.Base.APIRequest <SetBargainDetailsRP> pRequest) { var rd = new EmptyResponseData(); var para = pRequest.Parameters; var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo; var ItemMappingBll = new PanicbuyingKJEventItemMappingBLL(loggingSessionInfo); var SkuMappingBll = new PanicbuyingKJEventSkuMappingBLL(loggingSessionInfo); var PanicbuyingEventBLL = new PanicbuyingEventBLL(loggingSessionInfo); var pTran = ItemMappingBll.GetTran(); string m_EventItemMappingID = string.Empty; int SumQty = 0; using (pTran.Connection) { try { #region 商品 if (!string.IsNullOrWhiteSpace(para.EventItemMappingID)) { //编辑 var UpdateItemData = ItemMappingBll.GetByID(para.EventItemMappingID); if (UpdateItemData == null) { throw new APIException("未找到相关砍价活动商品,请确认参数") { ErrorCode = ERROR_CODES.INVALID_BUSINESS } } ; UpdateItemData.SinglePurchaseQty = para.SinglePurchaseQty; UpdateItemData.BargaingingInterval = para.BargaingingInterval; // ItemMappingBll.Update(UpdateItemData, pTran); // m_EventItemMappingID = para.EventItemMappingID; } else { #region 创建砍价商品 var ItemResult = ItemMappingBll.QueryByEntity(new PanicbuyingKJEventItemMappingEntity() { EventId = new Guid(para.EventId), ItemID = para.ItemId }, null).ToList(); if (ItemResult.Count() > 0) { throw new APIException("当前砍价活动已添加过相同的商品,请换一个商品添加!") { ErrorCode = ERROR_CODES.INVALID_BUSINESS } } ; var AddItemData = new PanicbuyingKJEventItemMappingEntity(); AddItemData.EventItemMappingID = System.Guid.NewGuid(); AddItemData.EventId = new Guid(para.EventId); AddItemData.ItemID = para.ItemId; AddItemData.MinPrice = 0; AddItemData.MinBasePrice = 0; AddItemData.SoldQty = 0; AddItemData.Qty = 0; AddItemData.KeepQty = 0; AddItemData.SinglePurchaseQty = para.SinglePurchaseQty; AddItemData.DiscountRate = 0; AddItemData.PromotePersonCount = 0; AddItemData.BargainPersonCount = 0; AddItemData.PurchasePersonCount = 0; AddItemData.Status = 1; AddItemData.StatusReason = ""; AddItemData.DisplayIndex = 0; AddItemData.BargaingingInterval = para.BargaingingInterval; AddItemData.customerId = loggingSessionInfo.ClientID; // ItemMappingBll.Create(AddItemData, pTran); //更新活动商品数量 var UpdateEventData = PanicbuyingEventBLL.GetByID(para.EventId); if (UpdateEventData == null) { throw new APIException("未找到相关砍价活动,请确认参数") { ErrorCode = ERROR_CODES.INVALID_BUSINESS } } ; UpdateEventData.ItemQty += 1; PanicbuyingEventBLL.Update(UpdateEventData, pTran); // m_EventItemMappingID = AddItemData.EventItemMappingID.ToString(); #endregion } #endregion #region sku if (para.EventSkuInfoList.Count > 0) { foreach (var item in para.EventSkuInfoList) { if (!string.IsNullOrWhiteSpace(item.EventSKUMappingId)) { var UpdateSkuData = SkuMappingBll.GetByID(item.EventSKUMappingId); if (UpdateSkuData == null) { throw new APIException("未找到相关砍价活动商品规格信息,请确认参数") { ErrorCode = ERROR_CODES.INVALID_BUSINESS } } ; if (item.IsDelete == 1) { //删除 SkuMappingBll.Delete(UpdateSkuData, pTran); // // SumQty += -UpdateSkuData.Qty.Value; } else { // SumQty += item.Qty - UpdateSkuData.Qty.Value; #region 编辑 UpdateSkuData.BasePrice = item.BasePrice; UpdateSkuData.Qty = item.Qty; UpdateSkuData.BargainStartPrice = item.BargainStartPrice; UpdateSkuData.BargainEndPrice = item.BargainEndPrice; // SkuMappingBll.Update(UpdateSkuData, pTran); #endregion } } else { #region 创建 var SkuResult = SkuMappingBll.QueryByEntity(new PanicbuyingKJEventSkuMappingEntity() { EventItemMappingID = m_EventItemMappingID, SkuID = item.SkuID }, null).ToList(); if (SkuResult.Count() > 0) { throw new APIException("当前砍价活动商品已添加过相同的Sku,请换一个!") { ErrorCode = ERROR_CODES.INVALID_BUSINESS } } ; var AddSkuData = new PanicbuyingKJEventSkuMappingEntity(); AddSkuData.EventSKUMappingId = System.Guid.NewGuid(); AddSkuData.EventItemMappingID = m_EventItemMappingID; AddSkuData.SkuID = item.SkuID; AddSkuData.AddedTime = DateTime.Now; AddSkuData.Qty = item.Qty; AddSkuData.KeepQty = 0; AddSkuData.SoldQty = 0; AddSkuData.SinglePurchaseQty = 0; AddSkuData.Price = item.Price; AddSkuData.BasePrice = item.BasePrice; AddSkuData.BargainStartPrice = item.BargainStartPrice; AddSkuData.BargainEndPrice = item.BargainEndPrice; AddSkuData.DisplayIndex = 0; AddSkuData.IsFirst = 1; AddSkuData.Status = 1; AddSkuData.CustomerId = loggingSessionInfo.ClientID; // SkuMappingBll.Create(AddSkuData, pTran); // SumQty += AddSkuData.Qty.Value; #endregion } } } #endregion //提交 pTran.Commit(); } catch (APIException ex) { pTran.Rollback(); throw ex; } } //更新砍价商品总库存、最小底价、原价 if (SumQty > 0) { var UpdateData = ItemMappingBll.GetByID(m_EventItemMappingID); UpdateData.Qty += SumQty; UpdateData.MinPrice = SkuMappingBll.GetConfigPrice(UpdateData.EventItemMappingID.ToString(), "MinPrice"); UpdateData.MinBasePrice = SkuMappingBll.GetConfigPrice(UpdateData.EventItemMappingID.ToString(), "MinBasePrice"); ItemMappingBll.Update(UpdateData); } 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 JoinInKJEventRD ProcessRequest(APIRequest <JoinInKJEventRP> pRequest) { JoinInKJEventRP rp = pRequest.Parameters; JoinInKJEventRD rd = new JoinInKJEventRD(); PanicbuyingKJEventJoinBLL panicbuyingKJEventJoinBll = new PanicbuyingKJEventJoinBLL(CurrentUserInfo); PanicbuyingEventBLL panicbuyingEventBll = new PanicbuyingEventBLL(CurrentUserInfo); PanicbuyingKJEventItemMappingBLL panicbuyingKJEventItemMappingBll = new PanicbuyingKJEventItemMappingBLL(CurrentUserInfo); if (string.IsNullOrEmpty(rp.EventId)) { throw new APIException("EventId不能为空"); } if (string.IsNullOrEmpty(rp.SkuId)) { throw new APIException("SkuId不能为空"); } #region 价参与 PanicbuyingKJEventJoinEntity panicbuyingKJEventJoinEntity = new PanicbuyingKJEventJoinEntity() { KJEventJoinId = Guid.NewGuid(), EventId = new Guid(rp.EventId), ItemId = rp.ItemId, SkuId = rp.SkuId, VipId = pRequest.UserID, CustomerId = pRequest.CustomerID, SalesPrice = rp.Price, }; panicbuyingKJEventJoinBll.Create(panicbuyingKJEventJoinEntity); #endregion #region 更新参与砍价活动人数统计 var panicbuyingEventEnetity = panicbuyingEventBll.QueryByEntity(new PanicbuyingEventEntity() { EventId = new Guid(rp.EventId) }, null).FirstOrDefault(); if (panicbuyingEventEnetity != null) { panicbuyingEventEnetity.PromotePersonCount += 1; //panicbuyingEventEnetity.BargainPersonCount += 1; panicbuyingEventBll.Update(panicbuyingEventEnetity); } #endregion #region 更新发起砍价商品活动人数统计 var panicbuyingKJEventItemMappingEntity = panicbuyingKJEventItemMappingBll.QueryByEntity(new PanicbuyingKJEventItemMappingEntity() { EventId = new Guid(rp.EventId), ItemID = rp.ItemId }, null).FirstOrDefault(); if (panicbuyingKJEventItemMappingEntity != null) { panicbuyingKJEventItemMappingEntity.PromotePersonCount += 1; panicbuyingKJEventItemMappingBll.Update(panicbuyingKJEventItemMappingEntity); } #endregion rd.KJEventJoinId = panicbuyingKJEventJoinEntity.KJEventJoinId.ToString(); return(rd); }