StoreHouseController.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. /*
  2. * 仓库
  3. */
  4. using System;
  5. using System.Web;
  6. using System.Collections.Generic;
  7. using System.Diagnostics;
  8. using System.Linq;
  9. using System.Data;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using Microsoft.AspNetCore.Mvc;
  13. using Microsoft.AspNetCore.Http;
  14. using Microsoft.Extensions.Logging;
  15. using Microsoft.Extensions.Options;
  16. using MySystem.Models;
  17. using Library;
  18. using LitJson;
  19. using MySystemLib;
  20. namespace MySystem.Areas.Admin.Controllers
  21. {
  22. [Area("Admin")]
  23. [Route("Admin/[controller]/[action]")]
  24. public class StoreHouseController : BaseController
  25. {
  26. public StoreHouseController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  27. {
  28. OtherMySqlConn.connstr = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  29. }
  30. #region 仓库列表
  31. /// <summary>
  32. /// 根据条件查询仓库列表
  33. /// </summary>
  34. /// <returns></returns>
  35. public IActionResult Index(StoreHouse data, string right)
  36. {
  37. ViewBag.RightInfo = RightInfo;
  38. ViewBag.right = right;
  39. return View();
  40. }
  41. #endregion
  42. #region 根据条件查询仓库列表
  43. /// <summary>
  44. /// 仓库列表
  45. /// </summary>
  46. /// <returns></returns>
  47. public JsonResult IndexData(StoreHouse data, string UserIdMakerCode, string UserIdRealName, string ManageUserIdRealName, string ManageUserIdMobile, string ManageUserIdMakerCode, string StoreStatusSelect, int page = 1, int limit = 30)
  48. {
  49. Dictionary<string, string> Fields = new Dictionary<string, string>();
  50. Fields.Add("StoreNo", "1"); //仓库编号
  51. Fields.Add("CreateDate", "3"); //时间
  52. Fields.Add("StoreName", "1"); //仓库名称
  53. Fields.Add("ManagerEmail", "1"); //管理者邮箱
  54. string condition = " and Status>-1";
  55. //仓库归属人创客编号
  56. if (!string.IsNullOrEmpty(UserIdMakerCode))
  57. {
  58. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  59. }
  60. //仓库归属人真实姓名
  61. if (!string.IsNullOrEmpty(UserIdRealName))
  62. {
  63. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  64. }
  65. //仓库管理员真实姓名
  66. if (!string.IsNullOrEmpty(ManageUserIdRealName))
  67. {
  68. condition += " and ManageUserId in (select ManageUserId from UserForRealName where RealName='" + ManageUserIdRealName + "')";
  69. }
  70. //仓库管理员手机号
  71. if (!string.IsNullOrEmpty(ManageUserIdMobile))
  72. {
  73. condition += " and ManageUserId in (select ManageUserId from UserForMobile where Mobile='" + ManageUserIdMobile + "')";
  74. }
  75. //仓库管理员创客编号
  76. if (!string.IsNullOrEmpty(ManageUserIdMakerCode))
  77. {
  78. condition += " and ManageUserId in (select ManageUserId from UserForMakerCode where MakerCode='" + ManageUserIdMakerCode + "')";
  79. }
  80. //仓库状态
  81. if (!string.IsNullOrEmpty(StoreStatusSelect))
  82. {
  83. condition += " and StoreStatus=" + StoreStatusSelect;
  84. }
  85. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("StoreHouse", Fields, "Id desc", "0", page, limit, condition);
  86. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  87. foreach (Dictionary<string, object> dic in diclist)
  88. {
  89. //仓库归属人
  90. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  91. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  92. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  93. dic["UserIdRealName"] = userid_Users.RealName;
  94. //产品类型
  95. dic["BrandId"] = RelationClass.GetKqProductBrandList(dic["BrandId"].ToString());
  96. //仓库管理员
  97. int ManageUserId = int.Parse(function.CheckInt(dic["ManageUserId"].ToString()));
  98. Users manageuserid_Users = db.Users.FirstOrDefault(m => m.Id == ManageUserId) ?? new Users();
  99. dic["ManageUserIdRealName"] = manageuserid_Users.RealName;
  100. dic["ManageUserIdMobile"] = manageuserid_Users.Mobile;
  101. dic["ManageUserIdMakerCode"] = manageuserid_Users.MakerCode;
  102. //仓库类型
  103. int StoreType = int.Parse(dic["StoreType"].ToString());
  104. if (StoreType == 0) dic["StoreType"] = "实体仓";
  105. if (StoreType == 1) dic["StoreType"] = "虚拟仓";
  106. //仓库状态
  107. int StoreStatus = int.Parse(dic["StoreStatus"].ToString());
  108. if (StoreStatus == 1) dic["StoreStatus"] = "启用";
  109. if (StoreStatus == 0) dic["StoreStatus"] = "禁用";
  110. //仓库归属类型
  111. int StoreKind = int.Parse(dic["StoreKind"].ToString());
  112. if (StoreKind == 0) dic["StoreKind"] = "分仓";
  113. if (StoreKind == 1) dic["StoreKind"] = "总仓";
  114. }
  115. return Json(obj);
  116. }
  117. #endregion
  118. #region 增加仓库
  119. /// <summary>
  120. /// 增加或修改仓库信息
  121. /// </summary>
  122. /// <returns></returns>
  123. public IActionResult Add(string right)
  124. {
  125. ViewBag.RightInfo = RightInfo;
  126. ViewBag.right = right;
  127. return View();
  128. }
  129. #endregion
  130. #region 增加仓库
  131. /// <summary>
  132. /// 增加或修改仓库信息
  133. /// </summary>
  134. /// <returns></returns>
  135. [HttpPost]
  136. public string Add(StoreHouse data, string ManageMakerCode, string MakerCode)
  137. {
  138. string BrandIdString = data.BrandId;
  139. if (!string.IsNullOrEmpty(BrandIdString))
  140. {
  141. string[] BrandIdList = BrandIdString.Split(',');
  142. foreach (string BrandId in BrandIdList)
  143. {
  144. Dictionary<string, object> Fields = new Dictionary<string, object>();
  145. Fields.Add("StoreName", data.StoreName); //仓库名称
  146. UserForMakerCode user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  147. if (user == null)
  148. {
  149. return "您输入的仓库归属创客编号不存在,请重新输入正确的仓库归属创客编号";
  150. }
  151. Fields.Add("UserId", user.UserId); //仓库归属人
  152. Fields.Add("Areas", data.Areas); //所属地区
  153. Fields.Add("Address", data.Address); //仓库地址
  154. UserForMakerCode manage = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ManageMakerCode);
  155. if (manage == null)
  156. {
  157. return "您输入的仓库负责人编号不存在,请重新输入正确的仓库负责人编号";
  158. }
  159. Fields.Add("ManageUserId", manage.UserId); //仓库管理员
  160. Fields.Add("ManagerEmail", data.ManagerEmail); //管理者邮箱
  161. Fields.Add("ManageMobile", data.ManageMobile);
  162. Fields.Add("Remark", data.Remark); //备注
  163. Fields.Add("LimitTopUserId", data.LimitTopUserId); //限制创客特殊仓库
  164. Fields.Add("StoreKind", data.StoreKind); //仓库归属类型
  165. int bid = int.Parse(BrandId);
  166. KqProducts pro = db.KqProducts.FirstOrDefault(m => m.Id == bid) ?? new KqProducts();
  167. Fields.Add("BrandId", BrandId);
  168. Fields.Add("ProductName", pro.Name);
  169. Fields.Add("StoreStatus", 1);
  170. Fields.Add("Status", 1);
  171. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("StoreHouse", Fields, 0);
  172. StoreHouse edit = db.StoreHouse.FirstOrDefault(m => m.Id == Id);
  173. if (edit != null)
  174. {
  175. string No = Id.ToString();
  176. for (int i = 0; i < 7 - Id.ToString().Length; i++)
  177. {
  178. No = "0" + No;
  179. }
  180. No = "S" + No;
  181. edit.StoreNo = No;
  182. db.StoreForCode.Add(new StoreForCode()
  183. {
  184. Code = No,
  185. StoreId = Id,
  186. });
  187. RedisDbconn.Instance.Set("StoreForCode:" + No, Id);
  188. }
  189. db.StoreForName.Add(new StoreForName()
  190. {
  191. Name = data.StoreName,
  192. StoreId = Id,
  193. });
  194. RedisDbconn.Instance.Set("StoreForName:" + data.StoreName, Id);
  195. AddSysLog(data.Id.ToString(), "StoreHouse", "add");
  196. db.SaveChanges();
  197. SetRedis(Id, user.UserId);
  198. }
  199. }
  200. return "success";
  201. }
  202. #endregion
  203. #region 修改仓库
  204. /// <summary>
  205. /// 增加或修改仓库信息
  206. /// </summary>
  207. /// <returns></returns>
  208. public IActionResult Edit(string right, int Id = 0)
  209. {
  210. ViewBag.RightInfo = RightInfo;
  211. ViewBag.right = right;
  212. StoreHouse editData = db.StoreHouse.FirstOrDefault(m => m.Id == Id) ?? new StoreHouse();
  213. ViewBag.data = editData;
  214. Users manage = db.Users.FirstOrDefault(m => m.Id == editData.ManageUserId) ?? new Users();
  215. ViewBag.ManageMakerCode = manage.MakerCode;
  216. ViewBag.ManageRealName = manage.RealName;
  217. Users user = db.Users.FirstOrDefault(m => m.Id == editData.ManageUserId) ?? new Users();
  218. ViewBag.MakerCode = user.MakerCode;
  219. return View();
  220. }
  221. #endregion
  222. #region 修改仓库
  223. /// <summary>
  224. /// 增加或修改仓库信息
  225. /// </summary>
  226. /// <returns></returns>
  227. [HttpPost]
  228. public string Edit(StoreHouse data, string ManageMakerCode, string MakerCode)
  229. {
  230. Dictionary<string, object> Fields = new Dictionary<string, object>();
  231. Fields.Add("StoreName", data.StoreName); //仓库名称
  232. UserForMakerCode user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  233. if (user == null)
  234. {
  235. return "您输入的仓库归属创客编号不存在,请重新输入正确的仓库归属创客编号";
  236. }
  237. Fields.Add("UserId", user.UserId); //仓库归属人
  238. Fields.Add("Areas", data.Areas); //所属地区
  239. Fields.Add("Address", data.Address); //仓库地址
  240. UserForMakerCode manage = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ManageMakerCode);
  241. if (manage == null)
  242. {
  243. return "您输入的仓库负责人编号不存在,请重新输入正确的仓库负责人编号";
  244. }
  245. Fields.Add("ManageUserId", manage.UserId); //仓库管理员
  246. Fields.Add("ManagerEmail", data.ManagerEmail); //管理者邮箱
  247. Fields.Add("ManageMobile", data.ManageMobile);
  248. Fields.Add("Remark", data.Remark); //备注
  249. Fields.Add("LimitTopUserId", data.LimitTopUserId); //限制创客特殊仓库
  250. Fields.Add("StoreKind", data.StoreKind); //仓库归属类型
  251. Fields.Add("Status", data.Status);
  252. Fields.Add("StoreStatus", data.Status);
  253. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreHouse", Fields, data.Id);
  254. AddSysLog(data.Id.ToString(), "StoreHouse", "update");
  255. db.SaveChanges();
  256. SetRedis(data.Id, user.UserId);
  257. return "success";
  258. }
  259. #endregion
  260. #region 删除仓库信息
  261. /// <summary>
  262. /// 删除仓库信息
  263. /// </summary>
  264. /// <returns></returns>
  265. public string Delete(string Id)
  266. {
  267. string[] idlist = Id.Split(new char[] { ',' });
  268. AddSysLog(Id, "StoreHouse", "del");
  269. foreach (string subid in idlist)
  270. {
  271. int id = int.Parse(subid);
  272. Dictionary<string, object> Fields = new Dictionary<string, object>();
  273. Fields.Add("Status", -1);
  274. StoreHouse edit = db.StoreHouse.FirstOrDefault(m => m.Id == id);
  275. if (edit != null)
  276. {
  277. StoreForCode code = db.StoreForCode.FirstOrDefault(m => m.Code == edit.StoreNo);
  278. if (code != null)
  279. {
  280. db.StoreForCode.Remove(code);
  281. }
  282. StoreForName name = db.StoreForName.FirstOrDefault(m => m.Name == edit.StoreName);
  283. if (name != null)
  284. {
  285. db.StoreForName.Remove(name);
  286. }
  287. }
  288. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreHouse", Fields, id);
  289. }
  290. db.SaveChanges();
  291. return "success";
  292. }
  293. #endregion
  294. #region 开启
  295. /// <summary>
  296. /// 开启
  297. /// </summary>
  298. /// <returns></returns>
  299. public string Open(string Id)
  300. {
  301. string[] idlist = Id.Split(new char[] { ',' });
  302. AddSysLog(Id, "StoreHouse", "open");
  303. foreach (string subid in idlist)
  304. {
  305. int id = int.Parse(subid);
  306. Dictionary<string, object> Fields = new Dictionary<string, object>();
  307. Fields.Add("Status", 1);
  308. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreHouse", Fields, id);
  309. }
  310. db.SaveChanges();
  311. return "success";
  312. }
  313. #endregion
  314. #region 关闭
  315. /// <summary>
  316. /// 关闭
  317. /// </summary>
  318. /// <returns></returns>
  319. public string Close(string Id)
  320. {
  321. string[] idlist = Id.Split(new char[] { ',' });
  322. AddSysLog(Id, "StoreHouse", "close");
  323. foreach (string subid in idlist)
  324. {
  325. int id = int.Parse(subid);
  326. Dictionary<string, object> Fields = new Dictionary<string, object>();
  327. Fields.Add("Status", 0);
  328. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreHouse", Fields, id);
  329. }
  330. db.SaveChanges();
  331. return "success";
  332. }
  333. #endregion
  334. #region 排序
  335. /// <summary>
  336. /// 排序
  337. /// </summary>
  338. /// <param name="Id"></param>
  339. public string Sort(int Id, int Sort)
  340. {
  341. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("StoreHouse", Sort, Id);
  342. AddSysLog(Id.ToString(), "StoreHouse", "sort");
  343. return "success";
  344. }
  345. #endregion
  346. #region 导入数据
  347. public IActionResult Import(string right, string ExcelKind)
  348. {
  349. ViewBag.RightInfo = RightInfo;
  350. ViewBag.right = right;
  351. ViewBag.ExcelKind = ExcelKind;
  352. return View();
  353. }
  354. /// <summary>
  355. /// 导入数据
  356. /// </summary>
  357. /// <param name="ExcelData"></param>
  358. [HttpPost]
  359. public string ImportPost(string ExcelPath, int Kind = 0)
  360. {
  361. // RedisDbconn.Instance.AddList("ExcelImport", ExcelPath + "#cut#" + Kind);
  362. string key = function.MD5_16(Guid.NewGuid().ToString());
  363. RedisDbconn.Instance.AddList("ExcelImportV2", ExcelPath + "#cut#" + Kind + "#cut#" + key);
  364. return "success|" + key;
  365. }
  366. public string CheckImport(string key)
  367. {
  368. string result = RedisDbconn.Instance.Get<string>("CheckImport:" + key);
  369. if (!string.IsNullOrEmpty(result))
  370. {
  371. string[] datalist = result.Split('|');
  372. if (datalist[0] == "success")
  373. {
  374. return result;
  375. }
  376. return datalist[0];
  377. }
  378. return "0";
  379. }
  380. #endregion
  381. #region 导出Excel
  382. /// <summary>
  383. /// 导出Excel
  384. /// </summary>
  385. /// <returns></returns>
  386. public JsonResult ExportExcel(StoreHouse data, string UserIdMakerCode, string UserIdRealName, string ManageUserIdRealName, string ManageUserIdMobile, string ManageUserIdMakerCode, string StoreStatusSelect)
  387. {
  388. Dictionary<string, string> Fields = new Dictionary<string, string>();
  389. Fields.Add("StoreNo", "1"); //仓库编号
  390. Fields.Add("CreateDate", "3"); //时间
  391. Fields.Add("StoreName", "1"); //仓库名称
  392. Fields.Add("ManagerEmail", "1"); //管理者邮箱
  393. string condition = " and Status>-1";
  394. //仓库归属人创客编号
  395. if (!string.IsNullOrEmpty(UserIdMakerCode))
  396. {
  397. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  398. }
  399. //仓库归属人真实姓名
  400. if (!string.IsNullOrEmpty(UserIdRealName))
  401. {
  402. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  403. }
  404. //仓库管理员真实姓名
  405. if (!string.IsNullOrEmpty(ManageUserIdRealName))
  406. {
  407. condition += " and ManageUserId in (select ManageUserId from UserForRealName where RealName='" + ManageUserIdRealName + "')";
  408. }
  409. //仓库管理员手机号
  410. if (!string.IsNullOrEmpty(ManageUserIdMobile))
  411. {
  412. condition += " and ManageUserId in (select ManageUserId from UserForMobile where Mobile='" + ManageUserIdMobile + "')";
  413. }
  414. //仓库管理员创客编号
  415. if (!string.IsNullOrEmpty(ManageUserIdMakerCode))
  416. {
  417. condition += " and ManageUserId in (select ManageUserId from UserForMakerCode where MakerCode='" + ManageUserIdMakerCode + "')";
  418. }
  419. //仓库状态
  420. if (!string.IsNullOrEmpty(StoreStatusSelect))
  421. {
  422. condition += " and StoreStatus=" + StoreStatusSelect;
  423. }
  424. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("StoreHouse", Fields, "Id desc", "0", 1, 20000, condition, "StoreNo,StoreName,UserId,BrandId,Address,ManageUserId,ManagerEmail,StoreType,TotalNum,LaveNum,OutNum,LimitTopUserId,StoreStatus,StoreKind", false);
  425. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  426. foreach (Dictionary<string, object> dic in diclist)
  427. {
  428. //仓库归属人
  429. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  430. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  431. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  432. dic["UserIdRealName"] = userid_Users.RealName;
  433. //产品类型
  434. dic["BrandId"] = RelationClass.GetKqProductBrandList(dic["BrandId"].ToString());
  435. //仓库管理员
  436. int ManageUserId = int.Parse(function.CheckInt(dic["ManageUserId"].ToString()));
  437. Users manageuserid_Users = db.Users.FirstOrDefault(m => m.Id == ManageUserId) ?? new Users();
  438. dic["ManageUserIdRealName"] = manageuserid_Users.RealName;
  439. dic["ManageUserIdMobile"] = manageuserid_Users.Mobile;
  440. dic["ManageUserIdMakerCode"] = manageuserid_Users.MakerCode;
  441. //仓库类型
  442. int StoreType = int.Parse(dic["StoreType"].ToString());
  443. if (StoreType == 0) dic["StoreType"] = "实体仓";
  444. if (StoreType == 1) dic["StoreType"] = "虚拟仓";
  445. //仓库状态
  446. int StoreStatus = int.Parse(dic["StoreStatus"].ToString());
  447. if (StoreStatus == 1) dic["StoreStatus"] = "启用";
  448. if (StoreStatus == 0) dic["StoreStatus"] = "禁用";
  449. //仓库归属类型
  450. int StoreKind = int.Parse(dic["StoreKind"].ToString());
  451. if (StoreKind == 0) dic["StoreKind"] = "分仓";
  452. if (StoreKind == 1) dic["StoreKind"] = "总仓";
  453. }
  454. Dictionary<string, object> result = new Dictionary<string, object>();
  455. result.Add("Status", "1");
  456. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  457. result.Add("Obj", diclist);
  458. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  459. ReturnFields.Add("StoreNo", "仓库编号");
  460. ReturnFields.Add("StoreName", "仓库名称");
  461. ReturnFields.Add("UserIdMakerCode", "仓库归属人创客编号");
  462. ReturnFields.Add("UserIdRealName", "仓库归属人真实姓名");
  463. ReturnFields.Add("BrandId", "产品类型");
  464. ReturnFields.Add("Address", "仓库地址");
  465. ReturnFields.Add("ManageUserIdRealName", "仓库管理员真实姓名");
  466. ReturnFields.Add("ManageUserIdMobile", "仓库管理员手机号");
  467. ReturnFields.Add("ManageUserIdMakerCode", "仓库管理员创客编号");
  468. ReturnFields.Add("ManagerEmail", "管理者邮箱");
  469. ReturnFields.Add("StoreType", "仓库类型");
  470. ReturnFields.Add("TotalNum", "总库存数");
  471. ReturnFields.Add("LaveNum", "剩余库存数");
  472. ReturnFields.Add("OutNum", "出库数");
  473. ReturnFields.Add("LimitTopUserId", "限制创客特殊仓库");
  474. ReturnFields.Add("StoreStatus", "仓库状态");
  475. ReturnFields.Add("StoreKind", "仓库归属类型");
  476. result.Add("Fields", ReturnFields);
  477. AddSysLog("0", "StoreHouse", "ExportExcel");
  478. return Json(result);
  479. }
  480. #endregion
  481. #region 同步数据
  482. /// <summary>
  483. /// 同步数据
  484. /// </summary>
  485. /// <returns></returns>
  486. public string SycnData(int Id = 0)
  487. {
  488. if (Id > 0)
  489. {
  490. DataTable dt = OtherMySqlConn.dtable("select Id,(select count(Id) from PosMachinesTwo where StoreId=s.Id and UserId=0) as CurLaveNum from StoreHouse s where Id=" + Id);
  491. if (dt.Rows.Count > 0)
  492. {
  493. int CurLaveNum = int.Parse(function.CheckInt(dt.Rows[0]["CurLaveNum"].ToString()));
  494. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == Id);
  495. if (store != null)
  496. {
  497. store.LaveNum = CurLaveNum;
  498. db.SaveChanges();
  499. RedisDbconn.Instance.Set("StoreHouse:" + Id, store);
  500. }
  501. }
  502. }
  503. else
  504. {
  505. DataTable dt = OtherMySqlConn.dtable("select s.Id,LaveNum,count(p.Id) as CurLaveNum from StoreHouse s left join PosMachinesTwo p on s.Id=p.StoreId and s.BrandId=p.BrandId and p.UserId=0 group by s.Id HAVING LaveNum!=count(p.Id)");
  506. foreach (DataRow dr in dt.Rows)
  507. {
  508. int StoreId = int.Parse(function.CheckInt(dr["Id"].ToString()));
  509. int CurLaveNum = int.Parse(function.CheckInt(dr["CurLaveNum"].ToString()));
  510. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId);
  511. if (store != null)
  512. {
  513. store.LaveNum = CurLaveNum;
  514. db.SaveChanges();
  515. RedisDbconn.Instance.Set("StoreHouse:" + StoreId, store);
  516. }
  517. }
  518. }
  519. AddSysLog(Id, "StoreHouse", "SycnData");
  520. db.SaveChanges();
  521. return "success";
  522. }
  523. #endregion
  524. #region 设置缓存
  525. private void SetRedis(int Id, int UserId)
  526. {
  527. if (UserId > 0)
  528. {
  529. RedisDbconn.Instance.Clear("StoreHouseList:" + UserId);
  530. List<StoreHouse> stores = db.StoreHouse.Where(m => m.Status > -1 && m.UserId == UserId).OrderByDescending(m => m.Sort).ThenByDescending(m => m.Id).ToList();
  531. RedisDbconn.Instance.Clear("StoreHouse");
  532. stores = db.StoreHouse.Where(m => m.Status > -1).OrderByDescending(m => m.Sort).ThenByDescending(m => m.Id).ToList();
  533. }
  534. if (Id > 0)
  535. {
  536. StoreHouse edit = db.StoreHouse.FirstOrDefault(m => m.Id == Id);
  537. if (edit != null)
  538. {
  539. RedisDbconn.Instance.Clear("StoreHouse:" + Id);
  540. }
  541. }
  542. }
  543. #endregion
  544. }
  545. }