StoreSnActivateSummaryController.cs 17 KB

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