StoreHouseController.cs 67 KB

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