PosMerchantInfoListController.cs 44 KB

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