PosMerchantInfoListController.cs 54 KB

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