Ejemplo n.º 1
0
        public async Task <JsonResult> ExecuteSql(List <int> hotelIds, string sql)
        {
            StringBuilder sb = new StringBuilder();

            foreach (int id in hotelIds)
            {
                Hotel hotel = await YummyOnlineManager.GetHotelById(id);

                OriginSql      originSql = new OriginSql(hotel.AdminConnectionString);
                FunctionResult result    = await originSql.ExecuteSql(sql);

                if (!result.Succeeded)
                {
                    sb.Append($"{hotel.Name}({hotel.Id}) Error, {result.Message}</br>");
                    await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Error, $"Execute SQL {hotel.Name}({hotel.Id}) Failed",
                                                       $"Error: {result.Message}, SQL: {sql}");
                }
                else
                {
                    await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Success, $"Execute SQL {hotel.Name}({hotel.Id}) Successfully", sql);
                }
            }
            if (sb.Length != 0)
            {
                return(Json(new JsonError(sb.ToString())));
            }
            return(Json(new JsonSuccess()));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 生成短信验证码并且发送
        /// </summary>
        /// <param name="phoneNumber">手机号</param>
        /// <returns>短信验证码</returns>
        private FunctionResult generateSmsCodeAndSend(string phoneNumber)
        {
            DateTime?LastSmsDateTime = Session["LastSmsDateTime"] as DateTime?;

            if (LastSmsDateTime.HasValue && (DateTime.Now - LastSmsDateTime.Value).TotalSeconds < 50)
            {
                return(new FunctionResult(false, "您还不能发送短信验证码"));
            }

            Random rand = new Random(unchecked ((int)DateTime.Now.Ticks));
            string code = "";

            for (int i = 0; i < 6; i++)
            {
                code += rand.Next(10);
            }
            Session["LastSmsDateTime"] = DateTime.Now;

#if DEBUG
            var _ = YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Debug, phoneNumber + " : " + code);
#else
            if (!Utility.SMSSender.Send(phoneNumber, code))
            {
                return(new FunctionResult(false, "发送失败"));
            }
#endif
            return(new FunctionResult {
                Succeeded = true,
                Data = code
            });
        }
Ejemplo n.º 3
0
        public async Task <JsonResult> UpdateHotel(Hotel hotel)
        {
            await YummyOnlineManager.UpdateHotel(hotel);

            await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Warning, $"Hotel {hotel.Id} Updated");

            return(Json(new JsonSuccess()));
        }
Ejemplo n.º 4
0
        public async Task <JsonResult> DeleteAdmin(string id)
        {
            await UserManager.RemoveFromRoleAsync(id, Role.Admin);

            await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Warning, $"User {id} Removed from Admin");

            return(Json(new JsonSuccess()));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 收银员台支付
        /// </summary>
        public async Task <ActionResult> ManagerPay(Cart cart, ManagerCartAddition cartAddition)
        {
            SystemConfig system = await YummyOnlineManager.GetSystemConfig();

            if (system.Token != cartAddition.Token)
            {
                return(Json(new JsonError("身份验证失败")));
            }

            var hotel = await YummyOnlineManager.GetHotelById(cartAddition.HotelId);

            CurrHotel = new CurrHotelInfo(hotel.Id, hotel.ConnectionString);

            if (!hotel.Usable)
            {
                return(RedirectToAction("HotelUnavailable", "Error"));
            }

            cart.PayKindId = await new HotelManager(CurrHotel.ConnectionString).GetOtherPayKindId();
            CartAddition addition = new CartAddition {
                WaiterId     = cartAddition.WaiterId,
                DineType     = cartAddition.DineType,
                Discount     = cartAddition.Discount,
                DiscountName = cartAddition.DiscountName,
                GiftMenus    = cartAddition.GiftMenus,
                From         = DineFrom.Manager
            };

            User user = await UserManager.FindByIdAsync(cartAddition.UserId);

            addition.UserId = user?.Id;

            // 创建新订单
            FunctionResult result = await OrderManager.CreateDine(cart, addition);

            if (!result.Succeeded)
            {
                if (await UserManager.IsInRoleAsync(user.Id, Role.Nemo))
                {
                    await UserManager.DeleteAsync(user);

                    await YummyOnlineManager.RecordLog(YummyOnlineDAO.Models.Log.LogProgram.Identity, YummyOnlineDAO.Models.Log.LogLevel.Warning, $"Anonymous User Deleted {user.Id}, Via Manager");
                }
                await HotelManager.RecordLog(HotelDAO.Models.Log.LogLevel.Error, $"{result.Detail}, Host:{Request.UserHostAddress}", HttpPost.GetPostData(Request));

                return(Json(new JsonError(result.Message)));
            }

            Dine dine = ((Dine)result.Data);

            await newDineInform(dine, "Manager");

            return(Json(new JsonSuccess {
                Data = dine.Id
            }));
        }
