PosMerchantInfoListController.cs 43 KB

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