ToChargeBackRecordSubController.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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 KindSelect, 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(KindSelect))
  60. {
  61. condition += " and Kind=" + KindSelect;
  62. }
  63. //状态
  64. if (!string.IsNullOrEmpty(StatusSelect))
  65. {
  66. condition += " and Status=" + StatusSelect;
  67. }
  68. //创建时间
  69. if (!string.IsNullOrEmpty(CreateDateData))
  70. {
  71. string[] datelist = CreateDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  72. string start = datelist[0];
  73. string end = datelist[1];
  74. condition += " and CreateDate>='" + start + " 00:00:00' and CreateDate<='" + end + " 23:59:59'";
  75. }
  76. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("ToChargeBackRecordSub", Fields, "Id desc", "0", page, limit, condition);
  77. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  78. foreach (Dictionary<string, object> dic in diclist)
  79. {
  80. //状态
  81. int Status = int.Parse(function.CheckInt(dic["Status"].ToString()));
  82. dic["StatusName"] = "";
  83. if (Status == 0)
  84. {
  85. dic["StatusName"] = "待扣款";
  86. }
  87. if (Status == 1)
  88. {
  89. dic["StatusName"] = "已扣款";
  90. }
  91. if (Status == 2)
  92. {
  93. dic["StatusName"] = "扣款中";
  94. }
  95. //待扣类别
  96. int Kind = int.Parse(dic["Kind"].ToString());
  97. if (Kind == 0) dic["KindName"] = "创客预扣款";
  98. if (Kind == 1) dic["KindName"] = "盟主预扣款";
  99. if (Kind == 2) dic["KindName"] = "运营中心预扣款";
  100. //分期单号
  101. int ParentId = int.Parse(function.CheckInt(dic["ParentId"].ToString()));
  102. var toChargeByStage = db.ToChargeByStage.FirstOrDefault(m => m.Id == ParentId) ?? new ToChargeByStage();
  103. dic["OrderNo"] = toChargeByStage.SeoKeyword;
  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 ParentId)
  114. {
  115. ViewBag.RightInfo = RightInfo;
  116. ViewBag.right = right;
  117. ViewBag.ParentId = ParentId;
  118. return View();
  119. }
  120. #endregion
  121. #region 增加待扣款明细
  122. /// <summary>
  123. /// 增加或修改待扣款明细信息
  124. /// </summary>
  125. /// <returns></returns>
  126. [HttpPost]
  127. public string Add(ToChargeBackRecordSub data)
  128. {
  129. Dictionary<string, object> Fields = new Dictionary<string, object>();
  130. Fields.Add("ParentId", data.ParentId);
  131. Fields.Add("ChargeAmount", data.ChargeAmount); //待扣金额
  132. Fields.Add("Remark", data.Remark); //备注
  133. Fields.Add("StartDate", data.StartDate); //扣款开始时间
  134. Fields.Add("TimeNumber", data.TimeNumber); //期数
  135. Fields.Add("SeoTitle", data.SeoTitle);
  136. Fields.Add("SeoKeyword", data.SeoKeyword);
  137. Fields.Add("SeoDescription", data.SeoDescription);
  138. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("ToChargeBackRecordSub", Fields, 0);
  139. AddSysLog(data.Id.ToString(), "ToChargeBackRecordSub", "add");
  140. db.SaveChanges();
  141. return "success";
  142. }
  143. #endregion
  144. #region 修改待扣款明细
  145. /// <summary>
  146. /// 增加或修改待扣款明细信息
  147. /// </summary>
  148. /// <returns></returns>
  149. public IActionResult Edit(string right, string ParentId, int Id = 0)
  150. {
  151. ViewBag.RightInfo = RightInfo;
  152. ViewBag.right = right;
  153. ViewBag.ParentId = ParentId;
  154. ToChargeBackRecordSub editData = db.ToChargeBackRecordSub.FirstOrDefault(m => m.Id == Id) ?? new ToChargeBackRecordSub();
  155. ViewBag.data = editData;
  156. return View();
  157. }
  158. #endregion
  159. #region 修改待扣款明细
  160. /// <summary>
  161. /// 增加或修改待扣款明细信息
  162. /// </summary>
  163. /// <returns></returns>
  164. [HttpPost]
  165. public string Edit(ToChargeBackRecordSub data)
  166. {
  167. Dictionary<string, object> Fields = new Dictionary<string, object>();
  168. var toChargeBackRecordSub = db.ToChargeBackRecordSub.FirstOrDefault(m => m.Id == data.Id) ?? new ToChargeBackRecordSub();
  169. var toChargeByStage = db.ToChargeByStage.FirstOrDefault(m => m.Id == toChargeBackRecordSub.ParentId) ?? new ToChargeByStage();
  170. if (toChargeByStage.QueryCount > 0)
  171. {
  172. return "该扣款记录正处于扣款中或已经结束,不能修改!";
  173. }
  174. if (toChargeBackRecordSub.ChargeAmount != data.ChargeAmount)
  175. {
  176. var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == toChargeByStage.UserId) ?? new UserAccount();
  177. if (toChargeBackRecordSub.ChargeAmount > data.ChargeAmount)
  178. {
  179. toChargeByStage.TotalAmount -= toChargeBackRecordSub.ChargeAmount - data.ChargeAmount;
  180. if (toChargeBackRecordSub.Kind == 0) userAccount.ToChargeAmount -= toChargeBackRecordSub.ChargeAmount - data.ChargeAmount;
  181. if (toChargeBackRecordSub.Kind == 1) userAccount.LeaderToChargeAmount -= toChargeBackRecordSub.ChargeAmount - data.ChargeAmount;
  182. if (toChargeBackRecordSub.Kind == 2) userAccount.OperateToChargeAmount -= toChargeBackRecordSub.ChargeAmount - data.ChargeAmount;
  183. }
  184. if (toChargeBackRecordSub.ChargeAmount < data.ChargeAmount)
  185. {
  186. toChargeByStage.TotalAmount += data.ChargeAmount - toChargeBackRecordSub.ChargeAmount;
  187. if (toChargeBackRecordSub.Kind == 0) userAccount.ToChargeAmount += data.ChargeAmount - toChargeBackRecordSub.ChargeAmount;
  188. if (toChargeBackRecordSub.Kind == 1) userAccount.LeaderToChargeAmount += data.ChargeAmount - toChargeBackRecordSub.ChargeAmount;
  189. if (toChargeBackRecordSub.Kind == 2) userAccount.OperateToChargeAmount += data.ChargeAmount - toChargeBackRecordSub.ChargeAmount;
  190. }
  191. }
  192. Fields.Add("ChargeAmount", data.ChargeAmount); //待扣金额
  193. Fields.Add("Remark", data.Remark); //备注
  194. Fields.Add("StartDate", data.StartDate); //扣款开始时间
  195. Fields.Add("TimeNumber", data.TimeNumber); //期数
  196. Fields.Add("SeoTitle", data.SeoTitle);
  197. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("ToChargeBackRecordSub", Fields, data.Id);
  198. AddSysLog(data.Id.ToString(), "ToChargeBackRecordSub", "update");
  199. db.SaveChanges();
  200. return "success";
  201. }
  202. #endregion
  203. #region 删除待扣款明细信息
  204. /// <summary>
  205. /// 删除待扣款明细信息
  206. /// </summary>
  207. /// <returns></returns>
  208. public string Delete(string Id)
  209. {
  210. string[] idlist = Id.Split(new char[] { ',' });
  211. AddSysLog(Id, "ToChargeBackRecordSub", "del");
  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", -1);
  217. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("ToChargeBackRecordSub", Fields, id);
  218. }
  219. db.SaveChanges();
  220. return "success";
  221. }
  222. #endregion
  223. #region 开启
  224. /// <summary>
  225. /// 开启
  226. /// </summary>
  227. /// <returns></returns>
  228. public string Open(string Id)
  229. {
  230. string[] idlist = Id.Split(new char[] { ',' });
  231. AddSysLog(Id, "ToChargeBackRecordSub", "open");
  232. foreach (string subid in idlist)
  233. {
  234. int id = int.Parse(subid);
  235. Dictionary<string, object> Fields = new Dictionary<string, object>();
  236. Fields.Add("Status", 1);
  237. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("ToChargeBackRecordSub", Fields, id);
  238. }
  239. db.SaveChanges();
  240. return "success";
  241. }
  242. #endregion
  243. #region 关闭
  244. /// <summary>
  245. /// 关闭
  246. /// </summary>
  247. /// <returns></returns>
  248. public string Close(string Id)
  249. {
  250. string[] idlist = Id.Split(new char[] { ',' });
  251. AddSysLog(Id, "ToChargeBackRecordSub", "close");
  252. foreach (string subid in idlist)
  253. {
  254. int id = int.Parse(subid);
  255. Dictionary<string, object> Fields = new Dictionary<string, object>();
  256. Fields.Add("Status", 0);
  257. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("ToChargeBackRecordSub", Fields, id);
  258. }
  259. db.SaveChanges();
  260. return "success";
  261. }
  262. #endregion
  263. #region 排序
  264. /// <summary>
  265. /// 排序
  266. /// </summary>
  267. /// <param name="Id"></param>
  268. public string Sort(int Id, int Sort)
  269. {
  270. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("ToChargeBackRecordSub", Sort, Id);
  271. AddSysLog(Id.ToString(), "ToChargeBackRecordSub", "sort");
  272. return "success";
  273. }
  274. #endregion
  275. #region 导入数据
  276. /// <summary>
  277. /// 导入数据
  278. /// </summary>
  279. /// <param name="ExcelData"></param>
  280. public string Import(string ExcelData)
  281. {
  282. ExcelData = HttpUtility.UrlDecode(ExcelData);
  283. JsonData list = JsonMapper.ToObject(ExcelData);
  284. for (int i = 1; i < list.Count; i++)
  285. {
  286. JsonData dr = list[i];
  287. db.ToChargeBackRecordSub.Add(new ToChargeBackRecordSub()
  288. {
  289. CreateDate = DateTime.Now,
  290. UpdateDate = DateTime.Now,
  291. });
  292. db.SaveChanges();
  293. }
  294. AddSysLog("0", "ToChargeBackRecordSub", "Import");
  295. return "success";
  296. }
  297. #endregion
  298. #region 导出Excel
  299. /// <summary>
  300. /// 导出Excel
  301. /// </summary>
  302. /// <returns></returns>
  303. public JsonResult ExportExcel(ToChargeBackRecordSub data)
  304. {
  305. Dictionary<string, string> Fields = new Dictionary<string, string>();
  306. Fields.Add("CreateDate", "3"); //时间
  307. string condition = " and Status>-1";
  308. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("ToChargeBackRecordSub", Fields, "Id desc", "0", 1, 20000, condition, "ChargeAmount,Remark", false);
  309. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  310. foreach (Dictionary<string, object> dic in diclist)
  311. {
  312. }
  313. Dictionary<string, object> result = new Dictionary<string, object>();
  314. result.Add("Status", "1");
  315. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  316. result.Add("Obj", diclist);
  317. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  318. ReturnFields.Add("ChargeAmount", "待扣金额");
  319. ReturnFields.Add("Remark", "备注");
  320. result.Add("Fields", ReturnFields);
  321. AddSysLog("0", "ToChargeBackRecordSub", "ExportExcel");
  322. return Json(result);
  323. }
  324. #endregion
  325. }
  326. }