Пример #1
0
        public void handler(IResponder responder)
        {
            Bookingshop bookingshop = new Bookingshop();

            bookingshop.Bookingid   = SJSRequest.GetInt("Bookingid", 0);
            bookingshop.Bookingname = SJSRequest.GetString("Bookingname");
            bookingshop.Shopid      = SJSRequest.GetInt("Shopid", 0);
            bookingshop.Shopname    = SJSRequest.GetString("Shopname");
            bookingshop.Uid         = PageUtils.AccountID;
            bookingshop.Realname    = PageUtils.RealName.Trim();
            bookingshop.Isover      = false;
            //bookingshop.Begintime = DateTime.Now;// DateTime.UtcNow;

            if (bookingshop.Bookingid <= 0)
            {
                responder.WriteErroredMsg("预订参数错误!");
                return;
            }

            if (bookingshop.Shopid <= 0)
            {
                responder.WriteErroredMsg("店铺参数错误!");
                return;
            }

            Booking booking = BookingManager.GetBooking(bookingshop.Bookingid);

            if (booking == null)
            {
                responder.WriteErroredMsg("此预订不存在,无法加入!");
                return;
            }

            if (booking.Isbooking == false)
            {
                responder.WriteErroredMsg("此预订已结束,无法加入!");
                return;
            }

            Bookingshop confirm = BookingshopManager.GetBookingshop(bookingshop.Bookingid, bookingshop.Shopid, bookingshop.Uid);

            if (confirm != null)
            {
                responder.WriteErroredMsg("此店铺已存在于" + bookingshop.Bookingname + "的店铺列表,无法再次加入预订!");
                return;
            }

            bookingshop.Begintime = booking.Bookingtime;

            int rlt = BookingshopManager.AddBookingshop(bookingshop);

            if (rlt <= 0)
            {
                responder.WriteErroredMsg("店铺预订加入失败,数据库写入不成功!");
                return;
            }

            responder.WriteSuccessedMsg("加入预订成功!");
        }
Пример #2
0
        public static Bookingshop GetBookingshop(int id)
        {
            IDataReader reader = DatabaseProvider.GetInstance().GetBookingshop(id);

            Bookingshop model = null;

            if (reader.Read())
            {
                model = GetBookingshop(reader);
            }

            reader.Close();
            return(model);
        }
Пример #3
0
        public static IList <Bookingshop> GetBookingshop(DateTime specifiedDate, int uid)
        {
            IDataReader reader = DatabaseProvider.GetInstance().GetBookingshop(specifiedDate, uid);

            IList <Bookingshop> list = new List <Bookingshop>();

            while (reader.Read())
            {
                Bookingshop model = GetBookingshop(reader);

                list.Add(model);
            }

            reader.Close();
            return(list);
        }
Пример #4
0
        public static IList <Bookingshop> GetBookingshop(int bookingId, int uid, bool notUseThisParam)
        {
            IDataReader reader = DatabaseProvider.GetInstance().GetBookingshop(bookingId, uid, notUseThisParam);

            IList <Bookingshop> list = new List <Bookingshop>();

            while (reader.Read())
            {
                Bookingshop model = GetBookingshop(reader);

                list.Add(model);
            }

            reader.Close();
            return(list);
        }
Пример #5
0
        public static IList <Bookingshop> GetBookingshop(DateTime minDate, bool isOver)
        {
            IDataReader reader = DatabaseProvider.GetInstance().GetBookingshop(minDate, isOver);

            IList <Bookingshop> list = new List <Bookingshop>();

            while (reader.Read())
            {
                Bookingshop model = GetBookingshop(reader);

                list.Add(model);
            }

            reader.Close();
            return(list);
        }
Пример #6
0
        public static IList <Bookingshop> GetBookingshop(int pageSize, int currentPage)
        {
            IDataReader reader = DatabaseProvider.GetInstance().GetBookingshop(pageSize, currentPage);

            IList <Bookingshop> list = new List <Bookingshop>();

            while (reader.Read())
            {
                Bookingshop model = GetBookingshop(reader);

                list.Add(model);
            }

            reader.Close();
            return(list);
        }
