StoreSnActivateSummaryController.cs 16 KB

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