PosMerchantInfoListController.cs 31 KB

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