PosCouponRecordController.cs 15 KB

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