StoreHouseController.cs 68 KB

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