PosMerchantInfoListController.cs 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980
  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. string condition = " and Status>-1 and StandardStatus=-2";
  161. //身份证号
  162. if (!string.IsNullOrEmpty(MerIdcardNo))
  163. {
  164. var IdCardf = MerIdcardNo.Substring(0, 6);
  165. var IdCardb = MerIdcardNo.Substring(MerIdcardNo.Length - 4);
  166. condition += " and LEFT(MerIdcardNo,6)=" + IdCardf + " AND RIGHT(MerIdcardNo,4)=" + IdCardb + "";
  167. }
  168. //商户姓名
  169. if (!string.IsNullOrEmpty(MerchantName))
  170. {
  171. condition += " and MerchantName like '%" + MerchantName + "%'";
  172. }
  173. //手机号
  174. if (!string.IsNullOrEmpty(PhoneNo))
  175. {
  176. var PhoneNof = PhoneNo.Substring(0, 3);
  177. var PhoneNob = PhoneNo.Substring(PhoneNo.Length - 4);
  178. condition += " and LEFT(MerchantMobile,3)=" + PhoneNof + " AND RIGHT(MerchantMobile,4)=" + PhoneNob + "";
  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, "Id 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. }
  241. return Json(obj);
  242. }
  243. #endregion
  244. #region 达标商户列表
  245. /// <summary>
  246. /// 达标商户列表
  247. /// </summary>
  248. /// <returns></returns>
  249. public IActionResult Indexs(PosMerchantInfo data, string right, string BrandId)
  250. {
  251. ViewBag.RightInfo = RightInfo;
  252. ViewBag.right = right;
  253. ViewBag.BrandId = BrandId;
  254. return View();
  255. }
  256. #endregion
  257. #region 根据条件查询达标商户列表
  258. /// <summary>
  259. /// 根据条件查询达标商户列表
  260. /// </summary>
  261. /// <returns></returns>
  262. public JsonResult IndexsData(PosMerchantInfo data, int page = 1, int limit = 30)
  263. {
  264. Dictionary<string, string> Fields = new Dictionary<string, string>();
  265. Fields.Add("MerchantMobile", "1"); //商户手机号
  266. Fields.Add("KqSnNo", "1"); //快钱SN号
  267. Fields.Add("MerIdcardNo", "1"); //身份证号
  268. string condition = " and Status>-1 and StandardStatus=4 and StandardMonths=10";
  269. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosMerchantInfo", Fields, "Id desc", "0", page, limit, condition);
  270. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  271. foreach (Dictionary<string, object> dic in diclist)
  272. {
  273. //直属创客
  274. int UserId = int.Parse(dic["UserId"].ToString());
  275. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  276. dic["MakerCode"] = puser.MakerCode;
  277. dic["RealName"] = puser.RealName;
  278. //顶级创客
  279. int TopUserId = int.Parse(dic["TopUserId"].ToString());
  280. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  281. dic["TopMakerCode"] = tuser.MakerCode;
  282. dic["TopRealName"] = tuser.RealName;
  283. //商户创客
  284. int MerUserId = int.Parse(dic["MerUserId"].ToString());
  285. Users muser = db.Users.FirstOrDefault(m => m.Id == MerUserId) ?? new Users();
  286. dic["MerMakerCode"] = muser.MakerCode;
  287. dic["MerRealName"] = muser.RealName;
  288. //申请创客
  289. int SnApplyUserId = int.Parse(dic["SnApplyUserId"].ToString());
  290. Users snuser = db.Users.FirstOrDefault(m => m.Id == SnApplyUserId) ?? new Users();
  291. dic["SnApplyMakerCode"] = snuser.MakerCode;
  292. dic["SnApplyRealName"] = snuser.RealName;
  293. //SN仓库
  294. int SnStoreId = int.Parse(dic["SnStoreId"].ToString());
  295. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == SnStoreId) ?? new StoreHouse();
  296. dic["StoreNo"] = store.StoreNo;
  297. dic["StoreName"] = store.StoreName;
  298. //机具类型
  299. int SnType = int.Parse(dic["SnType"].ToString());
  300. if (SnType == 0) dic["SnType"] = "购买机具";
  301. if (SnType == 1) dic["SnType"] = "赠送机具";
  302. //返利资格
  303. dic["RebateQual"] = dic["RebateQual"].ToString() == "1" ? "是" : "否";
  304. //激活类型
  305. int ActType = int.Parse(dic["ActType"].ToString());
  306. if (ActType == 0) dic["ActType"] = "正常激活";
  307. if (ActType == 1) dic["ActType"] = "首次已激活MPOS";
  308. if (ActType == 2) dic["ActType"] = "首次已激活KPOS";
  309. if (ActType == 3) dic["ActType"] = "循环机划拨激活";
  310. //商户状态
  311. int MerStatus = int.Parse(dic["MerStatus"].ToString());
  312. if (MerStatus == 0) dic["MerStatus"] = "正常";
  313. if (MerStatus == 1) dic["MerStatus"] = "冻结";
  314. if (MerStatus == 2) dic["MerStatus"] = "关闭";
  315. //商户激活状态
  316. int ActiveStatus = int.Parse(dic["ActiveStatus"].ToString());
  317. if (ActiveStatus == 0) dic["ActiveStatus"] = "未激活";
  318. if (ActiveStatus == 1) dic["ActiveStatus"] = "已激活";
  319. if (ActiveStatus == 2) dic["ActiveStatus"] = "SN已返现";
  320. //商户创客类型
  321. int MerUserType = int.Parse(dic["MerUserType"].ToString());
  322. if (MerUserType == 0) dic["MerUserType"] = "非商户型创客";
  323. if (MerUserType == 1) dic["MerUserType"] = "商户型创客";
  324. }
  325. return Json(obj);
  326. }
  327. #endregion
  328. #region 首台达标商户列表
  329. /// <summary>
  330. /// 首台达标商户列表
  331. /// </summary>
  332. /// <returns></returns>
  333. public IActionResult Indexfs(string right)
  334. {
  335. ViewBag.RightInfo = RightInfo;
  336. ViewBag.right = right;
  337. return View();
  338. }
  339. #endregion
  340. #region 根据条件查询首台达标商户列表
  341. /// <summary>
  342. /// 根据条件查询首台达标商户列表
  343. /// </summary>
  344. /// <returns></returns>
  345. public IActionResult IndexfsData(string MerchantMobile, string KqSnNo, string MerIdcardNo, int page = 1, int limit = 30)
  346. {
  347. string condition = "";
  348. if (!string.IsNullOrEmpty(MerchantMobile))
  349. {
  350. condition += " and b.MerchantMobile like '%" + MerchantMobile + "%'";
  351. }
  352. if (!string.IsNullOrEmpty(KqSnNo))
  353. {
  354. condition += " and b.KqSnNo like '%" + KqSnNo + "%'";
  355. }
  356. if (!string.IsNullOrEmpty(MerIdcardNo))
  357. {
  358. condition += " and b.MerIdcardNo like '%" + MerIdcardNo + "%'";
  359. }
  360. var amount = 0.00M;
  361. List<Dictionary<string, object>> diclist = new List<Dictionary<string, object>>();
  362. 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);
  363. if (dt.Rows.Count > 0)
  364. {
  365. foreach (DataRow item in dt.Rows)
  366. {
  367. var BindMerchantId = item["BindMerchantId"].ToString();
  368. var BrandId = item["BrandId"].ToString();
  369. var PosSn = item["PosSn"].ToString();
  370. var SeoKeyword = item["SeoKeyword"].ToString();
  371. if (BrandId != "2" && BrandId != "7")
  372. {
  373. SeoKeyword = (decimal.Parse(SeoKeyword) / 100).ToString();
  374. }
  375. amount += decimal.Parse(SeoKeyword);
  376. var KqMerNo = item["KqMerNo"].ToString();
  377. var IdcardNo = item["MerIdcardNo"].ToString();
  378. var MerchantName = item["MerchantName"].ToString();
  379. var Mobile = item["MerchantMobile"].ToString();
  380. Dictionary<string, object> datas = new Dictionary<string, object>();
  381. datas.Add("Id", BindMerchantId);
  382. datas.Add("PosSn", PosSn);
  383. datas.Add("SeoKeyword", SeoKeyword);
  384. datas.Add("KqMerNo", KqMerNo);
  385. datas.Add("IdcardNo", IdcardNo);
  386. datas.Add("MerchantName", MerchantName);
  387. datas.Add("MerchantMobile", Mobile);
  388. diclist.Add(datas);
  389. }
  390. }
  391. Dictionary<string, object> obj = new Dictionary<string, object>();
  392. Dictionary<string, object> other = new Dictionary<string, object>();
  393. var ReturnAmount = amount;
  394. var fReturnAmount = amount * 0.92M;
  395. other.Add("ReturnAmount", ReturnAmount.ToString("f2"));
  396. other.Add("fReturnAmount", fReturnAmount.ToString("f2"));
  397. obj.Add("other", other);
  398. obj.Add("code", 0);
  399. obj.Add("msg", "");
  400. obj.Add("count", diclist.Count);
  401. obj.Add("data", diclist);
  402. return Json(obj);
  403. }
  404. #endregion
  405. #region 非首台达标商户列表
  406. /// <summary>
  407. /// 非首台达标商户列表
  408. /// </summary>
  409. /// <returns></returns>
  410. public IActionResult Indexnfs(string right)
  411. {
  412. ViewBag.RightInfo = RightInfo;
  413. ViewBag.right = right;
  414. return View();
  415. }
  416. #endregion
  417. #region 根据条件查询非首台达标商户列表
  418. /// <summary>
  419. /// 根据条件查询非首台达标商户列表
  420. /// </summary>
  421. /// <returns></returns>
  422. public IActionResult IndexnfsData(string MerchantMobile, string KqSnNo, string MerIdcardNo, int page = 1, int limit = 30)
  423. {
  424. string condition = "";
  425. if (!string.IsNullOrEmpty(MerchantMobile))
  426. {
  427. condition += " and b.MerchantMobile like '%" + MerchantMobile + "%'";
  428. }
  429. if (!string.IsNullOrEmpty(KqSnNo))
  430. {
  431. condition += " and b.KqSnNo like '%" + KqSnNo + "%'";
  432. }
  433. if (!string.IsNullOrEmpty(MerIdcardNo))
  434. {
  435. condition += " and b.MerIdcardNo like '%" + MerIdcardNo + "%'";
  436. }
  437. var amount = 0.00M;
  438. List<Dictionary<string, object>> diclist = new List<Dictionary<string, object>>();
  439. 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);
  440. if (dt.Rows.Count > 0)
  441. {
  442. foreach (DataRow item in dt.Rows)
  443. {
  444. var BindMerchantId = item["BindMerchantId"].ToString();
  445. var BrandId = item["BrandId"].ToString();
  446. var PosSn = item["PosSn"].ToString();
  447. var SeoKeyword = item["SeoKeyword"].ToString();
  448. if (BrandId != "2" && BrandId != "7")
  449. {
  450. SeoKeyword = (decimal.Parse(SeoKeyword) / 100).ToString();
  451. }
  452. amount += decimal.Parse(SeoKeyword);
  453. var KqMerNo = item["KqMerNo"].ToString();
  454. var IdcardNo = item["MerIdcardNo"].ToString();
  455. var MerchantName = item["MerchantName"].ToString();
  456. var Mobile = item["MerchantMobile"].ToString();
  457. Dictionary<string, object> datas = new Dictionary<string, object>();
  458. datas.Add("Id", BindMerchantId);
  459. datas.Add("PosSn", PosSn);
  460. datas.Add("SeoKeyword", SeoKeyword);
  461. datas.Add("KqMerNo", KqMerNo);
  462. datas.Add("IdcardNo", IdcardNo);
  463. datas.Add("MerchantName", MerchantName);
  464. datas.Add("MerchantMobile", Mobile);
  465. diclist.Add(datas);
  466. }
  467. }
  468. Dictionary<string, object> obj = new Dictionary<string, object>();
  469. Dictionary<string, object> other = new Dictionary<string, object>();
  470. var ReturnAmount = amount;
  471. var fReturnAmount = amount * 0.92M;
  472. other.Add("ReturnAmount", ReturnAmount.ToString("f2"));
  473. other.Add("fReturnAmount", fReturnAmount.ToString("f2"));
  474. obj.Add("other", other);
  475. obj.Add("code", 0);
  476. obj.Add("msg", "");
  477. obj.Add("count", diclist.Count);
  478. obj.Add("data", diclist);
  479. return Json(obj);
  480. }
  481. #endregion
  482. #region 批量通过
  483. /// <summary>
  484. /// 批量通过
  485. /// </summary>
  486. /// <returns></returns>
  487. public string BatchSetting(string Id)
  488. {
  489. string[] idlist = Id.Split(new char[] { ',' });
  490. AddSysLog(Id, "PosMerchantInfo", "BatchSetting");
  491. var Ids = "";//商户Id
  492. foreach (string subid in idlist)
  493. {
  494. int id = int.Parse(subid);
  495. Ids += id + ",";
  496. Dictionary<string, object> Fields = new Dictionary<string, object>();
  497. Fields.Add("StandardStatus", 101);//设置为可退押状态
  498. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  499. }
  500. string text = string.Format("商户押金退还批量通过,商户Id: '" + Ids.TrimEnd(',') + "',操作人: '" + SysUserName + "_" + SysRealName + "',Time'" + DateTime.Now + "'");
  501. function.WriteLog(text, "商户押金退还批量通过");
  502. db.SaveChanges();
  503. return "success";
  504. }
  505. #endregion
  506. #region 增加商户
  507. /// <summary>
  508. /// 增加或修改商户信息
  509. /// </summary>
  510. /// <returns></returns>
  511. public IActionResult Add(string right)
  512. {
  513. ViewBag.RightInfo = RightInfo;
  514. ViewBag.right = right;
  515. return View();
  516. }
  517. #endregion
  518. #region 增加商户
  519. /// <summary>
  520. /// 增加或修改商户信息
  521. /// </summary>
  522. /// <returns></returns>
  523. [HttpPost]
  524. public string Add(PosMerchantInfo data)
  525. {
  526. Dictionary<string, object> Fields = new Dictionary<string, object>();
  527. Fields.Add("SeoTitle", data.SeoTitle);
  528. Fields.Add("SeoKeyword", data.SeoKeyword);
  529. Fields.Add("SeoDescription", data.SeoDescription);
  530. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("PosMerchantInfo", Fields, 0);
  531. AddSysLog(data.Id.ToString(), "PosMerchantInfo", "add");
  532. db.SaveChanges();
  533. return "success";
  534. }
  535. #endregion
  536. #region 修改商户
  537. /// <summary>
  538. /// 增加或修改商户信息
  539. /// </summary>
  540. /// <returns></returns>
  541. public IActionResult Edit(string right, int Id = 0)
  542. {
  543. ViewBag.RightInfo = RightInfo;
  544. ViewBag.right = right;
  545. PosMerchantInfo editData = db.PosMerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new PosMerchantInfo();
  546. ViewBag.data = editData;
  547. return View();
  548. }
  549. #endregion
  550. #region 修改商户
  551. /// <summary>
  552. /// 增加或修改商户信息
  553. /// </summary>
  554. /// <returns></returns>
  555. [HttpPost]
  556. public string Edit(PosMerchantInfo data)
  557. {
  558. Dictionary<string, object> Fields = new Dictionary<string, object>();
  559. Fields.Add("SeoTitle", data.SeoTitle);
  560. Fields.Add("SeoKeyword", data.SeoKeyword);
  561. Fields.Add("SeoDescription", data.SeoDescription);
  562. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, data.Id);
  563. AddSysLog(data.Id.ToString(), "PosMerchantInfo", "update");
  564. db.SaveChanges();
  565. return "success";
  566. }
  567. #endregion
  568. #region 删除商户信息
  569. /// <summary>
  570. /// 删除商户信息
  571. /// </summary>
  572. /// <returns></returns>
  573. public string Delete(string Id)
  574. {
  575. string[] idlist = Id.Split(new char[] { ',' });
  576. AddSysLog(Id, "PosMerchantInfo", "del");
  577. foreach (string subid in idlist)
  578. {
  579. int id = int.Parse(subid);
  580. Dictionary<string, object> Fields = new Dictionary<string, object>();
  581. Fields.Add("Status", -1);
  582. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  583. }
  584. db.SaveChanges();
  585. return "success";
  586. }
  587. #endregion
  588. #region 开启
  589. /// <summary>
  590. /// 开启
  591. /// </summary>
  592. /// <returns></returns>
  593. public string Open(string Id)
  594. {
  595. string[] idlist = Id.Split(new char[] { ',' });
  596. AddSysLog(Id, "PosMerchantInfo", "open");
  597. foreach (string subid in idlist)
  598. {
  599. int id = int.Parse(subid);
  600. Dictionary<string, object> Fields = new Dictionary<string, object>();
  601. Fields.Add("Status", 1);
  602. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  603. }
  604. db.SaveChanges();
  605. return "success";
  606. }
  607. #endregion
  608. #region 关闭
  609. /// <summary>
  610. /// 关闭
  611. /// </summary>
  612. /// <returns></returns>
  613. public string Close(string Id)
  614. {
  615. string[] idlist = Id.Split(new char[] { ',' });
  616. AddSysLog(Id, "PosMerchantInfo", "close");
  617. foreach (string subid in idlist)
  618. {
  619. int id = int.Parse(subid);
  620. Dictionary<string, object> Fields = new Dictionary<string, object>();
  621. Fields.Add("Status", 0);
  622. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  623. }
  624. db.SaveChanges();
  625. return "success";
  626. }
  627. #endregion
  628. #region 排序
  629. /// <summary>
  630. /// 排序
  631. /// </summary>
  632. /// <param name="Id"></param>
  633. public string Sort(int Id, int Sort)
  634. {
  635. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("PosMerchantInfo", Sort, Id);
  636. AddSysLog(Id.ToString(), "PosMerchantInfo", "sort");
  637. return "success";
  638. }
  639. #endregion
  640. #region 导入数据
  641. /// <summary>
  642. /// 导入数据
  643. /// </summary>
  644. /// <param name="ExcelData"></param>
  645. public string Import(string ExcelData)
  646. {
  647. ExcelData = HttpUtility.UrlDecode(ExcelData);
  648. JsonData list = JsonMapper.ToObject(ExcelData);
  649. var Ids = "";
  650. for (int i = 1; i < list.Count; i++)
  651. {
  652. JsonData dr = list[i];
  653. string KqMerNo = dr[0].ToString(); // 商户编号
  654. string Amount = dr[0].ToString(); // 已退金额
  655. var posMerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == KqMerNo) ?? new PosMerchantInfo();
  656. posMerchantInfo.StandardStatus = -2;
  657. posMerchantInfo.Remark = Amount;
  658. Ids += posMerchantInfo.Id + "_" + Amount + ",";
  659. db.SaveChanges();
  660. }
  661. AddSysLog("0", "PosMerchantInfo", "Import");
  662. string text = string.Format("导入人工已退,商户Id: '" + Ids.TrimEnd(',') + "',操作人: '" + SysUserName + "_" + SysRealName + "',Time'" + DateTime.Now + "'");
  663. function.WriteLog(text, "导入人工已退");
  664. return "success";
  665. }
  666. #endregion
  667. #region 导出Excel
  668. /// <summary>
  669. /// 导出Excel
  670. /// </summary>
  671. /// <returns></returns>
  672. public JsonResult ExportExcel(PosMerchantInfo data, string MakerCode, string RealName, string MerMakerCode, string StoreNo, string StoreName, string MerStatusSelect, string ActiveStatusSelect, string ActTypeSelect, string MerUserTypeSelect)
  673. {
  674. Dictionary<string, string> Fields = new Dictionary<string, string>();
  675. Fields.Add("BrandId", "1");
  676. Fields.Add("MerchantNo", "1"); //商户编号
  677. Fields.Add("MerchantName", "1"); //商户姓名
  678. Fields.Add("MerchantMobile", "1"); //商户手机号
  679. Fields.Add("KqMerNo", "1"); //快钱商户编码
  680. Fields.Add("KqSnNo", "1"); //快钱SN号
  681. Fields.Add("KqRegTime", "3"); //渠道注册时间
  682. Fields.Add("TopUserId", "0"); //顶级创客
  683. string condition = " and Status>-1";
  684. //创客编号
  685. if (!string.IsNullOrEmpty(MakerCode))
  686. {
  687. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  688. }
  689. //创客名称
  690. if (!string.IsNullOrEmpty(RealName))
  691. {
  692. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  693. }
  694. //商户创客编号
  695. if (!string.IsNullOrEmpty(MerMakerCode))
  696. {
  697. condition += " and MerUserId in (select UserId from UserForMakerCode where MakerCode='" + MerMakerCode + "')";
  698. }
  699. //仓库编号
  700. if (!string.IsNullOrEmpty(StoreNo))
  701. {
  702. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreNo + "')";
  703. }
  704. //仓库名称
  705. if (!string.IsNullOrEmpty(RealName))
  706. {
  707. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreName + "')";
  708. }
  709. //商户状态
  710. if (!string.IsNullOrEmpty(MerStatusSelect))
  711. {
  712. condition += " and MerStatus=" + MerStatusSelect;
  713. }
  714. //商户激活状态
  715. if (!string.IsNullOrEmpty(ActiveStatusSelect))
  716. {
  717. condition += " and ActiveStatus=" + ActiveStatusSelect;
  718. }
  719. //激活类型
  720. if (!string.IsNullOrEmpty(ActTypeSelect))
  721. {
  722. condition += " and ActType=" + ActTypeSelect;
  723. }
  724. //商户创客类型
  725. if (!string.IsNullOrEmpty(MerUserTypeSelect))
  726. {
  727. condition += " and MerUserType=" + MerUserTypeSelect;
  728. }
  729. 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);
  730. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  731. foreach (Dictionary<string, object> dic in diclist)
  732. {
  733. //直属创客
  734. int UserId = int.Parse(dic["UserId"].ToString());
  735. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  736. dic["MakerCode"] = puser.MakerCode;
  737. dic["RealName"] = puser.RealName;
  738. //顶级创客
  739. int TopUserId = int.Parse(dic["TopUserId"].ToString());
  740. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  741. dic["TopMakerCode"] = tuser.MakerCode;
  742. dic["TopRealName"] = tuser.RealName;
  743. //商户创客
  744. int MerUserId = int.Parse(dic["MerUserId"].ToString());
  745. Users muser = db.Users.FirstOrDefault(m => m.Id == MerUserId) ?? new Users();
  746. dic["MerMakerCode"] = muser.MakerCode;
  747. dic["MerRealName"] = muser.RealName;
  748. //申请创客
  749. int SnApplyUserId = int.Parse(dic["SnApplyUserId"].ToString());
  750. Users snuser = db.Users.FirstOrDefault(m => m.Id == SnApplyUserId) ?? new Users();
  751. dic["SnApplyMakerCode"] = snuser.MakerCode;
  752. dic["SnApplyRealName"] = snuser.RealName;
  753. //SN仓库
  754. int SnStoreId = int.Parse(dic["SnStoreId"].ToString());
  755. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == SnStoreId) ?? new StoreHouse();
  756. dic["StoreNo"] = store.StoreNo;
  757. dic["StoreName"] = store.StoreName;
  758. //机具类型
  759. int SnType = int.Parse(dic["SnType"].ToString());
  760. if (SnType == 0) dic["SnType"] = "购买机具";
  761. if (SnType == 1) dic["SnType"] = "赠送机具";
  762. //返利资格
  763. dic["RebateQual"] = dic["RebateQual"].ToString() == "1" ? "是" : "否";
  764. //激活类型
  765. int ActType = int.Parse(dic["ActType"].ToString());
  766. if (ActType == 0) dic["ActType"] = "正常激活";
  767. if (ActType == 1) dic["ActType"] = "首次已激活MPOS";
  768. if (ActType == 2) dic["ActType"] = "首次已激活KPOS";
  769. if (ActType == 3) dic["ActType"] = "循环机划拨激活";
  770. //商户状态
  771. int MerStatus = int.Parse(dic["MerStatus"].ToString());
  772. if (MerStatus == 0) dic["MerStatus"] = "正常";
  773. if (MerStatus == 1) dic["MerStatus"] = "冻结";
  774. if (MerStatus == 2) dic["MerStatus"] = "关闭";
  775. //商户激活状态
  776. int ActiveStatus = int.Parse(dic["ActiveStatus"].ToString());
  777. if (ActiveStatus == 0) dic["ActiveStatus"] = "未激活";
  778. if (ActiveStatus == 1) dic["ActiveStatus"] = "已激活";
  779. if (ActiveStatus == 2) dic["ActiveStatus"] = "SN已返现";
  780. //商户创客类型
  781. int MerUserType = int.Parse(dic["MerUserType"].ToString());
  782. if (MerUserType == 0) dic["MerUserType"] = "非商户型创客";
  783. if (MerUserType == 1) dic["MerUserType"] = "商户型创客";
  784. dic.Remove("UserId");
  785. dic.Remove("TopUserId");
  786. dic.Remove("MerUserId");
  787. dic.Remove("SnApplyUserId");
  788. dic.Remove("SnStoreId");
  789. }
  790. Dictionary<string, object> result = new Dictionary<string, object>();
  791. result.Add("Status", "1");
  792. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  793. result.Add("Obj", diclist);
  794. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  795. ReturnFields.Add("MerchantNo", "商户编号");
  796. ReturnFields.Add("MerchantName", "商户名称");
  797. ReturnFields.Add("MerchantMobile", "商户手机号");
  798. ReturnFields.Add("KqMerNo", "快钱商户编码");
  799. ReturnFields.Add("KqSnNo", "快钱SN号");
  800. ReturnFields.Add("SnType", "机具类型");
  801. ReturnFields.Add("RebateQual", "返利资格");
  802. ReturnFields.Add("ActType", "激活类型");
  803. ReturnFields.Add("MerStatus", "商户状态");
  804. ReturnFields.Add("ActiveStatus", "商户激活状态");
  805. ReturnFields.Add("MerMakerCode", "商户创客编码");
  806. ReturnFields.Add("MerRealName", "商户创客名称");
  807. ReturnFields.Add("MerUserType", "商户创客类型");
  808. ReturnFields.Add("MakerCode", "直属创客编号");
  809. ReturnFields.Add("RealName", "直属创客姓名");
  810. ReturnFields.Add("TopMakerCode", "顶级创客编码");
  811. ReturnFields.Add("TopRealName", "顶级创客名称");
  812. ReturnFields.Add("StoreNo", "SN仓库编号");
  813. ReturnFields.Add("StoreName", "SN仓库名称");
  814. ReturnFields.Add("SnApplyMakerCode", "申请创客编号");
  815. ReturnFields.Add("SnApplyRealName", "申请创客姓名");
  816. ReturnFields.Add("KqRegTime", "注册时间");
  817. result.Add("Fields", ReturnFields);
  818. AddSysLog("0", "PosMerchantInfo", "ExportExcel");
  819. return Json(result);
  820. }
  821. #endregion
  822. #region 同步交易额
  823. public IActionResult SycnTradeAmount(string right, int Id = 0)
  824. {
  825. ViewBag.RightInfo = RightInfo;
  826. ViewBag.right = right;
  827. PosMerchantInfo editData = db.PosMerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new PosMerchantInfo();
  828. ViewBag.data = editData;
  829. return View();
  830. }
  831. #endregion
  832. #region 同步交易额
  833. [HttpPost]
  834. public string SycnTradeAmountDo(DateTime sdate, DateTime edate, int MerchantId)
  835. {
  836. if (sdate.AddMonths(1) < edate)
  837. {
  838. return "时间间隔不能超过1个月";
  839. }
  840. if (edate >= DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00"))
  841. {
  842. return "结束时间只能是今天之前";
  843. }
  844. string check = RedisDbconn.Instance.Get<string>("ResetMerchantTradeQueue:" + MerchantId);
  845. if (!string.IsNullOrEmpty(check))
  846. {
  847. return "请稍后再试";
  848. }
  849. try
  850. {
  851. RedisDbconn.Instance.AddList("ResetMerchantTradeQueue", MerchantId + "#cut#" + sdate.ToString("yyyy-MM-dd HH:mm:ss") + "#cut#" + edate.ToString("yyyy-MM-dd HH:mm:ss"));
  852. RedisDbconn.Instance.Set("ResetMerchantTradeQueue:" + MerchantId, "wait");
  853. RedisDbconn.Instance.SetExpire("ResetMerchantTradeQueue:" + MerchantId, 3600);
  854. }
  855. catch (Exception ex)
  856. {
  857. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计商户的交易额异常");
  858. return "同步异常";
  859. }
  860. return "success";
  861. }
  862. #endregion
  863. }
  864. }