Ejemplo n.º 1
0
        public static bool CreatOrder(List <OrderInfo> orderInfos)
        {
            if (orderInfos.Count <= 0)
            {
                return(false);
            }
            bool     result   = false;
            Database database = DatabaseFactory.CreateDatabase();

            using (DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    foreach (OrderInfo orderInfo in orderInfos)
                    {
                        if (orderInfo == null)
                        {
                            dbTransaction.Rollback();
                            return(false);
                        }
                        ShoppingProcessor.MoveOrderItemImages(orderInfo);
                        OrderDao orderDao = new OrderDao();
                        if (orderInfo.CountDownBuyId > 0)
                        {
                            orderInfo.OrderType = OrderType.CountDown;
                            if (orderDao.ExistCountDownOverbBought(orderInfo, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                return(false);
                            }
                            if (!orderDao.UpdateCountDownBuyNum(orderInfo, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                return(false);
                            }
                        }
                        if (orderInfo.FightGroupActivityId > 0)
                        {
                            orderInfo.OrderType = OrderType.FightGroup;
                            if (!ShoppingProcessor.ManageFightGroupOrder(orderInfo, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                return(false);
                            }
                        }
                        if (orderInfo.PreSaleId > 0)
                        {
                            orderInfo.OrderType = OrderType.PreSale;
                        }
                        if (orderInfo.GroupBuyId > 0)
                        {
                            orderInfo.OrderType = OrderType.GroupOrder;
                        }
                        if (!orderDao.CreatOrder(orderInfo, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            return(false);
                        }
                        if (orderInfo.LineItems.Count > 0 && orderInfo.ParentOrderId != "-1" && !new LineItemDao().AddOrderLineItems(orderInfo.OrderId, orderInfo.LineItems.Values, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            return(false);
                        }
                        if (orderInfo.Gifts.Count > 0)
                        {
                            OrderGiftDao orderGiftDao = new OrderGiftDao();
                            if (!orderGiftDao.AddOrderGift(orderInfo.OrderId, orderInfo.Gifts, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                return(false);
                            }
                        }
                        if (orderInfo.InputItems != null && orderInfo.InputItems.Count > 0 && !new OrderInputItemDao().AddItems(orderInfo.OrderId, orderInfo.InputItems, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            return(false);
                        }
                        if (orderInfo.ParentOrderId == "0" || orderInfo.ParentOrderId == "-1")
                        {
                            if (!string.IsNullOrEmpty(orderInfo.CouponCode) && !new CouponDao().AddCouponUseRecord(orderInfo, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                return(false);
                            }
                            if (orderInfo.DeductionPoints.HasValue && orderInfo.DeductionPoints > 0 && !ShoppingProcessor.CutNeedPoint(orderInfo.DeductionPoints.Value, orderInfo.OrderId, PointTradeType.ShoppingDeduction, orderInfo.UserId))
                            {
                                dbTransaction.Rollback();
                                return(false);
                            }
                        }
                    }
                    dbTransaction.Commit();
                    result = true;
                }
                catch (Exception ex)
                {
                    result = false;
                    Globals.WriteExceptionLog(ex, null, "OrderCreate");
                    dbTransaction.Rollback();
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        public static bool CreatOrder(OrderInfo orderInfo)
        {
            bool     flag     = false;
            Database database = DatabaseFactory.CreateDatabase();
            int      quantity = orderInfo.LineItems.Sum <KeyValuePair <string, LineItemInfo> >((Func <KeyValuePair <string, LineItemInfo>, int>)(item => item.Value.Quantity));

            lock (createOrderLocker)
            {
                if (orderInfo.GroupBuyId > 0)
                {
                    checkCanGroupBuy(quantity, orderInfo.GroupBuyId);
                }
                using (DbConnection connection = database.CreateConnection())
                {
                    connection.Open();
                    DbTransaction dbTran = connection.BeginTransaction();

                    try
                    {
                        //WriteLog(orderInfo == null ? "orderinfo空" : "不为空");
                        if (string.IsNullOrEmpty(orderInfo.OrderId))
                        {
                            orderInfo.OrderId = GenerateOrderIdByOrder(0, dbTran);
                        }

                        if (!new OrderDao().CreatOrder(orderInfo, dbTran))
                        {
                            dbTran.Rollback();
                            return(false);
                        }
                        if ((orderInfo.LineItems.Count > 0) && !new LineItemDao().AddOrderLineItems(orderInfo.OrderId, orderInfo.LineItems.Values, dbTran))
                        {
                            dbTran.Rollback();
                            return(false);
                        }
                        //如果有礼品,添加到礼品表
                        //add@20150921 by hj
                        if (orderInfo.Gifts.Count > 0)
                        {
                            OrderGiftDao dao = new OrderGiftDao();
                            foreach (OrderGiftInfo info in orderInfo.Gifts)
                            {
                                if (!dao.AddOrderGift(orderInfo.OrderId, info, 0, dbTran))
                                {
                                    dbTran.Rollback();
                                    return(false);
                                }
                            }
                        }

                        if (!string.IsNullOrEmpty(orderInfo.CouponCode) && !new CouponDao().AddCouponUseRecord(orderInfo, dbTran))
                        {
                            dbTran.Rollback();
                            return(false);
                        }
                        //代金券功能目前不使用,redpagerId字段废除,用迪蔓的新规则:选择服务天使门店id代替

                        /*
                         * if ((orderInfo.RedPagerID > 0) && !new UserRedPagerDao().AddUserRedPagerRecord(orderInfo, dbTran))
                         * {
                         *  dbTran.Rollback();
                         *  return false;
                         * }
                         */
                        if (orderInfo.GroupBuyId > 0)
                        {
                            GroupBuyDao  dao      = new GroupBuyDao();
                            GroupBuyInfo groupBuy = dao.GetGroupBuy(orderInfo.GroupBuyId, dbTran);
                            groupBuy.SoldCount += quantity;
                            dao.UpdateGroupBuy(groupBuy, dbTran);
                            dao.RefreshGroupBuyFinishState(orderInfo.GroupBuyId, dbTran);
                        }
                        dbTran.Commit();
                        flag = true;
                    }
                    catch (Exception ex)
                    {
                        //WriteLog(ex.Message);
                        dbTran.Rollback();
                        throw;
                    }
                    finally
                    {
                        connection.Close();
                    }
                }
            }
            return(flag);
        }
Ejemplo n.º 3
0
        public static bool CreatOrder(OrderInfo orderInfo)
        {
            if (orderInfo == null)
            {
                return(false);
            }
            bool     result   = false;
            Database database = DatabaseFactory.CreateDatabase();

            using (DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    OrderDao orderDao = new OrderDao();
                    if (orderInfo.CountDownBuyId > 0)
                    {
                        orderInfo.OrderType = OrderType.CountDown;
                        if (orderDao.ExistCountDownOverbBought(orderInfo, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            return(false);
                        }
                        if (!orderDao.UpdateCountDownBuyNum(orderInfo, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            return(false);
                        }
                    }
                    if (orderInfo.FightGroupActivityId > 0)
                    {
                        orderInfo.OrderType = OrderType.FightGroup;
                        if (!ShoppingProcessor.ManageFightGroupOrder(orderInfo, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            return(false);
                        }
                    }
                    if (orderInfo.PreSaleId > 0)
                    {
                        orderInfo.OrderType = OrderType.PreSale;
                    }
                    if (orderInfo.GroupBuyId > 0)
                    {
                        orderInfo.OrderType = OrderType.GroupOrder;
                    }
                    if (!orderDao.CreatOrder(orderInfo, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        return(false);
                    }
                    if (orderInfo.LineItems.Count > 0 && !new LineItemDao().AddOrderLineItems(orderInfo.OrderId, orderInfo.LineItems.Values, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        return(false);
                    }
                    if (orderInfo.Gifts.Count > 0)
                    {
                        OrderGiftDao orderGiftDao = new OrderGiftDao();
                        if (!orderGiftDao.AddOrderGift(orderInfo.OrderId, orderInfo.Gifts, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            return(false);
                        }
                    }
                    if (!string.IsNullOrEmpty(orderInfo.CouponCode) && !new CouponDao().AddCouponUseRecord(orderInfo, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        return(false);
                    }
                    if (orderInfo.DeductionPoints.HasValue && orderInfo.DeductionPoints > 0 && !ShoppingProcessor.CutNeedPoint(orderInfo.DeductionPoints.Value, orderInfo.OrderId, PointTradeType.ShoppingDeduction, orderInfo.UserId))
                    {
                        dbTransaction.Rollback();
                        return(false);
                    }
                    dbTransaction.Commit();
                    result = true;
                }
                catch
                {
                    dbTransaction.Rollback();
                    throw;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            return(result);
        }