StoreMachineApplyController.cs 13 KB

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