Ejemplo n.º 6
0
        public async Task <JsonResult> StopSite(int siteId)
        {
            if (IISManager.StopSite(siteId))
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Warning, $"Site {IISManager.GetSiteById(siteId).Name} Stoped");

                return(Json(new JsonSuccess()));
            }
            return(Json(new JsonError("无法停止")));
        }
Ejemplo n.º 7
0
        public async Task <JsonResult> DeleteGuid(Guid guid)
        {
            if (!await YummyOnlineManager.DeleteGuid(guid))
            {
                return(Json(new JsonError()));
            }
            SystemTcpClient.SendSystemCommand(SystemCommandType.RefreshNewDineClients);
            await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Warning, $"Guid {guid} Removed");

            return(Json(new JsonSuccess()));
        }
Ejemplo n.º 8
0
        public virtual async Task <JsonResult> Signup(SignupViewModel model)
        {
            if ((string)Session["SmsCode"] != model.Code)
            {
                return(Json(new JsonError("验证码不正确", "code")));
            }
            if (model.PhoneNumber == null)
            {
                return(Json(new JsonError("手机号不能为空")));
            }
            if (model.Password == null)
            {
                return(Json(new JsonError("密码不能为空")));
            }
            if (model.Password == model.PasswordAga)
            {
                return(Json(new JsonError("密码不一致")));
            }
            User user;
            bool succeeded;

            if (await SigninManager.IsAuthenticated())
            {
                user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                user.PhoneNumber  = model.PhoneNumber;
                user.UserName     = model.PhoneNumber;
                user.PasswordHash = UserManager.GetMd5(model.Password);
                succeeded         = await UserManager.UpdateAsync(user);

                await UserManager.RemoveFromRoleAsync(user.Id, Role.Nemo);

                await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"User Update: {User.Identity.GetUserId()}");
            }
            else
            {
                user = new User {
                    PhoneNumber = model.PhoneNumber,
                    UserName    = model.PhoneNumber
                };
                succeeded = await UserManager.CreateAsync(user, model.Password);
            }

            if (!succeeded)
            {
                return(Json(new JsonError("注册失败")));
            }
            await UserManager.AddToRoleAsync(user.Id, Role.Customer);

            SigninManager.Signin(user, true);
            await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Success, $"User Signup: {user.Id} ({user.PhoneNumber})");

            return(Json(new JsonSuccess()));
        }
Ejemplo n.º 9
0
        public virtual async Task <JsonResult> Forget(ForgetViewModel model)
        {
            if (Session["SMSForgetCode"] == null || Session["SMSForgetCode"].ToString() != model.Code)
            {
                return(Json(new JsonError("验证码不正确", "code")));
            }
            await UserManager.ChangePasswordAsync(model.PhoneNumber, model.Password);

            await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"{model.PhoneNumber} {model.Password} Change Password");

            return(Json(new JsonSuccess()));
        }
Ejemplo n.º 10
0
        public async Task <JsonResult> StopTcpServer()
        {
            bool result = TcpServerProcess.StopTcpServer();

            if (result)
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Warning, "TcpServer Stoped");

                return(Json(new JsonSuccess()));
            }
            return(Json(new JsonError("关闭失败")));
        }
