MerchantInfoController.cs 36 KB

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