ProfitReceiveRecordController.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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 ProfitReceiveRecordController : BaseController
  23. {
  24. public ProfitReceiveRecordController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  25. {
  26. }
  27. #region 分账记录列表
  28. /// <summary>
  29. /// 根据条件查询分账记录列表
  30. /// </summary>
  31. /// <returns></returns>
  32. public IActionResult Index(ProfitReceiveRecord data, string right)
  33. {
  34. ViewBag.RightInfo = RightInfo;
  35. ViewBag.right = right;
  36. return View();
  37. }
  38. #endregion
  39. #region 根据条件查询分账记录列表
  40. /// <summary>
  41. /// 分账记录列表
  42. /// </summary>
  43. /// <returns></returns>
  44. public JsonResult IndexData(ProfitReceiveRecord data, string TypeSelect, string RelationTypeSelect, string StateSelect, int page = 1, int limit = 30)
  45. {
  46. Dictionary<string, string> Fields = new Dictionary<string, string>();
  47. Fields.Add("CreateDate", "3"); //时间
  48. Fields.Add("SubMchid", "1"); //子商户号
  49. Fields.Add("AppId", "1"); //应用ID
  50. Fields.Add("SubAppId", "1"); //子商户应用ID
  51. Fields.Add("Account", "1"); //分账接收方账号
  52. Fields.Add("TransactionId", "1"); //微信订单号
  53. Fields.Add("OutOrderNo", "1"); //商户分账单号
  54. Fields.Add("OrderId", "1"); //微信分账单号
  55. string condition = " and Status>-1";
  56. //分账接收方类型
  57. if (!string.IsNullOrEmpty(TypeSelect))
  58. {
  59. condition += " and Type=" + TypeSelect;
  60. }
  61. //与分账方的关系类型
  62. if (!string.IsNullOrEmpty(RelationTypeSelect))
  63. {
  64. condition += " and RelationType=" + RelationTypeSelect;
  65. }
  66. //分账单状态
  67. if (!string.IsNullOrEmpty(StateSelect))
  68. {
  69. condition += " and State=" + StateSelect;
  70. }
  71. Dictionary<string, object> obj = new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).IndexData("ProfitReceiveRecord", 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. string Type = dic["Type"].ToString();
  77. if(Type == "MERCHANT_ID") dic["Type"] = "商户ID";
  78. if(Type == "PERSONAL_OPENID") dic["Type"] = "个人openid";
  79. if(Type == "PERSONAL_SUB_OPENID") dic["Type"] = "个人sub_openid";
  80. if(Type == "") dic["Type"] = "";
  81. //与分账方的关系类型
  82. string RelationType = dic["RelationType"].ToString();
  83. if(RelationType == "SERVICE_PROVIDER") dic["RelationType"] = "服务商";
  84. if(RelationType == "STORE") dic["RelationType"] = "门店";
  85. if(RelationType == "STAFF") dic["RelationType"] = "员工";
  86. if(RelationType == "STORE_OWNER") dic["RelationType"] = "店主";
  87. if(RelationType == "PARTNER") dic["RelationType"] = "合作伙伴";
  88. if(RelationType == "HEADQUARTER") dic["RelationType"] = "总部";
  89. if(RelationType == "BRAND") dic["RelationType"] = "品牌方";
  90. if(RelationType == "DISTRIBUTOR") dic["RelationType"] = "分销商";
  91. if(RelationType == "USER") dic["RelationType"] = "用户";
  92. if(RelationType == "SUPPLIER") dic["RelationType"] = "供应商";
  93. if(RelationType == "CUSTOM") dic["RelationType"] = "自定义";
  94. if(RelationType == "") dic["RelationType"] = "";
  95. dic["UnfreezeUnsplitName"] = dic["UnfreezeUnsplit"].ToString() == "1" ? "是" : "否";
  96. //分账单状态
  97. string State = dic["State"].ToString();
  98. if(State == "PROCESSING") dic["State"] = "处理中";
  99. if(State == "FINISHED") dic["State"] = "分账完成";
  100. if(State == "") dic["State"] = "";
  101. }
  102. return Json(obj);
  103. }
  104. #endregion
  105. #region 增加分账记录
  106. /// <summary>
  107. /// 增加或修改分账记录信息
  108. /// </summary>
  109. /// <returns></returns>
  110. public IActionResult Add(string right)
  111. {
  112. ViewBag.RightInfo = RightInfo;
  113. ViewBag.right = right;
  114. return View();
  115. }
  116. #endregion
  117. #region 增加分账记录
  118. /// <summary>
  119. /// 增加或修改分账记录信息
  120. /// </summary>
  121. /// <returns></returns>
  122. [HttpPost]
  123. public string Add(ProfitReceiveRecord data)
  124. {
  125. Dictionary<string, object> Fields = new Dictionary<string, object>();
  126. Fields.Add("MerchantId", data.MerchantId); //商户
  127. Fields.Add("SubMchid", data.SubMchid); //子商户号
  128. Fields.Add("AppId", data.AppId); //应用ID
  129. Fields.Add("SubAppId", data.SubAppId); //子商户应用ID
  130. Fields.Add("Type", data.Type); //分账接收方类型
  131. Fields.Add("Account", data.Account); //分账接收方账号
  132. Fields.Add("Name", data.Name); //分账个人接收方姓名
  133. Fields.Add("RelationType", data.RelationType); //与分账方的关系类型
  134. Fields.Add("CustomRelation", data.CustomRelation); //自定义的分账关系
  135. Fields.Add("TransactionId", data.TransactionId); //微信订单号
  136. Fields.Add("OutOrderNo", data.OutOrderNo); //商户分账单号
  137. Fields.Add("Amount", data.Amount); //分账金额
  138. Fields.Add("Description", data.Description); //分账描述
  139. Fields.Add("UnfreezeUnsplit", data.UnfreezeUnsplit); //是否解冻剩余未分资金
  140. Fields.Add("SeoTitle", data.SeoTitle);
  141. Fields.Add("SeoKeyword", data.SeoKeyword);
  142. Fields.Add("SeoDescription", data.SeoDescription);
  143. int Id = new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Add("ProfitReceiveRecord", Fields, 0);
  144. AddSysLog(data.Id.ToString(), "ProfitReceiveRecord", "add");
  145. db.SaveChanges();
  146. return "success";
  147. }
  148. #endregion
  149. #region 修改分账记录
  150. /// <summary>
  151. /// 增加或修改分账记录信息
  152. /// </summary>
  153. /// <returns></returns>
  154. public IActionResult Edit(string right, int Id = 0)
  155. {
  156. ViewBag.RightInfo = RightInfo;
  157. ViewBag.right = right;
  158. ProfitReceiveRecord editData = db.ProfitReceiveRecord.FirstOrDefault(m => m.Id == Id) ?? new ProfitReceiveRecord();
  159. ViewBag.data = editData;
  160. return View();
  161. }
  162. #endregion
  163. #region 修改分账记录
  164. /// <summary>
  165. /// 增加或修改分账记录信息
  166. /// </summary>
  167. /// <returns></returns>
  168. [HttpPost]
  169. public string Edit(ProfitReceiveRecord data)
  170. {
  171. Dictionary<string, object> Fields = new Dictionary<string, object>();
  172. Fields.Add("MerchantId", data.MerchantId); //商户
  173. Fields.Add("SubMchid", data.SubMchid); //子商户号
  174. Fields.Add("AppId", data.AppId); //应用ID
  175. Fields.Add("SubAppId", data.SubAppId); //子商户应用ID
  176. Fields.Add("Type", data.Type); //分账接收方类型
  177. Fields.Add("Account", data.Account); //分账接收方账号
  178. Fields.Add("Name", data.Name); //分账个人接收方姓名
  179. Fields.Add("RelationType", data.RelationType); //与分账方的关系类型
  180. Fields.Add("CustomRelation", data.CustomRelation); //自定义的分账关系
  181. Fields.Add("TransactionId", data.TransactionId); //微信订单号
  182. Fields.Add("OutOrderNo", data.OutOrderNo); //商户分账单号
  183. Fields.Add("Amount", data.Amount); //分账金额
  184. Fields.Add("Description", data.Description); //分账描述
  185. Fields.Add("UnfreezeUnsplit", data.UnfreezeUnsplit); //是否解冻剩余未分资金
  186. Fields.Add("SeoTitle", data.SeoTitle);
  187. Fields.Add("SeoKeyword", data.SeoKeyword);
  188. Fields.Add("SeoDescription", data.SeoDescription);
  189. new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Edit("ProfitReceiveRecord", Fields, data.Id);
  190. AddSysLog(data.Id.ToString(),"ProfitReceiveRecord","update");
  191. db.SaveChanges();
  192. return "success";
  193. }
  194. #endregion
  195. #region 删除分账记录信息
  196. /// <summary>
  197. /// 删除分账记录信息
  198. /// </summary>
  199. /// <returns></returns>
  200. public string Delete(string Id)
  201. {
  202. string[] idlist = Id.Split(new char[] { ',' });
  203. AddSysLog(Id,"ProfitReceiveRecord","del");
  204. foreach (string subid in idlist)
  205. {
  206. int id = int.Parse(subid);
  207. Dictionary<string, object> Fields = new Dictionary<string, object>();
  208. Fields.Add("Status", -1);
  209. new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Edit("ProfitReceiveRecord", Fields, id);
  210. }
  211. db.SaveChanges();
  212. return "success";
  213. }
  214. #endregion
  215. #region 开启
  216. /// <summary>
  217. /// 开启
  218. /// </summary>
  219. /// <returns></returns>
  220. public string Open(string Id)
  221. {
  222. string[] idlist = Id.Split(new char[] { ',' });
  223. AddSysLog(Id,"ProfitReceiveRecord","open");
  224. foreach (string subid in idlist)
  225. {
  226. int id = int.Parse(subid);
  227. Dictionary<string, object> Fields = new Dictionary<string, object>();
  228. Fields.Add("Status", 1);
  229. new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Edit("ProfitReceiveRecord", Fields, id);
  230. }
  231. db.SaveChanges();
  232. return "success";
  233. }
  234. #endregion
  235. #region 关闭
  236. /// <summary>
  237. /// 关闭
  238. /// </summary>
  239. /// <returns></returns>
  240. public string Close(string Id)
  241. {
  242. string[] idlist = Id.Split(new char[] { ',' });
  243. AddSysLog(Id,"ProfitReceiveRecord","close");
  244. foreach (string subid in idlist)
  245. {
  246. int id = int.Parse(subid);
  247. Dictionary<string, object> Fields = new Dictionary<string, object>();
  248. Fields.Add("Status", 0);
  249. new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Edit("ProfitReceiveRecord", Fields, id);
  250. }
  251. db.SaveChanges();
  252. return "success";
  253. }
  254. #endregion
  255. #region 排序
  256. /// <summary>
  257. /// 排序
  258. /// </summary>
  259. /// <param name="Id"></param>
  260. public string Sort(int Id, int Sort)
  261. {
  262. new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Sort("ProfitReceiveRecord", Sort, Id);
  263. AddSysLog(Id.ToString(), "ProfitReceiveRecord", "sort");
  264. return "success";
  265. }
  266. #endregion
  267. #region 导入数据
  268. /// <summary>
  269. /// 导入数据
  270. /// </summary>
  271. /// <param name="ExcelData"></param>
  272. public string Import(string ExcelData)
  273. {
  274. ExcelData = HttpUtility.UrlDecode(ExcelData);
  275. JsonData list = JsonMapper.ToObject(ExcelData);
  276. for (int i = 1; i < list.Count;i++ )
  277. {
  278. JsonData dr = list[i];
  279. db.ProfitReceiveRecord.Add(new ProfitReceiveRecord()
  280. {
  281. CreateDate = DateTime.Now,
  282. UpdateDate = DateTime.Now,
  283. });
  284. db.SaveChanges();
  285. }
  286. AddSysLog("0", "ProfitReceiveRecord", "Import");
  287. return "success";
  288. }
  289. #endregion
  290. #region 导出Excel
  291. /// <summary>
  292. /// 导出Excel
  293. /// </summary>
  294. /// <returns></returns>
  295. public JsonResult ExportExcel(ProfitReceiveRecord data, string TypeSelect, string RelationTypeSelect, string StateSelect)
  296. {
  297. Dictionary<string, string> Fields = new Dictionary<string, string>();
  298. Fields.Add("CreateDate", "3"); //时间
  299. Fields.Add("SubMchid", "1"); //子商户号
  300. Fields.Add("AppId", "1"); //应用ID
  301. Fields.Add("SubAppId", "1"); //子商户应用ID
  302. Fields.Add("Account", "1"); //分账接收方账号
  303. Fields.Add("TransactionId", "1"); //微信订单号
  304. Fields.Add("OutOrderNo", "1"); //商户分账单号
  305. Fields.Add("OrderId", "1"); //微信分账单号
  306. string condition = " and Status>-1";
  307. //分账接收方类型
  308. if (!string.IsNullOrEmpty(TypeSelect))
  309. {
  310. condition += " and Type=" + TypeSelect;
  311. }
  312. //与分账方的关系类型
  313. if (!string.IsNullOrEmpty(RelationTypeSelect))
  314. {
  315. condition += " and RelationType=" + RelationTypeSelect;
  316. }
  317. //分账单状态
  318. if (!string.IsNullOrEmpty(StateSelect))
  319. {
  320. condition += " and State=" + StateSelect;
  321. }
  322. Dictionary<string, object> obj = new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).IndexData("ProfitReceiveRecord", Fields, "Id desc", "0", 1, 20000, condition, "", false);
  323. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  324. foreach (Dictionary<string, object> dic in diclist)
  325. {
  326. //分账接收方类型
  327. string Type = dic["Type"].ToString();
  328. if(Type == "MERCHANT_ID") dic["Type"] = "商户ID";
  329. if(Type == "PERSONAL_OPENID") dic["Type"] = "个人openid";
  330. if(Type == "PERSONAL_SUB_OPENID") dic["Type"] = "个人sub_openid";
  331. if(Type == "") dic["Type"] = "";
  332. //与分账方的关系类型
  333. string RelationType = dic["RelationType"].ToString();
  334. if(RelationType == "SERVICE_PROVIDER") dic["RelationType"] = "服务商";
  335. if(RelationType == "STORE") dic["RelationType"] = "门店";
  336. if(RelationType == "STAFF") dic["RelationType"] = "员工";
  337. if(RelationType == "STORE_OWNER") dic["RelationType"] = "店主";
  338. if(RelationType == "PARTNER") dic["RelationType"] = "合作伙伴";
  339. if(RelationType == "HEADQUARTER") dic["RelationType"] = "总部";
  340. if(RelationType == "BRAND") dic["RelationType"] = "品牌方";
  341. if(RelationType == "DISTRIBUTOR") dic["RelationType"] = "分销商";
  342. if(RelationType == "USER") dic["RelationType"] = "用户";
  343. if(RelationType == "SUPPLIER") dic["RelationType"] = "供应商";
  344. if(RelationType == "CUSTOM") dic["RelationType"] = "自定义";
  345. if(RelationType == "") dic["RelationType"] = "";
  346. dic["UnfreezeUnsplitName"] = dic["UnfreezeUnsplit"].ToString() == "1" ? "是" : "否";
  347. //分账单状态
  348. string State = dic["State"].ToString();
  349. if(State == "PROCESSING") dic["State"] = "处理中";
  350. if(State == "FINISHED") dic["State"] = "分账完成";
  351. if(State == "") dic["State"] = "";
  352. }
  353. Dictionary<string, object> result = new Dictionary<string, object>();
  354. result.Add("Status", "1");
  355. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  356. result.Add("Obj", diclist);
  357. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  358. result.Add("Fields", ReturnFields);
  359. AddSysLog("0", "ProfitReceiveRecord", "ExportExcel");
  360. return Json(result);
  361. }
  362. #endregion
  363. }
  364. }