/// <summary> /// 子账号操作 /// </summary> /// <param name="requsetMsg"></param> /// <param name="head"></param> /// <returns></returns> public string ASubOperates(string requsetMsg, HeadMessage head) { sendHead.Method = head.Method ?? ""; error.ErrNo = "0004"; try { AgentSub aSub = JSON.ToObject <AgentSub>(requsetMsg); bool opResult = false; string pId; if (aSub == null) { error.ErrMsg = "参数不完整"; } else if (CommonDAL.IsSubAgent(head.LoginID, out pId)) { head.LoginID = pId; error.ErrMsg = "子账号不具有此操作权限"; } else if (CommonDAL.IsYes(head.LoginID)) { error.ErrMsg = "登录代理未启用,不能进行此操作"; } else { switch (sendHead.Method) { case "InsertAgentSub": //新增子账号 opResult = aSubDal.InsertASub(aSub, head, out error); break; case "UpdateAgentSub": //修改子账号 case "UpdateSubState": //修改子账号状态 opResult = aSubDal.UpdateASub(aSub, head, out error); break; case "DeleteAgentSub": opResult = aSubDal.DeleteASub(aSub, head, out error); break; } } sendMsg.Head = JSON.ToJSON(sendHead); sendMsg.Error = JSON.ToJSON(error); sendMsg.Reponse = JSON.ToJSON(new { JsonData = JSON.ToJSON(new { Result = opResult }) }); return(JSON.ToJSON(sendMsg)); } catch (Exception ex) { Common.LogHelper.WriteLog(typeof(LoginBLL), ex); error.ErrMsg = ex.Message.Replace("\r", "").Replace("\n", ""); sendMsg.Head = JSON.ToJSON(sendHead); sendMsg.Reponse = "{}"; sendMsg.Error = JSON.ToJSON(error); return(JSON.ToJSON(sendMsg)); } }
/// <summary> /// 删除子账号 /// </summary> /// <param name="model"></param> /// <param name="head"></param> /// <param name="error"></param> /// <returns></returns> public bool DeleteASub(AgentSub model, HeadMessage head, out ErrorMessage error) { error = new ErrorMessage(); error.ErrNo = "0004"; try { if (string.IsNullOrEmpty(model.AS_ID)) { error.ErrMsg = "参数不完整"; return(false); } Where <T_AgentSub> whereSql = new Where <T_AgentSub>(); whereSql.And(o => o.AgentSubID == model.AS_ID); bool res = AgentSubDAL.Delete(whereSql) > 0; if (res) { error.ErrMsg = "删除子账号成功"; error.ErrNo = "0000"; } else { error.ErrMsg = "删除子账号失败"; } T_OperationLog opLog = new T_OperationLog(); opLog.LogID = Guid.NewGuid().ToString().Replace("-", ""); opLog.LogTime = string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now); opLog.LogType = "删除子账号"; opLog.OpID = head.LoginID; opLog.LogInfo = error.ErrMsg; if (Db.Context_SqlServer.Insert <T_OperationLog>(opLog) <= 0) { Common.LogHelper.WriteErrLog(typeof(AgentListDAL), "插入" + head.Account + "删除子账号日志失败"); } return(res); } catch (Exception ex) { Common.LogHelper.WriteLog(typeof(AgentSubDAL), ex); error.ErrMsg = ex.Message.Replace("\r", "").Replace("\n", ""); return(false); } }
/// <summary> /// 新增子账号 /// </summary> /// <param name="model"></param> /// <param name="head"></param> /// <param name="error"></param> /// <returns></returns> public bool InsertASub(AgentSub model, HeadMessage head, out ErrorMessage error) { error = new ErrorMessage(); error.ErrNo = "0004"; try { if (string.IsNullOrEmpty(model.AS_AID)) { error.ErrMsg = "新增子账号必须指定所属代理ID"; return(false); } if (string.IsNullOrEmpty(model.AS_UserID)) { error.ErrMsg = "新增子账号必须填写子账号登录名称"; return(false); } if (string.IsNullOrEmpty(model.AS_Name)) { error.ErrMsg = "新增子账号必须填写子账号名称"; return(false); } if (string.IsNullOrEmpty(model.AS_Pwd)) { error.ErrMsg = "新增子账号必须填写子账号密码"; return(false); } T_AgentSub dbASub = new T_AgentSub(); dbASub.AgentID = model.AS_AID; dbASub.AgentSubID = Guid.NewGuid().ToString().Replace("-", ""); dbASub.State = "YES"; //model.AS_State; dbASub.Pwd = model.AS_Pwd; dbASub.LogName = model.AS_UserID; dbASub.AgentSubName = model.AS_Name; bool res = Db.Context_SqlServer.Insert <T_AgentSub>(dbASub) > 0; if (res) { error.ErrMsg = "新增子账号成功"; error.ErrNo = "0000"; } else { error.ErrMsg = "新增子账号失败"; } T_OperationLog opLog = new T_OperationLog(); opLog.LogID = Guid.NewGuid().ToString().Replace("-", ""); opLog.LogTime = string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now); opLog.LogType = "新增子账号"; opLog.OpID = head.LoginID; opLog.LogInfo = error.ErrMsg; if (Db.Context_SqlServer.Insert <T_OperationLog>(opLog) <= 0) { Common.LogHelper.WriteErrLog(typeof(AgentListDAL), "插入" + head.Account + "新增子账号日志失败"); } return(res); } catch (Exception ex) { Common.LogHelper.WriteLog(typeof(AgentSubDAL), ex); error.ErrMsg = ex.Message.Replace("\r", "").Replace("\n", ""); return(false); } }
/// <summary> /// 修改子账号 /// </summary> /// <param name="model"></param> /// <param name="head"></param> /// <param name="error"></param> /// <returns></returns> public bool UpdateASub(AgentSub model, HeadMessage head, out ErrorMessage error) { error = new ErrorMessage(); error.ErrNo = "0004"; try { if (string.IsNullOrEmpty(model.AS_ID) || string.IsNullOrEmpty(model.AS_AID)) { error.ErrMsg = "参数不完整"; return(false); } string strSql = Common.SqlTemplateCommon.GetSql("A_UpdateT_AgentSub"); if (string.IsNullOrEmpty(strSql)) { error.ErrMsg = "服务端没有读取到A_UpdateT_AgentSub数据模板,请联系管理员"; return(false); } strSql = strSql.Replace("${AgentSubID}", model.AS_ID); strSql = strSql.Replace("${LogName}", model.AS_UserID); StringBuilder aSubBuilder = new StringBuilder(); T_OperationLog opLog = new T_OperationLog(); StringBuilder descBuilder = new StringBuilder(); descBuilder.Append(head.Account + "修改了子账号" + model.AS_UserID + ":"); aSubBuilder.Append("UPDATE T_AgentSub SET AgentSubID = '" + model.AS_ID + "'"); if (!string.IsNullOrEmpty(model.AS_Name)) { aSubBuilder.Append(",AgentSubName='" + model.AS_Name + "'"); } if (!string.IsNullOrEmpty(model.AS_UserID)) { aSubBuilder.Append(",LogName='" + model.AS_UserID + "'"); } if (!string.IsNullOrEmpty(model.AS_Pwd)) { aSubBuilder.Append(",Pwd='" + model.AS_Pwd + "'"); descBuilder.Append("修改了子账号登录密码;"); } if (!string.IsNullOrEmpty(model.AS_State)) { aSubBuilder.Append(",State='" + model.AS_State + "'"); descBuilder.Append("把子账号状态改为了" + model.AS_State + ";"); } aSubBuilder.Append(" WHERE AgentSubID ='" + model.AS_ID + "'"); strSql = strSql.Replace("${UpAgentSub}", aSubBuilder.ToString()); strSql = strSql.Replace("##'", ""); strSql = strSql.Replace("##\"", ""); strSql = strSql.Replace("'##", ""); strSql = strSql.Replace("\"##", ""); Db.Context_SqlServer.FromSql(strSql).ToDataSet(); error.ErrMsg = "修改子账号成功"; error.ErrNo = "0000"; opLog.LogID = Guid.NewGuid().ToString().Replace("-", ""); opLog.LogTime = string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now); opLog.LogType = "修改子账号"; opLog.OpID = head.LoginID; opLog.LogInfo = descBuilder.ToString(); if (Db.Context_SqlServer.Insert <T_OperationLog>(opLog) <= 0) { Common.LogHelper.WriteErrLog(typeof(AgentListDAL), "插入" + head.Account + "修改子账号日志失败"); } return(true); } catch (Exception ex) { Common.LogHelper.WriteLog(typeof(AgentSubDAL), ex); error.ErrMsg = ex.Message.Replace("\r", "").Replace("\n", ""); return(false); } }