ToChargeBackRecordSubController.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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 ToChargeBackRecordSubController : BaseController
  23. {
  24. public ToChargeBackRecordSubController(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(ToChargeBackRecordSub data, string right, string ParentId)
  34. {
  35. ViewBag.RightInfo = RightInfo;
  36. ViewBag.right = right;
  37. ViewBag.ParentId = ParentId;
  38. return View();
  39. }
  40. #endregion
  41. #region 根据条件查询待扣款明细列表
  42. /// <summary>
  43. /// 待扣款明细列表
  44. /// </summary>
  45. /// <returns></returns>
  46. public JsonResult IndexData(ToChargeBackRecordSub data, string OrderNo, string StatusSelect, string CreateDateData, int page = 1, int limit = 30)
  47. {
  48. Dictionary<string, string> Fields = new Dictionary<string, string>();
  49. Fields.Add("ParentId", "1");
  50. string condition = " and Status>-1";
  51. //分期单号
  52. if (!string.IsNullOrEmpty(OrderNo))
  53. {
  54. var toChargeByStage = db.ToChargeByStage.FirstOrDefault(m => m.SeoKeyword == OrderNo) ?? new ToChargeByStage();
  55. var toChargeBackRecordSub = db.ToChargeBackRecordSub.FirstOrDefault(m => m.ParentId == toChargeByStage.Id) ?? new ToChargeBackRecordSub();
  56. condition += " and ParentId=" + toChargeByStage.Id;
  57. }
  58. //状态
  59. if (!string.IsNullOrEmpty(StatusSelect))
  60. {
  61. condition += " and Status=" + StatusSelect;
  62. }
  63. //创建时间
  64. if (!string.IsNullOrEmpty(CreateDateData))
  65. {
  66. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  67. string start = datelist[0];
  68. string end = datelist[1];
  69. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  70. }
  71. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("ToChargeBackRecordSub", Fields, "Id desc", "0", page, limit, condition);
  72. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  73. foreach (Dictionary<string, object> dic in diclist)
  74. {
  75. //状态
  76. int Status = int.Parse(function.CheckInt(dic["Status"].ToString()));
  77. dic["StatusName"] = "";
  78. if (Status == 0)
  79. {
  80. dic["StatusName"] = "待扣款";
  81. }
  82. if (Status == 1)
  83. {
  84. dic["StatusName"] = "已扣款";
  85. }
  86. if (Status == 2)
  87. {
  88. dic["StatusName"] = "扣款中";
  89. }
  90. //分期单号
  91. int ParentId = int.Parse(function.CheckInt(dic["ParentId"].ToString()));
  92. var toChargeByStage = db.ToChargeByStage.FirstOrDefault(m => m.Id == ParentId) ?? new ToChargeByStage();
  93. dic["OrderNo"] = toChargeByStage.SeoKeyword;
  94. }
  95. return Json(obj);
  96. }
  97. #endregion
  98. #region 增加待扣款明细
  99. /// <summary>
  100. /// 增加或修改待扣款明细信息
  101. /// </summary>
  102. /// <returns></returns>
  103. public IActionResult Add(string right, string ParentId)
  104. {
  105. ViewBag.RightInfo = RightInfo;
  106. ViewBag.right = right;
  107. ViewBag.ParentId = ParentId;
  108. return View();
  109. }
  110. #endregion
  111. #region 增加待扣款明细
  112. /// <summary>
  113. /// 增加或修改待扣款明细信息
  114. /// </summary>
  115. /// <returns></returns>
  116. [HttpPost]
  117. public string Add(ToChargeBackRecordSub data)
  118. {
  119. Dictionary<string, object> Fields = new Dictionary<string, object>();
  120. Fields.Add("ParentId", data.ParentId);
  121. Fields.Add("ChargeAmount", data.ChargeAmount); //待扣金额
  122. Fields.Add("Remark", data.Remark); //备注
  123. Fields.Add("StartDate", data.StartDate); //扣款开始时间
  124. Fields.Add("TimeNumber", data.TimeNumber); //期数
  125. Fields.Add("SeoTitle", data.SeoTitle);
  126. Fields.Add("SeoKeyword", data.SeoKeyword);
  127. Fields.Add("SeoDescription", data.SeoDescription);
  128. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("ToChargeBackRecordSub", Fields, 0);
  129. AddSysLog(data.Id.ToString(), "ToChargeBackRecordSub", "add");
  130. db.SaveChanges();
  131. return "success";
  132. }
  133. #endregion
  134. #region 修改待扣款明细
  135. /// <summary>
  136. /// 增加或修改待扣款明细信息
  137. /// </summary>
  138. /// <returns></returns>
  139. public IActionResult Edit(string right, string ParentId, int Id = 0)
  140. {
  141. ViewBag.RightInfo = RightInfo;
  142. ViewBag.right = right;
  143. ViewBag.ParentId = ParentId;
  144. ToChargeBackRecordSub editData = db.ToChargeBackRecordSub.FirstOrDefault(m => m.Id == Id) ?? new ToChargeBackRecordSub();
  145. ViewBag.data = editData;
  146. return View();
  147. }
  148. #endregion
  149. #region 修改待扣款明细
  150. /// <summary>
  151. /// 增加或修改待扣款明细信息
  152. /// </summary>
  153. /// <returns></returns>
  154. [HttpPost]
  155. public string Edit(ToChargeBackRecordSub data)
  156. {
  157. Dictionary<string, object> Fields = new Dictionary<string, object>();
  158. var toChargeBackRecordSub = db.ToChargeBackRecordSub.FirstOrDefault(m => m.Id == data.Id) ?? new ToChargeBackRecordSub();
  159. var toChargeByStage = db.ToChargeByStage.FirstOrDefault(m => m.Id == toChargeBackRecordSub.ParentId) ?? new ToChargeByStage();
  160. if (toChargeByStage.QueryCount > 0)
  161. {
  162. return "该扣款记录正处于扣款中或已经结束,不能修改!";
  163. }
  164. if (toChargeBackRecordSub.ChargeAmount != data.ChargeAmount)
  165. {
  166. var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == toChargeByStage.UserId) ?? new UserAccount();
  167. if (toChargeBackRecordSub.ChargeAmount > data.ChargeAmount)
  168. {
  169. toChargeByStage.TotalAmount -= toChargeBackRecordSub.ChargeAmount - data.ChargeAmount;
  170. userAccount.ToChargeAmount -= toChargeBackRecordSub.ChargeAmount - data.ChargeAmount;
  171. }
  172. if (toChargeBackRecordSub.ChargeAmount < data.ChargeAmount)
  173. {
  174. toChargeByStage.TotalAmount += data.ChargeAmount - toChargeBackRecordSub.ChargeAmount;
  175. userAccount.ToChargeAmount += data.ChargeAmount - toChargeBackRecordSub.ChargeAmount;
  176. }
  177. }
  178. Fields.Add("ChargeAmount", data.ChargeAmount); //待扣金额
  179. Fields.Add("Remark", data.Remark); //备注
  180. Fields.Add("StartDate", data.StartDate); //扣款开始时间
  181. Fields.Add("TimeNumber", data.TimeNumber); //期数
  182. Fields.Add("SeoTitle", data.SeoTitle);
  183. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("ToChargeBackRecordSub", Fields, data.Id);
  184. AddSysLog(data.Id.ToString(), "ToChargeBackRecordSub", "update");
  185. db.SaveChanges();
  186. return "success";
  187. }
  188. #endregion
  189. #region 删除待扣款明细信息
  190. /// <summary>
  191. /// 删除待扣款明细信息
  192. /// </summary>
  193. /// <returns></returns>
  194. public string Delete(string Id)
  195. {
  196. string[] idlist = Id.Split(new char[] { ',' });
  197. AddSysLog(Id, "ToChargeBackRecordSub", "del");
  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("ToChargeBackRecordSub", 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 Open(string Id)
  215. {
  216. string[] idlist = Id.Split(new char[] { ',' });
  217. AddSysLog(Id, "ToChargeBackRecordSub", "open");
  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", 1);
  223. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("ToChargeBackRecordSub", Fields, id);
  224. }
  225. db.SaveChanges();
  226. return "success";
  227. }
  228. #endregion
  229. #region 关闭
  230. /// <summary>
  231. /// 关闭
  232. /// </summary>
  233. /// <returns></returns>
  234. public string Close(string Id)
  235. {
  236. string[] idlist = Id.Split(new char[] { ',' });
  237. AddSysLog(Id, "ToChargeBackRecordSub", "close");
  238. foreach (string subid in idlist)
  239. {
  240. int id = int.Parse(subid);
  241. Dictionary<string, object> Fields = new Dictionary<string, object>();
  242. Fields.Add("Status", 0);
  243. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("ToChargeBackRecordSub", Fields, id);
  244. }
  245. db.SaveChanges();
  246. return "success";
  247. }
  248. #endregion
  249. #region 排序
  250. /// <summary>
  251. /// 排序
  252. /// </summary>
  253. /// <param name="Id"></param>
  254. public string Sort(int Id, int Sort)
  255. {
  256. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("ToChargeBackRecordSub", Sort, Id);
  257. AddSysLog(Id.ToString(), "ToChargeBackRecordSub", "sort");
  258. return "success";
  259. }
  260. #endregion
  261. #region 导入数据
  262. /// <summary>
  263. /// 导入数据
  264. /// </summary>
  265. /// <param name="ExcelData"></param>
  266. public string Import(string ExcelData)
  267. {
  268. ExcelData = HttpUtility.UrlDecode(ExcelData);
  269. JsonData list = JsonMapper.ToObject(ExcelData);
  270. for (int i = 1; i < list.Count; i++)
  271. {
  272. JsonData dr = list[i];
  273. db.ToChargeBackRecordSub.Add(new ToChargeBackRecordSub()
  274. {
  275. CreateDate = DateTime.Now,
  276. UpdateDate = DateTime.Now,
  277. });
  278. db.SaveChanges();
  279. }
  280. AddSysLog("0", "ToChargeBackRecordSub", "Import");
  281. return "success";
  282. }
  283. #endregion
  284. #region 导出Excel
  285. /// <summary>
  286. /// 导出Excel
  287. /// </summary>
  288. /// <returns></returns>
  289. public JsonResult ExportExcel(ToChargeBackRecordSub data)
  290. {
  291. Dictionary<string, string> Fields = new Dictionary<string, string>();
  292. Fields.Add("CreateDate", "3"); //时间
  293. string condition = " and Status>-1";
  294. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("ToChargeBackRecordSub", Fields, "Id desc", "0", 1, 20000, condition, "ChargeAmount,Remark", false);
  295. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  296. foreach (Dictionary<string, object> dic in diclist)
  297. {
  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("ChargeAmount", "待扣金额");
  305. ReturnFields.Add("Remark", "备注");
  306. result.Add("Fields", ReturnFields);
  307. AddSysLog("0", "ToChargeBackRecordSub", "ExportExcel");
  308. return Json(result);
  309. }
  310. #endregion
  311. }
  312. }