ProfitReceivesController.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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 ProfitReceivesController : BaseController
  23. {
  24. public ProfitReceivesController(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(ProfitReceives 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(ProfitReceives data, string TypeSelect, string RelationTypeSelect, 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. string condition = " and Status>-1";
  53. //分账接收方类型
  54. if (!string.IsNullOrEmpty(TypeSelect))
  55. {
  56. condition += " and Type=" + TypeSelect;
  57. }
  58. //与分账方的关系类型
  59. if (!string.IsNullOrEmpty(RelationTypeSelect))
  60. {
  61. condition += " and RelationType=" + RelationTypeSelect;
  62. }
  63. Dictionary<string, object> obj = new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).IndexData("ProfitReceives", Fields, "Id desc", "0", page, limit, condition);
  64. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  65. foreach (Dictionary<string, object> dic in diclist)
  66. {
  67. //商户
  68. dic["MerchantId"] = RelationClass.GetMerchantInfoInfo(int.Parse(dic["MerchantId"].ToString()));
  69. dic["StatusName"] = dic["Status"].ToString() == "1" ? "正常" : "关闭";
  70. //分账接收方类型
  71. string Type = dic["Type"].ToString();
  72. if(Type == "MERCHANT_ID") dic["Type"] = "商户ID";
  73. if(Type == "PERSONAL_OPENID") dic["Type"] = "个人openid";
  74. if(Type == "PERSONAL_SUB_OPENID") dic["Type"] = "个人sub_openid";
  75. if(Type == "") dic["Type"] = "";
  76. //与分账方的关系类型
  77. string RelationType = dic["RelationType"].ToString();
  78. if(RelationType == "SERVICE_PROVIDER") dic["RelationType"] = "服务商";
  79. if(RelationType == "STORE") dic["RelationType"] = "门店";
  80. if(RelationType == "STAFF") dic["RelationType"] = "员工";
  81. if(RelationType == "STORE_OWNER") dic["RelationType"] = "店主";
  82. if(RelationType == "PARTNER") dic["RelationType"] = "合作伙伴";
  83. if(RelationType == "HEADQUARTER") dic["RelationType"] = "总部";
  84. if(RelationType == "BRAND") dic["RelationType"] = "品牌方";
  85. if(RelationType == "DISTRIBUTOR") dic["RelationType"] = "分销商";
  86. if(RelationType == "USER") dic["RelationType"] = "用户";
  87. if(RelationType == "SUPPLIER") dic["RelationType"] = "供应商";
  88. if(RelationType == "CUSTOM") dic["RelationType"] = "自定义";
  89. if(RelationType == "") dic["RelationType"] = "";
  90. }
  91. return Json(obj);
  92. }
  93. #endregion
  94. #region 增加分账接收方
  95. /// <summary>
  96. /// 增加或修改分账接收方信息
  97. /// </summary>
  98. /// <returns></returns>
  99. public IActionResult Add(string right)
  100. {
  101. ViewBag.RightInfo = RightInfo;
  102. ViewBag.right = right;
  103. return View();
  104. }
  105. #endregion
  106. #region 增加分账接收方
  107. /// <summary>
  108. /// 增加或修改分账接收方信息
  109. /// </summary>
  110. /// <returns></returns>
  111. [HttpPost]
  112. public string Add(ProfitReceives data)
  113. {
  114. Dictionary<string, object> Fields = new Dictionary<string, object>();
  115. Fields.Add("MerchantId", data.MerchantId); //商户
  116. Fields.Add("SubMchid", data.SubMchid); //子商户号
  117. Fields.Add("AppId", data.AppId); //应用ID
  118. Fields.Add("SubAppId", data.SubAppId); //子商户应用ID
  119. Fields.Add("Type", data.Type); //分账接收方类型
  120. Fields.Add("Account", data.Account); //分账接收方账号
  121. Fields.Add("Name", data.Name); //分账个人接收方姓名
  122. Fields.Add("RelationType", data.RelationType); //与分账方的关系类型
  123. Fields.Add("CustomRelation", data.CustomRelation); //自定义的分账关系
  124. Fields.Add("SeoTitle", data.SeoTitle);
  125. Fields.Add("SeoKeyword", data.SeoKeyword);
  126. Fields.Add("SeoDescription", data.SeoDescription);
  127. int Id = new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Add("ProfitReceives", Fields, 0);
  128. AddSysLog(data.Id.ToString(), "ProfitReceives", "add");
  129. db.SaveChanges();
  130. return "success";
  131. }
  132. #endregion
  133. #region 修改分账接收方
  134. /// <summary>
  135. /// 增加或修改分账接收方信息
  136. /// </summary>
  137. /// <returns></returns>
  138. public IActionResult Edit(string right, int Id = 0)
  139. {
  140. ViewBag.RightInfo = RightInfo;
  141. ViewBag.right = right;
  142. ProfitReceives editData = db.ProfitReceives.FirstOrDefault(m => m.Id == Id) ?? new ProfitReceives();
  143. ViewBag.data = editData;
  144. return View();
  145. }
  146. #endregion
  147. #region 修改分账接收方
  148. /// <summary>
  149. /// 增加或修改分账接收方信息
  150. /// </summary>
  151. /// <returns></returns>
  152. [HttpPost]
  153. public string Edit(ProfitReceives data)
  154. {
  155. Dictionary<string, object> Fields = new Dictionary<string, object>();
  156. Fields.Add("MerchantId", data.MerchantId); //商户
  157. Fields.Add("SubMchid", data.SubMchid); //子商户号
  158. Fields.Add("AppId", data.AppId); //应用ID
  159. Fields.Add("SubAppId", data.SubAppId); //子商户应用ID
  160. Fields.Add("Type", data.Type); //分账接收方类型
  161. Fields.Add("Account", data.Account); //分账接收方账号
  162. Fields.Add("Name", data.Name); //分账个人接收方姓名
  163. Fields.Add("RelationType", data.RelationType); //与分账方的关系类型
  164. Fields.Add("CustomRelation", data.CustomRelation); //自定义的分账关系
  165. Fields.Add("SeoTitle", data.SeoTitle);
  166. Fields.Add("SeoKeyword", data.SeoKeyword);
  167. Fields.Add("SeoDescription", data.SeoDescription);
  168. new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Edit("ProfitReceives", Fields, data.Id);
  169. AddSysLog(data.Id.ToString(),"ProfitReceives","update");
  170. db.SaveChanges();
  171. return "success";
  172. }
  173. #endregion
  174. #region 删除分账接收方信息
  175. /// <summary>
  176. /// 删除分账接收方信息
  177. /// </summary>
  178. /// <returns></returns>
  179. public string Delete(string Id)
  180. {
  181. string[] idlist = Id.Split(new char[] { ',' });
  182. AddSysLog(Id,"ProfitReceives","del");
  183. foreach (string subid in idlist)
  184. {
  185. int id = int.Parse(subid);
  186. Dictionary<string, object> Fields = new Dictionary<string, object>();
  187. Fields.Add("Status", -1);
  188. new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Edit("ProfitReceives", Fields, id);
  189. }
  190. db.SaveChanges();
  191. return "success";
  192. }
  193. #endregion
  194. #region 开启
  195. /// <summary>
  196. /// 开启
  197. /// </summary>
  198. /// <returns></returns>
  199. public string Open(string Id)
  200. {
  201. string[] idlist = Id.Split(new char[] { ',' });
  202. AddSysLog(Id,"ProfitReceives","open");
  203. foreach (string subid in idlist)
  204. {
  205. int id = int.Parse(subid);
  206. Dictionary<string, object> Fields = new Dictionary<string, object>();
  207. Fields.Add("Status", 1);
  208. new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Edit("ProfitReceives", Fields, id);
  209. }
  210. db.SaveChanges();
  211. return "success";
  212. }
  213. #endregion
  214. #region 关闭
  215. /// <summary>
  216. /// 关闭
  217. /// </summary>
  218. /// <returns></returns>
  219. public string Close(string Id)
  220. {
  221. string[] idlist = Id.Split(new char[] { ',' });
  222. AddSysLog(Id,"ProfitReceives","close");
  223. foreach (string subid in idlist)
  224. {
  225. int id = int.Parse(subid);
  226. Dictionary<string, object> Fields = new Dictionary<string, object>();
  227. Fields.Add("Status", 0);
  228. new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Edit("ProfitReceives", Fields, id);
  229. }
  230. db.SaveChanges();
  231. return "success";
  232. }
  233. #endregion
  234. #region 排序
  235. /// <summary>
  236. /// 排序
  237. /// </summary>
  238. /// <param name="Id"></param>
  239. public string Sort(int Id, int Sort)
  240. {
  241. new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Sort("ProfitReceives", Sort, Id);
  242. AddSysLog(Id.ToString(), "ProfitReceives", "sort");
  243. return "success";
  244. }
  245. #endregion
  246. #region 导入数据
  247. /// <summary>
  248. /// 导入数据
  249. /// </summary>
  250. /// <param name="ExcelData"></param>
  251. public string Import(string ExcelData)
  252. {
  253. ExcelData = HttpUtility.UrlDecode(ExcelData);
  254. JsonData list = JsonMapper.ToObject(ExcelData);
  255. for (int i = 1; i < list.Count;i++ )
  256. {
  257. JsonData dr = list[i];
  258. db.ProfitReceives.Add(new ProfitReceives()
  259. {
  260. CreateDate = DateTime.Now,
  261. UpdateDate = DateTime.Now,
  262. });
  263. db.SaveChanges();
  264. }
  265. AddSysLog("0", "ProfitReceives", "Import");
  266. return "success";
  267. }
  268. #endregion
  269. #region 导出Excel
  270. /// <summary>
  271. /// 导出Excel
  272. /// </summary>
  273. /// <returns></returns>
  274. public JsonResult ExportExcel(ProfitReceives data, string TypeSelect, string RelationTypeSelect)
  275. {
  276. Dictionary<string, string> Fields = new Dictionary<string, string>();
  277. Fields.Add("CreateDate", "3"); //时间
  278. Fields.Add("SubMchid", "1"); //子商户号
  279. Fields.Add("AppId", "1"); //应用ID
  280. Fields.Add("SubAppId", "1"); //子商户应用ID
  281. Fields.Add("Account", "1"); //分账接收方账号
  282. string condition = " and Status>-1";
  283. //分账接收方类型
  284. if (!string.IsNullOrEmpty(TypeSelect))
  285. {
  286. condition += " and Type=" + TypeSelect;
  287. }
  288. //与分账方的关系类型
  289. if (!string.IsNullOrEmpty(RelationTypeSelect))
  290. {
  291. condition += " and RelationType=" + RelationTypeSelect;
  292. }
  293. Dictionary<string, object> obj = new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).IndexData("ProfitReceives", Fields, "Id desc", "0", 1, 20000, condition, "", false);
  294. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  295. foreach (Dictionary<string, object> dic in diclist)
  296. {
  297. //商户
  298. dic["MerchantId"] = RelationClass.GetMerchantInfoInfo(int.Parse(dic["MerchantId"].ToString()));
  299. dic["StatusName"] = dic["Status"].ToString() == "1" ? "正常" : "关闭";
  300. //分账接收方类型
  301. string Type = dic["Type"].ToString();
  302. if(Type == "MERCHANT_ID") dic["Type"] = "商户ID";
  303. if(Type == "PERSONAL_OPENID") dic["Type"] = "个人openid";
  304. if(Type == "PERSONAL_SUB_OPENID") dic["Type"] = "个人sub_openid";
  305. if(Type == "") dic["Type"] = "";
  306. //与分账方的关系类型
  307. string RelationType = dic["RelationType"].ToString();
  308. if(RelationType == "SERVICE_PROVIDER") dic["RelationType"] = "服务商";
  309. if(RelationType == "STORE") dic["RelationType"] = "门店";
  310. if(RelationType == "STAFF") dic["RelationType"] = "员工";
  311. if(RelationType == "STORE_OWNER") dic["RelationType"] = "店主";
  312. if(RelationType == "PARTNER") dic["RelationType"] = "合作伙伴";
  313. if(RelationType == "HEADQUARTER") dic["RelationType"] = "总部";
  314. if(RelationType == "BRAND") dic["RelationType"] = "品牌方";
  315. if(RelationType == "DISTRIBUTOR") dic["RelationType"] = "分销商";
  316. if(RelationType == "USER") dic["RelationType"] = "用户";
  317. if(RelationType == "SUPPLIER") dic["RelationType"] = "供应商";
  318. if(RelationType == "CUSTOM") dic["RelationType"] = "自定义";
  319. if(RelationType == "") dic["RelationType"] = "";
  320. }
  321. Dictionary<string, object> result = new Dictionary<string, object>();
  322. result.Add("Status", "1");
  323. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  324. result.Add("Obj", diclist);
  325. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  326. result.Add("Fields", ReturnFields);
  327. AddSysLog("0", "ProfitReceives", "ExportExcel");
  328. return Json(result);
  329. }
  330. #endregion
  331. }
  332. }