UserController.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. using JCSoft.WX.Framework.Api;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.AspNetCore.Http;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. using Common.Wechat;
  9. using Common;
  10. using System.IO;
  11. using System.Text;
  12. using Newtonsoft.Json;
  13. using System.Data;
  14. using ZcPeng.PublicLibrary;
  15. using CoreEntity.Entity;
  16. using CoreEntity.DAL;
  17. using Common.Model;
  18. using Newtonsoft.Json.Converters;
  19. using System.Data.SqlClient;
  20. using SupplierWeb.Codes.mvc;
  21. using System.Collections.Concurrent;
  22. using Microsoft.Extensions.Caching.Memory;
  23. using Microsoft.AspNetCore.Authorization;
  24. using PublicLibrary.Common;
  25. using PublicLibrary.Model;
  26. using Microsoft.Extensions.Primitives;
  27. using LigerRM.Common;
  28. namespace SupplierWeb.Controllers
  29. {
  30. [Route("web/user")]
  31. ///超级管理员,采购管理员能进入查看账户号,密码等
  32. public class UserController : BaseController
  33. {
  34. public UserController(IMemoryCache cache, IApiClient client) : base(cache, client)
  35. {
  36. }
  37. private ConcurrentDictionary<int, Role> roleMap = new ConcurrentDictionary<int, Role>();
  38. ////内部管理用户列表
  39. //[HttpGet, Route("index")]
  40. //public ActionResult index(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
  41. // string sortField, Int32 sortDirection, string[] sumFields, string callback)
  42. //{
  43. // var r = this.indexp(filters, pageIndex, pageSize,
  44. // sortField, sortDirection, sumFields,null);
  45. // return Content(callback + "(" + JsonConvert.SerializeObject(r.Value)
  46. // + ")");
  47. //}
  48. ////内部管理用户列表
  49. [AuthPermission]
  50. [HttpPost, Route("index/{roleId}/{staffId}")]
  51. public JsonResult indexp(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
  52. string sortField, Int32 sortDirection, string[] sumFields,
  53. string roleId,
  54. string staffId,
  55. [FromBody]dynamic data)
  56. {
  57. string roleIdstr = getStaff(staffId, "roleid");
  58. string useridstr = getStaff(staffId, "userid");
  59. //判断参数是否合法
  60. if (string.IsNullOrEmpty(roleIdstr))
  61. {
  62. return Json(new
  63. {
  64. timeout = 1,
  65. msg = "没有登陆"
  66. });
  67. }
  68. if (data != null)
  69. {
  70. //Newtonsoft.Json.Linq.JArray
  71. filters = data.filters.ToObject<QueryFilter[]>();
  72. pageIndex = data.pageIndex;
  73. pageSize = data.pageSize;
  74. sortField = data.sortField;
  75. sortDirection = data.sortDirection;
  76. sumFields = data.sumFields.ToObject<string[]>();
  77. }
  78. #region 获取user
  79. List<SqlParameter> parameters = new List<SqlParameter>();
  80. string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters, new Account());
  81. if (roleId == "" || roleId == null)
  82. {
  83. filterstr += " and roleid != 3 ";
  84. }
  85. else if (roleId == "2")
  86. {
  87. filterstr += " and roleid = " + roleId;
  88. }
  89. else
  90. {
  91. filterstr += " and roleid != 3 " +
  92. " and roleid in(1,6,7)";
  93. }
  94. if (roleIdstr != "1" && roleIdstr != "6" && roleIdstr != "7")
  95. {
  96. filterstr += " and id = " + useridstr;
  97. }
  98. DataTable dt = new DataTable();
  99. string result = string.Empty;
  100. string direct = " desc ";
  101. if (sortDirection != 1)
  102. direct = " asc";
  103. int start = (pageIndex - 1) * pageSize;
  104. int end = (start + 1 + pageSize);
  105. string commandText0 = "select * from (";
  106. string commandText1 = "select *, row_number() over" +
  107. "( order by " + sortField + " " + direct + " ) as rownum" +
  108. " from " + Config.TablePrefix + "Account " +
  109. " where 1 = 1 " +
  110. filterstr +
  111. ")AAA";
  112. string commandText2 =
  113. " where AAA.rownum>" + start + " and AAA.rownum<" + end +
  114. " ";
  115. string commandText3 = commandText0 + commandText1 + commandText2;//-tanyang
  116. bool success = DataAccess.GetValues(commandText3, ref dt, parameters.ToArray(), out result);
  117. #endregion
  118. // 把DataTable转换为IList<UserInfo>
  119. IList<Account> users = new List<Account>();
  120. if (dt != null && dt.Rows.Count > 0)
  121. {
  122. // 把DataTable转换为IList<UserInfo>
  123. users = ModelConvertHelper<Account>.ConvertToModel(dt);
  124. }
  125. IList<Role> roles = RoleDAL.GetRoles();
  126. if (roleMap.Count < roles.Count)
  127. {
  128. foreach (Role role in roles)
  129. {
  130. roleMap.TryAdd(role.Id, role);
  131. }
  132. }
  133. string result1;
  134. long totalcount = DataAccess.GetRowCountDefine("select count(*) from (" + commandText1, parameters.ToArray(), out result1);
  135. foreach (Account user in users)
  136. {
  137. Role role;
  138. if (roleMap.TryGetValue(user.RoleId, out role))
  139. {
  140. user.RoleName = role.RoleRemark;
  141. }
  142. }
  143. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  144. {
  145. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  146. };
  147. var jsonData = JsonConvert.SerializeObject(users, timejson);
  148. return Json(new
  149. {
  150. items = JsonConvert.DeserializeObject(jsonData),
  151. sum = new { },
  152. totalCount = totalcount
  153. });
  154. }
  155. [AuthPermission]
  156. [HttpPost, Route("index")]
  157. public JsonResult index(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
  158. string sortField, Int32 sortDirection, string[] sumFields,
  159. string roleId,
  160. string staffId,
  161. [FromBody]dynamic data)
  162. {
  163. //string roleIdstr = getStaff(staffId, "roleid");
  164. string useridstr = getStaff(staffId, "userid");
  165. //判断参数是否合法
  166. if (string.IsNullOrEmpty(useridstr))
  167. {
  168. return Json(new
  169. {
  170. timeout = 1,
  171. msg = "没有登陆"
  172. });
  173. }
  174. if (data != null)
  175. {
  176. //Newtonsoft.Json.Linq.JArray
  177. filters = data.filters.ToObject<QueryFilter[]>();
  178. pageIndex = data.pageIndex;
  179. pageSize = data.pageSize;
  180. sortField = data.sortField;
  181. sortDirection = data.sortDirection;
  182. sumFields = data.sumFields.ToObject<string[]>();
  183. }
  184. #region 获取user
  185. List<SqlParameter> parameters = new List<SqlParameter>();
  186. string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters, new Account());
  187. DataTable dt = new DataTable();
  188. string result = string.Empty;
  189. string direct = " desc ";
  190. if (sortDirection != 1)
  191. direct = " asc";
  192. int start = (pageIndex - 1) * pageSize;
  193. int end = (start + 1 + pageSize);
  194. string commandText0 = "select * from (";
  195. string commandText1 = "select *, row_number() over" +
  196. "( order by " + sortField + " " + direct + " ) as rownum" +
  197. " from " + Config.TablePrefix + "Account " +
  198. " where 1 = 1 " +
  199. filterstr +
  200. ")AAA";
  201. string commandText2 =
  202. " where AAA.rownum>" + start + " and AAA.rownum<" + end +
  203. " ";
  204. string commandText3 = commandText0 + commandText1 + commandText2;//-tanyang
  205. bool success = DataAccess.GetValues(commandText3, ref dt, parameters.ToArray(), out result);
  206. #endregion
  207. // 把DataTable转换为IList<UserInfo>
  208. IList<Account> users = new List<Account>();
  209. if (dt != null && dt.Rows.Count > 0)
  210. {
  211. // 把DataTable转换为IList<UserInfo>
  212. users = ModelConvertHelper<Account>.ConvertToModel(dt);
  213. }
  214. IList<Role> roles = RoleDAL.GetRoles();
  215. if (roleMap.Count < roles.Count)
  216. {
  217. foreach (Role role in roles)
  218. {
  219. roleMap.TryAdd(role.Id, role);
  220. }
  221. }
  222. string result1;
  223. long totalcount = DataAccess.GetRowCountDefine("select count(*) from (" + commandText1, parameters.ToArray(), out result1);
  224. foreach (Account user in users)
  225. {
  226. Role role;
  227. if (roleMap.TryGetValue(user.RoleId, out role))
  228. {
  229. user.RoleName = role.RoleRemark;
  230. }
  231. }
  232. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  233. {
  234. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  235. };
  236. var jsonData = JsonConvert.SerializeObject(users, timejson);
  237. return Json(new
  238. {
  239. items = JsonConvert.DeserializeObject(jsonData),
  240. sum = new { },
  241. totalCount = totalcount
  242. });
  243. }
  244. ////角色列表
  245. [AllowAnonymous]
  246. [HttpGet, Route("role/{0}")]
  247. public ActionResult role(string callback)
  248. {
  249. #region 获取role
  250. IList<Role> roles = RoleDAL.GetRoles();
  251. #endregion
  252. IList<Option> options = new List<Option>();
  253. foreach (Role role in roles)
  254. {
  255. var option = new Option() { label = role.RoleRemark, value = role.Id.ToString(), disabled = role.IsDelete };
  256. options.Add(option);
  257. }
  258. var jsonData = JsonConvert.SerializeObject(options);
  259. return Content(callback + "(" + jsonData
  260. + ")");
  261. }
  262. ////角色列表
  263. [AllowAnonymous]
  264. [HttpGet, Route("role")]
  265. public JsonResult role()
  266. {
  267. #region 获取role
  268. IList<Role> roles = RoleDAL.GetRoles();
  269. #endregion
  270. IList<Option> options = new List<Option>();
  271. foreach (Role role in roles)
  272. {
  273. var option = new Option() { label = role.RoleRemark, value = role.Id.ToString(), disabled = role.IsDelete };
  274. options.Add(option);
  275. }
  276. //var jsonData = JsonConvert.SerializeObject(options);
  277. return Json(options
  278. );
  279. }
  280. ////添加内部管理人员账户,采购员账号
  281. [AuthPermission]
  282. [HttpPost, Route("addIntenel")]
  283. public ActionResult addIntenel(
  284. string accountName, string accountPassWord, string accountRealName
  285. , string AccountPhone, string STAFFID
  286. , [FromBody]dynamic data, Int32 RoleId = 2)
  287. {
  288. if (data != null)
  289. {
  290. //Newtonsoft.Json.Linq.JArray
  291. accountName = data.accountName;
  292. if (accountName == null)
  293. accountName = data.MOBILE;
  294. accountPassWord = data.AccountPassWord;
  295. accountRealName = data.accountRealName;
  296. if (accountRealName == null)
  297. accountRealName = data.STAFFNAME;
  298. AccountPhone = data.AccountPhone;
  299. if (AccountPhone == null)
  300. AccountPhone = data.MOBILE;
  301. STAFFID = data.STAFFID;
  302. //RoleId = data.RoleId;
  303. }
  304. //手机号已存在不能添加
  305. #region 获取user
  306. string commandTextUser = "Select Id From " + Config.TablePrefix + "Account Where AccountName=@AccountPhone";
  307. string commandTextStaff = "Select Id From " + Config.TablePrefix + "Account Where PurStaffId=@PurStaffId";
  308. string resultUser;
  309. Object value;
  310. Object valueStaff;
  311. List<List<Object>> parametersUser = new List<List<Object>>();
  312. if (accountName != null)
  313. parametersUser.Add(new List<Object>() { "AccountPhone", accountName });
  314. parametersUser.Add(new List<Object>() { "PurStaffId", STAFFID });
  315. DataAccess.GetOneValue(commandTextUser, DataAccess.ToParameters(parametersUser), out value, out resultUser);
  316. DataAccess.GetOneValue(commandTextStaff, DataAccess.ToParameters(parametersUser), out valueStaff, out resultUser);
  317. if (value != null || valueStaff != null)
  318. {
  319. return Json(new
  320. {
  321. success = 0,
  322. msg = value != null ? "手机号已存在" : "账户已绑定"
  323. });
  324. }
  325. #endregion
  326. #region 添加用户
  327. string commandText = "INSERT INTO " + Config.TablePrefix + "Account (accountname,accountpassword,accountrealname,accountphone,roleid,isdelete,PurStaffId)"
  328. + " VALUES (@accountname,@accountpassword,@accountrealname,@accountphone,@roleid,@isdelete,@PurStaffId)";
  329. string result;
  330. //准备参数
  331. List<List<Object>> parameters = new List<List<Object>>();
  332. parameters.Add(new List<Object>() { "accountname", accountName });
  333. parameters.Add(new List<Object>() { "accountpassword", accountPassWord });
  334. parameters.Add(new List<Object>() { "accountrealname", accountRealName });
  335. parameters.Add(new List<Object>() { "accountphone", AccountPhone });
  336. parameters.Add(new List<Object>() { "roleid", RoleId });
  337. parameters.Add(new List<Object>() { "isdelete", 0 });
  338. parameters.Add(new List<Object>() { "PurStaffId", STAFFID });
  339. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  340. int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  341. #endregion
  342. return Json(new
  343. {
  344. success = success
  345. });
  346. }
  347. ////添加内部管理人员账户,采购员账号
  348. [AuthPermission]
  349. [HttpPost, Route("add")]
  350. public JsonResult add(
  351. string accountName, string accountPassWord, string accountRealName
  352. , string AccountPhone, Int32 RoleId
  353. , string callback, [FromBody]dynamic data, Int32 IsDelete = 0
  354. )
  355. {
  356. string Sup_OrgId = "";
  357. RoleId = 0;
  358. if (data != null)
  359. {
  360. //Newtonsoft.Json.Linq.JArray
  361. accountName = data.AccountName;
  362. accountPassWord = data.AccountPassWord;
  363. accountRealName = data.AccountRealName;
  364. AccountPhone = data.AccountPhone;
  365. if (data.RoleId != null) { RoleId = data.RoleId; }
  366. IsDelete = data.IsDelete == null ? 0 : data.IsDelete;
  367. if (data.Sup_OrgId != null) { Sup_OrgId = data.Sup_OrgId; }
  368. }
  369. //手机号已存在不能添加
  370. #region 获取user
  371. string commandTextUser = "Select Id From " + Config.TablePrefix + "Account Where AccountName=@accountName";
  372. string resultUser;
  373. Object value;
  374. List<List<Object>> parametersUser = new List<List<Object>>();
  375. if (accountName != null)
  376. parametersUser.Add(new List<Object>() { "accountName", accountName });
  377. else
  378. {
  379. return Json(new
  380. {
  381. success = 0,
  382. msg = "请填账户名"
  383. });
  384. }
  385. DataAccess.GetOneValue(commandTextUser, DataAccess.ToParameters(parametersUser), out value, out resultUser);
  386. if (value != null)
  387. {
  388. return Json(new
  389. {
  390. success = 0,
  391. msg = "手机号已存在"
  392. });
  393. }
  394. #endregion
  395. #region 添加用户
  396. string commandText = "INSERT INTO " + Config.TablePrefix + "Account (accountname,accountpassword,accountrealname,accountphone,roleid,isdelete,Sup_OrgId)"
  397. + " VALUES (@accountname,@accountpassword,@accountrealname,@accountphone,@roleid,@isdelete,@Sup_OrgId)";
  398. string result;
  399. //准备参数
  400. List<List<Object>> parameters = new List<List<Object>>();
  401. parameters.Add(new List<Object>() { "accountname", accountName });
  402. parameters.Add(new List<Object>() { "accountpassword", accountPassWord });
  403. parameters.Add(new List<Object>() { "accountrealname", accountRealName });
  404. parameters.Add(new List<Object>() { "accountphone", AccountPhone });
  405. parameters.Add(new List<Object>() { "roleid", RoleId });
  406. parameters.Add(new List<Object>() { "isdelete", IsDelete });
  407. parameters.Add(new List<Object>() { "Sup_OrgId", Sup_OrgId });
  408. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  409. int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  410. #endregion
  411. return Json(new
  412. {
  413. success = success
  414. });
  415. }
  416. ////编辑内部管理人员账户,采购员账号
  417. //[AuthPermission]
  418. //[HttpGet, Route("edit")]
  419. //public ActionResult edit(Int32 Id,
  420. // string accountName, string accountPassWord, string accountRealName
  421. // , string AccountPhone, Int32 RoleId
  422. // , string callback, Int32 IsDelete, string WxOpenId
  423. // )
  424. //{
  425. // var r = this.editp(Id,
  426. // accountName, accountPassWord, accountRealName
  427. // , AccountPhone, RoleId
  428. // , callback, null, IsDelete, WxOpenId);
  429. // return Content(callback + "(" + JsonConvert.SerializeObject(r.Value)
  430. // + ")");
  431. //}
  432. [AuthPermission]
  433. [HttpPost, Route("edit")]
  434. public JsonResult editp(Int32 Id,
  435. string accountName, string accountPassWord, string accountRealName
  436. , string AccountPhone, Int32 RoleId
  437. , string callback, [FromBody]dynamic data
  438. , Int32 IsDelete, String WxOpenId
  439. )
  440. {
  441. var userid = getStaff("userid");
  442. //判断参数是否合法
  443. if (string.IsNullOrEmpty(userid))
  444. {
  445. return Json(new
  446. {
  447. success = 0,
  448. msg = "没有登陆",
  449. timeout = 1
  450. });
  451. }
  452. string Sup_OrgId = "";
  453. AccountPhone = "";
  454. if (data != null)
  455. {
  456. //Newtonsoft.Json.Linq.JArray
  457. Id = data.Id;
  458. accountName = data.AccountName;
  459. accountPassWord = data.AccountPassWord;
  460. accountRealName = data.AccountRealName;
  461. AccountPhone = data.AccountPhone;
  462. RoleId = data.RoleId;
  463. IsDelete = data.IsDelete == null ? 0 : data.IsDelete;
  464. WxOpenId = data.WxOpenId;
  465. if (data.Sup_OrgId != null) { Sup_OrgId = data.Sup_OrgId; }
  466. }
  467. //手机号已存在不能添加
  468. #region 获取user
  469. string commandTextUser = "Select Id From " + Config.TablePrefix + "Account Where AccountName=@AccountPhone and Id <> @Id";
  470. string resultUser;
  471. Object value;
  472. List<List<Object>> parametersUser = new List<List<Object>>();
  473. if (accountName != null)
  474. parametersUser.Add(new List<Object>() { "AccountPhone", accountName });
  475. else
  476. {
  477. return Json(new
  478. {
  479. success = 0,
  480. msg = "请填账户名"
  481. });
  482. }
  483. parametersUser.Add(new List<Object>() { "Id", Id });
  484. DataAccess.GetOneValue(commandTextUser, DataAccess.ToParameters(parametersUser), out value, out resultUser);
  485. if (value != null)
  486. {
  487. return Json(new
  488. {
  489. success = 0,
  490. msg = "手机号已存在"
  491. });
  492. }
  493. #endregion
  494. List<DataAccessCommand> list = new List<DataAccessCommand>(2);
  495. #region 编辑用户
  496. string commandText = "UPDATE " + Config.TablePrefix + "Account " +
  497. " SET accountname = accountname1," +
  498. "accountpassword = accountpassword1," +
  499. "accountrealname = accountrealname1," +
  500. "accountphone = accountphone1,roleid = roleid1" +
  501. " ,isdelete = isdelete1" +
  502. ",WxOpenId=WxOpenId1,Sup_OrgId=Sup_OrgId1" +
  503. ",LastModifiedPerson ='" + userid + "'" +
  504. ",LastModified =getdate()" +
  505. " FROM (SELECT @accountname as accountname1,@accountpassword as accountpassword1," +
  506. "@accountrealname as accountrealname1,@accountphone as accountphone1,@roleid as roleid1," +
  507. "@isdelete as isdelete1," +
  508. "@WxOpenId as WxOpenId1,@Sup_OrgId as Sup_OrgId1" +
  509. ") A" +
  510. " WHERE id= @Id";
  511. string result;
  512. //准备参数
  513. List<List<Object>> parameters = new List<List<Object>>();
  514. if (accountName != null)
  515. parameters.Add(new List<Object>() { "accountname", accountName });
  516. if (accountPassWord != null)
  517. parameters.Add(new List<Object>() { "accountpassword", accountPassWord });
  518. if (accountRealName != null)
  519. parameters.Add(new List<Object>() { "accountrealname", accountRealName });
  520. //if (AccountPhone != null)
  521. parameters.Add(new List<Object>() { "accountphone", AccountPhone });
  522. //if (RoleId != 0)
  523. parameters.Add(new List<Object>() { "roleid", RoleId });
  524. if (Sup_OrgId != null || Sup_OrgId != "") { parameters.Add(new List<Object>() { "Sup_OrgId", Sup_OrgId }); };
  525. parameters.Add(new List<Object>() { "isdelete", IsDelete });
  526. parameters.Add(new List<Object>() { "WxOpenId", WxOpenId });
  527. parameters.Add(new List<Object>() { "Id", Id });
  528. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  529. list.Add(new DataAccessCommand(commandText, parameters1, CommandType.Text, true));
  530. //int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  531. #endregion
  532. bool success = DataAccess.ExecuteBatchCommands(list,out result);
  533. return Json(new
  534. {
  535. success = success,
  536. result = result,
  537. });
  538. }
  539. ////删除用户账户
  540. [AuthPermission]
  541. [HttpPost, Route("delete")]
  542. public JsonResult Delete(Int32 Id)
  543. {
  544. List<DataAccessCommand> list = new List<DataAccessCommand>(2);
  545. #region 删除账户
  546. string commandText = "DELETE FROM " + Config.TablePrefix + "Account WHERE Id = @Id";
  547. //准备参数
  548. List<List<Object>> parameters = new List<List<Object>>();
  549. parameters.Add(new List<Object>() { "Id", Id });
  550. string result = "";
  551. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  552. //int successDel = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  553. list.Add(new DataAccessCommand(commandText, parameters1, CommandType.Text, true));
  554. #endregion
  555. bool successDel = DataAccess.ExecuteBatchCommands(list, out result);
  556. return Json(new
  557. {
  558. success = successDel,
  559. msg = result,
  560. successDel = successDel
  561. });
  562. }
  563. [AuthPermission]
  564. [HttpPost]
  565. [Route("modifypwd")]
  566. public JsonResult ModifyPwd(string staffid, [FromBody] PwdTemp data)
  567. {
  568. var userid = getStaffUserid(staffid);
  569. //判断参数是否合法
  570. if (string.IsNullOrEmpty(userid))
  571. {
  572. return Json(new
  573. {
  574. success = false,
  575. msg = "没有登陆"
  576. });
  577. }
  578. var sql0 = "select * from sup_Account where id = @userid";
  579. var param0 = new List<SqlParameter>();
  580. param0.Add(new SqlParameter("userid", int.Parse(userid)));
  581. var dt0 = new DataTable();
  582. DataAccess.GetValues(sql0, ref dt0, param0.ToArray(), out _);
  583. var pwd = string.Empty;
  584. if (dt0 != null && dt0.Rows.Count > 0)
  585. {
  586. pwd = dt0.Rows[0]["AccountPassWord"].ToString();
  587. }
  588. if (data.OldPass != pwd)
  589. {
  590. return Json(new
  591. {
  592. success = false,
  593. msg = "原密码不正确"
  594. });
  595. }
  596. var sql = "update sup_Account set AccountPassWord=@AccountPassWord where Id=@Id";
  597. var param = new List<SqlParameter>();
  598. param.Add(new SqlParameter("AccountPassWord", data.NewPass));
  599. param.Add(new SqlParameter("Id", userid));
  600. if (DataAccess.ExecuteCommand(sql, param, out _) > 0)
  601. {
  602. return Json(new
  603. {
  604. success = true
  605. });
  606. }
  607. return Json(new
  608. {
  609. success = false,
  610. msg = "修改失败"
  611. });
  612. }
  613. [HttpGet]
  614. [Route("login")]
  615. public JsonResult login()
  616. {
  617. return Json(new
  618. {
  619. msg = "没有登陆",
  620. timeout = 1
  621. });
  622. }
  623. [HttpGet]
  624. [Route("noauth")]
  625. public ActionResult noauth()
  626. {
  627. return View();
  628. }
  629. public class PwdTemp
  630. {
  631. public string ConfirmPass { get; set; }
  632. public string NewPass { get; set; }
  633. public string OldPass { get; set; }
  634. }
  635. }
  636. }