public JsonResult Check(AppTypeFlag?AppType, bool?Shopkeeper) //AppType等所以App版本更新后启用【必传不允许空】 { OperationResult oper = new OperationResult(OperationResultType.Error); try { string strName = Request["AdminName"]; string strPassword = Request["AdminPass"]; string strJpushRegistrationID = Request["JPushRegistrationID"]; if (string.IsNullOrEmpty(strName)) { oper.Message = "请填写登录名或者手机号码"; return(Json(oper)); } if (string.IsNullOrEmpty(strPassword)) { oper.Message = "请填写密码"; return(Json(oper)); } //if (dtoinfo.IsNull() || dtoinfo.AppVersion.IsNullOrEmpty() || dtoinfo.DeviceToken.IsNullOrEmpty()) //{ // oper.Message = "登录失败,参数丢失"; // return Json(oper); //} Administrator dto = new Administrator(); dto.Member = new Member(); dto.Member.MemberName = strName; dto.Member.MobilePhone = strName; dto.Member.MemberPass = strPassword; dto.JPushRegistrationID = strJpushRegistrationID; oper = _administratorContract.CheckLogin(dto); if (oper.ResultType == OperationResultType.Success) { var entity = (Administrator)oper.Data; // 查找部门下的店铺 var store = entity.Department.Stores.FirstOrDefault(); var storeId = 14; var storeName = "零时尚"; if (store != null) { //部门没有归属店铺,就不需要统计 storeId = store.Id; storeName = store.StoreName; } //蝶掌柜登录权限判断,App全部更新后需要弃用 if (!ConfigurationHelper.IsDevelopment()) { if (Shopkeeper.HasValue) { if (!entity.JobPosition.AppVerManages.Any(a => a.AppType == AppTypeFlag.碟掌柜 && a.IsEnabled && !a.IsDeleted)) { oper = new OperationResult(OperationResultType.LoginError, "无权登录"); return(Json(oper)); } } if (AppType.HasValue) { if (!entity.JobPosition.AppVerManages.Any(a => a.IsEnabled && !a.IsDeleted && a.AppType == AppType)) { return(Json(new OperationResult(OperationResultType.Error, $"没有登录 {AppType + ""} 的权限"))); } } } DateTime expiration = DateTime.Now.Add(FormsAuthentication.Timeout); var userData = new { Id = entity.Id, AdminName = entity.Member.MemberName, RealName = entity.Member.RealName, JPushRegistrationID = strJpushRegistrationID, }; FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(2, (userData.AdminName + userData.Id.ToString()), DateTime.Now, expiration, false, userData.ToJsonString(), FormsAuthentication.FormsCookiePath); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket)) { HttpOnly = true, Secure = FormsAuthentication.RequireSSL, Domain = FormsAuthentication.CookieDomain, Path = FormsAuthentication.FormsCookiePath, }; Response.Cookies.Remove(cookie.Name); Response.Cookies.Add(cookie); //oper.Data = null; bool EnablePhone = false; if (entity.Member.IsNotNull() && !entity.Member.MobilePhone.IsNullOrEmpty()) { EnablePhone = true; } oper = _administratorContract.GetWorkTime(entity.Id); WorkTime workTime = new WorkTime(); if (oper.ResultType == OperationResultType.Success) { workTime = oper.Data as WorkTime; workTime = OfficeHelper.CheckworkTime(workTime); } oper.Data = new { entity.Id, EnablePhone, workTime.AmStartTime, workTime.PmEndTime, workTime.IsVacations, workTime.WorkWeek, storeId, storeName, entity.IsPersonalTime }; #region 添加设置标签Jpush使用 if (!userData.JPushRegistrationID.IsNullOrEmpty()) { JPushClient jclient = new JPushClient(JpushApi.app_key, JpushApi.master_secret); var dresult = jclient.updateDeviceTagAlias(userData.JPushRegistrationID, userData.Id.ToString(), null, new HashSet <string>() { "yuangong" }, null); //oper.Other = dresult; } #endregion } return(Json(oper, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { oper.Message = "服务器忙,请稍后重试"; _Logger.Error <string>(ex.ToString()); return(Json(oper, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// 初始化打卡界面 /// </summary> /// <returns></returns> public ActionResult Registration() { Dictionary <string, int> dic = _holidayContract.GetHoliday(); string strStartTime = ""; string strEndTime = ""; string strLoginInTime = string.Empty; string strLoginOutTime = string.Empty; int adminId = AuthorityHelper.OperatorId ?? 0; //初始值默认不能签到和签退的 bool enableLoginIn = false; bool enableLoginOut = false; bool Isatten = false; var admin = _administratorContract.Administrators.FirstOrDefault(x => x.Id == adminId); if (dic == null && dic.Count == 0) { strStartTime = "请添加公休假"; strEndTime = "请添加公休假"; } else { OperationResult oper = _administratorContract.GetWorkTime(adminId); if (oper.ResultType == OperationResultType.Success) { WorkTime workTime = oper.Data as WorkTime; DateTime nowTime = DateTime.Now; Attendance atten = _attendanceContract.Attendances.Where(x => x.IsDeleted == false && x.IsEnabled == true && x.AdminId == adminId) .FirstOrDefault(x => nowTime.Year == x.AttendanceTime.Year && nowTime.Month == x.AttendanceTime.Month && nowTime.Day == x.AttendanceTime.Day); bool isWork = IsWorkDay(nowTime, workTime, dic); string strNotice = "弹性时间"; //提示上下班时间 if (!admin.IsPersonalTime) { strStartTime = workTime.IsFlexibleWork == true ? strNotice : workTime.AmStartTime; strEndTime = workTime.IsFlexibleWork == true ? strNotice : workTime.PmEndTime; } else { var _wd = _workTimeDetaileContract.WorkTimeDetailes.FirstOrDefault(x => x.WorkTimeId == admin.WorkTimeId && x.Year == nowTime.Year && x.Month == nowTime.Month && x.WorkDay == nowTime.Day); if (_wd != null) { if (_wd.WorkTimeType != 2) { strStartTime = workTime.IsFlexibleWork == true ? strNotice : _wd.AmStartTime; strEndTime = workTime.IsFlexibleWork == true ? strNotice : _wd.PmEndTime; } else { isWork = false; } } } if (isWork) { enableLoginIn = true; enableLoginOut = true; } else { isWork = IsOverTime(nowTime, adminId); if (isWork == true) { enableLoginIn = true; enableLoginOut = true; } } if (atten != null) { enableLoginIn = false; Isatten = true; strLoginInTime = atten.AmStartTime; strLoginOutTime = atten.PmEndTime; if (atten.LeaveInfoId != null) { enableLoginIn = true; enableLoginOut = true; enableLoginIn = true; } if (atten.FieldId != null) { enableLoginIn = true; enableLoginOut = true; enableLoginIn = true; } } } } ViewBag.EnableLoginIn = enableLoginIn; ViewBag.EnableLoginOut = enableLoginOut; ViewBag.LoginInTime = strLoginInTime; ViewBag.LoginOutTime = strLoginOutTime; ViewBag.StartTime = strStartTime; ViewBag.EndTime = strEndTime; return(PartialView()); }