PosMerchantInfoController.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. /*
  2. * 商户
  3. */
  4. using System;
  5. using System.Web;
  6. using System.Collections.Generic;
  7. using System.Diagnostics;
  8. using System.Linq;
  9. using System.Threading.Tasks;
  10. using Microsoft.AspNetCore.Mvc;
  11. using Microsoft.AspNetCore.Http;
  12. using Microsoft.Extensions.Logging;
  13. using Microsoft.Extensions.Options;
  14. using MySystem.Models;
  15. using Library;
  16. using LitJson;
  17. using MySystemLib;
  18. namespace MySystem.Areas.Admin.Controllers
  19. {
  20. [Area("Admin")]
  21. [Route("Admin/[controller]/[action]")]
  22. public class PosMerchantInfoController : BaseController
  23. {
  24. public PosMerchantInfoController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  25. {
  26. OtherMySqlConn.connstr = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  27. }
  28. #region 商户列表
  29. /// <summary>
  30. /// 根据条件查询商户列表
  31. /// </summary>
  32. /// <returns></returns>
  33. public IActionResult Index(PosMerchantInfo data, string right, string BrandId)
  34. {
  35. ViewBag.RightInfo = RightInfo;
  36. ViewBag.right = right;
  37. ViewBag.BrandId = BrandId;
  38. return View();
  39. }
  40. #endregion
  41. #region 根据条件查询商户列表
  42. /// <summary>
  43. /// 商户列表
  44. /// </summary>
  45. /// <returns></returns>
  46. public JsonResult IndexData(PosMerchantInfo data, string MerIdcardNo, string MerchantName, string MakerCode, string RealName, string MerMakerCode, string StoreNo, string StoreName, string MerStatusSelect, string ActiveStatusSelect, string ActTypeSelect, string MerUserTypeSelect, int page = 1, int limit = 30)
  47. {
  48. Dictionary<string, string> Fields = new Dictionary<string, string>();
  49. Fields.Add("BrandId", "1");
  50. Fields.Add("MerchantNo", "1"); //商户编号
  51. Fields.Add("MerchantName", "1"); //商户姓名
  52. Fields.Add("MerchantMobile", "1"); //商户手机号
  53. Fields.Add("KqMerNo", "1"); //快钱商户编码
  54. Fields.Add("KqSnNo", "1"); //快钱SN号
  55. Fields.Add("KqRegTime", "3"); //渠道注册时间
  56. Fields.Add("TopUserId", "0"); //顶级创客
  57. string condition = " and Status>-1";
  58. //身份证号
  59. if (!string.IsNullOrEmpty(MerIdcardNo))
  60. {
  61. condition += " and MerchantName like '%" + MerIdcardNo + "%'";
  62. }
  63. //商户姓名
  64. if (!string.IsNullOrEmpty(MerchantName))
  65. {
  66. condition += " and MerchantName like '%" + MerchantName + "%'";
  67. }
  68. //创客编号
  69. if (!string.IsNullOrEmpty(MakerCode))
  70. {
  71. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  72. }
  73. //创客名称
  74. if (!string.IsNullOrEmpty(RealName))
  75. {
  76. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  77. }
  78. //商户创客编号
  79. if (!string.IsNullOrEmpty(MerMakerCode))
  80. {
  81. condition += " and MerUserId in (select UserId from UserForMakerCode where MakerCode='" + MerMakerCode + "')";
  82. }
  83. //仓库编号
  84. if (!string.IsNullOrEmpty(StoreNo))
  85. {
  86. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreNo + "')";
  87. }
  88. //仓库名称
  89. if (!string.IsNullOrEmpty(RealName))
  90. {
  91. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreName + "')";
  92. }
  93. //商户状态
  94. if (!string.IsNullOrEmpty(MerStatusSelect))
  95. {
  96. condition += " and MerStatus=" + MerStatusSelect;
  97. }
  98. //商户激活状态
  99. if (!string.IsNullOrEmpty(ActiveStatusSelect))
  100. {
  101. condition += " and ActiveStatus=" + ActiveStatusSelect;
  102. }
  103. //激活类型
  104. if (!string.IsNullOrEmpty(ActTypeSelect))
  105. {
  106. condition += " and ActType=" + ActTypeSelect;
  107. }
  108. //商户创客类型
  109. if (!string.IsNullOrEmpty(MerUserTypeSelect))
  110. {
  111. condition += " and MerUserType=" + MerUserTypeSelect;
  112. }
  113. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosMerchantInfo", Fields, "Id desc", "0", page, limit, condition);
  114. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  115. foreach (Dictionary<string, object> dic in diclist)
  116. {
  117. //直属创客
  118. int UserId = int.Parse(dic["UserId"].ToString());
  119. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  120. dic["MakerCode"] = puser.MakerCode;
  121. dic["RealName"] = puser.RealName;
  122. //顶级创客
  123. int TopUserId = int.Parse(dic["TopUserId"].ToString());
  124. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  125. dic["TopMakerCode"] = tuser.MakerCode;
  126. dic["TopRealName"] = tuser.RealName;
  127. //商户创客
  128. int MerUserId = int.Parse(dic["MerUserId"].ToString());
  129. Users muser = db.Users.FirstOrDefault(m => m.Id == MerUserId) ?? new Users();
  130. dic["MerMakerCode"] = muser.MakerCode;
  131. dic["MerRealName"] = muser.RealName;
  132. //申请创客
  133. int SnApplyUserId = int.Parse(dic["SnApplyUserId"].ToString());
  134. Users snuser = db.Users.FirstOrDefault(m => m.Id == SnApplyUserId) ?? new Users();
  135. dic["SnApplyMakerCode"] = snuser.MakerCode;
  136. dic["SnApplyRealName"] = snuser.RealName;
  137. //SN仓库
  138. int SnStoreId = int.Parse(dic["SnStoreId"].ToString());
  139. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == SnStoreId) ?? new StoreHouse();
  140. dic["StoreNo"] = store.StoreNo;
  141. dic["StoreName"] = store.StoreName;
  142. //机具类型
  143. int SnType = int.Parse(dic["SnType"].ToString());
  144. if (SnType == 0) dic["SnType"] = "兑换机具";
  145. if (SnType == 1) dic["SnType"] = "循环机具";
  146. //返利资格
  147. dic["RebateQual"] = dic["RebateQual"].ToString() == "1" ? "是" : "否";
  148. //激活类型
  149. int ActType = int.Parse(dic["ActType"].ToString());
  150. if (ActType == 0) dic["ActType"] = "正常激活";
  151. if (ActType == 1) dic["ActType"] = "首次已激活MPOS";
  152. if (ActType == 2) dic["ActType"] = "首次已激活KPOS";
  153. if (ActType == 3) dic["ActType"] = "循环机划拨激活";
  154. //商户状态
  155. int MerStatus = int.Parse(dic["MerStatus"].ToString());
  156. if (MerStatus == 0) dic["MerStatus"] = "正常";
  157. if (MerStatus == 1) dic["MerStatus"] = "冻结";
  158. if (MerStatus == 2) dic["MerStatus"] = "关闭";
  159. //商户激活状态
  160. int ActiveStatus = int.Parse(dic["ActiveStatus"].ToString());
  161. if (ActiveStatus == 0) dic["ActiveStatus"] = "未激活";
  162. if (ActiveStatus == 1) dic["ActiveStatus"] = "已激活";
  163. if (ActiveStatus == 2) dic["ActiveStatus"] = "SN已返现";
  164. //商户创客类型
  165. int MerUserType = int.Parse(dic["MerUserType"].ToString());
  166. if (MerUserType == 0) dic["MerUserType"] = "非商户型创客";
  167. if (MerUserType == 1) dic["MerUserType"] = "商户型创客";
  168. }
  169. return Json(obj);
  170. }
  171. #endregion
  172. #region 列表
  173. public IActionResult List(PosMerchantInfo data, string right)
  174. {
  175. ViewBag.RightInfo = RightInfo;
  176. ViewBag.right = right;
  177. return View();
  178. }
  179. #endregion
  180. #region 列表
  181. public JsonResult ListData(PosMerchantInfo data, string MerIdcardNo, string MerchantName, string MakerCode, string RealName, string MerMakerCode, string StoreNo, string StoreName, string MerStatusSelect, string ActiveStatusSelect, string ActTypeSelect, string MerUserTypeSelect, int page = 1, int limit = 30)
  182. {
  183. Dictionary<string, string> Fields = new Dictionary<string, string>();
  184. Fields.Add("BrandId", "1");
  185. Fields.Add("MerchantNo", "1"); //商户编号
  186. Fields.Add("MerchantName", "1"); //商户姓名
  187. Fields.Add("MerchantMobile", "1"); //商户手机号
  188. Fields.Add("KqMerNo", "1"); //快钱商户编码
  189. Fields.Add("KqSnNo", "1"); //快钱SN号
  190. Fields.Add("KqRegTime", "3"); //渠道注册时间
  191. Fields.Add("TopUserId", "0"); //顶级创客
  192. string condition = " and Status>-1";
  193. //身份证号
  194. if (!string.IsNullOrEmpty(MerIdcardNo))
  195. {
  196. condition += " and MerchantName like '%" + MerIdcardNo + "%'";
  197. }
  198. //商户姓名
  199. if (!string.IsNullOrEmpty(MerchantName))
  200. {
  201. condition += " and MerchantName like '%" + MerchantName + "%'";
  202. }
  203. //创客编号
  204. if (!string.IsNullOrEmpty(MakerCode))
  205. {
  206. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  207. }
  208. //创客名称
  209. if (!string.IsNullOrEmpty(RealName))
  210. {
  211. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  212. }
  213. //商户创客编号
  214. if (!string.IsNullOrEmpty(MerMakerCode))
  215. {
  216. condition += " and MerUserId in (select UserId from UserForMakerCode where MakerCode='" + MerMakerCode + "')";
  217. }
  218. //仓库编号
  219. if (!string.IsNullOrEmpty(StoreNo))
  220. {
  221. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreNo + "')";
  222. }
  223. //仓库名称
  224. if (!string.IsNullOrEmpty(RealName))
  225. {
  226. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreName + "')";
  227. }
  228. //商户状态
  229. if (!string.IsNullOrEmpty(MerStatusSelect))
  230. {
  231. condition += " and MerStatus=" + MerStatusSelect;
  232. }
  233. //商户激活状态
  234. if (!string.IsNullOrEmpty(ActiveStatusSelect))
  235. {
  236. condition += " and ActiveStatus=" + ActiveStatusSelect;
  237. }
  238. //激活类型
  239. if (!string.IsNullOrEmpty(ActTypeSelect))
  240. {
  241. condition += " and ActType=" + ActTypeSelect;
  242. }
  243. //商户创客类型
  244. if (!string.IsNullOrEmpty(MerUserTypeSelect))
  245. {
  246. condition += " and MerUserType=" + MerUserTypeSelect;
  247. }
  248. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosMerchantInfo", Fields, "Id desc", "0", page, limit, condition);
  249. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  250. foreach (Dictionary<string, object> dic in diclist)
  251. {
  252. //直属创客
  253. int UserId = int.Parse(dic["UserId"].ToString());
  254. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  255. dic["MakerCode"] = puser.MakerCode;
  256. dic["RealName"] = puser.RealName;
  257. //顶级创客
  258. int TopUserId = int.Parse(dic["TopUserId"].ToString());
  259. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  260. dic["TopMakerCode"] = tuser.MakerCode;
  261. dic["TopRealName"] = tuser.RealName;
  262. //商户创客
  263. int MerUserId = int.Parse(dic["MerUserId"].ToString());
  264. Users muser = db.Users.FirstOrDefault(m => m.Id == MerUserId) ?? new Users();
  265. dic["MerMakerCode"] = muser.MakerCode;
  266. dic["MerRealName"] = muser.RealName;
  267. //申请创客
  268. int SnApplyUserId = int.Parse(dic["SnApplyUserId"].ToString());
  269. Users snuser = db.Users.FirstOrDefault(m => m.Id == SnApplyUserId) ?? new Users();
  270. dic["SnApplyMakerCode"] = snuser.MakerCode;
  271. dic["SnApplyRealName"] = snuser.RealName;
  272. //SN仓库
  273. int SnStoreId = int.Parse(dic["SnStoreId"].ToString());
  274. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == SnStoreId) ?? new StoreHouse();
  275. dic["StoreNo"] = store.StoreNo;
  276. dic["StoreName"] = store.StoreName;
  277. //机具类型
  278. int SnType = int.Parse(dic["SnType"].ToString());
  279. if (SnType == 0) dic["SnType"] = "兑换机具";
  280. if (SnType == 1) dic["SnType"] = "循环机具";
  281. //返利资格
  282. dic["RebateQual"] = dic["RebateQual"].ToString() == "1" ? "是" : "否";
  283. //激活类型
  284. int ActType = int.Parse(dic["ActType"].ToString());
  285. if (ActType == 0) dic["ActType"] = "正常激活";
  286. if (ActType == 1) dic["ActType"] = "首次已激活MPOS";
  287. if (ActType == 2) dic["ActType"] = "首次已激活KPOS";
  288. if (ActType == 3) dic["ActType"] = "循环机划拨激活";
  289. //商户状态
  290. int MerStatus = int.Parse(dic["MerStatus"].ToString());
  291. if (MerStatus == 0) dic["MerStatus"] = "正常";
  292. if (MerStatus == 1) dic["MerStatus"] = "冻结";
  293. if (MerStatus == 2) dic["MerStatus"] = "关闭";
  294. //商户激活状态
  295. int ActiveStatus = int.Parse(dic["ActiveStatus"].ToString());
  296. if (ActiveStatus == 0) dic["ActiveStatus"] = "未激活";
  297. if (ActiveStatus == 1) dic["ActiveStatus"] = "已激活";
  298. if (ActiveStatus == 2) dic["ActiveStatus"] = "SN已返现";
  299. //商户创客类型
  300. int MerUserType = int.Parse(dic["MerUserType"].ToString());
  301. if (MerUserType == 0) dic["MerUserType"] = "非商户型创客";
  302. if (MerUserType == 1) dic["MerUserType"] = "商户型创客";
  303. }
  304. return Json(obj);
  305. }
  306. #endregion
  307. #region 增加商户
  308. /// <summary>
  309. /// 增加或修改商户信息
  310. /// </summary>
  311. /// <returns></returns>
  312. public IActionResult Add(string right)
  313. {
  314. ViewBag.RightInfo = RightInfo;
  315. ViewBag.right = right;
  316. return View();
  317. }
  318. #endregion
  319. #region 增加商户
  320. /// <summary>
  321. /// 增加或修改商户信息
  322. /// </summary>
  323. /// <returns></returns>
  324. [HttpPost]
  325. public string Add(PosMerchantInfo data)
  326. {
  327. Dictionary<string, object> Fields = new Dictionary<string, object>();
  328. Fields.Add("SeoTitle", data.SeoTitle);
  329. Fields.Add("SeoKeyword", data.SeoKeyword);
  330. Fields.Add("SeoDescription", data.SeoDescription);
  331. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("PosMerchantInfo", Fields, 0);
  332. AddSysLog(data.Id.ToString(), "PosMerchantInfo", "add");
  333. db.SaveChanges();
  334. return "success";
  335. }
  336. #endregion
  337. #region 修改商户
  338. /// <summary>
  339. /// 增加或修改商户信息
  340. /// </summary>
  341. /// <returns></returns>
  342. public IActionResult Edit(string right, int Id = 0)
  343. {
  344. ViewBag.RightInfo = RightInfo;
  345. ViewBag.right = right;
  346. PosMerchantInfo editData = db.PosMerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new PosMerchantInfo();
  347. ViewBag.data = editData;
  348. return View();
  349. }
  350. #endregion
  351. #region 修改商户
  352. /// <summary>
  353. /// 增加或修改商户信息
  354. /// </summary>
  355. /// <returns></returns>
  356. [HttpPost]
  357. public string Edit(PosMerchantInfo data)
  358. {
  359. Dictionary<string, object> Fields = new Dictionary<string, object>();
  360. Fields.Add("SeoTitle", data.SeoTitle);
  361. Fields.Add("SeoKeyword", data.SeoKeyword);
  362. Fields.Add("SeoDescription", data.SeoDescription);
  363. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, data.Id);
  364. AddSysLog(data.Id.ToString(), "PosMerchantInfo", "update");
  365. db.SaveChanges();
  366. return "success";
  367. }
  368. #endregion
  369. #region 删除商户信息
  370. /// <summary>
  371. /// 删除商户信息
  372. /// </summary>
  373. /// <returns></returns>
  374. public string Delete(string Id)
  375. {
  376. string[] idlist = Id.Split(new char[] { ',' });
  377. AddSysLog(Id, "PosMerchantInfo", "del");
  378. foreach (string subid in idlist)
  379. {
  380. int id = int.Parse(subid);
  381. Dictionary<string, object> Fields = new Dictionary<string, object>();
  382. Fields.Add("Status", -1);
  383. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  384. }
  385. db.SaveChanges();
  386. return "success";
  387. }
  388. #endregion
  389. #region 开启
  390. /// <summary>
  391. /// 开启
  392. /// </summary>
  393. /// <returns></returns>
  394. public string Open(string Id)
  395. {
  396. string[] idlist = Id.Split(new char[] { ',' });
  397. AddSysLog(Id, "PosMerchantInfo", "open");
  398. foreach (string subid in idlist)
  399. {
  400. int id = int.Parse(subid);
  401. Dictionary<string, object> Fields = new Dictionary<string, object>();
  402. Fields.Add("Status", 1);
  403. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  404. }
  405. db.SaveChanges();
  406. return "success";
  407. }
  408. #endregion
  409. #region 关闭
  410. /// <summary>
  411. /// 关闭
  412. /// </summary>
  413. /// <returns></returns>
  414. public string Close(string Id)
  415. {
  416. string[] idlist = Id.Split(new char[] { ',' });
  417. AddSysLog(Id, "PosMerchantInfo", "close");
  418. foreach (string subid in idlist)
  419. {
  420. int id = int.Parse(subid);
  421. Dictionary<string, object> Fields = new Dictionary<string, object>();
  422. Fields.Add("Status", 0);
  423. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  424. }
  425. db.SaveChanges();
  426. return "success";
  427. }
  428. #endregion
  429. #region 排序
  430. /// <summary>
  431. /// 排序
  432. /// </summary>
  433. /// <param name="Id"></param>
  434. public string Sort(int Id, int Sort)
  435. {
  436. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("PosMerchantInfo", Sort, Id);
  437. AddSysLog(Id.ToString(), "PosMerchantInfo", "sort");
  438. return "success";
  439. }
  440. #endregion
  441. #region 导入数据
  442. /// <summary>
  443. /// 导入数据
  444. /// </summary>
  445. /// <param name="ExcelData"></param>
  446. public string Import(string ExcelData)
  447. {
  448. ExcelData = HttpUtility.UrlDecode(ExcelData);
  449. JsonData list = JsonMapper.ToObject(ExcelData);
  450. for (int i = 1; i < list.Count; i++)
  451. {
  452. JsonData dr = list[i];
  453. db.PosMerchantInfo.Add(new PosMerchantInfo()
  454. {
  455. CreateDate = DateTime.Now,
  456. UpdateDate = DateTime.Now,
  457. });
  458. db.SaveChanges();
  459. }
  460. AddSysLog("0", "PosMerchantInfo", "Import");
  461. return "success";
  462. }
  463. #endregion
  464. #region 导出Excel
  465. /// <summary>
  466. /// 导出Excel
  467. /// </summary>
  468. /// <returns></returns>
  469. public JsonResult ExportExcel(PosMerchantInfo data, string MakerCode, string RealName, string MerMakerCode, string StoreNo, string StoreName, string MerStatusSelect, string ActiveStatusSelect, string ActTypeSelect, string MerUserTypeSelect)
  470. {
  471. Dictionary<string, string> Fields = new Dictionary<string, string>();
  472. Fields.Add("BrandId", "1");
  473. Fields.Add("MerchantNo", "1"); //商户编号
  474. Fields.Add("MerchantName", "1"); //商户姓名
  475. Fields.Add("MerchantMobile", "1"); //商户手机号
  476. Fields.Add("KqMerNo", "1"); //快钱商户编码
  477. Fields.Add("KqSnNo", "1"); //快钱SN号
  478. Fields.Add("KqRegTime", "3"); //渠道注册时间
  479. Fields.Add("TopUserId", "0"); //顶级创客
  480. string condition = " and Status>-1";
  481. //创客编号
  482. if (!string.IsNullOrEmpty(MakerCode))
  483. {
  484. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  485. }
  486. //创客名称
  487. if (!string.IsNullOrEmpty(RealName))
  488. {
  489. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  490. }
  491. //商户创客编号
  492. if (!string.IsNullOrEmpty(MerMakerCode))
  493. {
  494. condition += " and MerUserId in (select UserId from UserForMakerCode where MakerCode='" + MerMakerCode + "')";
  495. }
  496. //仓库编号
  497. if (!string.IsNullOrEmpty(StoreNo))
  498. {
  499. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreNo + "')";
  500. }
  501. //仓库名称
  502. if (!string.IsNullOrEmpty(RealName))
  503. {
  504. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreName + "')";
  505. }
  506. //商户状态
  507. if (!string.IsNullOrEmpty(MerStatusSelect))
  508. {
  509. condition += " and MerStatus=" + MerStatusSelect;
  510. }
  511. //商户激活状态
  512. if (!string.IsNullOrEmpty(ActiveStatusSelect))
  513. {
  514. condition += " and ActiveStatus=" + ActiveStatusSelect;
  515. }
  516. //激活类型
  517. if (!string.IsNullOrEmpty(ActTypeSelect))
  518. {
  519. condition += " and ActType=" + ActTypeSelect;
  520. }
  521. //商户创客类型
  522. if (!string.IsNullOrEmpty(MerUserTypeSelect))
  523. {
  524. condition += " and MerUserType=" + MerUserTypeSelect;
  525. }
  526. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosMerchantInfo", Fields, "Id desc", "0", 1, 20000, condition, "MerchantNo,MerchantName,MerchantMobile,KqMerNo,KqSnNo,MerStatus,ActiveStatus,UserId,MerUserId,SnType,SnApplyUserId,KqRegTime,ActType,SnStoreId,TopUserId,MerUserType,RebateQual", false);
  527. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  528. foreach (Dictionary<string, object> dic in diclist)
  529. {
  530. //直属创客
  531. int UserId = int.Parse(dic["UserId"].ToString());
  532. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  533. dic["MakerCode"] = puser.MakerCode;
  534. dic["RealName"] = puser.RealName;
  535. //顶级创客
  536. int TopUserId = int.Parse(dic["TopUserId"].ToString());
  537. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  538. dic["TopMakerCode"] = tuser.MakerCode;
  539. dic["TopRealName"] = tuser.RealName;
  540. //商户创客
  541. int MerUserId = int.Parse(dic["MerUserId"].ToString());
  542. Users muser = db.Users.FirstOrDefault(m => m.Id == MerUserId) ?? new Users();
  543. dic["MerMakerCode"] = muser.MakerCode;
  544. dic["MerRealName"] = muser.RealName;
  545. //申请创客
  546. int SnApplyUserId = int.Parse(dic["SnApplyUserId"].ToString());
  547. Users snuser = db.Users.FirstOrDefault(m => m.Id == SnApplyUserId) ?? new Users();
  548. dic["SnApplyMakerCode"] = snuser.MakerCode;
  549. dic["SnApplyRealName"] = snuser.RealName;
  550. //SN仓库
  551. int SnStoreId = int.Parse(dic["SnStoreId"].ToString());
  552. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == SnStoreId) ?? new StoreHouse();
  553. dic["StoreNo"] = store.StoreNo;
  554. dic["StoreName"] = store.StoreName;
  555. //机具类型
  556. int SnType = int.Parse(dic["SnType"].ToString());
  557. if (SnType == 0) dic["SnType"] = "兑换机具";
  558. if (SnType == 1) dic["SnType"] = "循环机具";
  559. //返利资格
  560. dic["RebateQual"] = dic["RebateQual"].ToString() == "1" ? "是" : "否";
  561. //激活类型
  562. int ActType = int.Parse(dic["ActType"].ToString());
  563. if (ActType == 0) dic["ActType"] = "正常激活";
  564. if (ActType == 1) dic["ActType"] = "首次已激活MPOS";
  565. if (ActType == 2) dic["ActType"] = "首次已激活KPOS";
  566. if (ActType == 3) dic["ActType"] = "循环机划拨激活";
  567. //商户状态
  568. int MerStatus = int.Parse(dic["MerStatus"].ToString());
  569. if (MerStatus == 0) dic["MerStatus"] = "正常";
  570. if (MerStatus == 1) dic["MerStatus"] = "冻结";
  571. if (MerStatus == 2) dic["MerStatus"] = "关闭";
  572. //商户激活状态
  573. int ActiveStatus = int.Parse(dic["ActiveStatus"].ToString());
  574. if (ActiveStatus == 0) dic["ActiveStatus"] = "未激活";
  575. if (ActiveStatus == 1) dic["ActiveStatus"] = "已激活";
  576. if (ActiveStatus == 2) dic["ActiveStatus"] = "SN已返现";
  577. //商户创客类型
  578. int MerUserType = int.Parse(dic["MerUserType"].ToString());
  579. if (MerUserType == 0) dic["MerUserType"] = "非商户型创客";
  580. if (MerUserType == 1) dic["MerUserType"] = "商户型创客";
  581. dic.Remove("UserId");
  582. dic.Remove("TopUserId");
  583. dic.Remove("MerUserId");
  584. dic.Remove("SnApplyUserId");
  585. dic.Remove("SnStoreId");
  586. }
  587. Dictionary<string, object> result = new Dictionary<string, object>();
  588. result.Add("Status", "1");
  589. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  590. result.Add("Obj", diclist);
  591. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  592. ReturnFields.Add("MerchantNo", "商户编号");
  593. ReturnFields.Add("MerchantName", "商户名称");
  594. ReturnFields.Add("MerchantMobile", "商户手机号");
  595. ReturnFields.Add("KqMerNo", "快钱商户编码");
  596. ReturnFields.Add("KqSnNo", "快钱SN号");
  597. ReturnFields.Add("SnType", "机具类型");
  598. ReturnFields.Add("RebateQual", "返利资格");
  599. ReturnFields.Add("ActType", "激活类型");
  600. ReturnFields.Add("MerStatus", "商户状态");
  601. ReturnFields.Add("ActiveStatus", "商户激活状态");
  602. ReturnFields.Add("MerMakerCode", "商户创客编码");
  603. ReturnFields.Add("MerRealName", "商户创客名称");
  604. ReturnFields.Add("MerUserType", "商户创客类型");
  605. ReturnFields.Add("MakerCode", "直属创客编号");
  606. ReturnFields.Add("RealName", "直属创客姓名");
  607. ReturnFields.Add("TopMakerCode", "顶级创客编码");
  608. ReturnFields.Add("TopRealName", "顶级创客名称");
  609. ReturnFields.Add("StoreNo", "SN仓库编号");
  610. ReturnFields.Add("StoreName", "SN仓库名称");
  611. ReturnFields.Add("SnApplyMakerCode", "申请创客编号");
  612. ReturnFields.Add("SnApplyRealName", "申请创客姓名");
  613. ReturnFields.Add("KqRegTime", "注册时间");
  614. result.Add("Fields", ReturnFields);
  615. AddSysLog("0", "PosMerchantInfo", "ExportExcel");
  616. return Json(result);
  617. }
  618. #endregion
  619. #region 同步交易额
  620. public IActionResult SycnTradeAmount(string right, int Id = 0)
  621. {
  622. ViewBag.RightInfo = RightInfo;
  623. ViewBag.right = right;
  624. PosMerchantInfo editData = db.PosMerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new PosMerchantInfo();
  625. ViewBag.data = editData;
  626. return View();
  627. }
  628. #endregion
  629. #region 同步交易额
  630. [HttpPost]
  631. public string SycnTradeAmountDo(DateTime sdate, DateTime edate, int MerchantId)
  632. {
  633. if (sdate.AddMonths(1) < edate)
  634. {
  635. return "时间间隔不能超过1个月";
  636. }
  637. if (edate >= DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00"))
  638. {
  639. return "结束时间只能是今天之前";
  640. }
  641. string check = RedisDbconn.Instance.Get<string>("ResetMerchantTradeQueue:" + MerchantId);
  642. if (!string.IsNullOrEmpty(check))
  643. {
  644. return "请稍后再试";
  645. }
  646. try
  647. {
  648. RedisDbconn.Instance.AddList("ResetMerchantTradeQueue", MerchantId + "#cut#" + sdate.ToString("yyyy-MM-dd HH:mm:ss") + "#cut#" + edate.ToString("yyyy-MM-dd HH:mm:ss"));
  649. RedisDbconn.Instance.Set("ResetMerchantTradeQueue:" + MerchantId, "wait");
  650. RedisDbconn.Instance.SetExpire("ResetMerchantTradeQueue:" + MerchantId, 3600);
  651. }
  652. catch (Exception ex)
  653. {
  654. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计商户的交易额异常");
  655. return "同步异常";
  656. }
  657. return "success";
  658. }
  659. #endregion
  660. }
  661. }