Пример #7
0
        public static Bookingshop GetBookingshop(IDataReader reader)
        {
            Bookingshop model = new Bookingshop();

            model.Id          = (reader["Id"] is DBNull ? Convert.ToInt32("0") : Convert.ToInt32(reader["Id"]));
            model.Bookingid   = (reader["Bookingid"] is DBNull ? Convert.ToInt32("0") : Convert.ToInt32(reader["Bookingid"]));
            model.Bookingname = reader["Bookingname"].ToString();
            model.Uid         = (reader["Uid"] is DBNull ? Convert.ToInt32("0") : Convert.ToInt32(reader["Uid"]));
            model.Realname    = reader["Realname"].ToString();
            model.Shopid      = (reader["Shopid"] is DBNull ? Convert.ToInt32("0") : Convert.ToInt32(reader["Shopid"]));
            model.Shopname    = reader["Shopname"].ToString();
            model.Begintime   = (reader["Begintime"] is DBNull ? Convert.ToDateTime("1900-01-01") : Convert.ToDateTime(reader["Begintime"]));
            model.Isover      = (reader["Isover"] is DBNull ? Convert.ToBoolean("false") : Convert.ToBoolean(reader["Isover"]));


            return(model);
        }
Пример #8
0
        public int UpdateBookingshop(Bookingshop bookingshop)
        {
            string cmdText = "UPDATE BookingShop SET bookingid=@bookingid, bookingname=@bookingname, uid=@uid, realname=@realname, shopid=@shopid, shopname=@shopname, isover=@isover WHERE id=@id";

            DbParameter[] cmdParameters =
            {
                DbHelper.MakeInParam("@id",          (DbType)SqlDbType.Int,    0, bookingshop.Id) /**/,
                DbHelper.MakeInParam("@bookingid",   (DbType)SqlDbType.Int,    0, bookingshop.Bookingid) /**/,
                DbHelper.MakeInParam("@bookingname", (DbType)SqlDbType.NChar, 20, bookingshop.Bookingname) /**/,
                DbHelper.MakeInParam("@uid",         (DbType)SqlDbType.Int,    0, bookingshop.Uid) /**/,
                DbHelper.MakeInParam("@realname",    (DbType)SqlDbType.NChar, 10, bookingshop.Realname) /**/,
                DbHelper.MakeInParam("@shopid",      (DbType)SqlDbType.Int,    0, bookingshop.Shopid) /**/,
                DbHelper.MakeInParam("@shopname",    (DbType)SqlDbType.NChar, 20, bookingshop.Shopname) /**/,
                DbHelper.MakeInParam("@isover",      (DbType)SqlDbType.Bit,    0, bookingshop.Isover)                        /**/
            };

            return(DbHelper.ExecuteNonQuery(CommandType.Text, cmdText, cmdParameters));
        }
Пример #9
0
        public int AddBookingshop(Bookingshop bookingshop)
        {
            string cmdText = "INSERT INTO BookingShop(bookingid,bookingname,uid,realname,shopid,shopname,begintime,isover)VALUES(@bookingid,@bookingname,@uid,@realname,@shopid,@shopname,@begintime,@isover);SELECT @@identity";

            DbParameter[] cmdParameters =
            {
                DbHelper.MakeInParam("@bookingid",   (DbType)SqlDbType.Int,       0, bookingshop.Bookingid) /**/,
                DbHelper.MakeInParam("@bookingname", (DbType)SqlDbType.NChar,    20, bookingshop.Bookingname) /**/,
                DbHelper.MakeInParam("@uid",         (DbType)SqlDbType.Int,       0, bookingshop.Uid) /**/,
                DbHelper.MakeInParam("@realname",    (DbType)SqlDbType.NChar,    10, bookingshop.Realname) /**/,
                DbHelper.MakeInParam("@shopid",      (DbType)SqlDbType.Int,       0, bookingshop.Shopid) /**/,
                DbHelper.MakeInParam("@shopname",    (DbType)SqlDbType.NChar,    20, bookingshop.Shopname) /**/,
                DbHelper.MakeInParam("@begintime",   (DbType)SqlDbType.DateTime,  0, bookingshop.Begintime) /**/,
                DbHelper.MakeInParam("@isover",      (DbType)SqlDbType.Bit,       0, bookingshop.Isover)                     /**/
            };

            string s = DbHelper.ExecuteScalar(CommandType.Text, cmdText, cmdParameters).ToString();
            int    i = (string.IsNullOrEmpty(s) ? 0 : int.Parse(s));

            return(i);
        }
