123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Data;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Options;
- using Microsoft.AspNetCore.Authorization;
- using MySystem.MainModels;
- using MySystem.Services;
- using LitJson;
- using Library;
- namespace MySystem.Areas.Api.Controllers.v1
- {
- [Area("Api")]
- [Route("/v1/QrCodePlateMain/[controller]/[action]")]
- public class MerchantInfoController : BaseController
- {
- public MerchantInfoController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
- {
- }
- #region 首页-首页-商户门店信息-列表
- // [Authorize]
- public JsonResult MerchantInfoList(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- Dictionary<string, object> Other = new Dictionary<string, object>();
- List<Dictionary<string, object>> dataList = MerchantInfoListDo(value, out Other);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
- }
- private List<Dictionary<string, object>> MerchantInfoListDo(string value, out Dictionary<string, object> Other)
- {
- JsonData data = JsonMapper.ToObject(value);
- string Area = data["Area"].ToString(); //地区
- var Longitude = function.CheckNum(data["Longitude"].ToString()); //经度
- var Latitude = function.CheckNum(data["Latitude"].ToString()); //纬度
- string SearchKey = data["SearchKey"].ToString(); //搜索关键词
- int Sort = int.Parse(data["Sort"].ToString()); //排序(1 人气值降序 2 距离升序)
- int pageSize = int.Parse(function.CheckInt(data["page_size"].ToString()));
- int pageNum = int.Parse(function.CheckInt(data["page_num"].ToString()));
- string condition = " WHERE 1=1";
- if (!string.IsNullOrEmpty(data["Area"].ToString()))
- {
- condition += " AND s.Areas like '%" + Area + "%'";
- }
- if (!string.IsNullOrEmpty(data["Sort"].ToString()))
- {
- if (Sort == 1) condition += " ORDER BY s.Popularity DESC";
- if (Sort == 2) condition += " ORDER BY s.distance";
- }
- if (!string.IsNullOrEmpty(data["SearchKey"].ToString()))
- {
- condition += " AND s.Name like '%" + SearchKey + "%'";
- }
- string limitString = " LIMIT " + pageSize;
- if (pageNum > 1)
- {
- int skipNum = pageSize * (pageNum - 1);
- limitString = " LIMIT " + skipNum + "," + pageSize;
- }
- condition += limitString;
- List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
- 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);
- foreach (DataRow dr in dt.Rows)
- {
- Dictionary<string, object> curData = new Dictionary<string, object>();
- var Kind = int.Parse(dr["Kind"].ToString()); //商户类型(1 直连 2 银联)
- string[] StoreEntrancePic = dr["StoreEntrancePic"].ToString().Split(',');
- curData.Add("Id", int.Parse(dr["Id"].ToString())); //商户Id
- curData.Add("Kind", Kind); //商户类型(1 直连 2 银联)
- curData.Add("MerchantName", dr["Name"].ToString()); //商户名称
- curData.Add("MerchantShortName", dr["MerchantShortname"].ToString()); //商户简称
- curData.Add("BusinessName", dr["BusinessName"].ToString()); //经营类型
- curData.Add("StoreEntrancePic", StoreEntrancePic[0]); //门店门头照片
- curData.Add("BizStoreAddress", (dr["Areas"].ToString() + dr["Address"].ToString()).Replace(",", "")); //门店地址
- curData.Add("Popularity", dr["Popularity"].ToString()); //人气值
- curData.Add("Distance", decimal.Parse(dr["distance"].ToString()).ToString("F2")); //距离
- dataList.Add(curData);
- }
- Other = new Dictionary<string, object>();
- Other.Add("count", dt.Rows.Count);
- return dataList;
- }
- #endregion
- #region 首页-首页-商户门店信息-详情
- // [Authorize]
- public JsonResult MerchantInfoDetail(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- Dictionary<string, object> Obj = MerchantInfoDetailDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
- }
- private Dictionary<string, object> MerchantInfoDetailDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- int Id = int.Parse(data["Id"].ToString()); //商户Id
- int Kind = int.Parse(data["Kind"].ToString()); //商户类型(1 直连 2 银联)
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- var BusinessName = "";
- if (Kind == 1)
- {
- var merAddInfo = Services.Main.MerchantAddInfoService.Query(Id);
- var merInfo = Services.Main.MerchantInfoService.Query(Id);
- var info = maindb.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MainModels.MerchantInfo();
- info.Popularity += 1;
- maindb.SaveChanges();
- BusinessName = merAddInfo.QualificationType;
- string[] Atlas = new string[0];
- if (!string.IsNullOrEmpty(merAddInfo.StoreEntrancePic))
- {
- Atlas = merAddInfo.StoreEntrancePic.Split(',');
- }
- Obj.Add("Atlas", Atlas); //图集
- Obj.Add("MerchantName", merInfo.Name); //商户名称
- Obj.Add("MerchantShortName", merAddInfo.MerchantShortname); //商户简称
- Obj.Add("Popularity", merInfo.Popularity); //人气值
- Obj.Add("BusinessName", BusinessName); //经营类型
- Obj.Add("BusinessHours", merInfo.BusinessHours == null ? "周一至周日 09:00-22:00" : "周一至周日 09:00 - 22:00"); //营业时间
- Obj.Add("MerchantMobile", merInfo.Mobile); //商户电话
- Obj.Add("Introduction", merInfo.BriefIntroduction == null ? "暂无信息" : "暂无信息"); //商户简介
- Obj.Add("Longitude", merInfo.Longitude); //经度
- Obj.Add("Latitude", merInfo.Latitude); //纬度
- Obj.Add("StoreEntrancePic", Atlas[0]); //门店门头照片
- Obj.Add("BizStoreAddress", (merInfo.Areas + merInfo.Address).Replace(",", "")); //门店地址
- }
- if (Kind == 2)
- {
- var merAddInfo = Services.Main2.MerchantAddInfoService.Query(Id);
- var merInfo = Services.Main2.MerchantInfoService.Query(Id);
- var info = maindb2.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MainModels2.MerchantInfo();
- info.Popularity += 1;
- maindb2.SaveChanges();
- BusinessName = Services.Main2.BusinessScopeService.Query(int.Parse(merAddInfo.BusinessId)).Name;
- string[] Atlas = new string[0];
- if (!string.IsNullOrEmpty(merAddInfo.StoreEntrancePic))
- {
- Atlas = merAddInfo.StoreEntrancePic.Split(',');
- }
- Obj.Add("Atlas", Atlas); //图集
- Obj.Add("MerchantName", merInfo.Name); //商户名称
- Obj.Add("MerchantShortName", merAddInfo.MerchantShortname); //商户简称
- Obj.Add("Popularity", merInfo.Popularity); //人气值
- Obj.Add("BusinessName", BusinessName); //经营类型
- Obj.Add("BusinessHours", merInfo.BusinessHours == null ? "周一至周日 09:00-22:00" : "周一至周日 09:00 - 22:00"); //营业时间
- Obj.Add("MerchantMobile", merInfo.Mobile); //商户电话
- Obj.Add("Introduction", merInfo.BriefIntroduction == null ? "暂无信息" : "暂无信息"); //商户简介
- Obj.Add("Longitude", merInfo.Longitude); //经度
- Obj.Add("Latitude", merInfo.Latitude); //纬度
- Obj.Add("StoreEntrancePic", Atlas[0]); //门店门头照片
- Obj.Add("BizStoreAddress", (merInfo.Areas + merInfo.Address).Replace(",", "")); //门店地址
- }
- return Obj;
- }
- #endregion
- }
- }
|