MerchantInfoController.cs 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042
  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("Api/v1/[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 TeamPerformanceMerchants(string value)
  25. {
  26. value = DesDecrypt(value);
  27. JsonData data = JsonMapper.ToObject(value);
  28. List<Dictionary<string, object>> dataList = TeamPerformanceMerchantsDo(value);
  29. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  30. }
  31. public List<Dictionary<string, object>> TeamPerformanceMerchantsDo(string value)
  32. {
  33. JsonData data = JsonMapper.ToObject(value);
  34. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  35. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  36. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  37. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  38. List<int> query = MerchantInfoDbconn.Instance.GetList(UserId, PageNum, PageSize);
  39. foreach (int id in query)
  40. {
  41. MerchantInfo subdata = MerchantInfoDbconn.Instance.Get(id) ?? new MerchantInfo();
  42. Dictionary<string, object> curData = new Dictionary<string, object>();
  43. curData.Add("MerchantName", subdata.Name); //商户姓名
  44. curData.Add("Id", subdata.Id); //Id
  45. dataList.Add(curData);
  46. }
  47. return dataList;
  48. }
  49. #endregion
  50. #region 创客-首页-商户签约
  51. [Authorize]
  52. public JsonResult ContractList(string value)
  53. {
  54. value = DesDecrypt(value);
  55. JsonData data = JsonMapper.ToObject(value);
  56. List<Dictionary<string, object>> dataList = ContractListDo(value);
  57. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  58. }
  59. public List<Dictionary<string, object>> ContractListDo(string value)
  60. {
  61. JsonData data = JsonMapper.ToObject(value);
  62. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //所属创客
  63. string Status = data["Status"].ToString(); //签约状态
  64. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  65. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  66. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  67. List<int> query = MerchantInfoDbconn.Instance.GetList(UserId, PageNum, PageSize);
  68. foreach (var id in query)
  69. {
  70. MerchantInfo subdata = MerchantInfoDbconn.Instance.Get(id) ?? new MerchantInfo();
  71. Dictionary<string, object> curData = new Dictionary<string, object>();
  72. curData.Add("Name", subdata.Name); //名称
  73. curData.Add("Id", subdata.Id); //Id
  74. curData.Add("CreateDate", subdata.CreateDate == null ? "" : subdata.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate
  75. curData.Add("Status", ""); //签约状态
  76. curData.Add("MainType", ""); //主体类型
  77. dataList.Add(curData);
  78. }
  79. return dataList;
  80. }
  81. #endregion
  82. #region 创客-首页-商户签约-详情
  83. [Authorize]
  84. public JsonResult ContractDetail(string value)
  85. {
  86. value = DesDecrypt(value);
  87. JsonData data = JsonMapper.ToObject(value);
  88. Dictionary<string, object> Obj = ContractDetailDo(value);
  89. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  90. }
  91. public Dictionary<string, object> ContractDetailDo(string value)
  92. {
  93. JsonData data = JsonMapper.ToObject(value);
  94. Dictionary<string, object> Obj = new Dictionary<string, object>();
  95. MerchantInfo query = new MerchantInfo();
  96. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  97. query = MerchantInfoDbconn.Instance.Get(Id) ?? new MerchantInfo();
  98. Obj.Add("Name", query.Name); //名称
  99. Obj.Add("Status", ""); //签约状态
  100. Obj.Add("Platforms", ""); //品台列表
  101. Obj.Add("CreateDate", query.CreateDate); //创建时间
  102. return Obj;
  103. }
  104. #endregion
  105. #region 创客-首页-我的商户-商户列表
  106. [Authorize]
  107. public JsonResult MyMerchant(string value)
  108. {
  109. value = DesDecrypt(value);
  110. JsonData data = JsonMapper.ToObject(value);
  111. Dictionary<string, object> Other = new Dictionary<string, object>();
  112. List<Dictionary<string, object>> dataList = MyMerchantDo(value, out Other);
  113. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  114. }
  115. public List<Dictionary<string, object>> MyMerchantDo(string value, out Dictionary<string, object> Other)
  116. {
  117. JsonData data = JsonMapper.ToObject(value);
  118. string SearchKey = data["SearchKey"].ToString(); //搜索关键词
  119. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  120. int ActiveStatus = int.Parse(function.CheckInt(data["ActiveStatus"].ToString())); //商户达标状态
  121. int IsAct = int.Parse(function.CheckInt(data["IsAct"].ToString())); //激活状态(1 已激活 2 未激活)
  122. int Kind = int.Parse(function.CheckInt(data["Kind"].ToString()));
  123. string TradeSort = data["TradeSort"].ToString(); //排序
  124. string DateSort = data["DateSort"].ToString(); //排序
  125. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  126. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  127. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  128. IQueryable<MerchantInfo> query = maindb.MerchantInfo.Where(m => m.UserId == UserId && (m.Status == 2 || m.QueryCount == 2));
  129. DateTime today = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00");
  130. if (!string.IsNullOrEmpty(SearchKey))
  131. {
  132. query = query.Where(m => m.Name.Contains(SearchKey));
  133. }
  134. if (Kind > 0)
  135. {
  136. string subjectType = "";
  137. if (Kind == 1) subjectType = "SUBJECT_TYPE_INDIVIDUAL";
  138. if (Kind == 2) subjectType = "SUBJECT_TYPE_ENTERPRISE";
  139. if (Kind == 3) subjectType = "SUBJECT_TYPE_SMALL";
  140. List<int> ids = maindb.MerchantAddInfo.Where(m => m.SubjectType == subjectType).ToList().Select(m => m.Id).ToList();
  141. query = query.Where(m => ids.Contains(m.Id));
  142. }
  143. if (ActiveStatus > 0)
  144. {
  145. if (ActiveStatus == 2) ActiveStatus = 0;
  146. query = query.Where(m => m.ActivationStatus == ActiveStatus);
  147. }
  148. int TotalCount = query.Count();
  149. int IsActNum = query.Count(m => m.IsAct == 1);
  150. int ProductCount = query.Count();
  151. if (IsAct > 0)
  152. {
  153. if (IsAct == 2) IsAct = 0;
  154. query = query.Where(m => m.IsAct == IsAct);
  155. }
  156. int ActCount = query.Count(m => m.ActivationDate == today);
  157. int ProductActCount = query.Count(m => m.ActivationStatus == 1);
  158. int ProductUnActCount = ProductCount - ProductActCount;
  159. int UnActNum = ProductCount - IsActNum;
  160. if (TradeSort == "1")
  161. {
  162. if (DateSort == "1")
  163. {
  164. query = query.OrderBy(m => m.TotalAmount).ThenBy(m => m.CreateDate);
  165. }
  166. else
  167. {
  168. query = query.OrderBy(m => m.TotalAmount).ThenByDescending(m => m.CreateDate);
  169. }
  170. }
  171. else
  172. {
  173. if (DateSort == "1")
  174. {
  175. query = query.OrderByDescending(m => m.TotalAmount).ThenBy(m => m.CreateDate);
  176. }
  177. else
  178. {
  179. query = query.OrderByDescending(m => m.TotalAmount).ThenByDescending(m => m.CreateDate);
  180. }
  181. }
  182. if (PageNum == 1)
  183. {
  184. query = query.Take(PageSize);
  185. }
  186. else
  187. {
  188. int skipNum = PageSize * (PageNum - 1);
  189. query = query.Skip(skipNum).Take(PageSize);
  190. }
  191. foreach (var item in query.ToList())
  192. {
  193. Dictionary<string, object> curData = new Dictionary<string, object>();
  194. curData.Add("MerchantName", item.Name); //商户姓名
  195. curData.Add("KqRegTime", item.CreateDate == null ? "" : item.CreateDate.Value.ToString("yyyy-MM-dd")); //渠道注册时间
  196. curData.Add("Id", item.Id); //Id
  197. curData.Add("TotalAmount", item.TotalAmount.ToString("f2")); //交易额
  198. curData.Add("TodayTrade", MerchantTradeStat.Instance.Amount(item.Id, DateTime.Now.ToString("yyyyMMdd")).ToString("f2")); //今日交易额
  199. curData.Add("TradeCount", item.TotalConsumeCount); //交易笔数
  200. curData.Add("TodayTradeCount", MerchantTradeStat.Instance.Count(item.Id, DateTime.Now.ToString("yyyyMMdd"))); //今日交易笔数
  201. dataList.Add(curData);
  202. }
  203. Other = new Dictionary<string, object>();
  204. Other.Add("TotalCount", TotalCount); //商户数
  205. Other.Add("ActCount", ActCount); //商户达标数
  206. Other.Add("UnActCount", ProductUnActCount); //未达标数
  207. Other.Add("IsActNum", IsActNum); //商户激活数
  208. Other.Add("UnActNum", UnActNum); //商户未激活数
  209. return dataList;
  210. }
  211. #endregion
  212. #region 创客-首页-我的商户-商户详情
  213. [Authorize]
  214. public JsonResult MyMerchantDetail(string value)
  215. {
  216. value = DesDecrypt(value);
  217. JsonData data = JsonMapper.ToObject(value);
  218. Dictionary<string, object> Obj = MyMerchantDetailDo(value);
  219. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  220. }
  221. public Dictionary<string, object> MyMerchantDetailDo(string value)
  222. {
  223. JsonData data = JsonMapper.ToObject(value);
  224. Dictionary<string, object> Obj = new Dictionary<string, object>();
  225. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  226. MerchantInfo merchant = MerchantInfoDbconn.Instance.Get(Id) ?? new MerchantInfo();
  227. MerchantAddInfo addinfo = MerchantAddInfoDbconn.Instance.Get(Id) ?? new MerchantAddInfo();
  228. Obj.Add("Kind", 1); //通道(1 直连 2 银联)
  229. Obj.Add("MerchantName", merchant.Name); //商户名称
  230. Obj.Add("LegalName", addinfo.CertLegalPerson); //企业法人
  231. Obj.Add("MerchantMobile", addinfo.MobilePhone); //商户手机号
  232. Obj.Add("SubjectType", addinfo.SubjectType); //主体类型
  233. Obj.Add("CreateDate", merchant.CreateDate == null ? "" : merchant.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //注册时间
  234. Obj.Add("ActivationDate", merchant.ActivationDate == null ? "" : merchant.ActivationDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //达标时间
  235. Obj.Add("TotalAmount", merchant.TotalAmount.ToString("f2")); //总交易额
  236. Obj.Add("ActivationStatus", merchant.ActivationStatus); //达标状态
  237. Obj.Add("IsAct", merchant.IsAct); //是否激活(0 否 1 是)
  238. if (merchant.IsAct == 1)
  239. {
  240. var orderInfo = maindb.MerchantDepositOrder.FirstOrDefault(m => m.Status > 0 && m.MerchantId == Id) ?? new MerchantDepositOrder();
  241. var IsPay = 0;
  242. if (orderInfo.Id > 0)
  243. {
  244. IsPay = 1;
  245. Obj.Add("IsPay", IsPay); //是否缴纳服务费(0 否 1 是)
  246. Obj.Add("ActDate", orderInfo.UpdateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //激活时间
  247. }
  248. else
  249. {
  250. Obj.Add("IsPay", IsPay); //是否缴纳服务费(0 否 1 是)
  251. Obj.Add("ActDate", ""); //激活时间
  252. }
  253. }
  254. return Obj;
  255. }
  256. #endregion
  257. #region 创客-首页-我的商户-商户详情-交易统计
  258. [Authorize]
  259. public JsonResult MerchantTradeList(string value)
  260. {
  261. value = DesDecrypt(value);
  262. JsonData data = JsonMapper.ToObject(value);
  263. Dictionary<string, object> other = new Dictionary<string, object>();
  264. List<Dictionary<string, object>> dataList = MerchantTradeListDo(value, out other);
  265. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = other });
  266. }
  267. public List<Dictionary<string, object>> MerchantTradeListDo(string value, out Dictionary<string, object> other)
  268. {
  269. JsonData data = JsonMapper.ToObject(value);
  270. string TradeMonth = data["TradeMonth"].ToString(); //交易月
  271. int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString())); //商户Id
  272. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  273. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  274. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  275. string limit = " limit " + PageSize;
  276. if (PageNum > 1)
  277. {
  278. int skipNum = PageSize * (PageNum - 1);
  279. limit = " limit " + skipNum + "," + PageSize;
  280. }
  281. DataTable dt = CustomerSqlConn.dtable("select TradeDate,sum(TradeAmount),sum(TradeCount),sum(if(IsAct=1, TradeAmount, 0)),sum(if(IsAct=0, TradeAmount, 0)) from MerchantAmountSummay where MerchantId=" + MerchantId + " and TradeMonth='" + TradeMonth + "' group by TradeDate order by TradeDate desc" + limit, AppConfig.Base.SqlConnStr);
  282. foreach (DataRow dr in dt.Rows)
  283. {
  284. string TradeDate = dr["TradeDate"].ToString();
  285. Dictionary<string, object> curData = new Dictionary<string, object>();
  286. curData.Add("TradeDate", TradeDate.Substring(0, 4) + "-" + TradeDate.Substring(4, 2) + "-" + TradeDate.Substring(6, 2)); //交易日
  287. curData.Add("TradeAmt", dr[1].ToString()); //交易金额
  288. curData.Add("ActTradeAmt", dr[3].ToString()); //活动交易金额
  289. curData.Add("UnActTradeAmt", dr[4].ToString()); //非活动交易金额
  290. curData.Add("TradeCount", dr[2].ToString()); //交易笔数
  291. dataList.Add(curData);
  292. }
  293. other = new Dictionary<string, object>();
  294. if (PageNum == 1)
  295. {
  296. DataTable total = CustomerSqlConn.dtable("select sum(TradeAmount),sum(TradeCount),sum(if(IsAct=1, TradeAmount, 0)),sum(if(IsAct=0, TradeAmount, 0)) from MerchantAmountSummay where MerchantId=" + MerchantId + " and TradeMonth='" + TradeMonth + "'", AppConfig.Base.SqlConnStr);
  297. decimal TradeAmt = 0;
  298. decimal ActTradeAmt = 0;
  299. decimal UnActTradeAmt = 0;
  300. int TradeCount = 0;
  301. if (total.Rows.Count > 0)
  302. {
  303. TradeAmt = decimal.Parse(function.CheckNum(total.Rows[0][0].ToString())); //交易金额
  304. ActTradeAmt = decimal.Parse(function.CheckNum(total.Rows[0][2].ToString())); //活动交易金额
  305. UnActTradeAmt = decimal.Parse(function.CheckNum(total.Rows[0][3].ToString())); //非活动交易金额
  306. TradeCount = int.Parse(function.CheckNum(total.Rows[0][1].ToString())); //交易笔数
  307. }
  308. other.Add("TradeAmt", TradeAmt.ToString("f2")); //交易金额
  309. other.Add("ActTradeAmt", ActTradeAmt.ToString("f2")); //活动交易金额
  310. other.Add("UnActTradeAmt", UnActTradeAmt.ToString("f2")); //非活动交易金额
  311. other.Add("TradeCount", TradeCount); //交易笔数
  312. }
  313. return dataList;
  314. }
  315. #endregion
  316. #region 创客-首页-我的商户-商户详情-码牌
  317. [Authorize]
  318. public JsonResult QrCodeList(string value)
  319. {
  320. value = DesDecrypt(value);
  321. JsonData data = JsonMapper.ToObject(value);
  322. int TotalCount = 0;
  323. List<Dictionary<string, object>> dataList = QrCodeListDo(value, out TotalCount);
  324. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = TotalCount });
  325. }
  326. public List<Dictionary<string, object>> QrCodeListDo(string value, out int TotalCount)
  327. {
  328. JsonData data = JsonMapper.ToObject(value);
  329. int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString())); //商户Id
  330. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  331. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  332. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  333. IQueryable<MerchantQrCode> query = maindb.MerchantQrCode.Where(m => m.MerchantId == MerchantId && m.QueryCount == 1).OrderByDescending(m => m.Id);
  334. TotalCount = query.Count();
  335. if (PageNum == 1)
  336. {
  337. query = query.Take(PageSize);
  338. }
  339. else
  340. {
  341. int skipNum = PageSize * (PageNum - 1);
  342. query = query.Skip(skipNum).Take(PageSize);
  343. }
  344. foreach (MerchantQrCode item in query.ToList())
  345. {
  346. Dictionary<string, object> curData = new Dictionary<string, object>();
  347. curData.Add("SnNo", item.SnNo); //sn
  348. curData.Add("TradeAmount", QrCodeTradeStat.Instance.Amount(item.SnNo).ToString("f2"));
  349. dataList.Add(curData);
  350. }
  351. return dataList;
  352. }
  353. #endregion
  354. #region 创客-首页-我的商户-商户详情-音响
  355. // [Authorize]
  356. public JsonResult QrCodeList2(string value)
  357. {
  358. value = DesDecrypt(value);
  359. value = value.Replace("null", "\"\"");
  360. JsonData data = JsonMapper.ToObject(value);
  361. int TotalCount = 0;
  362. List<Dictionary<string, object>> dataList = QrCodeList2Do(value, out TotalCount);
  363. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = TotalCount });
  364. }
  365. public List<Dictionary<string, object>> QrCodeList2Do(string value, out int TotalCount)
  366. {
  367. JsonData data = JsonMapper.ToObject(value);
  368. int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString())); //商户Id
  369. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  370. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  371. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  372. IQueryable<MachineForQrCode> query = maindb.MachineForQrCode.Where(m => m.MerchantId == MerchantId && m.DataId.EndsWith("_1") && m.MachineSnNo != m.SnNo && !string.IsNullOrEmpty(m.MachineSnNo)).OrderByDescending(m => m.MerchantId);
  373. TotalCount = query.Count();
  374. if (PageNum == 1)
  375. {
  376. query = query.Take(PageSize);
  377. }
  378. else
  379. {
  380. int skipNum = PageSize * (PageNum - 1);
  381. query = query.Skip(skipNum).Take(PageSize);
  382. }
  383. foreach (MachineForQrCode item in query.ToList())
  384. {
  385. Dictionary<string, object> curData = new Dictionary<string, object>();
  386. curData.Add("SnNo", item.SnNo); //sn
  387. curData.Add("TradeAmount", QrCodeTradeStat.Instance.Amount(item.SnNo).ToString("f2"));
  388. curData.Add("BindTime", item.BindDate == null ? "" : item.BindDate.Value.ToString("yyyy-MM-dd HH:mm:ss"));
  389. dataList.Add(curData);
  390. }
  391. return dataList;
  392. }
  393. #endregion
  394. #region 首页-我的商户-商户搜索
  395. [Authorize]
  396. public JsonResult MerchantSearch(string value)
  397. {
  398. value = DesDecrypt(value);
  399. JsonData data = JsonMapper.ToObject(value);
  400. List<Dictionary<string, object>> dataList = MerchantSearchDo(value);
  401. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  402. }
  403. public List<Dictionary<string, object>> MerchantSearchDo(string value)
  404. {
  405. JsonData data = JsonMapper.ToObject(value);
  406. string SearchKey = data["SearchKey"].ToString(); //搜索关键词
  407. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString()));
  408. // int ProductType = 1; //int.Parse(function.CheckInt(data["ProductType"].ToString()));
  409. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  410. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  411. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  412. IQueryable<MerchantInfo> query = maindb.MerchantInfo.Where(m => m.UserId == UserId);
  413. if (!string.IsNullOrEmpty(SearchKey))
  414. {
  415. query = query.Where(m => m.Name.Contains(SearchKey));
  416. }
  417. if (PageNum == 1)
  418. {
  419. query = query.Take(PageSize);
  420. }
  421. else
  422. {
  423. int skipNum = PageSize * (PageNum - 1);
  424. query = query.Skip(skipNum).Take(PageSize);
  425. }
  426. foreach (var item in query.ToList())
  427. {
  428. MerchantInfo subdata = MerchantInfoDbconn.Instance.Get(item.Id) ?? new MerchantInfo();
  429. Dictionary<string, object> curData = new Dictionary<string, object>();
  430. curData.Add("MerchantName", subdata.Name); //商户姓名
  431. curData.Add("KqRegTime", subdata.CreateDate == null ? "" : subdata.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //渠道注册时间
  432. curData.Add("Id", item.Id); //Id
  433. curData.Add("ThisMonthTrade", item.TotalAmount); //当月交易额
  434. dataList.Add(curData);
  435. }
  436. return dataList;
  437. }
  438. #endregion
  439. #region 创客-首页-进件查询
  440. [Authorize]
  441. public JsonResult MerchantByStatus(string value)
  442. {
  443. value = DesDecrypt(value);
  444. JsonData data = JsonMapper.ToObject(value);
  445. List<Dictionary<string, object>> dataList = MerchantByStatusDo(value);
  446. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  447. }
  448. public List<Dictionary<string, object>> MerchantByStatusDo(string value)
  449. {
  450. JsonData data = JsonMapper.ToObject(value);
  451. string SearchKey = data["SearchKey"].ToString();
  452. int Status = int.Parse(function.CheckInt(data["Status"].ToString()));
  453. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //所属创客
  454. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  455. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  456. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  457. IQueryable<MerchantInfo> query = maindb.MerchantInfo.Where(m => m.UserId == UserId && m.Sort == 1);
  458. if (Status > 0)
  459. {
  460. if (Status == 1) Status = 0;
  461. if (Status == 2) Status = -1;
  462. if (Status == 3) Status = 1;
  463. if (Status == 4) Status = 2;
  464. query = query.Where(m => m.Status == Status);
  465. }
  466. if (!string.IsNullOrEmpty(SearchKey))
  467. {
  468. query = query.Where(m => m.Name.Contains(SearchKey));
  469. }
  470. if (PageNum == 1)
  471. {
  472. query = query.Take(PageSize);
  473. }
  474. else
  475. {
  476. int skipNum = PageSize * (PageNum - 1);
  477. query = query.Skip(skipNum).Take(PageSize);
  478. }
  479. foreach (var subdata in query.ToList())
  480. {
  481. MerchantAddInfo AddInfo = MerchantAddInfoDbconn.Instance.Get(subdata.Id) ?? new MerchantAddInfo();
  482. Dictionary<string, object> curData = new Dictionary<string, object>();
  483. curData.Add("Name", subdata.Name); //名称
  484. curData.Add("Id", subdata.Id); //Id
  485. curData.Add("CreateDate", subdata.CreateDate == null ? "" : subdata.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate
  486. curData.Add("Status", AddInfo.Status); //Status
  487. curData.Add("MainType", AddInfo.SubjectType); //主体类型
  488. dataList.Add(curData);
  489. }
  490. return dataList;
  491. }
  492. #endregion
  493. #region 创客-首页-进件查询-详情
  494. [Authorize]
  495. public JsonResult MerchantDetailByStatus(string value)
  496. {
  497. value = DesDecrypt(value);
  498. JsonData data = JsonMapper.ToObject(value);
  499. Dictionary<string, object> Obj = MerchantDetailByStatusDo(value);
  500. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  501. }
  502. public Dictionary<string, object> MerchantDetailByStatusDo(string value)
  503. {
  504. JsonData data = JsonMapper.ToObject(value);
  505. Dictionary<string, object> Obj = new Dictionary<string, object>();
  506. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  507. MerchantInfo query = MerchantInfoDbconn.Instance.Get(Id) ?? new MerchantInfo();
  508. MerchantAddInfo addInfo = MerchantAddInfoDbconn.Instance.Get(Id) ?? new MerchantAddInfo();
  509. Obj.Add("MerchantChannel", 1); //商户进件渠道(1 直连 2 银联)
  510. Obj.Add("Name", query.Name); //名称
  511. Obj.Add("CreateDate", query.CreateDate == null ? "" : query.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //提交时间
  512. List<Dictionary<string, object>> AuditResult = new List<Dictionary<string, object>>();
  513. Dictionary<string, object> WeChat = new Dictionary<string, object>();
  514. WeChat.Add("Name", "微信");
  515. WeChat.Add("Status", addInfo.Status);
  516. WeChat.Add("DoTime", addInfo.UpdateDate == null ? "" : addInfo.UpdateDate.Value.ToString("yyyy-MM-dd HH:mm:ss"));
  517. WeChat.Add("Season", addInfo.WeChatRemark);
  518. WeChat.Add("SignUrl", addInfo.WeChatSignUrl);
  519. AuditResult.Add(WeChat);
  520. Dictionary<string, object> Alipay = new Dictionary<string, object>();
  521. Alipay.Add("Name", "支付宝");
  522. Alipay.Add("Status", addInfo.QueryCount);
  523. Alipay.Add("DoTime", addInfo.UpdateDate == null ? "" : addInfo.UpdateDate.Value.ToString("yyyy-MM-dd HH:mm:ss"));
  524. Alipay.Add("Season", addInfo.AlipayRemark);
  525. Alipay.Add("SignUrl", function.CheckNull(addInfo.AlipaySignUrl).Replace("\\", ""));
  526. AuditResult.Add(Alipay);
  527. Obj.Add("Status", GetMainStatusName(addInfo.QueryCount, query.Status)); //状态
  528. Obj.Add("AuditResult", AuditResult); //审核结果
  529. Obj.Add("SubjectType", addInfo.SubjectType);
  530. return Obj;
  531. }
  532. #endregion
  533. #region 创客-首页-进件记录-删除
  534. [Authorize]
  535. public JsonResult Delete(string value)
  536. {
  537. value = DesDecrypt(value);
  538. JsonData data = JsonMapper.ToObject(value);
  539. AppResultJson result = DeleteDo(value);
  540. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  541. }
  542. public AppResultJson DeleteDo(string value)
  543. {
  544. JsonData data = JsonMapper.ToObject(value);
  545. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  546. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //所属创客
  547. Dictionary<string, object> Obj = new Dictionary<string, object>();
  548. MerchantInfo edit = maindb.MerchantInfo.FirstOrDefault(m => m.Id == Id && m.UserId == UserId);
  549. if (edit != null)
  550. {
  551. if (edit.Sort == 0 && edit.Status == 0 && edit.QueryCount == 0)
  552. {
  553. maindb.MerchantInfo.Remove(edit);
  554. MerchantAddInfo editadd = maindb.MerchantAddInfo.FirstOrDefault(m => m.Id == Id);
  555. if (editadd != null)
  556. {
  557. maindb.MerchantAddInfo.Remove(editadd);
  558. }
  559. maindb.SaveChanges();
  560. }
  561. else
  562. {
  563. return new AppResultJson() { Status = "-1", Info = "商户已进件签约,暂不支持删除", Data = Obj };
  564. }
  565. }
  566. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  567. }
  568. #endregion
  569. #region 创客-首页-暂存商户
  570. [Authorize]
  571. public JsonResult TmpMerchantList(string value)
  572. {
  573. value = DesDecrypt(value);
  574. JsonData data = JsonMapper.ToObject(value);
  575. List<Dictionary<string, object>> dataList = TmpMerchantListDo(value);
  576. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  577. }
  578. public List<Dictionary<string, object>> TmpMerchantListDo(string value)
  579. {
  580. JsonData data = JsonMapper.ToObject(value);
  581. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //所属创客
  582. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  583. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  584. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  585. IQueryable<MerchantInfo> query = maindb.MerchantInfo.Where(m => m.UserId == UserId && m.Sort == 0);
  586. if (PageNum == 1)
  587. {
  588. query = query.Take(PageSize);
  589. }
  590. else
  591. {
  592. int skipNum = PageSize * (PageNum - 1);
  593. query = query.Skip(skipNum).Take(PageSize);
  594. }
  595. foreach (var subdata in query.ToList())
  596. {
  597. Dictionary<string, object> curData = new Dictionary<string, object>();
  598. curData.Add("Name", subdata.Name); //名称
  599. curData.Add("Id", subdata.Id); //Id
  600. curData.Add("CreateDate", subdata.CreateDate == null ? "" : subdata.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate
  601. curData.Add("SubjectType", 1); //主体类型
  602. dataList.Add(curData);
  603. }
  604. return dataList;
  605. }
  606. #endregion
  607. #region 商户-主界面统计数据
  608. [Authorize]
  609. [Route("/v1/workspace/indexstat")]
  610. public JsonResult IndexStat(string value)
  611. {
  612. value = DesDecrypt(value);
  613. JsonData data = JsonMapper.ToObject(value);
  614. Dictionary<string, object> Obj = IndexStatDo(value);
  615. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  616. }
  617. public Dictionary<string, object> IndexStatDo(string value)
  618. {
  619. JsonData data = JsonMapper.ToObject(value);
  620. string TimeType = data["TimeType"].ToString(); //时间范围
  621. Dictionary<string, object> Obj = new Dictionary<string, object>();
  622. int Id = int.Parse(function.CheckInt(data["MerchantId"].ToString()));
  623. decimal TotalAmount = 0;
  624. decimal TotalOrder = 0;
  625. int TotalUser = 0;
  626. decimal TotalActual = 0;
  627. DateTime Start = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00");
  628. if (TimeType == "1")
  629. {
  630. Start = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00");
  631. }
  632. else if (TimeType == "2")
  633. {
  634. Start = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00").AddDays(-6);
  635. }
  636. else if (TimeType == "3")
  637. {
  638. Start = DateTime.Parse(DateTime.Now.ToString("yyyy-MM") + "-01 00:00:00");
  639. }
  640. while (Start <= DateTime.Now)
  641. {
  642. Dictionary<string, string> dic = new MerchantAmountSummayService().Sum("TradeAmount,TradeCount,TotalActual", " and MerchantId=" + Id + " and TradeDate='" + Start.ToString("yyyyMMdd") + "'");
  643. TotalAmount += decimal.Parse(dic["TradeAmount"]);
  644. TotalOrder += decimal.Parse(dic["TradeCount"]);
  645. // TotalUser += query.TotalUser;
  646. TotalActual += decimal.Parse(dic["TotalActual"]);
  647. Start = Start.AddDays(1);
  648. }
  649. Obj.Add("MerchantChannel", 1); //商户进件渠道(1 直连 2 银联)
  650. Obj.Add("TotalAmount", TotalAmount); //营总收益
  651. Obj.Add("TotalOrder", TotalOrder); //累计订单
  652. Obj.Add("TotalUser", TotalUser); //会员数
  653. Obj.Add("TotalActual", TotalActual); //实收总额
  654. MerchantInfo merchant = new MerchantInfoService().Query(Id);
  655. decimal AllocationAmount = merchant.ActMaxAmount - merchant.ActCurrentAmount;
  656. if (AllocationAmount < 0) AllocationAmount = 0;
  657. Obj.Add("AllocationAmount", AllocationAmount); //未分配活动金额
  658. return Obj;
  659. }
  660. #endregion
  661. #region 商户-修改登录密码
  662. [Authorize]
  663. public JsonResult ModifyLoginPwd(string value)
  664. {
  665. value = DesDecrypt(value);
  666. JsonData data = JsonMapper.ToObject(value);
  667. AppResultJson result = ModifyLoginPwdDo(value);
  668. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  669. }
  670. public AppResultJson ModifyLoginPwdDo(string value)
  671. {
  672. JsonData data = JsonMapper.ToObject(value);
  673. string LoginPwd = data["LoginPwd"].ToString(); //登录密码
  674. string NewLoginPwd = data["NewLoginPwd"].ToString(); //新登录密码
  675. Dictionary<string, object> Obj = new Dictionary<string, object>();
  676. MerchantInfo query = new MerchantInfo();
  677. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  678. query = MerchantInfoDbconn.Instance.Get(Id);
  679. if (query != null)
  680. {
  681. query.UpdateDate = DateTime.Now; //修改时间
  682. query.LoginPwd = LoginPwd; //登录密码
  683. }
  684. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  685. }
  686. #endregion
  687. #region 商户-商户统计数据(个人中心主界面)
  688. [Authorize]
  689. public JsonResult StatData(string value)
  690. {
  691. value = DesDecrypt(value);
  692. JsonData data = JsonMapper.ToObject(value);
  693. Dictionary<string, object> Obj = StatDataDo(value);
  694. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  695. }
  696. public Dictionary<string, object> StatDataDo(string value)
  697. {
  698. JsonData data = JsonMapper.ToObject(value);
  699. Dictionary<string, object> Obj = new Dictionary<string, object>();
  700. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  701. MerchantInfo query = MerchantInfoDbconn.Instance.Get(Id) ?? new MerchantInfo();
  702. Obj.Add("Name", query.Name); //名称
  703. Obj.Add("TotalAmount", query.TotalAmount.ToString("f2")); //营收总金额
  704. Obj.Add("TotalActual", query.TotalActual.ToString("f2")); //实收总金额
  705. Obj.Add("TotalOrder", query.TotalConsumeCount); //累计订单
  706. Obj.Add("TotalCustomer", query.TotalCustomer); //累计客户
  707. Obj.Add("Logo", DefaultPic(query.Logo)); //Logo图片
  708. int ConsumeCount = 0;
  709. decimal WeChatTotal = 0;
  710. decimal AlipayTotal = 0;
  711. for (int i = 0; i < 7; i++)
  712. {
  713. string Date = DateTime.Now.AddDays(-i).ToString("yyyyMMdd");
  714. // ConsumeCount += 0;
  715. WeChatTotal += MerchantAmountSummary.Instance.GetActualTradeByMode(Id, 2, Date);
  716. AlipayTotal += MerchantAmountSummary.Instance.GetActualTradeByMode(Id, 1, Date);
  717. }
  718. Obj.Add("SevenDayConsumer", ConsumeCount); //近7日新增会员
  719. Obj.Add("WeChatTotal", WeChatTotal.ToString("f2")); //微信实收
  720. Obj.Add("AlipayTotal", AlipayTotal.ToString("f2")); //支付宝实收
  721. Obj.Add("CreateDate", query.CreateDate == null ? "" : query.CreateDate.Value.ToString("yyyy-MM-dd"));
  722. string yesterday = DateTime.Now.AddDays(-1).ToString("yyyyMMdd");
  723. // Obj.Add("YesterDayActual", decimal.Parse(function.CheckNum(UserTradeDbconn.Instance.GetTrade(Id, yesterday, "InFactAmount")["InFactAmount"].ToString())).ToString("f2")); //昨日收入
  724. Obj.Add("YesterDayActual", decimal.Parse(new MerchantAmountSummayService().Sum("TotalActual", " and MerchantId=" + Id + " and TradeDate='" + yesterday + "'")["TotalActual"]).ToString("f2")); //昨日收入
  725. Obj.Add("SettleAmount", ""); //待结算金额
  726. return Obj;
  727. }
  728. #endregion
  729. #region 商户-商户详情
  730. [Authorize]
  731. public JsonResult Detail(string value)
  732. {
  733. value = DesDecrypt(value);
  734. JsonData data = JsonMapper.ToObject(value);
  735. Dictionary<string, object> Obj = DetailDo(value);
  736. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  737. }
  738. public Dictionary<string, object> DetailDo(string value)
  739. {
  740. JsonData data = JsonMapper.ToObject(value);
  741. Dictionary<string, object> Obj = new Dictionary<string, object>();
  742. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  743. MerchantInfo query = MerchantInfoDbconn.Instance.Get(Id) ?? new MerchantInfo();
  744. MerchantAddInfo merchantAddInfo = maindb.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  745. Obj.Add("Kind", 1); //通道(1 直连 2 银联)
  746. Obj.Add("Name", query.Name); //名称
  747. Obj.Add("Mobile", query.Mobile); //手机号
  748. Obj.Add("IsAuth", query.IsAuth); //是否认证
  749. Obj.Add("Logo", DefaultPic(query.Logo)); //Logo图片
  750. Obj.Add("Status", GetMainStatusName(merchantAddInfo.QueryCount, merchantAddInfo.Status));
  751. Obj.Add("AlipayStatus", merchantAddInfo.QueryCount);
  752. Obj.Add("WeChatStatus", merchantAddInfo.Status);
  753. Obj.Add("CreateDate", query.CreateDate == null ? "" : query.CreateDate.Value.ToString("yyyy-MM-dd"));
  754. Obj.Add("IsAct", query.IsAct); //是否激活(0 否 1 是)
  755. if (query.IsAct == 1)
  756. {
  757. var orderInfo = maindb.MerchantDepositOrder.FirstOrDefault(m => m.Status > 0 && m.MerchantId == Id) ?? new MerchantDepositOrder();
  758. var IsPay = 0;
  759. if (orderInfo.Id > 0)
  760. {
  761. IsPay = 1;
  762. }
  763. Obj.Add("IsPay", IsPay); //是否缴纳服务费(0 否 1 是)
  764. }
  765. return Obj;
  766. }
  767. private string GetMainStatusName(int AlipayStatus, int WeChatStatus)
  768. {
  769. if (AlipayStatus == 0 && WeChatStatus == 0) return "待审核";
  770. if (AlipayStatus == 0 && WeChatStatus == -1) return "部分未通过";
  771. if (AlipayStatus == -1 && WeChatStatus == 0) return "部分未通过";
  772. if (AlipayStatus == 0 && WeChatStatus == 1) return "部分待签约";
  773. if (AlipayStatus == 1 && WeChatStatus == 0) return "部分待签约";
  774. if (AlipayStatus == 0 && WeChatStatus == 2) return "部分已通过";
  775. if (AlipayStatus == 2 && WeChatStatus == 0) return "部分已通过";
  776. if (AlipayStatus == -1 && WeChatStatus == -1) return "审核未通过";
  777. if (AlipayStatus == -1 && WeChatStatus == 1) return "部分未通过";
  778. if (AlipayStatus == 1 && WeChatStatus == -1) return "部分未通过";
  779. if (AlipayStatus == -1 && WeChatStatus == 2) return "部分未通过";
  780. if (AlipayStatus == 2 && WeChatStatus == -1) return "部分未通过";
  781. if (AlipayStatus == 1 && WeChatStatus == 1) return "待签约";
  782. if (AlipayStatus == 1 && WeChatStatus == 2) return "部分待签约";
  783. if (AlipayStatus == 2 && WeChatStatus == 1) return "部分待签约";
  784. if (AlipayStatus == 2 && WeChatStatus == 2) return "已通过";
  785. return "";
  786. }
  787. private string GetStatusName(int WeChatStatus)
  788. {
  789. if (WeChatStatus == -1) return "审核未通过";
  790. if (WeChatStatus == 0) return "待审核";
  791. if (WeChatStatus == 1) return "待签约";
  792. if (WeChatStatus == 2) return "已通过";
  793. return "";
  794. }
  795. #endregion
  796. #region 商户-通过sn获取商户详情
  797. [Authorize]
  798. public JsonResult DetailBySn(string value)
  799. {
  800. if (string.IsNullOrEmpty(value))
  801. {
  802. System.IO.StreamReader sr = new System.IO.StreamReader(Request.Body);
  803. value = sr.ReadToEnd();
  804. value = value.Split('=')[1];
  805. }
  806. value = DesDecrypt(value);
  807. JsonData data = JsonMapper.ToObject(value);
  808. Dictionary<string, object> Obj = DetailBySnDo(value);
  809. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  810. }
  811. public Dictionary<string, object> DetailBySnDo(string value)
  812. {
  813. function.WriteLog(value, "商户-通过sn获取商户详情");
  814. JsonData data = JsonMapper.ToObject(value);
  815. Dictionary<string, object> Obj = new Dictionary<string, object>();
  816. string Sn = data["Sn"].ToString();
  817. string Machine = data["Machine"].ToString();
  818. if (Sn.Length > 20)
  819. {
  820. Sn = System.Web.HttpUtility.UrlDecode(Sn);
  821. if (!Sn.EndsWith("="))
  822. {
  823. Sn += "=";
  824. }
  825. Sn = dbconn.Decrypt3DES(Sn, "l2k0b2#3");
  826. Sn = Sn.TrimEnd('\0');
  827. Sn = Sn.Substring(0, Sn.Length - 8);
  828. }
  829. if (Machine == Sn)
  830. {
  831. MerchantQrCode code = new MerchantQrCodeService().Query(Sn);
  832. MerchantInfo query = new MerchantInfoService().Query(code.MerchantId);
  833. MerchantParamSet set = new MerchantParamSetService().Query(code.MerchantId);
  834. Obj.Add("Kind", 1); //通道(1 直连 2 银联)
  835. Obj.Add("Name", query.Name); //名称
  836. Obj.Add("Mobile", query.Mobile); //手机号
  837. Obj.Add("IsAuth", query.IsAuth); //是否认证
  838. Obj.Add("Logo", DefaultPic(query.Logo)); //Logo图片
  839. Obj.Add("DiviPercent", set.IsAll == 1 ? 0M : set.DiviPercent);
  840. Obj.Add("MinPayMoney", set.MinPayMoney);
  841. Obj.Add("IsAct", query.IsAct); //是否激活(0 否 1 是)
  842. }
  843. else
  844. {
  845. PosMachines machine = new PosMachinesService().Query(Sn);
  846. MainModels2.MerchantInfo query = new MerchantInfo2Service().Query(machine.BindMerchantId);
  847. MainModels2.MerchantParamSet set = new MerchantParamSet2Service().Query(machine.BindMerchantId);
  848. Obj.Add("Name", query.Name); //名称
  849. Obj.Add("Mobile", query.Mobile); //手机号
  850. Obj.Add("IsAuth", query.IsAuth); //是否认证
  851. Obj.Add("Logo", DefaultPic(query.Logo)); //Logo图片
  852. Obj.Add("DiviPercent", set.IsAll == 1 ? 0M : set.DiviPercent);
  853. Obj.Add("MinPayMoney", set.MinPayMoney);
  854. Obj.Add("IsAct", query.IsAct); //是否激活(0 否 1 是)
  855. }
  856. return Obj;
  857. }
  858. #endregion
  859. #region 商户-忘记密码
  860. // [Authorize]
  861. public JsonResult ForgetPwd(string value)
  862. {
  863. value = DesDecrypt(value);
  864. JsonData data = JsonMapper.ToObject(value);
  865. AppResultJson result = ForgetPwdDo(value);
  866. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  867. }
  868. public AppResultJson ForgetPwdDo(string value)
  869. {
  870. JsonData data = JsonMapper.ToObject(value);
  871. string Mobile = data["Mobile"].ToString(); //手机号
  872. string LoginPwd = data["LoginPwd"].ToString(); //登录密码
  873. string MobileCode = data["MobileCode"].ToString(); //短信验证码
  874. if (string.IsNullOrEmpty(data["Mobile"].ToString()))
  875. {
  876. return new AppResultJson() { Status = "-1", Info = "请填写手机号" };
  877. }
  878. if (data["Mobile"].ToString().Length > 11)
  879. {
  880. return new AppResultJson() { Status = "-1", Info = "手机号最多11个字符" };
  881. }
  882. // MobileCodeCheck mobilecheck = RedisDbconn.Instance.Get<MobileCodeCheck>("MobileCodeCheck:" + Mobile);
  883. // if (mobilecheck == null)
  884. // {
  885. // return new AppResultJson() { Status = "-1", Info = "短信验证码不正确" };
  886. // }
  887. // if (mobilecheck.CheckCode != MobileCode)
  888. // {
  889. // return new AppResultJson() { Status = "-1", Info = "短信验证码不正确" };
  890. // }
  891. // RedisDbconn.Instance.Clear("MobileCodeCheck:" + Mobile);
  892. Dictionary<string, object> Obj = new Dictionary<string, object>();
  893. // MerchantForMobile find = new MerchantForMobileService().Query(Mobile);
  894. // if (find == null)
  895. // {
  896. // return new AppResultJson() { Status = "-1", Info = "手机号不正确" };
  897. // }
  898. // MerchantInfo query = maindb.MerchantInfo.FirstOrDefault(m => m.Id == find.MerchantId);
  899. // if (query != null)
  900. // {
  901. // query.LoginPwd = function.MD532(LoginPwd); //登录密码
  902. // maindb.SaveChanges();
  903. // }
  904. MerchantLoginInfo query = maindb.MerchantLoginInfo.FirstOrDefault(m => m.LoginMobile == Mobile);
  905. if (query == null)
  906. {
  907. return new AppResultJson() { Status = "-1", Info = "手机号不正确" };
  908. }
  909. query.LoginPwd = function.MD532(LoginPwd); //登录密码
  910. maindb.SaveChanges();
  911. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  912. }
  913. #endregion
  914. #region 商户-登录
  915. // [Authorize]
  916. public JsonResult Login(string value)
  917. {
  918. value = DesDecrypt(value);
  919. JsonData data = JsonMapper.ToObject(value);
  920. string Mobile = data["Mobile"].ToString(); //手机号
  921. string LoginPwd = data["LoginPwd"].ToString(); //登录密码
  922. Dictionary<string, object> Obj = new Dictionary<string, object>();
  923. if (Mobile == "13802211996")
  924. {
  925. if (LoginPwd != "kxs2022")
  926. {
  927. return Json(new AppResultJson() { Status = "-1", Info = "登录密码不正确" });
  928. }
  929. Obj.Add("Id", 1);
  930. Obj.Add("Token", PublicFunction.AppToken(1, JwtSecret, JwtIss, "merchant"));
  931. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  932. }
  933. MerchantLoginInfo query = new MerchantLoginInfoService().Query(Mobile, function.MD532(LoginPwd));
  934. if (query.Id == 0)
  935. {
  936. return Json(new AppResultJson() { Status = "-1", Info = "手机号或登录密码不正确" });
  937. }
  938. Obj.Add("Id", query.Id); //Id
  939. Obj.Add("Token", PublicFunction.AppToken(query.Id, JwtSecret, JwtIss, "merchant"));
  940. Obj.Add("MerchantList", new MerchantAccountLinkInfoService().List(query.Id));
  941. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  942. }
  943. #endregion
  944. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  945. /// <summary>
  946. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  947. /// </summary>
  948. /// <param name="value">请求的参数(json字符串)</param>
  949. /// <param name="signField">要签名的字段</param>
  950. /// <returns></returns>
  951. private string CheckSign(string value, string[] signField)
  952. {
  953. JsonData json = JsonMapper.ToObject(value);
  954. Dictionary<string, string> dic = new Dictionary<string, string>();
  955. for (int i = 0; i < signField.Length; i++)
  956. {
  957. dic.Add(signField[i], json[signField[i]].ToString());
  958. }
  959. string sign = json["sign"].ToString(); //客户端签名字符串
  960. return new Sign().sign(dic, sign);
  961. }
  962. #endregion
  963. }
  964. }