Пример #10
0
 /// <summary>
 /// 修改方法
 /// </summary>
 public static int UpdateBookingshop(Bookingshop bookingshop)
 {
     return(DatabaseProvider.GetInstance().UpdateBookingshop(bookingshop));
 }
Пример #11
0
        public void handler(IResponder responder)
        {
            int          withUid      = SJSRequest.GetInt("WithUid", 0);
            Bookingtrade bookingtrade = new Bookingtrade();

            bookingtrade.Tradeid       = SJSRequest.GetInt("Tradeid", 0);
            bookingtrade.Bookingshopid = SJSRequest.GetInt("Id", 0);
            bookingtrade.Tradecount    = SJSRequest.GetInt("Tradecount", 0);
            //bookingtrade.Remarks = SJSRequest.GetString("Remarks");

            if (bookingtrade.Tradecount <= 0)
            {
                responder.WriteErroredMsg("预订数量只能是正数!");
                return;
            }

            if (bookingtrade.Tradeid <= 0)
            {
                responder.WriteErroredMsg("菜单项请求参数错误!");
                return;
            }

            if (bookingtrade.Bookingshopid <= 0)
            {
                responder.WriteErroredMsg("预订店铺记录请求参数错误!");
                return;
            }

            Bookingshop bookingshop = BookingshopManager.GetBookingshop(bookingtrade.Bookingshopid);

            if (bookingshop == null)
            {
                responder.WriteErroredMsg("此店铺接受预订记录不存在,无法预订!");
                return;
            }

            Booking booking = BookingManager.GetBooking(bookingshop.Bookingid);

            if (booking == null)
            {
                responder.WriteErroredMsg("此预订不存在,无法预订!");
                return;
            }

            if (booking.Isbooking == false && User.IsAdministrator(PageUtils.Utype) == false)
            {
                responder.WriteErroredMsg("此预订已结束,无法预订!");
                return;
            }

            Trade trade = TradeManager.GetTrade(bookingtrade.Tradeid);

            if (trade == null)
            {
                responder.WriteErroredMsg("不存在此菜单项,无法预订!");
                return;
            }

            IList <Bookingtrade> confirmList = BookingtradeManager.GetBookingtrade(bookingshop.Id, trade.Id, true);

            Bookingtrade confirm = null;

            int    uid   = PageUtils.AccountID;
            string rname = PageUtils.RealName;

            for (int i = 0; i < confirmList.Count; i++)
            {
                if (withUid > 0 && withUid == confirmList[i].Uid)
                {
                    confirm = confirmList[i];
                    break;
                }

                if (withUid <= 0 && uid == confirmList[i].Uid)
                {
                    confirm = confirmList[i];
                    break;
                }
            }

            int  rlt   = 0;
            bool isAdd = false;

            using (DbTransaction trans = DbHelper.BeginTransaction())
            {
                bool writeError = false;
                try
                {
                    User      user       = null;
                    Deduction deduction  = new Deduction();
                    int       addedCount = 0;
                    if (confirm != null && (withUid <= 0 || withUid == confirm.Uid))
                    {
                        addedCount = bookingtrade.Tradecount;

                        user = UserManager.GetUser(confirm.Uid, trans);

                        if (user == null)
                        {
                            writeError = true;
                            trans.Rollback();
                            responder.WriteErroredMsg("不存在此用户,无法预订!");
                            return;
                        }


                        if (user.Enabled == false)
                        {
                            writeError = true;
                            trans.Rollback();
                            responder.WriteErroredMsg(user.Realname + " 处于禁用状态,无法预订!");
                            return;
                        }


                        uid   = user.Uid;
                        rname = user.Realname;

                        deduction.Deductionbalance = user.Balance - confirm.Tradevalue * addedCount;
                        deduction.Deductioncount   = addedCount;
                        deduction.Deductionname    = string.Format("预订{0}", confirm.Tradename);
                        deduction.Deductiontime    = DateTime.Now;
                        deduction.Deductionvalue   = -confirm.Tradevalue * addedCount;
                        deduction.Uid      = confirm.Uid;
                        deduction.Realname = confirm.Realname;
                        deduction.Shopid   = confirm.Shopid;
                        deduction.Shopname = confirm.Shopname;
                        deduction.Remarks  = confirm.Remarks;

                        confirm.Tradecount += addedCount;
                        bookingtrade        = confirm;

                        isAdd = false;
                    }
                    else
                    {
                        if (withUid > 0 && uid != withUid)
                        {
                            user = UserManager.GetUser(withUid, trans);
                        }
                        else
                        {
                            user = UserManager.GetUser(uid, trans);
                        }

                        if (user == null)
                        {
                            writeError = true;
                            trans.Rollback();
                            responder.WriteErroredMsg("不存在此用户,无法预订!");
                            return;
                        }


                        if (user.Enabled == false)
                        {
                            writeError = true;
                            trans.Rollback();
                            responder.WriteErroredMsg(user.Realname + " 处于禁用状态,无法预订!");
                            return;
                        }


                        if (withUid > 0)
                        {
                            bookingtrade.Proxyid   = uid;
                            bookingtrade.Proxyname = rname;
                            bookingtrade.Remarks  += string.Format("由 {0} 代订", rname.Trim());
                        }

                        uid   = user.Uid;
                        rname = user.Realname;

                        bookingtrade.Bookingid   = booking.Id;
                        bookingtrade.Bookingname = booking.Bookingname;
                        bookingtrade.Handlerid   = bookingshop.Uid;
                        bookingtrade.Handlername = bookingshop.Realname;
                        bookingtrade.Uid         = uid;
                        bookingtrade.Realname    = rname;
                        bookingtrade.Shopid      = bookingshop.Shopid;
                        bookingtrade.Shopname    = bookingshop.Shopname;
                        bookingtrade.Tradename   = trade.Tradename;
                        bookingtrade.Tradevalue  = trade.Tradevalue;
                        bookingtrade.Issettle    = booking.Isbooking == false;
                        bookingtrade.Bookinttime = DateTime.Now;

                        if (booking.Bookingtime.Date.Equals(DateTime.Now.Date) == false)
                        {
                            bookingtrade.Bookinttime = new DateTime(booking.Bookingtime.Date.Ticks);
                            bookingtrade.Bookinttime = bookingtrade.Bookinttime.AddHours(DateTime.Now.Hour).AddMinutes(DateTime.Now.Minute).AddSeconds(DateTime.Now.Second);
                        }

                        addedCount = bookingtrade.Tradecount;
                        deduction.Deductionbalance = user.Balance - trade.Tradevalue * addedCount;
                        deduction.Deductioncount   = addedCount;
                        deduction.Deductionname    = string.Format("预订{0}", bookingtrade.Tradename);
                        deduction.Deductiontime    = DateTime.Now;
                        deduction.Deductionvalue   = -bookingtrade.Tradevalue * addedCount;
                        deduction.Uid      = bookingtrade.Uid;
                        deduction.Realname = bookingtrade.Realname;
                        deduction.Shopid   = bookingtrade.Shopid;
                        deduction.Shopname = bookingtrade.Shopname;
                        deduction.Remarks  = bookingtrade.Remarks;

                        isAdd = true;
                    }

                    rlt = UserManager.UpdateUserBalance(uid, trade.Tradevalue * addedCount, trans);
                    if (rlt <= 0)
                    {
                        writeError = true;
                        trans.Rollback();
                        responder.WriteErroredMsg("扣除余额失败,数据库更新不成功!");
                        return;
                    }

                    rlt = DeductionManager.AddDeduction(deduction, trans);
                    if (rlt <= 0)
                    {
                        writeError = true;
                        trans.Rollback();
                        responder.WriteErroredMsg("扣款记录失败,数据库写入不成功!");
                        return;
                    }

                    if (isAdd)
                    {
                        rlt = BookingtradeManager.AddBookingtrade(bookingtrade, trans);
                    }
                    else
                    {
                        rlt = BookingtradeManager.UpdateBookingtrade(bookingtrade, trans);
                    }

                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    if (writeError == false)
                    {
                        responder.WriteErroredMsg("预订失败,程序异常!");
                    }
                    return;
                }
            }

            if (rlt <= 0)
            {
                if (isAdd)
                {
                    responder.WriteErroredMsg("预订失败,数据库写入不成功!");
                }
                else
                {
                    responder.WriteErroredMsg("预订失败,数据库更新不成功!");
                }

                return;
            }

            if (isAdd)
            {
                responder.WriteSuccessedMsg("提交成功,预订项已添加!");
            }
            else
            {
                responder.WriteSuccessedMsg("提交成功,预订项已更新!");
            }
        }
