StoreStockChangeController.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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.Threading.Tasks;
  10. using Microsoft.AspNetCore.Mvc;
  11. using Microsoft.AspNetCore.Http;
  12. using Microsoft.Extensions.Logging;
  13. using Microsoft.Extensions.Options;
  14. using MySystem.Models;
  15. using Library;
  16. using LitJson;
  17. using MySystemLib;
  18. namespace MySystem.Areas.Admin.Controllers
  19. {
  20. [Area("Admin")]
  21. [Route("Admin/[controller]/[action]")]
  22. public class StoreStockChangeController : BaseController
  23. {
  24. public StoreStockChangeController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  25. {
  26. OtherMySqlConn.connstr = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  27. }
  28. #region 仓库库存变动记录列表
  29. /// <summary>
  30. /// 根据条件查询仓库库存变动记录列表
  31. /// </summary>
  32. /// <returns></returns>
  33. public IActionResult Index(StoreStockChange data, string right)
  34. {
  35. ViewBag.RightInfo = RightInfo;
  36. ViewBag.right = right;
  37. return View();
  38. }
  39. #endregion
  40. #region 根据条件查询仓库库存变动记录列表
  41. /// <summary>
  42. /// 仓库库存变动记录列表
  43. /// </summary>
  44. /// <returns></returns>
  45. public JsonResult IndexData(StoreStockChange data, string StoreIdStoreNo, string StoreIdStoreName, string BrandIdSelect, string TransTypeSelect, string StockOpDirectSelect, string SnStatusSelect, string BindStatusSelect, string BindMerchantMerchantNo, string BindMerchantMerchantName, string ActiveStatusSelect, string BrandTypeSelect, int page = 1, int limit = 30)
  46. {
  47. Dictionary<string, string> Fields = new Dictionary<string, string>();
  48. Fields.Add("CreateDate", "3"); //时间
  49. Fields.Add("SnNo", "1"); //SN编号
  50. string condition = " and Status>-1";
  51. //仓库编号
  52. if (!string.IsNullOrEmpty(StoreIdStoreNo))
  53. {
  54. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreIdStoreNo + "')";
  55. }
  56. //仓库名称
  57. if (!string.IsNullOrEmpty(StoreIdStoreName))
  58. {
  59. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreIdStoreName + "')";
  60. }
  61. //产品类型
  62. if (!string.IsNullOrEmpty(BrandIdSelect))
  63. {
  64. condition += " and BrandId=" + BrandIdSelect;
  65. }
  66. //交易类型
  67. if (!string.IsNullOrEmpty(TransTypeSelect))
  68. {
  69. condition += " and TransType=" + TransTypeSelect;
  70. }
  71. //库存操作方向
  72. if (!string.IsNullOrEmpty(StockOpDirectSelect))
  73. {
  74. condition += " and StockOpDirect=" + StockOpDirectSelect;
  75. }
  76. //SN状态
  77. if (!string.IsNullOrEmpty(SnStatusSelect))
  78. {
  79. condition += " and SnStatus=" + SnStatusSelect;
  80. }
  81. //绑定状态
  82. if (!string.IsNullOrEmpty(BindStatusSelect))
  83. {
  84. condition += " and BindStatus=" + BindStatusSelect;
  85. }
  86. //绑定商户商户编号
  87. if (!string.IsNullOrEmpty(BindMerchantMerchantNo))
  88. {
  89. condition += " and BindMerchant in (select BindMerchant from MerchantForCode where Code='" + BindMerchantMerchantNo + "')";
  90. }
  91. //绑定商户商户姓名
  92. if (!string.IsNullOrEmpty(BindMerchantMerchantName))
  93. {
  94. condition += " and BindMerchant in (select BindMerchant from MerchantForName where Name='" + BindMerchantMerchantName + "')";
  95. }
  96. //激活状态
  97. if (!string.IsNullOrEmpty(ActiveStatusSelect))
  98. {
  99. condition += " and ActiveStatus=" + ActiveStatusSelect;
  100. }
  101. //品牌类型
  102. if (!string.IsNullOrEmpty(BrandTypeSelect))
  103. {
  104. condition += " and BrandType=" + BrandTypeSelect;
  105. }
  106. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("StoreStockChange", Fields, "Id desc", "0", page, limit, condition);
  107. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  108. foreach (Dictionary<string, object> dic in diclist)
  109. {
  110. //仓库
  111. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  112. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  113. dic["StoreIdStoreNo"] = storeid_StoreHouse.StoreNo;
  114. dic["StoreIdStoreName"] = storeid_StoreHouse.StoreName;
  115. dic.Remove("StoreId");
  116. //产品类型
  117. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  118. //交易类型
  119. int TransType = int.Parse(dic["TransType"].ToString());
  120. if (TransType == 1) dic["TransType"] = "调拨";
  121. if (TransType == 2) dic["TransType"] = "出货";
  122. if (TransType == 3) dic["TransType"] = "退货";
  123. if (TransType == 0) dic["TransType"] = "采购";
  124. //库存操作方向
  125. int StockOpDirect = int.Parse(dic["StockOpDirect"].ToString());
  126. if (StockOpDirect == 0) dic["StockOpDirect"] = "入库";
  127. if (StockOpDirect == 1) dic["StockOpDirect"] = "出库";
  128. //SN状态
  129. int SnStatus = int.Parse(dic["SnStatus"].ToString());
  130. if (SnStatus == 0) dic["SnStatus"] = "未拨出";
  131. if (SnStatus == 1) dic["SnStatus"] = "已拨出";
  132. //绑定状态
  133. int BindStatus = int.Parse(dic["BindStatus"].ToString());
  134. if (BindStatus == 0) dic["BindStatus"] = "未绑定";
  135. if (BindStatus == 1) dic["BindStatus"] = "已绑定";
  136. //绑定商户
  137. int BindMerchant = int.Parse(function.CheckInt(dic["BindMerchant"].ToString()));
  138. MerchantInfo bindmerchant_MerchantInfo = db.MerchantInfo.FirstOrDefault(m => m.Id == BindMerchant) ?? new MerchantInfo();
  139. dic["BindMerchantMerchantNo"] = "";
  140. dic["BindMerchantMerchantName"] = bindmerchant_MerchantInfo.Name;
  141. dic.Remove("BindMerchant");
  142. //激活状态
  143. int ActiveStatus = int.Parse(dic["ActiveStatus"].ToString());
  144. if (ActiveStatus == 0) dic["ActiveStatus"] = "未激活";
  145. if (ActiveStatus == 1) dic["ActiveStatus"] = "已激活";
  146. //品牌类型
  147. string BrandType = dic["BrandType"].ToString();
  148. if (BrandType == "KysSignPos") dic["BrandType"] = "快益刷电签POS";
  149. if (BrandType == "KssSignPos") dic["BrandType"] = "快闪刷电签POS";
  150. if (BrandType == "") dic["BrandType"] = "";
  151. }
  152. return Json(obj);
  153. }
  154. #endregion
  155. #region 增加仓库库存变动记录
  156. /// <summary>
  157. /// 增加或修改仓库库存变动记录信息
  158. /// </summary>
  159. /// <returns></returns>
  160. public IActionResult Add(string right)
  161. {
  162. ViewBag.RightInfo = RightInfo;
  163. ViewBag.right = right;
  164. return View();
  165. }
  166. #endregion
  167. #region 增加仓库库存变动记录
  168. /// <summary>
  169. /// 增加或修改仓库库存变动记录信息
  170. /// </summary>
  171. /// <returns></returns>
  172. [HttpPost]
  173. public string Add(StoreStockChange data)
  174. {
  175. Dictionary<string, object> Fields = new Dictionary<string, object>();
  176. Fields.Add("SeoTitle", data.SeoTitle);
  177. Fields.Add("SeoKeyword", data.SeoKeyword);
  178. Fields.Add("SeoDescription", data.SeoDescription);
  179. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("StoreStockChange", Fields, 0);
  180. AddSysLog(data.Id.ToString(), "StoreStockChange", "add");
  181. db.SaveChanges();
  182. return "success";
  183. }
  184. #endregion
  185. #region 修改仓库库存变动记录
  186. /// <summary>
  187. /// 增加或修改仓库库存变动记录信息
  188. /// </summary>
  189. /// <returns></returns>
  190. public IActionResult Edit(string right, int Id = 0)
  191. {
  192. ViewBag.RightInfo = RightInfo;
  193. ViewBag.right = right;
  194. StoreStockChange editData = db.StoreStockChange.FirstOrDefault(m => m.Id == Id) ?? new StoreStockChange();
  195. ViewBag.data = editData;
  196. return View();
  197. }
  198. #endregion
  199. #region 修改仓库库存变动记录
  200. /// <summary>
  201. /// 增加或修改仓库库存变动记录信息
  202. /// </summary>
  203. /// <returns></returns>
  204. [HttpPost]
  205. public string Edit(StoreStockChange data)
  206. {
  207. Dictionary<string, object> Fields = new Dictionary<string, object>();
  208. Fields.Add("SeoTitle", data.SeoTitle);
  209. Fields.Add("SeoKeyword", data.SeoKeyword);
  210. Fields.Add("SeoDescription", data.SeoDescription);
  211. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreStockChange", Fields, data.Id);
  212. AddSysLog(data.Id.ToString(), "StoreStockChange", "update");
  213. db.SaveChanges();
  214. return "success";
  215. }
  216. #endregion
  217. #region 删除仓库库存变动记录信息
  218. /// <summary>
  219. /// 删除仓库库存变动记录信息
  220. /// </summary>
  221. /// <returns></returns>
  222. public string Delete(string Id)
  223. {
  224. string[] idlist = Id.Split(new char[] { ',' });
  225. AddSysLog(Id, "StoreStockChange", "del");
  226. foreach (string subid in idlist)
  227. {
  228. int id = int.Parse(subid);
  229. Dictionary<string, object> Fields = new Dictionary<string, object>();
  230. Fields.Add("Status", -1);
  231. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreStockChange", Fields, id);
  232. }
  233. db.SaveChanges();
  234. return "success";
  235. }
  236. #endregion
  237. #region 开启
  238. /// <summary>
  239. /// 开启
  240. /// </summary>
  241. /// <returns></returns>
  242. public string Open(string Id)
  243. {
  244. string[] idlist = Id.Split(new char[] { ',' });
  245. AddSysLog(Id, "StoreStockChange", "open");
  246. foreach (string subid in idlist)
  247. {
  248. int id = int.Parse(subid);
  249. Dictionary<string, object> Fields = new Dictionary<string, object>();
  250. Fields.Add("Status", 1);
  251. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreStockChange", Fields, id);
  252. }
  253. db.SaveChanges();
  254. return "success";
  255. }
  256. #endregion
  257. #region 关闭
  258. /// <summary>
  259. /// 关闭
  260. /// </summary>
  261. /// <returns></returns>
  262. public string Close(string Id)
  263. {
  264. string[] idlist = Id.Split(new char[] { ',' });
  265. AddSysLog(Id, "StoreStockChange", "close");
  266. foreach (string subid in idlist)
  267. {
  268. int id = int.Parse(subid);
  269. Dictionary<string, object> Fields = new Dictionary<string, object>();
  270. Fields.Add("Status", 0);
  271. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreStockChange", Fields, id);
  272. }
  273. db.SaveChanges();
  274. return "success";
  275. }
  276. #endregion
  277. #region 排序
  278. /// <summary>
  279. /// 排序
  280. /// </summary>
  281. /// <param name="Id"></param>
  282. public string Sort(int Id, int Sort)
  283. {
  284. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("StoreStockChange", Sort, Id);
  285. AddSysLog(Id.ToString(), "StoreStockChange", "sort");
  286. return "success";
  287. }
  288. #endregion
  289. #region 导入数据
  290. /// <summary>
  291. /// 导入数据
  292. /// </summary>
  293. /// <param name="ExcelData"></param>
  294. public string Import(string ExcelData)
  295. {
  296. ExcelData = HttpUtility.UrlDecode(ExcelData);
  297. JsonData list = JsonMapper.ToObject(ExcelData);
  298. for (int i = 1; i < list.Count; i++)
  299. {
  300. JsonData dr = list[i];
  301. db.StoreStockChange.Add(new StoreStockChange()
  302. {
  303. CreateDate = DateTime.Now,
  304. UpdateDate = DateTime.Now,
  305. });
  306. db.SaveChanges();
  307. }
  308. AddSysLog("0", "StoreStockChange", "Import");
  309. return "success";
  310. }
  311. #endregion
  312. #region 导出Excel
  313. /// <summary>
  314. /// 导出Excel
  315. /// </summary>
  316. /// <returns></returns>
  317. public JsonResult ExportExcel(StoreStockChange data, string StoreIdStoreNo, string StoreIdStoreName, string BrandIdSelect, string TransTypeSelect, string StockOpDirectSelect, string SnStatusSelect, string BindStatusSelect, string BindMerchantMerchantNo, string BindMerchantMerchantName, string ActiveStatusSelect, string BrandTypeSelect)
  318. {
  319. Dictionary<string, string> Fields = new Dictionary<string, string>();
  320. Fields.Add("CreateDate", "3"); //时间
  321. Fields.Add("SnNo", "1"); //SN编号
  322. string condition = " and Status>-1";
  323. //仓库编号
  324. if (!string.IsNullOrEmpty(StoreIdStoreNo))
  325. {
  326. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreIdStoreNo + "')";
  327. }
  328. //仓库名称
  329. if (!string.IsNullOrEmpty(StoreIdStoreName))
  330. {
  331. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreIdStoreName + "')";
  332. }
  333. //产品类型
  334. if (!string.IsNullOrEmpty(BrandIdSelect))
  335. {
  336. condition += " and BrandId=" + BrandIdSelect;
  337. }
  338. //交易类型
  339. if (!string.IsNullOrEmpty(TransTypeSelect))
  340. {
  341. condition += " and TransType=" + TransTypeSelect;
  342. }
  343. //库存操作方向
  344. if (!string.IsNullOrEmpty(StockOpDirectSelect))
  345. {
  346. condition += " and StockOpDirect=" + StockOpDirectSelect;
  347. }
  348. //SN状态
  349. if (!string.IsNullOrEmpty(SnStatusSelect))
  350. {
  351. condition += " and SnStatus=" + SnStatusSelect;
  352. }
  353. //绑定状态
  354. if (!string.IsNullOrEmpty(BindStatusSelect))
  355. {
  356. condition += " and BindStatus=" + BindStatusSelect;
  357. }
  358. //绑定商户商户编号
  359. if (!string.IsNullOrEmpty(BindMerchantMerchantNo))
  360. {
  361. condition += " and BindMerchant in (select BindMerchant from MerchantForCode where Code='" + BindMerchantMerchantNo + "')";
  362. }
  363. //绑定商户商户姓名
  364. if (!string.IsNullOrEmpty(BindMerchantMerchantName))
  365. {
  366. condition += " and BindMerchant in (select BindMerchant from MerchantForName where Name='" + BindMerchantMerchantName + "')";
  367. }
  368. //激活状态
  369. if (!string.IsNullOrEmpty(ActiveStatusSelect))
  370. {
  371. condition += " and ActiveStatus=" + ActiveStatusSelect;
  372. }
  373. //品牌类型
  374. if (!string.IsNullOrEmpty(BrandTypeSelect))
  375. {
  376. condition += " and BrandType=" + BrandTypeSelect;
  377. }
  378. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("StoreStockChange", Fields, "Id desc", "0", 1, 20000, condition, "StoreId,BrandId,TransType,SnNo,StockOpDirect,SnStatus,BindStatus,BindMerchant,ActiveStatus,ExpressNo,BrandType", false);
  379. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  380. foreach (Dictionary<string, object> dic in diclist)
  381. {
  382. //仓库
  383. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  384. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  385. dic["StoreIdStoreNo"] = storeid_StoreHouse.StoreNo;
  386. dic["StoreIdStoreName"] = storeid_StoreHouse.StoreName;
  387. dic.Remove("StoreId");
  388. //产品类型
  389. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  390. //交易类型
  391. int TransType = int.Parse(dic["TransType"].ToString());
  392. if (TransType == 1) dic["TransType"] = "调拨";
  393. if (TransType == 2) dic["TransType"] = "出货";
  394. if (TransType == 3) dic["TransType"] = "退货";
  395. if (TransType == 0) dic["TransType"] = "采购";
  396. //库存操作方向
  397. int StockOpDirect = int.Parse(dic["StockOpDirect"].ToString());
  398. if (StockOpDirect == 0) dic["StockOpDirect"] = "入库";
  399. if (StockOpDirect == 1) dic["StockOpDirect"] = "出库";
  400. //SN状态
  401. int SnStatus = int.Parse(dic["SnStatus"].ToString());
  402. if (SnStatus == 0) dic["SnStatus"] = "未拨出";
  403. if (SnStatus == 1) dic["SnStatus"] = "已拨出";
  404. //绑定状态
  405. int BindStatus = int.Parse(dic["BindStatus"].ToString());
  406. if (BindStatus == 0) dic["BindStatus"] = "未绑定";
  407. if (BindStatus == 1) dic["BindStatus"] = "已绑定";
  408. //绑定商户
  409. int BindMerchant = int.Parse(function.CheckInt(dic["BindMerchant"].ToString()));
  410. MerchantInfo bindmerchant_MerchantInfo = db.MerchantInfo.FirstOrDefault(m => m.Id == BindMerchant) ?? new MerchantInfo();
  411. dic["BindMerchantMerchantNo"] = "";
  412. dic["BindMerchantMerchantName"] = bindmerchant_MerchantInfo.Name;
  413. dic.Remove("BindMerchant");
  414. //激活状态
  415. int ActiveStatus = int.Parse(dic["ActiveStatus"].ToString());
  416. if (ActiveStatus == 0) dic["ActiveStatus"] = "未激活";
  417. if (ActiveStatus == 1) dic["ActiveStatus"] = "已激活";
  418. //品牌类型
  419. string BrandType = dic["BrandType"].ToString();
  420. if (BrandType == "KysSignPos") dic["BrandType"] = "快益刷电签POS";
  421. if (BrandType == "KssSignPos") dic["BrandType"] = "快闪刷电签POS";
  422. if (BrandType == "") dic["BrandType"] = "";
  423. }
  424. Dictionary<string, object> result = new Dictionary<string, object>();
  425. result.Add("Status", "1");
  426. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  427. result.Add("Obj", diclist);
  428. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  429. ReturnFields.Add("StoreIdStoreNo", "仓库编号");
  430. ReturnFields.Add("StoreIdStoreName", "仓库名称");
  431. ReturnFields.Add("BrandId", "产品类型");
  432. ReturnFields.Add("TransType", "交易类型");
  433. ReturnFields.Add("SnNo", "SN编号");
  434. ReturnFields.Add("StockOpDirect", "库存操作方向");
  435. ReturnFields.Add("SnStatus", "SN状态");
  436. ReturnFields.Add("BindStatus", "绑定状态");
  437. ReturnFields.Add("BindMerchantMerchantNo", "绑定商户编号");
  438. ReturnFields.Add("BindMerchantMerchantName", "绑定商户姓名");
  439. ReturnFields.Add("ActiveStatus", "激活状态");
  440. ReturnFields.Add("ExpressNo", "快递单号");
  441. ReturnFields.Add("BrandType", "品牌类型");
  442. ReturnFields.Add("CreateDate", "变动时间");
  443. result.Add("Fields", ReturnFields);
  444. AddSysLog("0", "StoreStockChange", "ExportExcel");
  445. return Json(result);
  446. }
  447. #endregion
  448. }
  449. }