Ejemplo n.º 11
0
        private async Task logPartition(int?hotelId, string method)
        {
            if (hotelId.HasValue)
            {
                Hotel hotel = await YummyOnlineManager.GetHotelById(hotelId.Value);

                await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Success, $"{method} On {hotel.Name} ({hotel.Id}) Successfully");
            }
            else
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Success, $"{method} On YummyOnlineDB Successfully");
            }
        }
Ejemplo n.º 12
0
        private async Task logPartition(int?hotelId, string method, string errorMessage)
        {
            if (hotelId.HasValue)
            {
                Hotel hotel = await YummyOnlineManager.GetHotelById(hotelId.Value);

                await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Error, $"{method} On {hotel.Name} ({hotel.Id}) Failed, {errorMessage}");
            }
            else
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Error, $"{method} On YummyOnlineDB Failed, {errorMessage}");
            }
        }
Ejemplo n.º 13
0
        public async Task <JsonResult> AddGuid(Guid guid, string description)
        {
            if (!await YummyOnlineManager.AddGuid(new NewDineInformClientGuid {
                Guid = guid,
                Description = description
            }))
            {
                return(Json(new JsonError()));
            }
            SystemTcpClient.SendSystemCommand(SystemCommandType.RefreshNewDineClients);
            await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Success, $"Guid {guid} ({description}) Added");

            return(Json(new JsonSuccess()));
        }
Ejemplo n.º 14
0
        public async Task <JsonResult> Backup(bool isYummyOnline, List <int> hotelIds)
        {
            SystemConfig config = await YummyOnlineManager.GetSystemConfig();

            string path = $"{config.SpecificationDir}\\Database";

            StringBuilder sb = new StringBuilder();

            if (isYummyOnline)
            {
                OriginSql      originSql = new OriginSql(YummyOnlineManager.ConnectionString);
                FunctionResult result    = await originSql.Backup(path);

                if (!result.Succeeded)
                {
                    sb.Append($"YummyOnlineDB Error, {result.Message}</br>");
                    await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Error, "Backup YummyOnlineDB Failed", result.Message);
                }
                else
                {
                    await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Success, "Backup YummyOnlineDB Successfully");
                }
            }

            foreach (int id in hotelIds)
            {
                Hotel hotel = await YummyOnlineManager.GetHotelById(id);

                OriginSql      originSql = new OriginSql(hotel.AdminConnectionString);
                FunctionResult result    = await originSql.Backup(path);

                if (!result.Succeeded)
                {
                    sb.Append($"{hotel.Name}({hotel.Id}) Error, {result.Message}</br>");
                    await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Error, $"Backup {hotel.Name}({hotel.Id}) Failed", result.Message);
                }
                else
                {
                    await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Success, $"Backup {hotel.Name}({hotel.Id}) Successfully");
                }
            }
            if (sb.Length != 0)
            {
                return(Json(new JsonError(sb.ToString())));
            }
            return(Json(new JsonSuccess()));
        }
Ejemplo n.º 15
0
        public async Task <JsonResult> AddAdmin(string phoneNumber)
        {
            User user = await UserManager.FindByPhoneNumberAsync(phoneNumber);

            if (user == null)
            {
                return(Json(new JsonError("此手机号未注册")));
            }
            if (await UserManager.IsInRoleAsync(user.Id, Role.Admin))
            {
                return(Json(new JsonError("已经为管理员")));
            }
            await UserManager.AddToRoleAsync(user.Id, Role.Admin);

            await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Success, $"User {user.Id} Added to Admin");

            return(Json(new JsonSuccess()));
        }
