PosMerchantInfoListController.cs 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  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 = item["BrandId"].ToString();
  504. var PosSn = item["PosSn"].ToString();
  505. var SeoKeyword = item["SeoKeyword"].ToString();
  506. if (BrandId != "2" && BrandId != "7")
  507. {
  508. SeoKeyword = (decimal.Parse(SeoKeyword) / 100).ToString();
  509. }
  510. amount += decimal.Parse(SeoKeyword);
  511. var KqMerNo = item["KqMerNo"].ToString();
  512. var IdcardNo = item["MerIdcardNo"].ToString();
  513. var MerchantName = item["MerchantName"].ToString();
  514. var Mobile = item["MerchantMobile"].ToString();
  515. Dictionary<string, object> datas = new Dictionary<string, object>();
  516. datas.Add("Id", BindMerchantId);
  517. datas.Add("PosSn", PosSn);
  518. datas.Add("SeoKeyword", SeoKeyword);
  519. datas.Add("KqMerNo", KqMerNo);
  520. datas.Add("IdcardNo", IdcardNo);
  521. datas.Add("MerchantName", MerchantName);
  522. datas.Add("MerchantMobile", Mobile);
  523. diclist.Add(datas);
  524. }
  525. }
  526. Dictionary<string, object> obj = new Dictionary<string, object>();
  527. Dictionary<string, object> other = new Dictionary<string, object>();
  528. var ReturnAmount = amount;
  529. var fReturnAmount = amount * 0.92M;
  530. other.Add("ReturnAmount", ReturnAmount.ToString("f2"));
  531. other.Add("fReturnAmount", fReturnAmount.ToString("f2"));
  532. obj.Add("other", other);
  533. obj.Add("code", 0);
  534. obj.Add("msg", "");
  535. obj.Add("count", diclist.Count);
  536. obj.Add("data", diclist);
  537. return Json(obj);
  538. }
  539. #endregion
  540. #region 非首台达标商户列表
  541. /// <summary>
  542. /// 非首台达标商户列表
  543. /// </summary>
  544. /// <returns></returns>
  545. public IActionResult Indexnfs(string right)
  546. {
  547. ViewBag.RightInfo = RightInfo;
  548. ViewBag.right = right;
  549. return View();
  550. }
  551. #endregion
  552. #region 根据条件查询非首台达标商户列表
  553. /// <summary>
  554. /// 根据条件查询非首台达标商户列表
  555. /// </summary>
  556. /// <returns></returns>
  557. public IActionResult IndexnfsData(string MerchantMobile, string KqSnNo, string MerIdcardNo, int page = 1, int limit = 30)
  558. {
  559. string condition = "";
  560. if (!string.IsNullOrEmpty(MerchantMobile))
  561. {
  562. condition += " and b.MerchantMobile like '%" + MerchantMobile + "%'";
  563. }
  564. if (!string.IsNullOrEmpty(KqSnNo))
  565. {
  566. condition += " and b.KqSnNo like '%" + KqSnNo + "%'";
  567. }
  568. if (!string.IsNullOrEmpty(MerIdcardNo))
  569. {
  570. condition += " and b.MerIdcardNo like '%" + MerIdcardNo + "%'";
  571. }
  572. var amount = 0.00M;
  573. List<Dictionary<string, object>> diclist = new List<Dictionary<string, object>>();
  574. 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);
  575. if (dt.Rows.Count > 0)
  576. {
  577. foreach (DataRow item in dt.Rows)
  578. {
  579. var BindMerchantId = item["BindMerchantId"].ToString();
  580. var BrandId = item["BrandId"].ToString();
  581. var PosSn = item["PosSn"].ToString();
  582. var SeoKeyword = item["SeoKeyword"].ToString();
  583. if (BrandId != "2" && BrandId != "7")
  584. {
  585. SeoKeyword = (decimal.Parse(SeoKeyword) / 100).ToString();
  586. }
  587. amount += decimal.Parse(SeoKeyword);
  588. var KqMerNo = item["KqMerNo"].ToString();
  589. var IdcardNo = item["MerIdcardNo"].ToString();
  590. var MerchantName = item["MerchantName"].ToString();
  591. var Mobile = item["MerchantMobile"].ToString();
  592. Dictionary<string, object> datas = new Dictionary<string, object>();
  593. datas.Add("Id", BindMerchantId);
  594. datas.Add("PosSn", PosSn);
  595. datas.Add("SeoKeyword", SeoKeyword);
  596. datas.Add("KqMerNo", KqMerNo);
  597. datas.Add("IdcardNo", IdcardNo);
  598. datas.Add("MerchantName", MerchantName);
  599. datas.Add("MerchantMobile", Mobile);
  600. diclist.Add(datas);
  601. }
  602. }
  603. Dictionary<string, object> obj = new Dictionary<string, object>();
  604. Dictionary<string, object> other = new Dictionary<string, object>();
  605. var ReturnAmount = amount;
  606. var fReturnAmount = amount * 0.92M;
  607. other.Add("ReturnAmount", ReturnAmount.ToString("f2"));
  608. other.Add("fReturnAmount", fReturnAmount.ToString("f2"));
  609. obj.Add("other", other);
  610. obj.Add("code", 0);
  611. obj.Add("msg", "");
  612. obj.Add("count", diclist.Count);
  613. obj.Add("data", diclist);
  614. return Json(obj);
  615. }
  616. #endregion
  617. #region 批量通过
  618. /// <summary>
  619. /// 批量通过
  620. /// </summary>
  621. /// <returns></returns>
  622. public string BatchSetting(string Id)
  623. {
  624. string[] idlist = Id.Split(new char[] { ',' });
  625. AddSysLog(Id, "PosMerchantInfo", "BatchSetting");
  626. var Ids = "";//商户Id
  627. foreach (string subid in idlist)
  628. {
  629. int id = int.Parse(subid);
  630. Ids += id + ",";
  631. Dictionary<string, object> Fields = new Dictionary<string, object>();
  632. Fields.Add("StandardStatus", 101);//设置为可退押状态
  633. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  634. }
  635. string text = string.Format("商户押金退还批量通过,商户Id: '" + Ids.TrimEnd(',') + "',操作人: '" + SysUserName + "_" + SysRealName + "',Time'" + DateTime.Now + "'");
  636. function.WriteLog(text, "商户押金退还批量通过");
  637. db.SaveChanges();
  638. return "success";
  639. }
  640. #endregion
  641. #region 增加商户
  642. /// <summary>
  643. /// 增加或修改商户信息
  644. /// </summary>
  645. /// <returns></returns>
  646. public IActionResult Add(string right)
  647. {
  648. ViewBag.RightInfo = RightInfo;
  649. ViewBag.right = right;
  650. return View();
  651. }
  652. #endregion
  653. #region 增加商户
  654. /// <summary>
  655. /// 增加或修改商户信息
  656. /// </summary>
  657. /// <returns></returns>
  658. [HttpPost]
  659. public string Add(PosMerchantInfo data)
  660. {
  661. Dictionary<string, object> Fields = new Dictionary<string, object>();
  662. Fields.Add("SeoTitle", data.SeoTitle);
  663. Fields.Add("SeoKeyword", data.SeoKeyword);
  664. Fields.Add("SeoDescription", data.SeoDescription);
  665. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("PosMerchantInfo", Fields, 0);
  666. AddSysLog(data.Id.ToString(), "PosMerchantInfo", "add");
  667. db.SaveChanges();
  668. return "success";
  669. }
  670. #endregion
  671. #region 修改商户
  672. /// <summary>
  673. /// 增加或修改商户信息
  674. /// </summary>
  675. /// <returns></returns>
  676. public IActionResult Edit(string right, int Id = 0)
  677. {
  678. ViewBag.RightInfo = RightInfo;
  679. ViewBag.right = right;
  680. PosMerchantInfo editData = db.PosMerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new PosMerchantInfo();
  681. ViewBag.data = editData;
  682. return View();
  683. }
  684. #endregion
  685. #region 修改商户
  686. /// <summary>
  687. /// 增加或修改商户信息
  688. /// </summary>
  689. /// <returns></returns>
  690. [HttpPost]
  691. public string Edit(PosMerchantInfo data)
  692. {
  693. Dictionary<string, object> Fields = new Dictionary<string, object>();
  694. Fields.Add("SeoTitle", data.SeoTitle);
  695. Fields.Add("SeoKeyword", data.SeoKeyword);
  696. Fields.Add("SeoDescription", data.SeoDescription);
  697. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, data.Id);
  698. AddSysLog(data.Id.ToString(), "PosMerchantInfo", "update");
  699. db.SaveChanges();
  700. return "success";
  701. }
  702. #endregion
  703. #region 删除商户信息
  704. /// <summary>
  705. /// 删除商户信息
  706. /// </summary>
  707. /// <returns></returns>
  708. public string Delete(string Id)
  709. {
  710. string[] idlist = Id.Split(new char[] { ',' });
  711. AddSysLog(Id, "PosMerchantInfo", "del");
  712. foreach (string subid in idlist)
  713. {
  714. int id = int.Parse(subid);
  715. Dictionary<string, object> Fields = new Dictionary<string, object>();
  716. Fields.Add("Status", -1);
  717. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  718. }
  719. db.SaveChanges();
  720. return "success";
  721. }
  722. #endregion
  723. #region 开启
  724. /// <summary>
  725. /// 开启
  726. /// </summary>
  727. /// <returns></returns>
  728. public string Open(string Id)
  729. {
  730. string[] idlist = Id.Split(new char[] { ',' });
  731. AddSysLog(Id, "PosMerchantInfo", "open");
  732. foreach (string subid in idlist)
  733. {
  734. int id = int.Parse(subid);
  735. Dictionary<string, object> Fields = new Dictionary<string, object>();
  736. Fields.Add("Status", 1);
  737. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  738. }
  739. db.SaveChanges();
  740. return "success";
  741. }
  742. #endregion
  743. #region 关闭
  744. /// <summary>
  745. /// 关闭
  746. /// </summary>
  747. /// <returns></returns>
  748. public string Close(string Id)
  749. {
  750. string[] idlist = Id.Split(new char[] { ',' });
  751. AddSysLog(Id, "PosMerchantInfo", "close");
  752. foreach (string subid in idlist)
  753. {
  754. int id = int.Parse(subid);
  755. Dictionary<string, object> Fields = new Dictionary<string, object>();
  756. Fields.Add("Status", 0);
  757. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  758. }
  759. db.SaveChanges();
  760. return "success";
  761. }
  762. #endregion
  763. #region 排序
  764. /// <summary>
  765. /// 排序
  766. /// </summary>
  767. /// <param name="Id"></param>
  768. public string Sort(int Id, int Sort)
  769. {
  770. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("PosMerchantInfo", Sort, Id);
  771. AddSysLog(Id.ToString(), "PosMerchantInfo", "sort");
  772. return "success";
  773. }
  774. #endregion
  775. #region 导入数据
  776. /// <summary>
  777. /// 导入数据
  778. /// </summary>
  779. /// <param name="ExcelData"></param>
  780. public string Import(string ExcelData)
  781. {
  782. ExcelData = HttpUtility.UrlDecode(ExcelData);
  783. JsonData list = JsonMapper.ToObject(ExcelData);
  784. var Ids = "";
  785. for (int i = 1; i < list.Count; i++)
  786. {
  787. JsonData dr = list[i];
  788. string KqMerNo = dr[0].ToString(); // 商户编号
  789. string Amount = dr[1].ToString(); // 已退金额
  790. string KqRegTime = dr[2].ToString(); // 退还时间
  791. var posMerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == KqMerNo) ?? new PosMerchantInfo();
  792. posMerchantInfo.StandardStatus = -2;
  793. posMerchantInfo.Remark = Amount;
  794. posMerchantInfo.KqRegTime = DateTime.Parse(KqRegTime);
  795. Ids += posMerchantInfo.Id + "_" + Amount + ",";
  796. db.SaveChanges();
  797. }
  798. AddSysLog("0", "PosMerchantInfo", "Import");
  799. string text = string.Format("导入人工已退,商户Id: '" + Ids.TrimEnd(',') + "',操作人: '" + SysUserName + "_" + SysRealName + "',Time'" + DateTime.Now + "'");
  800. function.WriteLog(text, "导入人工已退");
  801. return "success";
  802. }
  803. #endregion
  804. #region 导出Excel
  805. /// <summary>
  806. /// 导出Excel
  807. /// </summary>
  808. /// <returns></returns>
  809. public JsonResult ExportExcel(PosMerchantInfo data, string MakerCode, string RealName, string MerMakerCode, string StoreNo, string StoreName, string MerStatusSelect, string ActiveStatusSelect, string ActTypeSelect, string MerUserTypeSelect)
  810. {
  811. Dictionary<string, string> Fields = new Dictionary<string, string>();
  812. Fields.Add("BrandId", "1");
  813. Fields.Add("MerchantNo", "1"); //商户编号
  814. Fields.Add("MerchantName", "1"); //商户姓名
  815. Fields.Add("MerchantMobile", "1"); //商户手机号
  816. Fields.Add("KqMerNo", "1"); //快钱商户编码
  817. Fields.Add("KqSnNo", "1"); //快钱SN号
  818. Fields.Add("KqRegTime", "3"); //渠道注册时间
  819. Fields.Add("TopUserId", "0"); //顶级创客
  820. string condition = " and Status>-1";
  821. //创客编号
  822. if (!string.IsNullOrEmpty(MakerCode))
  823. {
  824. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  825. }
  826. //创客名称
  827. if (!string.IsNullOrEmpty(RealName))
  828. {
  829. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  830. }
  831. //商户创客编号
  832. if (!string.IsNullOrEmpty(MerMakerCode))
  833. {
  834. condition += " and MerUserId in (select UserId from UserForMakerCode where MakerCode='" + MerMakerCode + "')";
  835. }
  836. //仓库编号
  837. if (!string.IsNullOrEmpty(StoreNo))
  838. {
  839. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreNo + "')";
  840. }
  841. //仓库名称
  842. if (!string.IsNullOrEmpty(RealName))
  843. {
  844. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreName + "')";
  845. }
  846. //商户状态
  847. if (!string.IsNullOrEmpty(MerStatusSelect))
  848. {
  849. condition += " and MerStatus=" + MerStatusSelect;
  850. }
  851. //商户激活状态
  852. if (!string.IsNullOrEmpty(ActiveStatusSelect))
  853. {
  854. condition += " and ActiveStatus=" + ActiveStatusSelect;
  855. }
  856. //激活类型
  857. if (!string.IsNullOrEmpty(ActTypeSelect))
  858. {
  859. condition += " and ActType=" + ActTypeSelect;
  860. }
  861. //商户创客类型
  862. if (!string.IsNullOrEmpty(MerUserTypeSelect))
  863. {
  864. condition += " and MerUserType=" + MerUserTypeSelect;
  865. }
  866. 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);
  867. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  868. foreach (Dictionary<string, object> dic in diclist)
  869. {
  870. //直属创客
  871. int UserId = int.Parse(dic["UserId"].ToString());
  872. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  873. dic["MakerCode"] = puser.MakerCode;
  874. dic["RealName"] = puser.RealName;
  875. //顶级创客
  876. int TopUserId = int.Parse(dic["TopUserId"].ToString());
  877. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  878. dic["TopMakerCode"] = tuser.MakerCode;
  879. dic["TopRealName"] = tuser.RealName;
  880. //商户创客
  881. int MerUserId = int.Parse(dic["MerUserId"].ToString());
  882. Users muser = db.Users.FirstOrDefault(m => m.Id == MerUserId) ?? new Users();
  883. dic["MerMakerCode"] = muser.MakerCode;
  884. dic["MerRealName"] = muser.RealName;
  885. //申请创客
  886. int SnApplyUserId = int.Parse(dic["SnApplyUserId"].ToString());
  887. Users snuser = db.Users.FirstOrDefault(m => m.Id == SnApplyUserId) ?? new Users();
  888. dic["SnApplyMakerCode"] = snuser.MakerCode;
  889. dic["SnApplyRealName"] = snuser.RealName;
  890. //SN仓库
  891. int SnStoreId = int.Parse(dic["SnStoreId"].ToString());
  892. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == SnStoreId) ?? new StoreHouse();
  893. dic["StoreNo"] = store.StoreNo;
  894. dic["StoreName"] = store.StoreName;
  895. //机具类型
  896. int SnType = int.Parse(dic["SnType"].ToString());
  897. if (SnType == 0) dic["SnType"] = "兑换机具";
  898. if (SnType == 1) dic["SnType"] = "循环机具";
  899. //返利资格
  900. dic["RebateQual"] = dic["RebateQual"].ToString() == "1" ? "是" : "否";
  901. //激活类型
  902. int ActType = int.Parse(dic["ActType"].ToString());
  903. if (ActType == 0) dic["ActType"] = "正常激活";
  904. if (ActType == 1) dic["ActType"] = "首次已激活MPOS";
  905. if (ActType == 2) dic["ActType"] = "首次已激活KPOS";
  906. if (ActType == 3) dic["ActType"] = "循环机划拨激活";
  907. //商户状态
  908. int MerStatus = int.Parse(dic["MerStatus"].ToString());
  909. if (MerStatus == 0) dic["MerStatus"] = "正常";
  910. if (MerStatus == 1) dic["MerStatus"] = "冻结";
  911. if (MerStatus == 2) dic["MerStatus"] = "关闭";
  912. //商户激活状态
  913. int ActiveStatus = int.Parse(dic["ActiveStatus"].ToString());
  914. if (ActiveStatus == 0) dic["ActiveStatus"] = "未激活";
  915. if (ActiveStatus == 1) dic["ActiveStatus"] = "已激活";
  916. if (ActiveStatus == 2) dic["ActiveStatus"] = "SN已返现";
  917. //商户创客类型
  918. int MerUserType = int.Parse(dic["MerUserType"].ToString());
  919. if (MerUserType == 0) dic["MerUserType"] = "非商户型创客";
  920. if (MerUserType == 1) dic["MerUserType"] = "商户型创客";
  921. dic.Remove("UserId");
  922. dic.Remove("TopUserId");
  923. dic.Remove("MerUserId");
  924. dic.Remove("SnApplyUserId");
  925. dic.Remove("SnStoreId");
  926. }
  927. Dictionary<string, object> result = new Dictionary<string, object>();
  928. result.Add("Status", "1");
  929. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  930. result.Add("Obj", diclist);
  931. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  932. ReturnFields.Add("MerchantNo", "商户编号");
  933. ReturnFields.Add("MerchantName", "商户名称");
  934. ReturnFields.Add("MerchantMobile", "商户手机号");
  935. ReturnFields.Add("KqMerNo", "快钱商户编码");
  936. ReturnFields.Add("KqSnNo", "快钱SN号");
  937. ReturnFields.Add("SnType", "机具类型");
  938. ReturnFields.Add("RebateQual", "返利资格");
  939. ReturnFields.Add("ActType", "激活类型");
  940. ReturnFields.Add("MerStatus", "商户状态");
  941. ReturnFields.Add("ActiveStatus", "商户激活状态");
  942. ReturnFields.Add("MerMakerCode", "商户创客编码");
  943. ReturnFields.Add("MerRealName", "商户创客名称");
  944. ReturnFields.Add("MerUserType", "商户创客类型");
  945. ReturnFields.Add("MakerCode", "直属创客编号");
  946. ReturnFields.Add("RealName", "直属创客姓名");
  947. ReturnFields.Add("TopMakerCode", "顶级创客编码");
  948. ReturnFields.Add("TopRealName", "顶级创客名称");
  949. ReturnFields.Add("StoreNo", "SN仓库编号");
  950. ReturnFields.Add("StoreName", "SN仓库名称");
  951. ReturnFields.Add("SnApplyMakerCode", "申请创客编号");
  952. ReturnFields.Add("SnApplyRealName", "申请创客姓名");
  953. ReturnFields.Add("KqRegTime", "注册时间");
  954. result.Add("Fields", ReturnFields);
  955. AddSysLog("0", "PosMerchantInfo", "ExportExcel");
  956. return Json(result);
  957. }
  958. #endregion
  959. #region 首台机具查询
  960. /// <summary>
  961. /// 根据条件查询首台机具查询
  962. /// </summary>
  963. /// <returns></returns>
  964. public IActionResult FirstPosIndex(string right)
  965. {
  966. ViewBag.RightInfo = RightInfo;
  967. ViewBag.right = right;
  968. return View();
  969. }
  970. #endregion
  971. #region 根据条件查询首台机具查询
  972. /// <summary>
  973. /// 首台机具查询
  974. /// </summary>
  975. /// <returns></returns>
  976. public JsonResult FirstPosIndexData(string PosSn, int page = 1, int limit = 30)
  977. {
  978. // string condition = " and Id=0";
  979. // 机具sn、商户姓名、商户手机号、商户身份证号、绑定时间、激活时间、是否为首台机具、是否已变更、变更时间
  980. string conn = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  981. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  982. if (!string.IsNullOrEmpty(PosSn))
  983. {
  984. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Status > -1 && m.PosSn == PosSn) ?? new PosMachinesTwo();
  985. if (pos.BindMerchantId > 0)
  986. {
  987. var mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  988. if (mer.Id > 0)
  989. {
  990. string MerchantName = Regex.Replace(mer.MerchantName, @"\d|\W|[A-Za-z]", "");
  991. 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();
  992. foreach (var item in posMerchants)
  993. {
  994. Dictionary<string, object> curData = new Dictionary<string, object>();
  995. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == item.KqSnNo) ?? new PosMachinesTwo();
  996. int IsFirst = int.Parse(posInfo.IsFirst.ToString());
  997. var IsFirstName = "";
  998. if (IsFirst == 1) IsFirstName = "首台";
  999. if (IsFirst == 0) IsFirstName = "非首台";
  1000. curData.Add("PosSn", posInfo.PosSn); //机具Sn
  1001. curData.Add("MerchantName", item.MerchantName); //商户名称
  1002. curData.Add("MerchantMobile", item.MerchantMobile); //商户手机号
  1003. curData.Add("MerIdcardNo", item.MerIdcardNo); //商户身份证号
  1004. curData.Add("IsFirstName", IsFirstName); //是否首台
  1005. curData.Add("IsFirst", IsFirst);
  1006. curData.Add("BindingTime", string.IsNullOrEmpty(posInfo.BindingTime.ToString()) ? "" : Convert.ToDateTime(posInfo.BindingTime).ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  1007. curData.Add("ActivationTime", string.IsNullOrEmpty(posInfo.ActivationTime.ToString()) ? "" : Convert.ToDateTime(posInfo.ActivationTime).ToString("yyyy-MM-dd HH:mm:ss")); //激活时间
  1008. dataList.Add(curData);
  1009. }
  1010. }
  1011. }
  1012. }
  1013. Dictionary<string, object> obj = new Dictionary<string, object>();
  1014. obj.Add("code", 0);
  1015. obj.Add("msg", "");
  1016. obj.Add("count", dataList.Count);
  1017. obj.Add("data", dataList);
  1018. return Json(obj);
  1019. }
  1020. #endregion
  1021. #region 设置为首台机具
  1022. /// <summary>
  1023. /// 设置为首台机具
  1024. /// </summary>
  1025. /// <returns></returns>
  1026. public string SetFirstPos(string PosSn)
  1027. {
  1028. Dictionary<string, object> Fields = new Dictionary<string, object>();
  1029. var mer = db.PosMerchantInfo.FirstOrDefault(m => m.KqSnNo == PosSn) ?? new PosMerchantInfo();
  1030. string MerchantName = Regex.Replace(mer.MerchantName, @"\d|\W|[A-Za-z]", "");
  1031. 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();
  1032. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn) ?? new PosMachinesTwo();
  1033. var thisdate = pos.BindingTime;
  1034. var otherdate = pos.BindingTime;
  1035. var changeFlag = 0;
  1036. foreach (var item in posMerchants)
  1037. {
  1038. Dictionary<string, object> curData = new Dictionary<string, object>();
  1039. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == item.KqSnNo) ?? new PosMachinesTwo();
  1040. otherdate = posInfo.BindingTime;
  1041. if (thisdate < otherdate)
  1042. {
  1043. changeFlag = 1;
  1044. posInfo.IsFirst = 0;
  1045. }
  1046. else
  1047. {
  1048. return "不符合设置条件";
  1049. }
  1050. }
  1051. if (changeFlag == 1)
  1052. {
  1053. AddSysLog(PosSn, "PosMachinesTwo", "SetFirstPos");
  1054. pos.IsFirst = 1;
  1055. db.SaveChanges();
  1056. }
  1057. return "success";
  1058. }
  1059. #endregion
  1060. #region 同步交易额
  1061. public IActionResult SycnTradeAmount(string right, int Id = 0)
  1062. {
  1063. ViewBag.RightInfo = RightInfo;
  1064. ViewBag.right = right;
  1065. PosMerchantInfo editData = db.PosMerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new PosMerchantInfo();
  1066. ViewBag.data = editData;
  1067. return View();
  1068. }
  1069. #endregion
  1070. #region 同步交易额
  1071. [HttpPost]
  1072. public string SycnTradeAmountDo(DateTime sdate, DateTime edate, int MerchantId)
  1073. {
  1074. if (sdate.AddMonths(1) < edate)
  1075. {
  1076. return "时间间隔不能超过1个月";
  1077. }
  1078. if (edate >= DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00"))
  1079. {
  1080. return "结束时间只能是今天之前";
  1081. }
  1082. string check = RedisDbconn.Instance.Get<string>("ResetMerchantTradeQueue:" + MerchantId);
  1083. if (!string.IsNullOrEmpty(check))
  1084. {
  1085. return "请稍后再试";
  1086. }
  1087. try
  1088. {
  1089. RedisDbconn.Instance.AddList("ResetMerchantTradeQueue", MerchantId + "#cut#" + sdate.ToString("yyyy-MM-dd HH:mm:ss") + "#cut#" + edate.ToString("yyyy-MM-dd HH:mm:ss"));
  1090. RedisDbconn.Instance.Set("ResetMerchantTradeQueue:" + MerchantId, "wait");
  1091. RedisDbconn.Instance.SetExpire("ResetMerchantTradeQueue:" + MerchantId, 3600);
  1092. }
  1093. catch (Exception ex)
  1094. {
  1095. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计商户的交易额异常");
  1096. return "同步异常";
  1097. }
  1098. return "success";
  1099. }
  1100. #endregion
  1101. }
  1102. }