PosMerchantInfoListController.cs 54 KB

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