Пример #12
0
        public void handler(IResponder responder)
        {
            int id = SJSRequest.GetInt("Id", 0);

            if (id <= 0)
            {
                responder.WriteErroredMsg("请求参数错误!");
                return;
            }

            Bookingshop bookingshop = BookingshopManager.GetBookingshop(id);

            if (bookingshop == null)
            {
                responder.WriteErroredMsg("接受预订的店铺列表不存在此店铺,无法删除!");
                return;
            }

            Booking booking = BookingManager.GetBooking(bookingshop.Bookingid);

            if (booking != null)
            {
                if (booking.Isbooking == false)
                {
                    responder.WriteErroredMsg("此预订已结束,无法删除!");
                    return;
                }
            }

            if (bookingshop.Uid != PageUtils.AccountID)
            {
                responder.WriteErroredMsg("店铺删除失败,不是本人开启的预订没有权限进行此操作!");
                return;
            }

            using (DbTransaction trans = DbHelper.BeginTransaction())
            {
                bool writeError = false;
                try
                {
                    int rlt = BookingshopManager.DelBookingshop(id, trans);
                    if (rlt <= 0)
                    {
                        writeError = true;
                        trans.Rollback();
                        responder.WriteErroredMsg("店铺删除失败,数据库更新不成功!");
                        return;
                    }

                    IList <Bookingtrade> list = BookingtradeManager.GetBookingtrade(id, trans);

                    foreach (Bookingtrade item in list)
                    {
                        User user = UserManager.GetUser(item.Uid, trans);
                        user.Balance = user.Balance + item.Tradevalue * item.Tradecount;

                        rlt = UserManager.UpdateUserBalance(item.Uid, -item.Tradevalue * item.Tradecount, trans);
                        if (rlt <= 0)
                        {
                            writeError = true;
                            trans.Rollback();
                            responder.WriteErroredMsg("返还余额失败,数据库更新不成功!");
                            return;
                        }

                        Deduction deduction = new Deduction();
                        deduction.Deductionbalance = user.Balance;
                        deduction.Deductioncount   = -item.Tradecount;
                        deduction.Deductionname    = string.Format("退订{0}(删除接受预订的店铺)", item.Tradename);
                        deduction.Deductiontime    = DateTime.Now;
                        deduction.Deductionvalue   = item.Tradevalue * item.Tradecount;
                        deduction.Uid      = item.Uid;
                        deduction.Realname = item.Realname;
                        deduction.Shopid   = item.Shopid;
                        deduction.Shopname = item.Shopname;
                        deduction.Remarks  = item.Remarks;

                        rlt = DeductionManager.AddDeduction(deduction, trans);

                        if (rlt <= 0)
                        {
                            writeError = true;
                            trans.Rollback();
                            responder.WriteErroredMsg("扣款记录失败,数据库写入不成功!");
                            return;
                        }

                        rlt = BookingtradeManager.DelBookingtrade(item.Id, trans);
                        if (rlt <= 0)
                        {
                            writeError = true;
                            trans.Rollback();
                            responder.WriteErroredMsg("删除已预订列表失败,数据库更新不成功!");
                            return;
                        }
                    }

                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    if (writeError == false)
                    {
                        responder.WriteErroredMsg("删除失败,程序异常!");
                    }
                    return;
                }
            }
            responder.WriteSuccessedMsg("店铺和预订此店铺的记录删除成功!");
        }