MerchantInfoController.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 MySystem.Services;
  12. using LitJson;
  13. using Library;
  14. namespace MySystem.Areas.Api.Controllers.v1
  15. {
  16. [Area("Api")]
  17. [Route("/v1/QrCodePlateMain/[controller]/[action]")]
  18. public class MerchantInfoController : BaseController
  19. {
  20. public MerchantInfoController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  21. {
  22. }
  23. #region 首页-首页-商户门店信息-列表
  24. // [Authorize]
  25. public JsonResult MerchantInfoList(string value)
  26. {
  27. value = DesDecrypt(value);
  28. JsonData data = JsonMapper.ToObject(value);
  29. Dictionary<string, object> Other = new Dictionary<string, object>();
  30. List<Dictionary<string, object>> dataList = MerchantInfoListDo(value, out Other);
  31. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  32. }
  33. private List<Dictionary<string, object>> MerchantInfoListDo(string value, out Dictionary<string, object> Other)
  34. {
  35. JsonData data = JsonMapper.ToObject(value);
  36. string Area = data["Area"].ToString(); //地区
  37. var Longitude = function.CheckNum(data["Longitude"].ToString()); //经度
  38. var Latitude = function.CheckNum(data["Latitude"].ToString()); //纬度
  39. string SearchKey = data["SearchKey"].ToString(); //搜索关键词
  40. int Sort = int.Parse(data["Sort"].ToString()); //排序(1 人气值降序 2 距离升序)
  41. int pageSize = int.Parse(function.CheckInt(data["page_size"].ToString()));
  42. int pageNum = int.Parse(function.CheckInt(data["page_num"].ToString()));
  43. string condition = " WHERE 1=1";
  44. if (!string.IsNullOrEmpty(data["Area"].ToString()))
  45. {
  46. condition += " AND s.Areas like '%" + Area + "%'";
  47. }
  48. if (!string.IsNullOrEmpty(data["Sort"].ToString()))
  49. {
  50. if (Sort == 1) condition += " ORDER BY s.Popularity DESC";
  51. if (Sort == 2) condition += " ORDER BY s.distance";
  52. }
  53. if (!string.IsNullOrEmpty(data["SearchKey"].ToString()))
  54. {
  55. condition += " AND s.Name like '%" + SearchKey + "%'";
  56. }
  57. string limitString = " LIMIT " + pageSize;
  58. if (pageNum > 1)
  59. {
  60. int skipNum = pageSize * (pageNum - 1);
  61. limitString = " LIMIT " + skipNum + "," + pageSize;
  62. }
  63. condition += limitString;
  64. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  65. DataTable dt = CustomerSqlConn.dtable("SELECT DISTINCT s.Name,s.Id,s.Kind,s.Areas,s.Address,s.Popularity,s.Longitude,s.Latitude,s.ServicePhone,s.CertMerchantName,s.MerchantShortname,s.StoreEntrancePic,s.BusinessName,s.distance FROM(SELECT aa.*, FORMAT(ST_DISTANCE(POINT(aa.Longitude, aa.Latitude), POINT(" + Longitude + ", " + Latitude + ")),2) AS distance FROM (SELECT a.Id,1 Kind,a.Name,a.Areas,a.Address,a.Popularity,a.Longitude,a.Latitude,b.ServicePhone,b.CertMerchantName,b.MerchantShortname,b.StoreEntrancePic,b.QualificationType BusinessName FROM(SELECT Id,Name,Areas,Address,Popularity,Longitude,Latitude,Mobile FROM QrCodePlateMainServer.MerchantInfo WHERE IsAct=1 AND (Status=2 OR QueryCount=2))a LEFT JOIN (SELECT Id,ServicePhone,CertMerchantName,MerchantShortname,StoreEntrancePic,SalesScenesType,Qualifications,QualificationType,BizAddressCode,BizStoreAddress FROM QrCodePlateMainServer.MerchantAddInfo)b ON a.Id=b.Id UNION ALL SELECT a.Id,2 Kind,a.Name,a.Areas,a.Address,a.Popularity,a.Longitude,a.Latitude,b.ServicePhone,b.CertMerchantName,b.MerchantShortname,b.StoreEntrancePic,c.Name BusinessName FROM(SELECT Id,Name,Areas,Address,Popularity,Longitude,Latitude,Mobile FROM QrCodePlateMainServer2.MerchantInfo WHERE IsAct=1 AND (Status=2 OR QueryCount=2))a LEFT JOIN (SELECT Id,ServicePhone,CertMerchantName,MerchantShortname,StoreEntrancePic,BusinessId,BizAddressCode,BizStoreAddress FROM QrCodePlateMainServer2.MerchantAddInfo)b ON a.Id=b.Id LEFT JOIN (SELECT * FROM BusinessScope)c ON b.BusinessId=c.Id)aa)s" + condition, AppConfig.Base.SqlConnStr);
  66. foreach (DataRow dr in dt.Rows)
  67. {
  68. Dictionary<string, object> curData = new Dictionary<string, object>();
  69. var Kind = int.Parse(dr["Kind"].ToString()); //商户类型(1 直连 2 银联)
  70. string[] StoreEntrancePic = dr["StoreEntrancePic"].ToString().Split(',');
  71. curData.Add("Id", int.Parse(dr["Id"].ToString())); //商户Id
  72. curData.Add("Kind", Kind); //商户类型(1 直连 2 银联)
  73. curData.Add("MerchantName", dr["Name"].ToString()); //商户名称
  74. curData.Add("BusinessName", dr["BusinessName"].ToString()); //经营类型
  75. curData.Add("StoreEntrancePic", StoreEntrancePic[0]); //门店门头照片
  76. curData.Add("BizStoreAddress", dr["Areas"].ToString() + dr["Address"].ToString()); //门店地址
  77. curData.Add("Popularity", dr["Popularity"].ToString()); //人气值
  78. curData.Add("Distance", dr["distance"].ToString()); //距离
  79. dataList.Add(curData);
  80. }
  81. Other = new Dictionary<string, object>();
  82. Other.Add("count", dt.Rows.Count);
  83. return dataList;
  84. }
  85. #endregion
  86. #region 首页-首页-商户门店信息-详情
  87. // [Authorize]
  88. public JsonResult MerchantInfoDetail(string value)
  89. {
  90. value = DesDecrypt(value);
  91. JsonData data = JsonMapper.ToObject(value);
  92. Dictionary<string, object> Obj = MerchantInfoDetailDo(value);
  93. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  94. }
  95. private Dictionary<string, object> MerchantInfoDetailDo(string value)
  96. {
  97. JsonData data = JsonMapper.ToObject(value);
  98. int Id = int.Parse(data["Id"].ToString()); //商户Id
  99. int Kind = int.Parse(data["Kind"].ToString()); //商户类型(1 直连 2 银联)
  100. Dictionary<string, object> Obj = new Dictionary<string, object>();
  101. var BusinessName = "";
  102. if (Kind == 1)
  103. {
  104. var merAddInfo = Services.Main.MerchantAddInfoService.Query(Id);
  105. var merInfo = Services.Main.MerchantInfoService.Query(Id);
  106. BusinessName = merAddInfo.QualificationType;
  107. string[] Atlas = new string[0];
  108. if (!string.IsNullOrEmpty(merAddInfo.StoreEntrancePic))
  109. {
  110. Atlas = merAddInfo.StoreEntrancePic.Split(',');
  111. }
  112. Obj.Add("Atlas", Atlas); //图集
  113. Obj.Add("MerchantName", merInfo.Name); //商户名称
  114. Obj.Add("Popularity", merInfo.Popularity); //人气值
  115. Obj.Add("BusinessName", BusinessName); //经营类型
  116. Obj.Add("BusinessHours", merInfo.BusinessHours == null ? "周一至周五 09:00-22:00" : "周一至周五 09:00 - 22:00"); //营业时间
  117. Obj.Add("MerchantMobile", merInfo.Mobile); //商户电话
  118. Obj.Add("Introduction", merInfo.BriefIntroduction == null ? "待完善..." : "待完善..."); //商户简介
  119. Obj.Add("Longitude", merInfo.Longitude); //经度
  120. Obj.Add("Latitude", merInfo.Latitude); //纬度
  121. Obj.Add("StoreEntrancePic", Atlas[0]); //门店门头照片
  122. Obj.Add("BizStoreAddress", merInfo.Areas + merInfo.Address); //门店地址
  123. }
  124. if (Kind == 2)
  125. {
  126. var merAddInfo = Services.Main2.MerchantAddInfoService.Query(Id);
  127. var merInfo = Services.Main2.MerchantInfoService.Query(Id);
  128. BusinessName = Services.Main2.BusinessScopeService.Query(merAddInfo.BusinessId).Name;
  129. string[] Atlas = new string[0];
  130. if (!string.IsNullOrEmpty(merAddInfo.StoreEntrancePic))
  131. {
  132. Atlas = merAddInfo.StoreEntrancePic.Split(',');
  133. }
  134. Obj.Add("Atlas", Atlas); //图集
  135. Obj.Add("MerchantName", merInfo.Name); //商户名称
  136. Obj.Add("Popularity", merInfo.Popularity); //人气值
  137. Obj.Add("BusinessName", BusinessName); //经营类型
  138. Obj.Add("BusinessHours", merInfo.BusinessHours == null ? "周一至周五 09:00-22:00" : "周一至周五 09:00 - 22:00"); //营业时间
  139. Obj.Add("MerchantMobile", merInfo.Mobile); //商户电话
  140. Obj.Add("Introduction", merInfo.BriefIntroduction == null ? "待完善..." : "待完善..."); //商户简介
  141. Obj.Add("Longitude", merInfo.Longitude); //经度
  142. Obj.Add("Latitude", merInfo.Latitude); //纬度
  143. Obj.Add("StoreEntrancePic", Atlas[0]); //门店门头照片
  144. Obj.Add("BizStoreAddress", merInfo.Areas + merInfo.Address); //门店地址
  145. }
  146. return Obj;
  147. }
  148. #endregion
  149. }
  150. }