Exemple #1
0
        public Order createOrder(Order order, out string Msg)
        {
            if (order.UserID != null && order.Time != null && !String.IsNullOrWhiteSpace(order.CarID))
            {
                //用户是否审核
                User user = UserDb_manager.findUserId(order.UserID);
                if (user != null)
                {
                    if (!user.UserStatus.Equals(((int)(Commons.Authentication.APPLY)).ToString()))
                    {
                        //用户未审核
                        Msg = "用户审核中,不能预约";
                        return(null);
                    }
                }
                //如果有预约订单,不能再次创建
                IList <Order> ORDER = db_manager.Select(order.UserID);
                if (ORDER.Count() > 0)
                {
                    foreach (var x in ORDER)
                    {
                        if (x.State == (int)Commons.Type.BOOK)
                        {
                            Msg = "存在已预约订单,不能重复预约";
                            return(null);
                        }
                    }
                }

                //如果用户账户余额低于500,不能租车
                if (db_manager.QueryMoney(order.UserID) < 1)
                {
                    Msg = "账户余额不足,请充值";
                    return(null);
                }

                order.ID         = OrderIdUtil.create();
                order.CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                order.State      = (int)Commons.Type.BOOK;
                //生成公私钥
                //RSAHelper.RSAKey(secKey, pubKey);
                string pubKey = null, secKey = null;
                RSAHelper.GenerateRSAKey(out secKey, out pubKey);
                order.Pubkey  = pubKey;
                order.SecKey  = secKey;
                order.Creater = Commons.orderHandler.USER.ToString();
                Car c = zsc_manager.findCarByCarId(order.CarID);
                if (c != null)
                {
                    order.TerminalId = c.TermID;
                    order.CarType    = c.CarType;
                    order.CarNo      = c.CarNo;
                }
                UserAuthorization auth = new UserAuthorization();
                auth.Id      = Guid.NewGuid().ToString().Replace("-", "");
                auth.OrderId = order.ID;
                auth.UserId  = order.UserID;
                auth.Status  = (int)Commons.Authorized.BASED;
                auth.Date    = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                //1.发送到消息队列 2.存入缓存
                // cache_manager.Create(order);
                msmq_manager.Send(order);
                msmq_manager.SendUserAuth(auth);
                string type  = null;
                string carNo = null;
                Car    CAR   = zsc_manager.findCarByCarId(order.CarID);
                if (c != null)
                {
                    type  = CAR.CarType;
                    carNo = CAR.CarNo;
                }
                Messages msg = new Messages()
                {
                    userid  = order.UserID,
                    content = new StringBuilder().
                              Append(Commons.orderMsg1)
                              .Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).
                              Append(Commons.orderMsg2).
                              Append(type).
                              Append(Commons.orderMsg3).Append(carNo).Append(Commons.orderMsg4).ToString(),
                    time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    type = Convert.ToInt32(Commons.MessagesType.serviceType).ToString()
                };
                db_manager.AddMsg(msg);
                //修改车状态
                Msg = "预约成功";
                return(order);
            }
            Msg = "预约失败";
            return(null);
        }