StoreSnActivateSummaryController.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. /*
  2. * 仓库SN激活统计
  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 StoreSnActivateSummaryController : BaseController
  23. {
  24. public StoreSnActivateSummaryController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  25. {
  26. OtherMySqlConn.connstr = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  27. }
  28. #region 仓库SN激活统计列表
  29. /// <summary>
  30. /// 根据条件查询仓库SN激活统计列表
  31. /// </summary>
  32. /// <returns></returns>
  33. public IActionResult Index(StoreSnActivateSummary data, string right)
  34. {
  35. ViewBag.RightInfo = RightInfo;
  36. ViewBag.right = right;
  37. return View();
  38. }
  39. #endregion
  40. #region 根据条件查询仓库SN激活统计列表
  41. /// <summary>
  42. /// 仓库SN激活统计列表
  43. /// </summary>
  44. /// <returns></returns>
  45. public JsonResult IndexData(StoreSnActivateSummary data, string StoreIdStoreNo, string StoreIdStoreName, string AgentStoreIdStoreNo, string AgentStoreIdStoreName, string BrandIdSelect, string CreateDateData, int page = 1, int limit = 30)
  46. {
  47. Dictionary<string, string> Fields = new Dictionary<string, string>();
  48. string condition = " and Status>-1";
  49. //仓库仓库编号
  50. if (!string.IsNullOrEmpty(StoreIdStoreNo))
  51. {
  52. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreIdStoreNo + "')";
  53. }
  54. //仓库仓库名称
  55. if (!string.IsNullOrEmpty(StoreIdStoreName))
  56. {
  57. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreIdStoreName + "')";
  58. }
  59. //代理分仓仓库编号
  60. if (!string.IsNullOrEmpty(AgentStoreIdStoreNo))
  61. {
  62. condition += " and AgentStoreId in (select AgentStoreId from StoreForCode where Code='" + AgentStoreIdStoreNo + "')";
  63. }
  64. //代理分仓仓库名称
  65. if (!string.IsNullOrEmpty(AgentStoreIdStoreName))
  66. {
  67. condition += " and AgentStoreId in (select AgentStoreId from StoreForName where Name='" + AgentStoreIdStoreName + "')";
  68. }
  69. //产品类型
  70. if (!string.IsNullOrEmpty(BrandIdSelect))
  71. {
  72. condition += " and BrandId=" + BrandIdSelect;
  73. }
  74. if (!string.IsNullOrEmpty(CreateDateData))
  75. {
  76. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  77. string start = datelist[0];
  78. string end = datelist[1];
  79. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  80. }
  81. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("StoreSnActivateSummary", Fields, "Id desc", "0", page, limit, condition);
  82. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  83. foreach (Dictionary<string, object> dic in diclist)
  84. {
  85. //仓库
  86. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  87. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  88. dic["StoreIdStoreNo"] = storeid_StoreHouse.StoreNo;
  89. dic["StoreIdStoreName"] = storeid_StoreHouse.StoreName;
  90. dic.Remove("StoreId");
  91. //代理分仓
  92. int AgentStoreId = int.Parse(function.CheckInt(dic["AgentStoreId"].ToString()));
  93. StoreHouse agentstoreid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == AgentStoreId) ?? new StoreHouse();
  94. dic["AgentStoreIdStoreNo"] = agentstoreid_StoreHouse.StoreNo;
  95. dic["AgentStoreIdStoreName"] = agentstoreid_StoreHouse.StoreName;
  96. dic.Remove("AgentStoreId");
  97. //产品类型
  98. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  99. }
  100. Dictionary<string, object> other = new Dictionary<string, object>();
  101. other.Add("ActCount", 0);
  102. other.Add("RejectActCount", 0);
  103. other.Add("PutActCount", 0);
  104. other.Add("EffectActCount", 0);
  105. other.Add("ApplyCount", 0);
  106. obj.Add("other", other);
  107. return Json(obj);
  108. }
  109. #endregion
  110. #region 增加仓库SN激活统计
  111. /// <summary>
  112. /// 增加或修改仓库SN激活统计信息
  113. /// </summary>
  114. /// <returns></returns>
  115. public IActionResult Add(string right)
  116. {
  117. ViewBag.RightInfo = RightInfo;
  118. ViewBag.right = right;
  119. return View();
  120. }
  121. #endregion
  122. #region 增加仓库SN激活统计
  123. /// <summary>
  124. /// 增加或修改仓库SN激活统计信息
  125. /// </summary>
  126. /// <returns></returns>
  127. [HttpPost]
  128. public string Add(StoreSnActivateSummary data)
  129. {
  130. Dictionary<string, object> Fields = new Dictionary<string, object>();
  131. Fields.Add("SeoTitle", data.SeoTitle);
  132. Fields.Add("SeoKeyword", data.SeoKeyword);
  133. Fields.Add("SeoDescription", data.SeoDescription);
  134. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("StoreSnActivateSummary", Fields, 0);
  135. AddSysLog(data.Id.ToString(), "StoreSnActivateSummary", "add");
  136. db.SaveChanges();
  137. return "success";
  138. }
  139. #endregion
  140. #region 修改仓库SN激活统计
  141. /// <summary>
  142. /// 增加或修改仓库SN激活统计信息
  143. /// </summary>
  144. /// <returns></returns>
  145. public IActionResult Edit(string right, int Id = 0)
  146. {
  147. ViewBag.RightInfo = RightInfo;
  148. ViewBag.right = right;
  149. StoreSnActivateSummary editData = db.StoreSnActivateSummary.FirstOrDefault(m => m.Id == Id) ?? new StoreSnActivateSummary();
  150. ViewBag.data = editData;
  151. return View();
  152. }
  153. #endregion
  154. #region 修改仓库SN激活统计
  155. /// <summary>
  156. /// 增加或修改仓库SN激活统计信息
  157. /// </summary>
  158. /// <returns></returns>
  159. [HttpPost]
  160. public string Edit(StoreSnActivateSummary data)
  161. {
  162. Dictionary<string, object> Fields = new Dictionary<string, object>();
  163. Fields.Add("SeoTitle", data.SeoTitle);
  164. Fields.Add("SeoKeyword", data.SeoKeyword);
  165. Fields.Add("SeoDescription", data.SeoDescription);
  166. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreSnActivateSummary", Fields, data.Id);
  167. AddSysLog(data.Id.ToString(), "StoreSnActivateSummary", "update");
  168. db.SaveChanges();
  169. return "success";
  170. }
  171. #endregion
  172. #region 删除仓库SN激活统计信息
  173. /// <summary>
  174. /// 删除仓库SN激活统计信息
  175. /// </summary>
  176. /// <returns></returns>
  177. public string Delete(string Id)
  178. {
  179. string[] idlist = Id.Split(new char[] { ',' });
  180. AddSysLog(Id, "StoreSnActivateSummary", "del");
  181. foreach (string subid in idlist)
  182. {
  183. int id = int.Parse(subid);
  184. Dictionary<string, object> Fields = new Dictionary<string, object>();
  185. Fields.Add("Status", -1);
  186. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreSnActivateSummary", Fields, id);
  187. }
  188. db.SaveChanges();
  189. return "success";
  190. }
  191. #endregion
  192. #region 开启
  193. /// <summary>
  194. /// 开启
  195. /// </summary>
  196. /// <returns></returns>
  197. public string Open(string Id)
  198. {
  199. string[] idlist = Id.Split(new char[] { ',' });
  200. AddSysLog(Id, "StoreSnActivateSummary", "open");
  201. foreach (string subid in idlist)
  202. {
  203. int id = int.Parse(subid);
  204. Dictionary<string, object> Fields = new Dictionary<string, object>();
  205. Fields.Add("Status", 1);
  206. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreSnActivateSummary", Fields, id);
  207. }
  208. db.SaveChanges();
  209. return "success";
  210. }
  211. #endregion
  212. #region 关闭
  213. /// <summary>
  214. /// 关闭
  215. /// </summary>
  216. /// <returns></returns>
  217. public string Close(string Id)
  218. {
  219. string[] idlist = Id.Split(new char[] { ',' });
  220. AddSysLog(Id, "StoreSnActivateSummary", "close");
  221. foreach (string subid in idlist)
  222. {
  223. int id = int.Parse(subid);
  224. Dictionary<string, object> Fields = new Dictionary<string, object>();
  225. Fields.Add("Status", 0);
  226. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreSnActivateSummary", Fields, id);
  227. }
  228. db.SaveChanges();
  229. return "success";
  230. }
  231. #endregion
  232. #region 排序
  233. /// <summary>
  234. /// 排序
  235. /// </summary>
  236. /// <param name="Id"></param>
  237. public string Sort(int Id, int Sort)
  238. {
  239. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("StoreSnActivateSummary", Sort, Id);
  240. AddSysLog(Id.ToString(), "StoreSnActivateSummary", "sort");
  241. return "success";
  242. }
  243. #endregion
  244. #region 导入数据
  245. /// <summary>
  246. /// 导入数据
  247. /// </summary>
  248. /// <param name="ExcelData"></param>
  249. public string Import(string ExcelData)
  250. {
  251. ExcelData = HttpUtility.UrlDecode(ExcelData);
  252. JsonData list = JsonMapper.ToObject(ExcelData);
  253. for (int i = 1; i < list.Count; i++)
  254. {
  255. JsonData dr = list[i];
  256. db.StoreSnActivateSummary.Add(new StoreSnActivateSummary()
  257. {
  258. CreateDate = DateTime.Now,
  259. UpdateDate = DateTime.Now,
  260. });
  261. db.SaveChanges();
  262. }
  263. AddSysLog("0", "StoreSnActivateSummary", "Import");
  264. return "success";
  265. }
  266. #endregion
  267. #region 导出Excel
  268. /// <summary>
  269. /// 导出Excel
  270. /// </summary>
  271. /// <returns></returns>
  272. public JsonResult ExportExcel(StoreSnActivateSummary data, string StoreIdStoreNo, string StoreIdStoreName, string AgentStoreIdStoreNo, string AgentStoreIdStoreName, string BrandIdSelect)
  273. {
  274. Dictionary<string, string> Fields = new Dictionary<string, string>();
  275. Fields.Add("CreateDate", "3"); //时间
  276. string condition = " and Status>-1";
  277. //仓库仓库编号
  278. if (!string.IsNullOrEmpty(StoreIdStoreNo))
  279. {
  280. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreIdStoreNo + "')";
  281. }
  282. //仓库仓库名称
  283. if (!string.IsNullOrEmpty(StoreIdStoreName))
  284. {
  285. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreIdStoreName + "')";
  286. }
  287. //代理分仓仓库编号
  288. if (!string.IsNullOrEmpty(AgentStoreIdStoreNo))
  289. {
  290. condition += " and AgentStoreId in (select AgentStoreId from StoreForCode where Code='" + AgentStoreIdStoreNo + "')";
  291. }
  292. //代理分仓仓库名称
  293. if (!string.IsNullOrEmpty(AgentStoreIdStoreName))
  294. {
  295. condition += " and AgentStoreId in (select AgentStoreId from StoreForName where Name='" + AgentStoreIdStoreName + "')";
  296. }
  297. //产品类型
  298. if (!string.IsNullOrEmpty(BrandIdSelect))
  299. {
  300. condition += " and BrandId=" + BrandIdSelect;
  301. }
  302. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("StoreSnActivateSummary", Fields, "Id desc", "0", 1, 20000, condition, "TradeDate,TradeMonth,StoreId,AgentStoreId,BrandId,ActivateNum,RejectActNum,TransferActNum,EffectActNum,UserApplyNum,Remark", false);
  303. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  304. foreach (Dictionary<string, object> dic in diclist)
  305. {
  306. //仓库
  307. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  308. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  309. dic["StoreIdStoreNo"] = storeid_StoreHouse.StoreNo;
  310. dic["StoreIdStoreName"] = storeid_StoreHouse.StoreName;
  311. dic.Remove("StoreId");
  312. //代理分仓
  313. int AgentStoreId = int.Parse(function.CheckInt(dic["AgentStoreId"].ToString()));
  314. StoreHouse agentstoreid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == AgentStoreId) ?? new StoreHouse();
  315. dic["AgentStoreIdStoreNo"] = agentstoreid_StoreHouse.StoreNo;
  316. dic["AgentStoreIdStoreName"] = agentstoreid_StoreHouse.StoreName;
  317. dic.Remove("AgentStoreId");
  318. //产品类型
  319. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  320. }
  321. Dictionary<string, object> result = new Dictionary<string, object>();
  322. result.Add("Status", "1");
  323. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  324. result.Add("Obj", diclist);
  325. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  326. ReturnFields.Add("TradeDate", "交易日");
  327. ReturnFields.Add("TradeMonth", "交易月");
  328. ReturnFields.Add("StoreIdStoreNo", "仓库仓库编号");
  329. ReturnFields.Add("StoreIdStoreName", "仓库仓库名称");
  330. ReturnFields.Add("AgentStoreIdStoreNo", "代理分仓仓库编号");
  331. ReturnFields.Add("AgentStoreIdStoreName", "代理分仓仓库名称");
  332. ReturnFields.Add("BrandId", "产品类型");
  333. ReturnFields.Add("ActivateNum", "激活数量");
  334. ReturnFields.Add("RejectActNum", "互斥激活数量");
  335. ReturnFields.Add("TransferActNum", "划拨激活数量(循环机划拨激活数)");
  336. ReturnFields.Add("EffectActNum", "有效激活数量");
  337. ReturnFields.Add("UserApplyNum", "创客申请数量");
  338. ReturnFields.Add("Remark", "备注");
  339. result.Add("Fields", ReturnFields);
  340. AddSysLog("0", "StoreSnActivateSummary", "ExportExcel");
  341. return Json(result);
  342. }
  343. #endregion
  344. }
  345. }