public int BookOk(int bid)
        {
            try
            {
                HQ_BookRoom book = new HQ_BookRoom();
                book["id"] = bid;
                book.OStatus = 1;
                book.LastOperateTime = DateTime.Now;
                book.Save();
            }
            catch
            {
                return 0;
            }

            try
            {
                SearchModel sm = new SearchModel("uv_bookroom");
                sm["id"] = bid;
                sm.AddSearch("RoomName_G", "PhoneNum_G");
                var broom = sm.LoadEntity<HQ_BookRoom>();
                if (broom != null)
                {
                    NM.Util.SendUserInfo _U = new NM.Util.SendUserInfo() { isLog = 1, orgid = 555, username = broom.PhoneNum_G };
                    NM.Util.MsgSend.DirectSend(string.Format("尊敬的会员您好,您已成功预订 {0} 。", broom.RoomName_G), broom.PhoneNum_G, _U);
                }
            }
            catch { }

            return 1;
        }
 public int BookNo(int bid, string remark)
 {
     try
     {
         HQ_BookRoom book = new HQ_BookRoom();
         book["id"] = bid;
         book.OStatus = 2;
         book.Remark = remark;
         book.LastOperateTime = DateTime.Now;
         book.Save();
         return 1;
     }
     catch
     {
         return 0;
     }
 }
        public int Pay(int bid)
        {
            try
            {
                int shopUserId = 0;
                decimal balance = 0;
                string phoneNum = null;
                decimal cost = 0;
                var isMoneyEnough = WebSite.Controllers.MemberController.IsMoneyEnouth(bid, out balance, out shopUserId, out phoneNum, out cost);

                if (isMoneyEnough == -1)//余额不足
                {
                    return -1;
                }
                else if (isMoneyEnough == 0)//检查失败
                {
                    return 0;
                }

                using (var scope = new TransactionScope())
                {
                    var updateBRoom = new HQ_BookRoom();
                    updateBRoom["id"] = bid;
                    updateBRoom.OStatus = 3;
                    updateBRoom.LastOperateTime = DateTime.Now;
                    updateBRoom.Save();

                    #region 更改余额

                    Shop_Accounts_UsersExp uexp = new Shop_Accounts_UsersExp();
                    uexp["UserID"] = shopUserId;
                    uexp["Balance"] = balance;
                    uexp.Save();

                    #endregion

                    #region 记录扣款记录

                    Shop_Pay_BalanceDetails detail = new Shop_Pay_BalanceDetails();
                    detail.UserId = shopUserId;
                    detail.TradeDate = DateTime.Now;
                    detail.TradeType = 2;
                    detail.Expenses = cost;
                    detail.Balance = balance;
                    detail.Remark = "订房扣款";
                    detail.Save();

                    #endregion

                    scope.Complete();
                }

                try
                {
                    if (balance < 500)
                    {
                        NM.Util.SendUserInfo _U = new NM.Util.SendUserInfo() { isLog = 1, orgid = 555, username = phoneNum };
                        NM.Util.MsgSend.DirectSend("尊敬的会员您好,您的账户余额已不足500元,为不影响您度假旅行,请及时充值。", phoneNum, _U);
                    }
                }
                catch { }

                return 1;
            }
            catch
            {
                return 0;
            }
        }
 public long SaveBRoomRemark(HQ_BookRoom broom)
 {
     return broom.Save();
 }
 public int DeleteOrder(int orderid)
 {
     try
     {
         HQ_BookRoom broom = new HQ_BookRoom();
         broom["id"] = orderid;
         broom.OStatus = (int)EnumOrderState.Deleted;
         broom.Save();
     }
     catch
     {
         return 0;
     }
     return 1;
 }
        public long CancelBook(HQ_BookRoom broom)
        {
            var sm = new SearchModel("hq_bookroom");
            //var sm = new SearchModel("uv_bookroom");
            sm["id"] = broom.ID;
            var room = sm.LoadEntity<HQ_BookRoom>();
            if (room.OStatus == 0 || room.CanCancelBook_G == 1)
            {
                #region NoUse

                //sm = new SearchModel("uv_MemberWithAmount");
                //sm["id"] = room.MemberID;
                //sm.AddSearch("ShopUserID_G", "Balance_G");
                //var member = sm.LoadEntity<HQ_Member>();
                //if (member == null)
                //{
                //    return 0;
                //}
                //var toBalance = member.Balance_G + room.AllPrice_G;

                //using (TransactionScope scope = new TransactionScope())
                //{
                //    broom.OStatus = 4;
                //    broom.Save();

                //    //扣款后不能退订,所以退订时不会涉及用户金额问题
                //    //Shop_Accounts_UsersExp uexp = new Shop_Accounts_UsersExp();
                //    //uexp["UserID"] = member.ShopUserID_G;
                //    //uexp["Balance"] = toBalance;
                //    //uexp.Save();

                //    scope.Complete();
                //    return 1;
                //}

                #endregion

                broom.OStatus = 4;
                broom.LastOperateTime = DateTime.Now;
                broom.Save();
                return 1;
            }
            return -1;
        }
        public long BookRoom(int roomid, DateTime sdate, DateTime edate, string remark, long? userid)
        {
            if (userid == null && !LoginVerify.IsLogin("Client"))
            {
                return -1;//未登录
            }

            if (userid == null)
            {
                userid = LoginInfo.Current.UserID;
            }

            lock (_object)
            {
                if (IsRoomEnough(roomid, sdate, edate) <= 0)
                {
                    return -2;//房间数量不足
                }

                decimal balance = 0;
                int shopUserId = 0;
                string phoneNum = null;
                decimal cost = 0;
                decimal price = 0;
                var r = IsMoneyEnouth(roomid, userid.Value, sdate, edate, out balance, out shopUserId, out phoneNum, out cost, out price);
                if (r == 0)
                {
                    return 0;//预订日期填写错误
                }

                if (r == -1)
                {
                    return -3;//余额不足
                }

                HQ_BookRoom entity = new HQ_BookRoom();
                entity.MemberID = (int)userid.Value;
                entity.RoomID = roomid;
                entity.BookStartTime = sdate;
                entity.BookEndTime = edate;
                entity.OStatus = 0;
                var nowTime = DateTime.Now;
                entity.CreateOn = nowTime;
                entity.LastOperateTime = nowTime;
                entity.Price = (int)price;
                if (remark != null && remark.Length > 0)
                {
                    entity.Remark = remark;
                }

                try
                {
                    using (TransactionScope scope = new TransactionScope())
                    {
                        entity.Save();

                        //预订时不扣款
                        //Shop_Accounts_UsersExp uexp = new Shop_Accounts_UsersExp();
                        //uexp["UserID"] = shopUserId;
                        //uexp["Balance"] = balance;
                        //uexp.Save();

                        scope.Complete();
                    }
                }
                catch (Exception ex)
                {
                    return 0;
                }
                return 1;
            }
        }
 public void CancelBook(HQ_BookRoom broom)
 {
     MemberController controller = new MemberController();
     var r = controller.CancelBook(broom);
     OutResult(r);
 }
 public void UpdateOrderRemark(int orderid, string remark)
 {
     MemberController controller = new MemberController();
     var order = new HQ_BookRoom();
     order["ID"] = orderid;
     order.Remark = remark;
     var r = controller.SaveBRoomRemark(order);
     OutResult(r);
 }