StoreMachineApplyController.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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 StoreMachineApplyController : BaseController
  23. {
  24. public StoreMachineApplyController(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(StoreMachineApply 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(StoreMachineApply data, string BrandIdSelect, string UserIdRealName, string UserIdMakerCode, int page = 1, int limit = 30)
  46. {
  47. Dictionary<string, string> Fields = new Dictionary<string, string>();
  48. Fields.Add("CreateDate", "3"); //时间
  49. Fields.Add("ApplyNo", "1"); //申请单号
  50. Fields.Add("SendMode", "1"); //发货方式
  51. string condition = " and Status>-1";
  52. //品牌
  53. if (!string.IsNullOrEmpty(BrandIdSelect))
  54. {
  55. condition += " and BrandId=" + BrandIdSelect;
  56. }
  57. //创客真实姓名
  58. if (!string.IsNullOrEmpty(UserIdRealName))
  59. {
  60. condition += " and UserId in (select UserId from UsersForRealName where RealName='" + UserIdRealName + "')";
  61. }
  62. //创客创客编号
  63. if (!string.IsNullOrEmpty(UserIdMakerCode))
  64. {
  65. condition += " and UserId in (select UserId from UsersForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  66. }
  67. Dictionary<string, object> obj = new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).IndexData("StoreMachineApply", Fields, "Id desc", "0", page, limit, condition);
  68. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  69. foreach (Dictionary<string, object> dic in diclist)
  70. {
  71. //品牌
  72. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  73. dic["StatusName"] = dic["Status"].ToString() == "1" ? "正常" : "关闭";
  74. //创客
  75. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  76. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  77. dic["UserIdRealName"] = userid_Users.RealName;
  78. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  79. dic.Remove("UserId");
  80. }
  81. return Json(obj);
  82. }
  83. #endregion
  84. #region 增加分仓机具申请记录
  85. /// <summary>
  86. /// 增加或修改分仓机具申请记录信息
  87. /// </summary>
  88. /// <returns></returns>
  89. public IActionResult Add(string right)
  90. {
  91. ViewBag.RightInfo = RightInfo;
  92. ViewBag.right = right;
  93. return View();
  94. }
  95. #endregion
  96. #region 增加分仓机具申请记录
  97. /// <summary>
  98. /// 增加或修改分仓机具申请记录信息
  99. /// </summary>
  100. /// <returns></returns>
  101. [HttpPost]
  102. public string Add(StoreMachineApply data)
  103. {
  104. Dictionary<string, object> Fields = new Dictionary<string, object>();
  105. Fields.Add("BrandId", data.BrandId); //品牌
  106. Fields.Add("ApplyNo", data.ApplyNo); //申请单号
  107. Fields.Add("ApplyNum", data.ApplyNum); //申请台数
  108. Fields.Add("SendNum", data.SendNum); //发货台数
  109. Fields.Add("UseAmount", data.UseAmount); //使用额度
  110. Fields.Add("SendMode", data.SendMode); //发货方式
  111. Fields.Add("ErpCode", data.ErpCode); //快递单号
  112. Fields.Add("SendSn", data.SendSn); //发货SN数据
  113. Fields.Add("UserId", data.UserId); //创客
  114. Fields.Add("SeoTitle", data.SeoTitle);
  115. Fields.Add("SeoKeyword", data.SeoKeyword);
  116. Fields.Add("SeoDescription", data.SeoDescription);
  117. int Id = new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Add("StoreMachineApply", Fields, 0);
  118. AddSysLog(data.Id.ToString(), "StoreMachineApply", "add");
  119. db.SaveChanges();
  120. return "success";
  121. }
  122. #endregion
  123. #region 修改分仓机具申请记录
  124. /// <summary>
  125. /// 增加或修改分仓机具申请记录信息
  126. /// </summary>
  127. /// <returns></returns>
  128. public IActionResult Edit(string right, int Id = 0)
  129. {
  130. ViewBag.RightInfo = RightInfo;
  131. ViewBag.right = right;
  132. StoreMachineApply editData = db.StoreMachineApply.FirstOrDefault(m => m.Id == Id) ?? new StoreMachineApply();
  133. ViewBag.data = editData;
  134. return View();
  135. }
  136. #endregion
  137. #region 修改分仓机具申请记录
  138. /// <summary>
  139. /// 增加或修改分仓机具申请记录信息
  140. /// </summary>
  141. /// <returns></returns>
  142. [HttpPost]
  143. public string Edit(StoreMachineApply data)
  144. {
  145. Dictionary<string, object> Fields = new Dictionary<string, object>();
  146. Fields.Add("BrandId", data.BrandId); //品牌
  147. Fields.Add("ApplyNo", data.ApplyNo); //申请单号
  148. Fields.Add("ApplyNum", data.ApplyNum); //申请台数
  149. Fields.Add("SendNum", data.SendNum); //发货台数
  150. Fields.Add("UseAmount", data.UseAmount); //使用额度
  151. Fields.Add("SendMode", data.SendMode); //发货方式
  152. Fields.Add("ErpCode", data.ErpCode); //快递单号
  153. Fields.Add("SendSn", data.SendSn); //发货SN数据
  154. Fields.Add("UserId", data.UserId); //创客
  155. Fields.Add("SeoTitle", data.SeoTitle);
  156. Fields.Add("SeoKeyword", data.SeoKeyword);
  157. Fields.Add("SeoDescription", data.SeoDescription);
  158. new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreMachineApply", Fields, data.Id);
  159. AddSysLog(data.Id.ToString(), "StoreMachineApply", "update");
  160. db.SaveChanges();
  161. return "success";
  162. }
  163. #endregion
  164. #region 删除分仓机具申请记录信息
  165. /// <summary>
  166. /// 删除分仓机具申请记录信息
  167. /// </summary>
  168. /// <returns></returns>
  169. public string Delete(string Id)
  170. {
  171. string[] idlist = Id.Split(new char[] { ',' });
  172. AddSysLog(Id, "StoreMachineApply", "del");
  173. foreach (string subid in idlist)
  174. {
  175. int id = int.Parse(subid);
  176. Dictionary<string, object> Fields = new Dictionary<string, object>();
  177. Fields.Add("Status", -1);
  178. new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreMachineApply", Fields, id);
  179. }
  180. db.SaveChanges();
  181. return "success";
  182. }
  183. #endregion
  184. #region 开启
  185. /// <summary>
  186. /// 开启
  187. /// </summary>
  188. /// <returns></returns>
  189. public string Open(string Id)
  190. {
  191. string[] idlist = Id.Split(new char[] { ',' });
  192. AddSysLog(Id, "StoreMachineApply", "open");
  193. foreach (string subid in idlist)
  194. {
  195. int id = int.Parse(subid);
  196. Dictionary<string, object> Fields = new Dictionary<string, object>();
  197. Fields.Add("Status", 1);
  198. new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreMachineApply", Fields, id);
  199. }
  200. db.SaveChanges();
  201. return "success";
  202. }
  203. #endregion
  204. #region 关闭
  205. /// <summary>
  206. /// 关闭
  207. /// </summary>
  208. /// <returns></returns>
  209. public string Close(string Id)
  210. {
  211. string[] idlist = Id.Split(new char[] { ',' });
  212. AddSysLog(Id, "StoreMachineApply", "close");
  213. foreach (string subid in idlist)
  214. {
  215. int id = int.Parse(subid);
  216. Dictionary<string, object> Fields = new Dictionary<string, object>();
  217. Fields.Add("Status", 0);
  218. new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Edit("StoreMachineApply", Fields, id);
  219. }
  220. db.SaveChanges();
  221. return "success";
  222. }
  223. #endregion
  224. #region 排序
  225. /// <summary>
  226. /// 排序
  227. /// </summary>
  228. /// <param name="Id"></param>
  229. public string Sort(int Id, int Sort)
  230. {
  231. new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Sort("StoreMachineApply", Sort, Id);
  232. AddSysLog(Id.ToString(), "StoreMachineApply", "sort");
  233. return "success";
  234. }
  235. #endregion
  236. #region 导入数据
  237. /// <summary>
  238. /// 导入数据
  239. /// </summary>
  240. /// <param name="ExcelData"></param>
  241. public string Import(string ExcelData)
  242. {
  243. ExcelData = HttpUtility.UrlDecode(ExcelData);
  244. JsonData list = JsonMapper.ToObject(ExcelData);
  245. for (int i = 1; i < list.Count; i++)
  246. {
  247. JsonData dr = list[i];
  248. db.StoreMachineApply.Add(new StoreMachineApply()
  249. {
  250. CreateDate = DateTime.Now,
  251. UpdateDate = DateTime.Now,
  252. });
  253. db.SaveChanges();
  254. }
  255. AddSysLog("0", "StoreMachineApply", "Import");
  256. return "success";
  257. }
  258. #endregion
  259. #region 导出Excel
  260. /// <summary>
  261. /// 导出Excel
  262. /// </summary>
  263. /// <returns></returns>
  264. public JsonResult ExportExcel(StoreMachineApply data, string BrandIdSelect, string UserIdRealName, string UserIdMakerCode)
  265. {
  266. Dictionary<string, string> Fields = new Dictionary<string, string>();
  267. Fields.Add("CreateDate", "3"); //时间
  268. Fields.Add("ApplyNo", "1"); //申请单号
  269. Fields.Add("SendMode", "1"); //发货方式
  270. string condition = " and Status>-1";
  271. //品牌
  272. if (!string.IsNullOrEmpty(BrandIdSelect))
  273. {
  274. condition += " and BrandId=" + BrandIdSelect;
  275. }
  276. //创客真实姓名
  277. if (!string.IsNullOrEmpty(UserIdRealName))
  278. {
  279. condition += " and UserId in (select UserId from UsersForRealName where RealName='" + UserIdRealName + "')";
  280. }
  281. //创客创客编号
  282. if (!string.IsNullOrEmpty(UserIdMakerCode))
  283. {
  284. condition += " and UserId in (select UserId from UsersForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  285. }
  286. Dictionary<string, object> obj = new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).IndexData("StoreMachineApply", Fields, "Id desc", "0", 1, 20000, condition, "BrandId,ApplyNo,ApplyNum,SendNum,UseAmount,SendMode,ErpCode,UserId", false);
  287. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  288. foreach (Dictionary<string, object> dic in diclist)
  289. {
  290. //品牌
  291. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  292. dic["StatusName"] = dic["Status"].ToString() == "1" ? "正常" : "关闭";
  293. //创客
  294. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  295. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  296. dic["UserIdRealName"] = userid_Users.RealName;
  297. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  298. dic.Remove("UserId");
  299. }
  300. Dictionary<string, object> result = new Dictionary<string, object>();
  301. result.Add("Status", "1");
  302. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  303. result.Add("Obj", diclist);
  304. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  305. ReturnFields.Add("BrandId", "品牌");
  306. ReturnFields.Add("ApplyNo", "申请单号");
  307. ReturnFields.Add("ApplyNum", "申请台数");
  308. ReturnFields.Add("SendNum", "发货台数");
  309. ReturnFields.Add("UseAmount", "使用额度");
  310. ReturnFields.Add("SendMode", "发货方式");
  311. ReturnFields.Add("ErpCode", "快递单号");
  312. ReturnFields.Add("UserIdRealName", "创客真实姓名");
  313. ReturnFields.Add("UserIdMakerCode", "创客创客编号");
  314. result.Add("Fields", ReturnFields);
  315. AddSysLog("0", "StoreMachineApply", "ExportExcel");
  316. return Json(result);
  317. }
  318. #endregion
  319. }
  320. }