StoreHouseController.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  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. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreHouse", Fields, id);
  275. }
  276. db.SaveChanges();
  277. return "success";
  278. }
  279. #endregion
  280. #region 开启
  281. /// <summary>
  282. /// 开启
  283. /// </summary>
  284. /// <returns></returns>
  285. public string Open(string Id)
  286. {
  287. string[] idlist = Id.Split(new char[] { ',' });
  288. AddSysLog(Id, "StoreHouse", "open");
  289. foreach (string subid in idlist)
  290. {
  291. int id = int.Parse(subid);
  292. Dictionary<string, object> Fields = new Dictionary<string, object>();
  293. Fields.Add("Status", 1);
  294. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreHouse", Fields, id);
  295. }
  296. db.SaveChanges();
  297. return "success";
  298. }
  299. #endregion
  300. #region 关闭
  301. /// <summary>
  302. /// 关闭
  303. /// </summary>
  304. /// <returns></returns>
  305. public string Close(string Id)
  306. {
  307. string[] idlist = Id.Split(new char[] { ',' });
  308. AddSysLog(Id, "StoreHouse", "close");
  309. foreach (string subid in idlist)
  310. {
  311. int id = int.Parse(subid);
  312. Dictionary<string, object> Fields = new Dictionary<string, object>();
  313. Fields.Add("Status", 0);
  314. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreHouse", Fields, id);
  315. }
  316. db.SaveChanges();
  317. return "success";
  318. }
  319. #endregion
  320. #region 排序
  321. /// <summary>
  322. /// 排序
  323. /// </summary>
  324. /// <param name="Id"></param>
  325. public string Sort(int Id, int Sort)
  326. {
  327. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("StoreHouse", Sort, Id);
  328. AddSysLog(Id.ToString(), "StoreHouse", "sort");
  329. return "success";
  330. }
  331. #endregion
  332. #region 导入数据
  333. public IActionResult Import(string right, string ExcelKind)
  334. {
  335. ViewBag.RightInfo = RightInfo;
  336. ViewBag.right = right;
  337. ViewBag.ExcelKind = ExcelKind;
  338. return View();
  339. }
  340. /// <summary>
  341. /// 导入数据
  342. /// </summary>
  343. /// <param name="ExcelData"></param>
  344. [HttpPost]
  345. public string ImportPost(string ExcelPath, int Kind = 0)
  346. {
  347. // RedisDbconn.Instance.AddList("ExcelImport", ExcelPath + "#cut#" + Kind);
  348. string key = function.MD5_16(Guid.NewGuid().ToString());
  349. RedisDbconn.Instance.AddList("ExcelImportV2", ExcelPath + "#cut#" + Kind + "#cut#" + key);
  350. return "success|" + key;
  351. }
  352. public string CheckImport(string key)
  353. {
  354. string result = RedisDbconn.Instance.Get<string>("CheckImport:" + key);
  355. if (!string.IsNullOrEmpty(result))
  356. {
  357. string[] datalist = result.Split('|');
  358. if (datalist[0] == "success")
  359. {
  360. return result;
  361. }
  362. return datalist[0];
  363. }
  364. return "0";
  365. }
  366. #endregion
  367. #region 导出Excel
  368. /// <summary>
  369. /// 导出Excel
  370. /// </summary>
  371. /// <returns></returns>
  372. public JsonResult ExportExcel(StoreHouse data, string UserIdMakerCode, string UserIdRealName, string ManageUserIdRealName, string ManageUserIdMobile, string ManageUserIdMakerCode, string StoreStatusSelect)
  373. {
  374. Dictionary<string, string> Fields = new Dictionary<string, string>();
  375. Fields.Add("StoreNo", "1"); //仓库编号
  376. Fields.Add("CreateDate", "3"); //时间
  377. Fields.Add("StoreName", "1"); //仓库名称
  378. Fields.Add("ManagerEmail", "1"); //管理者邮箱
  379. string condition = " and Status>-1";
  380. //仓库归属人创客编号
  381. if (!string.IsNullOrEmpty(UserIdMakerCode))
  382. {
  383. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  384. }
  385. //仓库归属人真实姓名
  386. if (!string.IsNullOrEmpty(UserIdRealName))
  387. {
  388. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  389. }
  390. //仓库管理员真实姓名
  391. if (!string.IsNullOrEmpty(ManageUserIdRealName))
  392. {
  393. condition += " and ManageUserId in (select ManageUserId from UserForRealName where RealName='" + ManageUserIdRealName + "')";
  394. }
  395. //仓库管理员手机号
  396. if (!string.IsNullOrEmpty(ManageUserIdMobile))
  397. {
  398. condition += " and ManageUserId in (select ManageUserId from UserForMobile where Mobile='" + ManageUserIdMobile + "')";
  399. }
  400. //仓库管理员创客编号
  401. if (!string.IsNullOrEmpty(ManageUserIdMakerCode))
  402. {
  403. condition += " and ManageUserId in (select ManageUserId from UserForMakerCode where MakerCode='" + ManageUserIdMakerCode + "')";
  404. }
  405. //仓库状态
  406. if (!string.IsNullOrEmpty(StoreStatusSelect))
  407. {
  408. condition += " and StoreStatus=" + StoreStatusSelect;
  409. }
  410. 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);
  411. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  412. foreach (Dictionary<string, object> dic in diclist)
  413. {
  414. //仓库归属人
  415. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  416. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  417. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  418. dic["UserIdRealName"] = userid_Users.RealName;
  419. //产品类型
  420. dic["BrandId"] = RelationClass.GetKqProductBrandList(dic["BrandId"].ToString());
  421. //仓库管理员
  422. int ManageUserId = int.Parse(function.CheckInt(dic["ManageUserId"].ToString()));
  423. Users manageuserid_Users = db.Users.FirstOrDefault(m => m.Id == ManageUserId) ?? new Users();
  424. dic["ManageUserIdRealName"] = manageuserid_Users.RealName;
  425. dic["ManageUserIdMobile"] = manageuserid_Users.Mobile;
  426. dic["ManageUserIdMakerCode"] = manageuserid_Users.MakerCode;
  427. //仓库类型
  428. int StoreType = int.Parse(dic["StoreType"].ToString());
  429. if (StoreType == 0) dic["StoreType"] = "实体仓";
  430. if (StoreType == 1) dic["StoreType"] = "虚拟仓";
  431. //仓库状态
  432. int StoreStatus = int.Parse(dic["StoreStatus"].ToString());
  433. if (StoreStatus == 1) dic["StoreStatus"] = "启用";
  434. if (StoreStatus == 0) dic["StoreStatus"] = "禁用";
  435. //仓库归属类型
  436. int StoreKind = int.Parse(dic["StoreKind"].ToString());
  437. if (StoreKind == 0) dic["StoreKind"] = "分仓";
  438. if (StoreKind == 1) dic["StoreKind"] = "总仓";
  439. }
  440. Dictionary<string, object> result = new Dictionary<string, object>();
  441. result.Add("Status", "1");
  442. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  443. result.Add("Obj", diclist);
  444. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  445. ReturnFields.Add("StoreNo", "仓库编号");
  446. ReturnFields.Add("StoreName", "仓库名称");
  447. ReturnFields.Add("UserIdMakerCode", "仓库归属人创客编号");
  448. ReturnFields.Add("UserIdRealName", "仓库归属人真实姓名");
  449. ReturnFields.Add("BrandId", "产品类型");
  450. ReturnFields.Add("Address", "仓库地址");
  451. ReturnFields.Add("ManageUserIdRealName", "仓库管理员真实姓名");
  452. ReturnFields.Add("ManageUserIdMobile", "仓库管理员手机号");
  453. ReturnFields.Add("ManageUserIdMakerCode", "仓库管理员创客编号");
  454. ReturnFields.Add("ManagerEmail", "管理者邮箱");
  455. ReturnFields.Add("StoreType", "仓库类型");
  456. ReturnFields.Add("TotalNum", "总库存数");
  457. ReturnFields.Add("LaveNum", "剩余库存数");
  458. ReturnFields.Add("OutNum", "出库数");
  459. ReturnFields.Add("LimitTopUserId", "限制创客特殊仓库");
  460. ReturnFields.Add("StoreStatus", "仓库状态");
  461. ReturnFields.Add("StoreKind", "仓库归属类型");
  462. result.Add("Fields", ReturnFields);
  463. AddSysLog("0", "StoreHouse", "ExportExcel");
  464. return Json(result);
  465. }
  466. #endregion
  467. #region 同步数据
  468. /// <summary>
  469. /// 同步数据
  470. /// </summary>
  471. /// <returns></returns>
  472. public string SycnData(int Id = 0)
  473. {
  474. if (Id > 0)
  475. {
  476. 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);
  477. if (dt.Rows.Count > 0)
  478. {
  479. int CurLaveNum = int.Parse(function.CheckInt(dt.Rows[0]["CurLaveNum"].ToString()));
  480. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == Id);
  481. if (store != null)
  482. {
  483. store.LaveNum = CurLaveNum;
  484. db.SaveChanges();
  485. RedisDbconn.Instance.Set("StoreHouse:" + Id, store);
  486. }
  487. }
  488. }
  489. else
  490. {
  491. 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)");
  492. foreach (DataRow dr in dt.Rows)
  493. {
  494. int StoreId = int.Parse(function.CheckInt(dr["Id"].ToString()));
  495. int CurLaveNum = int.Parse(function.CheckInt(dr["CurLaveNum"].ToString()));
  496. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId);
  497. if (store != null)
  498. {
  499. store.LaveNum = CurLaveNum;
  500. db.SaveChanges();
  501. RedisDbconn.Instance.Set("StoreHouse:" + StoreId, store);
  502. }
  503. }
  504. }
  505. AddSysLog(Id, "StoreHouse", "SycnData");
  506. db.SaveChanges();
  507. return "success";
  508. }
  509. #endregion
  510. #region 设置缓存
  511. private void SetRedis(int Id, int UserId)
  512. {
  513. if (UserId > 0)
  514. {
  515. RedisDbconn.Instance.Clear("StoreHouseList:" + UserId);
  516. List<StoreHouse> stores = db.StoreHouse.Where(m => m.Status > -1 && m.UserId == UserId).OrderByDescending(m => m.Sort).ThenByDescending(m => m.Id).ToList();
  517. RedisDbconn.Instance.Clear("StoreHouse");
  518. stores = db.StoreHouse.Where(m => m.Status > -1).OrderByDescending(m => m.Sort).ThenByDescending(m => m.Id).ToList();
  519. }
  520. if (Id > 0)
  521. {
  522. StoreHouse edit = db.StoreHouse.FirstOrDefault(m => m.Id == Id);
  523. if (edit != null)
  524. {
  525. RedisDbconn.Instance.Clear("StoreHouse:" + Id);
  526. }
  527. }
  528. }
  529. #endregion
  530. }
  531. }