MerchantInfoController.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. namespace MySystem.Areas.Api.Controllers.v1
  14. {
  15. [Area("Api")]
  16. [Route("/v1/QrCodePlateMain/[controller]/[action]")]
  17. public class MerchantInfoController : BaseController
  18. {
  19. public MerchantInfoController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  20. {
  21. }
  22. #region 首页-首页-商户门店信息-列表
  23. [Authorize]
  24. public JsonResult MerchantInfoList(string value)
  25. {
  26. value = DesDecrypt(value);
  27. JsonData data = JsonMapper.ToObject(value);
  28. List<Dictionary<string, object>> dataList = MerchantInfoListDo(value);
  29. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  30. }
  31. private List<Dictionary<string, object>> MerchantInfoListDo(string value)
  32. {
  33. JsonData data = JsonMapper.ToObject(value);
  34. string Area = data["Area"].ToString(); //地区
  35. var Longitude = function.CheckNum(data["Longitude"].ToString()); //经度
  36. var Latitude = function.CheckNum(data["Latitude"].ToString()); //纬度
  37. int Sort = int.Parse(data["Sort"].ToString()); //排序(1 人气值降序 2 距离升序)
  38. int pageSize = int.Parse(function.CheckInt(data["page_size"].ToString()));
  39. int pageNum = int.Parse(function.CheckInt(data["page_num"].ToString()));
  40. string condition = " WHERE 1=1";
  41. if (!string.IsNullOrEmpty(data["Area"].ToString()))
  42. {
  43. condition += " AND s.Area=" + Area;
  44. }
  45. if (!string.IsNullOrEmpty(data["Sort"].ToString()))
  46. {
  47. if (Sort == 1) condition += " AND ORDER BY s.Popularity DESC";
  48. if (Sort == 2) condition += " AND ORDER BY s.distance";
  49. }
  50. string limitString = " LIMIT " + pageSize;
  51. if (pageNum > 1)
  52. {
  53. int skipNum = pageSize * (pageNum - 1);
  54. limitString = " LIMIT " + skipNum + "," + pageSize;
  55. }
  56. condition += limitString;
  57. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  58. 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);
  59. foreach (DataRow dr in dt.Rows)
  60. {
  61. Dictionary<string, object> curData = new Dictionary<string, object>();
  62. var Kind = int.Parse(dr["Kind"].ToString()); //商户类型(1 直连 2 银联)
  63. string[] StoreEntrancePic = dr["StoreEntrancePic"].ToString().Split(',');
  64. curData.Add("Kind", Kind); //商户类型(1 直连 2 银联)
  65. curData.Add("StoreEntrancePic", StoreEntrancePic[0]); //门店门头照片
  66. curData.Add("BizStoreAddress", dr["Areas"].ToString() + dr["Address"].ToString()); //门店地址
  67. curData.Add("Popularity", dr["Popularity"].ToString()); //人气值
  68. curData.Add("Distance", dr["distance"].ToString()); //距离
  69. }
  70. return dataList;
  71. }
  72. #endregion
  73. #region 首页-首页-商户门店信息-详情
  74. // [Authorize]
  75. public JsonResult MerchantInfoDetail(string value)
  76. {
  77. value = DesDecrypt(value);
  78. JsonData data = JsonMapper.ToObject(value);
  79. Dictionary<string, object> Obj = MerchantInfoDetailDo(value);
  80. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  81. }
  82. private Dictionary<string, object> MerchantInfoDetailDo(string value)
  83. {
  84. JsonData data = JsonMapper.ToObject(value);
  85. int Id = int.Parse(data["Id"].ToString()); //商户Id
  86. int Kind = int.Parse(data["Kind"].ToString()); //商户类型(1 直连 2 银联)
  87. MerchantAddInfo merAddInfo = new MerchantAddInfo();
  88. MerchantInfo merInfo = new MerchantInfo();
  89. if (Kind == 1)
  90. {
  91. merAddInfo = Services.Main.MerchantAddInfoService.Query(Id);
  92. merInfo = Services.Main.MerchantInfoService.Query(Id);
  93. }
  94. if (Kind == 2)
  95. {
  96. merAddInfo = Services.Main.MerchantAddInfoService.Query(Id);
  97. merInfo = Services.Main.MerchantInfoService.Query(Id);
  98. }
  99. Dictionary<string, object> Obj = new Dictionary<string, object>();
  100. var Atlas = merAddInfo.StoreEntrancePic.Split(',');
  101. Obj.Add("Atlas", Atlas); //图集
  102. Obj.Add("BusinessHours", merInfo.BusinessHours == null ? "周一至周五 09:00-22:00" : "周一至周五 09:00 - 22:00"); //营业时间
  103. Obj.Add("MerchantMobile", merInfo.Mobile); //商户电话
  104. Obj.Add("Introduction", merInfo.BriefIntroduction == null ? "暂无..." : "暂无..."); //商户简介
  105. Obj.Add("Longitude", merInfo.Longitude); //经度
  106. Obj.Add("Latitude", merInfo.Latitude); //纬度
  107. Obj.Add("StoreEntrancePic", merAddInfo.StoreEntrancePic); //门店门头照片
  108. Obj.Add("BizStoreAddress", merInfo.Areas + merInfo.Address); //门店地址
  109. return Obj;
  110. }
  111. #endregion
  112. }
  113. }