MerchantInfoController.cs 51 KB

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