PosMerchantInfoListController.cs 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245
  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 System.Text.RegularExpressions;
  19. using MySystemLib;
  20. namespace MySystem.Areas.Admin.Controllers
  21. {
  22. [Area("Admin")]
  23. [Route("Admin/[controller]/[action]")]
  24. public class PosMerchantInfoListController : BaseController
  25. {
  26. public PosMerchantInfoListController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  27. {
  28. OtherMySqlConn.connstr = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  29. }
  30. #region 商户列表
  31. /// <summary>
  32. /// 根据条件查询商户列表
  33. /// </summary>
  34. /// <returns></returns>
  35. public IActionResult Index(PosMerchantInfo data, string right, string BrandId)
  36. {
  37. ViewBag.RightInfo = RightInfo;
  38. ViewBag.right = right;
  39. ViewBag.BrandId = BrandId;
  40. return View();
  41. }
  42. #endregion
  43. #region 根据条件查询商户列表
  44. /// <summary>
  45. /// 商户列表
  46. /// </summary>
  47. /// <returns></returns>
  48. public JsonResult IndexData(PosMerchantInfo data, string MerIdcardNo, string MerchantName, string PhoneNo, string PosSn, int ShowFlag = 0, int page = 1, int limit = 30)
  49. {
  50. Dictionary<string, string> Fields = new Dictionary<string, string>();
  51. if (ShowFlag == 0)
  52. {
  53. Dictionary<string, object> objs = new Dictionary<string, object>();
  54. return Json(objs);
  55. }
  56. string condition = " and Status>-1";
  57. //身份证号
  58. if (!string.IsNullOrEmpty(MerIdcardNo))
  59. {
  60. var IdCardf = MerIdcardNo.Substring(0, 6);
  61. var IdCardb = MerIdcardNo.Substring(MerIdcardNo.Length - 4);
  62. condition += " and LEFT(MerIdcardNo,6)=" + IdCardf + " AND RIGHT(MerIdcardNo,4)=" + IdCardb + "";
  63. }
  64. //商户姓名
  65. if (!string.IsNullOrEmpty(MerchantName))
  66. {
  67. condition += " and MerchantName like '%" + MerchantName + "%'";
  68. }
  69. //手机号
  70. if (!string.IsNullOrEmpty(PhoneNo))
  71. {
  72. var PhoneNof = PhoneNo.Substring(0, 3);
  73. var PhoneNob = PhoneNo.Substring(PhoneNo.Length - 4);
  74. condition += " and LEFT(MerchantMobile,3)=" + PhoneNof + " AND RIGHT(MerchantMobile,4)=" + PhoneNob + "";
  75. }
  76. //机具号
  77. if (!string.IsNullOrEmpty(PosSn))
  78. {
  79. condition += " and KqSnNo='" + PosSn + "'";
  80. }
  81. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosMerchantInfo", Fields, "Id desc", "0", page, limit, condition);
  82. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  83. foreach (Dictionary<string, object> dic in diclist)
  84. {
  85. //直属创客
  86. int UserId = int.Parse(dic["UserId"].ToString());
  87. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  88. dic["MakerCode"] = puser.MakerCode;
  89. dic["RealName"] = puser.RealName;
  90. //顶级创客
  91. int TopUserId = int.Parse(dic["TopUserId"].ToString());
  92. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  93. dic["TopMakerCode"] = tuser.MakerCode;
  94. dic["TopRealName"] = tuser.RealName;
  95. //商户创客
  96. int MerUserId = int.Parse(dic["MerUserId"].ToString());
  97. Users muser = db.Users.FirstOrDefault(m => m.Id == MerUserId) ?? new Users();
  98. dic["MerMakerCode"] = muser.MakerCode;
  99. dic["MerRealName"] = muser.RealName;
  100. //申请创客
  101. int SnApplyUserId = int.Parse(dic["SnApplyUserId"].ToString());
  102. Users snuser = db.Users.FirstOrDefault(m => m.Id == SnApplyUserId) ?? new Users();
  103. dic["SnApplyMakerCode"] = snuser.MakerCode;
  104. dic["SnApplyRealName"] = snuser.RealName;
  105. //SN仓库
  106. int SnStoreId = int.Parse(dic["SnStoreId"].ToString());
  107. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == SnStoreId) ?? new StoreHouse();
  108. dic["StoreNo"] = store.StoreNo;
  109. dic["StoreName"] = store.StoreName;
  110. //机具类型
  111. int SnType = int.Parse(dic["SnType"].ToString());
  112. if (SnType == 0) dic["SnType"] = "兑换机具";
  113. if (SnType == 1) dic["SnType"] = "循环机具";
  114. //返利资格
  115. dic["RebateQual"] = dic["RebateQual"].ToString() == "1" ? "是" : "否";
  116. //激活类型
  117. int ActType = int.Parse(dic["ActType"].ToString());
  118. if (ActType == 0) dic["ActType"] = "正常激活";
  119. if (ActType == 1) dic["ActType"] = "首次已激活MPOS";
  120. if (ActType == 2) dic["ActType"] = "首次已激活KPOS";
  121. if (ActType == 3) dic["ActType"] = "循环机划拨激活";
  122. //商户状态
  123. int MerStatus = int.Parse(dic["MerStatus"].ToString());
  124. if (MerStatus == 0) dic["MerStatus"] = "正常";
  125. if (MerStatus == 1) dic["MerStatus"] = "冻结";
  126. if (MerStatus == 2) dic["MerStatus"] = "关闭";
  127. //商户激活状态
  128. int ActiveStatus = int.Parse(dic["ActiveStatus"].ToString());
  129. if (ActiveStatus == 0) dic["ActiveStatus"] = "未激活";
  130. if (ActiveStatus == 1) dic["ActiveStatus"] = "已激活";
  131. if (ActiveStatus == 2) dic["ActiveStatus"] = "SN已返现";
  132. //商户创客类型
  133. int MerUserType = int.Parse(dic["MerUserType"].ToString());
  134. if (MerUserType == 0) dic["MerUserType"] = "非商户型创客";
  135. if (MerUserType == 1) dic["MerUserType"] = "商户型创客";
  136. }
  137. return Json(obj);
  138. }
  139. #endregion
  140. #region 人工已退商户列表
  141. /// <summary>
  142. /// 根据条件人工已退商户列表
  143. /// </summary>
  144. /// <returns></returns>
  145. public IActionResult Indexrg(PosMerchantInfo data, string right, string BrandId)
  146. {
  147. ViewBag.RightInfo = RightInfo;
  148. ViewBag.right = right;
  149. ViewBag.BrandId = BrandId;
  150. return View();
  151. }
  152. #endregion
  153. #region 根据条件查询人工已退商户列表
  154. /// <summary>
  155. /// 人工已退商户列表
  156. /// </summary>
  157. /// <returns></returns>
  158. public JsonResult IndexrgData(PosMerchantInfo data, string KqMerNo, string MerIdcardNo, string MerchantName, string PhoneNo, string PosSn, int page = 1, int limit = 30)
  159. {
  160. Dictionary<string, string> Fields = new Dictionary<string, string>();
  161. // Fields.Add("KqMerNo", "1"); //商户编号
  162. string condition = " and Status>-1 and StandardStatus=-2";
  163. //身份证号
  164. if (!string.IsNullOrEmpty(MerIdcardNo))
  165. {
  166. var IdCardf = MerIdcardNo.Substring(0, 6);
  167. var IdCardb = MerIdcardNo.Substring(MerIdcardNo.Length - 4);
  168. condition += " and LEFT(MerIdcardNo,6)=" + IdCardf + " AND RIGHT(MerIdcardNo,4)=" + IdCardb + "";
  169. }
  170. //商户姓名
  171. if (!string.IsNullOrEmpty(MerchantName))
  172. {
  173. condition += " and MerchantName like '%" + MerchantName + "%'";
  174. }
  175. //商户编号
  176. if (!string.IsNullOrEmpty(KqMerNo))
  177. {
  178. condition += " and KqMerNo='" + KqMerNo + "'";
  179. }
  180. //机具号
  181. if (!string.IsNullOrEmpty(PosSn))
  182. {
  183. condition += " and KqSnNo='" + PosSn + "'";
  184. }
  185. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosMerchantInfo", Fields, "KqRegTime DESC", "0", page, limit, condition);
  186. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  187. foreach (Dictionary<string, object> dic in diclist)
  188. {
  189. //直属创客
  190. int UserId = int.Parse(dic["UserId"].ToString());
  191. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  192. dic["MakerCode"] = puser.MakerCode;
  193. dic["RealName"] = puser.RealName;
  194. //顶级创客
  195. int TopUserId = int.Parse(dic["TopUserId"].ToString());
  196. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  197. dic["TopMakerCode"] = tuser.MakerCode;
  198. dic["TopRealName"] = tuser.RealName;
  199. //商户创客
  200. int MerUserId = int.Parse(dic["MerUserId"].ToString());
  201. Users muser = db.Users.FirstOrDefault(m => m.Id == MerUserId) ?? new Users();
  202. dic["MerMakerCode"] = muser.MakerCode;
  203. dic["MerRealName"] = muser.RealName;
  204. //申请创客
  205. int SnApplyUserId = int.Parse(dic["SnApplyUserId"].ToString());
  206. Users snuser = db.Users.FirstOrDefault(m => m.Id == SnApplyUserId) ?? new Users();
  207. dic["SnApplyMakerCode"] = snuser.MakerCode;
  208. dic["SnApplyRealName"] = snuser.RealName;
  209. //SN仓库
  210. int SnStoreId = int.Parse(dic["SnStoreId"].ToString());
  211. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == SnStoreId) ?? new StoreHouse();
  212. dic["StoreNo"] = store.StoreNo;
  213. dic["StoreName"] = store.StoreName;
  214. //机具类型
  215. int SnType = int.Parse(dic["SnType"].ToString());
  216. if (SnType == 0) dic["SnType"] = "兑换机具";
  217. if (SnType == 1) dic["SnType"] = "循环机具";
  218. //返利资格
  219. dic["RebateQual"] = dic["RebateQual"].ToString() == "1" ? "是" : "否";
  220. //激活类型
  221. int ActType = int.Parse(dic["ActType"].ToString());
  222. if (ActType == 0) dic["ActType"] = "正常激活";
  223. if (ActType == 1) dic["ActType"] = "首次已激活MPOS";
  224. if (ActType == 2) dic["ActType"] = "首次已激活KPOS";
  225. if (ActType == 3) dic["ActType"] = "循环机划拨激活";
  226. //商户状态
  227. int MerStatus = int.Parse(dic["MerStatus"].ToString());
  228. if (MerStatus == 0) dic["MerStatus"] = "正常";
  229. if (MerStatus == 1) dic["MerStatus"] = "冻结";
  230. if (MerStatus == 2) dic["MerStatus"] = "关闭";
  231. //商户激活状态
  232. int ActiveStatus = int.Parse(dic["ActiveStatus"].ToString());
  233. if (ActiveStatus == 0) dic["ActiveStatus"] = "未激活";
  234. if (ActiveStatus == 1) dic["ActiveStatus"] = "已激活";
  235. if (ActiveStatus == 2) dic["ActiveStatus"] = "SN已返现";
  236. //商户创客类型
  237. int MerUserType = int.Parse(dic["MerUserType"].ToString());
  238. if (MerUserType == 0) dic["MerUserType"] = "非商户型创客";
  239. if (MerUserType == 1) dic["MerUserType"] = "商户型创客";
  240. var KqSnNo = dic["KqSnNo"].ToString();
  241. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == KqSnNo) ?? new PosMachinesTwo();
  242. //实际押金
  243. string SeoKeyword = "0";
  244. if (!string.IsNullOrEmpty(pos.SeoKeyword))
  245. {
  246. if (pos.BrandId != 2 && pos.BrandId != 7 && pos.BrandId != 10 && pos.BrandId != 11)
  247. {
  248. SeoKeyword = (decimal.Parse(pos.SeoKeyword) / 100).ToString();
  249. }
  250. else
  251. {
  252. SeoKeyword = pos.SeoKeyword;
  253. }
  254. }
  255. dic["SeoKeyword"] = SeoKeyword;
  256. //设置押金
  257. string PrizeParams = "0";
  258. if (!string.IsNullOrEmpty(pos.PrizeParams))
  259. {
  260. PrizeParams = pos.PrizeParams.ToString();
  261. }
  262. dic["PrizeParams"] = PrizeParams;
  263. }
  264. Dictionary<string, object> other = new Dictionary<string, object>();
  265. decimal ReturnAmount = 0.00M;//服务费总金额
  266. decimal ReturnAmounts = 0.00M;//退还总金额
  267. DataTable dt = OtherMySqlConn.dtable("SELECT SUM(Remark) FROM PosMerchantInfo WHERE 1=1" + condition);
  268. if (dt.Rows.Count > 0)
  269. {
  270. ReturnAmounts = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString()));
  271. }
  272. DataTable dts = OtherMySqlConn.dtable("SELECT KqSnNo FROM PosMerchantInfo WHERE 1=1" + condition);
  273. if (dt.Rows.Count > 0)
  274. {
  275. foreach (DataRow item in dts.Rows)
  276. {
  277. string KqSnNo = item["KqSnNo"].ToString();
  278. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == KqSnNo) ?? new PosMachinesTwo();
  279. if (!string.IsNullOrEmpty(pos.SeoKeyword))
  280. {
  281. if (pos.BrandId != 2 && pos.BrandId != 7 && pos.BrandId != 10 && pos.BrandId != 11)
  282. {
  283. ReturnAmount += decimal.Parse(pos.SeoKeyword) / 100;
  284. }
  285. else
  286. {
  287. ReturnAmount += decimal.Parse(pos.SeoKeyword);
  288. }
  289. }
  290. }
  291. }
  292. other.Add("ReturnAmount", ReturnAmount.ToString("f2"));
  293. other.Add("ReturnAmounts", ReturnAmounts.ToString("f2"));
  294. obj.Add("other", other);
  295. return Json(obj);
  296. }
  297. #endregion
  298. #region 导出人工已退商户Excel
  299. /// <summary>
  300. /// 导出人工已退商户Excel
  301. /// </summary>
  302. /// <returns></returns>
  303. public JsonResult ExportrgExcel(PosMerchantInfo data, string MerIdcardNo, string MerchantName, string PhoneNo, string PosSn)
  304. {
  305. Dictionary<string, string> Fields = new Dictionary<string, string>();
  306. Fields.Add("KqMerNo", "1"); //商户编号
  307. string condition = " and Status>-1 and StandardStatus=-2";
  308. //身份证号
  309. if (!string.IsNullOrEmpty(MerIdcardNo))
  310. {
  311. var IdCardf = MerIdcardNo.Substring(0, 6);
  312. var IdCardb = MerIdcardNo.Substring(MerIdcardNo.Length - 4);
  313. condition += " and LEFT(MerIdcardNo,6)=" + IdCardf + " AND RIGHT(MerIdcardNo,4)=" + IdCardb + "";
  314. }
  315. //商户姓名
  316. if (!string.IsNullOrEmpty(MerchantName))
  317. {
  318. condition += " and MerchantName like '%" + MerchantName + "%'";
  319. }
  320. //手机号
  321. if (!string.IsNullOrEmpty(PhoneNo))
  322. {
  323. var PhoneNof = PhoneNo.Substring(0, 3);
  324. var PhoneNob = PhoneNo.Substring(PhoneNo.Length - 4);
  325. condition += " and LEFT(MerchantMobile,3)=" + PhoneNof + " AND RIGHT(MerchantMobile,4)=" + PhoneNob + "";
  326. }
  327. //机具号
  328. if (!string.IsNullOrEmpty(PosSn))
  329. {
  330. condition += " and KqSnNo='" + PosSn + "'";
  331. }
  332. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosMerchantInfo", Fields, "Id desc", "0", 1, 20000, condition, "MerchantName,Remark,KqMerNo,KqSnNo,UserId,KqRegTime", false);
  333. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  334. foreach (Dictionary<string, object> dic in diclist)
  335. {
  336. var KqSnNo = dic["KqSnNo"].ToString();
  337. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == KqSnNo) ?? new PosMachinesTwo();
  338. var brand = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId) ?? new KqProducts();
  339. dic["BrandName"] = brand.Name;
  340. int UserId = int.Parse(dic["UserId"].ToString());
  341. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  342. dic["MakerCode"] = puser.MakerCode;
  343. dic["RealName"] = puser.RealName;
  344. dic.Remove("UserId");
  345. //实际押金
  346. string SeoKeyword = "0";
  347. if (!string.IsNullOrEmpty(pos.SeoKeyword))
  348. {
  349. if (pos.BrandId != 2 && pos.BrandId != 7 && pos.BrandId != 10 && pos.BrandId != 11)
  350. {
  351. SeoKeyword = (decimal.Parse(pos.SeoKeyword) / 100).ToString();
  352. }
  353. else
  354. {
  355. SeoKeyword = pos.SeoKeyword;
  356. }
  357. }
  358. dic["SeoKeyword"] = SeoKeyword;
  359. }
  360. Dictionary<string, object> result = new Dictionary<string, object>();
  361. result.Add("Status", "1");
  362. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  363. result.Add("Obj", diclist);
  364. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  365. ReturnFields.Add("KqMerNo", "商户编号");
  366. ReturnFields.Add("MerchantName", "商户名称");
  367. ReturnFields.Add("BrandName", "机具品牌");
  368. ReturnFields.Add("KqSnNo", "机具SN");
  369. ReturnFields.Add("KqRegTime", "退还时间");
  370. ReturnFields.Add("SeoKeyword", "服务费金额");
  371. ReturnFields.Add("Remark", "已退还金额");
  372. ReturnFields.Add("MakerCode", "创客编号");
  373. ReturnFields.Add("RealName", "创客姓名");
  374. result.Add("Fields", ReturnFields);
  375. AddSysLog("0", "PosMerchantInfo", "ExportrgExcel");
  376. return Json(result);
  377. }
  378. #endregion
  379. #region 达标商户列表
  380. /// <summary>
  381. /// 达标商户列表
  382. /// </summary>
  383. /// <returns></returns>
  384. public IActionResult Indexs(PosMerchantInfo data, string right, string BrandId)
  385. {
  386. ViewBag.RightInfo = RightInfo;
  387. ViewBag.right = right;
  388. ViewBag.BrandId = BrandId;
  389. return View();
  390. }
  391. #endregion
  392. #region 根据条件查询达标商户列表
  393. /// <summary>
  394. /// 根据条件查询达标商户列表
  395. /// </summary>
  396. /// <returns></returns>
  397. public JsonResult IndexsData(PosMerchantInfo data, int page = 1, int limit = 30)
  398. {
  399. Dictionary<string, string> Fields = new Dictionary<string, string>();
  400. Fields.Add("MerchantMobile", "1"); //商户手机号
  401. Fields.Add("KqSnNo", "1"); //快钱SN号
  402. Fields.Add("MerIdcardNo", "1"); //身份证号
  403. string condition = " and Status>-1 and StandardStatus=4 and StandardMonths=10";
  404. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosMerchantInfo", Fields, "Id desc", "0", page, limit, condition);
  405. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  406. foreach (Dictionary<string, object> dic in diclist)
  407. {
  408. //直属创客
  409. int UserId = int.Parse(dic["UserId"].ToString());
  410. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  411. dic["MakerCode"] = puser.MakerCode;
  412. dic["RealName"] = puser.RealName;
  413. //顶级创客
  414. int TopUserId = int.Parse(dic["TopUserId"].ToString());
  415. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  416. dic["TopMakerCode"] = tuser.MakerCode;
  417. dic["TopRealName"] = tuser.RealName;
  418. //商户创客
  419. int MerUserId = int.Parse(dic["MerUserId"].ToString());
  420. Users muser = db.Users.FirstOrDefault(m => m.Id == MerUserId) ?? new Users();
  421. dic["MerMakerCode"] = muser.MakerCode;
  422. dic["MerRealName"] = muser.RealName;
  423. //申请创客
  424. int SnApplyUserId = int.Parse(dic["SnApplyUserId"].ToString());
  425. Users snuser = db.Users.FirstOrDefault(m => m.Id == SnApplyUserId) ?? new Users();
  426. dic["SnApplyMakerCode"] = snuser.MakerCode;
  427. dic["SnApplyRealName"] = snuser.RealName;
  428. //SN仓库
  429. int SnStoreId = int.Parse(dic["SnStoreId"].ToString());
  430. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == SnStoreId) ?? new StoreHouse();
  431. dic["StoreNo"] = store.StoreNo;
  432. dic["StoreName"] = store.StoreName;
  433. //机具类型
  434. int SnType = int.Parse(dic["SnType"].ToString());
  435. if (SnType == 0) dic["SnType"] = "兑换机具";
  436. if (SnType == 1) dic["SnType"] = "循环机具";
  437. //返利资格
  438. dic["RebateQual"] = dic["RebateQual"].ToString() == "1" ? "是" : "否";
  439. //激活类型
  440. int ActType = int.Parse(dic["ActType"].ToString());
  441. if (ActType == 0) dic["ActType"] = "正常激活";
  442. if (ActType == 1) dic["ActType"] = "首次已激活MPOS";
  443. if (ActType == 2) dic["ActType"] = "首次已激活KPOS";
  444. if (ActType == 3) dic["ActType"] = "循环机划拨激活";
  445. //商户状态
  446. int MerStatus = int.Parse(dic["MerStatus"].ToString());
  447. if (MerStatus == 0) dic["MerStatus"] = "正常";
  448. if (MerStatus == 1) dic["MerStatus"] = "冻结";
  449. if (MerStatus == 2) dic["MerStatus"] = "关闭";
  450. //商户激活状态
  451. int ActiveStatus = int.Parse(dic["ActiveStatus"].ToString());
  452. if (ActiveStatus == 0) dic["ActiveStatus"] = "未激活";
  453. if (ActiveStatus == 1) dic["ActiveStatus"] = "已激活";
  454. if (ActiveStatus == 2) dic["ActiveStatus"] = "SN已返现";
  455. //商户创客类型
  456. int MerUserType = int.Parse(dic["MerUserType"].ToString());
  457. if (MerUserType == 0) dic["MerUserType"] = "非商户型创客";
  458. if (MerUserType == 1) dic["MerUserType"] = "商户型创客";
  459. }
  460. return Json(obj);
  461. }
  462. #endregion
  463. #region 首台达标商户列表
  464. /// <summary>
  465. /// 首台达标商户列表
  466. /// </summary>
  467. /// <returns></returns>
  468. public IActionResult Indexfs(string right)
  469. {
  470. ViewBag.RightInfo = RightInfo;
  471. ViewBag.right = right;
  472. return View();
  473. }
  474. #endregion
  475. #region 根据条件查询首台达标商户列表
  476. /// <summary>
  477. /// 根据条件查询首台达标商户列表
  478. /// </summary>
  479. /// <returns></returns>
  480. public IActionResult IndexfsData(string MerchantMobile, string KqSnNo, string MerIdcardNo, int page = 1, int limit = 30)
  481. {
  482. string condition = "";
  483. if (!string.IsNullOrEmpty(MerchantMobile))
  484. {
  485. condition += " and b.MerchantMobile like '%" + MerchantMobile + "%'";
  486. }
  487. if (!string.IsNullOrEmpty(KqSnNo))
  488. {
  489. condition += " and b.KqSnNo like '%" + KqSnNo + "%'";
  490. }
  491. if (!string.IsNullOrEmpty(MerIdcardNo))
  492. {
  493. condition += " and b.MerIdcardNo like '%" + MerIdcardNo + "%'";
  494. }
  495. var amount = 0.00M;
  496. List<Dictionary<string, object>> diclist = new List<Dictionary<string, object>>();
  497. DataTable dt = OtherMySqlConn.dtable("SELECT a.BrandId,a.PosSn,a.BindMerchantId,a.SeoKeyword,b.KqMerNo,b.MerIdcardNo,b.MerchantName,b.MerchantMobile FROM PosMachinesTwo a,PosMerchantInfo b WHERE a.`Status`>-1 AND a.SeoKeyword!='' AND a.SeoKeyword!='0' AND a.SeoKeyword IS NOT NULL AND a.IsFirst=1 AND b.StandardMonths=10 AND b.StandardStatus=4 AND a.BindMerchantId=b.Id " + condition);
  498. if (dt.Rows.Count > 0)
  499. {
  500. foreach (DataRow item in dt.Rows)
  501. {
  502. var BindMerchantId = item["BindMerchantId"].ToString();
  503. var BrandId = int.Parse(item["BrandId"].ToString());
  504. var PosSn = item["PosSn"].ToString();
  505. var SeoKeyword = item["SeoKeyword"].ToString();
  506. var brand = db.KqProducts.FirstOrDefault(m => m.Id == BrandId) ?? new KqProducts();
  507. if (brand.Id > 0 && brand.SingleDepositApi == 0 && !string.IsNullOrEmpty(SeoKeyword))
  508. {
  509. SeoKeyword = (decimal.Parse(SeoKeyword) / 100).ToString();
  510. }
  511. amount += decimal.Parse(SeoKeyword);
  512. var KqMerNo = item["KqMerNo"].ToString();
  513. var IdcardNo = item["MerIdcardNo"].ToString();
  514. var MerchantName = item["MerchantName"].ToString();
  515. var Mobile = item["MerchantMobile"].ToString();
  516. Dictionary<string, object> datas = new Dictionary<string, object>();
  517. datas.Add("Id", BindMerchantId);
  518. datas.Add("PosSn", PosSn);
  519. datas.Add("SeoKeyword", SeoKeyword);
  520. datas.Add("KqMerNo", KqMerNo);
  521. datas.Add("IdcardNo", IdcardNo);
  522. datas.Add("MerchantName", MerchantName);
  523. datas.Add("MerchantMobile", Mobile);
  524. diclist.Add(datas);
  525. }
  526. }
  527. Dictionary<string, object> obj = new Dictionary<string, object>();
  528. Dictionary<string, object> other = new Dictionary<string, object>();
  529. var ReturnAmount = amount;
  530. var fReturnAmount = amount * 0.92M;
  531. other.Add("ReturnAmount", ReturnAmount.ToString("f2"));
  532. other.Add("fReturnAmount", fReturnAmount.ToString("f2"));
  533. obj.Add("other", other);
  534. obj.Add("code", 0);
  535. obj.Add("msg", "");
  536. obj.Add("count", diclist.Count);
  537. obj.Add("data", diclist);
  538. return Json(obj);
  539. }
  540. #endregion
  541. #region 非首台达标商户列表
  542. /// <summary>
  543. /// 非首台达标商户列表
  544. /// </summary>
  545. /// <returns></returns>
  546. public IActionResult Indexnfs(string right)
  547. {
  548. ViewBag.RightInfo = RightInfo;
  549. ViewBag.right = right;
  550. return View();
  551. }
  552. #endregion
  553. #region 根据条件查询非首台达标商户列表
  554. /// <summary>
  555. /// 根据条件查询非首台达标商户列表
  556. /// </summary>
  557. /// <returns></returns>
  558. public IActionResult IndexnfsData(string MerchantMobile, string KqSnNo, string MerIdcardNo, int page = 1, int limit = 30)
  559. {
  560. string condition = "";
  561. if (!string.IsNullOrEmpty(MerchantMobile))
  562. {
  563. condition += " and b.MerchantMobile like '%" + MerchantMobile + "%'";
  564. }
  565. if (!string.IsNullOrEmpty(KqSnNo))
  566. {
  567. condition += " and b.KqSnNo like '%" + KqSnNo + "%'";
  568. }
  569. if (!string.IsNullOrEmpty(MerIdcardNo))
  570. {
  571. condition += " and b.MerIdcardNo like '%" + MerIdcardNo + "%'";
  572. }
  573. var amount = 0.00M;
  574. List<Dictionary<string, object>> diclist = new List<Dictionary<string, object>>();
  575. DataTable dt = OtherMySqlConn.dtable("SELECT a.BrandId,a.PosSn,a.BindMerchantId,a.SeoKeyword,b.KqMerNo,b.MerIdcardNo,b.MerchantName,b.MerchantMobile FROM PosMachinesTwo a,PosMerchantInfo b WHERE a.`Status`>-1 AND a.SeoKeyword!='' AND a.SeoKeyword!='0' AND a.SeoKeyword IS NOT NULL AND a.IsFirst=0 AND b.StandardMonths=10 AND b.StandardStatus=4 AND a.BindMerchantId=b.Id " + condition);
  576. if (dt.Rows.Count > 0)
  577. {
  578. foreach (DataRow item in dt.Rows)
  579. {
  580. var BindMerchantId = item["BindMerchantId"].ToString();
  581. var BrandId = int.Parse(item["BrandId"].ToString());
  582. var PosSn = item["PosSn"].ToString();
  583. var SeoKeyword = item["SeoKeyword"].ToString();
  584. var brand = db.KqProducts.FirstOrDefault(m => m.Id == BrandId) ?? new KqProducts();
  585. if (brand.Id > 0 && brand.SingleDepositApi == 0 && !string.IsNullOrEmpty(SeoKeyword))
  586. {
  587. SeoKeyword = (decimal.Parse(SeoKeyword) / 100).ToString();
  588. }
  589. amount += decimal.Parse(SeoKeyword);
  590. var KqMerNo = item["KqMerNo"].ToString();
  591. var IdcardNo = item["MerIdcardNo"].ToString();
  592. var MerchantName = item["MerchantName"].ToString();
  593. var Mobile = item["MerchantMobile"].ToString();
  594. Dictionary<string, object> datas = new Dictionary<string, object>();
  595. datas.Add("Id", BindMerchantId);
  596. datas.Add("PosSn", PosSn);
  597. datas.Add("SeoKeyword", SeoKeyword);
  598. datas.Add("KqMerNo", KqMerNo);
  599. datas.Add("IdcardNo", IdcardNo);
  600. datas.Add("MerchantName", MerchantName);
  601. datas.Add("MerchantMobile", Mobile);
  602. diclist.Add(datas);
  603. }
  604. }
  605. Dictionary<string, object> obj = new Dictionary<string, object>();
  606. Dictionary<string, object> other = new Dictionary<string, object>();
  607. var ReturnAmount = amount;
  608. var fReturnAmount = amount * 0.92M;
  609. other.Add("ReturnAmount", ReturnAmount.ToString("f2"));
  610. other.Add("fReturnAmount", fReturnAmount.ToString("f2"));
  611. obj.Add("other", other);
  612. obj.Add("code", 0);
  613. obj.Add("msg", "");
  614. obj.Add("count", diclist.Count);
  615. obj.Add("data", diclist);
  616. return Json(obj);
  617. }
  618. #endregion
  619. #region 批量通过
  620. /// <summary>
  621. /// 批量通过
  622. /// </summary>
  623. /// <returns></returns>
  624. public string BatchSetting(string Id)
  625. {
  626. string[] idlist = Id.Split(new char[] { ',' });
  627. AddSysLog(Id, "PosMerchantInfo", "BatchSetting");
  628. var Ids = "";//商户Id
  629. foreach (string subid in idlist)
  630. {
  631. int id = int.Parse(subid);
  632. Ids += id + ",";
  633. Dictionary<string, object> Fields = new Dictionary<string, object>();
  634. Fields.Add("StandardStatus", 101);//设置为可退押状态
  635. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  636. }
  637. string text = string.Format("商户押金退还批量通过,商户Id: '" + Ids.TrimEnd(',') + "',操作人: '" + SysUserName + "_" + SysRealName + "',Time'" + DateTime.Now + "'");
  638. function.WriteLog(text, "商户押金退还批量通过");
  639. db.SaveChanges();
  640. return "success";
  641. }
  642. #endregion
  643. #region 增加商户
  644. /// <summary>
  645. /// 增加或修改商户信息
  646. /// </summary>
  647. /// <returns></returns>
  648. public IActionResult Add(string right)
  649. {
  650. ViewBag.RightInfo = RightInfo;
  651. ViewBag.right = right;
  652. return View();
  653. }
  654. #endregion
  655. #region 增加商户
  656. /// <summary>
  657. /// 增加或修改商户信息
  658. /// </summary>
  659. /// <returns></returns>
  660. [HttpPost]
  661. public string Add(PosMerchantInfo data)
  662. {
  663. Dictionary<string, object> Fields = new Dictionary<string, object>();
  664. Fields.Add("SeoTitle", data.SeoTitle);
  665. Fields.Add("SeoKeyword", data.SeoKeyword);
  666. Fields.Add("SeoDescription", data.SeoDescription);
  667. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("PosMerchantInfo", Fields, 0);
  668. AddSysLog(data.Id.ToString(), "PosMerchantInfo", "add");
  669. db.SaveChanges();
  670. return "success";
  671. }
  672. #endregion
  673. #region 修改商户
  674. /// <summary>
  675. /// 增加或修改商户信息
  676. /// </summary>
  677. /// <returns></returns>
  678. public IActionResult Edit(string right, int Id = 0)
  679. {
  680. ViewBag.RightInfo = RightInfo;
  681. ViewBag.right = right;
  682. PosMerchantInfo editData = db.PosMerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new PosMerchantInfo();
  683. ViewBag.data = editData;
  684. return View();
  685. }
  686. #endregion
  687. #region 修改商户
  688. /// <summary>
  689. /// 增加或修改商户信息
  690. /// </summary>
  691. /// <returns></returns>
  692. [HttpPost]
  693. public string Edit(PosMerchantInfo data)
  694. {
  695. Dictionary<string, object> Fields = new Dictionary<string, object>();
  696. Fields.Add("SeoTitle", data.SeoTitle);
  697. Fields.Add("SeoKeyword", data.SeoKeyword);
  698. Fields.Add("SeoDescription", data.SeoDescription);
  699. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, data.Id);
  700. AddSysLog(data.Id.ToString(), "PosMerchantInfo", "update");
  701. db.SaveChanges();
  702. return "success";
  703. }
  704. #endregion
  705. #region 删除商户信息
  706. /// <summary>
  707. /// 删除商户信息
  708. /// </summary>
  709. /// <returns></returns>
  710. public string Delete(string Id)
  711. {
  712. string[] idlist = Id.Split(new char[] { ',' });
  713. AddSysLog(Id, "PosMerchantInfo", "del");
  714. foreach (string subid in idlist)
  715. {
  716. int id = int.Parse(subid);
  717. Dictionary<string, object> Fields = new Dictionary<string, object>();
  718. Fields.Add("Status", -1);
  719. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  720. }
  721. db.SaveChanges();
  722. return "success";
  723. }
  724. #endregion
  725. #region 开启
  726. /// <summary>
  727. /// 开启
  728. /// </summary>
  729. /// <returns></returns>
  730. public string Open(string Id)
  731. {
  732. string[] idlist = Id.Split(new char[] { ',' });
  733. AddSysLog(Id, "PosMerchantInfo", "open");
  734. foreach (string subid in idlist)
  735. {
  736. int id = int.Parse(subid);
  737. Dictionary<string, object> Fields = new Dictionary<string, object>();
  738. Fields.Add("Status", 1);
  739. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  740. }
  741. db.SaveChanges();
  742. return "success";
  743. }
  744. #endregion
  745. #region 关闭
  746. /// <summary>
  747. /// 关闭
  748. /// </summary>
  749. /// <returns></returns>
  750. public string Close(string Id)
  751. {
  752. string[] idlist = Id.Split(new char[] { ',' });
  753. AddSysLog(Id, "PosMerchantInfo", "close");
  754. foreach (string subid in idlist)
  755. {
  756. int id = int.Parse(subid);
  757. Dictionary<string, object> Fields = new Dictionary<string, object>();
  758. Fields.Add("Status", 0);
  759. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  760. }
  761. db.SaveChanges();
  762. return "success";
  763. }
  764. #endregion
  765. #region 排序
  766. /// <summary>
  767. /// 排序
  768. /// </summary>
  769. /// <param name="Id"></param>
  770. public string Sort(int Id, int Sort)
  771. {
  772. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("PosMerchantInfo", Sort, Id);
  773. AddSysLog(Id.ToString(), "PosMerchantInfo", "sort");
  774. return "success";
  775. }
  776. #endregion
  777. #region 导入数据
  778. /// <summary>
  779. /// 导入数据
  780. /// </summary>
  781. /// <param name="ExcelData"></param>
  782. public string Import(string ExcelData)
  783. {
  784. ExcelData = HttpUtility.UrlDecode(ExcelData);
  785. JsonData list = JsonMapper.ToObject(ExcelData);
  786. var Ids = "";
  787. for (int i = 1; i < list.Count; i++)
  788. {
  789. JsonData dr = list[i];
  790. string KqMerNo = dr[0].ToString(); // 商户编号
  791. string Amount = dr[1].ToString(); // 已退金额
  792. string KqRegTime = dr[2].ToString(); // 退还时间
  793. var posMerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == KqMerNo) ?? new PosMerchantInfo();
  794. posMerchantInfo.StandardStatus = -2;
  795. posMerchantInfo.Remark = Amount;
  796. posMerchantInfo.KqRegTime = DateTime.Parse(KqRegTime);
  797. Ids += posMerchantInfo.Id + "_" + Amount + ",";
  798. db.SaveChanges();
  799. }
  800. AddSysLog("0", "PosMerchantInfo", "Import");
  801. string text = string.Format("导入人工已退,商户Id: '" + Ids.TrimEnd(',') + "',操作人: '" + SysUserName + "_" + SysRealName + "',Time'" + DateTime.Now + "'");
  802. function.WriteLog(text, "导入人工已退");
  803. return "success";
  804. }
  805. #endregion
  806. #region 导出Excel
  807. /// <summary>
  808. /// 导出Excel
  809. /// </summary>
  810. /// <returns></returns>
  811. public JsonResult ExportExcel(PosMerchantInfo data, string MakerCode, string RealName, string MerMakerCode, string StoreNo, string StoreName, string MerStatusSelect, string ActiveStatusSelect, string ActTypeSelect, string MerUserTypeSelect)
  812. {
  813. Dictionary<string, string> Fields = new Dictionary<string, string>();
  814. Fields.Add("BrandId", "1");
  815. Fields.Add("MerchantNo", "1"); //商户编号
  816. Fields.Add("MerchantName", "1"); //商户姓名
  817. Fields.Add("MerchantMobile", "1"); //商户手机号
  818. Fields.Add("KqMerNo", "1"); //快钱商户编码
  819. Fields.Add("KqSnNo", "1"); //快钱SN号
  820. Fields.Add("KqRegTime", "3"); //渠道注册时间
  821. Fields.Add("TopUserId", "0"); //顶级创客
  822. string condition = " and Status>-1";
  823. //创客编号
  824. if (!string.IsNullOrEmpty(MakerCode))
  825. {
  826. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  827. }
  828. //创客名称
  829. if (!string.IsNullOrEmpty(RealName))
  830. {
  831. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  832. }
  833. //商户创客编号
  834. if (!string.IsNullOrEmpty(MerMakerCode))
  835. {
  836. condition += " and MerUserId in (select UserId from UserForMakerCode where MakerCode='" + MerMakerCode + "')";
  837. }
  838. //仓库编号
  839. if (!string.IsNullOrEmpty(StoreNo))
  840. {
  841. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreNo + "')";
  842. }
  843. //仓库名称
  844. if (!string.IsNullOrEmpty(RealName))
  845. {
  846. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreName + "')";
  847. }
  848. //商户状态
  849. if (!string.IsNullOrEmpty(MerStatusSelect))
  850. {
  851. condition += " and MerStatus=" + MerStatusSelect;
  852. }
  853. //商户激活状态
  854. if (!string.IsNullOrEmpty(ActiveStatusSelect))
  855. {
  856. condition += " and ActiveStatus=" + ActiveStatusSelect;
  857. }
  858. //激活类型
  859. if (!string.IsNullOrEmpty(ActTypeSelect))
  860. {
  861. condition += " and ActType=" + ActTypeSelect;
  862. }
  863. //商户创客类型
  864. if (!string.IsNullOrEmpty(MerUserTypeSelect))
  865. {
  866. condition += " and MerUserType=" + MerUserTypeSelect;
  867. }
  868. 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);
  869. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  870. foreach (Dictionary<string, object> dic in diclist)
  871. {
  872. //直属创客
  873. int UserId = int.Parse(dic["UserId"].ToString());
  874. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  875. dic["MakerCode"] = puser.MakerCode;
  876. dic["RealName"] = puser.RealName;
  877. //顶级创客
  878. int TopUserId = int.Parse(dic["TopUserId"].ToString());
  879. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  880. dic["TopMakerCode"] = tuser.MakerCode;
  881. dic["TopRealName"] = tuser.RealName;
  882. //商户创客
  883. int MerUserId = int.Parse(dic["MerUserId"].ToString());
  884. Users muser = db.Users.FirstOrDefault(m => m.Id == MerUserId) ?? new Users();
  885. dic["MerMakerCode"] = muser.MakerCode;
  886. dic["MerRealName"] = muser.RealName;
  887. //申请创客
  888. int SnApplyUserId = int.Parse(dic["SnApplyUserId"].ToString());
  889. Users snuser = db.Users.FirstOrDefault(m => m.Id == SnApplyUserId) ?? new Users();
  890. dic["SnApplyMakerCode"] = snuser.MakerCode;
  891. dic["SnApplyRealName"] = snuser.RealName;
  892. //SN仓库
  893. int SnStoreId = int.Parse(dic["SnStoreId"].ToString());
  894. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == SnStoreId) ?? new StoreHouse();
  895. dic["StoreNo"] = store.StoreNo;
  896. dic["StoreName"] = store.StoreName;
  897. //机具类型
  898. int SnType = int.Parse(dic["SnType"].ToString());
  899. if (SnType == 0) dic["SnType"] = "兑换机具";
  900. if (SnType == 1) dic["SnType"] = "循环机具";
  901. //返利资格
  902. dic["RebateQual"] = dic["RebateQual"].ToString() == "1" ? "是" : "否";
  903. //激活类型
  904. int ActType = int.Parse(dic["ActType"].ToString());
  905. if (ActType == 0) dic["ActType"] = "正常激活";
  906. if (ActType == 1) dic["ActType"] = "首次已激活MPOS";
  907. if (ActType == 2) dic["ActType"] = "首次已激活KPOS";
  908. if (ActType == 3) dic["ActType"] = "循环机划拨激活";
  909. //商户状态
  910. int MerStatus = int.Parse(dic["MerStatus"].ToString());
  911. if (MerStatus == 0) dic["MerStatus"] = "正常";
  912. if (MerStatus == 1) dic["MerStatus"] = "冻结";
  913. if (MerStatus == 2) dic["MerStatus"] = "关闭";
  914. //商户激活状态
  915. int ActiveStatus = int.Parse(dic["ActiveStatus"].ToString());
  916. if (ActiveStatus == 0) dic["ActiveStatus"] = "未激活";
  917. if (ActiveStatus == 1) dic["ActiveStatus"] = "已激活";
  918. if (ActiveStatus == 2) dic["ActiveStatus"] = "SN已返现";
  919. //商户创客类型
  920. int MerUserType = int.Parse(dic["MerUserType"].ToString());
  921. if (MerUserType == 0) dic["MerUserType"] = "非商户型创客";
  922. if (MerUserType == 1) dic["MerUserType"] = "商户型创客";
  923. dic.Remove("UserId");
  924. dic.Remove("TopUserId");
  925. dic.Remove("MerUserId");
  926. dic.Remove("SnApplyUserId");
  927. dic.Remove("SnStoreId");
  928. }
  929. Dictionary<string, object> result = new Dictionary<string, object>();
  930. result.Add("Status", "1");
  931. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  932. result.Add("Obj", diclist);
  933. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  934. ReturnFields.Add("MerchantNo", "商户编号");
  935. ReturnFields.Add("MerchantName", "商户名称");
  936. ReturnFields.Add("MerchantMobile", "商户手机号");
  937. ReturnFields.Add("KqMerNo", "快钱商户编码");
  938. ReturnFields.Add("KqSnNo", "快钱SN号");
  939. ReturnFields.Add("SnType", "机具类型");
  940. ReturnFields.Add("RebateQual", "返利资格");
  941. ReturnFields.Add("ActType", "激活类型");
  942. ReturnFields.Add("MerStatus", "商户状态");
  943. ReturnFields.Add("ActiveStatus", "商户激活状态");
  944. ReturnFields.Add("MerMakerCode", "商户创客编码");
  945. ReturnFields.Add("MerRealName", "商户创客名称");
  946. ReturnFields.Add("MerUserType", "商户创客类型");
  947. ReturnFields.Add("MakerCode", "直属创客编号");
  948. ReturnFields.Add("RealName", "直属创客姓名");
  949. ReturnFields.Add("TopMakerCode", "顶级创客编码");
  950. ReturnFields.Add("TopRealName", "顶级创客名称");
  951. ReturnFields.Add("StoreNo", "SN仓库编号");
  952. ReturnFields.Add("StoreName", "SN仓库名称");
  953. ReturnFields.Add("SnApplyMakerCode", "申请创客编号");
  954. ReturnFields.Add("SnApplyRealName", "申请创客姓名");
  955. ReturnFields.Add("KqRegTime", "注册时间");
  956. result.Add("Fields", ReturnFields);
  957. AddSysLog("0", "PosMerchantInfo", "ExportExcel");
  958. return Json(result);
  959. }
  960. #endregion
  961. #region 首台机具查询
  962. /// <summary>
  963. /// 根据条件查询首台机具查询
  964. /// </summary>
  965. /// <returns></returns>
  966. public IActionResult FirstPosIndex(string right)
  967. {
  968. ViewBag.RightInfo = RightInfo;
  969. ViewBag.right = right;
  970. return View();
  971. }
  972. #endregion
  973. #region 根据条件查询首台机具查询
  974. /// <summary>
  975. /// 首台机具查询
  976. /// </summary>
  977. /// <returns></returns>
  978. public JsonResult FirstPosIndexData(string PosSn, int page = 1, int limit = 30)
  979. {
  980. // string condition = " and Id=0";
  981. // 机具sn、商户姓名、商户手机号、商户身份证号、绑定时间、激活时间、是否为首台机具、是否已变更、变更时间
  982. string conn = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  983. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  984. if (!string.IsNullOrEmpty(PosSn))
  985. {
  986. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Status > -1 && m.PosSn == PosSn) ?? new PosMachinesTwo();
  987. if (pos.BindMerchantId > 0)
  988. {
  989. var mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  990. if (mer.Id > 0)
  991. {
  992. string MerchantName = Regex.Replace(mer.MerchantName, @"\d|\W|[A-Za-z]", "");
  993. var posMerchants = db.PosMerchantInfo.Where(m => m.MerIdcardNo.ToUpper().StartsWith(mer.MerIdcardNo.ToUpper().Substring(0, 6)) && m.MerIdcardNo.ToUpper().EndsWith(mer.MerIdcardNo.ToUpper().Substring(mer.MerIdcardNo.Length - 4, 4)) && m.MerchantName.Contains(MerchantName)).ToList();
  994. foreach (var item in posMerchants)
  995. {
  996. Dictionary<string, object> curData = new Dictionary<string, object>();
  997. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == item.KqSnNo) ?? new PosMachinesTwo();
  998. int IsFirst = int.Parse(posInfo.IsFirst.ToString());
  999. var IsFirstName = "";
  1000. if (IsFirst == 1) IsFirstName = "首台";
  1001. if (IsFirst == 0) IsFirstName = "非首台";
  1002. curData.Add("PosSn", posInfo.PosSn); //机具Sn
  1003. curData.Add("MerchantName", item.MerchantName); //商户名称
  1004. curData.Add("MerchantMobile", item.MerchantMobile); //商户手机号
  1005. curData.Add("MerIdcardNo", item.MerIdcardNo); //商户身份证号
  1006. curData.Add("IsFirstName", IsFirstName); //是否首台
  1007. curData.Add("IsFirst", IsFirst);
  1008. curData.Add("BindingTime", string.IsNullOrEmpty(posInfo.BindingTime.ToString()) ? "" : Convert.ToDateTime(posInfo.BindingTime).ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  1009. curData.Add("ActivationTime", string.IsNullOrEmpty(posInfo.ActivationTime.ToString()) ? "" : Convert.ToDateTime(posInfo.ActivationTime).ToString("yyyy-MM-dd HH:mm:ss")); //激活时间
  1010. dataList.Add(curData);
  1011. }
  1012. }
  1013. }
  1014. }
  1015. Dictionary<string, object> obj = new Dictionary<string, object>();
  1016. obj.Add("code", 0);
  1017. obj.Add("msg", "");
  1018. obj.Add("count", dataList.Count);
  1019. obj.Add("data", dataList);
  1020. return Json(obj);
  1021. }
  1022. #endregion
  1023. #region 设置为首台机具
  1024. /// <summary>
  1025. /// 设置为首台机具
  1026. /// </summary>
  1027. /// <returns></returns>
  1028. public string SetFirstPos(string PosSn)
  1029. {
  1030. Dictionary<string, object> Fields = new Dictionary<string, object>();
  1031. var mer = db.PosMerchantInfo.FirstOrDefault(m => m.KqSnNo == PosSn) ?? new PosMerchantInfo();
  1032. string MerchantName = Regex.Replace(mer.MerchantName, @"\d|\W|[A-Za-z]", "");
  1033. var posMerchants = db.PosMerchantInfo.Where(m => m.MerIdcardNo.ToUpper().StartsWith(mer.MerIdcardNo.ToUpper().Substring(0, 6)) && m.MerIdcardNo.ToUpper().EndsWith(mer.MerIdcardNo.ToUpper().Substring(mer.MerIdcardNo.Length - 4, 4)) && m.MerchantName.Contains(MerchantName) && m.KqSnNo != PosSn).ToList();
  1034. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn) ?? new PosMachinesTwo();
  1035. var thisdate = pos.BindingTime;
  1036. var otherdate = pos.BindingTime;
  1037. var changeFlag = 0;
  1038. foreach (var item in posMerchants)
  1039. {
  1040. Dictionary<string, object> curData = new Dictionary<string, object>();
  1041. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == item.KqSnNo) ?? new PosMachinesTwo();
  1042. otherdate = posInfo.BindingTime;
  1043. if (thisdate < otherdate)
  1044. {
  1045. changeFlag = 1;
  1046. posInfo.IsFirst = 0;
  1047. }
  1048. else
  1049. {
  1050. return "不符合设置条件";
  1051. }
  1052. }
  1053. if (changeFlag == 1)
  1054. {
  1055. AddSysLog(PosSn, "PosMachinesTwo", "SetFirstPos");
  1056. pos.IsFirst = 1;
  1057. db.SaveChanges();
  1058. }
  1059. return "success";
  1060. }
  1061. #endregion
  1062. #region 同步交易额
  1063. public IActionResult SycnTradeAmount(string right, int Id = 0)
  1064. {
  1065. ViewBag.RightInfo = RightInfo;
  1066. ViewBag.right = right;
  1067. PosMerchantInfo editData = db.PosMerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new PosMerchantInfo();
  1068. ViewBag.data = editData;
  1069. return View();
  1070. }
  1071. #endregion
  1072. #region 同步交易额
  1073. [HttpPost]
  1074. public string SycnTradeAmountDo(DateTime sdate, DateTime edate, int MerchantId)
  1075. {
  1076. if (sdate.AddMonths(1) < edate)
  1077. {
  1078. return "时间间隔不能超过1个月";
  1079. }
  1080. if (edate >= DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00"))
  1081. {
  1082. return "结束时间只能是今天之前";
  1083. }
  1084. string check = RedisDbconn.Instance.Get<string>("ResetMerchantTradeQueue:" + MerchantId);
  1085. if (!string.IsNullOrEmpty(check))
  1086. {
  1087. return "请稍后再试";
  1088. }
  1089. try
  1090. {
  1091. RedisDbconn.Instance.AddList("ResetMerchantTradeQueue", MerchantId + "#cut#" + sdate.ToString("yyyy-MM-dd HH:mm:ss") + "#cut#" + edate.ToString("yyyy-MM-dd HH:mm:ss"));
  1092. RedisDbconn.Instance.Set("ResetMerchantTradeQueue:" + MerchantId, "wait");
  1093. RedisDbconn.Instance.SetExpire("ResetMerchantTradeQueue:" + MerchantId, 3600);
  1094. }
  1095. catch (Exception ex)
  1096. {
  1097. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计商户的交易额异常");
  1098. return "同步异常";
  1099. }
  1100. return "success";
  1101. }
  1102. #endregion
  1103. }
  1104. }