PosMerchantInfoListController.cs 43 KB

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