PosCouponRecordController.cs 15 KB

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