PosMachinesTwoChangeController.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  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 PosMachinesTwoChangeController : BaseController
  24. {
  25. public PosMachinesTwoChangeController(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(PosMachinesTwo data, string right)
  35. {
  36. ViewBag.RightInfo = RightInfo;
  37. ViewBag.right = right;
  38. return View();
  39. }
  40. #endregion
  41. #region 根据条件查询机具库列表
  42. /// <summary>
  43. /// 机具库列表
  44. /// </summary>
  45. /// <returns></returns>
  46. public JsonResult IndexData(PosMachinesTwo data, string BindingStateSelect, string ActivationStateSelect, string UserIdMakerCode, string UserIdRealName, string StoreIdCode, string StoreIdName, string ActivationDateData, string BindingDateData, string BrandSelect = "1", int page = 1, int limit = 30)
  47. {
  48. Dictionary<string, string> Fields = new Dictionary<string, string>();
  49. Fields.Add("PosSn", "1"); //SN编号
  50. Fields.Add("BrandId", "0"); //品牌
  51. string condition = " and Status>-1 AND BindingState = 1 AND DATE_SUB(CURDATE(), INTERVAL 90 DAY) >= date(BindingTime) and UpFeeFlag=1 and DownFeeFlag=0 and BrandId!=6 and (SeoDescription!='设置成功' or SeoDescription is null or SeoDescription='')";
  52. //绑定状态
  53. if (!string.IsNullOrEmpty(BindingStateSelect))
  54. {
  55. condition += " and BindingState=" + BindingStateSelect;
  56. }
  57. //激活状态
  58. if (!string.IsNullOrEmpty(ActivationStateSelect))
  59. {
  60. condition += " and ActivationState=" + ActivationStateSelect;
  61. }
  62. //所属创客编号
  63. if (!string.IsNullOrEmpty(UserIdMakerCode))
  64. {
  65. condition += " and BuyUserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  66. }
  67. //所属创客真实姓名
  68. if (!string.IsNullOrEmpty(UserIdRealName))
  69. {
  70. condition += " and BuyUserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  71. }
  72. //所属仓库编号
  73. if (!string.IsNullOrEmpty(StoreIdCode))
  74. {
  75. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreIdCode + "')";
  76. }
  77. //所属仓库名称
  78. if (!string.IsNullOrEmpty(StoreIdName))
  79. {
  80. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreIdName + "')";
  81. }
  82. //品牌
  83. if (!string.IsNullOrEmpty(BrandSelect))
  84. {
  85. condition += " and BrandId = " + Convert.ToInt32(BrandSelect);
  86. }
  87. if (!string.IsNullOrEmpty(ActivationDateData))
  88. {
  89. string[] datelist = ActivationDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  90. string start = datelist[0];
  91. string end = datelist[1];
  92. condition += " and ActivationTime>='" + start + " 00:00:00' and ActivationTime<='" + end + " 23:59:59'";
  93. }
  94. if (!string.IsNullOrEmpty(BindingDateData))
  95. {
  96. string[] datelist = BindingDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  97. string start = datelist[0];
  98. string end = datelist[1];
  99. condition += " and BindingTime>='" + start + " 00:00:00' and BindingTime<='" + end + " 23:59:59'";
  100. }
  101. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosMachinesTwo", Fields, "Id desc", "0", page, limit, condition);
  102. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  103. foreach (Dictionary<string, object> dic in diclist)
  104. {
  105. //是否真实调升/降
  106. if (!string.IsNullOrEmpty(dic["ActivityList"].ToString()))
  107. {
  108. string ActivityList = dic["ActivityList"].ToString();
  109. if (ActivityList == "1") dic["ActivityList"] = "已真实调升";
  110. if (ActivityList == "2") dic["ActivityList"] = "已真实调降";
  111. }
  112. if (string.IsNullOrEmpty(dic["ActivityList"].ToString()))
  113. {
  114. dic["ActivityList"] = "";
  115. }
  116. //绑定状态
  117. int BindingState = int.Parse(dic["BindingState"].ToString());
  118. if (BindingState == 0) dic["BindingState"] = "未绑定";
  119. if (BindingState == 1) dic["BindingState"] = "已绑定";
  120. //激活状态
  121. int ActivationState = int.Parse(dic["ActivationState"].ToString());
  122. if (ActivationState == 0) dic["ActivationState"] = "未激活";
  123. if (ActivationState == 1) dic["ActivationState"] = "已激活";
  124. //所属创客
  125. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  126. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  127. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  128. dic["UserIdRealName"] = userid_Users.RealName;
  129. dic.Remove("UserId");
  130. //所属仓库
  131. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  132. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  133. dic["StoreIdCode"] = storeid_StoreHouse.StoreNo;
  134. dic["StoreIdName"] = storeid_StoreHouse.StoreName;
  135. dic.Remove("StoreId");
  136. //产品类型
  137. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  138. //绑定商户
  139. int BindMerchantId = int.Parse(function.CheckInt(dic["BindMerchantId"].ToString()));
  140. PosMerchantInfo bindmerchantid_MerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == BindMerchantId) ?? new PosMerchantInfo();
  141. dic["BindMerchantIdMerchantNo"] = bindmerchantid_MerchantInfo.MerchantNo;
  142. dic["BindMerchantIdMerchantName"] = bindmerchantid_MerchantInfo.MerchantName;
  143. dic.Remove("BindMerchantId");
  144. //机具类型
  145. int PosSnType = int.Parse(dic["PosSnType"].ToString());
  146. if (PosSnType == 0) dic["PosSnType"] = "兑换机具";
  147. if (PosSnType == 1) dic["PosSnType"] = "循环机具";
  148. //设备类型
  149. string DeviceType = dic["DeviceType"].ToString();
  150. if (DeviceType == "KysSignPos") dic["DeviceType"] = "快益刷电签POS";
  151. if (DeviceType == "KssSignPos") dic["DeviceType"] = "快闪刷电签POS";
  152. if (DeviceType == "") dic["DeviceType"] = "";
  153. //盟主信息
  154. int LeaderUserId = int.Parse(function.CheckInt(dic["LeaderUserId"].ToString()));
  155. if (LeaderUserId != 0)
  156. {
  157. Users users = db.Users.FirstOrDefault(m => m.Id == LeaderUserId) ?? new Users();
  158. dic["UserInfo"] = users.MakerCode + "_" + users.RealName;
  159. }
  160. //是否为第一台机具
  161. int IsFirst = int.Parse(dic["IsFirst"].ToString());
  162. int FirstFlag = int.Parse(dic["FirstFlag"].ToString());
  163. // if (IsFirst == 0) dic["IsFirst"] = "否";
  164. // if (IsFirst == 1) dic["IsFirst"] = "是";
  165. dic["IsFirst"] = FirstFlag == 1 ? "首台" : "非首台"; //是否首台(服务费领取)
  166. dic["PosIsFirst"] = IsFirst == 1 ? "首台" : "非首台"; //是否首台(机具奖励发放)
  167. //循环开始时间
  168. if (!string.IsNullOrEmpty(dic["RecycEndDate"].ToString()))
  169. {
  170. var RecycStartDate = Convert.ToDateTime(dic["RecycEndDate"].ToString()).AddMonths(-3).ToString("yyyy-MM-dd HH:mm:ss");
  171. dic["RecycStartDate"] = RecycStartDate;
  172. }
  173. //是否调升
  174. int UpFeeFlag = int.Parse(dic["UpFeeFlag"].ToString());
  175. if (UpFeeFlag == 0) dic["UpFeeFlag"] = "否";
  176. if (UpFeeFlag == 1) dic["UpFeeFlag"] = "是";
  177. //是否调降
  178. int DownFeeFlag = int.Parse(dic["DownFeeFlag"].ToString());
  179. if (DownFeeFlag == 0) dic["DownFeeFlag"] = "否";
  180. if (DownFeeFlag == 1) dic["DownFeeFlag"] = "是";
  181. //调升时间
  182. if (!string.IsNullOrEmpty(dic["UpFeeDate"].ToString()))
  183. {
  184. var UpFeeDate = Convert.ToDateTime(dic["UpFeeDate"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
  185. dic["UpFeeDate"] = UpFeeDate;
  186. }
  187. //调降时间
  188. if (!string.IsNullOrEmpty(dic["DownFeeDate"].ToString()))
  189. {
  190. var DownFeeDate = Convert.ToDateTime(dic["DownFeeDate"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
  191. dic["DownFeeDate"] = DownFeeDate;
  192. }
  193. }
  194. Dictionary<string, object> other = new Dictionary<string, object>();
  195. int TotalCount = 0;//总机具数
  196. DataTable dt = OtherMySqlConn.dtable("select count(0) from PosMachinesTwo where 1=1" + condition);
  197. if (dt.Rows.Count > 0)
  198. {
  199. TotalCount = int.Parse(function.CheckNum(dt.Rows[0][0].ToString()));
  200. }
  201. other.Add("TotalCount", TotalCount);
  202. other.Add("KysCount99", 0);
  203. other.Add("KssCount99", 0);
  204. other.Add("KssCoun198", 0);
  205. other.Add("KssCount298", 0);
  206. obj.Add("other", other);
  207. return Json(obj);
  208. }
  209. #endregion
  210. #region 增加机具库
  211. /// <summary>
  212. /// 增加或修改机具库信息
  213. /// </summary>
  214. /// <returns></returns>
  215. public IActionResult Add(string right)
  216. {
  217. ViewBag.RightInfo = RightInfo;
  218. ViewBag.right = right;
  219. return View();
  220. }
  221. #endregion
  222. #region 增加机具库
  223. /// <summary>
  224. /// 增加或修改机具库信息
  225. /// </summary>
  226. /// <returns></returns>
  227. [HttpPost]
  228. public string Add(PosMachinesTwo data)
  229. {
  230. Dictionary<string, object> Fields = new Dictionary<string, object>();
  231. Fields.Add("SeoTitle", data.SeoTitle);
  232. Fields.Add("SeoKeyword", data.SeoKeyword);
  233. Fields.Add("SeoDescription", data.SeoDescription);
  234. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("PosMachinesTwo", Fields, 0);
  235. AddSysLog(data.Id.ToString(), "PosMachinesTwo", "add");
  236. db.SaveChanges();
  237. return "success";
  238. }
  239. #endregion
  240. #region 修改机具库
  241. /// <summary>
  242. /// 增加或修改机具库信息
  243. /// </summary>
  244. /// <returns></returns>
  245. public IActionResult Edit(string right, int Id = 0)
  246. {
  247. ViewBag.RightInfo = RightInfo;
  248. ViewBag.right = right;
  249. PosMachinesTwo editData = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id) ?? new PosMachinesTwo();
  250. ViewBag.data = editData;
  251. return View();
  252. }
  253. #endregion
  254. #region 修改机具库
  255. /// <summary>
  256. /// 增加或修改机具库信息
  257. /// </summary>
  258. /// <returns></returns>
  259. [HttpPost]
  260. public string Edit(PosMachinesTwo data)
  261. {
  262. Dictionary<string, object> Fields = new Dictionary<string, object>();
  263. Fields.Add("PosSnType", data.PosSnType);
  264. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, data.Id);
  265. AddSysLog(data.Id.ToString(), "PosMachinesTwo", "update");
  266. db.SaveChanges();
  267. return "success";
  268. }
  269. #endregion
  270. #region 未使用机具归位总仓
  271. /// <summary>
  272. /// 未使用机具归位总仓
  273. /// </summary>
  274. /// <returns></returns>
  275. public IActionResult Home(string right, int Id = 0)
  276. {
  277. ViewBag.RightInfo = RightInfo;
  278. ViewBag.right = right;
  279. PosMachinesTwo editData = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id) ?? new PosMachinesTwo();
  280. ViewBag.data = editData;
  281. return View();
  282. }
  283. #endregion
  284. #region 未使用机具归位总仓
  285. /// <summary>
  286. /// 未使用机具归位总仓
  287. /// </summary>
  288. /// <returns></returns>
  289. [HttpPost]
  290. public string Home(PosMachinesTwo data)
  291. {
  292. Dictionary<string, object> Fields = new Dictionary<string, object>();
  293. Fields.Add("SeoTitle", "");
  294. Fields.Add("SeoKeyword", "");
  295. Fields.Add("PosSnType", 0);
  296. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, data.Id);
  297. AddSysLog(data.Id.ToString(), "PosMachinesTwo", "home");
  298. db.SaveChanges();
  299. return "success";
  300. }
  301. #endregion
  302. #region 删除机具库信息
  303. /// <summary>
  304. /// 删除机具库信息
  305. /// </summary>
  306. /// <returns></returns>
  307. public string Delete(string Id)
  308. {
  309. string[] idlist = Id.Split(new char[] { ',' });
  310. AddSysLog(Id, "PosMachinesTwo", "del");
  311. foreach (string subid in idlist)
  312. {
  313. int id = int.Parse(subid);
  314. Dictionary<string, object> Fields = new Dictionary<string, object>();
  315. Fields.Add("Status", -1);
  316. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, id);
  317. }
  318. db.SaveChanges();
  319. return "success";
  320. }
  321. #endregion
  322. #region 开启
  323. /// <summary>
  324. /// 开启
  325. /// </summary>
  326. /// <returns></returns>
  327. public string Open(string Id)
  328. {
  329. string[] idlist = Id.Split(new char[] { ',' });
  330. AddSysLog(Id, "PosMachinesTwo", "open");
  331. foreach (string subid in idlist)
  332. {
  333. int id = int.Parse(subid);
  334. Dictionary<string, object> Fields = new Dictionary<string, object>();
  335. Fields.Add("Status", 1);
  336. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, id);
  337. }
  338. db.SaveChanges();
  339. return "success";
  340. }
  341. #endregion
  342. #region 关闭
  343. /// <summary>
  344. /// 关闭
  345. /// </summary>
  346. /// <returns></returns>
  347. public string Close(string Id)
  348. {
  349. string[] idlist = Id.Split(new char[] { ',' });
  350. AddSysLog(Id, "PosMachinesTwo", "close");
  351. foreach (string subid in idlist)
  352. {
  353. int id = int.Parse(subid);
  354. Dictionary<string, object> Fields = new Dictionary<string, object>();
  355. Fields.Add("Status", 0);
  356. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, id);
  357. }
  358. db.SaveChanges();
  359. return "success";
  360. }
  361. #endregion
  362. #region 排序
  363. /// <summary>
  364. /// 排序
  365. /// </summary>
  366. /// <param name="Id"></param>
  367. public string Sort(int Id, int Sort)
  368. {
  369. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("PosMachinesTwo", Sort, Id);
  370. AddSysLog(Id.ToString(), "PosMachinesTwo", "sort");
  371. return "success";
  372. }
  373. #endregion
  374. #region 批量调升费率
  375. /// <summary>
  376. /// 批量调升费率
  377. /// </summary>
  378. /// <returns></returns>
  379. public string BatchSetting(string Id)
  380. {
  381. string opdate = function.ReadInstance("/PublicParams/UpFeeDate/" + DateTime.Now.ToString("yyyyMMdd") + ".txt");
  382. if (!string.IsNullOrEmpty(opdate))
  383. {
  384. return "已提交,请勿重复操作";
  385. }
  386. function.WritePage("/PublicParams/UpFeeDate/", DateTime.Now.ToString("yyyyMMdd") + ".txt", DateTime.Now.ToString("HH:mm:ss"));
  387. AddSysLog(Id, "PosMachinesTwo", "UpFeePosMachinesTwo");
  388. List<int> posIds = new List<int>();
  389. List<int> upposIds = new List<int>();
  390. string userIds = "";
  391. DateTime check = DateTime.Now.AddDays(-90);
  392. List<PosMachinesTwo> poslist = db.PosMachinesTwo.Where(m => m.Status > -1 && m.BindingState == 1 && m.UserNav == "85天调升提醒" && m.DownFeeFlag == 0 && m.BindingTime <= check && m.SeoDescription != "设置成功" && m.BrandId != 6).ToList();//非盒子
  393. foreach (PosMachinesTwo pos in poslist)
  394. {
  395. Dictionary<string, object> Fields = new Dictionary<string, object>();
  396. Fields.Add("UpFeeFlag", 1);
  397. Fields.Add("UpFeeMan", SysUserName);
  398. Fields.Add("UpFeeDate", DateTime.Now);
  399. if (!userIds.Contains(pos.BuyUserId.ToString()))
  400. {
  401. userIds += pos.BuyUserId + ",";
  402. }
  403. string info = "{\"RecordId\":\"\",\"PosId\":\"" + pos.Id + "\",\"Fee\": \"" + 0.63 + "\",\"Kind\": \"" + 1 + "\",\"OpMan\": \"" + SysUserName + "\"}";
  404. RedisDbconn.Instance.AddList("SetDepositPostQueue", info);
  405. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, pos.Id);
  406. }
  407. db.SaveChanges();
  408. return "success";
  409. }
  410. #endregion
  411. #region 导入费率调整结果
  412. /// <summary>
  413. /// 导入费率调整结果
  414. /// </summary>
  415. /// <param name="ExcelData"></param>
  416. public string ImportEnd(string ExcelData)
  417. {
  418. ExcelData = HttpUtility.UrlDecode(ExcelData);
  419. JsonData list = JsonMapper.ToObject(ExcelData);
  420. List<int> dnposIds = new List<int>();
  421. string userIds = "";
  422. string warning = "";
  423. for (int i = 1; i < list.Count; i++)
  424. {
  425. JsonData dr = list[i];
  426. string PosNo = dr[0].ToString(); // 机具Sn
  427. var Amount = double.Parse(dr[1].ToString()); // 调整费率
  428. int Kind = int.Parse(dr[2].ToString()); // 1 调升 2 调低
  429. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosNo) ?? new PosMachinesTwo();
  430. if (pos.UpFeeFlag == 1)
  431. {
  432. if (Kind != 2 || Amount != 0.6)
  433. {
  434. warning += PosNo + ",该机具调低费率数值或类型不正确,请检查好后全部重新导入";
  435. }
  436. else
  437. {
  438. if (Kind == 2 && Amount == 0.6)
  439. {
  440. pos.DownFeeFlag = 1;
  441. pos.DownFeeDate = DateTime.Now;
  442. pos.DownFeeMan = SysUserName + "_" + SysRealName;
  443. var poschange = db.PosMachinesFeeChangeRecord.FirstOrDefault(m => m.PosId == pos.Id);
  444. poschange.Status = 1;
  445. db.SaveChanges();
  446. dnposIds.Add(pos.Id);
  447. }
  448. if (!userIds.Contains(pos.BuyUserId.ToString()))
  449. {
  450. userIds += pos.BuyUserId + ",";
  451. }
  452. }
  453. }
  454. else
  455. {
  456. warning += PosNo + ",该机具不符合调低条件,请检查好后全部重新导入";
  457. }
  458. }
  459. if (!string.IsNullOrEmpty(warning))
  460. {
  461. return "waning |" + warning;
  462. }
  463. string[] lists = userIds.TrimEnd(',').Split(new char[] { ',' });
  464. int times = lists.ToList().Count;
  465. if (dnposIds.Count > 0)
  466. {
  467. //调降
  468. for (int i = 0; i < times; i++)
  469. {
  470. var UserId = lists[i];
  471. var posInfo = db.PosMachinesTwo.Where(m => dnposIds.Contains(m.Id) && m.BuyUserId == Convert.ToInt32(UserId)).ToList();
  472. string snhtml = "<div style='margin-bottom: .48rem;'>";
  473. foreach (var items in posInfo)
  474. {
  475. var mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == items.BindMerchantId);
  476. string Name = mer.MerchantName;
  477. if (mer.BrandId == 2)
  478. {
  479. if (Name.Contains("-"))
  480. {
  481. Name = Name.Split('-')[1];
  482. }
  483. else if (Name.Contains("_"))
  484. {
  485. Name = Name.Split('_')[1];
  486. }
  487. }
  488. var brand = db.KqProducts.FirstOrDefault(m => m.Id == items.BrandId);
  489. snhtml += "<div style='margin-bottom: .48rem;'><div class='f16'>商户姓名:" + Name + "</div>";
  490. snhtml += "<div class='f16'>机具品牌:" + brand.Name + "</div>";
  491. snhtml += "<div class='f16'>SN:" + items.PosSn + "</div>";
  492. snhtml += "<div class='f16'>当前费率:0.6%</div>";
  493. snhtml += "<div class='f16'>费率调整时间:" + items.DownFeeDate + "</div></div>";
  494. }
  495. snhtml += "</div>";
  496. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  497. {
  498. UserId = Convert.ToInt32(UserId), //创客
  499. Title = "商户费率变更通知", //标题
  500. Content = "<div class='f16' style='margin-bottom: .72rem'>您的商户刷卡交易费率已变更成功!</div>" + snhtml, //内容
  501. Summary = "您的商户刷卡交易费率已变更成功!",
  502. CreateDate = DateTime.Now,
  503. }));
  504. }
  505. }
  506. AddSysLog("0", "PosMachinesTwoChange", "ImportEnd");
  507. return "success";
  508. }
  509. #endregion
  510. #region 导入数据
  511. public IActionResult Import(string right)
  512. {
  513. ViewBag.RightInfo = RightInfo;
  514. ViewBag.right = right;
  515. return View();
  516. }
  517. /// <summary>
  518. /// 导入数据
  519. /// </summary>
  520. /// <param name="ExcelData"></param>
  521. [HttpPost]
  522. public string ImportPost(string ExcelPath)
  523. {
  524. string key = function.MD5_16(Guid.NewGuid().ToString());
  525. RedisDbconn.Instance.AddList("ExcelImport10", ExcelPath + "#cut#ChangeFee#cut#" + key + "#cut#" + SysUserName);
  526. return "success|" + key;
  527. }
  528. public string CheckImport(string key)
  529. {
  530. string result = RedisDbconn.Instance.Get<string>("CheckImport:" + key);
  531. if (!string.IsNullOrEmpty(result))
  532. {
  533. string[] datalist = result.Split('|');
  534. if (datalist[0] == "success")
  535. {
  536. return result;
  537. }
  538. return datalist[0];
  539. }
  540. return "0";
  541. }
  542. public Dictionary<string, object> CheckImportV2(string key)
  543. {
  544. Dictionary<string, object> Obj = new Dictionary<string, object>();
  545. string result = RedisDbconn.Instance.Get<string>("CheckImport:" + key);
  546. if (!string.IsNullOrEmpty(result))
  547. {
  548. string[] datalist = result.Split('|');
  549. if (datalist[0] == "success")
  550. {
  551. List<string> errList = RedisDbconn.Instance.GetList<string>("ErrList" + key);
  552. if (errList.Count > 0)
  553. {
  554. Obj.Add("status", 2);
  555. Obj.Add("errList", errList);
  556. }
  557. else
  558. {
  559. Obj.Add("status", 1);
  560. Obj.Add("data", result);
  561. }
  562. return Obj;
  563. }
  564. Obj.Add("status", 0);
  565. Obj.Add("data", datalist[0]);
  566. return Obj;
  567. }
  568. Obj.Add("status", -1);
  569. Obj.Add("data", "执行中...");
  570. return Obj;
  571. }
  572. #endregion
  573. #region 导出Excel
  574. /// <summary>
  575. /// 导出Excel
  576. /// </summary>
  577. /// <returns></returns>
  578. public JsonResult ExportExcel(PosMachinesTwo data, string BindingStateSelect, string ActivationStateSelect, string UserIdMakerCode, string UserIdRealName, string StoreIdCode, string StoreIdName, string UpFeeFlagSelect)
  579. {
  580. Dictionary<string, string> Fields = new Dictionary<string, string>();
  581. Fields.Add("PosSn", "1"); //SN编号
  582. Fields.Add("BrandId", "0"); //品牌
  583. string condition = " and Status>-1 and BrandId = " + data.BrandId + " ";
  584. //绑定状态
  585. if (!string.IsNullOrEmpty(BindingStateSelect))
  586. {
  587. condition += " and BindingState=" + BindingStateSelect;
  588. }
  589. //激活状态
  590. if (!string.IsNullOrEmpty(ActivationStateSelect))
  591. {
  592. condition += " and ActivationState=" + ActivationStateSelect;
  593. }
  594. //所属创客编号
  595. if (!string.IsNullOrEmpty(UserIdMakerCode))
  596. {
  597. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  598. }
  599. //所属创客真实姓名
  600. if (!string.IsNullOrEmpty(UserIdRealName))
  601. {
  602. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  603. }
  604. //所属仓库编号
  605. if (!string.IsNullOrEmpty(StoreIdCode))
  606. {
  607. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreIdCode + "')";
  608. }
  609. //所属仓库名称
  610. if (!string.IsNullOrEmpty(StoreIdName))
  611. {
  612. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreIdName + "')";
  613. }
  614. //是否调整
  615. if (!string.IsNullOrEmpty(UpFeeFlagSelect))
  616. {
  617. condition += " and UpFeeFlag = " + UpFeeFlagSelect;
  618. }
  619. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosMachinesTwo", Fields, "Id desc", "0", 1, 20000, condition, "BindingState,ActivationState,UserId,StoreId,PosSn,BrandId,ActivityList,BindMerchantId,PosSnType,DeviceType,BindingTime,UpFeeDate,DownFeeDate,ActivationTime,TransferTime", false);
  620. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  621. foreach (Dictionary<string, object> dic in diclist)
  622. {
  623. //绑定状态
  624. int BindingState = int.Parse(dic["BindingState"].ToString());
  625. if (BindingState == 0) dic["BindingState"] = "未绑定";
  626. if (BindingState == 1) dic["BindingState"] = "已绑定";
  627. //绑定时间
  628. if (!string.IsNullOrEmpty(dic["BindingTime"].ToString()))
  629. {
  630. DateTime BindingTime = Convert.ToDateTime(dic["BindingTime"].ToString());
  631. }
  632. //激活状态
  633. int ActivationState = int.Parse(dic["ActivationState"].ToString());
  634. if (ActivationState == 0) dic["ActivationState"] = "未激活";
  635. if (ActivationState == 1) dic["ActivationState"] = "已激活";
  636. //激活时间
  637. if (!string.IsNullOrEmpty(dic["ActivationTime"].ToString()))
  638. {
  639. DateTime ActivationTime = Convert.ToDateTime(dic["ActivationTime"].ToString());
  640. }
  641. //划拨时间
  642. if (!string.IsNullOrEmpty(dic["TransferTime"].ToString()))
  643. {
  644. DateTime TransferTime = Convert.ToDateTime(dic["TransferTime"].ToString());
  645. }
  646. //调升时间
  647. if (!string.IsNullOrEmpty(dic["UpFeeDate"].ToString()))
  648. {
  649. DateTime UpFeeDate = Convert.ToDateTime(dic["UpFeeDate"].ToString());
  650. }
  651. //调降时间
  652. if (!string.IsNullOrEmpty(dic["DownFeeDate"].ToString()))
  653. {
  654. DateTime DownFeeDate = Convert.ToDateTime(dic["DownFeeDate"].ToString());
  655. }
  656. //所属创客
  657. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  658. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  659. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  660. dic["UserIdRealName"] = userid_Users.RealName;
  661. dic.Remove("UserId");
  662. //所属仓库
  663. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  664. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  665. dic["StoreIdCode"] = storeid_StoreHouse.StoreNo;
  666. dic["StoreIdName"] = storeid_StoreHouse.StoreName;
  667. dic.Remove("StoreId");
  668. //产品类型
  669. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  670. //绑定商户
  671. int BindMerchantId = int.Parse(function.CheckInt(dic["BindMerchantId"].ToString()));
  672. PosMerchantInfo bindmerchantid_MerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == BindMerchantId) ?? new PosMerchantInfo();
  673. dic["BindMerchantIdMerchantNo"] = bindmerchantid_MerchantInfo.MerchantNo;
  674. dic["BindMerchantIdMerchantName"] = bindmerchantid_MerchantInfo.MerchantName;
  675. dic.Remove("BindMerchantId");
  676. //机具类型
  677. int PosSnType = int.Parse(dic["PosSnType"].ToString());
  678. if (PosSnType == 0) dic["PosSnType"] = "兑换机具";
  679. if (PosSnType == 1) dic["PosSnType"] = "循环机具";
  680. }
  681. Dictionary<string, object> result = new Dictionary<string, object>();
  682. result.Add("Status", "1");
  683. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  684. result.Add("Obj", diclist);
  685. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  686. ReturnFields.Add("UserIdMakerCode", "创客编号");
  687. ReturnFields.Add("UserIdRealName", "创客姓名");
  688. ReturnFields.Add("StoreIdCode", "仓库编号");
  689. ReturnFields.Add("StoreIdName", "仓库名称");
  690. ReturnFields.Add("BrandId", "产品类型");
  691. ReturnFields.Add("PosSn", "SN编号");
  692. ReturnFields.Add("PosSnType", "SN类型");
  693. ReturnFields.Add("BindMerchantIdMerchantNo", "绑定商户编号");
  694. ReturnFields.Add("BindMerchantIdMerchantName", "绑定商户姓名");
  695. ReturnFields.Add("DeviceType", "设备类型");
  696. ReturnFields.Add("BindingState", "绑定状态");
  697. ReturnFields.Add("BindingTime", "绑定时间");
  698. ReturnFields.Add("ActivationState", "激活状态");
  699. ReturnFields.Add("ActivationTime", "激活时间");
  700. ReturnFields.Add("TransferTime", "划拨时间");
  701. ReturnFields.Add("UpFeeFlag", "调升标记");
  702. ReturnFields.Add("UpFeeDate", "调升时间");
  703. ReturnFields.Add("UpFeeMan", "调升人");
  704. ReturnFields.Add("DownFeeFlag", "调降标记");
  705. ReturnFields.Add("DownFeeDate", "调降时间");
  706. ReturnFields.Add("DownFeeMan", "调降人");
  707. result.Add("Fields", ReturnFields);
  708. AddSysLog("0", "PosMachinesTwo", "ExportExcel");
  709. return Json(result);
  710. }
  711. #endregion
  712. }
  713. }