Example #1
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 /// <param name="pTran">事务实例,可为null,如果为null,则不使用事务来更新</param>
 public void Update(PanicbuyingKJEventJoinDetailEntity pEntity, IDbTransaction pTran)
 {
     _currentDAO.Update(pEntity, pTran);
 }
Example #2
0
 /// <summary>
 /// 创建一个新实例
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 public void Create(PanicbuyingKJEventJoinDetailEntity pEntity)
 {
     _currentDAO.Create(pEntity);
 }
Example #3
0
 /// <summary>
 /// 分页根据实体条件查询实体
 /// </summary>
 /// <param name="pQueryEntity">以实体形式传入的参数</param>
 /// <param name="pOrderBys">排序组合</param>
 /// <returns>符合条件的实体集</returns>
 public PagedQueryResult <PanicbuyingKJEventJoinDetailEntity> PagedQueryByEntity(PanicbuyingKJEventJoinDetailEntity pQueryEntity, OrderBy[] pOrderBys, int pPageSize, int pCurrentPageIndex)
 {
     return(_currentDAO.PagedQueryByEntity(pQueryEntity, pOrderBys, pPageSize, pCurrentPageIndex));
 }
Example #4
0
 /// <summary>
 /// 根据实体条件查询实体
 /// </summary>
 /// <param name="pQueryEntity">以实体形式传入的参数</param>
 /// <param name="pOrderBys">排序组合</param>
 /// <returns>符合条件的实体集</returns>
 public PanicbuyingKJEventJoinDetailEntity[] QueryByEntity(PanicbuyingKJEventJoinDetailEntity pQueryEntity, OrderBy[] pOrderBys)
 {
     return(_currentDAO.QueryByEntity(pQueryEntity, pOrderBys));
 }
Example #5
0
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="pEntity"></param>
 public void Delete(PanicbuyingKJEventJoinDetailEntity pEntity)
 {
     _currentDAO.Delete(pEntity);
 }
        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);
        }
    }
}