StoreHouseController.cs 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372
  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, string CreateDateData, int page = 1, int limit = 30)
  48. {
  49. Dictionary<string, string> Fields = new Dictionary<string, string>();
  50. Fields.Add("StoreNo", "1"); //仓库编号
  51. Fields.Add("StoreName", "1"); //仓库名称
  52. Fields.Add("ManagerEmail", "1"); //管理者邮箱
  53. string condition = " and Status>-1";
  54. //仓库归属人创客编号
  55. if (!string.IsNullOrEmpty(UserIdMakerCode))
  56. {
  57. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  58. }
  59. // //仓库归属人真实姓名
  60. // if (!string.IsNullOrEmpty(UserIdRealName))
  61. // {
  62. // DataTable dt = OtherMySqlConn.dtable("SELECT Id FROM Users WHERE RealName like '%" + UserIdRealName + "%'");
  63. // var Count = dt.Rows.Count;
  64. // int times = 0;
  65. // string UserIds = "";
  66. // foreach (DataRow item in dt.Rows)
  67. // {
  68. // times++;
  69. // if (times == Count)
  70. // {
  71. // UserIds += item["Id"].ToString();
  72. // }
  73. // else
  74. // {
  75. // UserIds += item["Id"].ToString() + ",";
  76. // }
  77. // }
  78. // // condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  79. // condition += " and UserId in (" + UserIds + ")";
  80. // }
  81. // //仓库管理员真实姓名
  82. // if (!string.IsNullOrEmpty(ManageUserIdRealName))
  83. // {
  84. // DataTable dts = OtherMySqlConn.dtable("SELECT Id FROM Users WHERE RealName like '%" + ManageUserIdRealName + "%'");
  85. // var Counts = dts.Rows.Count;
  86. // int time = 1;
  87. // string UserIdss = "";
  88. // foreach (DataRow items in dts.Rows)
  89. // {
  90. // time++;
  91. // if (time == Counts)
  92. // {
  93. // UserIdss += items["Id"].ToString();
  94. // }
  95. // else
  96. // {
  97. // UserIdss += items["Id"].ToString() + ",";
  98. // }
  99. // }
  100. // // condition += " and ManageUserId in (select ManageUserId from UserForRealName where RealName='" + ManageUserIdRealName + "')";
  101. // condition += " and UserId in (" + UserIdss + ")";
  102. // }
  103. //仓库管理员手机号
  104. if (!string.IsNullOrEmpty(ManageUserIdMobile))
  105. {
  106. condition += " and ManageUserId in (select ManageUserId from UserForMobile where Mobile='" + ManageUserIdMobile + "')";
  107. }
  108. //仓库管理员创客编号
  109. if (!string.IsNullOrEmpty(ManageUserIdMakerCode))
  110. {
  111. condition += " and ManageUserId in (select ManageUserId from UserForMakerCode where MakerCode='" + ManageUserIdMakerCode + "')";
  112. }
  113. //仓库状态
  114. if (!string.IsNullOrEmpty(StoreStatusSelect))
  115. {
  116. condition += " and StoreStatus=" + StoreStatusSelect;
  117. }
  118. if (!string.IsNullOrEmpty(CreateDateData))
  119. {
  120. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  121. string start = datelist[0];
  122. string end = datelist[1];
  123. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  124. }
  125. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("StoreHouse", Fields, "Id desc", "0", page, limit, condition);
  126. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  127. foreach (Dictionary<string, object> dic in diclist)
  128. {
  129. //仓库归属人
  130. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  131. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  132. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  133. dic["UserIdRealName"] = userid_Users.RealName;
  134. //产品类型
  135. dic["BrandId"] = RelationClass.GetKqProductBrandList(dic["BrandId"].ToString());
  136. //仓库管理员
  137. int ManageUserId = int.Parse(function.CheckInt(dic["ManageUserId"].ToString()));
  138. Users manageuserid_Users = db.Users.FirstOrDefault(m => m.Id == ManageUserId) ?? new Users();
  139. dic["ManageUserIdRealName"] = manageuserid_Users.RealName;
  140. dic["ManageUserIdMobile"] = manageuserid_Users.Mobile;
  141. dic["ManageUserIdMakerCode"] = manageuserid_Users.MakerCode;
  142. //仓库类型
  143. int StoreType = int.Parse(dic["StoreType"].ToString());
  144. if (StoreType == 0) dic["StoreType"] = "实体仓";
  145. if (StoreType == 1) dic["StoreType"] = "虚拟仓";
  146. //仓库状态
  147. int StoreStatus = int.Parse(dic["StoreStatus"].ToString());
  148. if (StoreStatus == 1) dic["StoreStatus"] = "启用";
  149. if (StoreStatus == 0) dic["StoreStatus"] = "禁用";
  150. //仓库归属类型
  151. int StoreKind = int.Parse(dic["StoreKind"].ToString());
  152. if (StoreKind == 0) dic["StoreKind"] = "分仓";
  153. if (StoreKind == 1) dic["StoreKind"] = "总仓";
  154. //小分仓
  155. int Id = int.Parse(function.CheckInt(dic["Id"].ToString()));
  156. int PreCount = db.PreSendStockDetail.Count(m => m.FromStoreId == Id && m.ApplyFlag == 0 && m.Status >= 0 && m.Status <= 1);
  157. dic["PreNum"] = PreCount.ToString();
  158. //分仓额度
  159. var amount = db.UserAccount.FirstOrDefault(m => m.Id == UserId) ?? new UserAccount();
  160. var ValidAmount = amount.ValidAmount;
  161. var FixedAmount = amount.FixedAmount;
  162. var TempAmount = amount.TempAmount;
  163. var LeaderBalanceAmount = amount.LeaderBalanceAmount;
  164. dic["ValidAmount"] = ValidAmount.ToString();//可用额度
  165. dic["FixedAmount"] = FixedAmount.ToString();//固定额度
  166. dic["TempAmount"] = TempAmount.ToString();//临时额度
  167. dic["LeaderBalanceAmount"] = LeaderBalanceAmount.ToString();//担保金额
  168. }
  169. return Json(obj);
  170. }
  171. #endregion
  172. #region 增加仓库
  173. /// <summary>
  174. /// 增加或修改仓库信息
  175. /// </summary>
  176. /// <returns></returns>
  177. public IActionResult Add(string right)
  178. {
  179. ViewBag.RightInfo = RightInfo;
  180. ViewBag.right = right;
  181. return View();
  182. }
  183. #endregion
  184. #region 增加仓库
  185. /// <summary>
  186. /// 增加或修改仓库信息
  187. /// </summary>
  188. /// <returns></returns>
  189. [HttpPost]
  190. public string Add(StoreHouse data, string ManageMakerCode, string MakerCode)
  191. {
  192. string BrandIdString = data.BrandId;
  193. if (!string.IsNullOrEmpty(BrandIdString))
  194. {
  195. string[] BrandIdList = BrandIdString.Split(',');
  196. foreach (string BrandId in BrandIdList)
  197. {
  198. Dictionary<string, object> Fields = new Dictionary<string, object>();
  199. Fields.Add("CreateMan", SysUserName); //创建人
  200. Fields.Add("StoreName", data.StoreName); //仓库名称
  201. UserForMakerCode user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  202. if (user == null)
  203. {
  204. return "您输入的仓库归属创客编号不存在,请重新输入正确的仓库归属创客编号";
  205. }
  206. Fields.Add("UserId", user.UserId); //仓库归属人
  207. Fields.Add("Areas", data.Areas); //所属地区
  208. Fields.Add("Address", data.Address); //仓库地址
  209. UserForMakerCode manage = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ManageMakerCode);
  210. if (manage == null)
  211. {
  212. return "您输入的仓库负责人编号不存在,请重新输入正确的仓库负责人编号";
  213. }
  214. Fields.Add("ManageUserId", manage.UserId); //仓库管理员
  215. Fields.Add("ManagerEmail", data.ManagerEmail); //管理者邮箱
  216. Fields.Add("ManageMobile", data.ManageMobile);
  217. Fields.Add("Remark", data.Remark); //备注
  218. Fields.Add("LimitTopUserId", data.LimitTopUserId); //限制创客特殊仓库
  219. Fields.Add("StoreKind", data.StoreKind); //仓库归属类型
  220. int bid = int.Parse(BrandId);
  221. KqProducts pro = db.KqProducts.FirstOrDefault(m => m.Id == bid) ?? new KqProducts();
  222. Fields.Add("BrandId", BrandId);
  223. Fields.Add("ProductName", pro.Name);
  224. Fields.Add("StoreStatus", 1);
  225. Fields.Add("Status", 1);
  226. var name = db.StoreHouse.FirstOrDefault(m => m.UserId == user.UserId && m.BrandId == BrandId && m.StoreName == data.StoreName);
  227. if (name != null)
  228. {
  229. return "您的仓库名重复,请重新填写";
  230. }
  231. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("StoreHouse", Fields, 0);
  232. StoreHouse edit = db.StoreHouse.FirstOrDefault(m => m.Id == Id);
  233. if (edit != null)
  234. {
  235. string No = Id.ToString();
  236. for (int i = 0; i < 7 - Id.ToString().Length; i++)
  237. {
  238. No = "0" + No;
  239. }
  240. No = "S" + No;
  241. edit.StoreNo = No;
  242. db.StoreForCode.Add(new StoreForCode()
  243. {
  244. Code = No,
  245. StoreId = Id,
  246. });
  247. RedisDbconn.Instance.Set("StoreForCode:" + No, Id);
  248. }
  249. db.StoreForName.Add(new StoreForName()
  250. {
  251. Name = data.StoreName + "-" + pro.Name,
  252. StoreId = Id,
  253. });
  254. UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == user.UserId);
  255. if (account == null)
  256. {
  257. account = db.UserAccount.Add(new UserAccount()
  258. {
  259. Id = user.UserId,
  260. UserId = user.UserId,
  261. }).Entity;
  262. db.SaveChanges();
  263. }
  264. if (account.FixedAmount == 0 && account.ValidAmount == 0)
  265. {
  266. account.FixedAmount = 20000;
  267. account.ValidAmount = 20000;
  268. }
  269. RedisDbconn.Instance.Set("StoreForName:" + data.StoreName, Id);
  270. AddSysLog(data.Id.ToString(), "StoreHouse", "add");
  271. db.SaveChanges();
  272. SetRedis(Id, user.UserId);
  273. }
  274. }
  275. return "success";
  276. }
  277. #endregion
  278. #region 修改仓库
  279. /// <summary>
  280. /// 增加或修改仓库信息
  281. /// </summary>
  282. /// <returns></returns>
  283. public IActionResult Edit(string right, int Id = 0)
  284. {
  285. ViewBag.RightInfo = RightInfo;
  286. ViewBag.right = right;
  287. StoreHouse editData = db.StoreHouse.FirstOrDefault(m => m.Id == Id) ?? new StoreHouse();
  288. ViewBag.data = editData;
  289. Users manage = db.Users.FirstOrDefault(m => m.Id == editData.ManageUserId) ?? new Users();
  290. ViewBag.ManageMakerCode = manage.MakerCode;
  291. ViewBag.ManageRealName = manage.RealName;
  292. Users user = db.Users.FirstOrDefault(m => m.Id == editData.ManageUserId) ?? new Users();
  293. ViewBag.MakerCode = user.MakerCode;
  294. return View();
  295. }
  296. #endregion
  297. #region 修改仓库
  298. /// <summary>
  299. /// 增加或修改仓库信息
  300. /// </summary>
  301. /// <returns></returns>
  302. [HttpPost]
  303. public string Edit(StoreHouse data, string ManageMakerCode, string MakerCode)
  304. {
  305. Dictionary<string, object> Fields = new Dictionary<string, object>();
  306. Fields.Add("CreateMan", SysUserName); //创建人
  307. Fields.Add("StoreName", data.StoreName); //仓库名称
  308. UserForMakerCode user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  309. if (user == null)
  310. {
  311. return "您输入的仓库归属创客编号不存在,请重新输入正确的仓库归属创客编号";
  312. }
  313. Fields.Add("UserId", user.UserId); //仓库归属人
  314. Fields.Add("Areas", data.Areas); //所属地区
  315. Fields.Add("Address", data.Address); //仓库地址
  316. UserForMakerCode manage = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ManageMakerCode);
  317. if (manage == null)
  318. {
  319. return "您输入的仓库负责人编号不存在,请重新输入正确的仓库负责人编号";
  320. }
  321. Fields.Add("ManageUserId", manage.UserId); //仓库管理员
  322. Fields.Add("ManagerEmail", data.ManagerEmail); //管理者邮箱
  323. Fields.Add("ManageMobile", data.ManageMobile);
  324. Fields.Add("Remark", data.Remark); //备注
  325. Fields.Add("LimitTopUserId", data.LimitTopUserId); //限制创客特殊仓库
  326. Fields.Add("StoreKind", data.StoreKind); //仓库归属类型
  327. Fields.Add("Status", data.Status);
  328. Fields.Add("StoreStatus", data.Status);
  329. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreHouse", Fields, data.Id);
  330. AddSysLog(data.Id.ToString(), "StoreHouse", "update");
  331. db.SaveChanges();
  332. SetRedis(data.Id, user.UserId);
  333. return "success";
  334. }
  335. #endregion
  336. #region 一键添加仓库
  337. /// <summary>
  338. /// 一件添加仓库
  339. /// </summary>
  340. /// <returns></returns>
  341. public IActionResult Edits(string right, int Id = 0)
  342. {
  343. ViewBag.RightInfo = RightInfo;
  344. ViewBag.right = right;
  345. StoreHouse editData = db.StoreHouse.FirstOrDefault(m => m.Id == Id) ?? new StoreHouse();
  346. ViewBag.data = editData;
  347. Users manage = db.Users.FirstOrDefault(m => m.Id == editData.ManageUserId) ?? new Users();
  348. ViewBag.ManageMakerCode = manage.MakerCode;
  349. ViewBag.ManageRealName = manage.RealName;
  350. Users user = db.Users.FirstOrDefault(m => m.Id == editData.ManageUserId) ?? new Users();
  351. ViewBag.MakerCode = user.MakerCode;
  352. return View();
  353. }
  354. #endregion
  355. #region 一键添加仓库
  356. /// <summary>
  357. /// 一键添加仓库
  358. /// </summary>
  359. /// <returns></returns>
  360. [HttpPost]
  361. public string Edits(StoreHouse data, string ManageMakerCode, string MakerCode)
  362. {
  363. Dictionary<string, object> Fields = new Dictionary<string, object>();
  364. StoreHouse storeHouse = db.StoreHouse.FirstOrDefault(m => m.Id == data.Id);
  365. var brand = db.StoreHouse.FirstOrDefault(m => m.UserId == storeHouse.UserId && m.BrandId == data.BrandId);
  366. if (brand != null)
  367. {
  368. return "您已有该品牌类型的仓库,请重新选择";
  369. }
  370. var name = db.StoreHouse.FirstOrDefault(m => m.UserId == storeHouse.UserId && m.StoreName == data.StoreName);
  371. if (name != null)
  372. {
  373. return "您的仓库名重复,请重新填写";
  374. }
  375. Fields.Add("StoreName", data.StoreName); //仓库名称
  376. UserForMakerCode user = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  377. if (user == null)
  378. {
  379. return "您输入的仓库归属创客编号不存在,请重新输入正确的仓库归属创客编号";
  380. }
  381. Fields.Add("UserId", user.UserId); //仓库归属人
  382. Fields.Add("Areas", data.Areas); //所属地区
  383. Fields.Add("Address", data.Address); //仓库地址
  384. UserForMakerCode manage = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == ManageMakerCode);
  385. if (manage == null)
  386. {
  387. return "您输入的仓库负责人编号不存在,请重新输入正确的仓库负责人编号";
  388. }
  389. Fields.Add("CreateMan", SysUserName); //创建人
  390. Fields.Add("ManageUserId", manage.UserId); //仓库管理员
  391. Fields.Add("ManagerEmail", data.ManagerEmail); //管理者邮箱
  392. Fields.Add("ManageMobile", data.ManageMobile);
  393. Fields.Add("Remark", data.Remark); //备注
  394. Fields.Add("LimitTopUserId", data.LimitTopUserId); //限制创客特殊仓库
  395. Fields.Add("StoreKind", data.StoreKind); //仓库归属类型
  396. int bid = Convert.ToInt32(data.BrandId);
  397. KqProducts pro = db.KqProducts.FirstOrDefault(m => m.Id == bid) ?? new KqProducts();
  398. Fields.Add("BrandId", data.BrandId);
  399. Fields.Add("ProductName", pro.Name);
  400. Fields.Add("StoreStatus", 1);
  401. Fields.Add("Status", 1);
  402. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("StoreHouse", Fields, 0);
  403. StoreHouse edit = db.StoreHouse.FirstOrDefault(m => m.Id == Id);
  404. if (edit != null)
  405. {
  406. string No = Id.ToString();
  407. for (int i = 0; i < 7 - Id.ToString().Length; i++)
  408. {
  409. No = "0" + No;
  410. }
  411. No = "S" + No;
  412. edit.StoreNo = No;
  413. db.StoreForCode.Add(new StoreForCode()
  414. {
  415. Code = No,
  416. StoreId = Id,
  417. });
  418. RedisDbconn.Instance.Set("StoreForCode:" + No, Id);
  419. }
  420. db.StoreForName.Add(new StoreForName()
  421. {
  422. Name = data.StoreName,
  423. StoreId = Id,
  424. });
  425. RedisDbconn.Instance.Set("StoreForName:" + data.StoreName, Id);
  426. AddSysLog(data.Id.ToString(), "StoreHouse", "add");
  427. db.SaveChanges();
  428. SetRedis(Id, user.UserId);
  429. return "success";
  430. }
  431. #endregion
  432. #region 删除仓库信息
  433. /// <summary>
  434. /// 删除仓库信息
  435. /// </summary>
  436. /// <returns></returns>
  437. public string Delete(string Id)
  438. {
  439. string[] idlist = Id.Split(new char[] { ',' });
  440. AddSysLog(Id, "StoreHouse", "del");
  441. foreach (string subid in idlist)
  442. {
  443. int id = int.Parse(subid);
  444. Dictionary<string, object> Fields = new Dictionary<string, object>();
  445. Fields.Add("Status", -1);
  446. StoreHouse edit = db.StoreHouse.FirstOrDefault(m => m.Id == id);
  447. if (edit != null)
  448. {
  449. StoreForCode code = db.StoreForCode.FirstOrDefault(m => m.Code == edit.StoreNo);
  450. if (code != null)
  451. {
  452. db.StoreForCode.Remove(code);
  453. }
  454. StoreForName name = db.StoreForName.FirstOrDefault(m => m.Name == edit.StoreName);
  455. if (name != null)
  456. {
  457. db.StoreForName.Remove(name);
  458. }
  459. }
  460. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreHouse", Fields, id);
  461. }
  462. db.SaveChanges();
  463. return "success";
  464. }
  465. #endregion
  466. #region 开启
  467. /// <summary>
  468. /// 开启
  469. /// </summary>
  470. /// <returns></returns>
  471. public string Open(string Id)
  472. {
  473. string[] idlist = Id.Split(new char[] { ',' });
  474. AddSysLog(Id, "StoreHouse", "open");
  475. foreach (string subid in idlist)
  476. {
  477. int id = int.Parse(subid);
  478. Dictionary<string, object> Fields = new Dictionary<string, object>();
  479. Fields.Add("Status", 1);
  480. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreHouse", Fields, id);
  481. }
  482. db.SaveChanges();
  483. return "success";
  484. }
  485. #endregion
  486. #region 关闭
  487. /// <summary>
  488. /// 关闭
  489. /// </summary>
  490. /// <returns></returns>
  491. public string Close(string Id)
  492. {
  493. string[] idlist = Id.Split(new char[] { ',' });
  494. AddSysLog(Id, "StoreHouse", "close");
  495. foreach (string subid in idlist)
  496. {
  497. int id = int.Parse(subid);
  498. Dictionary<string, object> Fields = new Dictionary<string, object>();
  499. Fields.Add("Status", 0);
  500. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreHouse", Fields, id);
  501. }
  502. db.SaveChanges();
  503. return "success";
  504. }
  505. #endregion
  506. #region 排序
  507. /// <summary>
  508. /// 排序
  509. /// </summary>
  510. /// <param name="Id"></param>
  511. public string Sort(int Id, int Sort)
  512. {
  513. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("StoreHouse", Sort, Id);
  514. AddSysLog(Id.ToString(), "StoreHouse", "sort");
  515. return "success";
  516. }
  517. #endregion
  518. #region 导入数据
  519. public IActionResult Import(string right, string ExcelKind)
  520. {
  521. ViewBag.RightInfo = RightInfo;
  522. ViewBag.right = right;
  523. ViewBag.ExcelKind = ExcelKind;
  524. return View();
  525. }
  526. /// <summary>
  527. /// 导入数据
  528. /// </summary>
  529. /// <param name="ExcelData"></param>
  530. [HttpPost]
  531. public string ImportPost(string ExcelPath, int Kind = 0)
  532. {
  533. // RedisDbconn.Instance.AddList("ExcelImport", ExcelPath + "#cut#" + Kind);
  534. string key = function.MD5_16(Guid.NewGuid().ToString());
  535. RedisDbconn.Instance.AddList("ExcelImportV3", ExcelPath + "#cut#" + Kind + "#cut#" + key + "#cut#" + SysUserName);
  536. return "success|" + key;
  537. }
  538. // [HttpPost]
  539. // public Dictionary<string, object> ImportPostV2(string ExcelPath, int Kind = 0)
  540. // {
  541. // Dictionary<string, object> Obj = new Dictionary<string, object>();
  542. // string key = function.MD5_16(Guid.NewGuid().ToString());
  543. // RedisDbconn.Instance.AddList("ExcelImportV2", ExcelPath + "#cut#" + Kind + "#cut#" + key);
  544. // Obj.Add("status", "success");
  545. // Obj.Add("key", key);
  546. // Obj.Add("errlist", RedisDbconn.Instance.GetList<string>("ErrList" + key));
  547. // return Obj;
  548. // }
  549. public string CheckImport(string key)
  550. {
  551. string result = RedisDbconn.Instance.Get<string>("CheckImport:" + key);
  552. if (!string.IsNullOrEmpty(result))
  553. {
  554. string[] datalist = result.Split('|');
  555. if (datalist[0] == "success")
  556. {
  557. return result;
  558. }
  559. return datalist[0];
  560. }
  561. return "0";
  562. }
  563. public Dictionary<string, object> CheckImportV2(string key)
  564. {
  565. Dictionary<string, object> Obj = new Dictionary<string, object>();
  566. string result = RedisDbconn.Instance.Get<string>("CheckImport:" + key);
  567. if (!string.IsNullOrEmpty(result))
  568. {
  569. string[] datalist = result.Split('|');
  570. if (datalist[0] == "success")
  571. {
  572. List<string> errList = RedisDbconn.Instance.GetList<string>("ErrList" + key);
  573. if (errList.Count > 0)
  574. {
  575. Obj.Add("status", 2);
  576. Obj.Add("errList", errList);
  577. }
  578. else
  579. {
  580. Obj.Add("status", 1);
  581. Obj.Add("data", result);
  582. }
  583. return Obj;
  584. }
  585. Obj.Add("status", 0);
  586. Obj.Add("data", datalist[0]);
  587. return Obj;
  588. }
  589. Obj.Add("status", -1);
  590. Obj.Add("data", "执行中...");
  591. return Obj;
  592. }
  593. #endregion
  594. #region 机具驳回仓库
  595. /// <summary>
  596. /// 机具驳回仓库
  597. /// </summary>
  598. /// <param name="ExcelData"></param>
  599. public string RejectStore(string ExcelData, int ExcelKind = 0)
  600. {
  601. ExcelData = HttpUtility.UrlDecode(ExcelData);
  602. JsonData list = JsonMapper.ToObject(ExcelData);
  603. if (ExcelKind == 1)
  604. {
  605. string error = "";
  606. List<string> PosSnList = new List<string>();
  607. for (int i = 1; i < list.Count; i++)
  608. {
  609. JsonData dr = list[i];
  610. string itemJson = dr.ToJson();
  611. string PosSn = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
  612. string BrandId = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
  613. string MakerCode = itemJson.Contains("\"C\"") ? dr["C"].ToString() : "";
  614. string StoreNo = itemJson.Contains("\"D\"") ? dr["D"].ToString() : "";
  615. string No = itemJson.Contains("\"E\"") ? dr["E"].ToString() : "";
  616. string Remark = itemJson.Contains("\"F\"") ? dr["F"].ToString() : "";
  617. UserForMakerCode userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  618. StoreForCode storeForCode = db.StoreForCode.FirstOrDefault(m => m.Code == StoreNo);
  619. var store = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCode.StoreId && m.BrandId == BrandId) ?? new StoreHouse();
  620. MachineForSnNo machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  621. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId && m.BrandId == Convert.ToInt32(BrandId) && m.BindingState == 0 && m.BuyUserId == userForMakerCode.UserId) ?? new PosMachinesTwo();
  622. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId && m.BrandId == Convert.ToInt32(BrandId) && m.BindingState == 0) ?? new PosMachinesTwo();
  623. if (pos.Id == 0)
  624. {
  625. error += "以下操作失败" + PosSn + ',' + "未找到创客" + MakerCode + "的该台机具" + '\n';
  626. }
  627. if (store.Id == 0)
  628. {
  629. error += "以下操作失败" + PosSn + ',' + StoreNo + ',' + "未找到该仓库" + '\n';
  630. }
  631. if (posInfo.Id == 0)
  632. {
  633. error += "以下操作失败" + PosSn + ',' + "未找到该品牌的未使用机具" + '\n';
  634. }
  635. if (PosSnList.Contains(PosSn))
  636. {
  637. error += "以下操作失败" + PosSn + ',' + "该机具号重复" + '\n';
  638. }
  639. else
  640. {
  641. PosSnList.Add(PosSn);
  642. }
  643. }
  644. if (!string.IsNullOrEmpty(error))
  645. {
  646. return "Warning|" + error;
  647. }
  648. for (int i = 1; i < list.Count; i++)
  649. {
  650. JsonData dr = list[i];
  651. string itemJson = dr.ToJson();
  652. string PosSn = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
  653. string BrandId = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
  654. string MakerCode = itemJson.Contains("\"C\"") ? dr["C"].ToString() : "";
  655. string StoreNo = itemJson.Contains("\"D\"") ? dr["D"].ToString() : "";
  656. string No = itemJson.Contains("\"E\"") ? dr["E"].ToString() : "";
  657. string Remark = itemJson.Contains("\"F\"") ? dr["F"].ToString() : "";
  658. decimal amount = 0;
  659. UserForMakerCode userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  660. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  661. StoreForCode storeForCode = db.StoreForCode.FirstOrDefault(m => m.Code == StoreNo);
  662. var fromStore = db.StoreHouse.FirstOrDefault(m => m.Id == pos.StoreId && m.BrandId == BrandId) ?? new StoreHouse();
  663. var toStore = db.StoreHouse.FirstOrDefault(m => m.Id == storeForCode.StoreId && m.BrandId == BrandId) ?? new StoreHouse();
  664. var user = db.Users.FirstOrDefault(m => m.Id == toStore.UserId) ?? new Users();
  665. var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == toStore.UserId) ?? new UserAccount();
  666. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == Convert.ToInt32(BrandId)) ?? new KqProducts();
  667. if (brandInfo.Name.Contains("电签"))
  668. {
  669. amount = 200;
  670. }
  671. if (brandInfo.Name.Contains("大POS"))
  672. {
  673. amount = 300;
  674. }
  675. userAccount.ValidAmount -= amount;
  676. string text = string.Format("导入机具驳回仓库,UserId: '" + user.Id + "',BeforeChangeAmount:'" + userAccount.ValidAmount + "',AfterChangeAmount:'" + userAccount.ValidAmount + amount + "',ChangeAmount:'" + amount + "',Time'" + DateTime.Now + "'");
  677. function.WriteLog(text, "机具驳回仓库");//机具驳回仓库日志
  678. db.SaveChanges();
  679. MachineForSnNo machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  680. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId && m.BrandId == Convert.ToInt32(BrandId) && m.BindingState == 0 && m.BuyUserId == userForMakerCode.UserId);
  681. if (posInfo != null)
  682. {
  683. if (fromStore.Id != toStore.Id)
  684. {
  685. var changeNo = "JJBH" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  686. StoreStockChange stockchange = db.StoreStockChange.Add(new StoreStockChange()
  687. {
  688. CreateDate = DateTime.Now,
  689. StoreId = fromStore.Id, //出货仓库
  690. ToStoreId = toStore.Id, //发货仓库
  691. BrandId = Convert.ToInt32(BrandId), //产品类型
  692. ProductName = RelationClass.GetKqProductBrandInfo(Convert.ToInt32(BrandId)), //产品名称
  693. ChangeNo = changeNo, //变更记录单号
  694. BizBatchNo = No, //业务批次号
  695. TransType = 4, //交易类型
  696. SnNo = PosSn, //SN编号
  697. StockOpDirect = 1, //库存操作方向
  698. SnStatus = 1, //SN状态
  699. DeviceVendor = posInfo.DeviceName, //设备厂商
  700. DeviceModel = posInfo.DeviceKind, //设备型号
  701. DeviceType = posInfo.DeviceType, //设备类型
  702. SourceStoreId = posInfo.SourceStoreId, //源仓库编号
  703. BrandType = posInfo.DeviceType, //品牌类型
  704. }).Entity;
  705. db.SaveChanges();
  706. db.StoreChangeHistory.Add(new StoreChangeHistory()
  707. {
  708. CreateDate = DateTime.Now,
  709. UserId = user.Id, //创客
  710. StoreId = fromStore.Id, //出货仓库
  711. ToStoreId = toStore.Id, //发货仓库
  712. BrandId = Convert.ToInt32(BrandId), //产品类型
  713. ChangeRecordNo = changeNo, //变更记录单号
  714. SeoTitle = "机具驳回仓库",
  715. BizBatchNo = No, //业务批次号
  716. TransType = 4,//驳回
  717. SnNo = PosSn, //SN编号
  718. });
  719. db.SaveChanges();
  720. StoreBalance fbalance = db.StoreBalance.Add(new StoreBalance()
  721. {
  722. CreateDate = DateTime.Now,
  723. StoreId = fromStore.Id, //仓库
  724. BrandId = Convert.ToInt32(BrandId), //产品类型
  725. OpStoreNum = 1, //操作库存数
  726. OpSymbol = "-", //操作符
  727. BeforeTotalNum = fromStore.TotalNum, //操作前总库存数
  728. AfterTotalNum = fromStore.TotalNum - 1, //操作后总库存数
  729. BeforeLaveNum = fromStore.LaveNum, //操作前剩余库存数
  730. AfterLaveNum = fromStore.LaveNum - 1, //操作后剩余库存数
  731. BeforeOutNum = fromStore.OutNum, //操作前出库数
  732. AfterOutNum = fromStore.OutNum - 1, //操作后出库数
  733. }).Entity;
  734. db.SaveChanges();
  735. StoreBalance tbalance = db.StoreBalance.Add(new StoreBalance()
  736. {
  737. CreateDate = DateTime.Now,
  738. StoreId = toStore.Id, //仓库
  739. BrandId = Convert.ToInt32(BrandId), //产品类型
  740. OpStoreNum = 1, //操作库存数
  741. OpSymbol = "+", //操作符
  742. BeforeTotalNum = toStore.TotalNum, //操作前总库存数
  743. AfterTotalNum = toStore.TotalNum + 1, //操作后总库存数
  744. BeforeLaveNum = toStore.LaveNum, //操作前剩余库存数
  745. AfterLaveNum = toStore.LaveNum + 1, //操作后剩余库存数
  746. BeforeOutNum = toStore.OutNum, //操作前出库数
  747. AfterOutNum = toStore.OutNum, //操作后出库数
  748. }).Entity;
  749. db.SaveChanges();
  750. posInfo.StoreId = toStore.Id;
  751. posInfo.BuyUserId = 0;
  752. toStore.TotalNum += 1;
  753. toStore.LaveNum += 1;
  754. fromStore.TotalNum -= 1;
  755. fromStore.LaveNum -= 1;
  756. db.SaveChanges();
  757. }
  758. else
  759. {
  760. var changeNo = "JJBH" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  761. StoreStockChange stockchange = db.StoreStockChange.Add(new StoreStockChange()
  762. {
  763. CreateDate = DateTime.Now,
  764. StoreId = fromStore.Id, //出货仓库
  765. ToStoreId = toStore.Id, //发货仓库
  766. BrandId = Convert.ToInt32(BrandId), //产品类型
  767. ProductName = RelationClass.GetKqProductBrandInfo(Convert.ToInt32(BrandId)), //产品名称
  768. ChangeNo = changeNo, //变更记录单号
  769. BizBatchNo = No, //业务批次号
  770. TransType = 4, //交易类型
  771. SnNo = PosSn, //SN编号
  772. StockOpDirect = 1, //库存操作方向
  773. SnStatus = 1, //SN状态
  774. DeviceVendor = posInfo.DeviceName, //设备厂商
  775. DeviceModel = posInfo.DeviceKind, //设备型号
  776. DeviceType = posInfo.DeviceType, //设备类型
  777. SourceStoreId = posInfo.SourceStoreId, //源仓库编号
  778. BrandType = posInfo.DeviceType, //品牌类型
  779. }).Entity;
  780. db.SaveChanges();
  781. db.StoreChangeHistory.Add(new StoreChangeHistory()
  782. {
  783. CreateDate = DateTime.Now,
  784. UserId = user.Id, //创客
  785. StoreId = fromStore.Id, //出货仓库
  786. ToStoreId = toStore.Id, //发货仓库
  787. BrandId = Convert.ToInt32(BrandId), //产品类型
  788. ChangeRecordNo = changeNo, //变更记录单号
  789. SeoTitle = "机具驳回仓库",
  790. BizBatchNo = No, //业务批次号
  791. SnNo = PosSn, //SN编号
  792. TransType = 4,//驳回
  793. });
  794. db.SaveChanges();
  795. StoreBalance fbalance = db.StoreBalance.Add(new StoreBalance()
  796. {
  797. CreateDate = DateTime.Now,
  798. StoreId = fromStore.Id, //仓库
  799. BrandId = Convert.ToInt32(BrandId), //产品类型
  800. OpStoreNum = 1, //操作库存数
  801. OpSymbol = "-", //操作符
  802. BeforeTotalNum = fromStore.TotalNum, //操作前总库存数
  803. AfterTotalNum = fromStore.TotalNum - 1, //操作后总库存数
  804. BeforeLaveNum = fromStore.LaveNum, //操作前剩余库存数
  805. AfterLaveNum = fromStore.LaveNum - 1, //操作后剩余库存数
  806. BeforeOutNum = fromStore.OutNum, //操作前出库数
  807. AfterOutNum = fromStore.OutNum - 1, //操作后出库数
  808. }).Entity;
  809. db.SaveChanges();
  810. StoreBalance tbalance = db.StoreBalance.Add(new StoreBalance()
  811. {
  812. CreateDate = DateTime.Now,
  813. StoreId = toStore.Id, //仓库
  814. BrandId = Convert.ToInt32(BrandId), //产品类型
  815. OpStoreNum = 1, //操作库存数
  816. OpSymbol = "+", //操作符
  817. BeforeTotalNum = toStore.TotalNum, //操作前总库存数
  818. AfterTotalNum = toStore.TotalNum + 1, //操作后总库存数
  819. BeforeLaveNum = toStore.LaveNum, //操作前剩余库存数
  820. AfterLaveNum = toStore.LaveNum + 1, //操作后剩余库存数
  821. BeforeOutNum = toStore.OutNum, //操作前出库数
  822. AfterOutNum = toStore.OutNum, //操作后出库数
  823. }).Entity;
  824. db.SaveChanges();
  825. posInfo.StoreId = toStore.Id;
  826. posInfo.BuyUserId = 0;
  827. toStore.LaveNum += 1;
  828. db.SaveChanges();
  829. }
  830. db.SaveChanges();
  831. }
  832. }
  833. }
  834. AddSysLog("0", "MachinesRejectStore", "Import");
  835. return "success";
  836. }
  837. #endregion
  838. #region 导出Excel
  839. /// <summary>
  840. /// 导出Excel
  841. /// </summary>
  842. /// <returns></returns>
  843. public JsonResult ExportExcel(StoreHouse data, string UserIdMakerCode, string UserIdRealName, string ManageUserIdRealName, string ManageUserIdMobile, string ManageUserIdMakerCode, string StoreStatusSelect)
  844. {
  845. Dictionary<string, string> Fields = new Dictionary<string, string>();
  846. Fields.Add("StoreNo", "1"); //仓库编号
  847. Fields.Add("CreateDate", "3"); //时间
  848. Fields.Add("StoreName", "1"); //仓库名称
  849. Fields.Add("ManagerEmail", "1"); //管理者邮箱
  850. string condition = " and Status>-1";
  851. //仓库归属人创客编号
  852. if (!string.IsNullOrEmpty(UserIdMakerCode))
  853. {
  854. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  855. }
  856. //仓库归属人真实姓名
  857. if (!string.IsNullOrEmpty(UserIdRealName))
  858. {
  859. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  860. }
  861. //仓库管理员真实姓名
  862. if (!string.IsNullOrEmpty(ManageUserIdRealName))
  863. {
  864. condition += " and ManageUserId in (select ManageUserId from UserForRealName where RealName='" + ManageUserIdRealName + "')";
  865. }
  866. //仓库管理员手机号
  867. if (!string.IsNullOrEmpty(ManageUserIdMobile))
  868. {
  869. condition += " and ManageUserId in (select ManageUserId from UserForMobile where Mobile='" + ManageUserIdMobile + "')";
  870. }
  871. //仓库管理员创客编号
  872. if (!string.IsNullOrEmpty(ManageUserIdMakerCode))
  873. {
  874. condition += " and ManageUserId in (select ManageUserId from UserForMakerCode where MakerCode='" + ManageUserIdMakerCode + "')";
  875. }
  876. //仓库状态
  877. if (!string.IsNullOrEmpty(StoreStatusSelect))
  878. {
  879. condition += " and StoreStatus=" + StoreStatusSelect;
  880. }
  881. 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);
  882. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  883. foreach (Dictionary<string, object> dic in diclist)
  884. {
  885. //仓库归属人
  886. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  887. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  888. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  889. dic["UserIdRealName"] = userid_Users.RealName;
  890. //产品类型
  891. dic["BrandId"] = RelationClass.GetKqProductBrandList(dic["BrandId"].ToString());
  892. //仓库管理员
  893. int ManageUserId = int.Parse(function.CheckInt(dic["ManageUserId"].ToString()));
  894. Users manageuserid_Users = db.Users.FirstOrDefault(m => m.Id == ManageUserId) ?? new Users();
  895. dic["ManageUserIdRealName"] = manageuserid_Users.RealName;
  896. dic["ManageUserIdMobile"] = manageuserid_Users.Mobile;
  897. dic["ManageUserIdMakerCode"] = manageuserid_Users.MakerCode;
  898. //仓库类型
  899. int StoreType = int.Parse(dic["StoreType"].ToString());
  900. if (StoreType == 0) dic["StoreType"] = "实体仓";
  901. if (StoreType == 1) dic["StoreType"] = "虚拟仓";
  902. //仓库状态
  903. int StoreStatus = int.Parse(dic["StoreStatus"].ToString());
  904. if (StoreStatus == 1) dic["StoreStatus"] = "启用";
  905. if (StoreStatus == 0) dic["StoreStatus"] = "禁用";
  906. //仓库归属类型
  907. int StoreKind = int.Parse(dic["StoreKind"].ToString());
  908. if (StoreKind == 0) dic["StoreKind"] = "分仓";
  909. if (StoreKind == 1) dic["StoreKind"] = "总仓";
  910. }
  911. Dictionary<string, object> result = new Dictionary<string, object>();
  912. result.Add("Status", "1");
  913. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  914. result.Add("Obj", diclist);
  915. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  916. ReturnFields.Add("StoreNo", "仓库编号");
  917. ReturnFields.Add("StoreName", "仓库名称");
  918. ReturnFields.Add("UserIdMakerCode", "仓库归属人创客编号");
  919. ReturnFields.Add("UserIdRealName", "仓库归属人真实姓名");
  920. ReturnFields.Add("BrandId", "产品类型");
  921. ReturnFields.Add("Address", "仓库地址");
  922. ReturnFields.Add("ManageUserIdRealName", "仓库管理员真实姓名");
  923. ReturnFields.Add("ManageUserIdMobile", "仓库管理员手机号");
  924. ReturnFields.Add("ManageUserIdMakerCode", "仓库管理员创客编号");
  925. ReturnFields.Add("ManagerEmail", "管理者邮箱");
  926. ReturnFields.Add("StoreType", "仓库类型");
  927. ReturnFields.Add("TotalNum", "总库存数");
  928. ReturnFields.Add("LaveNum", "剩余库存数");
  929. ReturnFields.Add("OutNum", "出库数");
  930. ReturnFields.Add("LimitTopUserId", "限制创客特殊仓库");
  931. ReturnFields.Add("StoreStatus", "仓库状态");
  932. ReturnFields.Add("StoreKind", "仓库归属类型");
  933. result.Add("Fields", ReturnFields);
  934. AddSysLog("0", "StoreHouse", "ExportExcel");
  935. return Json(result);
  936. }
  937. #endregion
  938. #region 仓库列表
  939. /// <summary>
  940. /// 根据条件查询仓库列表
  941. /// </summary>
  942. /// <returns></returns>
  943. public IActionResult Stat(StoreHouse data, string right)
  944. {
  945. ViewBag.RightInfo = RightInfo;
  946. ViewBag.right = right;
  947. return View();
  948. }
  949. #endregion
  950. #region 根据条件查询仓库列表
  951. /// <summary>
  952. /// 仓库列表
  953. /// </summary>
  954. /// <returns></returns>
  955. public JsonResult StatDo(string CreateDateData, int page = 1, int limit = 30)
  956. {
  957. OtherMySqlConn.connstr = ConfigurationManager.AppSettings["StatSqlConnStr"].ToString();
  958. string sCreateDate = DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00";
  959. string eCreateDate = DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59";
  960. if (!string.IsNullOrEmpty(CreateDateData))
  961. {
  962. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  963. sCreateDate = datelist[0] + " 00:00:00";
  964. eCreateDate = datelist[1] + " 23:59:59";
  965. }
  966. else
  967. {
  968. Dictionary<string, object> nodata = new Dictionary<string, object>();
  969. nodata.Add("code", 0);
  970. nodata.Add("msg", "");
  971. nodata.Add("count", 0);
  972. nodata.Add("data", new List<Dictionary<string, object>>());
  973. return Json(nodata);
  974. }
  975. string minId = "0";
  976. string maxId = "0";
  977. string minPosId = "0";
  978. string maxPosId = "0";
  979. DataTable startDt = OtherMySqlConn.dtable("select min(Id) from StoreStockChange where CreateDate>='" + sCreateDate + "'");
  980. if (startDt.Rows.Count > 0)
  981. {
  982. minId = function.CheckInt(startDt.Rows[0][0].ToString());
  983. if (minId == "0")
  984. {
  985. startDt = OtherMySqlConn.dtable("select max(Id) from StoreStockChange");
  986. if (startDt.Rows.Count > 0)
  987. {
  988. minId = function.CheckInt(startDt.Rows[0][0].ToString());
  989. }
  990. }
  991. }
  992. DataTable endDt = OtherMySqlConn.dtable("select max(Id) from StoreStockChange where CreateDate>='" + sCreateDate + "'");
  993. if (endDt.Rows.Count > 0)
  994. {
  995. maxId = function.CheckInt(endDt.Rows[0][0].ToString());
  996. if (minId == "0")
  997. {
  998. endDt = OtherMySqlConn.dtable("select max(Id) from StoreStockChange");
  999. if (endDt.Rows.Count > 0)
  1000. {
  1001. maxId = function.CheckInt(endDt.Rows[0][0].ToString());
  1002. }
  1003. }
  1004. }
  1005. DataTable startPosDt = OtherMySqlConn.dtable("select min(Id) from PosMachinesTwo where ActivationTime>='" + sCreateDate + "'");
  1006. if (startPosDt.Rows.Count > 0)
  1007. {
  1008. minPosId = function.CheckInt(startPosDt.Rows[0][0].ToString());
  1009. if (minPosId == "0")
  1010. {
  1011. startPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo");
  1012. if (startPosDt.Rows.Count > 0)
  1013. {
  1014. minPosId = function.CheckInt(startPosDt.Rows[0][0].ToString());
  1015. }
  1016. }
  1017. }
  1018. DataTable endPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo where ActivationTime>='" + sCreateDate + "'");
  1019. if (endPosDt.Rows.Count > 0)
  1020. {
  1021. maxPosId = function.CheckInt(endPosDt.Rows[0][0].ToString());
  1022. if (maxPosId == "0")
  1023. {
  1024. endPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo");
  1025. if (endPosDt.Rows.Count > 0)
  1026. {
  1027. maxPosId = function.CheckInt(endPosDt.Rows[0][0].ToString());
  1028. }
  1029. }
  1030. }
  1031. DataTable list = OtherMySqlConn.dtable("select * from (select s.StoreName,s.StoreNo,u.RealName,u.Mobile,k.Name,s.LaveNum,(select count(Id) from StoreStockChange where Id>=" + minId + " and Id<=" + maxId + " and CreateDate>='" + sCreateDate + "' and CreateDate<='" + eCreateDate + "' and StoreId=s.Id and TransType=1) as c1,(select count(Id) from StoreStockChange where Id>=" + minId + " and Id<=" + maxId + " and CreateDate>='" + sCreateDate + "' and CreateDate<='" + eCreateDate + "' and StoreId=s.Id and TransType in (10,11,2)) as c2,(select count(Id) from PosMachinesTwo where Id>=" + minPosId + " and Id<=" + maxPosId + " and ActivationState=1 and ActivationTime>='" + sCreateDate + "' and ActivationTime<='" + eCreateDate + "' and StoreId=s.Id) as c3 from StoreHouse s left join Users u on s.BrandId>0 and s.UserId=u.Id left join KqProducts k on s.BrandId=k.Id) tb where c1>0 or c2>0 or c3>0");
  1032. int recordcount = list.Rows.Count;
  1033. List<Dictionary<string, object>> diclist = new List<Dictionary<string, object>>();
  1034. foreach (DataRow sub in list.Rows)
  1035. {
  1036. Dictionary<string, object> row = new Dictionary<string, object>();
  1037. row.Add("StoreName", sub["StoreName"].ToString());
  1038. row.Add("StoreNo", sub["StoreNo"].ToString());
  1039. row.Add("Mobile", sub["Mobile"].ToString());
  1040. row.Add("RealName", sub["RealName"].ToString());
  1041. row.Add("Name", sub["Name"].ToString());
  1042. row.Add("LaveNum", sub["LaveNum"].ToString());
  1043. row.Add("c1", sub["c1"].ToString());
  1044. row.Add("c2", sub["c2"].ToString());
  1045. row.Add("c3", sub["c3"].ToString());
  1046. diclist.Add(row);
  1047. }
  1048. Dictionary<string, object> obj = new Dictionary<string, object>();
  1049. obj.Add("code", 0);
  1050. obj.Add("msg", "");
  1051. obj.Add("count", recordcount);
  1052. obj.Add("data", diclist);
  1053. return Json(obj);
  1054. }
  1055. #endregion
  1056. #region 导出Excel
  1057. /// <summary>
  1058. /// 导出Excel
  1059. /// </summary>
  1060. /// <returns></returns>
  1061. public JsonResult StatExportExcel(string CreateDateData)
  1062. {
  1063. OtherMySqlConn.connstr = ConfigurationManager.AppSettings["StatSqlConnStr"].ToString();
  1064. string sCreateDate = DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00";
  1065. string eCreateDate = DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59";
  1066. if (!string.IsNullOrEmpty(CreateDateData))
  1067. {
  1068. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  1069. sCreateDate = datelist[0] + " 00:00:00";
  1070. eCreateDate = datelist[1] + " 23:59:59";
  1071. }
  1072. else
  1073. {
  1074. Dictionary<string, object> nodata = new Dictionary<string, object>();
  1075. nodata.Add("Status", "1");
  1076. nodata.Add("Info", "分仓统计数据报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1077. nodata.Add("Obj", new List<Dictionary<string, object>>());
  1078. Dictionary<string, object> NoDataReturnFields = new Dictionary<string, object>();
  1079. NoDataReturnFields.Add("StoreName", "仓库名称");
  1080. NoDataReturnFields.Add("StoreNo", "仓库编号");
  1081. NoDataReturnFields.Add("Mobile", "仓库所属人手机号");
  1082. NoDataReturnFields.Add("RealName", "仓库所属人名称");
  1083. NoDataReturnFields.Add("MakerCode", "仓库所属人编码");
  1084. NoDataReturnFields.Add("ManageMakerCode", "仓库管理员编码");
  1085. NoDataReturnFields.Add("Name", "品牌");
  1086. NoDataReturnFields.Add("LaveNum", "当前库存");
  1087. NoDataReturnFields.Add("c1", "出库(调拨)量");
  1088. NoDataReturnFields.Add("c2", "出货(发货到创客)量");
  1089. NoDataReturnFields.Add("c3", "激活量");
  1090. nodata.Add("Fields", NoDataReturnFields);
  1091. return Json(nodata);
  1092. }
  1093. string minId = "0";
  1094. string maxId = "0";
  1095. string minPosId = "0";
  1096. string maxPosId = "0";
  1097. DataTable startDt = OtherMySqlConn.dtable("select min(Id) from StoreStockChange where CreateDate>='" + sCreateDate + "'");
  1098. if (startDt.Rows.Count > 0)
  1099. {
  1100. minId = function.CheckInt(startDt.Rows[0][0].ToString());
  1101. if (minId == "0")
  1102. {
  1103. startDt = OtherMySqlConn.dtable("select max(Id) from StoreStockChange");
  1104. if (startDt.Rows.Count > 0)
  1105. {
  1106. minId = function.CheckInt(startDt.Rows[0][0].ToString());
  1107. }
  1108. }
  1109. }
  1110. DataTable endDt = OtherMySqlConn.dtable("select max(Id) from StoreStockChange where CreateDate>='" + sCreateDate + "'");
  1111. if (endDt.Rows.Count > 0)
  1112. {
  1113. maxId = function.CheckInt(endDt.Rows[0][0].ToString());
  1114. if (minId == "0")
  1115. {
  1116. endDt = OtherMySqlConn.dtable("select max(Id) from StoreStockChange");
  1117. if (endDt.Rows.Count > 0)
  1118. {
  1119. maxId = function.CheckInt(endDt.Rows[0][0].ToString());
  1120. }
  1121. }
  1122. }
  1123. DataTable startPosDt = OtherMySqlConn.dtable("select min(Id) from PosMachinesTwo where ActivationTime>='" + sCreateDate + "'");
  1124. if (startPosDt.Rows.Count > 0)
  1125. {
  1126. minPosId = function.CheckInt(startPosDt.Rows[0][0].ToString());
  1127. if (minPosId == "0")
  1128. {
  1129. startPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo");
  1130. if (startPosDt.Rows.Count > 0)
  1131. {
  1132. minPosId = function.CheckInt(startPosDt.Rows[0][0].ToString());
  1133. }
  1134. }
  1135. }
  1136. DataTable endPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo where ActivationTime>='" + sCreateDate + "'");
  1137. if (endPosDt.Rows.Count > 0)
  1138. {
  1139. maxPosId = function.CheckInt(endPosDt.Rows[0][0].ToString());
  1140. if (maxPosId == "0")
  1141. {
  1142. endPosDt = OtherMySqlConn.dtable("select max(Id) from PosMachinesTwo");
  1143. if (endPosDt.Rows.Count > 0)
  1144. {
  1145. maxPosId = function.CheckInt(endPosDt.Rows[0][0].ToString());
  1146. }
  1147. }
  1148. }
  1149. DataTable list = OtherMySqlConn.dtable("select * from (select s.StoreName,s.StoreNo,u.RealName,u.Mobile,u.MakerCode,(select MakerCode from Users where Id=s.ManageUserId) as ManageMakerCode,k.Name,s.LaveNum,(select count(Id) from StoreStockChange where Id>=" + minId + " and Id<=" + maxId + " and CreateDate>='" + sCreateDate + "' and CreateDate<='" + eCreateDate + "' and StoreId=s.Id and TransType=1) as c1,(select count(Id) from StoreStockChange where Id>=" + minId + " and Id<=" + maxId + " and CreateDate>='" + sCreateDate + "' and CreateDate<='" + eCreateDate + "' and StoreId=s.Id and TransType in (10,11,2)) as c2,(select count(Id) from PosMachinesTwo where Id>=" + minPosId + " and Id<=" + maxPosId + " and ActivationState=1 and ActivationTime>='" + sCreateDate + "' and ActivationTime<='" + eCreateDate + "' and StoreId=s.Id) as c3 from StoreHouse s left join Users u on s.BrandId>0 and s.UserId=u.Id left join KqProducts k on s.BrandId=k.Id) tb where c1>0 or c2>0 or c3>0");
  1150. int recordcount = list.Rows.Count;
  1151. List<Dictionary<string, object>> diclist = new List<Dictionary<string, object>>();
  1152. foreach (DataRow sub in list.Rows)
  1153. {
  1154. Dictionary<string, object> row = new Dictionary<string, object>();
  1155. row.Add("StoreName", sub["StoreName"].ToString());
  1156. row.Add("StoreNo", sub["StoreNo"].ToString());
  1157. row.Add("Mobile", sub["Mobile"].ToString());
  1158. row.Add("RealName", sub["RealName"].ToString());
  1159. row.Add("MakerCode", sub["MakerCode"].ToString());
  1160. row.Add("ManageMakerCode", sub["ManageMakerCode"].ToString());
  1161. row.Add("Name", sub["Name"].ToString());
  1162. row.Add("LaveNum", sub["LaveNum"].ToString());
  1163. row.Add("c1", sub["c1"].ToString());
  1164. row.Add("c2", sub["c2"].ToString());
  1165. row.Add("c3", sub["c3"].ToString());
  1166. diclist.Add(row);
  1167. }
  1168. Dictionary<string, object> result = new Dictionary<string, object>();
  1169. result.Add("Status", "1");
  1170. result.Add("Info", "分仓统计数据报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  1171. result.Add("Obj", diclist);
  1172. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  1173. ReturnFields.Add("StoreName", "仓库名称");
  1174. ReturnFields.Add("StoreNo", "仓库编号");
  1175. ReturnFields.Add("Mobile", "仓库所属人手机号");
  1176. ReturnFields.Add("RealName", "仓库所属人名称");
  1177. ReturnFields.Add("MakerCode", "仓库所属人编码");
  1178. ReturnFields.Add("ManageMakerCode", "仓库管理员编码");
  1179. ReturnFields.Add("Name", "品牌");
  1180. ReturnFields.Add("LaveNum", "当前库存");
  1181. ReturnFields.Add("c1", "出库(调拨)量");
  1182. ReturnFields.Add("c2", "出货(发货到创客)量");
  1183. ReturnFields.Add("c3", "激活量");
  1184. result.Add("Fields", ReturnFields);
  1185. AddSysLog("0", "StoreHouse", "StatExportExcel");
  1186. return Json(result);
  1187. }
  1188. #endregion
  1189. #region 同步数据
  1190. /// <summary>
  1191. /// 同步数据
  1192. /// </summary>
  1193. /// <returns></returns>
  1194. public string SycnData(int Id = 0)
  1195. {
  1196. if (Id > 0)
  1197. {
  1198. DataTable dt = OtherMySqlConn.dtable("select Id,(select count(Id) from PosMachinesTwo where StoreId=s.Id and BuyUserId=0 and PreUserId=0 and Status>-1) as CurLaveNum from StoreHouse s where Id=" + Id);
  1199. if (dt.Rows.Count > 0)
  1200. {
  1201. int CurLaveNum = int.Parse(function.CheckInt(dt.Rows[0]["CurLaveNum"].ToString()));
  1202. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == Id);
  1203. if (store != null)
  1204. {
  1205. store.LaveNum = CurLaveNum;
  1206. db.SaveChanges();
  1207. }
  1208. }
  1209. }
  1210. else
  1211. {
  1212. 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.BuyUserId=0 and p.PreUserId=0 and p.Status>-1 group by s.Id HAVING LaveNum!=count(p.Id)");
  1213. foreach (DataRow dr in dt.Rows)
  1214. {
  1215. int StoreId = int.Parse(function.CheckInt(dr["Id"].ToString()));
  1216. int CurLaveNum = int.Parse(function.CheckInt(dr["CurLaveNum"].ToString()));
  1217. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId);
  1218. if (store != null)
  1219. {
  1220. store.LaveNum = CurLaveNum;
  1221. db.SaveChanges();
  1222. }
  1223. }
  1224. }
  1225. AddSysLog(Id, "StoreHouse", "SycnData");
  1226. db.SaveChanges();
  1227. return "success";
  1228. }
  1229. #endregion
  1230. #region 设置缓存
  1231. private void SetRedis(int Id, int UserId)
  1232. {
  1233. if (UserId > 0)
  1234. {
  1235. RedisDbconn.Instance.Clear("StoreHouseList:" + UserId);
  1236. List<StoreHouse> stores = db.StoreHouse.Where(m => m.Status > -1 && m.UserId == UserId).OrderByDescending(m => m.Sort).ThenByDescending(m => m.Id).ToList();
  1237. RedisDbconn.Instance.Clear("StoreHouse");
  1238. stores = db.StoreHouse.Where(m => m.Status > -1).OrderByDescending(m => m.Sort).ThenByDescending(m => m.Id).ToList();
  1239. }
  1240. if (Id > 0)
  1241. {
  1242. StoreHouse edit = db.StoreHouse.FirstOrDefault(m => m.Id == Id);
  1243. if (edit != null)
  1244. {
  1245. RedisDbconn.Instance.Clear("StoreHouse:" + Id);
  1246. }
  1247. }
  1248. }
  1249. #endregion
  1250. }
  1251. }