MerchantInfoController.cs 39 KB

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