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 = 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. Fields.Add("MatchTime", DateTime.Now);//设置入口开放时间
  624. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  625. }
  626. string text = string.Format("商户押金退还批量通过,商户Id: '" + Ids.TrimEnd(',') + "',操作人: '" + SysUserName + "_" + SysRealName + "',Time'" + DateTime.Now + "'");
  627. function.WriteLog(text, "商户押金退还批量通过");
  628. db.SaveChanges();
  629. return "success";
  630. }
  631. #endregion
  632. #region 增加商户
  633. /// <summary>
  634. /// 增加或修改商户信息
  635. /// </summary>
  636. /// <returns></returns>
  637. public IActionResult Add(string right)
  638. {
  639. ViewBag.RightInfo = RightInfo;
  640. ViewBag.right = right;
  641. return View();
  642. }
  643. #endregion
  644. #region 增加商户
  645. /// <summary>
  646. /// 增加或修改商户信息
  647. /// </summary>
  648. /// <returns></returns>
  649. [HttpPost]
  650. public string Add(PosMerchantInfo data)
  651. {
  652. Dictionary<string, object> Fields = new Dictionary<string, object>();
  653. Fields.Add("SeoTitle", data.SeoTitle);
  654. Fields.Add("SeoKeyword", data.SeoKeyword);
  655. Fields.Add("SeoDescription", data.SeoDescription);
  656. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("PosMerchantInfo", Fields, 0);
  657. AddSysLog(data.Id.ToString(), "PosMerchantInfo", "add");
  658. db.SaveChanges();
  659. return "success";
  660. }
  661. #endregion
  662. #region 修改商户
  663. /// <summary>
  664. /// 增加或修改商户信息
  665. /// </summary>
  666. /// <returns></returns>
  667. public IActionResult Edit(string right, int Id = 0)
  668. {
  669. ViewBag.RightInfo = RightInfo;
  670. ViewBag.right = right;
  671. PosMerchantInfo editData = db.PosMerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new PosMerchantInfo();
  672. ViewBag.data = editData;
  673. return View();
  674. }
  675. #endregion
  676. #region 修改商户
  677. /// <summary>
  678. /// 增加或修改商户信息
  679. /// </summary>
  680. /// <returns></returns>
  681. [HttpPost]
  682. public string Edit(PosMerchantInfo data)
  683. {
  684. Dictionary<string, object> Fields = new Dictionary<string, object>();
  685. Fields.Add("SeoTitle", data.SeoTitle);
  686. Fields.Add("SeoKeyword", data.SeoKeyword);
  687. Fields.Add("SeoDescription", data.SeoDescription);
  688. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, data.Id);
  689. AddSysLog(data.Id.ToString(), "PosMerchantInfo", "update");
  690. db.SaveChanges();
  691. return "success";
  692. }
  693. #endregion
  694. #region 删除商户信息
  695. /// <summary>
  696. /// 删除商户信息
  697. /// </summary>
  698. /// <returns></returns>
  699. public string Delete(string Id)
  700. {
  701. string[] idlist = Id.Split(new char[] { ',' });
  702. AddSysLog(Id, "PosMerchantInfo", "del");
  703. foreach (string subid in idlist)
  704. {
  705. int id = int.Parse(subid);
  706. Dictionary<string, object> Fields = new Dictionary<string, object>();
  707. Fields.Add("Status", -1);
  708. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  709. }
  710. db.SaveChanges();
  711. return "success";
  712. }
  713. #endregion
  714. #region 开启
  715. /// <summary>
  716. /// 开启
  717. /// </summary>
  718. /// <returns></returns>
  719. public string Open(string Id)
  720. {
  721. string[] idlist = Id.Split(new char[] { ',' });
  722. AddSysLog(Id, "PosMerchantInfo", "open");
  723. foreach (string subid in idlist)
  724. {
  725. int id = int.Parse(subid);
  726. Dictionary<string, object> Fields = new Dictionary<string, object>();
  727. Fields.Add("Status", 1);
  728. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  729. }
  730. db.SaveChanges();
  731. return "success";
  732. }
  733. #endregion
  734. #region 关闭
  735. /// <summary>
  736. /// 关闭
  737. /// </summary>
  738. /// <returns></returns>
  739. public string Close(string Id)
  740. {
  741. string[] idlist = Id.Split(new char[] { ',' });
  742. AddSysLog(Id, "PosMerchantInfo", "close");
  743. foreach (string subid in idlist)
  744. {
  745. int id = int.Parse(subid);
  746. Dictionary<string, object> Fields = new Dictionary<string, object>();
  747. Fields.Add("Status", 0);
  748. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  749. }
  750. db.SaveChanges();
  751. return "success";
  752. }
  753. #endregion
  754. #region 排序
  755. /// <summary>
  756. /// 排序
  757. /// </summary>
  758. /// <param name="Id"></param>
  759. public string Sort(int Id, int Sort)
  760. {
  761. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("PosMerchantInfo", Sort, Id);
  762. AddSysLog(Id.ToString(), "PosMerchantInfo", "sort");
  763. return "success";
  764. }
  765. #endregion
  766. #region 导入数据
  767. /// <summary>
  768. /// 导入数据
  769. /// </summary>
  770. /// <param name="ExcelData"></param>
  771. public string Import(string ExcelData)
  772. {
  773. ExcelData = HttpUtility.UrlDecode(ExcelData);
  774. JsonData list = JsonMapper.ToObject(ExcelData);
  775. var Ids = "";
  776. for (int i = 1; i < list.Count; i++)
  777. {
  778. JsonData dr = list[i];
  779. string KqMerNo = dr[0].ToString(); // 商户编号
  780. string Amount = dr[1].ToString(); // 已退金额
  781. string KqRegTime = dr[2].ToString(); // 退还时间
  782. var posMerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == KqMerNo) ?? new PosMerchantInfo();
  783. posMerchantInfo.StandardStatus = -2;
  784. posMerchantInfo.Remark = Amount;
  785. posMerchantInfo.KqRegTime = DateTime.Parse(KqRegTime);
  786. Ids += posMerchantInfo.Id + "_" + Amount + ",";
  787. db.SaveChanges();
  788. }
  789. AddSysLog("0", "PosMerchantInfo", "Import");
  790. string text = string.Format("导入人工已退,商户Id: '" + Ids.TrimEnd(',') + "',操作人: '" + SysUserName + "_" + SysRealName + "',Time'" + DateTime.Now + "'");
  791. function.WriteLog(text, "导入人工已退");
  792. return "success";
  793. }
  794. #endregion
  795. #region 导出Excel
  796. /// <summary>
  797. /// 导出Excel
  798. /// </summary>
  799. /// <returns></returns>
  800. public JsonResult ExportExcel(PosMerchantInfo data, string MakerCode, string RealName, string MerMakerCode, string StoreNo, string StoreName, string MerStatusSelect, string ActiveStatusSelect, string ActTypeSelect, string MerUserTypeSelect)
  801. {
  802. Dictionary<string, string> Fields = new Dictionary<string, string>();
  803. Fields.Add("BrandId", "1");
  804. Fields.Add("MerchantNo", "1"); //商户编号
  805. Fields.Add("MerchantName", "1"); //商户姓名
  806. Fields.Add("MerchantMobile", "1"); //商户手机号
  807. Fields.Add("KqMerNo", "1"); //快钱商户编码
  808. Fields.Add("KqSnNo", "1"); //快钱SN号
  809. Fields.Add("KqRegTime", "3"); //渠道注册时间
  810. Fields.Add("TopUserId", "0"); //顶级创客
  811. string condition = " and Status>-1";
  812. //创客编号
  813. if (!string.IsNullOrEmpty(MakerCode))
  814. {
  815. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  816. }
  817. //创客名称
  818. if (!string.IsNullOrEmpty(RealName))
  819. {
  820. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  821. }
  822. //商户创客编号
  823. if (!string.IsNullOrEmpty(MerMakerCode))
  824. {
  825. condition += " and MerUserId in (select UserId from UserForMakerCode where MakerCode='" + MerMakerCode + "')";
  826. }
  827. //仓库编号
  828. if (!string.IsNullOrEmpty(StoreNo))
  829. {
  830. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreNo + "')";
  831. }
  832. //仓库名称
  833. if (!string.IsNullOrEmpty(RealName))
  834. {
  835. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreName + "')";
  836. }
  837. //商户状态
  838. if (!string.IsNullOrEmpty(MerStatusSelect))
  839. {
  840. condition += " and MerStatus=" + MerStatusSelect;
  841. }
  842. //商户激活状态
  843. if (!string.IsNullOrEmpty(ActiveStatusSelect))
  844. {
  845. condition += " and ActiveStatus=" + ActiveStatusSelect;
  846. }
  847. //激活类型
  848. if (!string.IsNullOrEmpty(ActTypeSelect))
  849. {
  850. condition += " and ActType=" + ActTypeSelect;
  851. }
  852. //商户创客类型
  853. if (!string.IsNullOrEmpty(MerUserTypeSelect))
  854. {
  855. condition += " and MerUserType=" + MerUserTypeSelect;
  856. }
  857. 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);
  858. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  859. foreach (Dictionary<string, object> dic in diclist)
  860. {
  861. //直属创客
  862. int UserId = int.Parse(dic["UserId"].ToString());
  863. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  864. dic["MakerCode"] = puser.MakerCode;
  865. dic["RealName"] = puser.RealName;
  866. //顶级创客
  867. int TopUserId = int.Parse(dic["TopUserId"].ToString());
  868. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  869. dic["TopMakerCode"] = tuser.MakerCode;
  870. dic["TopRealName"] = tuser.RealName;
  871. //商户创客
  872. int MerUserId = int.Parse(dic["MerUserId"].ToString());
  873. Users muser = db.Users.FirstOrDefault(m => m.Id == MerUserId) ?? new Users();
  874. dic["MerMakerCode"] = muser.MakerCode;
  875. dic["MerRealName"] = muser.RealName;
  876. //申请创客
  877. int SnApplyUserId = int.Parse(dic["SnApplyUserId"].ToString());
  878. Users snuser = db.Users.FirstOrDefault(m => m.Id == SnApplyUserId) ?? new Users();
  879. dic["SnApplyMakerCode"] = snuser.MakerCode;
  880. dic["SnApplyRealName"] = snuser.RealName;
  881. //SN仓库
  882. int SnStoreId = int.Parse(dic["SnStoreId"].ToString());
  883. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == SnStoreId) ?? new StoreHouse();
  884. dic["StoreNo"] = store.StoreNo;
  885. dic["StoreName"] = store.StoreName;
  886. //机具类型
  887. int SnType = int.Parse(dic["SnType"].ToString());
  888. if (SnType == 0) dic["SnType"] = "兑换机具";
  889. if (SnType == 1) dic["SnType"] = "循环机具";
  890. //返利资格
  891. dic["RebateQual"] = dic["RebateQual"].ToString() == "1" ? "是" : "否";
  892. //激活类型
  893. int ActType = int.Parse(dic["ActType"].ToString());
  894. if (ActType == 0) dic["ActType"] = "正常激活";
  895. if (ActType == 1) dic["ActType"] = "首次已激活MPOS";
  896. if (ActType == 2) dic["ActType"] = "首次已激活KPOS";
  897. if (ActType == 3) dic["ActType"] = "循环机划拨激活";
  898. //商户状态
  899. int MerStatus = int.Parse(dic["MerStatus"].ToString());
  900. if (MerStatus == 0) dic["MerStatus"] = "正常";
  901. if (MerStatus == 1) dic["MerStatus"] = "冻结";
  902. if (MerStatus == 2) dic["MerStatus"] = "关闭";
  903. //商户激活状态
  904. int ActiveStatus = int.Parse(dic["ActiveStatus"].ToString());
  905. if (ActiveStatus == 0) dic["ActiveStatus"] = "未激活";
  906. if (ActiveStatus == 1) dic["ActiveStatus"] = "已激活";
  907. if (ActiveStatus == 2) dic["ActiveStatus"] = "SN已返现";
  908. //商户创客类型
  909. int MerUserType = int.Parse(dic["MerUserType"].ToString());
  910. if (MerUserType == 0) dic["MerUserType"] = "非商户型创客";
  911. if (MerUserType == 1) dic["MerUserType"] = "商户型创客";
  912. dic.Remove("UserId");
  913. dic.Remove("TopUserId");
  914. dic.Remove("MerUserId");
  915. dic.Remove("SnApplyUserId");
  916. dic.Remove("SnStoreId");
  917. }
  918. Dictionary<string, object> result = new Dictionary<string, object>();
  919. result.Add("Status", "1");
  920. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  921. result.Add("Obj", diclist);
  922. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  923. ReturnFields.Add("MerchantNo", "商户编号");
  924. ReturnFields.Add("MerchantName", "商户名称");
  925. ReturnFields.Add("MerchantMobile", "商户手机号");
  926. ReturnFields.Add("KqMerNo", "快钱商户编码");
  927. ReturnFields.Add("KqSnNo", "快钱SN号");
  928. ReturnFields.Add("SnType", "机具类型");
  929. ReturnFields.Add("RebateQual", "返利资格");
  930. ReturnFields.Add("ActType", "激活类型");
  931. ReturnFields.Add("MerStatus", "商户状态");
  932. ReturnFields.Add("ActiveStatus", "商户激活状态");
  933. ReturnFields.Add("MerMakerCode", "商户创客编码");
  934. ReturnFields.Add("MerRealName", "商户创客名称");
  935. ReturnFields.Add("MerUserType", "商户创客类型");
  936. ReturnFields.Add("MakerCode", "直属创客编号");
  937. ReturnFields.Add("RealName", "直属创客姓名");
  938. ReturnFields.Add("TopMakerCode", "顶级创客编码");
  939. ReturnFields.Add("TopRealName", "顶级创客名称");
  940. ReturnFields.Add("StoreNo", "SN仓库编号");
  941. ReturnFields.Add("StoreName", "SN仓库名称");
  942. ReturnFields.Add("SnApplyMakerCode", "申请创客编号");
  943. ReturnFields.Add("SnApplyRealName", "申请创客姓名");
  944. ReturnFields.Add("KqRegTime", "注册时间");
  945. result.Add("Fields", ReturnFields);
  946. AddSysLog("0", "PosMerchantInfo", "ExportExcel");
  947. return Json(result);
  948. }
  949. #endregion
  950. #region 首台机具查询
  951. /// <summary>
  952. /// 根据条件查询首台机具查询
  953. /// </summary>
  954. /// <returns></returns>
  955. public IActionResult FirstPosIndex(string right)
  956. {
  957. ViewBag.RightInfo = RightInfo;
  958. ViewBag.right = right;
  959. return View();
  960. }
  961. #endregion
  962. #region 根据条件查询首台机具查询
  963. /// <summary>
  964. /// 首台机具查询
  965. /// </summary>
  966. /// <returns></returns>
  967. public JsonResult FirstPosIndexData(string PosSn, int page = 1, int limit = 30)
  968. {
  969. string conn = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  970. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  971. if (!string.IsNullOrEmpty(PosSn))
  972. {
  973. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Status > -1 && m.PosSn == PosSn) ?? new PosMachinesTwo();
  974. if (pos.BindMerchantId > 0)
  975. {
  976. var mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  977. if (mer.Id > 0 && !string.IsNullOrEmpty(mer.MerIdcardNo))
  978. {
  979. string MerchantName = Regex.Replace(mer.MerchantName, @"\d|\W|[A-Za-z]", "");
  980. // 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();
  981. var posMerchants = db.PosMerchantInfo.Where(m => m.MerchantName.Contains(MerchantName)).ToList();
  982. foreach (var item in posMerchants)
  983. {
  984. Dictionary<string, object> curData = new Dictionary<string, object>();
  985. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == item.KqSnNo) ?? new PosMachinesTwo();
  986. int IsFirst = int.Parse(posInfo.IsFirst.ToString());
  987. var IsFirstName = "";
  988. if (IsFirst == 1) IsFirstName = "首台";
  989. if (IsFirst == 0) IsFirstName = "非首台";
  990. curData.Add("PosSn", posInfo.PosSn); //机具Sn
  991. curData.Add("MerchantName", item.MerchantName); //商户名称
  992. curData.Add("MerchantMobile", item.MerchantMobile); //商户手机号
  993. curData.Add("MerIdcardNo", item.MerIdcardNo); //商户身份证号
  994. curData.Add("IsFirstName", IsFirstName); //是否首台
  995. curData.Add("IsFirst", IsFirst);
  996. curData.Add("BindingTime", string.IsNullOrEmpty(posInfo.BindingTime.ToString()) ? "" : Convert.ToDateTime(posInfo.BindingTime).ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  997. curData.Add("ActivationTime", string.IsNullOrEmpty(posInfo.ActivationTime.ToString()) ? "" : Convert.ToDateTime(posInfo.ActivationTime).ToString("yyyy-MM-dd HH:mm:ss")); //激活时间
  998. dataList.Add(curData);
  999. }
  1000. }
  1001. }
  1002. }
  1003. Dictionary<string, object> obj = new Dictionary<string, object>();
  1004. obj.Add("code", 0);
  1005. obj.Add("msg", "");
  1006. obj.Add("count", dataList.Count);
  1007. obj.Add("data", dataList);
  1008. return Json(obj);
  1009. }
  1010. #endregion
  1011. #region 设置为首台机具
  1012. /// <summary>
  1013. /// 设置为首台机具
  1014. /// </summary>
  1015. /// <returns></returns>
  1016. public string SetFirstPos(string PosSn)
  1017. {
  1018. Dictionary<string, object> Fields = new Dictionary<string, object>();
  1019. var mer = db.PosMerchantInfo.FirstOrDefault(m => m.KqSnNo == PosSn) ?? new PosMerchantInfo();
  1020. string MerchantName = Regex.Replace(mer.MerchantName, @"\d|\W|[A-Za-z]", "");
  1021. 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();
  1022. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn) ?? new PosMachinesTwo();
  1023. var thisdate = pos.BindingTime;
  1024. var otherdate = pos.BindingTime;
  1025. if (posMerchants.Count > 0)
  1026. {
  1027. var flag = 0;
  1028. foreach (var item in posMerchants)
  1029. {
  1030. var changeFlag = 0;
  1031. Dictionary<string, object> curData = new Dictionary<string, object>();
  1032. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == item.KqSnNo) ?? new PosMachinesTwo();
  1033. otherdate = posInfo.BindingTime;
  1034. if (thisdate <= otherdate)
  1035. {
  1036. changeFlag = 1;
  1037. posInfo.IsFirst = 0;
  1038. flag = changeFlag;
  1039. }
  1040. else
  1041. {
  1042. return "不符合设置条件";
  1043. }
  1044. }
  1045. if (flag == 1)
  1046. {
  1047. AddSysLog(PosSn, "PosMachinesTwo", "SetFirstPos");
  1048. pos.IsFirst = 1;
  1049. }
  1050. }
  1051. else
  1052. {
  1053. AddSysLog(PosSn, "PosMachinesTwo", "SetFirstPos");
  1054. pos.IsFirst = 1;
  1055. }
  1056. db.SaveChanges();
  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. }