Ejemplo n.º 16
0
        public async Task <ActionResult> GetFile(string dir, string name)
        {
            User user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

            SystemConfig config = await YummyOnlineManager.GetSystemConfig();

            string path = $"{config.SpecificationDir}\\{dir}\\{name}";

            if (name.EndsWith(".html") || name.EndsWith(".htm"))
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Info, $"{user.Id}({user.UserName}) Reads {dir}\\{name}");

                return(File(path, "text/html"));
            }
            await YummyOnlineManager.RecordLog(Log.LogProgram.System, Log.LogLevel.Info, $"{user.Id}({user.UserName}) Downloads {dir}\\{name}");

            return(File(path, "application/octet-stream", name));
        }
Ejemplo n.º 17
0
        public virtual async Task <JsonResult> Signin(SigninViewModel model)
        {
            User user = await UserManager.FindByPhoneNumberAsync(model.PhoneNumber);

            if (user == null)
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"User Signin: {model.PhoneNumber} No PhoneNumber, Host: {Request.UserHostAddress}");

                return(Json(new JsonError("手机未注册")));
            }
            if (!await UserManager.CheckPasswordAsync(user, model.Password))
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"User Signin: {model.PhoneNumber} Password Error, Host: {Request.UserHostAddress}",
                                                   $"Password: {model.Password}");

                return(Json(new JsonError("密码不正确")));
            }
            if (User.Identity.IsAuthenticated)
            {
                User oldUser = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                if (oldUser != null && await UserManager.IsInRoleAsync(oldUser.Id, Role.Nemo))
                {
                    // 原来为匿名用户, 每个饭店该匿名用户点过的订单转移到登录的用户帐号下
                    List <Hotel> hotels = await YummyOnlineManager.GetHotels();

                    foreach (Hotel h in hotels)
                    {
                        HotelManager hotelManager = new HotelManager(h.ConnectionString);
                        await hotelManager.TransferDines(oldUser.Id, user.Id);
                    }
                    await UserManager.TransferUserPrice(user, oldUser);

                    await UserManager.DeleteAsync(oldUser);

                    await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"User Transfer: {oldUser.Id} -> {user.Id}");
                }
            }
            SigninManager.Signin(user, true);
            await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Success, $"User Signin: {user.Id} ({user.PhoneNumber}), Host: {Request.UserHostAddress}");

            return(Json(new JsonSuccess()));
        }
Ejemplo n.º 18
0
        public async Task <JsonResult> RemoteRecord(int?hotelId, int level, string message, string detail)
        {
            if (hotelId == null)
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.Remote, (Log.LogLevel) level, message, detail);
            }
            else
            {
                string connStr = await YummyOnlineManager.GetHotelConnectionStringById((int)hotelId);

                HotelManager hotelManager = new HotelManager(connStr);
                await hotelManager.RecordLog((HotelDAO.Models.Log.LogLevel) level, message, detail);
            }

            Response.Headers.Add("Access-Control-Allow-Origin", "*");
            Response.Headers.Add("Access-Control-Allow-Methods", "POST");
            Response.Headers.Add("Access-Control-Allow-Headers", "x-requested-with,content-type");
            return(Json(new JsonSuccess()));
        }
Ejemplo n.º 19
0
        public async Task <JsonResult> Signin(string signinName, string password)
        {
            Staff staff = await StaffManager.FindStaffBySigninName(signinName);

            if (staff == null)
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"Staff Signin: {signinName} No SigninName, Host: {Request.UserHostAddress}");

                return(Json(new JsonError("没有此登录名")));
            }
            if (!await StaffManager.CheckPasswordAsync(staff, password))
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"Staff Signin: {signinName} Password Error, Host: {Request.UserHostAddress}",
                                                   $"Password: {password}");

                return(Json(new JsonError("密码不正确")));
            }

            Hotel hotel = await YummyOnlineManager.GetHotelById(staff.HotelId);

            if (!hotel.Usable)
            {
                return(Json(new JsonError("该饭店不可用,请联系管理员")));
            }
            CurrHotel = hotel;

            if (!await HotelManager.IsStaffHasSchema(staff.Id, HotelDAO.Models.Schema.ReadWaiterData))
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"Staff Signin: {staff.Id} (HotelId {staff.HotelId}) No Authority, Host: {Request.UserHostAddress}");

                return(Json(new JsonError("没有权限")));
            }
            SigninManager.Signin(staff, true);
            await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Success, $"Staff Signin: {staff.Id} (HotelId {staff.HotelId}), Host: {Request.UserHostAddress}");

            return(Json(new JsonSuccess {
                Data = staff.Id
            }));
        }
