UserController.cs 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  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 addp(
  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. #region 添加用户
  370. string commandText = "INSERT INTO " + Config.TablePrefix + "Account (accountname,accountpassword,accountrealname,accountphone,roleid,isdelete,Sup_OrgId)"
  371. + " VALUES (@accountname,@accountpassword,@accountrealname,@accountphone,@roleid,@isdelete,@Sup_OrgId)";
  372. string result;
  373. //准备参数
  374. List<List<Object>> parameters = new List<List<Object>>();
  375. parameters.Add(new List<Object>() { "accountname", accountName });
  376. parameters.Add(new List<Object>() { "accountpassword", accountPassWord });
  377. parameters.Add(new List<Object>() { "accountrealname", accountRealName });
  378. parameters.Add(new List<Object>() { "accountphone", AccountPhone });
  379. parameters.Add(new List<Object>() { "roleid", RoleId });
  380. parameters.Add(new List<Object>() { "isdelete", IsDelete });
  381. parameters.Add(new List<Object>() { "Sup_OrgId", Sup_OrgId });
  382. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  383. int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  384. #endregion
  385. return Json(new
  386. {
  387. success = success
  388. });
  389. }
  390. ////编辑内部管理人员账户,采购员账号
  391. //[AuthPermission]
  392. //[HttpGet, Route("edit")]
  393. //public ActionResult edit(Int32 Id,
  394. // string accountName, string accountPassWord, string accountRealName
  395. // , string AccountPhone, Int32 RoleId
  396. // , string callback, Int32 IsDelete, string WxOpenId
  397. // )
  398. //{
  399. // var r = this.editp(Id,
  400. // accountName, accountPassWord, accountRealName
  401. // , AccountPhone, RoleId
  402. // , callback, null, IsDelete, WxOpenId);
  403. // return Content(callback + "(" + JsonConvert.SerializeObject(r.Value)
  404. // + ")");
  405. //}
  406. [AuthPermission]
  407. [HttpPost, Route("edit")]
  408. public JsonResult editp(Int32 Id,
  409. string accountName, string accountPassWord, string accountRealName
  410. , string AccountPhone, Int32 RoleId
  411. , string callback, [FromBody]dynamic data
  412. , Int32 IsDelete, String WxOpenId
  413. )
  414. {
  415. var userid = getStaff("userid");
  416. //判断参数是否合法
  417. if (string.IsNullOrEmpty(userid))
  418. {
  419. return Json(new
  420. {
  421. success = 0,
  422. msg = "没有登陆",
  423. timeout = 1
  424. });
  425. }
  426. string Sup_OrgId = "";
  427. AccountPhone = "";
  428. if (data != null)
  429. {
  430. //Newtonsoft.Json.Linq.JArray
  431. Id = data.Id;
  432. accountName = data.AccountName;
  433. accountPassWord = data.AccountPassWord;
  434. accountRealName = data.AccountRealName;
  435. AccountPhone = data.AccountPhone;
  436. RoleId = data.RoleId;
  437. IsDelete = data.IsDelete == null ? 0 : data.IsDelete;
  438. WxOpenId = data.WxOpenId;
  439. if (data.Sup_OrgId != null) { Sup_OrgId = data.Sup_OrgId; }
  440. }
  441. //手机号已存在不能添加
  442. #region 获取user
  443. string commandTextUser = "Select Id From " + Config.TablePrefix + "Account Where AccountName=@AccountPhone and Id <> @Id";
  444. string resultUser;
  445. Object value;
  446. List<List<Object>> parametersUser = new List<List<Object>>();
  447. if (accountName != null)
  448. parametersUser.Add(new List<Object>() { "AccountPhone", accountName });
  449. else
  450. {
  451. return Json(new
  452. {
  453. success = 0,
  454. msg = "请填账户名"
  455. });
  456. }
  457. parametersUser.Add(new List<Object>() { "Id", Id });
  458. DataAccess.GetOneValue(commandTextUser, DataAccess.ToParameters(parametersUser), out value, out resultUser);
  459. if (value != null)
  460. {
  461. return Json(new
  462. {
  463. success = 0,
  464. msg = "手机号已存在"
  465. });
  466. }
  467. #endregion
  468. List<DataAccessCommand> list = new List<DataAccessCommand>(2);
  469. #region 编辑用户
  470. string commandText = "UPDATE " + Config.TablePrefix + "Account " +
  471. " SET accountname = accountname1," +
  472. "accountpassword = accountpassword1," +
  473. "accountrealname = accountrealname1," +
  474. "accountphone = accountphone1,roleid = roleid1" +
  475. " ,isdelete = isdelete1" +
  476. ",WxOpenId=WxOpenId1,Sup_OrgId=Sup_OrgId1" +
  477. ",LastModifiedPerson ='" + userid + "'" +
  478. ",LastModified =getdate()" +
  479. " FROM (SELECT @accountname as accountname1,@accountpassword as accountpassword1," +
  480. "@accountrealname as accountrealname1,@accountphone as accountphone1,@roleid as roleid1," +
  481. "@isdelete as isdelete1," +
  482. "@WxOpenId as WxOpenId1,@Sup_OrgId as Sup_OrgId1" +
  483. ") A" +
  484. " WHERE id= @Id";
  485. string result;
  486. //准备参数
  487. List<List<Object>> parameters = new List<List<Object>>();
  488. if (accountName != null)
  489. parameters.Add(new List<Object>() { "accountname", accountName });
  490. if (accountPassWord != null)
  491. parameters.Add(new List<Object>() { "accountpassword", accountPassWord });
  492. if (accountRealName != null)
  493. parameters.Add(new List<Object>() { "accountrealname", accountRealName });
  494. //if (AccountPhone != null)
  495. parameters.Add(new List<Object>() { "accountphone", AccountPhone });
  496. //if (RoleId != 0)
  497. parameters.Add(new List<Object>() { "roleid", RoleId });
  498. if (Sup_OrgId != null || Sup_OrgId != "") { parameters.Add(new List<Object>() { "Sup_OrgId", Sup_OrgId }); };
  499. parameters.Add(new List<Object>() { "isdelete", IsDelete });
  500. parameters.Add(new List<Object>() { "WxOpenId", WxOpenId });
  501. parameters.Add(new List<Object>() { "Id", Id });
  502. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  503. list.Add(new DataAccessCommand(commandText, parameters1, CommandType.Text, true));
  504. //int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  505. #endregion
  506. #region 编辑ContactDoc
  507. string commandTextC = "UPDATE ContactDoc " +
  508. " SET " +
  509. " focusMicNo=@WxOpenId," +
  510. " UserId= @UserId" +
  511. " WHERE Mobile = @Mobile";
  512. string resultC;
  513. //准备参数
  514. List<List<Object>> parametersC = new List<List<Object>>();
  515. parametersC.Add(new List<Object>() { "WxOpenId", WxOpenId });
  516. parametersC.Add(new List<Object>() { "UserId", Id });
  517. parametersC.Add(new List<Object>() { "Mobile", AccountPhone });
  518. List<SqlParameter> parametersC1 = DataAccess.ToParameters(parametersC);
  519. int successC = DataAccess.ExecuteCommand(commandTextC, parametersC1, out resultC);
  520. //list.Add(new DataAccessCommand(commandTextC, parametersC1,CommandType.Text,true) );
  521. #endregion
  522. bool success = DataAccess.ExecuteBatchCommands(list,out result);
  523. return Json(new
  524. {
  525. success = success,
  526. result = result,
  527. });
  528. }
  529. //////业务员用户列表
  530. //[HttpGet, Route("salesman")]
  531. //public ActionResult Salesman(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
  532. // string sortField, Int32 sortDirection, string[] sumFields, string callback)
  533. //{
  534. // var r = this.Salesmanp(filters, pageIndex, pageSize,
  535. // sortField, sortDirection, sumFields,null);
  536. // return Content(callback + "(" + JsonConvert.SerializeObject(r.Value)
  537. // + ")");
  538. //}
  539. ////业务员用户列表
  540. [AuthPermission]
  541. [HttpPost, Route("salesman")]
  542. public JsonResult Salesmanp(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
  543. string sortField, Int32 sortDirection, string[] sumFields, [FromBody]dynamic data)
  544. {
  545. string LoginAccountId;
  546. string userid = LoginAccountId = getStaff("userid");
  547. string RoleId = getStaff("roleid");
  548. //判断参数是否合法
  549. if (string.IsNullOrEmpty(userid))
  550. {
  551. return Json(new
  552. {
  553. timeout = 1,
  554. msg = "没有登陆"
  555. });
  556. }
  557. if (data != null)
  558. {
  559. //Newtonsoft.Json.Linq.JArray
  560. filters = data.filters.ToObject<QueryFilter[]>();
  561. pageIndex = data.pageIndex;
  562. pageSize = data.pageSize;
  563. sortField = data.sortField;
  564. sortDirection = data.sortDirection;
  565. sumFields = data.sumFields.ToObject<string[]>();
  566. }
  567. List<SqlParameter> parameters1 = new List<SqlParameter>();
  568. string filterstring = QueryFilter.getFilterSqlParam(filters, out parameters1, new Account(),"A.");
  569. filterstring = filterstring.Replace("A.Creater","B.AccountRealName");
  570. filterstring = filterstring.Replace("A.StaffName", "K.StaffName");
  571. sortField = sortField.Replace("Pk","Id");
  572. #region 获取业务员
  573. DataTable dt = new DataTable();
  574. string result = string.Empty;
  575. string direct = " desc ";
  576. if (sortDirection != 1)
  577. direct = " asc";
  578. int start = (pageIndex - 1) * pageSize;
  579. int end = (start + 1 + pageSize);
  580. string permission = string.Empty;
  581. //if (RoleId == "1" || RoleId == "6" || RoleId == "7")
  582. //{
  583. // permission = "";
  584. //}
  585. //else if (RoleId == "2")
  586. //{
  587. // permission = " and A.CreationPerson = '" + userid + "' ";
  588. //}
  589. string StaffDocId = StaffDocDAL.GetStaffId(LoginAccountId);
  590. permission = ((RoleId == "1" || RoleId == "6" || RoleId == "7") ? "" : (" and K.SaleManId = '" + StaffDocId + "' "));//只查询当前采购员的联系人
  591. string commandText = "select * from " ;
  592. string commandText0 =
  593. "(select AA.*,row_number() over (order by AA." + sortField + " " + direct + " ) as rownum from (" +
  594. "select distinct K.StaffName,concat(A.Id,K.StaffName) as Pk,A.*,B.AccountRealName As Creater," +
  595. "isnull(A1.OrgId,'') as OrgId," +
  596. "row_number() over" +
  597. "( partition by A.id order by A." + sortField + " " + direct + " ) as rn"+
  598. " from " + Config.TablePrefix + "Account A " +
  599. " left join OrgDoc A1 on A1.K_UserId = A.Id and A1.EntId='E1WB67UEYPG' " +
  600. " left join "+Config.TablePrefix+"Account B on A.CreationPerson = B.id" +
  601. " left join ContactDoc D on D.UserId = A.Id "+
  602. //" left join K_SaleContact K on K.K_ContactId = D.ContactId " +
  603. //" left join StaffDoc J on K.SaleManId = J.StaffId " +
  604. " left join " +
  605. "(select distinct a.ContactId,a.SaleManId,b.StaffName from K_ContactSP a left join StaffDoc b on b.STAFFID = a.SaleManId )" +
  606. " K on K.ContactId = D.ContactId " + filterstring.Replace("K.SaleManId","a.SaleManId") +
  607. " where A.roleid = 3 " +
  608. permission +
  609. filterstring +
  610. ")AA where AA.rn = 1)AAA " +
  611. "";
  612. string commandText1 =
  613. " where 1 = 1 " +
  614. "and AAA.rownum>" + start + " and AAA.rownum<" + end +
  615. " ";
  616. bool result1 = DataAccess.GetValues(commandText + commandText0 + commandText1, ref dt, parameters1.ToArray(), out result);
  617. IList<Account> users = new List<Account>();
  618. if (dt != null && dt.Rows.Count > 0)
  619. {
  620. // 把DataTable转换为IList<UserInfo>
  621. users = ModelConvertHelper<Account>.ConvertToModel(dt);
  622. }
  623. #endregion
  624. #region 获取角色
  625. IList<Role> roles = RoleDAL.GetRoles();
  626. // 把DataTable转换为IList<Role>
  627. if (roleMap.Count < roles.Count)
  628. {
  629. foreach (Role role in roles)
  630. {
  631. roleMap.TryAdd(role.Id, role);
  632. }
  633. }
  634. foreach (Account user in users)
  635. {
  636. Role role;
  637. if (roleMap.TryGetValue(user.RoleId, out role))
  638. {
  639. user.RoleName = role.RoleRemark;
  640. }
  641. }
  642. #endregion
  643. string resultrow;
  644. long totalcount = DataAccess.GetRowCountDefine("select count(1) from " + commandText0, parameters1.ToArray(), out resultrow);
  645. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  646. {
  647. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  648. };
  649. var jsonData = JsonConvert.SerializeObject(users, timejson);
  650. return Json(new
  651. {
  652. items = JsonConvert.DeserializeObject(jsonData),
  653. sum = new { },
  654. totalCount = totalcount,
  655. msg = result,
  656. msgcount = resultrow
  657. });
  658. }
  659. ////删除用户账户
  660. [AuthPermission]
  661. [HttpPost, Route("delete")]
  662. public JsonResult Delete(Int32 Id)
  663. {
  664. List<DataAccessCommand> list = new List<DataAccessCommand>(2);
  665. #region 删除账户关联
  666. string commandTextRelate = "UPDATE ContactDoc SET UserId='',focusMicNo='' WHERE UserId = @Id";
  667. //准备参数
  668. List<List<Object>> parametersRelate = new List<List<Object>>();
  669. parametersRelate.Add(new List<Object>() { "Id", Id });
  670. List<SqlParameter> parametersRelate1 = DataAccess.ToParameters(parametersRelate);
  671. //int successRelate = DataAccess.ExecuteCommand(commandTextRelate, parametersRelate1, out resultRelate);
  672. list.Add(new DataAccessCommand(commandTextRelate, parametersRelate1,CommandType.Text,false));
  673. #endregion
  674. #region 删除账户
  675. string commandText = "DELETE FROM " + Config.TablePrefix + "Account WHERE Id = @Id";
  676. //准备参数
  677. List<List<Object>> parameters = new List<List<Object>>();
  678. parameters.Add(new List<Object>() { "Id", Id });
  679. string result = "";
  680. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  681. //int successDel = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  682. list.Add(new DataAccessCommand(commandText, parameters1, CommandType.Text, true));
  683. #endregion
  684. bool successDel = DataAccess.ExecuteBatchCommands(list, out result);
  685. return Json(new
  686. {
  687. success = successDel,
  688. msg = result,
  689. successDel = successDel
  690. });
  691. }
  692. ////待推送联系人列表-包括未建立账户的
  693. [AuthPermission]
  694. [HttpPost, Route("pushcontacts")]
  695. public JsonResult PushContacts(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
  696. string sortField, Int32 sortDirection, string[] sumFields, [FromBody]dynamic data)
  697. {
  698. string LoginAccountId;
  699. string userid = LoginAccountId = getStaff("userid");
  700. string RoleId = getStaff("roleid");
  701. //判断参数是否合法
  702. if (string.IsNullOrEmpty(userid))
  703. {
  704. return Json(new
  705. {
  706. items = new string[] { },
  707. sum = new { },
  708. totalCount = 0,
  709. timeout = 1,
  710. msg = "没有登陆"
  711. });
  712. }
  713. if (data != null)
  714. {
  715. //Newtonsoft.Json.Linq.JArray
  716. filters = data.filters.ToObject<QueryFilter[]>();
  717. pageIndex = data.pageIndex;
  718. pageSize = data.pageSize;
  719. sortField = data.sortField;
  720. sortDirection = data.sortDirection;
  721. sumFields = data.sumFields.ToObject<string[]>();
  722. }
  723. #region 获取user
  724. if (filters == null || filters.Length == 0)
  725. {
  726. return Json(new
  727. {
  728. items = new string[] { },
  729. sum = new { },
  730. totalCount = 0
  731. });
  732. }
  733. DataTable dt = new DataTable();
  734. string result = string.Empty;
  735. List<SqlParameter> parameters1 = new List<SqlParameter>();
  736. string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters1, new ContactDocExt(),"A.");
  737. filterstr = filterstr.Replace("A.BusinessName", "B.BusinessName");
  738. //string StaffDocId = StaffDocDAL.GetStaffId(LoginAccountId);
  739. //filterstr += ((RoleId == "1" || RoleId == "6" || RoleId == "7") ? "" : (" and K.SaleManId = '" + StaffDocId + "' "));
  740. string direct = " desc ";
  741. if (sortDirection != 1)
  742. direct = " asc";
  743. int start = (pageIndex - 1) * pageSize;
  744. int end = (start + 1 + pageSize);
  745. string rulefilter = FilterTranslator.ruleSql(ref parameters1);
  746. string commandText0 = "select * from (";
  747. string commandText1 =
  748. "select A.*,B.BusinessName,row_number() over" +
  749. "( order by ContactId " + direct + " ) as rownum" +
  750. " from " + "ContactDoc A " +
  751. " left join BusinessDoc B on A.BusinessId = B.BusinessId " +
  752. " where 1= 1 " +
  753. filterstr +
  754. rulefilter+
  755. //" where A.contactid in (select contactid from k_contactsp ) " +
  756. ")AAA";
  757. string commandText2 =
  758. " where AAA.rownum>" + start + " and AAA.rownum<" + end +
  759. " ";
  760. //string connectstr = "Data Source =192.168.50.30; Initial Catalog = LJHYBZK; Persist Security Info = True; User ID = sa; Password = xq!@#2014;Pooling=true;MAX Pool Size=512;Min Pool Size=50;Connection Lifetime=30";
  761. bool result1 = DataAccess.GetValues(commandText0 + commandText1 + commandText2, ref dt, parameters1.ToArray(), out result);
  762. #endregion
  763. // 把DataTable转换为IList<UserInfo>
  764. IList<ContactDocExt> users = new List<ContactDocExt>();
  765. if (dt != null && dt.Rows.Count > 0)
  766. {
  767. // 把DataTable转换为IList<UserInfo>
  768. users = ModelConvertHelper<ContactDocExt>.ConvertToModel(dt);
  769. }
  770. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  771. {
  772. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  773. };
  774. var jsonData = JsonConvert.SerializeObject(users, timejson);
  775. string resultrow;
  776. long totalcount = DataAccess.GetRowCountDefine("select count(*) from (" + commandText1,
  777. parameters1.ToArray(), out resultrow);
  778. return Json(new
  779. {
  780. items = JsonConvert.DeserializeObject(jsonData),
  781. sum = new { },
  782. totalCount = totalcount
  783. });
  784. }
  785. ////内部人员列表-包括未建立账户的
  786. [AuthPermission]
  787. [HttpPost, Route("pushstaffs")]
  788. public JsonResult PushStaffs(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
  789. string sortField, Int32 sortDirection, string[] sumFields, [FromBody]dynamic data)
  790. {
  791. if (data != null)
  792. {
  793. //Newtonsoft.Json.Linq.JArray
  794. filters = data.filters.ToObject<QueryFilter[]>();
  795. pageIndex = data.pageIndex;
  796. pageSize = data.pageSize;
  797. sortField = data.sortField;
  798. sortDirection = data.sortDirection;
  799. sumFields = data.sumFields.ToObject<string[]>();
  800. }
  801. #region 获取user
  802. DataTable dt = new DataTable();
  803. string result = string.Empty;
  804. string direct = " desc ";
  805. if (sortDirection != 1)
  806. direct = " asc";
  807. int start = (pageIndex - 1) * pageSize;
  808. int end = (start + 1 + pageSize);
  809. List<SqlParameter> parameters1 = new List<SqlParameter>();
  810. string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters1, new StaffDoc());
  811. filterstr = filterstr.Replace("and ","and C.");
  812. string commandText0 = "select * from (";
  813. string commandText1 =
  814. "select C.*, row_number() over" +
  815. "( order by C.StaffId " + direct + " ) as rownum" +
  816. " from " + "StaffDOC C " +
  817. " where 1=1 " +
  818. //" where A.StaffId = C.StaffId " +
  819. filterstr +
  820. ")AAA";
  821. string commandText2 =
  822. " where AAA.rownum>" + start + " and AAA.rownum<" + end +
  823. " ";
  824. //string connectstr = "Data Source =192.168.50.30; Initial Catalog = LJHYBZK; Persist Security Info = True; User ID = sa; Password = xq!@#2014;Pooling=true;MAX Pool Size=512;Min Pool Size=50;Connection Lifetime=30";
  825. bool result1 = DataAccess.GetValues(commandText0 + commandText1 + commandText2, ref dt, parameters1.ToArray(), out result);
  826. #endregion
  827. // 把DataTable转换为IList<UserInfo>
  828. IList<StaffDoc> users = new List<StaffDoc>();
  829. if (dt != null && dt.Rows.Count > 0)
  830. {
  831. // 把DataTable转换为IList<StaffDoc>
  832. users = ModelConvertHelper<StaffDoc>.ConvertToModel(dt);
  833. foreach (StaffDoc user in users)
  834. {
  835. user.AccountPassWord = RandHelper.GenerateRandomCode(5);
  836. }
  837. }
  838. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  839. {
  840. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  841. };
  842. var jsonData = JsonConvert.SerializeObject(users, timejson);
  843. string resultrow;
  844. long totalcount = DataAccess.GetRowCountDefine("select count(*) from (" + commandText1,
  845. parameters1.ToArray(), out resultrow);
  846. return Json(new
  847. {
  848. items = JsonConvert.DeserializeObject(jsonData),
  849. sum = new { },
  850. totalCount = totalcount
  851. });
  852. }
  853. ////待推送联系人
  854. [AuthPermission]
  855. [HttpPost, Route("pendingcontacts")]
  856. public JsonResult PendingContacts(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
  857. string sortField, Int32 sortDirection, string[] sumFields, [FromBody]dynamic data)
  858. {
  859. if (data != null)
  860. {
  861. //Newtonsoft.Json.Linq.JArray
  862. filters = data.filters.ToObject<QueryFilter[]>();
  863. pageIndex = data.pageIndex;
  864. pageSize = data.pageSize;
  865. sortField = data.sortField;
  866. sortDirection = data.sortDirection;
  867. sumFields = data.sumFields.ToObject<string[]>();
  868. }
  869. #region 获取待推联系人
  870. DataTable dt = new DataTable();
  871. string result = string.Empty;
  872. string direct = " desc ";
  873. if (sortDirection != 1)
  874. direct = " asc";
  875. int start = (pageIndex - 1) * pageSize;
  876. int end = (start + 1 + pageSize);
  877. List<SqlParameter> parameters1 = new List<SqlParameter>();
  878. string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters1, new PushContactWithGoods());
  879. IList<PushContactWithGoods> users = new List<PushContactWithGoods>();
  880. Int64 totalcount = 0;
  881. //跨库 获取存储上下限
  882. IList<PushStorLimit> limits = PushRecordDAL.GetPushLimit();
  883. if (limits.Count > 0)
  884. {
  885. List<string> superior_list = new List<string>(0);
  886. foreach (PushStorLimit limit in limits)
  887. {
  888. //Role role;
  889. //if (roleMap.TryGetValue(permsr.RoleId, out role))
  890. //{
  891. // listRoles.Add(role);
  892. //}
  893. superior_list.Add(limit.GoodsId);
  894. }
  895. //perms.RoleList = listRoles;
  896. string limitss = string.Join("','", superior_list.ToArray());
  897. string commandText0 = "select * from (";
  898. string commandText1 = "select *, row_number() over" +
  899. "(order by ContactCode " + direct + " ) as rownum " +
  900. " FROM(SELECT ROW_NUMBER() OVER(PARTITION BY t1.GoodsId,t1.ContactId ORDER BY t1.Sysdates1 DESC,t1.LastPrice ASC) AS RNUM," +
  901. " * " +
  902. "FROM sup_PushContactWithGoods t1" +
  903. " WHERE exists(" +
  904. " select 1 from LJHYBZK.dbo.sup_PushStorLimit A " +
  905. " where A.GoodsId = t1.GoodsId)" +
  906. //" WHERE t1.GoodsId IN ('" +
  907. //limitss +
  908. //" ')" +
  909. filterstr +
  910. ") AS T " +
  911. " WHERE T.RNUM = 1" +
  912. ")AAA";
  913. string commandText2 = commandText0 + commandText1 + " where AAA.rownum>" + start + " and AAA.rownum<" + end +
  914. " ";
  915. //string connectstr = "Data Source =192.168.50.30; Initial Catalog = LJHYBZK; Persist Security Info = True; User ID = sa; Password = xq!@#2014;Pooling=true;MAX Pool Size=512;Min Pool Size=50;Connection Lifetime=30";
  916. //bool result1 = DataAccess.GetValues(connectstr, commandText, ref dt, parameters1.ToArray(), out result);
  917. bool result1 = DataAccess.GetValues(commandText2, ref dt, parameters1.ToArray(), out result);
  918. #endregion
  919. // 把DataTable转换为IList<UserInfo>
  920. if (dt != null && dt.Rows.Count > 0)
  921. {
  922. // 把DataTable转换为IList<UserInfo>
  923. users = ModelConvertHelper<PushContactWithGoods>.ConvertToModel(dt);
  924. foreach (PushContactWithGoods user in users)
  925. {
  926. user.AccountPassword = RandHelper.GenerateRandomCode(5);
  927. }
  928. }
  929. string resultrow;
  930. string commandTextRowCount = "select count(*) from (" + commandText1;
  931. //totalcount = DataAccess.GetRowCountDefine(connectstr, commandTextRowCount, out resultrow);
  932. totalcount = DataAccess.GetRowCountDefine(commandTextRowCount, out resultrow);
  933. }
  934. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  935. {
  936. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  937. };
  938. var jsonData = JsonConvert.SerializeObject(users, timejson);
  939. return Json(new
  940. {
  941. items = JsonConvert.DeserializeObject(jsonData),
  942. sum = new { },
  943. totalCount = totalcount
  944. });
  945. }
  946. ////添加联系人和账户(Account)的关联,如果没有手机号,电话填写手机号,电话
  947. [AuthPermission]
  948. [HttpPost, Route("addContact")]
  949. public JsonResult addContact(
  950. string ContactId, string Contact, string Telephone
  951. , string Mobile, string AccountPassword
  952. , [FromBody]dynamic data
  953. )
  954. {
  955. string userid = getStaffUserid("");
  956. //判断参数是否合法
  957. if (string.IsNullOrEmpty(userid))
  958. {
  959. return Json(new
  960. {
  961. success = 0,
  962. msg = "没有登陆"
  963. });
  964. }
  965. string accountname = "";
  966. string accountphone = "";
  967. string FocusMicNo = "";
  968. if (data != null)
  969. {
  970. ContactId = data.ContactId;
  971. Contact = data.Contact;
  972. Telephone = data.Telephone;
  973. Mobile = data.Mobile;
  974. AccountPassword = data.AccountPassword;
  975. FocusMicNo = data.FocusMicNo;
  976. }
  977. //Newtonsoft.Json.Linq.JArray
  978. if (data.Mobile != null)
  979. accountname = data.Mobile;
  980. else if (data.Telephone != null)
  981. accountname = data.Telephone;
  982. if (data.Mobile != null)
  983. accountphone = data.Mobile;
  984. else if (data.Telephone != null)
  985. accountphone = data.Telephone;
  986. //手机号已存在不能添加 ,只能建立和货商的绑定关系
  987. #region 获取user
  988. string commandTextUser = "Select Id,roleId,accountName,AccountPhone,WxOpenId From " + Config.TablePrefix + "Account Where AccountName=@AccountPhone";
  989. string resultUser;
  990. DataTable value = new DataTable();
  991. List<List<Object>> parametersUser = new List<List<Object>>();
  992. if (accountphone != null)
  993. parametersUser.Add(new List<Object>() { "AccountPhone", accountphone });
  994. DataAccess.GetValues(commandTextUser, ref value, DataAccess.ToParameters(parametersUser).ToArray(), out resultUser);
  995. if (value != null && value.Rows.Count > 0 )
  996. {
  997. //return Json(new
  998. //{
  999. // success = 0,
  1000. // msg = "手机号已存在"
  1001. //});建立和货商的绑定关系
  1002. #region 添加联系人和账户(Account)的关联 姓名 手机号(或者电话) 必须唯一代表一个联系人
  1003. string commandTextNewSupp = "UPDATE ContactDoc "
  1004. + " SET " +
  1005. " FocusMicNo = @FocusMicNo," +
  1006. " UserId = @AccountId " +
  1007. " where 1 = 1 " +
  1008. " and Mobile = @Mobile";
  1009. //准备参数
  1010. List<List<Object>> parametersNewSupp = new List<List<Object>>();
  1011. parametersNewSupp.Add(new List<Object>() { "AccountId", (int)value.Rows[0]["Id"] });
  1012. parametersNewSupp.Add(new List<Object>() { "FocusMicNo", value.Rows[0]["WxOpenId"].ToString() });
  1013. parametersNewSupp.Add(new List<Object>() { "Mobile", Mobile });
  1014. string resultNewSupp;
  1015. List<SqlParameter> parametersNewSupp1 = DataAccess.ToParameters(parametersNewSupp);
  1016. int successNewSupp = DataAccess.ExecuteCommand(commandTextNewSupp, parametersNewSupp1, out resultNewSupp);
  1017. #endregion
  1018. int successR = 1;
  1019. if (resultNewSupp.IndexOf("错误") > 0)
  1020. successR = 0;
  1021. string msg = (successR == 0)? resultNewSupp:"添加关联成功";
  1022. return Json(new
  1023. {
  1024. success = successR,
  1025. msg = msg
  1026. });
  1027. }
  1028. #endregion
  1029. #region 添加用户
  1030. string commandText = "INSERT INTO " + Config.TablePrefix + "Account (accountname,AccountPassword,accountrealname,accountphone,roleid,isdelete,CreationPerson)"
  1031. + " VALUES (@accountname,@AccountPassword,@accountrealname,@accountphone,@roleid,@isdelete,@CreationPerson)";
  1032. string result;
  1033. //准备参数
  1034. List<List<Object>> parameters = new List<List<Object>>();
  1035. parameters.Add(new List<Object>() { "accountname", accountname });
  1036. parameters.Add(new List<Object>() { "AccountPassword", AccountPassword });
  1037. parameters.Add(new List<Object>() { "accountrealname", Contact });
  1038. parameters.Add(new List<Object>() { "accountphone", accountphone });
  1039. parameters.Add(new List<Object>() { "roleid", 3 });
  1040. parameters.Add(new List<Object>() { "isdelete", 0 });
  1041. parameters.Add(new List<Object>() { "CreationPerson", userid });
  1042. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  1043. int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  1044. #endregion
  1045. //取id
  1046. int Id = BaseDAL.GetId(Config.TablePrefix + "Account");
  1047. #region 添加联系人和账户(Account)的关联 姓名 手机号(或者电话) 必须唯一代表一个联系人
  1048. string commandTextRelate = "UPDATE ContactDoc "
  1049. + " SET " +
  1050. " UserId = @AccountId " +
  1051. " where 1 = 1 " +
  1052. " and ( Contact = @Contact " +
  1053. " and Case Mobile when '' then '/' else Mobile end = Case @Mobile when '' then '/' else @Mobile end )" +
  1054. " or (Contact = @Contact" +
  1055. " and Case Telephone when '' then '/' else Telephone end = Case @Telephone when '' then '/' else @Telephone end )";
  1056. string resultRelate;
  1057. //准备参数
  1058. List<List<Object>> parametersRelate = new List<List<Object>>();
  1059. parametersRelate.Add(new List<Object>() { "AccountId", Id });
  1060. //parametersRelate.Add(new List<Object>() { "ContactId", ContactId });
  1061. parametersRelate.Add(new List<Object>() { "Contact", Contact });
  1062. parametersRelate.Add(new List<Object>() { "Mobile", Mobile });
  1063. parametersRelate.Add(new List<Object>() { "Telephone", Telephone });
  1064. List<SqlParameter> parametersRelate1 = DataAccess.ToParameters(parametersRelate);
  1065. int successRelate = DataAccess.ExecuteCommand(commandTextRelate, parametersRelate1, out resultRelate);
  1066. #endregion
  1067. return Json(new
  1068. {
  1069. success = success,
  1070. successRelate = successRelate
  1071. });
  1072. }
  1073. [AuthPermission]
  1074. [HttpPost]
  1075. [Route("modifypwd")]
  1076. public JsonResult ModifyPwd(string staffid, [FromBody] PwdTemp data)
  1077. {
  1078. var userid = getStaffUserid(staffid);
  1079. //判断参数是否合法
  1080. if (string.IsNullOrEmpty(userid))
  1081. {
  1082. return Json(new
  1083. {
  1084. success = false,
  1085. msg = "没有登陆"
  1086. });
  1087. }
  1088. var sql0 = "select * from sup_Account where id = @userid";
  1089. var param0 = new List<SqlParameter>();
  1090. param0.Add(new SqlParameter("userid", int.Parse(userid)));
  1091. var dt0 = new DataTable();
  1092. DataAccess.GetValues(sql0, ref dt0, param0.ToArray(), out _);
  1093. var pwd = string.Empty;
  1094. if (dt0 != null && dt0.Rows.Count > 0)
  1095. {
  1096. pwd = dt0.Rows[0]["AccountPassWord"].ToString();
  1097. }
  1098. if (data.OldPass != pwd)
  1099. {
  1100. return Json(new
  1101. {
  1102. success = false,
  1103. msg = "原密码不正确"
  1104. });
  1105. }
  1106. var sql = "update sup_Account set AccountPassWord=@AccountPassWord where Id=@Id";
  1107. var param = new List<SqlParameter>();
  1108. param.Add(new SqlParameter("AccountPassWord", data.NewPass));
  1109. param.Add(new SqlParameter("Id", userid));
  1110. if (DataAccess.ExecuteCommand(sql, param, out _) > 0)
  1111. {
  1112. return Json(new
  1113. {
  1114. success = true
  1115. });
  1116. }
  1117. return Json(new
  1118. {
  1119. success = false,
  1120. msg = "修改失败"
  1121. });
  1122. }
  1123. [HttpGet]
  1124. [Route("login")]
  1125. public JsonResult login()
  1126. {
  1127. return Json(new
  1128. {
  1129. msg = "没有登陆",
  1130. timeout = 1
  1131. });
  1132. }
  1133. [HttpGet]
  1134. [Route("noauth")]
  1135. public ActionResult noauth()
  1136. {
  1137. return View();
  1138. }
  1139. public class PwdTemp
  1140. {
  1141. public string ConfirmPass { get; set; }
  1142. public string NewPass { get; set; }
  1143. public string OldPass { get; set; }
  1144. }
  1145. }
  1146. }