PosMerchantInfoListController.cs 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250
  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. if (brand.Id > 0 && brand.NoticeMoneyUnit == 2 && !string.IsNullOrEmpty(SeoKeyword))
  247. {
  248. SeoKeyword = (decimal.Parse(SeoKeyword) / 100).ToString();
  249. }
  250. dic["SeoKeyword"] = SeoKeyword;
  251. //设置押金
  252. string PrizeParams = "0";
  253. if (!string.IsNullOrEmpty(pos.PrizeParams))
  254. {
  255. PrizeParams = pos.PrizeParams.ToString();
  256. }
  257. dic["PrizeParams"] = PrizeParams;
  258. }
  259. Dictionary<string, object> other = new Dictionary<string, object>();
  260. decimal ReturnAmount = 0.00M;//服务费总金额
  261. decimal ReturnAmounts = 0.00M;//退还总金额
  262. DataTable dt = OtherMySqlConn.dtable("SELECT SUM(Remark) FROM PosMerchantInfo WHERE 1=1" + condition);
  263. if (dt.Rows.Count > 0)
  264. {
  265. ReturnAmounts = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString()));
  266. }
  267. DataTable dts = OtherMySqlConn.dtable("SELECT KqSnNo FROM PosMerchantInfo WHERE 1=1" + condition);
  268. if (dt.Rows.Count > 0)
  269. {
  270. foreach (DataRow item in dts.Rows)
  271. {
  272. string KqSnNo = item["KqSnNo"].ToString();
  273. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == KqSnNo) ?? new PosMachinesTwo();
  274. var brand = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId) ?? new KqProducts();
  275. if (!string.IsNullOrEmpty(pos.SeoKeyword))
  276. {
  277. // if (brand.Id > 0 && brand.SingleDepositApi == 0 && !string.IsNullOrEmpty(pos.SeoKeyword))
  278. if (brand.Id > 0 && brand.NoticeMoneyUnit == 2 && !string.IsNullOrEmpty(pos.SeoKeyword))
  279. {
  280. ReturnAmount += (decimal.Parse(pos.SeoKeyword) / 100);
  281. }
  282. else
  283. {
  284. ReturnAmount += 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 导出人工已退商户Excel
  296. /// <summary>
  297. /// 导出人工已退商户Excel
  298. /// </summary>
  299. /// <returns></returns>
  300. public JsonResult ExportrgExcel(PosMerchantInfo data, string MerIdcardNo, string MerchantName, string PhoneNo, string PosSn)
  301. {
  302. Dictionary<string, string> Fields = new Dictionary<string, string>();
  303. Fields.Add("KqMerNo", "1"); //商户编号
  304. string condition = " and Status>-1 and StandardStatus=-2";
  305. //身份证号
  306. if (!string.IsNullOrEmpty(MerIdcardNo))
  307. {
  308. var IdCardf = MerIdcardNo.Substring(0, 6);
  309. var IdCardb = MerIdcardNo.Substring(MerIdcardNo.Length - 4);
  310. condition += " and LEFT(MerIdcardNo,6)=" + IdCardf + " AND RIGHT(MerIdcardNo,4)=" + IdCardb + "";
  311. }
  312. //商户姓名
  313. if (!string.IsNullOrEmpty(MerchantName))
  314. {
  315. condition += " and MerchantName like '%" + MerchantName + "%'";
  316. }
  317. //手机号
  318. if (!string.IsNullOrEmpty(PhoneNo))
  319. {
  320. var PhoneNof = PhoneNo.Substring(0, 3);
  321. var PhoneNob = PhoneNo.Substring(PhoneNo.Length - 4);
  322. condition += " and LEFT(MerchantMobile,3)=" + PhoneNof + " AND RIGHT(MerchantMobile,4)=" + PhoneNob + "";
  323. }
  324. //机具号
  325. if (!string.IsNullOrEmpty(PosSn))
  326. {
  327. condition += " and KqSnNo='" + PosSn + "'";
  328. }
  329. 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);
  330. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  331. foreach (Dictionary<string, object> dic in diclist)
  332. {
  333. var KqSnNo = dic["KqSnNo"].ToString();
  334. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == KqSnNo) ?? new PosMachinesTwo();
  335. var brand = db.KqProducts.FirstOrDefault(m => m.Id == pos.BrandId) ?? new KqProducts();
  336. dic["BrandName"] = brand.Name;
  337. int UserId = int.Parse(dic["UserId"].ToString());
  338. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  339. dic["MakerCode"] = puser.MakerCode;
  340. dic["RealName"] = puser.RealName;
  341. dic.Remove("UserId");
  342. //实际押金
  343. string SeoKeyword = pos.SeoKeyword;
  344. // if (brand.Id > 0 && brand.SingleDepositApi == 0 && !string.IsNullOrEmpty(SeoKeyword))
  345. if (brand.Id > 0 && brand.NoticeMoneyUnit == 2 && !string.IsNullOrEmpty(SeoKeyword))
  346. {
  347. SeoKeyword = (decimal.Parse(SeoKeyword) / 100).ToString();
  348. }
  349. dic["SeoKeyword"] = SeoKeyword;
  350. }
  351. Dictionary<string, object> result = new Dictionary<string, object>();
  352. result.Add("Status", "1");
  353. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  354. result.Add("Obj", diclist);
  355. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  356. ReturnFields.Add("KqMerNo", "商户编号");
  357. ReturnFields.Add("MerchantName", "商户名称");
  358. ReturnFields.Add("BrandName", "机具品牌");
  359. ReturnFields.Add("KqSnNo", "机具SN");
  360. ReturnFields.Add("KqRegTime", "退还时间");
  361. ReturnFields.Add("SeoKeyword", "服务费金额");
  362. ReturnFields.Add("Remark", "已退还金额");
  363. ReturnFields.Add("MakerCode", "创客编号");
  364. ReturnFields.Add("RealName", "创客姓名");
  365. result.Add("Fields", ReturnFields);
  366. AddSysLog("0", "PosMerchantInfo", "ExportrgExcel");
  367. return Json(result);
  368. }
  369. #endregion
  370. #region 达标商户列表
  371. /// <summary>
  372. /// 达标商户列表
  373. /// </summary>
  374. /// <returns></returns>
  375. public IActionResult Indexs(PosMerchantInfo data, string right, string BrandId)
  376. {
  377. ViewBag.RightInfo = RightInfo;
  378. ViewBag.right = right;
  379. ViewBag.BrandId = BrandId;
  380. return View();
  381. }
  382. #endregion
  383. #region 根据条件查询达标商户列表
  384. /// <summary>
  385. /// 根据条件查询达标商户列表
  386. /// </summary>
  387. /// <returns></returns>
  388. public JsonResult IndexsData(PosMerchantInfo data, int page = 1, int limit = 30)
  389. {
  390. Dictionary<string, string> Fields = new Dictionary<string, string>();
  391. Fields.Add("MerchantMobile", "1"); //商户手机号
  392. Fields.Add("KqSnNo", "1"); //快钱SN号
  393. Fields.Add("MerIdcardNo", "1"); //身份证号
  394. string condition = " and Status>-1 and StandardStatus=4 and StandardMonths=10";
  395. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosMerchantInfo", Fields, "Id desc", "0", page, limit, condition);
  396. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  397. foreach (Dictionary<string, object> dic in diclist)
  398. {
  399. //直属创客
  400. int UserId = int.Parse(dic["UserId"].ToString());
  401. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  402. dic["MakerCode"] = puser.MakerCode;
  403. dic["RealName"] = puser.RealName;
  404. //顶级创客
  405. int TopUserId = int.Parse(dic["TopUserId"].ToString());
  406. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  407. dic["TopMakerCode"] = tuser.MakerCode;
  408. dic["TopRealName"] = tuser.RealName;
  409. //商户创客
  410. int MerUserId = int.Parse(dic["MerUserId"].ToString());
  411. Users muser = db.Users.FirstOrDefault(m => m.Id == MerUserId) ?? new Users();
  412. dic["MerMakerCode"] = muser.MakerCode;
  413. dic["MerRealName"] = muser.RealName;
  414. //申请创客
  415. int SnApplyUserId = int.Parse(dic["SnApplyUserId"].ToString());
  416. Users snuser = db.Users.FirstOrDefault(m => m.Id == SnApplyUserId) ?? new Users();
  417. dic["SnApplyMakerCode"] = snuser.MakerCode;
  418. dic["SnApplyRealName"] = snuser.RealName;
  419. //SN仓库
  420. int SnStoreId = int.Parse(dic["SnStoreId"].ToString());
  421. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == SnStoreId) ?? new StoreHouse();
  422. dic["StoreNo"] = store.StoreNo;
  423. dic["StoreName"] = store.StoreName;
  424. //机具类型
  425. int SnType = int.Parse(dic["SnType"].ToString());
  426. if (SnType == 0) dic["SnType"] = "兑换机具";
  427. if (SnType == 1) dic["SnType"] = "循环机具";
  428. //返利资格
  429. dic["RebateQual"] = dic["RebateQual"].ToString() == "1" ? "是" : "否";
  430. //激活类型
  431. int ActType = int.Parse(dic["ActType"].ToString());
  432. if (ActType == 0) dic["ActType"] = "正常激活";
  433. if (ActType == 1) dic["ActType"] = "首次已激活MPOS";
  434. if (ActType == 2) dic["ActType"] = "首次已激活KPOS";
  435. if (ActType == 3) dic["ActType"] = "循环机划拨激活";
  436. //商户状态
  437. int MerStatus = int.Parse(dic["MerStatus"].ToString());
  438. if (MerStatus == 0) dic["MerStatus"] = "正常";
  439. if (MerStatus == 1) dic["MerStatus"] = "冻结";
  440. if (MerStatus == 2) dic["MerStatus"] = "关闭";
  441. //商户激活状态
  442. int ActiveStatus = int.Parse(dic["ActiveStatus"].ToString());
  443. if (ActiveStatus == 0) dic["ActiveStatus"] = "未激活";
  444. if (ActiveStatus == 1) dic["ActiveStatus"] = "已激活";
  445. if (ActiveStatus == 2) dic["ActiveStatus"] = "SN已返现";
  446. //商户创客类型
  447. int MerUserType = int.Parse(dic["MerUserType"].ToString());
  448. if (MerUserType == 0) dic["MerUserType"] = "非商户型创客";
  449. if (MerUserType == 1) dic["MerUserType"] = "商户型创客";
  450. }
  451. return Json(obj);
  452. }
  453. #endregion
  454. #region 首台达标商户列表
  455. /// <summary>
  456. /// 首台达标商户列表
  457. /// </summary>
  458. /// <returns></returns>
  459. public IActionResult Indexfs(string right)
  460. {
  461. ViewBag.RightInfo = RightInfo;
  462. ViewBag.right = right;
  463. return View();
  464. }
  465. #endregion
  466. #region 根据条件查询首台达标商户列表
  467. /// <summary>
  468. /// 根据条件查询首台达标商户列表
  469. /// </summary>
  470. /// <returns></returns>
  471. public IActionResult IndexfsData(string MerchantMobile, string KqSnNo, string MerIdcardNo, int page = 1, int limit = 30)
  472. {
  473. string condition = "";
  474. if (!string.IsNullOrEmpty(MerchantMobile))
  475. {
  476. condition += " and b.MerchantMobile like '%" + MerchantMobile + "%'";
  477. }
  478. if (!string.IsNullOrEmpty(KqSnNo))
  479. {
  480. condition += " and b.KqSnNo like '%" + KqSnNo + "%'";
  481. }
  482. if (!string.IsNullOrEmpty(MerIdcardNo))
  483. {
  484. condition += " and b.MerIdcardNo like '%" + MerIdcardNo + "%'";
  485. }
  486. var amount = 0.00M;
  487. List<Dictionary<string, object>> diclist = new List<Dictionary<string, object>>();
  488. 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.FirstFlag=1 AND b.StandardMonths=10 AND b.StandardStatus=4 AND a.BindMerchantId=b.Id " + condition);
  489. if (dt.Rows.Count > 0)
  490. {
  491. foreach (DataRow item in dt.Rows)
  492. {
  493. var BindMerchantId = item["BindMerchantId"].ToString();
  494. var BrandId = int.Parse(item["BrandId"].ToString());
  495. var PosSn = item["PosSn"].ToString();
  496. var SeoKeyword = item["SeoKeyword"].ToString();
  497. var brand = db.KqProducts.FirstOrDefault(m => m.Id == BrandId) ?? new KqProducts();
  498. // if (brand.Id > 0 && brand.SingleDepositApi == 0 && !string.IsNullOrEmpty(SeoKeyword))
  499. if (brand.Id > 0 && brand.NoticeMoneyUnit == 2 && !string.IsNullOrEmpty(SeoKeyword))
  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 IActionResult Indexnfs(string right)
  539. {
  540. ViewBag.RightInfo = RightInfo;
  541. ViewBag.right = right;
  542. return View();
  543. }
  544. #endregion
  545. #region 根据条件查询非首台达标商户列表
  546. /// <summary>
  547. /// 根据条件查询非首台达标商户列表
  548. /// </summary>
  549. /// <returns></returns>
  550. public IActionResult IndexnfsData(string MerchantMobile, string KqSnNo, string MerIdcardNo, int page = 1, int limit = 30)
  551. {
  552. string condition = "";
  553. if (!string.IsNullOrEmpty(MerchantMobile))
  554. {
  555. condition += " and b.MerchantMobile like '%" + MerchantMobile + "%'";
  556. }
  557. if (!string.IsNullOrEmpty(KqSnNo))
  558. {
  559. condition += " and b.KqSnNo like '%" + KqSnNo + "%'";
  560. }
  561. if (!string.IsNullOrEmpty(MerIdcardNo))
  562. {
  563. condition += " and b.MerIdcardNo like '%" + MerIdcardNo + "%'";
  564. }
  565. var amount = 0.00M;
  566. List<Dictionary<string, object>> diclist = new List<Dictionary<string, object>>();
  567. 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.FirstFlag=0 AND b.StandardMonths=10 AND b.StandardStatus=4 AND a.BindMerchantId=b.Id " + condition);
  568. if (dt.Rows.Count > 0)
  569. {
  570. foreach (DataRow item in dt.Rows)
  571. {
  572. var BindMerchantId = item["BindMerchantId"].ToString();
  573. var BrandId = int.Parse(item["BrandId"].ToString());
  574. var PosSn = item["PosSn"].ToString();
  575. var SeoKeyword = item["SeoKeyword"].ToString();
  576. var brand = db.KqProducts.FirstOrDefault(m => m.Id == BrandId) ?? new KqProducts();
  577. // if (brand.Id > 0 && brand.SingleDepositApi == 0 && !string.IsNullOrEmpty(SeoKeyword))
  578. if (brand.Id > 0 && brand.NoticeMoneyUnit == 2 && !string.IsNullOrEmpty(SeoKeyword))
  579. {
  580. SeoKeyword = (decimal.Parse(SeoKeyword) / 100).ToString();
  581. }
  582. amount += decimal.Parse(SeoKeyword);
  583. var KqMerNo = item["KqMerNo"].ToString();
  584. var IdcardNo = item["MerIdcardNo"].ToString();
  585. var MerchantName = item["MerchantName"].ToString();
  586. var Mobile = item["MerchantMobile"].ToString();
  587. Dictionary<string, object> datas = new Dictionary<string, object>();
  588. datas.Add("Id", BindMerchantId);
  589. datas.Add("PosSn", PosSn);
  590. datas.Add("SeoKeyword", SeoKeyword);
  591. datas.Add("KqMerNo", KqMerNo);
  592. datas.Add("IdcardNo", IdcardNo);
  593. datas.Add("MerchantName", MerchantName);
  594. datas.Add("MerchantMobile", Mobile);
  595. diclist.Add(datas);
  596. }
  597. }
  598. Dictionary<string, object> obj = new Dictionary<string, object>();
  599. Dictionary<string, object> other = new Dictionary<string, object>();
  600. var ReturnAmount = amount;
  601. var fReturnAmount = amount * 0.92M;
  602. other.Add("ReturnAmount", ReturnAmount.ToString("f2"));
  603. other.Add("fReturnAmount", fReturnAmount.ToString("f2"));
  604. obj.Add("other", other);
  605. obj.Add("code", 0);
  606. obj.Add("msg", "");
  607. obj.Add("count", diclist.Count);
  608. obj.Add("data", diclist);
  609. return Json(obj);
  610. }
  611. #endregion
  612. #region 批量通过
  613. /// <summary>
  614. /// 批量通过
  615. /// </summary>
  616. /// <returns></returns>
  617. public string BatchSetting(string Id)
  618. {
  619. string[] idlist = Id.Split(new char[] { ',' });
  620. AddSysLog(Id, "PosMerchantInfo", "BatchSetting");
  621. var Ids = "";//商户Id
  622. foreach (string subid in idlist)
  623. {
  624. int id = int.Parse(subid);
  625. Ids += id + ",";
  626. Dictionary<string, object> Fields = new Dictionary<string, object>();
  627. Fields.Add("StandardStatus", 101);//设置为可退押状态
  628. Fields.Add("MatchTime", DateTime.Now);//设置入口开放时间
  629. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  630. }
  631. string text = string.Format("商户押金退还批量通过,商户Id: '" + Ids.TrimEnd(',') + "',操作人: '" + SysUserName + "_" + SysRealName + "',Time'" + DateTime.Now + "'");
  632. function.WriteLog(text, "商户押金退还批量通过");
  633. db.SaveChanges();
  634. return "success";
  635. }
  636. #endregion
  637. #region 增加商户
  638. /// <summary>
  639. /// 增加或修改商户信息
  640. /// </summary>
  641. /// <returns></returns>
  642. public IActionResult Add(string right)
  643. {
  644. ViewBag.RightInfo = RightInfo;
  645. ViewBag.right = right;
  646. return View();
  647. }
  648. #endregion
  649. #region 增加商户
  650. /// <summary>
  651. /// 增加或修改商户信息
  652. /// </summary>
  653. /// <returns></returns>
  654. [HttpPost]
  655. public string Add(PosMerchantInfo data)
  656. {
  657. Dictionary<string, object> Fields = new Dictionary<string, object>();
  658. Fields.Add("SeoTitle", data.SeoTitle);
  659. Fields.Add("SeoKeyword", data.SeoKeyword);
  660. Fields.Add("SeoDescription", data.SeoDescription);
  661. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("PosMerchantInfo", Fields, 0);
  662. AddSysLog(data.Id.ToString(), "PosMerchantInfo", "add");
  663. db.SaveChanges();
  664. return "success";
  665. }
  666. #endregion
  667. #region 修改商户
  668. /// <summary>
  669. /// 增加或修改商户信息
  670. /// </summary>
  671. /// <returns></returns>
  672. public IActionResult Edit(string right, int Id = 0)
  673. {
  674. ViewBag.RightInfo = RightInfo;
  675. ViewBag.right = right;
  676. PosMerchantInfo editData = db.PosMerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new PosMerchantInfo();
  677. ViewBag.data = editData;
  678. return View();
  679. }
  680. #endregion
  681. #region 修改商户
  682. /// <summary>
  683. /// 增加或修改商户信息
  684. /// </summary>
  685. /// <returns></returns>
  686. [HttpPost]
  687. public string Edit(PosMerchantInfo data)
  688. {
  689. Dictionary<string, object> Fields = new Dictionary<string, object>();
  690. Fields.Add("SeoTitle", data.SeoTitle);
  691. Fields.Add("SeoKeyword", data.SeoKeyword);
  692. Fields.Add("SeoDescription", data.SeoDescription);
  693. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, data.Id);
  694. AddSysLog(data.Id.ToString(), "PosMerchantInfo", "update");
  695. db.SaveChanges();
  696. return "success";
  697. }
  698. #endregion
  699. #region 删除商户信息
  700. /// <summary>
  701. /// 删除商户信息
  702. /// </summary>
  703. /// <returns></returns>
  704. public string Delete(string Id)
  705. {
  706. string[] idlist = Id.Split(new char[] { ',' });
  707. AddSysLog(Id, "PosMerchantInfo", "del");
  708. foreach (string subid in idlist)
  709. {
  710. int id = int.Parse(subid);
  711. Dictionary<string, object> Fields = new Dictionary<string, object>();
  712. Fields.Add("Status", -1);
  713. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  714. }
  715. db.SaveChanges();
  716. return "success";
  717. }
  718. #endregion
  719. #region 开启
  720. /// <summary>
  721. /// 开启
  722. /// </summary>
  723. /// <returns></returns>
  724. public string Open(string Id)
  725. {
  726. string[] idlist = Id.Split(new char[] { ',' });
  727. AddSysLog(Id, "PosMerchantInfo", "open");
  728. foreach (string subid in idlist)
  729. {
  730. int id = int.Parse(subid);
  731. Dictionary<string, object> Fields = new Dictionary<string, object>();
  732. Fields.Add("Status", 1);
  733. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  734. }
  735. db.SaveChanges();
  736. return "success";
  737. }
  738. #endregion
  739. #region 关闭
  740. /// <summary>
  741. /// 关闭
  742. /// </summary>
  743. /// <returns></returns>
  744. public string Close(string Id)
  745. {
  746. string[] idlist = Id.Split(new char[] { ',' });
  747. AddSysLog(Id, "PosMerchantInfo", "close");
  748. foreach (string subid in idlist)
  749. {
  750. int id = int.Parse(subid);
  751. Dictionary<string, object> Fields = new Dictionary<string, object>();
  752. Fields.Add("Status", 0);
  753. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  754. }
  755. db.SaveChanges();
  756. return "success";
  757. }
  758. #endregion
  759. #region 排序
  760. /// <summary>
  761. /// 排序
  762. /// </summary>
  763. /// <param name="Id"></param>
  764. public string Sort(int Id, int Sort)
  765. {
  766. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("PosMerchantInfo", Sort, Id);
  767. AddSysLog(Id.ToString(), "PosMerchantInfo", "sort");
  768. return "success";
  769. }
  770. #endregion
  771. #region 导入数据
  772. /// <summary>
  773. /// 导入数据
  774. /// </summary>
  775. /// <param name="ExcelData"></param>
  776. public string Import(string ExcelData)
  777. {
  778. ExcelData = HttpUtility.UrlDecode(ExcelData);
  779. JsonData list = JsonMapper.ToObject(ExcelData);
  780. var Ids = "";
  781. for (int i = 1; i < list.Count; i++)
  782. {
  783. JsonData dr = list[i];
  784. string KqMerNo = dr[0].ToString(); // 商户编号
  785. string Amount = dr[1].ToString(); // 已退金额
  786. string KqRegTime = dr[2].ToString(); // 退还时间
  787. var posMerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == KqMerNo) ?? new PosMerchantInfo();
  788. posMerchantInfo.StandardStatus = -2;
  789. posMerchantInfo.Remark = Amount;
  790. posMerchantInfo.KqRegTime = DateTime.Parse(KqRegTime);
  791. Ids += posMerchantInfo.Id + "_" + Amount + ",";
  792. db.SaveChanges();
  793. }
  794. AddSysLog("0", "PosMerchantInfo", "Import");
  795. string text = string.Format("导入人工已退,商户Id: '" + Ids.TrimEnd(',') + "',操作人: '" + SysUserName + "_" + SysRealName + "',Time'" + DateTime.Now + "'");
  796. function.WriteLog(text, "导入人工已退");
  797. return "success";
  798. }
  799. #endregion
  800. #region 导出Excel
  801. /// <summary>
  802. /// 导出Excel
  803. /// </summary>
  804. /// <returns></returns>
  805. public JsonResult ExportExcel(PosMerchantInfo data, string MakerCode, string RealName, string MerMakerCode, string StoreNo, string StoreName, string MerStatusSelect, string ActiveStatusSelect, string ActTypeSelect, string MerUserTypeSelect)
  806. {
  807. Dictionary<string, string> Fields = new Dictionary<string, string>();
  808. Fields.Add("BrandId", "1");
  809. Fields.Add("MerchantNo", "1"); //商户编号
  810. Fields.Add("MerchantName", "1"); //商户姓名
  811. Fields.Add("MerchantMobile", "1"); //商户手机号
  812. Fields.Add("KqMerNo", "1"); //快钱商户编码
  813. Fields.Add("KqSnNo", "1"); //快钱SN号
  814. Fields.Add("KqRegTime", "3"); //渠道注册时间
  815. Fields.Add("TopUserId", "0"); //顶级创客
  816. string condition = " and Status>-1";
  817. //创客编号
  818. if (!string.IsNullOrEmpty(MakerCode))
  819. {
  820. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  821. }
  822. //创客名称
  823. if (!string.IsNullOrEmpty(RealName))
  824. {
  825. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  826. }
  827. //商户创客编号
  828. if (!string.IsNullOrEmpty(MerMakerCode))
  829. {
  830. condition += " and MerUserId in (select UserId from UserForMakerCode where MakerCode='" + MerMakerCode + "')";
  831. }
  832. //仓库编号
  833. if (!string.IsNullOrEmpty(StoreNo))
  834. {
  835. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreNo + "')";
  836. }
  837. //仓库名称
  838. if (!string.IsNullOrEmpty(RealName))
  839. {
  840. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreName + "')";
  841. }
  842. //商户状态
  843. if (!string.IsNullOrEmpty(MerStatusSelect))
  844. {
  845. condition += " and MerStatus=" + MerStatusSelect;
  846. }
  847. //商户激活状态
  848. if (!string.IsNullOrEmpty(ActiveStatusSelect))
  849. {
  850. condition += " and ActiveStatus=" + ActiveStatusSelect;
  851. }
  852. //激活类型
  853. if (!string.IsNullOrEmpty(ActTypeSelect))
  854. {
  855. condition += " and ActType=" + ActTypeSelect;
  856. }
  857. //商户创客类型
  858. if (!string.IsNullOrEmpty(MerUserTypeSelect))
  859. {
  860. condition += " and MerUserType=" + MerUserTypeSelect;
  861. }
  862. 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);
  863. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  864. foreach (Dictionary<string, object> dic in diclist)
  865. {
  866. //直属创客
  867. int UserId = int.Parse(dic["UserId"].ToString());
  868. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  869. dic["MakerCode"] = puser.MakerCode;
  870. dic["RealName"] = puser.RealName;
  871. //顶级创客
  872. int TopUserId = int.Parse(dic["TopUserId"].ToString());
  873. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  874. dic["TopMakerCode"] = tuser.MakerCode;
  875. dic["TopRealName"] = tuser.RealName;
  876. //商户创客
  877. int MerUserId = int.Parse(dic["MerUserId"].ToString());
  878. Users muser = db.Users.FirstOrDefault(m => m.Id == MerUserId) ?? new Users();
  879. dic["MerMakerCode"] = muser.MakerCode;
  880. dic["MerRealName"] = muser.RealName;
  881. //申请创客
  882. int SnApplyUserId = int.Parse(dic["SnApplyUserId"].ToString());
  883. Users snuser = db.Users.FirstOrDefault(m => m.Id == SnApplyUserId) ?? new Users();
  884. dic["SnApplyMakerCode"] = snuser.MakerCode;
  885. dic["SnApplyRealName"] = snuser.RealName;
  886. //SN仓库
  887. int SnStoreId = int.Parse(dic["SnStoreId"].ToString());
  888. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == SnStoreId) ?? new StoreHouse();
  889. dic["StoreNo"] = store.StoreNo;
  890. dic["StoreName"] = store.StoreName;
  891. //机具类型
  892. int SnType = int.Parse(dic["SnType"].ToString());
  893. if (SnType == 0) dic["SnType"] = "兑换机具";
  894. if (SnType == 1) dic["SnType"] = "循环机具";
  895. //返利资格
  896. dic["RebateQual"] = dic["RebateQual"].ToString() == "1" ? "是" : "否";
  897. //激活类型
  898. int ActType = int.Parse(dic["ActType"].ToString());
  899. if (ActType == 0) dic["ActType"] = "正常激活";
  900. if (ActType == 1) dic["ActType"] = "首次已激活MPOS";
  901. if (ActType == 2) dic["ActType"] = "首次已激活KPOS";
  902. if (ActType == 3) dic["ActType"] = "循环机划拨激活";
  903. //商户状态
  904. int MerStatus = int.Parse(dic["MerStatus"].ToString());
  905. if (MerStatus == 0) dic["MerStatus"] = "正常";
  906. if (MerStatus == 1) dic["MerStatus"] = "冻结";
  907. if (MerStatus == 2) dic["MerStatus"] = "关闭";
  908. //商户激活状态
  909. int ActiveStatus = int.Parse(dic["ActiveStatus"].ToString());
  910. if (ActiveStatus == 0) dic["ActiveStatus"] = "未激活";
  911. if (ActiveStatus == 1) dic["ActiveStatus"] = "已激活";
  912. if (ActiveStatus == 2) dic["ActiveStatus"] = "SN已返现";
  913. //商户创客类型
  914. int MerUserType = int.Parse(dic["MerUserType"].ToString());
  915. if (MerUserType == 0) dic["MerUserType"] = "非商户型创客";
  916. if (MerUserType == 1) dic["MerUserType"] = "商户型创客";
  917. dic.Remove("UserId");
  918. dic.Remove("TopUserId");
  919. dic.Remove("MerUserId");
  920. dic.Remove("SnApplyUserId");
  921. dic.Remove("SnStoreId");
  922. }
  923. Dictionary<string, object> result = new Dictionary<string, object>();
  924. result.Add("Status", "1");
  925. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  926. result.Add("Obj", diclist);
  927. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  928. ReturnFields.Add("MerchantNo", "商户编号");
  929. ReturnFields.Add("MerchantName", "商户名称");
  930. ReturnFields.Add("MerchantMobile", "商户手机号");
  931. ReturnFields.Add("KqMerNo", "快钱商户编码");
  932. ReturnFields.Add("KqSnNo", "快钱SN号");
  933. ReturnFields.Add("SnType", "机具类型");
  934. ReturnFields.Add("RebateQual", "返利资格");
  935. ReturnFields.Add("ActType", "激活类型");
  936. ReturnFields.Add("MerStatus", "商户状态");
  937. ReturnFields.Add("ActiveStatus", "商户激活状态");
  938. ReturnFields.Add("MerMakerCode", "商户创客编码");
  939. ReturnFields.Add("MerRealName", "商户创客名称");
  940. ReturnFields.Add("MerUserType", "商户创客类型");
  941. ReturnFields.Add("MakerCode", "直属创客编号");
  942. ReturnFields.Add("RealName", "直属创客姓名");
  943. ReturnFields.Add("TopMakerCode", "顶级创客编码");
  944. ReturnFields.Add("TopRealName", "顶级创客名称");
  945. ReturnFields.Add("StoreNo", "SN仓库编号");
  946. ReturnFields.Add("StoreName", "SN仓库名称");
  947. ReturnFields.Add("SnApplyMakerCode", "申请创客编号");
  948. ReturnFields.Add("SnApplyRealName", "申请创客姓名");
  949. ReturnFields.Add("KqRegTime", "注册时间");
  950. result.Add("Fields", ReturnFields);
  951. AddSysLog("0", "PosMerchantInfo", "ExportExcel");
  952. return Json(result);
  953. }
  954. #endregion
  955. #region 首台机具查询
  956. /// <summary>
  957. /// 根据条件查询首台机具查询
  958. /// </summary>
  959. /// <returns></returns>
  960. public IActionResult FirstPosIndex(string right)
  961. {
  962. ViewBag.RightInfo = RightInfo;
  963. ViewBag.right = right;
  964. return View();
  965. }
  966. #endregion
  967. #region 根据条件查询首台机具查询
  968. /// <summary>
  969. /// 首台机具查询
  970. /// </summary>
  971. /// <returns></returns>
  972. public JsonResult FirstPosIndexData(string PosSn, int page = 1, int limit = 30)
  973. {
  974. string conn = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  975. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  976. if (!string.IsNullOrEmpty(PosSn))
  977. {
  978. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Status > -1 && m.PosSn == PosSn) ?? new PosMachinesTwo();
  979. if (pos.BindMerchantId > 0)
  980. {
  981. var mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId) ?? new PosMerchantInfo();
  982. if (mer.Id > 0 && !string.IsNullOrEmpty(mer.MerIdcardNo))
  983. {
  984. string MerchantName = Regex.Replace(mer.MerchantName, @"\d|\W|[A-Za-z]", "");
  985. // 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();
  986. var posMerchants = db.PosMerchantInfo.Where(m => m.MerchantName.Contains(MerchantName)).ToList();
  987. foreach (var item in posMerchants)
  988. {
  989. Dictionary<string, object> curData = new Dictionary<string, object>();
  990. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == item.KqSnNo) ?? new PosMachinesTwo();
  991. int IsFirst = int.Parse(posInfo.FirstFlag.ToString());
  992. var IsFirstName = "";
  993. if (IsFirst == 1) IsFirstName = "首台";
  994. if (IsFirst == 0) IsFirstName = "非首台";
  995. curData.Add("PosSn", posInfo.PosSn); //机具Sn
  996. curData.Add("MerchantName", item.MerchantName); //商户名称
  997. curData.Add("MerchantMobile", item.MerchantMobile); //商户手机号
  998. curData.Add("MerIdcardNo", item.MerIdcardNo); //商户身份证号
  999. curData.Add("IsFirstName", posInfo.FirstFlag == 1 ? "首台" : "非首台"); //是否首台(服务费领取)
  1000. curData.Add("PosIsFirstName", posInfo.IsFirst == 1 ? "首台" : "非首台"); //是否首台(机具奖励发放)
  1001. curData.Add("IsFirst", posInfo.FirstFlag);
  1002. curData.Add("PosIsFirst", posInfo.IsFirst);
  1003. curData.Add("BindingTime", string.IsNullOrEmpty(posInfo.BindingTime.ToString()) ? "" : Convert.ToDateTime(posInfo.BindingTime).ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  1004. curData.Add("ActivationTime", string.IsNullOrEmpty(posInfo.ActivationTime.ToString()) ? "" : Convert.ToDateTime(posInfo.ActivationTime).ToString("yyyy-MM-dd HH:mm:ss")); //激活时间
  1005. dataList.Add(curData);
  1006. }
  1007. }
  1008. }
  1009. }
  1010. Dictionary<string, object> obj = new Dictionary<string, object>();
  1011. obj.Add("code", 0);
  1012. obj.Add("msg", "");
  1013. obj.Add("count", dataList.Count);
  1014. obj.Add("data", dataList);
  1015. return Json(obj);
  1016. }
  1017. #endregion
  1018. #region 设置为首台机具
  1019. /// <summary>
  1020. /// 设置为首台机具
  1021. /// </summary>
  1022. /// <returns></returns>
  1023. public string SetFirstPos(string PosSn)
  1024. {
  1025. Dictionary<string, object> Fields = new Dictionary<string, object>();
  1026. var mer = db.PosMerchantInfo.FirstOrDefault(m => m.KqSnNo == PosSn) ?? new PosMerchantInfo();
  1027. string MerchantName = Regex.Replace(mer.MerchantName, @"\d|\W|[A-Za-z]", "");
  1028. 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();
  1029. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn) ?? new PosMachinesTwo();
  1030. var thisdate = pos.BindingTime;
  1031. var otherdate = pos.BindingTime;
  1032. if (posMerchants.Count > 0)
  1033. {
  1034. var flag = 0;
  1035. foreach (var item in posMerchants)
  1036. {
  1037. var changeFlag = 0;
  1038. Dictionary<string, object> curData = new Dictionary<string, object>();
  1039. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == item.KqSnNo) ?? new PosMachinesTwo();
  1040. otherdate = posInfo.BindingTime;
  1041. if (thisdate <= otherdate)
  1042. {
  1043. changeFlag = 1;
  1044. posInfo.FirstFlag = 0;
  1045. flag = changeFlag;
  1046. }
  1047. else
  1048. {
  1049. return "不符合设置条件";
  1050. }
  1051. }
  1052. if (flag == 1)
  1053. {
  1054. AddSysLog(PosSn, "PosMachinesTwo", "SetFirstPos");
  1055. pos.FirstFlag = 1;
  1056. }
  1057. }
  1058. else
  1059. {
  1060. AddSysLog(PosSn, "PosMachinesTwo", "SetFirstPos");
  1061. pos.FirstFlag = 1;
  1062. }
  1063. db.SaveChanges();
  1064. return "success";
  1065. }
  1066. #endregion
  1067. #region 同步交易额
  1068. public IActionResult SycnTradeAmount(string right, int Id = 0)
  1069. {
  1070. ViewBag.RightInfo = RightInfo;
  1071. ViewBag.right = right;
  1072. PosMerchantInfo editData = db.PosMerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new PosMerchantInfo();
  1073. ViewBag.data = editData;
  1074. return View();
  1075. }
  1076. #endregion
  1077. #region 同步交易额
  1078. [HttpPost]
  1079. public string SycnTradeAmountDo(DateTime sdate, DateTime edate, int MerchantId)
  1080. {
  1081. if (sdate.AddMonths(1) < edate)
  1082. {
  1083. return "时间间隔不能超过1个月";
  1084. }
  1085. if (edate >= DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00"))
  1086. {
  1087. return "结束时间只能是今天之前";
  1088. }
  1089. string check = RedisDbconn.Instance.Get<string>("ResetMerchantTradeQueue:" + MerchantId);
  1090. if (!string.IsNullOrEmpty(check))
  1091. {
  1092. return "请稍后再试";
  1093. }
  1094. try
  1095. {
  1096. RedisDbconn.Instance.AddList("ResetMerchantTradeQueue", MerchantId + "#cut#" + sdate.ToString("yyyy-MM-dd HH:mm:ss") + "#cut#" + edate.ToString("yyyy-MM-dd HH:mm:ss"));
  1097. RedisDbconn.Instance.Set("ResetMerchantTradeQueue:" + MerchantId, "wait");
  1098. RedisDbconn.Instance.SetExpire("ResetMerchantTradeQueue:" + MerchantId, 3600);
  1099. }
  1100. catch (Exception ex)
  1101. {
  1102. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计商户的交易额异常");
  1103. return "同步异常";
  1104. }
  1105. return "success";
  1106. }
  1107. #endregion
  1108. }
  1109. }