StoreHouseOperateController.cs 69 KB

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