StoreStockChangeController.cs 21 KB

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