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