Ejemplo n.º 20
0
        public async Task <JsonResult> Signin(string userName, string password, bool rememberMe)
        {
            User user = null;

            if (userName.Contains('@'))
            {
                user = await UserManager.FindByEmailAsync(userName);
            }
            else
            {
                user = await UserManager.FindByPhoneNumberAsync(userName);
            }
            if (user == null)
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"Admin Signin: {userName} No UserName, Host: {Request.UserHostAddress}");

                return(Json(new JsonError("未找到此用户")));
            }
            if (!await UserManager.CheckPasswordAsync(user, password))
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"Admin Signin: {userName} Password Error, Host: {Request.UserHostAddress}",
                                                   $"Password: {password}");

                return(Json(new JsonError("密码不正确")));
            }
            if (!await UserManager.IsInRoleAsync(user.Id, Role.Admin))
            {
                await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"Admin Signin: {userName} No Authority, Host: {Request.UserHostAddress}");

                return(Json(new JsonError("没有权限")));
            }
            SigninManager.Signin(user, rememberMe);
            await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Success, $"Admin Signin: {user.Id} ({user.UserName }), Host: {Request.UserHostAddress}");

            return(Json(new JsonSuccess()));
        }
Ejemplo n.º 21
0
        public async Task <JsonResult> Pay(Cart cart)
        {
            CartAddition addition = new CartAddition();

            // 新建或获取用户Id
            User user = await createOrGetUser(User.Identity.GetUserId(), "OrderSystem");

            if (user == null)
            {
                return(Json(new JsonError("创建匿名用户失败")));
            }
            SigninManager.Signin(user, true);
            addition.UserId = user.Id;

            // 创建新订单
            FunctionResult result = await OrderManager.CreateDine(cart, addition);

            if (!result.Succeeded)
            {
                if (await UserManager.IsInRoleAsync(user.Id, Role.Nemo))
                {
                    await UserManager.DeleteAsync(user);

                    await YummyOnlineManager.RecordLog(YummyOnlineDAO.Models.Log.LogProgram.Identity, YummyOnlineDAO.Models.Log.LogLevel.Warning, $"Anonymous User Deleted {user.Id}, Via OrderSystem");
                }
                await HotelManager.RecordLog(HotelDAO.Models.Log.LogLevel.Error, $"{result.Detail}, Host:{Request.UserHostAddress}", HttpPost.GetPostData(Request));

                return(Json(new JsonError(result.Message)));
            }

            Dine dine = ((Dine)result.Data);

            await newDineInform(dine, "OrderSystem");

            PayKind payKind = await HotelManager.GetPayKindById(cart.PayKindId);

            string redirectUrl = $"{payKind.CompleteUrl}?Succeeded={true}&DineId={dine.Id}";

            if (payKind.Type == PayKindType.Online)
            {
                DinePaidDetail mainPaidDetail = await HotelManager.GetDineOnlinePaidDetail(dine.Id);

                // 如果实际需要支付的价格等于0则直接显示支付完成界面
                if (mainPaidDetail.Price == 0)
                {
                    await onlinePayCompleted(dine.Id, null);
                }
                else
                {
                    redirectUrl = await getOnlineRedirectUrl(dine.Id);
                }
            }
            else
            {
                HotelConfig config = await HotelManager.GetHotelConfig();

                if (config.IsPrintReciptAfterPayingOffline)
                {
                    await requestPrintDine(dine.Id, new List <PrintType> {
                        PrintType.Recipt
                    });
                }
            }

            return(Json(new JsonSuccess(redirectUrl)));
        }