PosMerchantInfoListController.cs 43 KB

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