MerchantInfoController.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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.*, ST_DISTANCE_SPHERE(POINT(aa.Longitude, aa.Latitude), POINT(" + Longitude + ", " + Latitude + ")) 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("MerchantShortName", dr["MerchantShortname"].ToString()); //商户简称
  75. curData.Add("BusinessName", dr["BusinessName"].ToString()); //经营类型
  76. curData.Add("StoreEntrancePic", StoreEntrancePic[0]); //门店门头照片
  77. curData.Add("BizStoreAddress", (dr["Areas"].ToString() + dr["Address"].ToString()).Replace(",", "")); //门店地址
  78. curData.Add("Popularity", dr["Popularity"].ToString()); //人气值
  79. curData.Add("Distance", decimal.Parse(dr["distance"].ToString()).ToString("F2")); //距离
  80. dataList.Add(curData);
  81. }
  82. Other = new Dictionary<string, object>();
  83. Other.Add("count", dt.Rows.Count);
  84. return dataList;
  85. }
  86. #endregion
  87. #region 首页-首页-商户门店信息-详情
  88. // [Authorize]
  89. public JsonResult MerchantInfoDetail(string value)
  90. {
  91. value = DesDecrypt(value);
  92. JsonData data = JsonMapper.ToObject(value);
  93. Dictionary<string, object> Obj = MerchantInfoDetailDo(value);
  94. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  95. }
  96. private Dictionary<string, object> MerchantInfoDetailDo(string value)
  97. {
  98. JsonData data = JsonMapper.ToObject(value);
  99. int Id = int.Parse(data["Id"].ToString()); //商户Id
  100. int Kind = int.Parse(data["Kind"].ToString()); //商户类型(1 直连 2 银联)
  101. Dictionary<string, object> Obj = new Dictionary<string, object>();
  102. var BusinessName = "";
  103. if (Kind == 1)
  104. {
  105. var merAddInfo = Services.Main.MerchantAddInfoService.Query(Id);
  106. var merInfo = Services.Main.MerchantInfoService.Query(Id);
  107. var info = maindb.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MainModels.MerchantInfo();
  108. info.Popularity += 1;
  109. maindb.SaveChanges();
  110. BusinessName = merAddInfo.QualificationType;
  111. string[] Atlas = new string[0];
  112. if (!string.IsNullOrEmpty(merAddInfo.StoreEntrancePic))
  113. {
  114. Atlas = merAddInfo.StoreEntrancePic.Split(',');
  115. }
  116. Obj.Add("Atlas", Atlas); //图集
  117. Obj.Add("MerchantName", merInfo.Name); //商户名称
  118. Obj.Add("MerchantShortName", merAddInfo.MerchantShortname); //商户简称
  119. Obj.Add("Popularity", merInfo.Popularity); //人气值
  120. Obj.Add("BusinessName", BusinessName); //经营类型
  121. Obj.Add("BusinessHours", merInfo.BusinessHours == null ? "周一至周日 09:00-22:00" : "周一至周日 09:00 - 22:00"); //营业时间
  122. Obj.Add("MerchantMobile", merInfo.Mobile); //商户电话
  123. Obj.Add("Introduction", merInfo.BriefIntroduction == null ? "暂无信息" : "暂无信息"); //商户简介
  124. Obj.Add("Longitude", merInfo.Longitude); //经度
  125. Obj.Add("Latitude", merInfo.Latitude); //纬度
  126. Obj.Add("StoreEntrancePic", Atlas[0]); //门店门头照片
  127. Obj.Add("BizStoreAddress", (merInfo.Areas + merInfo.Address).Replace(",", "")); //门店地址
  128. }
  129. if (Kind == 2)
  130. {
  131. var merAddInfo = Services.Main2.MerchantAddInfoService.Query(Id);
  132. var merInfo = Services.Main2.MerchantInfoService.Query(Id);
  133. var info = maindb2.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MainModels2.MerchantInfo();
  134. info.Popularity += 1;
  135. maindb2.SaveChanges();
  136. BusinessName = Services.Main2.BusinessScopeService.Query(int.Parse(merAddInfo.BusinessId)).Name;
  137. string[] Atlas = new string[0];
  138. if (!string.IsNullOrEmpty(merAddInfo.StoreEntrancePic))
  139. {
  140. Atlas = merAddInfo.StoreEntrancePic.Split(',');
  141. }
  142. Obj.Add("Atlas", Atlas); //图集
  143. Obj.Add("MerchantName", merInfo.Name); //商户名称
  144. Obj.Add("MerchantShortName", merAddInfo.MerchantShortname); //商户简称
  145. Obj.Add("Popularity", merInfo.Popularity); //人气值
  146. Obj.Add("BusinessName", BusinessName); //经营类型
  147. Obj.Add("BusinessHours", merInfo.BusinessHours == null ? "周一至周日 09:00-22:00" : "周一至周日 09:00 - 22:00"); //营业时间
  148. Obj.Add("MerchantMobile", merInfo.Mobile); //商户电话
  149. Obj.Add("Introduction", merInfo.BriefIntroduction == null ? "暂无信息" : "暂无信息"); //商户简介
  150. Obj.Add("Longitude", merInfo.Longitude); //经度
  151. Obj.Add("Latitude", merInfo.Latitude); //纬度
  152. Obj.Add("StoreEntrancePic", Atlas[0]); //门店门头照片
  153. Obj.Add("BizStoreAddress", (merInfo.Areas + merInfo.Address).Replace(",", "")); //门店地址
  154. }
  155. return Obj;
  156. }
  157. #endregion
  158. }
  159. }