PosMerchantInfoListController.cs 35 KB

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