PosCouponRecordController.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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 PosCouponRecordController : BaseController
  23. {
  24. public PosCouponRecordController(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(PosCouponRecord data, string right, string OrderNo)
  34. {
  35. ViewBag.RightInfo = RightInfo;
  36. ViewBag.right = right;
  37. ViewBag.OrderNo = OrderNo;
  38. return View();
  39. }
  40. #endregion
  41. #region 根据条件查询机具券明细记录列表
  42. /// <summary>
  43. /// 机具券明细记录列表
  44. /// </summary>
  45. /// <returns></returns>
  46. public JsonResult IndexData(PosCouponRecord data, string PosCouponIdSelect, string FromUserIdMakerCode, string FromUserIdRealName, string ToUserIdMakerCode, string ToUserIdRealName, string ChangeKindSelect, int page = 1, int limit = 30)
  47. {
  48. Dictionary<string, string> Fields = new Dictionary<string, string>();
  49. Fields.Add("OrderNo", "1");
  50. string condition = " and Status>-1";
  51. //机具券Id
  52. if (!string.IsNullOrEmpty(PosCouponIdSelect))
  53. {
  54. condition += " and PosCouponId=" + PosCouponIdSelect;
  55. }
  56. //来源创客编号
  57. if (!string.IsNullOrEmpty(FromUserIdMakerCode))
  58. {
  59. condition += " and FromUserId in (select FromUserId from UserForMakerCode where MakerCode='" + FromUserIdMakerCode + "')";
  60. }
  61. //来源创客真实姓名
  62. if (!string.IsNullOrEmpty(FromUserIdRealName))
  63. {
  64. condition += " and FromUserId in (select FromUserId from UserForRealName where RealName='" + FromUserIdRealName + "')";
  65. }
  66. //目标创客编号
  67. if (!string.IsNullOrEmpty(ToUserIdMakerCode))
  68. {
  69. condition += " and ToUserId in (select ToUserId from UserForMakerCode where MakerCode='" + ToUserIdMakerCode + "')";
  70. }
  71. //目标创客真实姓名
  72. if (!string.IsNullOrEmpty(ToUserIdRealName))
  73. {
  74. condition += " and ToUserId in (select ToUserId from UserForRealName where RealName='" + ToUserIdRealName + "')";
  75. }
  76. //变更类型
  77. if (!string.IsNullOrEmpty(ChangeKindSelect))
  78. {
  79. condition += " and ChangeKind=" + ChangeKindSelect;
  80. }
  81. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosCouponRecord", 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. //机具券Id
  86. dic["PosCouponId"] = RelationClass.GetPosCouponsInfo(int.Parse(dic["PosCouponId"].ToString()));
  87. //来源创客
  88. int FromUserId = int.Parse(function.CheckInt(dic["FromUserId"].ToString()));
  89. Users fromuserid_Users = db.Users.FirstOrDefault(m => m.Id == FromUserId) ?? new Users();
  90. dic["FromUserIdMakerCode"] = fromuserid_Users.MakerCode;
  91. dic["FromUserIdRealName"] = fromuserid_Users.RealName;
  92. dic.Remove("FromUserId");
  93. //目标创客
  94. int ToUserId = int.Parse(function.CheckInt(dic["ToUserId"].ToString()));
  95. Users touserid_Users = db.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Users();
  96. dic["ToUserIdMakerCode"] = touserid_Users.MakerCode;
  97. dic["ToUserIdRealName"] = touserid_Users.RealName;
  98. dic.Remove("ToUserId");
  99. int ChangeKind = int.Parse(function.CheckInt(dic["ChangeKind"].ToString()));
  100. if(ChangeKind == 0) dic["ToUserIdRealName"] = "购买";
  101. if(ChangeKind == 1) dic["ToUserIdRealName"] = "划拨";
  102. if(ChangeKind == 2) dic["ToUserIdRealName"] = "使⽤";
  103. if(ChangeKind == 3) dic["ToUserIdRealName"] = "申请机具循环驳回";
  104. }
  105. return Json(obj);
  106. }
  107. #endregion
  108. #region 增加机具券明细记录
  109. /// <summary>
  110. /// 增加或修改机具券明细记录信息
  111. /// </summary>
  112. /// <returns></returns>
  113. public IActionResult Add(string right, string OrderNo)
  114. {
  115. ViewBag.RightInfo = RightInfo;
  116. ViewBag.right = right;
  117. ViewBag.OrderNo = OrderNo;
  118. return View();
  119. }
  120. #endregion
  121. #region 增加机具券明细记录
  122. /// <summary>
  123. /// 增加或修改机具券明细记录信息
  124. /// </summary>
  125. /// <returns></returns>
  126. [HttpPost]
  127. public string Add(PosCouponRecord data)
  128. {
  129. Dictionary<string, object> Fields = new Dictionary<string, object>();
  130. Fields.Add("OrderNo", data.OrderNo);
  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("PosCouponRecord", Fields, 0);
  135. AddSysLog(data.Id.ToString(), "PosCouponRecord", "add");
  136. db.SaveChanges();
  137. return "success";
  138. }
  139. #endregion
  140. #region 修改机具券明细记录
  141. /// <summary>
  142. /// 增加或修改机具券明细记录信息
  143. /// </summary>
  144. /// <returns></returns>
  145. public IActionResult Edit(string right, string OrderNo, int Id = 0)
  146. {
  147. ViewBag.RightInfo = RightInfo;
  148. ViewBag.right = right;
  149. ViewBag.OrderNo = OrderNo;
  150. PosCouponRecord editData = db.PosCouponRecord.FirstOrDefault(m => m.Id == Id) ?? new PosCouponRecord();
  151. ViewBag.data = editData;
  152. return View();
  153. }
  154. #endregion
  155. #region 修改机具券明细记录
  156. /// <summary>
  157. /// 增加或修改机具券明细记录信息
  158. /// </summary>
  159. /// <returns></returns>
  160. [HttpPost]
  161. public string Edit(PosCouponRecord data)
  162. {
  163. Dictionary<string, object> Fields = new Dictionary<string, object>();
  164. Fields.Add("OrderNo", data.OrderNo);
  165. Fields.Add("SeoTitle", data.SeoTitle);
  166. Fields.Add("SeoKeyword", data.SeoKeyword);
  167. Fields.Add("SeoDescription", data.SeoDescription);
  168. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosCouponRecord", Fields, data.Id);
  169. AddSysLog(data.Id.ToString(), "PosCouponRecord", "update");
  170. db.SaveChanges();
  171. return "success";
  172. }
  173. #endregion
  174. #region 删除机具券明细记录信息
  175. /// <summary>
  176. /// 删除机具券明细记录信息
  177. /// </summary>
  178. /// <returns></returns>
  179. public string Delete(string Id)
  180. {
  181. string[] idlist = Id.Split(new char[] { ',' });
  182. AddSysLog(Id, "PosCouponRecord", "del");
  183. foreach (string subid in idlist)
  184. {
  185. int id = int.Parse(subid);
  186. Dictionary<string, object> Fields = new Dictionary<string, object>();
  187. Fields.Add("Status", -1);
  188. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosCouponRecord", Fields, id);
  189. }
  190. db.SaveChanges();
  191. return "success";
  192. }
  193. #endregion
  194. #region 开启
  195. /// <summary>
  196. /// 开启
  197. /// </summary>
  198. /// <returns></returns>
  199. public string Open(string Id)
  200. {
  201. string[] idlist = Id.Split(new char[] { ',' });
  202. AddSysLog(Id, "PosCouponRecord", "open");
  203. foreach (string subid in idlist)
  204. {
  205. int id = int.Parse(subid);
  206. Dictionary<string, object> Fields = new Dictionary<string, object>();
  207. Fields.Add("Status", 1);
  208. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosCouponRecord", Fields, id);
  209. }
  210. db.SaveChanges();
  211. return "success";
  212. }
  213. #endregion
  214. #region 关闭
  215. /// <summary>
  216. /// 关闭
  217. /// </summary>
  218. /// <returns></returns>
  219. public string Close(string Id)
  220. {
  221. string[] idlist = Id.Split(new char[] { ',' });
  222. AddSysLog(Id, "PosCouponRecord", "close");
  223. foreach (string subid in idlist)
  224. {
  225. int id = int.Parse(subid);
  226. Dictionary<string, object> Fields = new Dictionary<string, object>();
  227. Fields.Add("Status", 0);
  228. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosCouponRecord", Fields, id);
  229. }
  230. db.SaveChanges();
  231. return "success";
  232. }
  233. #endregion
  234. #region 排序
  235. /// <summary>
  236. /// 排序
  237. /// </summary>
  238. /// <param name="Id"></param>
  239. public string Sort(int Id, int Sort)
  240. {
  241. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("PosCouponRecord", Sort, Id);
  242. AddSysLog(Id.ToString(), "PosCouponRecord", "sort");
  243. return "success";
  244. }
  245. #endregion
  246. #region 导入数据
  247. /// <summary>
  248. /// 导入数据
  249. /// </summary>
  250. /// <param name="ExcelData"></param>
  251. public string Import(string ExcelData)
  252. {
  253. ExcelData = HttpUtility.UrlDecode(ExcelData);
  254. JsonData list = JsonMapper.ToObject(ExcelData);
  255. for (int i = 1; i < list.Count; i++)
  256. {
  257. JsonData dr = list[i];
  258. db.PosCouponRecord.Add(new PosCouponRecord()
  259. {
  260. CreateDate = DateTime.Now,
  261. UpdateDate = DateTime.Now,
  262. });
  263. db.SaveChanges();
  264. }
  265. AddSysLog("0", "PosCouponRecord", "Import");
  266. return "success";
  267. }
  268. #endregion
  269. #region 导出Excel
  270. /// <summary>
  271. /// 导出Excel
  272. /// </summary>
  273. /// <returns></returns>
  274. public JsonResult ExportExcel(PosCouponRecord data, string PosCouponIdSelect, string FromUserIdMakerCode, string FromUserIdRealName, string ToUserIdMakerCode, string ToUserIdRealName, string ChangeKindSelect)
  275. {
  276. Dictionary<string, string> Fields = new Dictionary<string, string>();
  277. Fields.Add("CreateDate", "3"); //时间
  278. Fields.Add("OrderNo", "1"); //单号
  279. string condition = " and Status>-1";
  280. //机具券Id
  281. if (!string.IsNullOrEmpty(PosCouponIdSelect))
  282. {
  283. condition += " and PosCouponId=" + PosCouponIdSelect;
  284. }
  285. //来源创客编号
  286. if (!string.IsNullOrEmpty(FromUserIdMakerCode))
  287. {
  288. condition += " and FromUserId in (select FromUserId from UserForMakerCode where MakerCode='" + FromUserIdMakerCode + "')";
  289. }
  290. //来源创客真实姓名
  291. if (!string.IsNullOrEmpty(FromUserIdRealName))
  292. {
  293. condition += " and FromUserId in (select FromUserId from UserForRealName where RealName='" + FromUserIdRealName + "')";
  294. }
  295. //目标创客编号
  296. if (!string.IsNullOrEmpty(ToUserIdMakerCode))
  297. {
  298. condition += " and ToUserId in (select ToUserId from UserForMakerCode where MakerCode='" + ToUserIdMakerCode + "')";
  299. }
  300. //目标创客真实姓名
  301. if (!string.IsNullOrEmpty(ToUserIdRealName))
  302. {
  303. condition += " and ToUserId in (select ToUserId from UserForRealName where RealName='" + ToUserIdRealName + "')";
  304. }
  305. //变更类型
  306. if (!string.IsNullOrEmpty(ChangeKindSelect))
  307. {
  308. condition += " and ChangeKind=" + ChangeKindSelect;
  309. }
  310. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosCouponRecord", Fields, "Id desc", "0", 1, 20000, condition, "PosCouponId,FromUserId,ToUserId,OrderNo,ChangeKind", false);
  311. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  312. foreach (Dictionary<string, object> dic in diclist)
  313. {
  314. //机具券Id
  315. dic["PosCouponId"] = RelationClass.GetPosCouponsInfo(int.Parse(dic["PosCouponId"].ToString()));
  316. //来源创客
  317. int FromUserId = int.Parse(function.CheckInt(dic["FromUserId"].ToString()));
  318. Users fromuserid_Users = db.Users.FirstOrDefault(m => m.Id == FromUserId) ?? new Users();
  319. dic["FromUserIdMakerCode"] = fromuserid_Users.MakerCode;
  320. dic["FromUserIdRealName"] = fromuserid_Users.RealName;
  321. dic.Remove("FromUserId");
  322. //目标创客
  323. int ToUserId = int.Parse(function.CheckInt(dic["ToUserId"].ToString()));
  324. Users touserid_Users = db.Users.FirstOrDefault(m => m.Id == ToUserId) ?? new Users();
  325. dic["ToUserIdMakerCode"] = touserid_Users.MakerCode;
  326. dic["ToUserIdRealName"] = touserid_Users.RealName;
  327. dic.Remove("ToUserId");
  328. int ChangeKind = int.Parse(function.CheckInt(dic["ChangeKind"].ToString()));
  329. if(ChangeKind == 0) dic["ToUserIdRealName"] = "购买";
  330. if(ChangeKind == 1) dic["ToUserIdRealName"] = "划拨";
  331. if(ChangeKind == 2) dic["ToUserIdRealName"] = "使⽤";
  332. if(ChangeKind == 3) dic["ToUserIdRealName"] = "申请机具循环驳回";
  333. }
  334. Dictionary<string, object> result = new Dictionary<string, object>();
  335. result.Add("Status", "1");
  336. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  337. result.Add("Obj", diclist);
  338. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  339. ReturnFields.Add("PosCouponId", "机具券Id");
  340. ReturnFields.Add("FromUserIdMakerCode", "来源创客编号");
  341. ReturnFields.Add("FromUserIdRealName", "来源创客真实姓名");
  342. ReturnFields.Add("ToUserIdMakerCode", "目标创客编号");
  343. ReturnFields.Add("ToUserIdRealName", "目标创客真实姓名");
  344. ReturnFields.Add("OrderNo", "单号");
  345. ReturnFields.Add("ChangeKind", "变更类型");
  346. result.Add("Fields", ReturnFields);
  347. AddSysLog("0", "PosCouponRecord", "ExportExcel");
  348. return Json(result);
  349. }
  350. #endregion
  351. }
  352. }