MerchantInfoController.cs 49 KB

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