ConsumerProfitController.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Data;
  5. using Microsoft.AspNetCore.Mvc;
  6. using Microsoft.AspNetCore.Http;
  7. using Microsoft.Extensions.Logging;
  8. using Microsoft.Extensions.Options;
  9. using Microsoft.AspNetCore.Authorization;
  10. using MySystem.MainModels;
  11. using LitJson;
  12. using Library;
  13. using System.Security.Cryptography;
  14. using System.Text;
  15. namespace MySystem.Areas.Api.Controllers.v1
  16. {
  17. [Area("Api")]
  18. [Route("/v1/QrCodePlateMain/[controller]/[action]")]
  19. public class ConsumerProfitController : ConsumersController
  20. {
  21. public ConsumerProfitController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  22. {
  23. }
  24. #region 我的-分红记录-列表
  25. [Authorize]
  26. public JsonResult List(string value)
  27. {
  28. value = DesDecrypt(value);
  29. JsonData data = JsonMapper.ToObject(value);
  30. Dictionary<string, object> Other = new Dictionary<string, object>();
  31. List<Dictionary<string, object>> dataList = ListDo(value, out Other);
  32. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  33. }
  34. private List<Dictionary<string, object>> ListDo(string value, out Dictionary<string, object> Other)
  35. {
  36. JsonData data = JsonMapper.ToObject(value);
  37. int ConsumerId = int.Parse(function.CheckInt(data["ConsumerId"].ToString())); //用户Id
  38. int Kind = int.Parse(function.CheckInt(data["Kind"].ToString())); //类型(1 支付宝 2 微信)
  39. int pageSize = int.Parse(function.CheckInt(data["page_size"].ToString()));
  40. int pageNum = int.Parse(function.CheckInt(data["page_num"].ToString()));
  41. string condition = " WHERE 1=1";
  42. string limitString = " LIMIT " + pageSize;
  43. if (pageNum > 1)
  44. {
  45. int skipNum = pageSize * (pageNum - 1);
  46. limitString = " LIMIT " + skipNum + "," + pageSize;
  47. }
  48. condition += limitString;
  49. List<RelationData> relationData = new List<RelationData>();
  50. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  51. Other = new Dictionary<string, object>();
  52. var WechatOpenId = "";
  53. var consumer = Services.Main.ConsumersService.Query(ConsumerId);
  54. var consumer2 = Services.Main2.ConsumersService.Query(ConsumerId);
  55. if (consumer.Id > 0 && ConsumerId > 0)
  56. {
  57. WechatOpenId = consumer.WechatOpenId;
  58. }
  59. else
  60. {
  61. if (consumer2.Id > 0 && ConsumerId > 0)
  62. {
  63. WechatOpenId = consumer2.WechatOpenId;
  64. }
  65. }
  66. if (ConsumerId > 0 && !string.IsNullOrEmpty(WechatOpenId))
  67. {
  68. DataTable dt = CustomerSqlConn.dtable("SELECT * FROM(SELECT a.*,b.CertMerchantName FROM (SELECT Id,1 Kind,CreateDate,SeoTitle,GetMoney,MerchantId FROM QrCodePlateMainServer.ConsumerProfit WHERE OrderId IN(SELECT Id FROM QrCodePlateMainServer.ConsumerOrders WHERE ConsumerId IN(SELECT Id FROM QrCodePlateMainServer.Consumers WHERE WechatOpenId='" + WechatOpenId + "') AND Status>0 AND PayMode=" + Kind + "))a LEFT JOIN (SELECT Id,CertMerchantName FROM QrCodePlateMainServer.MerchantAddInfo WHERE Status=2 OR QueryCount=2)b ON a.MerchantId=b.Id UNION ALL SELECT a.*,b.CertMerchantName FROM (SELECT Id,2 Kind,CreateDate,SeoTitle,GetMoney,MerchantId FROM QrCodePlateMainServer2.ConsumerProfit WHERE OrderId IN(SELECT Id FROM QrCodePlateMainServer2.ConsumerOrders WHERE ConsumerId IN(SELECT Id FROM QrCodePlateMainServer2.Consumers WHERE WechatOpenId='" + WechatOpenId + "') AND Status>0 AND PayMode=" + Kind + "))a LEFT JOIN (SELECT Id,CertMerchantName FROM QrCodePlateMainServer2.MerchantAddInfo WHERE Status=2 OR QueryCount=2)b ON a.MerchantId=b.Id)aa" + condition, AppConfig.Base.SqlConnStr);
  69. foreach (DataRow dr in dt.Rows)
  70. {
  71. Dictionary<string, object> curData = new Dictionary<string, object>();
  72. curData.Add("Id", int.Parse(dr["Id"].ToString())); //Id
  73. curData.Add("Kind", int.Parse(dr["Kind"].ToString())); //商户类型(1 直连 2 银联)
  74. curData.Add("OrderNo", dr["SeoTitle"].ToString()); //订单号
  75. curData.Add("CreateDate", dr["CreateDate"].ToString()); //创建时间
  76. curData.Add("MerchantName", dr["CertMerchantName"].ToString()); //商户名称
  77. curData.Add("GetMoney", decimal.Parse(dr["GetMoney"].ToString())); //分红金额
  78. dataList.Add(curData);
  79. }
  80. Other.Add("count", dt.Rows.Count);
  81. }
  82. else
  83. {
  84. Other.Add("count", 0);
  85. }
  86. return dataList;
  87. }
  88. #endregion
  89. }
  90. }