MerchantInfoController.cs 49 KB

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