Exemplo n.º 1
0
        public IMessageProvider Save()
        {
            if (string.IsNullOrWhiteSpace(commodityNo))
            {
                AddError(1, "请输入商品编码");
                return(this);
            }
            var commdity = CommodityService.GetBycommodityNo(commodityNo);

            if (commdity == null)
            {
                AddError(1, "商品编码不存在");
                return(this);
            }
            var model = SecondKillCommoditysService.GetById(Id);

            if (model != null)
            {
                model.commodityId = commdity.commodityId;
                model.num         = num;
                model.price       = price;
                model.surplusNum  = num - model.payNum;
                model.commodityNo = commodityNo;
                SecondKillCommoditysService.Update(model);
            }
            AddMessage("success");
            return(this);
        }
Exemplo n.º 2
0
        public ResultMessage SecondKillGDtlOrder(int id, int userId)
        {
            var set = SecondKillSetService.GetFirst();

            if (set == null)
            {
                return new ResultMessage()
                       {
                           Code = -3, Msg = "当前没有秒杀"
                       }
            }
            ;
            if (set.state != SecondKillSetState.Normal)
            {
                return(new ResultMessage()
                {
                    Code = -3, Msg = "当前没有秒杀"
                });
            }
            if (set.startTime > DateTime.Now)
            {
                return new ResultMessage()
                       {
                           Code = -3, Msg = "秒杀还没开始"
                       }
            }
            ;
            if (DateTime.Now >= set.endTime)
            {
                return new ResultMessage()
                       {
                           Code = -3, Msg = "秒杀已结束"
                       }
            }
            ;
            var tran = TransactionHelper.BeginTransaction();
            var secondKillCommunity = SecondKillCommoditysService.GetById(id);

            if (secondKillCommunity == null)
            {
                return(new ResultMessage()
                {
                    Code = -3, Msg = "秒杀商品不存在"
                });
            }
            if (secondKillCommunity.surplusNum <= 0)
            {
                return new ResultMessage()
                       {
                           Code = -3, Msg = "已买完"
                       }
            }
            ;


            try
            {
                secondKillCommunity.surplusNum -= 1;

                secondKillCommunity.payNum += 1;
                SecondKillCommoditysService.Update(secondKillCommunity);
                decimal amount = 0;
                decimal point  = 0;
                ///订单
                Order  model       = new Order();
                string dateTime    = string.Format("{0:yyyyMMddHHmmssffff}", DateTime.Now);
                var    GetUserInfo = MembershipService.GetUserById(userId);
                if (GetUserInfo != null)
                {
                    //accountId = GetUserInfo.accountId;
                    ///订单
                    model.orderNo = dateTime + userId;
                }
                //bool isFirs = false;
                //var Firs = OrderService.MicroMallQuery(new MicroMallOrderRequest() { PageSize = 1, UserId = GetUserInfo.UserId });
                //if (Firs == null || Firs.ModelList == null || Firs.ModelList.Count <= 0)
                //    isFirs = true;
                ///订单详情
                var commodity = JuMeiMallService.GetById(secondKillCommunity.commodityId);
                if (commodity == null)
                {
                    return new ResultMessage()
                           {
                               Code = -1, Msg = "商品不存在,请重新下订单!"
                           }
                }
                ;
                if (commodity.commodityState == CommodityStates.soldOut)
                {
                    return new ResultMessage()
                           {
                               Code = -1, Msg = "商品已下架,请重新下订单!"
                           }
                }
                ;
                if (commodity != null)
                {
                    var orderDetail = new OrderDetail();

                    orderDetail.commodityId   = commodity.commodityId;
                    orderDetail.commodityName = commodity.commodityName;
                    orderDetail.orderNo       = model.orderNo;
                    orderDetail.price         = secondKillCommunity.price;
                    orderDetail.quantity      = 1;
                    //orderDetail.specification = Specification;
                    orderDetail.point  = 0;// commodity.commodityJifen;
                    orderDetail.amount = secondKillCommunity.price;
                    amount            += orderDetail.price * orderDetail.quantity;
                    //point += orderDetail.point * orderDetail.quantity;
                    ///插入订单详情
                    OrderDetailService.Insert(orderDetail);
                }

                //运费
                model.freight = commodity.commodityFreight;

                //商品库存减少
                //commodity.commodityInventory = commodity.commodityInventory - quantity;
                commodity.sellQuantity  = commodity.sellQuantity + 1;
                commodity.sellQuantity1 = commodity.sellQuantity1 + 1;
                JuMeiMallService.Update(commodity);
                //订单
                model.orderState = OrderStates.awaitPay;
                model.payState   = PayStates.non_payment;
                model.submitTime = DateTime.Now;
                model.orderType  = OrderType.secondKill;
                //model.distributionType = DistributionWay.kuaidi;
                model.userId = userId;
                //model.distributionstate = DistributionStates.unfilled;
                model.amount    = amount;
                model.point     = point;
                model.payAmount = 0;
                model.IsFirs    = false;
                //用户地址首次为空,待用户选择provinceId,cityId,detailedAddress


                model.orderId = OrderService.Insert(model);

                var GetOrderService = OrderService.GetByOrderNo(model.orderNo);
                if (GetOrderService != null)
                {
                    var UpdDtl = OrderDetailService.GetByOrderNo(model.orderNo);
                    if (UpdDtl != null)
                    {
                        OrderDetailService.UpdateOrderDetailOrderId(GetOrderService.item.orderId, model.orderNo);
                    }
                }
                //if (!string.IsNullOrWhiteSpace(GetUserInfo))
                //{
                //    var message = new Fz_Messages();
                //    message.accountId = GetUserInfo.accountId;
                //    message.openId = GetUserInfo.openID;
                //    message.state = MessagesState.staySend;
                //    message.submitTime = DateTime.Now;
                //    message.keyword1 = model.orderNo;
                //    message.keyword2 = "等待付款";
                //    message.msgType = MsgType.orderState;
                //    IMessagesService.Insert(message);
                //}
                tran.Commit();
                // RebateService.Rebate2(model.orderId);
                return(new ResultMessage()
                {
                    Code = 0, Msg = model.orderNo
                });
            }
            catch (Exception ex)
            {
                logService.Insert(ex);
                return(new ResultMessage()
                {
                    Code = -1, Msg = "生成订单失败!请稍后再试"
                });
            }
            finally { tran.Dispose(); }
        }
    }
}