PosMerchantInfoListController.cs 52 KB

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