ProfitSubsidyDetailController.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  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.Data;
  10. using System.Threading.Tasks;
  11. using Microsoft.AspNetCore.Mvc;
  12. using Microsoft.AspNetCore.Http;
  13. using Microsoft.Extensions.Logging;
  14. using Microsoft.Extensions.Options;
  15. using MySystem.Models;
  16. using Library;
  17. using LitJson;
  18. using MySystemLib;
  19. namespace MySystem.Areas.Admin.Controllers
  20. {
  21. [Area("Admin")]
  22. [Route("Admin/[controller]/[action]")]
  23. public class ProfitSubsidyDetailController : BaseController
  24. {
  25. public ProfitSubsidyDetailController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  26. {
  27. OtherMySqlConn.connstr = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  28. }
  29. #region 分润补贴明细列表
  30. /// <summary>
  31. /// 根据条件查询分润补贴明细列表
  32. /// </summary>
  33. /// <returns></returns>
  34. public IActionResult Index(ProfitSubsidyDetail data, string right)
  35. {
  36. ViewBag.RightInfo = RightInfo;
  37. ViewBag.right = right;
  38. List<KqProducts> Brands = db.KqProducts.OrderBy(m => m.Id).ToList();
  39. ViewBag.Brands = Brands;
  40. return View();
  41. }
  42. #endregion
  43. #region 根据条件查询分润补贴明细列表
  44. /// <summary>
  45. /// 分润补贴明细列表
  46. /// </summary>
  47. /// <returns></returns>
  48. public JsonResult IndexData(ProfitSubsidyDetail data, string MerchantNo, string MerchantName, string MakerCode, string RealName, string TradeMonthSelect, string BrandIdSelect, string SubsidyTypeSelect, int page = 1, int limit = 30)
  49. {
  50. Dictionary<string, string> Fields = new Dictionary<string, string>();
  51. Fields.Add("BrandId", "1"); //品牌
  52. Fields.Add("MerNo", "2"); //渠道商户编号
  53. Fields.Add("SnNo", "2"); //渠道SN号
  54. string condition = " and Status>-1";
  55. //商户编号
  56. if (!string.IsNullOrEmpty(MerchantNo))
  57. {
  58. condition += " and MerchantId in (select MerchantId from MerchantForCode where Code='" + MerchantNo + "')";
  59. }
  60. //商户名称
  61. if (!string.IsNullOrEmpty(MerchantName))
  62. {
  63. condition += " and MerchantId in (select MerchantId from MerchantForName where Name='" + MerchantName + "')";
  64. }
  65. //补贴创客编号
  66. if (!string.IsNullOrEmpty(MakerCode))
  67. {
  68. condition += " and SubsidyUserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  69. }
  70. //补贴创客名称
  71. if (!string.IsNullOrEmpty(RealName))
  72. {
  73. condition += " and SubsidyUserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  74. }
  75. //分润补贴类型
  76. if (!string.IsNullOrEmpty(SubsidyTypeSelect))
  77. {
  78. condition += " and SubsidyType=" + SubsidyTypeSelect;
  79. }
  80. //交易月份
  81. // if(!string.IsNullOrEmpty(TradeMonthSelect))
  82. // {
  83. // condition += " and TradeMonth=" + TradeMonthSelect.Replace("-", "");
  84. // }
  85. if (!string.IsNullOrEmpty(TradeMonthSelect))
  86. {
  87. string[] datelist = TradeMonthSelect.Split(new string[] { " - " }, StringSplitOptions.None);
  88. string start = datelist[0];
  89. condition += " and TradeMonth=" + start;
  90. // var check = db.ProfitSubsidyDetail.Any(m => Convert.ToInt32(m.TradeMonth) >= Convert.ToInt32(start));
  91. // var checks = db.ProfitSubsidyDetail.Any(m => Convert.ToInt32(m.TradeMonth) <= Convert.ToInt32(end));
  92. // if (check)
  93. // {
  94. // var sId = db.ProfitSubsidyDetail.Where(m => Convert.ToInt32(m.TradeMonth) >= Convert.ToInt32(start)).Min(m => m.Id);
  95. // condition += " and Id >=" + sId;
  96. // }
  97. // if (checks)
  98. // {
  99. // var eId = db.ProfitSubsidyDetail.Where(m => Convert.ToInt32(m.TradeMonth) <= Convert.ToInt32(start)).Max(m => m.Id);
  100. // condition += " and Id <=" + eId;
  101. // }
  102. }
  103. else
  104. {
  105. var start = DateTime.Now.AddMonths(-1).ToString("yyyyMM");
  106. condition += " and TradeMonth>=" + start;
  107. // var check = db.ProfitSubsidyDetail.Any(m => Convert.ToInt32(m.TradeMonth) >= Convert.ToInt32(start));
  108. // if (check)
  109. // {
  110. // var minId = db.ProfitSubsidyDetail.Where(m => Convert.ToInt32(m.TradeMonth) >= Convert.ToInt32(start)).Min(m => m.Id);
  111. // var Info = Convert.ToInt32(function.ReadInstance("/WritePage/ProfitSubsidyDetail/ProfitSubsidyDetail.txt"));
  112. // if (string.IsNullOrEmpty(Info.ToString()))
  113. // {
  114. // function.WritePage("/WritePage/ProfitSubsidyDetail/", "ProfitSubsidyDetail.txt", minId.ToString());
  115. // condition += " and Id >=" + minId;
  116. // }
  117. // else
  118. // {
  119. // condition += " and Id >=" + Info;
  120. // }
  121. // }
  122. // else
  123. // {
  124. // condition += " and Id =0";
  125. // }
  126. }
  127. //产品类型
  128. if (!string.IsNullOrEmpty(BrandIdSelect))
  129. {
  130. condition += " and BrandId=" + BrandIdSelect;
  131. }
  132. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("ProfitSubsidyDetail", Fields, "Id desc", "0", page, limit, condition);
  133. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  134. foreach (Dictionary<string, object> dic in diclist)
  135. {
  136. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  137. int SubsidyUserId = int.Parse(dic["SubsidyUserId"].ToString());
  138. Users user = db.Users.FirstOrDefault(m => m.Id == SubsidyUserId) ?? new Users();
  139. dic["MakerCode"] = user.MakerCode;
  140. dic["RealName"] = user.RealName;
  141. int MerchantId = int.Parse(dic["MerchantId"].ToString());
  142. MerchantInfo mer = db.MerchantInfo.FirstOrDefault(m => m.Id == MerchantId) ?? new MerchantInfo();
  143. dic["MerchantNo"] = "";
  144. dic["MerchantName"] = mer.Name;
  145. int SubsidyType = int.Parse(dic["SubsidyType"].ToString());
  146. if (SubsidyType == 0) dic["SubsidyType"] = "直营商户交易分润补贴";
  147. if (SubsidyType == 1) dic["SubsidyType"] = "下级商户交易分润补贴";
  148. }
  149. Dictionary<string, object> other = new Dictionary<string, object>();
  150. string SubsidyProfit = "0.00";//分润补贴金额
  151. DataTable dt = OtherMySqlConn.dtable("select sum(SubsidyProfit) from ProfitSubsidyDetail where 1=1" + condition);
  152. if (dt.Rows.Count > 0)
  153. {
  154. SubsidyProfit = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  155. }
  156. other.Add("SubsidyProfit", SubsidyProfit);
  157. obj.Add("other", other);
  158. return Json(obj);
  159. }
  160. #endregion
  161. #region 增加分润补贴明细
  162. /// <summary>
  163. /// 增加或修改分润补贴明细信息
  164. /// </summary>
  165. /// <returns></returns>
  166. public IActionResult Add(string right)
  167. {
  168. ViewBag.RightInfo = RightInfo;
  169. ViewBag.right = right;
  170. return View();
  171. }
  172. #endregion
  173. #region 增加分润补贴明细
  174. /// <summary>
  175. /// 增加或修改分润补贴明细信息
  176. /// </summary>
  177. /// <returns></returns>
  178. [HttpPost]
  179. public string Add(ProfitSubsidyDetail data)
  180. {
  181. Dictionary<string, object> Fields = new Dictionary<string, object>();
  182. Fields.Add("Remark", data.Remark); //备注
  183. Fields.Add("SeoTitle", data.SeoTitle);
  184. Fields.Add("SeoKeyword", data.SeoKeyword);
  185. Fields.Add("SeoDescription", data.SeoDescription);
  186. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("ProfitSubsidyDetail", Fields, 0);
  187. AddSysLog(data.Id.ToString(), "ProfitSubsidyDetail", "add");
  188. db.SaveChanges();
  189. return "success";
  190. }
  191. #endregion
  192. #region 修改分润补贴明细
  193. /// <summary>
  194. /// 增加或修改分润补贴明细信息
  195. /// </summary>
  196. /// <returns></returns>
  197. public IActionResult Edit(string right, int Id = 0)
  198. {
  199. ViewBag.RightInfo = RightInfo;
  200. ViewBag.right = right;
  201. ProfitSubsidyDetail editData = db.ProfitSubsidyDetail.FirstOrDefault(m => m.Id == Id) ?? new ProfitSubsidyDetail();
  202. ViewBag.data = editData;
  203. return View();
  204. }
  205. #endregion
  206. #region 修改分润补贴明细
  207. /// <summary>
  208. /// 增加或修改分润补贴明细信息
  209. /// </summary>
  210. /// <returns></returns>
  211. [HttpPost]
  212. public string Edit(ProfitSubsidyDetail data)
  213. {
  214. Dictionary<string, object> Fields = new Dictionary<string, object>();
  215. Fields.Add("Remark", data.Remark); //备注
  216. Fields.Add("SeoTitle", data.SeoTitle);
  217. Fields.Add("SeoKeyword", data.SeoKeyword);
  218. Fields.Add("SeoDescription", data.SeoDescription);
  219. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("ProfitSubsidyDetail", Fields, data.Id);
  220. AddSysLog(data.Id.ToString(), "ProfitSubsidyDetail", "update");
  221. db.SaveChanges();
  222. return "success";
  223. }
  224. #endregion
  225. #region 删除分润补贴明细信息
  226. /// <summary>
  227. /// 删除分润补贴明细信息
  228. /// </summary>
  229. /// <returns></returns>
  230. public string Delete(string Id)
  231. {
  232. string[] idlist = Id.Split(new char[] { ',' });
  233. AddSysLog(Id, "ProfitSubsidyDetail", "del");
  234. foreach (string subid in idlist)
  235. {
  236. int id = int.Parse(subid);
  237. Dictionary<string, object> Fields = new Dictionary<string, object>();
  238. Fields.Add("Status", -1);
  239. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("ProfitSubsidyDetail", Fields, id);
  240. }
  241. db.SaveChanges();
  242. return "success";
  243. }
  244. #endregion
  245. #region 开启
  246. /// <summary>
  247. /// 开启
  248. /// </summary>
  249. /// <returns></returns>
  250. public string Open(string Id)
  251. {
  252. string[] idlist = Id.Split(new char[] { ',' });
  253. AddSysLog(Id, "ProfitSubsidyDetail", "open");
  254. foreach (string subid in idlist)
  255. {
  256. int id = int.Parse(subid);
  257. Dictionary<string, object> Fields = new Dictionary<string, object>();
  258. Fields.Add("Status", 1);
  259. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("ProfitSubsidyDetail", Fields, id);
  260. }
  261. db.SaveChanges();
  262. return "success";
  263. }
  264. #endregion
  265. #region 关闭
  266. /// <summary>
  267. /// 关闭
  268. /// </summary>
  269. /// <returns></returns>
  270. public string Close(string Id)
  271. {
  272. string[] idlist = Id.Split(new char[] { ',' });
  273. AddSysLog(Id, "ProfitSubsidyDetail", "close");
  274. foreach (string subid in idlist)
  275. {
  276. int id = int.Parse(subid);
  277. Dictionary<string, object> Fields = new Dictionary<string, object>();
  278. Fields.Add("Status", 0);
  279. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("ProfitSubsidyDetail", Fields, id);
  280. }
  281. db.SaveChanges();
  282. return "success";
  283. }
  284. #endregion
  285. #region 排序
  286. /// <summary>
  287. /// 排序
  288. /// </summary>
  289. /// <param name="Id"></param>
  290. public string Sort(int Id, int Sort)
  291. {
  292. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("ProfitSubsidyDetail", Sort, Id);
  293. AddSysLog(Id.ToString(), "ProfitSubsidyDetail", "sort");
  294. return "success";
  295. }
  296. #endregion
  297. #region 导入数据
  298. /// <summary>
  299. /// 导入数据
  300. /// </summary>
  301. /// <param name="ExcelData"></param>
  302. public string Import(string ExcelData)
  303. {
  304. ExcelData = HttpUtility.UrlDecode(ExcelData);
  305. JsonData list = JsonMapper.ToObject(ExcelData);
  306. for (int i = 1; i < list.Count; i++)
  307. {
  308. JsonData dr = list[i];
  309. db.ProfitSubsidyDetail.Add(new ProfitSubsidyDetail()
  310. {
  311. CreateDate = DateTime.Now,
  312. UpdateDate = DateTime.Now,
  313. });
  314. db.SaveChanges();
  315. }
  316. AddSysLog("0", "ProfitSubsidyDetail", "Import");
  317. return "success";
  318. }
  319. #endregion
  320. #region 导出Excel
  321. /// <summary>
  322. /// 导出Excel
  323. /// </summary>
  324. /// <returns></returns>
  325. public JsonResult ExportExcel(ProfitSubsidyDetail data, string MerchantNo, string MerchantName, string MakerCode, string RealName, string TradeMonthSelect, string SubsidyTypeSelect)
  326. {
  327. Dictionary<string, string> Fields = new Dictionary<string, string>();
  328. Fields.Add("BrandId", "1"); //品牌
  329. Fields.Add("MerNo", "2"); //渠道商户编号
  330. Fields.Add("SnNo", "2"); //渠道SN号
  331. string condition = " and Status>-1";
  332. //商户编号
  333. if (!string.IsNullOrEmpty(MerchantNo))
  334. {
  335. condition += " and MerchantId in (select MerchantId from MerchantForCode where Code='" + MerchantNo + "')";
  336. }
  337. //商户名称
  338. if (!string.IsNullOrEmpty(MerchantName))
  339. {
  340. condition += " and MerchantId in (select MerchantId from MerchantForName where Name='" + MerchantName + "')";
  341. }
  342. //补贴创客编号
  343. if (!string.IsNullOrEmpty(MakerCode))
  344. {
  345. condition += " and SubsidyUserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  346. }
  347. //补贴创客名称
  348. if (!string.IsNullOrEmpty(RealName))
  349. {
  350. condition += " and SubsidyUserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  351. }
  352. //分润补贴类型
  353. if (!string.IsNullOrEmpty(SubsidyTypeSelect))
  354. {
  355. condition += " and SubsidyType=" + SubsidyTypeSelect;
  356. }
  357. //交易月份
  358. if (!string.IsNullOrEmpty(TradeMonthSelect))
  359. {
  360. condition += " and TradeMonth=" + TradeMonthSelect.Replace("-", "");
  361. }
  362. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("ProfitSubsidyDetail", Fields, "Id desc", "0", 1, 20000, condition, "BrandId,MerchantId,MerNo,SnNo,MerRegTime,MerStandardDate,SubsidyUserId,SubsidyType,CreditTradeAmt,QrCreditTradeAmt,NonQrCreditTradeAmt,CreditProfitRate,SubsidyProfitRate,SubsidyProfit", false);
  363. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  364. foreach (Dictionary<string, object> dic in diclist)
  365. {
  366. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  367. int SubsidyUserId = int.Parse(dic["SubsidyUserId"].ToString());
  368. Users user = db.Users.FirstOrDefault(m => m.Id == SubsidyUserId) ?? new Users();
  369. dic["MakerCode"] = user.MakerCode;
  370. dic["RealName"] = user.RealName;
  371. int MerchantId = int.Parse(dic["MerchantId"].ToString());
  372. MerchantInfo mer = db.MerchantInfo.FirstOrDefault(m => m.Id == MerchantId) ?? new MerchantInfo();
  373. dic["MerchantNo"] = "";
  374. dic["MerchantName"] = mer.Name;
  375. int SubsidyType = int.Parse(dic["SubsidyType"].ToString());
  376. if (SubsidyType == 0) dic["SubsidyType"] = "直营商户交易分润补贴";
  377. if (SubsidyType == 1) dic["SubsidyType"] = "下级商户交易分润补贴";
  378. dic.Remove("SubsidyUserId");
  379. dic.Remove("MerchantId");
  380. }
  381. Dictionary<string, object> result = new Dictionary<string, object>();
  382. result.Add("Status", "1");
  383. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  384. result.Add("Obj", diclist);
  385. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  386. ReturnFields.Add("BrandId", "品牌");
  387. ReturnFields.Add("MerchantId", "商户");
  388. ReturnFields.Add("MerNo", "渠道商户编号");
  389. ReturnFields.Add("SnNo", "渠道SN号");
  390. ReturnFields.Add("MerRegTime", "渠道注册时间");
  391. ReturnFields.Add("MerStandardDate", "商户激活时间");
  392. ReturnFields.Add("SubsidyUserId", "补贴人");
  393. ReturnFields.Add("SubsidyType", "分润补贴类型");
  394. ReturnFields.Add("CreditTradeAmt", "商户贷记卡交易总金额");
  395. ReturnFields.Add("QrCreditTradeAmt", "商户(云闪付)贷记卡交易总金额");
  396. ReturnFields.Add("NonQrCreditTradeAmt", "商户(非云闪付)贷记卡交易总金额");
  397. ReturnFields.Add("CreditProfitRate", "(非云闪付)贷记卡交易分润比例");
  398. ReturnFields.Add("SubsidyProfitRate", "创客活动期内直营商户分润万分之十");
  399. ReturnFields.Add("SubsidyProfit", "商户(非云闪付)贷记卡交易分润补贴金额");
  400. result.Add("Fields", ReturnFields);
  401. AddSysLog("0", "ProfitSubsidyDetail", "ExportExcel");
  402. return Json(result);
  403. }
  404. #endregion
  405. }
  406. }