PosMerchantInfoListController.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  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. var amount = 0.00M;
  251. List<Dictionary<string, object>> diclist = new List<Dictionary<string, object>>();
  252. 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);
  253. if (dt.Rows.Count > 0)
  254. {
  255. foreach (DataRow item in dt.Rows)
  256. {
  257. var BindMerchantId = item["BindMerchantId"].ToString();
  258. var BrandId = item["BrandId"].ToString();
  259. var PosSn = item["PosSn"].ToString();
  260. var SeoKeyword = item["SeoKeyword"].ToString();
  261. if (BrandId != "2" && BrandId != "7")
  262. {
  263. SeoKeyword = (decimal.Parse(SeoKeyword) / 100).ToString();
  264. }
  265. amount += decimal.Parse(SeoKeyword);
  266. var KqMerNo = item["KqMerNo"].ToString();
  267. var IdcardNo = item["MerIdcardNo"].ToString();
  268. var MerchantName = item["MerchantName"].ToString();
  269. var Mobile = item["MerchantMobile"].ToString();
  270. Dictionary<string, object> datas = new Dictionary<string, object>();
  271. datas.Add("Id", BindMerchantId);
  272. datas.Add("PosSn", PosSn);
  273. datas.Add("SeoKeyword", SeoKeyword);
  274. datas.Add("KqMerNo", KqMerNo);
  275. datas.Add("IdcardNo", IdcardNo);
  276. datas.Add("MerchantName", MerchantName);
  277. datas.Add("MerchantMobile", Mobile);
  278. diclist.Add(datas);
  279. }
  280. }
  281. Dictionary<string, object> obj = new Dictionary<string, object>();
  282. Dictionary<string, object> other = new Dictionary<string, object>();
  283. var ReturnAmount = amount;
  284. var fReturnAmount = amount * 0.92M;
  285. other.Add("ReturnAmount", ReturnAmount.ToString("f2"));
  286. other.Add("fReturnAmount", fReturnAmount.ToString("f2"));
  287. obj.Add("other", other);
  288. obj.Add("code", 0);
  289. obj.Add("msg", "");
  290. obj.Add("count", diclist.Count);
  291. obj.Add("data", diclist);
  292. return Json(obj);
  293. }
  294. #endregion
  295. #region 非首台达标商户列表
  296. /// <summary>
  297. /// 非首台达标商户列表
  298. /// </summary>
  299. /// <returns></returns>
  300. public IActionResult Indexnfs(string right)
  301. {
  302. ViewBag.RightInfo = RightInfo;
  303. ViewBag.right = right;
  304. return View();
  305. }
  306. #endregion
  307. #region 根据条件查询非首台达标商户列表
  308. /// <summary>
  309. /// 根据条件查询非首台达标商户列表
  310. /// </summary>
  311. /// <returns></returns>
  312. public IActionResult IndexnfsData(string MerchantMobile, string KqSnNo, string MerIdcardNo, int page = 1, int limit = 30)
  313. {
  314. string condition = "";
  315. if (!string.IsNullOrEmpty(MerchantMobile))
  316. {
  317. condition += " and b.MerchantMobile like '%" + MerchantMobile + "%'";
  318. }
  319. if (!string.IsNullOrEmpty(KqSnNo))
  320. {
  321. condition += " and b.KqSnNo like '%" + KqSnNo + "%'";
  322. }
  323. if (!string.IsNullOrEmpty(MerIdcardNo))
  324. {
  325. condition += " and b.MerIdcardNo like '%" + MerIdcardNo + "%'";
  326. }
  327. var amount = 0.00M;
  328. List<Dictionary<string, object>> diclist = new List<Dictionary<string, object>>();
  329. 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);
  330. if (dt.Rows.Count > 0)
  331. {
  332. foreach (DataRow item in dt.Rows)
  333. {
  334. var BindMerchantId = item["BindMerchantId"].ToString();
  335. var BrandId = item["BrandId"].ToString();
  336. var PosSn = item["PosSn"].ToString();
  337. var SeoKeyword = item["SeoKeyword"].ToString();
  338. if (BrandId != "2" && BrandId != "7")
  339. {
  340. SeoKeyword = (decimal.Parse(SeoKeyword) / 100).ToString();
  341. }
  342. amount += decimal.Parse(SeoKeyword);
  343. var KqMerNo = item["KqMerNo"].ToString();
  344. var IdcardNo = item["MerIdcardNo"].ToString();
  345. var MerchantName = item["MerchantName"].ToString();
  346. var Mobile = item["MerchantMobile"].ToString();
  347. Dictionary<string, object> datas = new Dictionary<string, object>();
  348. datas.Add("Id", BindMerchantId);
  349. datas.Add("PosSn", PosSn);
  350. datas.Add("SeoKeyword", SeoKeyword);
  351. datas.Add("KqMerNo", KqMerNo);
  352. datas.Add("IdcardNo", IdcardNo);
  353. datas.Add("MerchantName", MerchantName);
  354. datas.Add("MerchantMobile", Mobile);
  355. diclist.Add(datas);
  356. }
  357. }
  358. Dictionary<string, object> obj = new Dictionary<string, object>();
  359. Dictionary<string, object> other = new Dictionary<string, object>();
  360. var ReturnAmount = amount;
  361. var fReturnAmount = amount * 0.92M;
  362. other.Add("ReturnAmount", ReturnAmount.ToString("f2"));
  363. other.Add("fReturnAmount", fReturnAmount.ToString("f2"));
  364. obj.Add("other", other);
  365. obj.Add("code", 0);
  366. obj.Add("msg", "");
  367. obj.Add("count", diclist.Count);
  368. obj.Add("data", diclist);
  369. return Json(obj);
  370. }
  371. #endregion
  372. #region 批量通过
  373. /// <summary>
  374. /// 批量通过
  375. /// </summary>
  376. /// <returns></returns>
  377. public string BatchSetting(string Id)
  378. {
  379. string[] idlist = Id.Split(new char[] { ',' });
  380. AddSysLog(Id, "PosMerchantInfo", "BatchSetting");
  381. var Ids = "";//商户Id
  382. foreach (string subid in idlist)
  383. {
  384. int id = int.Parse(subid);
  385. Ids += id + ",";
  386. Dictionary<string, object> Fields = new Dictionary<string, object>();
  387. Fields.Add("StandardStatus", 101);//设置为可退押状态
  388. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  389. }
  390. string text = string.Format("商户押金退还批量通过,商户Id: '" + Ids.TrimEnd(',') + "',操作人: '" + SysUserName + "_" + SysRealName + "',Time'" + DateTime.Now + "'");
  391. function.WriteLog(text, "商户押金退还批量通过");
  392. db.SaveChanges();
  393. return "success";
  394. }
  395. #endregion
  396. #region 增加商户
  397. /// <summary>
  398. /// 增加或修改商户信息
  399. /// </summary>
  400. /// <returns></returns>
  401. public IActionResult Add(string right)
  402. {
  403. ViewBag.RightInfo = RightInfo;
  404. ViewBag.right = right;
  405. return View();
  406. }
  407. #endregion
  408. #region 增加商户
  409. /// <summary>
  410. /// 增加或修改商户信息
  411. /// </summary>
  412. /// <returns></returns>
  413. [HttpPost]
  414. public string Add(PosMerchantInfo data)
  415. {
  416. Dictionary<string, object> Fields = new Dictionary<string, object>();
  417. Fields.Add("SeoTitle", data.SeoTitle);
  418. Fields.Add("SeoKeyword", data.SeoKeyword);
  419. Fields.Add("SeoDescription", data.SeoDescription);
  420. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("PosMerchantInfo", Fields, 0);
  421. AddSysLog(data.Id.ToString(), "PosMerchantInfo", "add");
  422. db.SaveChanges();
  423. return "success";
  424. }
  425. #endregion
  426. #region 修改商户
  427. /// <summary>
  428. /// 增加或修改商户信息
  429. /// </summary>
  430. /// <returns></returns>
  431. public IActionResult Edit(string right, int Id = 0)
  432. {
  433. ViewBag.RightInfo = RightInfo;
  434. ViewBag.right = right;
  435. PosMerchantInfo editData = db.PosMerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new PosMerchantInfo();
  436. ViewBag.data = editData;
  437. return View();
  438. }
  439. #endregion
  440. #region 修改商户
  441. /// <summary>
  442. /// 增加或修改商户信息
  443. /// </summary>
  444. /// <returns></returns>
  445. [HttpPost]
  446. public string Edit(PosMerchantInfo data)
  447. {
  448. Dictionary<string, object> Fields = new Dictionary<string, object>();
  449. Fields.Add("SeoTitle", data.SeoTitle);
  450. Fields.Add("SeoKeyword", data.SeoKeyword);
  451. Fields.Add("SeoDescription", data.SeoDescription);
  452. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, data.Id);
  453. AddSysLog(data.Id.ToString(), "PosMerchantInfo", "update");
  454. db.SaveChanges();
  455. return "success";
  456. }
  457. #endregion
  458. #region 删除商户信息
  459. /// <summary>
  460. /// 删除商户信息
  461. /// </summary>
  462. /// <returns></returns>
  463. public string Delete(string Id)
  464. {
  465. string[] idlist = Id.Split(new char[] { ',' });
  466. AddSysLog(Id, "PosMerchantInfo", "del");
  467. foreach (string subid in idlist)
  468. {
  469. int id = int.Parse(subid);
  470. Dictionary<string, object> Fields = new Dictionary<string, object>();
  471. Fields.Add("Status", -1);
  472. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  473. }
  474. db.SaveChanges();
  475. return "success";
  476. }
  477. #endregion
  478. #region 开启
  479. /// <summary>
  480. /// 开启
  481. /// </summary>
  482. /// <returns></returns>
  483. public string Open(string Id)
  484. {
  485. string[] idlist = Id.Split(new char[] { ',' });
  486. AddSysLog(Id, "PosMerchantInfo", "open");
  487. foreach (string subid in idlist)
  488. {
  489. int id = int.Parse(subid);
  490. Dictionary<string, object> Fields = new Dictionary<string, object>();
  491. Fields.Add("Status", 1);
  492. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  493. }
  494. db.SaveChanges();
  495. return "success";
  496. }
  497. #endregion
  498. #region 关闭
  499. /// <summary>
  500. /// 关闭
  501. /// </summary>
  502. /// <returns></returns>
  503. public string Close(string Id)
  504. {
  505. string[] idlist = Id.Split(new char[] { ',' });
  506. AddSysLog(Id, "PosMerchantInfo", "close");
  507. foreach (string subid in idlist)
  508. {
  509. int id = int.Parse(subid);
  510. Dictionary<string, object> Fields = new Dictionary<string, object>();
  511. Fields.Add("Status", 0);
  512. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMerchantInfo", Fields, id);
  513. }
  514. db.SaveChanges();
  515. return "success";
  516. }
  517. #endregion
  518. #region 排序
  519. /// <summary>
  520. /// 排序
  521. /// </summary>
  522. /// <param name="Id"></param>
  523. public string Sort(int Id, int Sort)
  524. {
  525. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("PosMerchantInfo", Sort, Id);
  526. AddSysLog(Id.ToString(), "PosMerchantInfo", "sort");
  527. return "success";
  528. }
  529. #endregion
  530. #region 导入数据
  531. /// <summary>
  532. /// 导入数据
  533. /// </summary>
  534. /// <param name="ExcelData"></param>
  535. public string Import(string ExcelData)
  536. {
  537. ExcelData = HttpUtility.UrlDecode(ExcelData);
  538. JsonData list = JsonMapper.ToObject(ExcelData);
  539. var Ids = "";
  540. for (int i = 1; i < list.Count; i++)
  541. {
  542. JsonData dr = list[i];
  543. string KqMerNo = dr[0].ToString(); // 商户编号
  544. var posMerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.KqMerNo == KqMerNo) ?? new PosMerchantInfo();
  545. posMerchantInfo.StandardStatus = -2;
  546. Ids += posMerchantInfo.Id + ",";
  547. db.SaveChanges();
  548. }
  549. AddSysLog("0", "PosMerchantInfo", "Import");
  550. string text = string.Format("导入人工已退,商户Id: '" + Ids.TrimEnd(',') + "',操作人: '" + SysUserName + "_" + SysRealName + "',Time'" + DateTime.Now + "'");
  551. function.WriteLog(text, "导入人工已退");
  552. RedisDbconn.Instance.AddList("ToAlipayAccountQueue", Ids.TrimEnd(','));
  553. return "success";
  554. }
  555. #endregion
  556. #region 导出Excel
  557. /// <summary>
  558. /// 导出Excel
  559. /// </summary>
  560. /// <returns></returns>
  561. public JsonResult ExportExcel(PosMerchantInfo data, string MakerCode, string RealName, string MerMakerCode, string StoreNo, string StoreName, string MerStatusSelect, string ActiveStatusSelect, string ActTypeSelect, string MerUserTypeSelect)
  562. {
  563. Dictionary<string, string> Fields = new Dictionary<string, string>();
  564. Fields.Add("BrandId", "1");
  565. Fields.Add("MerchantNo", "1"); //商户编号
  566. Fields.Add("MerchantName", "1"); //商户姓名
  567. Fields.Add("MerchantMobile", "1"); //商户手机号
  568. Fields.Add("KqMerNo", "1"); //快钱商户编码
  569. Fields.Add("KqSnNo", "1"); //快钱SN号
  570. Fields.Add("KqRegTime", "3"); //渠道注册时间
  571. Fields.Add("TopUserId", "0"); //顶级创客
  572. string condition = " and Status>-1";
  573. //创客编号
  574. if (!string.IsNullOrEmpty(MakerCode))
  575. {
  576. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + MakerCode + "')";
  577. }
  578. //创客名称
  579. if (!string.IsNullOrEmpty(RealName))
  580. {
  581. condition += " and UserId in (select UserId from UserForRealName where RealName='" + RealName + "')";
  582. }
  583. //商户创客编号
  584. if (!string.IsNullOrEmpty(MerMakerCode))
  585. {
  586. condition += " and MerUserId in (select UserId from UserForMakerCode where MakerCode='" + MerMakerCode + "')";
  587. }
  588. //仓库编号
  589. if (!string.IsNullOrEmpty(StoreNo))
  590. {
  591. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreNo + "')";
  592. }
  593. //仓库名称
  594. if (!string.IsNullOrEmpty(RealName))
  595. {
  596. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreName + "')";
  597. }
  598. //商户状态
  599. if (!string.IsNullOrEmpty(MerStatusSelect))
  600. {
  601. condition += " and MerStatus=" + MerStatusSelect;
  602. }
  603. //商户激活状态
  604. if (!string.IsNullOrEmpty(ActiveStatusSelect))
  605. {
  606. condition += " and ActiveStatus=" + ActiveStatusSelect;
  607. }
  608. //激活类型
  609. if (!string.IsNullOrEmpty(ActTypeSelect))
  610. {
  611. condition += " and ActType=" + ActTypeSelect;
  612. }
  613. //商户创客类型
  614. if (!string.IsNullOrEmpty(MerUserTypeSelect))
  615. {
  616. condition += " and MerUserType=" + MerUserTypeSelect;
  617. }
  618. 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);
  619. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  620. foreach (Dictionary<string, object> dic in diclist)
  621. {
  622. //直属创客
  623. int UserId = int.Parse(dic["UserId"].ToString());
  624. Users puser = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  625. dic["MakerCode"] = puser.MakerCode;
  626. dic["RealName"] = puser.RealName;
  627. //顶级创客
  628. int TopUserId = int.Parse(dic["TopUserId"].ToString());
  629. Users tuser = db.Users.FirstOrDefault(m => m.Id == TopUserId) ?? new Users();
  630. dic["TopMakerCode"] = tuser.MakerCode;
  631. dic["TopRealName"] = tuser.RealName;
  632. //商户创客
  633. int MerUserId = int.Parse(dic["MerUserId"].ToString());
  634. Users muser = db.Users.FirstOrDefault(m => m.Id == MerUserId) ?? new Users();
  635. dic["MerMakerCode"] = muser.MakerCode;
  636. dic["MerRealName"] = muser.RealName;
  637. //申请创客
  638. int SnApplyUserId = int.Parse(dic["SnApplyUserId"].ToString());
  639. Users snuser = db.Users.FirstOrDefault(m => m.Id == SnApplyUserId) ?? new Users();
  640. dic["SnApplyMakerCode"] = snuser.MakerCode;
  641. dic["SnApplyRealName"] = snuser.RealName;
  642. //SN仓库
  643. int SnStoreId = int.Parse(dic["SnStoreId"].ToString());
  644. StoreHouse store = db.StoreHouse.FirstOrDefault(m => m.Id == SnStoreId) ?? new StoreHouse();
  645. dic["StoreNo"] = store.StoreNo;
  646. dic["StoreName"] = store.StoreName;
  647. //机具类型
  648. int SnType = int.Parse(dic["SnType"].ToString());
  649. if (SnType == 0) dic["SnType"] = "购买机具";
  650. if (SnType == 1) dic["SnType"] = "赠送机具";
  651. //返利资格
  652. dic["RebateQual"] = dic["RebateQual"].ToString() == "1" ? "是" : "否";
  653. //激活类型
  654. int ActType = int.Parse(dic["ActType"].ToString());
  655. if (ActType == 0) dic["ActType"] = "正常激活";
  656. if (ActType == 1) dic["ActType"] = "首次已激活MPOS";
  657. if (ActType == 2) dic["ActType"] = "首次已激活KPOS";
  658. if (ActType == 3) dic["ActType"] = "循环机划拨激活";
  659. //商户状态
  660. int MerStatus = int.Parse(dic["MerStatus"].ToString());
  661. if (MerStatus == 0) dic["MerStatus"] = "正常";
  662. if (MerStatus == 1) dic["MerStatus"] = "冻结";
  663. if (MerStatus == 2) dic["MerStatus"] = "关闭";
  664. //商户激活状态
  665. int ActiveStatus = int.Parse(dic["ActiveStatus"].ToString());
  666. if (ActiveStatus == 0) dic["ActiveStatus"] = "未激活";
  667. if (ActiveStatus == 1) dic["ActiveStatus"] = "已激活";
  668. if (ActiveStatus == 2) dic["ActiveStatus"] = "SN已返现";
  669. //商户创客类型
  670. int MerUserType = int.Parse(dic["MerUserType"].ToString());
  671. if (MerUserType == 0) dic["MerUserType"] = "非商户型创客";
  672. if (MerUserType == 1) dic["MerUserType"] = "商户型创客";
  673. dic.Remove("UserId");
  674. dic.Remove("TopUserId");
  675. dic.Remove("MerUserId");
  676. dic.Remove("SnApplyUserId");
  677. dic.Remove("SnStoreId");
  678. }
  679. Dictionary<string, object> result = new Dictionary<string, object>();
  680. result.Add("Status", "1");
  681. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  682. result.Add("Obj", diclist);
  683. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  684. ReturnFields.Add("MerchantNo", "商户编号");
  685. ReturnFields.Add("MerchantName", "商户名称");
  686. ReturnFields.Add("MerchantMobile", "商户手机号");
  687. ReturnFields.Add("KqMerNo", "快钱商户编码");
  688. ReturnFields.Add("KqSnNo", "快钱SN号");
  689. ReturnFields.Add("SnType", "机具类型");
  690. ReturnFields.Add("RebateQual", "返利资格");
  691. ReturnFields.Add("ActType", "激活类型");
  692. ReturnFields.Add("MerStatus", "商户状态");
  693. ReturnFields.Add("ActiveStatus", "商户激活状态");
  694. ReturnFields.Add("MerMakerCode", "商户创客编码");
  695. ReturnFields.Add("MerRealName", "商户创客名称");
  696. ReturnFields.Add("MerUserType", "商户创客类型");
  697. ReturnFields.Add("MakerCode", "直属创客编号");
  698. ReturnFields.Add("RealName", "直属创客姓名");
  699. ReturnFields.Add("TopMakerCode", "顶级创客编码");
  700. ReturnFields.Add("TopRealName", "顶级创客名称");
  701. ReturnFields.Add("StoreNo", "SN仓库编号");
  702. ReturnFields.Add("StoreName", "SN仓库名称");
  703. ReturnFields.Add("SnApplyMakerCode", "申请创客编号");
  704. ReturnFields.Add("SnApplyRealName", "申请创客姓名");
  705. ReturnFields.Add("KqRegTime", "注册时间");
  706. result.Add("Fields", ReturnFields);
  707. AddSysLog("0", "PosMerchantInfo", "ExportExcel");
  708. return Json(result);
  709. }
  710. #endregion
  711. #region 同步交易额
  712. public IActionResult SycnTradeAmount(string right, int Id = 0)
  713. {
  714. ViewBag.RightInfo = RightInfo;
  715. ViewBag.right = right;
  716. PosMerchantInfo editData = db.PosMerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new PosMerchantInfo();
  717. ViewBag.data = editData;
  718. return View();
  719. }
  720. #endregion
  721. #region 同步交易额
  722. [HttpPost]
  723. public string SycnTradeAmountDo(DateTime sdate, DateTime edate, int MerchantId)
  724. {
  725. if (sdate.AddMonths(1) < edate)
  726. {
  727. return "时间间隔不能超过1个月";
  728. }
  729. if (edate >= DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00"))
  730. {
  731. return "结束时间只能是今天之前";
  732. }
  733. string check = RedisDbconn.Instance.Get<string>("ResetMerchantTradeQueue:" + MerchantId);
  734. if (!string.IsNullOrEmpty(check))
  735. {
  736. return "请稍后再试";
  737. }
  738. try
  739. {
  740. RedisDbconn.Instance.AddList("ResetMerchantTradeQueue", MerchantId + "#cut#" + sdate.ToString("yyyy-MM-dd HH:mm:ss") + "#cut#" + edate.ToString("yyyy-MM-dd HH:mm:ss"));
  741. RedisDbconn.Instance.Set("ResetMerchantTradeQueue:" + MerchantId, "wait");
  742. RedisDbconn.Instance.SetExpire("ResetMerchantTradeQueue:" + MerchantId, 3600);
  743. }
  744. catch (Exception ex)
  745. {
  746. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计商户的交易额异常");
  747. return "同步异常";
  748. }
  749. return "success";
  750. }
  751. #endregion
  752. }
  753. }