MerchantInfoController.cs 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.Extensions.Logging;
  7. using Microsoft.Extensions.Options;
  8. using Microsoft.AspNetCore.Authorization;
  9. using MySystem.MainModels;
  10. using LitJson;
  11. using Library;
  12. namespace MySystem.Areas.Api.Controllers.v1
  13. {
  14. [Area("Api")]
  15. [Route("Api/v1/[controller]/[action]")]
  16. public class MerchantInfoController : BaseController
  17. {
  18. public MerchantInfoController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  19. {
  20. }
  21. #region 首页-快联盟产品-我的业绩-团队业绩-商户列表
  22. [Authorize]
  23. public JsonResult TeamPerformanceMerchants(string value)
  24. {
  25. value = DesDecrypt(value);
  26. JsonData data = JsonMapper.ToObject(value);
  27. List<Dictionary<string, object>> dataList = TeamPerformanceMerchantsDo(value);
  28. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  29. }
  30. public List<Dictionary<string, object>> TeamPerformanceMerchantsDo(string value)
  31. {
  32. JsonData data = JsonMapper.ToObject(value);
  33. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  34. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  35. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  36. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  37. List<int> query = MerchantInfoDbconn.Instance.GetList(UserId, PageNum, PageSize);
  38. foreach (int id in query)
  39. {
  40. MerchantInfo subdata = MerchantInfoDbconn.Instance.Get(id) ?? new MerchantInfo();
  41. Dictionary<string, object> curData = new Dictionary<string, object>();
  42. curData.Add("MerchantName", subdata.Name); //商户姓名
  43. curData.Add("Id", subdata.Id); //Id
  44. dataList.Add(curData);
  45. }
  46. return dataList;
  47. }
  48. #endregion
  49. #region 创客-首页-商户签约
  50. [Authorize]
  51. public JsonResult ContractList(string value)
  52. {
  53. value = DesDecrypt(value);
  54. JsonData data = JsonMapper.ToObject(value);
  55. List<Dictionary<string, object>> dataList = ContractListDo(value);
  56. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  57. }
  58. public List<Dictionary<string, object>> ContractListDo(string value)
  59. {
  60. JsonData data = JsonMapper.ToObject(value);
  61. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //所属创客
  62. string Status = data["Status"].ToString(); //签约状态
  63. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  64. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  65. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  66. List<int> query = MerchantInfoDbconn.Instance.GetList(UserId, PageNum, PageSize);
  67. foreach (var id in query)
  68. {
  69. MerchantInfo subdata = MerchantInfoDbconn.Instance.Get(id) ?? new MerchantInfo();
  70. Dictionary<string, object> curData = new Dictionary<string, object>();
  71. curData.Add("Name", subdata.Name); //名称
  72. curData.Add("Id", subdata.Id); //Id
  73. curData.Add("CreateDate", subdata.CreateDate == null ? "" : subdata.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate
  74. curData.Add("Status", ""); //签约状态
  75. curData.Add("MainType", ""); //主体类型
  76. dataList.Add(curData);
  77. }
  78. return dataList;
  79. }
  80. #endregion
  81. #region 创客-首页-商户签约-详情
  82. [Authorize]
  83. public JsonResult ContractDetail(string value)
  84. {
  85. value = DesDecrypt(value);
  86. JsonData data = JsonMapper.ToObject(value);
  87. Dictionary<string, object> Obj = ContractDetailDo(value);
  88. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  89. }
  90. public Dictionary<string, object> ContractDetailDo(string value)
  91. {
  92. JsonData data = JsonMapper.ToObject(value);
  93. Dictionary<string, object> Obj = new Dictionary<string, object>();
  94. MerchantInfo query = new MerchantInfo();
  95. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  96. query = MerchantInfoDbconn.Instance.Get(Id) ?? new MerchantInfo();
  97. Obj.Add("Name", query.Name); //名称
  98. Obj.Add("Status", ""); //签约状态
  99. Obj.Add("Platforms", ""); //品台列表
  100. Obj.Add("CreateDate", query.CreateDate); //创建时间
  101. return Obj;
  102. }
  103. #endregion
  104. #region 创客-首页-我的商户-商户列表
  105. [Authorize]
  106. public JsonResult MyMerchant(string value)
  107. {
  108. value = DesDecrypt(value);
  109. JsonData data = JsonMapper.ToObject(value);
  110. Dictionary<string, object> Other = new Dictionary<string, object>();
  111. List<Dictionary<string, object>> dataList = MyMerchantDo(value, out Other);
  112. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  113. }
  114. public List<Dictionary<string, object>> MyMerchantDo(string value, out Dictionary<string, object> Other)
  115. {
  116. JsonData data = JsonMapper.ToObject(value);
  117. string SearchKey = data["SearchKey"].ToString(); //搜索关键词
  118. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //创客
  119. int ActiveStatus = int.Parse(function.CheckInt(data["ActiveStatus"].ToString())); //商户激活状态
  120. int Kind = int.Parse(function.CheckInt(data["Kind"].ToString()));
  121. string Sort = data["Sort"].ToString(); //排序
  122. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  123. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  124. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  125. IQueryable<MerchantInfo> query = maindb.MerchantInfo.Where(m => m.UserId == UserId);
  126. DateTime today = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00");
  127. int TotalCount = query.Count();
  128. int ActCount = query.Count(m => m.ActivationDate == today);
  129. int ProductCount = query.Count();
  130. int ProductActCount = query.Count(m => m.ActivationStatus == 1);
  131. int ProductUnActCount = ProductCount - ProductActCount;
  132. if (!string.IsNullOrEmpty(SearchKey))
  133. {
  134. query = query.Where(m => m.Name.Contains(SearchKey));
  135. }
  136. if (ActiveStatus > 0)
  137. {
  138. if (ActiveStatus == 2) ActiveStatus = 0;
  139. query = query.Where(m => m.ActivationStatus == ActiveStatus);
  140. }
  141. if (Sort == "trade")
  142. {
  143. query = query.OrderByDescending(m => m.TotalAmount);
  144. }
  145. if (Sort == "regdate")
  146. {
  147. query = query.OrderByDescending(m => m.CreateDate);
  148. }
  149. if (PageNum == 1)
  150. {
  151. query = query.Take(PageSize);
  152. }
  153. else
  154. {
  155. int skipNum = PageSize * (PageNum - 1);
  156. query = query.Skip(skipNum).Take(PageSize);
  157. }
  158. foreach (var item in query.ToList())
  159. {
  160. Dictionary<string, object> curData = new Dictionary<string, object>();
  161. curData.Add("MerchantName", item.Name); //商户姓名
  162. curData.Add("KqRegTime", item.CreateDate == null ? "" : item.CreateDate.Value.ToString("yyyy-MM-dd")); //渠道注册时间
  163. curData.Add("Id", item.Id); //Id
  164. curData.Add("TotalAmount", item.TotalAmount); //交易额
  165. curData.Add("TodayTrade", 0); //今日交易额
  166. curData.Add("TradeCount", 0); //交易笔数
  167. curData.Add("TodayTradeCount", 0); //今日交易笔数
  168. dataList.Add(curData);
  169. }
  170. Other = new Dictionary<string, object>();
  171. Other.Add("TotalCount", TotalCount); //商户数
  172. Other.Add("ActCount", ActCount); //商户达标数
  173. Other.Add("UnActCount", ProductUnActCount); //未达标数
  174. return dataList;
  175. }
  176. #endregion
  177. #region 创客-首页-我的商户-商户详情
  178. [Authorize]
  179. public JsonResult MyMerchantDetail(string value)
  180. {
  181. value = DesDecrypt(value);
  182. JsonData data = JsonMapper.ToObject(value);
  183. Dictionary<string, object> Obj = MyMerchantDetailDo(value);
  184. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  185. }
  186. public Dictionary<string, object> MyMerchantDetailDo(string value)
  187. {
  188. JsonData data = JsonMapper.ToObject(value);
  189. Dictionary<string, object> Obj = new Dictionary<string, object>();
  190. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  191. MerchantInfo merchant = MerchantInfoDbconn.Instance.Get(Id) ?? new MerchantInfo();
  192. MerchantAddInfo addinfo = MerchantAddInfoDbconn.Instance.Get(Id) ?? new MerchantAddInfo();
  193. Obj.Add("MerchantName", merchant.Name); //商户名称
  194. Obj.Add("LegalName", addinfo.CertLegalPerson); //企业法人
  195. Obj.Add("MerchantMobile", addinfo.MobilePhone); //商户手机号
  196. Obj.Add("SubjectType", addinfo.SubjectType); //主体类型
  197. Obj.Add("CreateDate", merchant.CreateDate == null ? "" : merchant.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //注册时间
  198. Obj.Add("ActivationDate", merchant.ActivationDate == null ? "" : merchant.ActivationDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //达标时间
  199. Obj.Add("TotalAmount", merchant.TotalAmount); //总交易额
  200. return Obj;
  201. }
  202. #endregion
  203. #region 创客-首页-我的商户-商户详情-交易统计
  204. [Authorize]
  205. public JsonResult MerchantTradeList(string value)
  206. {
  207. value = DesDecrypt(value);
  208. JsonData data = JsonMapper.ToObject(value);
  209. List<Dictionary<string, object>> dataList = MerchantTradeListDo(value);
  210. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  211. }
  212. public List<Dictionary<string, object>> MerchantTradeListDo(string value)
  213. {
  214. JsonData data = JsonMapper.ToObject(value);
  215. string TradeMonth = data["TradeMonth"].ToString(); //交易月
  216. int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString())); //商户Id
  217. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  218. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  219. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  220. IQueryable<PosMerchantTradeSummay> query = maindb.PosMerchantTradeSummay.Where(m => m.MerchantId == MerchantId && m.TradeMonth == TradeMonth).OrderByDescending(m => m.TradeDate);
  221. if (PageNum == 1)
  222. {
  223. query = query.Take(PageSize);
  224. }
  225. else
  226. {
  227. int skipNum = PageSize * (PageNum - 1);
  228. query = query.Skip(skipNum).Take(PageSize);
  229. }
  230. foreach (PosMerchantTradeSummay item in query)
  231. {
  232. Dictionary<string, object> curData = new Dictionary<string, object>();
  233. curData.Add("TradeDate", item.TradeDate); //交易日
  234. curData.Add("TradeAmt", item.TradeAmount); //交易金额
  235. curData.Add("ActTradeAmt", 0); //活动交易金额
  236. curData.Add("UnActTradeAmt", 0); //非活动交易金额
  237. curData.Add("TradeCount", 0); //交易笔数
  238. dataList.Add(curData);
  239. }
  240. return dataList;
  241. }
  242. #endregion
  243. #region 创客-首页-我的商户-商户详情-码牌
  244. [Authorize]
  245. public JsonResult QrCodeList(string value)
  246. {
  247. value = DesDecrypt(value);
  248. JsonData data = JsonMapper.ToObject(value);
  249. List<Dictionary<string, object>> dataList = QrCodeListDo(value);
  250. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  251. }
  252. public List<Dictionary<string, object>> QrCodeListDo(string value)
  253. {
  254. JsonData data = JsonMapper.ToObject(value);
  255. int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString())); //商户Id
  256. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  257. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  258. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  259. IQueryable<MerchantQrCode> query = maindb.MerchantQrCode.Where(m => m.MerchantId == MerchantId).OrderByDescending(m => m.Id);
  260. if (PageNum == 1)
  261. {
  262. query = query.Take(PageSize);
  263. }
  264. else
  265. {
  266. int skipNum = PageSize * (PageNum - 1);
  267. query = query.Skip(skipNum).Take(PageSize);
  268. }
  269. foreach (MerchantQrCode item in query)
  270. {
  271. Dictionary<string, object> curData = new Dictionary<string, object>();
  272. curData.Add("SnNo", item.SnNo); //sn
  273. curData.Add("TradeAmount", 0);
  274. dataList.Add(curData);
  275. }
  276. return dataList;
  277. }
  278. #endregion
  279. #region 首页-我的商户-商户搜索
  280. [Authorize]
  281. public JsonResult MerchantSearch(string value)
  282. {
  283. value = DesDecrypt(value);
  284. JsonData data = JsonMapper.ToObject(value);
  285. List<Dictionary<string, object>> dataList = MerchantSearchDo(value);
  286. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  287. }
  288. public List<Dictionary<string, object>> MerchantSearchDo(string value)
  289. {
  290. JsonData data = JsonMapper.ToObject(value);
  291. string SearchKey = data["SearchKey"].ToString(); //搜索关键词
  292. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString()));
  293. // int ProductType = 1; //int.Parse(function.CheckInt(data["ProductType"].ToString()));
  294. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  295. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  296. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  297. IQueryable<MerchantInfo> query = maindb.MerchantInfo.Where(m => m.UserId == UserId);
  298. if (!string.IsNullOrEmpty(SearchKey))
  299. {
  300. query = query.Where(m => m.Name.Contains(SearchKey));
  301. }
  302. if (PageNum == 1)
  303. {
  304. query = query.Take(PageSize);
  305. }
  306. else
  307. {
  308. int skipNum = PageSize * (PageNum - 1);
  309. query = query.Skip(skipNum).Take(PageSize);
  310. }
  311. foreach (var item in query.ToList())
  312. {
  313. MerchantInfo subdata = MerchantInfoDbconn.Instance.Get(item.Id) ?? new MerchantInfo();
  314. Dictionary<string, object> curData = new Dictionary<string, object>();
  315. curData.Add("MerchantName", subdata.Name); //商户姓名
  316. curData.Add("KqRegTime", subdata.CreateDate == null ? "" : subdata.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //渠道注册时间
  317. curData.Add("Id", item.Id); //Id
  318. curData.Add("ThisMonthTrade", item.TotalAmount); //当月交易额
  319. dataList.Add(curData);
  320. }
  321. return dataList;
  322. }
  323. #endregion
  324. #region 创客-首页-进件查询
  325. [Authorize]
  326. public JsonResult MerchantByStatus(string value)
  327. {
  328. value = DesDecrypt(value);
  329. JsonData data = JsonMapper.ToObject(value);
  330. List<Dictionary<string, object>> dataList = MerchantByStatusDo(value);
  331. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  332. }
  333. public List<Dictionary<string, object>> MerchantByStatusDo(string value)
  334. {
  335. // value = "{\"PageSize\":10,\"PageNum\":1,\"UserId\":\"13\",\"Status\":0,\"SearchKey\":\"\"}";
  336. JsonData data = JsonMapper.ToObject(value);
  337. string SearchKey = data["SearchKey"].ToString();
  338. int Status = int.Parse(function.CheckInt(data["Status"].ToString()));
  339. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //所属创客
  340. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  341. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  342. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  343. IQueryable<MerchantInfo> query = maindb.MerchantInfo.Where(m => m.UserId == UserId && m.QueryCount == 0);
  344. if (Status > 0)
  345. {
  346. if (Status == 1) Status = 0;
  347. if (Status == 2) Status = -1;
  348. if (Status == 3) Status = 1;
  349. if (Status == 3) Status = 2;
  350. query = query.Where(m => m.Status == Status);
  351. }
  352. if (PageNum == 1)
  353. {
  354. query = query.Take(PageSize);
  355. }
  356. else
  357. {
  358. int skipNum = PageSize * (PageNum - 1);
  359. query = query.Skip(skipNum).Take(PageSize);
  360. }
  361. foreach (var subdata in query.ToList())
  362. {
  363. MerchantAddInfo AddInfo = MerchantAddInfoDbconn.Instance.Get(subdata.Id) ?? new MerchantAddInfo();
  364. Dictionary<string, object> curData = new Dictionary<string, object>();
  365. curData.Add("Name", subdata.Name); //名称
  366. curData.Add("Id", subdata.Id); //Id
  367. curData.Add("CreateDate", subdata.CreateDate == null ? "" : subdata.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate
  368. curData.Add("Status", subdata.Status); //Status
  369. curData.Add("MainType", AddInfo.SubjectType); //主体类型
  370. dataList.Add(curData);
  371. }
  372. return dataList;
  373. }
  374. #endregion
  375. #region 创客-首页-进件查询-详情
  376. [Authorize]
  377. public JsonResult MerchantDetailByStatus(string value)
  378. {
  379. value = DesDecrypt(value);
  380. JsonData data = JsonMapper.ToObject(value);
  381. Dictionary<string, object> Obj = MerchantDetailByStatusDo(value);
  382. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  383. }
  384. public Dictionary<string, object> MerchantDetailByStatusDo(string value)
  385. {
  386. JsonData data = JsonMapper.ToObject(value);
  387. Dictionary<string, object> Obj = new Dictionary<string, object>();
  388. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  389. MerchantInfo query = MerchantInfoDbconn.Instance.Get(Id) ?? new MerchantInfo();
  390. MerchantAddInfo addInfo = MerchantAddInfoDbconn.Instance.Get(Id) ?? new MerchantAddInfo();
  391. Obj.Add("Name", query.Name); //名称
  392. Obj.Add("Status", query.Status); //状态
  393. Obj.Add("CreateDate", query.CreateDate == null ? "" : query.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //提交时间
  394. List<Dictionary<string, object>> AuditResult = new List<Dictionary<string, object>>();
  395. Dictionary<string, object> WeChat = new Dictionary<string, object>();
  396. WeChat.Add("Name", "微信");
  397. WeChat.Add("Status", addInfo.Status);
  398. WeChat.Add("DoTime", addInfo.UpdateDate == null ? "" : addInfo.UpdateDate.Value.ToString("yyyy-MM-dd HH:mm:ss"));
  399. if (addInfo.Status == -1)
  400. {
  401. string Season = addInfo.SeoDescription;
  402. Season = Season.Substring(Season.IndexOf("WeChat:") + 7);
  403. Season = Season.Substring(0, Season.LastIndexOf(";"));
  404. WeChat.Add("Season", Season);
  405. }
  406. else
  407. {
  408. WeChat.Add("Season", "");
  409. }
  410. if (addInfo.Status == 1)
  411. {
  412. string SignUrl = addInfo.SeoKeyword;
  413. SignUrl = SignUrl.Substring(SignUrl.IndexOf("WeChat:") + 7);
  414. SignUrl = SignUrl.Substring(0, SignUrl.LastIndexOf(";"));
  415. WeChat.Add("SignUrl", SignUrl);
  416. }
  417. else
  418. {
  419. WeChat.Add("SignUrl", "");
  420. }
  421. AuditResult.Add(WeChat);
  422. Dictionary<string, object> Alipay = new Dictionary<string, object>();
  423. Alipay.Add("Name", "支付宝");
  424. Alipay.Add("Status", addInfo.QueryCount);
  425. Alipay.Add("DoTime", addInfo.UpdateDate == null ? "" : addInfo.UpdateDate.Value.ToString("yyyy-MM-dd HH:mm:ss"));
  426. if (addInfo.QueryCount == -1)
  427. {
  428. string Season = addInfo.SeoDescription;
  429. Season = Season.Substring(Season.IndexOf("Alipay:") + 7);
  430. Season = Season.Substring(0, Season.IndexOf(";"));
  431. Alipay.Add("Season", Season);
  432. }
  433. else
  434. {
  435. Alipay.Add("Season", "");
  436. }
  437. if (addInfo.QueryCount == 1)
  438. {
  439. string SignUrl = addInfo.SeoKeyword;
  440. SignUrl = SignUrl.Substring(SignUrl.IndexOf("Alipay:") + 7);
  441. SignUrl = SignUrl.Substring(0, SignUrl.IndexOf(";"));
  442. Alipay.Add("SignUrl", SignUrl);
  443. }
  444. else
  445. {
  446. Alipay.Add("SignUrl", "");
  447. }
  448. AuditResult.Add(Alipay);
  449. Obj.Add("AuditResult", AuditResult); //审核结果
  450. return Obj;
  451. }
  452. #endregion
  453. #region 创客-首页-进件记录-删除
  454. [Authorize]
  455. public JsonResult Delete(string value)
  456. {
  457. value = DesDecrypt(value);
  458. JsonData data = JsonMapper.ToObject(value);
  459. AppResultJson result = DeleteDo(value);
  460. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  461. }
  462. public AppResultJson DeleteDo(string value)
  463. {
  464. JsonData data = JsonMapper.ToObject(value);
  465. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  466. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //所属创客
  467. Dictionary<string, object> Obj = new Dictionary<string, object>();
  468. MerchantInfo edit = maindb.MerchantInfo.FirstOrDefault(m => m.Id == Id && m.UserId == UserId);
  469. if(edit != null)
  470. {
  471. // maindb.MerchantInfo.Remove(edit);
  472. edit.QueryCount = 0;
  473. maindb.SaveChanges();
  474. }
  475. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  476. }
  477. #endregion
  478. #region 创客-首页-暂存商户
  479. [Authorize]
  480. public JsonResult TmpMerchantList(string value)
  481. {
  482. value = DesDecrypt(value);
  483. JsonData data = JsonMapper.ToObject(value);
  484. List<Dictionary<string, object>> dataList = TmpMerchantListDo(value);
  485. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
  486. }
  487. public List<Dictionary<string, object>> TmpMerchantListDo(string value)
  488. {
  489. JsonData data = JsonMapper.ToObject(value);
  490. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //所属创客
  491. int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
  492. int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
  493. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  494. List<MerchantInfo> query = maindb.MerchantInfo.Where(m => m.UserId == UserId && m.QueryCount == 1).ToList();
  495. foreach (var subdata in query)
  496. {
  497. Dictionary<string, object> curData = new Dictionary<string, object>();
  498. curData.Add("Name", subdata.Name); //名称
  499. curData.Add("Id", subdata.Id); //Id
  500. curData.Add("CreateDate", subdata.CreateDate == null ? "" : subdata.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //CreateDate
  501. curData.Add("SubjectType", 1); //主体类型
  502. dataList.Add(curData);
  503. }
  504. return dataList;
  505. }
  506. #endregion
  507. #region 商户-主界面统计数据
  508. [Authorize]
  509. public JsonResult IndexStat(string value)
  510. {
  511. value = DesDecrypt(value);
  512. JsonData data = JsonMapper.ToObject(value);
  513. Dictionary<string, object> Obj = IndexStatDo(value);
  514. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  515. }
  516. public Dictionary<string, object> IndexStatDo(string value)
  517. {
  518. JsonData data = JsonMapper.ToObject(value);
  519. string TimeType = data["TimeType"].ToString(); //时间范围
  520. Dictionary<string, object> Obj = new Dictionary<string, object>();
  521. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  522. decimal TotalAmount = 0;
  523. decimal TotalOrder = 0;
  524. int TotalUser = 0;
  525. decimal TotalActual = 0;
  526. DateTime Start = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00");
  527. if (TimeType == "1")
  528. {
  529. Start = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00");
  530. }
  531. else if (TimeType == "2")
  532. {
  533. Start = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00").AddDays(-6);
  534. }
  535. else if (TimeType == "3")
  536. {
  537. Start = DateTime.Parse(DateTime.Now.ToString("yyyy-MM") + "-01 00:00:00");
  538. }
  539. while(Start <= DateTime.Now)
  540. {
  541. MerchantAmountSummay query = new MerchantAmountSummayService().Query(Id, Start.ToString("yyyyMMdd"));
  542. // TotalAmount += query.TradeAmount;
  543. TotalOrder += query.TradeAmount;
  544. // TotalUser += query.TotalUser;
  545. // TotalActual += query.TotalActual;
  546. Start = Start.AddDays(1);
  547. }
  548. Obj.Add("TotalAmount", TotalActual); //平台总收益
  549. Obj.Add("TotalOrder", TotalOrder); //累计订单
  550. Obj.Add("TotalUser", TotalUser); //会员数
  551. Obj.Add("TotalActual", TotalAmount); //营收总额
  552. return Obj;
  553. }
  554. #endregion
  555. #region 商户-修改登录密码
  556. [Authorize]
  557. public JsonResult ModifyLoginPwd(string value)
  558. {
  559. value = DesDecrypt(value);
  560. JsonData data = JsonMapper.ToObject(value);
  561. AppResultJson result = ModifyLoginPwdDo(value);
  562. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  563. }
  564. public AppResultJson ModifyLoginPwdDo(string value)
  565. {
  566. JsonData data = JsonMapper.ToObject(value);
  567. string LoginPwd = data["LoginPwd"].ToString(); //登录密码
  568. string NewLoginPwd = data["NewLoginPwd"].ToString(); //新登录密码
  569. Dictionary<string, object> Obj = new Dictionary<string, object>();
  570. MerchantInfo query = new MerchantInfo();
  571. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  572. query = MerchantInfoDbconn.Instance.Get(Id);
  573. if (query != null)
  574. {
  575. query.UpdateDate = DateTime.Now; //修改时间
  576. query.LoginPwd = LoginPwd; //登录密码
  577. }
  578. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  579. }
  580. #endregion
  581. #region 商户-商户统计数据(个人中心主界面)
  582. [Authorize]
  583. public JsonResult StatData(string value)
  584. {
  585. value = DesDecrypt(value);
  586. JsonData data = JsonMapper.ToObject(value);
  587. Dictionary<string, object> Obj = StatDataDo(value);
  588. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  589. }
  590. public Dictionary<string, object> StatDataDo(string value)
  591. {
  592. JsonData data = JsonMapper.ToObject(value);
  593. Dictionary<string, object> Obj = new Dictionary<string, object>();
  594. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  595. MerchantInfo query = MerchantInfoDbconn.Instance.Get(Id) ?? new MerchantInfo();
  596. Obj.Add("Name", query.Name); //名称
  597. Obj.Add("TotalActual", query.TotalActual); //实收总金额
  598. Obj.Add("TotalOrder", query.TotalOrder); //累计订单
  599. Obj.Add("TotalCustomer", query.TotalCustomer); //累计客户
  600. Obj.Add("Logo", DefaultPic(query.Logo)); //Logo图片
  601. int ConsumeCount = 0;
  602. decimal WeChatTotal = 0;
  603. decimal AlipayTotal = 0;
  604. for (int i = 0; i < 7; i++)
  605. {
  606. string Date = DateTime.Now.AddDays(-i).ToString("yyyyMMdd");
  607. // ConsumeCount += 0;
  608. WeChatTotal += MerchantAmountSummary.Instance.GetTradeByMode(Id, 2, Date);
  609. AlipayTotal += MerchantAmountSummary.Instance.GetTradeByMode(Id, 1, Date);
  610. }
  611. Obj.Add("SevenDayConsumer", ConsumeCount); //近7日新增会员
  612. Obj.Add("WeChatTotal", WeChatTotal); //微信实收
  613. Obj.Add("AlipayTotal", AlipayTotal); //支付宝实收
  614. Obj.Add("CreateDate", query.CreateDate == null ? "" : query.CreateDate.Value.ToString("yyyy-MM-dd"));
  615. return Obj;
  616. }
  617. #endregion
  618. #region 商户-商户详情
  619. [Authorize]
  620. public JsonResult Detail(string value)
  621. {
  622. value = DesDecrypt(value);
  623. JsonData data = JsonMapper.ToObject(value);
  624. Dictionary<string, object> Obj = DetailDo(value);
  625. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  626. }
  627. public Dictionary<string, object> DetailDo(string value)
  628. {
  629. JsonData data = JsonMapper.ToObject(value);
  630. Dictionary<string, object> Obj = new Dictionary<string, object>();
  631. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  632. MerchantInfo query = MerchantInfoDbconn.Instance.Get(Id) ?? new MerchantInfo();
  633. MerchantAddInfo merchantAddInfo = maindb.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
  634. Obj.Add("Name", query.Name); //名称
  635. Obj.Add("Mobile", query.Mobile); //手机号
  636. Obj.Add("IsAuth", query.IsAuth); //是否认证
  637. Obj.Add("Logo", DefaultPic(query.Logo)); //Logo图片
  638. Obj.Add("Status", merchantAddInfo.Status);
  639. Obj.Add("CreateDate", query.CreateDate == null ? "" : query.CreateDate.Value.ToString("yyyy-MM-dd"));
  640. return Obj;
  641. }
  642. #endregion
  643. #region 商户-通过sn获取商户详情
  644. [Authorize]
  645. public JsonResult DetailBySn(string value)
  646. {
  647. if (string.IsNullOrEmpty(value))
  648. {
  649. System.IO.StreamReader sr = new System.IO.StreamReader(Request.Body);
  650. value = sr.ReadToEnd();
  651. value = value.Split('=')[1];
  652. }
  653. value = DesDecrypt(value);
  654. JsonData data = JsonMapper.ToObject(value);
  655. Dictionary<string, object> Obj = DetailBySnDo(value);
  656. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  657. }
  658. public Dictionary<string, object> DetailBySnDo(string value)
  659. {
  660. JsonData data = JsonMapper.ToObject(value);
  661. Dictionary<string, object> Obj = new Dictionary<string, object>();
  662. string Sn = data["Sn"].ToString();
  663. MerchantQrCode code = MerchantQrCodeDbconn.Instance.Get(Sn) ?? new MerchantQrCode();
  664. MerchantInfo query = MerchantInfoDbconn.Instance.Get(code.MerchantId) ?? new MerchantInfo();
  665. Obj.Add("Name", query.Name); //名称
  666. Obj.Add("Mobile", query.Mobile); //手机号
  667. Obj.Add("IsAuth", query.IsAuth); //是否认证
  668. Obj.Add("Logo", DefaultPic(query.Logo)); //Logo图片
  669. return Obj;
  670. }
  671. #endregion
  672. #region 商户-忘记密码
  673. [Authorize]
  674. public JsonResult ForgetPwd(string value)
  675. {
  676. value = DesDecrypt(value);
  677. JsonData data = JsonMapper.ToObject(value);
  678. AppResultJson result = ForgetPwdDo(value);
  679. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  680. }
  681. public AppResultJson ForgetPwdDo(string value)
  682. {
  683. JsonData data = JsonMapper.ToObject(value);
  684. string Mobile = data["Mobile"].ToString(); //手机号
  685. string LoginPwd = data["LoginPwd"].ToString(); //登录密码
  686. string MobileCode = data["MobileCode"].ToString(); //短信验证码
  687. if (string.IsNullOrEmpty(data["Mobile"].ToString()))
  688. {
  689. return new AppResultJson() { Status = "-1", Info = "请填写手机号" };
  690. }
  691. if (data["Mobile"].ToString().Length > 11)
  692. {
  693. return new AppResultJson() { Status = "-1", Info = "手机号最多11个字符" };
  694. }
  695. MobileCodeCheck mobilecheck = RedisDbconn.Instance.Get<MobileCodeCheck>("MobileCodeCheck:" + Mobile);
  696. if (mobilecheck == null)
  697. {
  698. return new AppResultJson() { Status = "-1", Info = "短信验证码不正确" };
  699. }
  700. if (mobilecheck.CheckCode != MobileCode)
  701. {
  702. return new AppResultJson() { Status = "-1", Info = "短信验证码不正确" };
  703. }
  704. RedisDbconn.Instance.Clear("MobileCodeCheck:" + Mobile);
  705. Dictionary<string, object> Obj = new Dictionary<string, object>();
  706. MerchantForMobile find = new MerchantForMobileService().Query(Mobile);
  707. if (find == null)
  708. {
  709. return new AppResultJson() { Status = "-1", Info = "手机号不正确" };
  710. }
  711. MerchantInfo query = MerchantInfoDbconn.Instance.Get(find.MerchantId);
  712. if (query != null)
  713. {
  714. query.LoginPwd = function.MD532(LoginPwd); //登录密码
  715. }
  716. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  717. }
  718. #endregion
  719. #region 商户-登录
  720. // [Authorize]
  721. public JsonResult Login(string value)
  722. {
  723. value = DesDecrypt(value);
  724. JsonData data = JsonMapper.ToObject(value);
  725. string Mobile = data["Mobile"].ToString(); //手机号
  726. string LoginPwd = data["LoginPwd"].ToString(); //登录密码
  727. Dictionary<string, object> Obj = new Dictionary<string, object>();
  728. if (Mobile == "13802211996")
  729. {
  730. if (LoginPwd != "kxs2022")
  731. {
  732. return Json(new AppResultJson() { Status = "-1", Info = "登录密码不正确" });
  733. }
  734. Obj.Add("Id", 1);
  735. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  736. }
  737. MerchantForMobile find = new MerchantForMobileService().Query(Mobile);
  738. if (find == null)
  739. {
  740. return Json(new AppResultJson() { Status = "-1", Info = "手机号不正确" });
  741. }
  742. MerchantInfo query = MerchantInfoDbconn.Instance.Get(find.MerchantId) ?? new MerchantInfo();
  743. if (query.LoginPwd != function.MD532(LoginPwd))
  744. {
  745. return Json(new AppResultJson() { Status = "-1", Info = "登录密码不正确" });
  746. }
  747. Obj.Add("Id", query.Id); //Id
  748. Obj.Add("Token", PublicFunction.AppToken(query.Id, JwtSecret, JwtIss, "merchant"));
  749. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  750. }
  751. #endregion
  752. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  753. /// <summary>
  754. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  755. /// </summary>
  756. /// <param name="value">请求的参数(json字符串)</param>
  757. /// <param name="signField">要签名的字段</param>
  758. /// <returns></returns>
  759. private string CheckSign(string value, string[] signField)
  760. {
  761. JsonData json = JsonMapper.ToObject(value);
  762. Dictionary<string, string> dic = new Dictionary<string, string>();
  763. for (int i = 0; i < signField.Length; i++)
  764. {
  765. dic.Add(signField[i], json[signField[i]].ToString());
  766. }
  767. string sign = json["sign"].ToString(); //客户端签名字符串
  768. return new Sign().sign(dic, sign);
  769. }
  770. #endregion
  771. }
  772. }