ConsumerProfitController.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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 ConsumerProfitController : BaseController
  23. {
  24. public ConsumerProfitController(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(ConsumerProfit 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(ConsumerProfit data, string ConsumerIdNickName, string ConsumerIdMobile, string MerchantIdSelect, int page = 1, int limit = 30)
  45. {
  46. Dictionary<string, string> Fields = new Dictionary<string, string>();
  47. Fields.Add("CreateDate", "3"); //时间
  48. string condition = " and Status>-1";
  49. //消费者昵称
  50. if (!string.IsNullOrEmpty(ConsumerIdNickName))
  51. {
  52. condition += " and ConsumerId in (select ConsumerId from ConsumersForNickName where NickName='" + ConsumerIdNickName + "')";
  53. }
  54. //消费者手机号
  55. if (!string.IsNullOrEmpty(ConsumerIdMobile))
  56. {
  57. condition += " and ConsumerId in (select ConsumerId from ConsumersForMobile where Mobile='" + ConsumerIdMobile + "')";
  58. }
  59. //商户
  60. if (!string.IsNullOrEmpty(MerchantIdSelect))
  61. {
  62. condition += " and MerchantId=" + MerchantIdSelect;
  63. }
  64. Dictionary<string, object> obj = new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).IndexData("ConsumerProfit", Fields, "Id desc", "0", page, limit, condition);
  65. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  66. foreach (Dictionary<string, object> dic in diclist)
  67. {
  68. //消费者
  69. int ConsumerId = int.Parse(function.CheckInt(dic["ConsumerId"].ToString()));
  70. Consumers consumerid_Consumers = db.Consumers.FirstOrDefault(m => m.Id == ConsumerId) ?? new Consumers();
  71. dic["ConsumerIdNickName"] = consumerid_Consumers.NickName;
  72. dic["ConsumerIdMobile"] = consumerid_Consumers.Mobile;
  73. dic.Remove("ConsumerId");
  74. //商户
  75. dic["MerchantId"] = RelationClass.GetMerchantInfoInfo(int.Parse(dic["MerchantId"].ToString()));
  76. }
  77. return Json(obj);
  78. }
  79. #endregion
  80. #region 增加消费者分红记录
  81. /// <summary>
  82. /// 增加或修改消费者分红记录信息
  83. /// </summary>
  84. /// <returns></returns>
  85. public IActionResult Add(string right)
  86. {
  87. ViewBag.RightInfo = RightInfo;
  88. ViewBag.right = right;
  89. return View();
  90. }
  91. #endregion
  92. #region 增加消费者分红记录
  93. /// <summary>
  94. /// 增加或修改消费者分红记录信息
  95. /// </summary>
  96. /// <returns></returns>
  97. [HttpPost]
  98. public string Add(ConsumerProfit data)
  99. {
  100. Dictionary<string, object> Fields = new Dictionary<string, object>();
  101. Fields.Add("SeoTitle", data.SeoTitle);
  102. Fields.Add("SeoKeyword", data.SeoKeyword);
  103. Fields.Add("SeoDescription", data.SeoDescription);
  104. int Id = new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Add("ConsumerProfit", Fields, 0);
  105. AddSysLog(data.Id.ToString(), "ConsumerProfit", "add");
  106. db.SaveChanges();
  107. return "success";
  108. }
  109. #endregion
  110. #region 修改消费者分红记录
  111. /// <summary>
  112. /// 增加或修改消费者分红记录信息
  113. /// </summary>
  114. /// <returns></returns>
  115. public IActionResult Edit(string right, int Id = 0)
  116. {
  117. ViewBag.RightInfo = RightInfo;
  118. ViewBag.right = right;
  119. ConsumerProfit editData = db.ConsumerProfit.FirstOrDefault(m => m.Id == Id) ?? new ConsumerProfit();
  120. ViewBag.data = editData;
  121. return View();
  122. }
  123. #endregion
  124. #region 修改消费者分红记录
  125. /// <summary>
  126. /// 增加或修改消费者分红记录信息
  127. /// </summary>
  128. /// <returns></returns>
  129. [HttpPost]
  130. public string Edit(ConsumerProfit data)
  131. {
  132. Dictionary<string, object> Fields = new Dictionary<string, object>();
  133. Fields.Add("SeoTitle", data.SeoTitle);
  134. Fields.Add("SeoKeyword", data.SeoKeyword);
  135. Fields.Add("SeoDescription", data.SeoDescription);
  136. new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Edit("ConsumerProfit", Fields, data.Id);
  137. AddSysLog(data.Id.ToString(),"ConsumerProfit","update");
  138. db.SaveChanges();
  139. return "success";
  140. }
  141. #endregion
  142. #region 删除消费者分红记录信息
  143. /// <summary>
  144. /// 删除消费者分红记录信息
  145. /// </summary>
  146. /// <returns></returns>
  147. public string Delete(string Id)
  148. {
  149. string[] idlist = Id.Split(new char[] { ',' });
  150. AddSysLog(Id,"ConsumerProfit","del");
  151. foreach (string subid in idlist)
  152. {
  153. int id = int.Parse(subid);
  154. Dictionary<string, object> Fields = new Dictionary<string, object>();
  155. Fields.Add("Status", -1);
  156. new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Edit("ConsumerProfit", Fields, id);
  157. }
  158. db.SaveChanges();
  159. return "success";
  160. }
  161. #endregion
  162. #region 开启
  163. /// <summary>
  164. /// 开启
  165. /// </summary>
  166. /// <returns></returns>
  167. public string Open(string Id)
  168. {
  169. string[] idlist = Id.Split(new char[] { ',' });
  170. AddSysLog(Id,"ConsumerProfit","open");
  171. foreach (string subid in idlist)
  172. {
  173. int id = int.Parse(subid);
  174. Dictionary<string, object> Fields = new Dictionary<string, object>();
  175. Fields.Add("Status", 1);
  176. new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Edit("ConsumerProfit", Fields, id);
  177. }
  178. db.SaveChanges();
  179. return "success";
  180. }
  181. #endregion
  182. #region 关闭
  183. /// <summary>
  184. /// 关闭
  185. /// </summary>
  186. /// <returns></returns>
  187. public string Close(string Id)
  188. {
  189. string[] idlist = Id.Split(new char[] { ',' });
  190. AddSysLog(Id,"ConsumerProfit","close");
  191. foreach (string subid in idlist)
  192. {
  193. int id = int.Parse(subid);
  194. Dictionary<string, object> Fields = new Dictionary<string, object>();
  195. Fields.Add("Status", 0);
  196. new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Edit("ConsumerProfit", Fields, id);
  197. }
  198. db.SaveChanges();
  199. return "success";
  200. }
  201. #endregion
  202. #region 排序
  203. /// <summary>
  204. /// 排序
  205. /// </summary>
  206. /// <param name="Id"></param>
  207. public string Sort(int Id, int Sort)
  208. {
  209. new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).Sort("ConsumerProfit", Sort, Id);
  210. AddSysLog(Id.ToString(), "ConsumerProfit", "sort");
  211. return "success";
  212. }
  213. #endregion
  214. #region 导入数据
  215. /// <summary>
  216. /// 导入数据
  217. /// </summary>
  218. /// <param name="ExcelData"></param>
  219. public string Import(string ExcelData)
  220. {
  221. ExcelData = HttpUtility.UrlDecode(ExcelData);
  222. JsonData list = JsonMapper.ToObject(ExcelData);
  223. for (int i = 1; i < list.Count;i++ )
  224. {
  225. JsonData dr = list[i];
  226. db.ConsumerProfit.Add(new ConsumerProfit()
  227. {
  228. CreateDate = DateTime.Now,
  229. UpdateDate = DateTime.Now,
  230. });
  231. db.SaveChanges();
  232. }
  233. AddSysLog("0", "ConsumerProfit", "Import");
  234. return "success";
  235. }
  236. #endregion
  237. #region 导出Excel
  238. /// <summary>
  239. /// 导出Excel
  240. /// </summary>
  241. /// <returns></returns>
  242. public JsonResult ExportExcel(ConsumerProfit data, string ConsumerIdNickName, string ConsumerIdMobile, string MerchantIdSelect)
  243. {
  244. Dictionary<string, string> Fields = new Dictionary<string, string>();
  245. Fields.Add("CreateDate", "3"); //时间
  246. string condition = " and Status>-1";
  247. //消费者昵称
  248. if (!string.IsNullOrEmpty(ConsumerIdNickName))
  249. {
  250. condition += " and ConsumerId in (select ConsumerId from ConsumersForNickName where NickName='" + ConsumerIdNickName + "')";
  251. }
  252. //消费者手机号
  253. if (!string.IsNullOrEmpty(ConsumerIdMobile))
  254. {
  255. condition += " and ConsumerId in (select ConsumerId from ConsumersForMobile where Mobile='" + ConsumerIdMobile + "')";
  256. }
  257. //商户
  258. if (!string.IsNullOrEmpty(MerchantIdSelect))
  259. {
  260. condition += " and MerchantId=" + MerchantIdSelect;
  261. }
  262. Dictionary<string, object> obj = new AdminContent(_accessor.HttpContext, PublicFunction.MainTables).IndexData("ConsumerProfit", Fields, "Id desc", "0", 1, 20000, condition, "", false);
  263. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  264. foreach (Dictionary<string, object> dic in diclist)
  265. {
  266. //消费者
  267. int ConsumerId = int.Parse(function.CheckInt(dic["ConsumerId"].ToString()));
  268. Consumers consumerid_Consumers = db.Consumers.FirstOrDefault(m => m.Id == ConsumerId) ?? new Consumers();
  269. dic["ConsumerIdNickName"] = consumerid_Consumers.NickName;
  270. dic["ConsumerIdMobile"] = consumerid_Consumers.Mobile;
  271. dic.Remove("ConsumerId");
  272. //商户
  273. dic["MerchantId"] = RelationClass.GetMerchantInfoInfo(int.Parse(dic["MerchantId"].ToString()));
  274. }
  275. Dictionary<string, object> result = new Dictionary<string, object>();
  276. result.Add("Status", "1");
  277. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  278. result.Add("Obj", diclist);
  279. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  280. result.Add("Fields", ReturnFields);
  281. AddSysLog("0", "ConsumerProfit", "ExportExcel");
  282. return Json(result);
  283. }
  284. #endregion
  285. }
  286. }