StoreHouseAmountPromissController.cs 14 KB

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