StoreHouseController.cs 67 KB

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