FluxProfitDetailController.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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 FluxProfitDetailController : BaseController
  23. {
  24. public FluxProfitDetailController(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(FluxProfitDetail 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(FluxProfitDetail data, string MakerCode, string RealName, string TopMakerCode, string TopRealName, string MerUserTypeSelect, string ProfitTypeSelect, int page = 1, int limit = 30)
  46. {
  47. Dictionary<string, string> Fields = new Dictionary<string, string>();
  48. Fields.Add("CreateDate", "3"); //时间
  49. Fields.Add("MerNo", "1"); //渠道商户编号
  50. Fields.Add("SnNo", "1"); //渠道SN号
  51. Fields.Add("FluxOrderNo", "1"); //流量扣费单号
  52. Fields.Add("TradeOrderNo", "1"); //交易流水号
  53. string condition = " and Status>-1";
  54. //创客编号
  55. if (!string.IsNullOrEmpty(MakerCode))
  56. {
  57. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  58. }
  59. //创客名称
  60. if (!string.IsNullOrEmpty(RealName))
  61. {
  62. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  63. }
  64. //顶级创客编号
  65. if (!string.IsNullOrEmpty(TopMakerCode))
  66. {
  67. condition += " and TopUserId in (select UserId from UserForMakerCode where MakerCode='" + TopMakerCode + "')";
  68. }
  69. //顶级创客名称
  70. if (!string.IsNullOrEmpty(TopRealName))
  71. {
  72. condition += " and TopUserId in (select UserId from UserForRealName where RealName='" + TopRealName + "')";
  73. }
  74. //商户创客类型
  75. if (!string.IsNullOrEmpty(MerUserTypeSelect))
  76. {
  77. condition += " and MerUserType=" + MerUserTypeSelect;
  78. }
  79. //分润类型
  80. if (!string.IsNullOrEmpty(ProfitTypeSelect))
  81. {
  82. condition += " and ProfitType=" + ProfitTypeSelect;
  83. }
  84. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("FluxProfitDetail", Fields, "Id desc", "0", page, limit, condition);
  85. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  86. foreach (Dictionary<string, object> dic in diclist)
  87. {
  88. int UserId = int.Parse(dic["UserId"].ToString());
  89. Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  90. dic["MakerCode"] = user.MakerCode;
  91. dic["RealName"] = user.RealName;
  92. int TopUserId = int.Parse(dic["TopUserId"].ToString());
  93. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  94. dic["TopMakerCode"] = tuser.MakerCode;
  95. dic["TopRealName"] = tuser.RealName;
  96. int MerchantId = int.Parse(dic["MerchantId"].ToString());
  97. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == MerchantId) ?? new MerchantInfo();
  98. dic["MerchantMobile"] = merchant.Mobile;
  99. int MerUserType = int.Parse(dic["MerUserType"].ToString());
  100. if (MerUserType == 0) dic["MerUserType"] = "非商户型创客";
  101. if (MerUserType == 1) dic["MerUserType"] = "商户型创客";
  102. int ProfitType = int.Parse(dic["ProfitType"].ToString());
  103. if (ProfitType == 0) dic["ProfitType"] = "直属分佣";
  104. if (ProfitType == 1) dic["ProfitType"] = "顶级交易分润";
  105. if (ProfitType == 2) dic["ProfitType"] = "上级交易分佣";
  106. }
  107. Dictionary<string, object> other = new Dictionary<string, object>();
  108. other.Add("ProfitAmt", 0);
  109. obj.Add("other", other);
  110. return Json(obj);
  111. }
  112. #endregion
  113. #region 增加流量分佣明细
  114. /// <summary>
  115. /// 增加或修改流量分佣明细信息
  116. /// </summary>
  117. /// <returns></returns>
  118. public IActionResult Add(string right)
  119. {
  120. ViewBag.RightInfo = RightInfo;
  121. ViewBag.right = right;
  122. return View();
  123. }
  124. #endregion
  125. #region 增加流量分佣明细
  126. /// <summary>
  127. /// 增加或修改流量分佣明细信息
  128. /// </summary>
  129. /// <returns></returns>
  130. [HttpPost]
  131. public string Add(FluxProfitDetail data)
  132. {
  133. Dictionary<string, object> Fields = new Dictionary<string, object>();
  134. Fields.Add("SeoTitle", data.SeoTitle);
  135. Fields.Add("SeoKeyword", data.SeoKeyword);
  136. Fields.Add("SeoDescription", data.SeoDescription);
  137. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("FluxProfitDetail", Fields, 0);
  138. AddSysLog(data.Id.ToString(), "FluxProfitDetail", "add");
  139. db.SaveChanges();
  140. return "success";
  141. }
  142. #endregion
  143. #region 修改流量分佣明细
  144. /// <summary>
  145. /// 增加或修改流量分佣明细信息
  146. /// </summary>
  147. /// <returns></returns>
  148. public IActionResult Edit(string right, int Id = 0)
  149. {
  150. ViewBag.RightInfo = RightInfo;
  151. ViewBag.right = right;
  152. FluxProfitDetail editData = db.FluxProfitDetail.FirstOrDefault(m => m.Id == Id) ?? new FluxProfitDetail();
  153. ViewBag.data = editData;
  154. return View();
  155. }
  156. #endregion
  157. #region 修改流量分佣明细
  158. /// <summary>
  159. /// 增加或修改流量分佣明细信息
  160. /// </summary>
  161. /// <returns></returns>
  162. [HttpPost]
  163. public string Edit(FluxProfitDetail data)
  164. {
  165. Dictionary<string, object> Fields = new Dictionary<string, object>();
  166. Fields.Add("SeoTitle", data.SeoTitle);
  167. Fields.Add("SeoKeyword", data.SeoKeyword);
  168. Fields.Add("SeoDescription", data.SeoDescription);
  169. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("FluxProfitDetail", Fields, data.Id);
  170. AddSysLog(data.Id.ToString(), "FluxProfitDetail", "update");
  171. db.SaveChanges();
  172. return "success";
  173. }
  174. #endregion
  175. #region 删除流量分佣明细信息
  176. /// <summary>
  177. /// 删除流量分佣明细信息
  178. /// </summary>
  179. /// <returns></returns>
  180. public string Delete(string Id)
  181. {
  182. string[] idlist = Id.Split(new char[] { ',' });
  183. AddSysLog(Id, "FluxProfitDetail", "del");
  184. foreach (string subid in idlist)
  185. {
  186. int id = int.Parse(subid);
  187. Dictionary<string, object> Fields = new Dictionary<string, object>();
  188. Fields.Add("Status", -1);
  189. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("FluxProfitDetail", Fields, id);
  190. }
  191. db.SaveChanges();
  192. return "success";
  193. }
  194. #endregion
  195. #region 开启
  196. /// <summary>
  197. /// 开启
  198. /// </summary>
  199. /// <returns></returns>
  200. public string Open(string Id)
  201. {
  202. string[] idlist = Id.Split(new char[] { ',' });
  203. AddSysLog(Id, "FluxProfitDetail", "open");
  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 AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("FluxProfitDetail", 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 Close(string Id)
  221. {
  222. string[] idlist = Id.Split(new char[] { ',' });
  223. AddSysLog(Id, "FluxProfitDetail", "close");
  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", 0);
  229. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("FluxProfitDetail", Fields, id);
  230. }
  231. db.SaveChanges();
  232. return "success";
  233. }
  234. #endregion
  235. #region 排序
  236. /// <summary>
  237. /// 排序
  238. /// </summary>
  239. /// <param name="Id"></param>
  240. public string Sort(int Id, int Sort)
  241. {
  242. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("FluxProfitDetail", Sort, Id);
  243. AddSysLog(Id.ToString(), "FluxProfitDetail", "sort");
  244. return "success";
  245. }
  246. #endregion
  247. #region 导入数据
  248. /// <summary>
  249. /// 导入数据
  250. /// </summary>
  251. /// <param name="ExcelData"></param>
  252. public string Import(string ExcelData)
  253. {
  254. ExcelData = HttpUtility.UrlDecode(ExcelData);
  255. JsonData list = JsonMapper.ToObject(ExcelData);
  256. for (int i = 1; i < list.Count; i++)
  257. {
  258. JsonData dr = list[i];
  259. db.FluxProfitDetail.Add(new FluxProfitDetail()
  260. {
  261. CreateDate = DateTime.Now,
  262. UpdateDate = DateTime.Now,
  263. });
  264. db.SaveChanges();
  265. }
  266. AddSysLog("0", "FluxProfitDetail", "Import");
  267. return "success";
  268. }
  269. #endregion
  270. #region 导出Excel
  271. /// <summary>
  272. /// 导出Excel
  273. /// </summary>
  274. /// <returns></returns>
  275. public JsonResult ExportExcel(FluxProfitDetail data, string MakerCode, string RealName, string TopMakerCode, string TopRealName, string MerUserTypeSelect, string ProfitTypeSelect)
  276. {
  277. Dictionary<string, string> Fields = new Dictionary<string, string>();
  278. Fields.Add("CreateDate", "3"); //时间
  279. Fields.Add("TradeDate", "2"); //交易日期
  280. Fields.Add("MerNo", "2"); //渠道商户编号
  281. Fields.Add("SnNo", "2"); //渠道SN号
  282. Fields.Add("ProfitType", "1"); //分润类型
  283. Fields.Add("FluxOrderNo", "2"); //流量扣费单号
  284. Fields.Add("TradeOrderNo", "2"); //交易流水号
  285. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("FluxProfitDetail", Fields, "Id desc", "0", 1, 20000, "", "TradeDate,UserId,TopUserId,MerchantId,MerNo,SnNo,ProfitType,FluxOrderNo,TradeOrderNo,TradeAmt,FluxFeeAmt,FluxStartDate,FluxEndDate,FluxProfitAmt,MerUserType", false);
  286. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  287. foreach (Dictionary<string, object> dic in diclist)
  288. {
  289. int UserId = int.Parse(dic["UserId"].ToString());
  290. Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  291. dic["MakerCode"] = user.MakerCode;
  292. dic["RealName"] = user.RealName;
  293. int TopUserId = int.Parse(dic["TopUserId"].ToString());
  294. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  295. dic["TopMakerCode"] = tuser.MakerCode;
  296. dic["TopRealName"] = tuser.RealName;
  297. int MerchantId = int.Parse(dic["MerchantId"].ToString());
  298. MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == MerchantId) ?? new MerchantInfo();
  299. dic["MerchantMobile"] = merchant.Mobile;
  300. int MerUserType = int.Parse(dic["MerUserType"].ToString());
  301. if (MerUserType == 0) dic["MerUserType"] = "非商户型创客";
  302. if (MerUserType == 1) dic["MerUserType"] = "商户型创客";
  303. int ProfitType = int.Parse(dic["ProfitType"].ToString());
  304. if (ProfitType == 0) dic["ProfitType"] = "直属分佣";
  305. if (ProfitType == 1) dic["ProfitType"] = "顶级交易分润";
  306. if (ProfitType == 2) dic["ProfitType"] = "上级交易分佣";
  307. dic.Remove("UserId");
  308. dic.Remove("TopUserId");
  309. dic.Remove("MerchantId");
  310. }
  311. Dictionary<string, object> result = new Dictionary<string, object>();
  312. result.Add("Status", "1");
  313. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  314. result.Add("Obj", diclist);
  315. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  316. ReturnFields.Add("MakerCode", "创客编号");
  317. ReturnFields.Add("RealName", "创客姓名");
  318. ReturnFields.Add("TopMakerCode", "顶级创客编号");
  319. ReturnFields.Add("TopRealName", "顶级创客姓名");
  320. ReturnFields.Add("TradeDate", "交易日期");
  321. ReturnFields.Add("MerUserType", "商户创客类型");
  322. ReturnFields.Add("MerchantMobile", "商户手机号");
  323. ReturnFields.Add("MerNo", "快钱商户编号");
  324. ReturnFields.Add("SnNo", "快钱SN号");
  325. ReturnFields.Add("ProfitType", "分润类型");
  326. ReturnFields.Add("FluxOrderNo", "流量扣费单号");
  327. ReturnFields.Add("TradeOrderNo", "交易流水号");
  328. ReturnFields.Add("TradeAmt", "商户交易额元)'");
  329. ReturnFields.Add("FluxFeeAmt", "流量费元)'");
  330. ReturnFields.Add("FluxProfitAmt", "流量分润总金额元)'");
  331. ReturnFields.Add("FluxStartDate", "流量扣费开始日期");
  332. ReturnFields.Add("FluxEndDate", "流量扣费结束日期");
  333. result.Add("Fields", ReturnFields);
  334. AddSysLog("0", "FluxProfitDetail", "ExportExcel");
  335. return Json(result);
  336. }
  337. #endregion
  338. }
  339. }