MerchantInfoController.cs 50 KB

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