コード例 #1
0
        /// <summary>
        /// 新增美团订单 add by caoheyang 20150421
        /// </summary>
        /// <param name="paramodel">paraModel</param>
        public void AddOrder(CreatePM_OpenApi paramodel)
        {
            string     orderNo = Helper.generateOrderCode(paramodel.businessId);
            RedisCache redis   = new RedisCache();

            try
            {
                using (IUnitOfWork tran = EdsUtilOfWorkFactory.GetUnitOfWorkOfEDS())
                {
                    OrderDao orderDao = new OrderDao();
                    paramodel.OrderNo = orderNo;
                    //将当前订单插入到缓存中,设置过期时间30天
                    redis.Set(string.Format(RedissCacheKey.OtherOrderInfo, paramodel.orderfrom.ToString(),
                                            paramodel.order_id.ToString()), orderNo, DateTime.Now.AddDays(30)); //先加入缓存,相当于加锁
                    int orderId = orderDao.CreateToSql(paramodel);                                              //插入订单返回订单id
                    orderDao.CreateToSqlAddOrderOther(paramodel.businessId, orderId);                           //操作插入OrderOther表
                    orderDao.CreateToSqlAddOrderDetail(paramodel, orderNo);                                     //操作插入OrderDetail表
                    orderDao.CreateToSqlAddOrderChild(paramodel, orderId);                                      //插入订单子表
                    tran.Complete();
                }
            }
            catch (Exception ex)
            {
                redis.Delete(string.Format(RedissCacheKey.OtherOrderInfo, //同步失败,清除缓存内的订单信息信息
                                           paramodel.store_info.group.ToString(), paramodel.order_id.ToString()));
                throw ex;
            }
        }