/// <summary> /// 更新员工信息 /// </summary> /// <param name="staff"></param> /// <returns></returns> public Tuple <bool, string> UpdateStoreStaff(StoreStaffParam staff) { var count = helper.QueryScalar($@"select Count(1) from [User] where Phone='{staff.Phone}' and Id not in ({staff.Id})"); if (Convert.ToInt32(count) > 0) { return(Tuple.Create(false, "该手机号已经存在")); } var temp = helper.QueryScalar($@"select [Password] from [User] where Id={staff.Id}"); if (temp == null) { return(Tuple.Create(false, "异常参数")); } string password = temp.ToString(); if (password != staff.Password) { password = Util.MD5Encrypt(staff.Password); } helper.Execute($@"update StoreDetailInfo set StoreName='{staff.StaffName}' where UserId={staff.Id}"); string sql = $@"update [User] set StaffName='{staff.StaffName}',Phone='{staff.Phone}',Password='******', StoreManage='{staff.StoreManage}',SongManage='{staff.SongManage}',UserManage='{staff.UserManage}' where Id={staff.Id}"; return(Tuple.Create(helper.Execute(sql) > 0 ? true : false, string.Empty)); }
/// <summary> /// 添加员工 /// </summary> /// <param name="token"></param> /// <param name="staff"></param> /// <returns></returns> public Tuple <bool, string> AddStoreStaff(string token, StoreStaffParam staff) { var temp = helper.QueryScalar($@"select Count(1) from [User] where Phone='{staff.Phone}'"); if (Convert.ToInt32(temp) > 0) { return(Tuple.Create(false, "该手机号已经存在,无法添加")); } // 先根据token,Id,再获取,获取 StoreCode,然后再添加Staff string storeCode = helper.QueryScalar($@"select StoreCode from UserAccessToken a left join [User] b on a.UserId=b.Id where TokenId='{token}'").ToString(); if (string.IsNullOrWhiteSpace(storeCode)) { return(Tuple.Create(false, "该账号无法添加员工")); } // string sql = $@"insert into [User] (StoreCode,StaffName,Phone,Password,StoreManage,SongManage,UserManage,Enable,Status,UserType,IsMain) //values ('{storeCode}','{staff.StaffName}','{staff.Phone}','{Util.MD5Encrypt(staff.Password)}', //'{staff.StoreManage}','{staff.SongManage}','{staff.UserManage}',{1},{1},{2},{0})"; //同时向StoreDeatilInfo表添加数据,为了管理员工播放列表 var p = new DynamicParameters(); p.Add("@Id", dbType: DbType.Int32, direction: ParameterDirection.Output); var result = helper.Execute($@"insert into [User] (StoreCode,StaffName,Phone,Password,StoreManage,SongManage,UserManage,Enable,Status,UserType,IsMain) values ('{storeCode}','{staff.StaffName}','{staff.Phone}','{Util.MD5Encrypt(staff.Password)}', '{staff.StoreManage}','{staff.SongManage}','{staff.UserManage}',{1},{1},{2},{0}); SELECT @Id=SCOPE_IDENTITY()", p); var id = p.Get <int>("@Id"); string sql = $@"insert into StoreDetailInfo (UserId,StoreName,Enabled,CreateTime) values ({id},'{staff.StaffName}',{1},'{DateTime.Now}')"; return(Tuple.Create(helper.Execute(sql) > 0 ? true : false, string.Empty)); }
public ResponseResultDto <bool> UpdateStaff(StoreStaffParam storeStaffParam) { if (!Util.ValidateMobilePhone(storeStaffParam.Phone)) { return(new ResponseResultDto <bool> { IsSuccess = false, ErrorMessage = "手机号格式不正确", Result = false }); } var result = storeStaffApiRepository.UpdateStoreStaff(storeStaffParam); return(new ResponseResultDto <bool> { IsSuccess = result.Item1, ErrorMessage = result.Item2, Result = result.Item1 }); }
public ResponseResultDto <bool> AddStaff(StoreStaffParam storeStaffParam) { if (!Util.ValidateMobilePhone(storeStaffParam.Phone)) { return(new ResponseResultDto <bool> { IsSuccess = false, ErrorMessage = "手机号格式不正确", Result = false }); } HttpRequest request = HttpContext.Current.Request; string token = request.Headers.GetValues("Access-Token").FirstOrDefault(); var result = storeStaffApiRepository.AddStoreStaff(token, storeStaffParam); return(new ResponseResultDto <bool> { IsSuccess = result.Item1, ErrorMessage = result.Item2, Result = result.Item1 }); }