StoreStockChangeController.cs 22 KB

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