PosMachinesTwoChangeController.cs 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953
  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 UpFeeFlagSelect, string UserIdMakerCode, string UserIdRealName, string StoreIdCode, string StoreIdName, string ActivationDateData, string BindingDateData, 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 180 DAY) >= date(BindingTime)";
  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 (data.BrandId == 0)
  84. {
  85. condition += " and BrandId = 1";
  86. }
  87. if (data.BrandId != 0)
  88. {
  89. condition += " and BrandId = " + data.BrandId;
  90. }
  91. if (!string.IsNullOrEmpty(UpFeeFlagSelect))
  92. {
  93. condition += " and UpFeeFlag = " + UpFeeFlagSelect;
  94. }
  95. if (!string.IsNullOrEmpty(ActivationDateData))
  96. {
  97. string[] datelist = ActivationDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  98. string start = datelist[0];
  99. string end = datelist[1];
  100. condition += " and ActivationTime>='" + start + " 00:00:00' and ActivationTime<='" + end + " 23:59:59'";
  101. }
  102. if (!string.IsNullOrEmpty(BindingDateData))
  103. {
  104. string[] datelist = BindingDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  105. string start = datelist[0];
  106. string end = datelist[1];
  107. condition += " and BindingTime>='" + start + " 00:00:00' and BindingTime<='" + end + " 23:59:59'";
  108. }
  109. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosMachinesTwo", Fields, "Id desc", "0", page, limit, condition);
  110. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  111. foreach (Dictionary<string, object> dic in diclist)
  112. {
  113. //绑定状态
  114. int BindingState = int.Parse(dic["BindingState"].ToString());
  115. if (BindingState == 0) dic["BindingState"] = "未绑定";
  116. if (BindingState == 1) dic["BindingState"] = "已绑定";
  117. //激活状态
  118. int ActivationState = int.Parse(dic["ActivationState"].ToString());
  119. if (ActivationState == 0) dic["ActivationState"] = "未激活";
  120. if (ActivationState == 1) dic["ActivationState"] = "已激活";
  121. //所属创客
  122. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  123. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  124. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  125. dic["UserIdRealName"] = userid_Users.RealName;
  126. dic.Remove("UserId");
  127. //所属仓库
  128. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  129. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  130. dic["StoreIdCode"] = storeid_StoreHouse.StoreNo;
  131. dic["StoreIdName"] = storeid_StoreHouse.StoreName;
  132. dic.Remove("StoreId");
  133. //产品类型
  134. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  135. //参加活动
  136. dic["ActivityList"] = RelationClass.GetProfitObjectsActivesList(dic["ActivityList"].ToString());
  137. //绑定商户
  138. int BindMerchantId = int.Parse(function.CheckInt(dic["BindMerchantId"].ToString()));
  139. PosMerchantInfo bindmerchantid_MerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == BindMerchantId) ?? new PosMerchantInfo();
  140. dic["BindMerchantIdMerchantNo"] = bindmerchantid_MerchantInfo.MerchantNo;
  141. dic["BindMerchantIdMerchantName"] = bindmerchantid_MerchantInfo.MerchantName;
  142. dic.Remove("BindMerchantId");
  143. //机具类型
  144. int PosSnType = int.Parse(dic["PosSnType"].ToString());
  145. if (PosSnType == 0) dic["PosSnType"] = "购买机具";
  146. if (PosSnType == 1) dic["PosSnType"] = "赠送机具";
  147. //设备类型
  148. string DeviceType = dic["DeviceType"].ToString();
  149. if (DeviceType == "KysSignPos") dic["DeviceType"] = "快益刷电签POS";
  150. if (DeviceType == "KssSignPos") dic["DeviceType"] = "快闪刷电签POS";
  151. if (DeviceType == "") dic["DeviceType"] = "";
  152. //盟主信息
  153. int LeaderUserId = int.Parse(function.CheckInt(dic["LeaderUserId"].ToString()));
  154. if (LeaderUserId != 0)
  155. {
  156. Users users = db.Users.FirstOrDefault(m => m.Id == LeaderUserId) ?? new Users();
  157. dic["UserInfo"] = users.MakerCode + "_" + users.RealName;
  158. }
  159. //是否为第一台机具
  160. int IsFirst = int.Parse(dic["IsFirst"].ToString());
  161. if (IsFirst == 0) dic["IsFirst"] = "否";
  162. if (IsFirst == 1) dic["IsFirst"] = "是";
  163. //循环开始时间
  164. if (!string.IsNullOrEmpty(dic["RecycEndDate"].ToString()))
  165. {
  166. var RecycStartDate = Convert.ToDateTime(dic["RecycEndDate"].ToString()).AddMonths(-3).ToString("yyyy-MM-dd HH:mm:ss");
  167. dic["RecycStartDate"] = RecycStartDate;
  168. }
  169. //是否调升
  170. int UpFeeFlag = int.Parse(dic["UpFeeFlag"].ToString());
  171. if (UpFeeFlag == 0) dic["UpFeeFlag"] = "否";
  172. if (UpFeeFlag == 1) dic["UpFeeFlag"] = "是";
  173. //是否调降
  174. int DownFeeFlag = int.Parse(dic["DownFeeFlag"].ToString());
  175. if (DownFeeFlag == 0) dic["DownFeeFlag"] = "否";
  176. if (DownFeeFlag == 1) dic["DownFeeFlag"] = "是";
  177. //调升时间
  178. if (!string.IsNullOrEmpty(dic["UpFeeDate"].ToString()))
  179. {
  180. var UpFeeDate = Convert.ToDateTime(dic["UpFeeDate"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
  181. dic["UpFeeDate"] = UpFeeDate;
  182. }
  183. //调降时间
  184. if (!string.IsNullOrEmpty(dic["DownFeeDate"].ToString()))
  185. {
  186. var DownFeeDate = Convert.ToDateTime(dic["DownFeeDate"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
  187. dic["DownFeeDate"] = DownFeeDate;
  188. }
  189. }
  190. Dictionary<string, object> other = new Dictionary<string, object>();
  191. int TotalCount = 0;//总机具数
  192. string KysCount99 = "0.00";
  193. string KssCount99 = "0.00";
  194. string KssCoun198 = "0.00";
  195. string KssCount298 = "0.00";
  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. // dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=1" + condition);
  202. // if (dt.Rows.Count > 0)
  203. // {
  204. // FailAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  205. // }
  206. other.Add("TotalCount", TotalCount);
  207. other.Add("KysCount99", 0);
  208. other.Add("KssCount99", 0);
  209. other.Add("KssCoun198", 0);
  210. other.Add("KssCount298", 0);
  211. obj.Add("other", other);
  212. return Json(obj);
  213. }
  214. #endregion
  215. #region 增加机具库
  216. /// <summary>
  217. /// 增加或修改机具库信息
  218. /// </summary>
  219. /// <returns></returns>
  220. public IActionResult Add(string right)
  221. {
  222. ViewBag.RightInfo = RightInfo;
  223. ViewBag.right = right;
  224. return View();
  225. }
  226. #endregion
  227. #region 增加机具库
  228. /// <summary>
  229. /// 增加或修改机具库信息
  230. /// </summary>
  231. /// <returns></returns>
  232. [HttpPost]
  233. public string Add(PosMachinesTwo data)
  234. {
  235. Dictionary<string, object> Fields = new Dictionary<string, object>();
  236. Fields.Add("SeoTitle", data.SeoTitle);
  237. Fields.Add("SeoKeyword", data.SeoKeyword);
  238. Fields.Add("SeoDescription", data.SeoDescription);
  239. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("PosMachinesTwo", Fields, 0);
  240. AddSysLog(data.Id.ToString(), "PosMachinesTwo", "add");
  241. db.SaveChanges();
  242. return "success";
  243. }
  244. #endregion
  245. #region 修改机具库
  246. /// <summary>
  247. /// 增加或修改机具库信息
  248. /// </summary>
  249. /// <returns></returns>
  250. public IActionResult Edit(string right, int Id = 0)
  251. {
  252. ViewBag.RightInfo = RightInfo;
  253. ViewBag.right = right;
  254. PosMachinesTwo editData = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id) ?? new PosMachinesTwo();
  255. ViewBag.data = editData;
  256. return View();
  257. }
  258. #endregion
  259. #region 修改机具库
  260. /// <summary>
  261. /// 增加或修改机具库信息
  262. /// </summary>
  263. /// <returns></returns>
  264. [HttpPost]
  265. public string Edit(PosMachinesTwo data)
  266. {
  267. Dictionary<string, object> Fields = new Dictionary<string, object>();
  268. Fields.Add("PosSnType", data.PosSnType);
  269. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, data.Id);
  270. AddSysLog(data.Id.ToString(), "PosMachinesTwo", "update");
  271. db.SaveChanges();
  272. RedisDbconn.Instance.Clear("PosMachinesTwo:" + data.Id);
  273. return "success";
  274. }
  275. #endregion
  276. #region 未使用机具归位总仓
  277. /// <summary>
  278. /// 未使用机具归位总仓
  279. /// </summary>
  280. /// <returns></returns>
  281. public IActionResult Home(string right, int Id = 0)
  282. {
  283. ViewBag.RightInfo = RightInfo;
  284. ViewBag.right = right;
  285. PosMachinesTwo editData = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id) ?? new PosMachinesTwo();
  286. ViewBag.data = editData;
  287. return View();
  288. }
  289. #endregion
  290. #region 未使用机具归位总仓
  291. /// <summary>
  292. /// 未使用机具归位总仓
  293. /// </summary>
  294. /// <returns></returns>
  295. [HttpPost]
  296. public string Home(PosMachinesTwo data)
  297. {
  298. Dictionary<string, object> Fields = new Dictionary<string, object>();
  299. Fields.Add("SeoTitle", "");
  300. Fields.Add("SeoKeyword", "");
  301. Fields.Add("PosSnType", 0);
  302. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, data.Id);
  303. AddSysLog(data.Id.ToString(), "PosMachinesTwo", "home");
  304. db.SaveChanges();
  305. RedisDbconn.Instance.Clear("PosMachinesTwo:" + data.Id);
  306. return "success";
  307. }
  308. #endregion
  309. #region 删除机具库信息
  310. /// <summary>
  311. /// 删除机具库信息
  312. /// </summary>
  313. /// <returns></returns>
  314. public string Delete(string Id)
  315. {
  316. string[] idlist = Id.Split(new char[] { ',' });
  317. AddSysLog(Id, "PosMachinesTwo", "del");
  318. foreach (string subid in idlist)
  319. {
  320. int id = int.Parse(subid);
  321. Dictionary<string, object> Fields = new Dictionary<string, object>();
  322. Fields.Add("Status", -1);
  323. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, id);
  324. }
  325. db.SaveChanges();
  326. return "success";
  327. }
  328. #endregion
  329. #region 开启
  330. /// <summary>
  331. /// 开启
  332. /// </summary>
  333. /// <returns></returns>
  334. public string Open(string Id)
  335. {
  336. string[] idlist = Id.Split(new char[] { ',' });
  337. AddSysLog(Id, "PosMachinesTwo", "open");
  338. foreach (string subid in idlist)
  339. {
  340. int id = int.Parse(subid);
  341. Dictionary<string, object> Fields = new Dictionary<string, object>();
  342. Fields.Add("Status", 1);
  343. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, id);
  344. }
  345. db.SaveChanges();
  346. return "success";
  347. }
  348. #endregion
  349. #region 关闭
  350. /// <summary>
  351. /// 关闭
  352. /// </summary>
  353. /// <returns></returns>
  354. public string Close(string Id)
  355. {
  356. string[] idlist = Id.Split(new char[] { ',' });
  357. AddSysLog(Id, "PosMachinesTwo", "close");
  358. foreach (string subid in idlist)
  359. {
  360. int id = int.Parse(subid);
  361. Dictionary<string, object> Fields = new Dictionary<string, object>();
  362. Fields.Add("Status", 0);
  363. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, id);
  364. }
  365. db.SaveChanges();
  366. return "success";
  367. }
  368. #endregion
  369. #region 排序
  370. /// <summary>
  371. /// 排序
  372. /// </summary>
  373. /// <param name="Id"></param>
  374. public string Sort(int Id, int Sort)
  375. {
  376. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("PosMachinesTwo", Sort, Id);
  377. AddSysLog(Id.ToString(), "PosMachinesTwo", "sort");
  378. return "success";
  379. }
  380. #endregion
  381. #region 批量调升费率
  382. /// <summary>
  383. /// 批量调升费率
  384. /// </summary>
  385. /// <returns></returns>
  386. public string BatchSetting(string Id)
  387. {
  388. string[] idlist = Id.Split(new char[] { ',' });
  389. AddSysLog(Id, "PosMachinesTwo", "UpFeePosMachinesTwo");
  390. List<int> posIds = new List<int>();
  391. List<int> upposIds = new List<int>();
  392. string userIds = "";
  393. foreach (string subids in idlist)
  394. {
  395. int id = int.Parse(subids);
  396. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == id) ?? new PosMachinesTwo();
  397. Dictionary<string, object> Fields = new Dictionary<string, object>();
  398. Fields.Add("UpFeeFlag", 1);
  399. Fields.Add("UpFeeMan", SysUserName);
  400. Fields.Add("UpFeeDate", DateTime.Now);
  401. if (!userIds.Contains(pos.BuyUserId.ToString()))
  402. {
  403. userIds += pos.BuyUserId + ",";
  404. }
  405. if (pos.BrandId == 1 || pos.BrandId == 3 || pos.BrandId == 6)
  406. {
  407. // PosId:机具Id
  408. // Kind:1或2,1为费率0.63,2为费率0.6
  409. // OpMan:操作人,app传创客编号,后台传SysUserName
  410. string info = "{\"RecordId\":\"\",\"PosId\":\"" + id + "\",\"Fee\": \"" + 0.63 + "\",\"Kind\": \"" + 1 + "\",\"OpMan\": \"" + SysUserName + "\"}";
  411. RedisDbconn.Instance.AddList("SetDepositQueue", info);
  412. }
  413. else
  414. {
  415. upposIds.Add(id);
  416. }
  417. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, id);
  418. }
  419. string[] lists = userIds.TrimEnd(',').Split(new char[] { ',' });
  420. int times = lists.ToList().Count;
  421. if (upposIds.Count > 0)
  422. {
  423. //调升
  424. for (int i = 0; i < times; i++)
  425. {
  426. var UserId = lists[i];
  427. var posInfo = db.PosMachinesTwo.Where(m => upposIds.Contains(m.Id) && m.BuyUserId == Convert.ToInt32(UserId)).ToList();
  428. string snhtml = "<div style='margin-bottom: .48rem;'>";
  429. foreach (var items in posInfo)
  430. {
  431. var mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == items.BindMerchantId);
  432. string Name = mer.MerchantName;
  433. if (mer.BrandId == 2)
  434. {
  435. if (Name.Contains("-"))
  436. {
  437. Name = Name.Split('-')[1];
  438. }
  439. else if (Name.Contains("_"))
  440. {
  441. Name = Name.Split('_')[1];
  442. }
  443. }
  444. var brand = db.KqProducts.FirstOrDefault(m => m.Id == items.BrandId);
  445. snhtml += "<div style='margin-bottom: .48rem;'><div class='f16'>商户姓名:" + Name + "</div>";
  446. snhtml += "<div class='f16'>机具品牌:" + brand.Name + "</div>";
  447. snhtml += "<div class='f16'>SN:" + items.PosSn + "</div></div>";
  448. }
  449. snhtml += "</div>";
  450. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  451. {
  452. UserId = Convert.ToInt32(UserId), //创客
  453. Title = "商户费率变更通知", //标题
  454. Content = "<div class='f16' style='margin-bottom: .72rem'>您的部分机具已绑定超过180天,刷卡费率已自动变更为0.63%,如需调整费率,请前往我的商户-商户详情中调整费率</div>" + snhtml, //内容
  455. Summary = "您的部分机具已绑定超过180天,刷卡费率已自动变更为0.63%,如需调整费率,请前往我的商户-商户详情中调整费率",
  456. CreateDate = DateTime.Now,
  457. }));
  458. }
  459. }
  460. db.SaveChanges();
  461. return "success";
  462. }
  463. #endregion
  464. // #region 批量调升费率(无接口限制)
  465. // /// <summary>
  466. // /// 批量调升费率
  467. // /// </summary>
  468. // /// <returns></returns>
  469. // public string BatchSetting(string Id)
  470. // {
  471. // string[] idlist = Id.Split(new char[] { ',' });
  472. // AddSysLog(Id, "PosMachinesTwo", "UpFeePosMachinesTwo");
  473. // List<int> posIds = new List<int>();
  474. // List<int> upposIds = new List<int>();
  475. // string userIds = "";
  476. // foreach (string subids in idlist)
  477. // {
  478. // int id = int.Parse(subids);
  479. // var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == id) ?? new PosMachinesTwo();
  480. // Dictionary<string, object> Fields = new Dictionary<string, object>();
  481. // Fields.Add("UpFeeFlag", 1);
  482. // Fields.Add("UpFeeMan", SysUserName);
  483. // Fields.Add("UpFeeDate", DateTime.Now);
  484. // if (!userIds.Contains(pos.BuyUserId.ToString()))
  485. // {
  486. // userIds += pos.BuyUserId + ",";
  487. // }
  488. // upposIds.Add(id);
  489. // new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, id);
  490. // }
  491. // string[] lists = userIds.TrimEnd(',').Split(new char[] { ',' });
  492. // int times = lists.ToList().Count;
  493. // if (upposIds.Count > 0)
  494. // {
  495. // //调升
  496. // for (int i = 0; i < times; i++)
  497. // {
  498. // var UserId = lists[i];
  499. // var posInfo = db.PosMachinesTwo.Where(m => upposIds.Contains(m.Id) && m.BuyUserId == Convert.ToInt32(UserId)).ToList();
  500. // string snhtml = "<div style='margin-bottom: .48rem;'>";
  501. // foreach (var items in posInfo)
  502. // {
  503. // var mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == items.BindMerchantId);
  504. // string Name = mer.MerchantName;
  505. // if (mer.BrandId == 2)
  506. // {
  507. // if (Name.Contains("-"))
  508. // {
  509. // Name = Name.Split('-')[1];
  510. // }
  511. // else if (Name.Contains("_"))
  512. // {
  513. // Name = Name.Split('_')[1];
  514. // }
  515. // }
  516. // var brand = db.KqProducts.FirstOrDefault(m => m.Id == items.BrandId);
  517. // snhtml += "<div style='margin-bottom: .48rem;'><div class='f16'>商户姓名:" + Name + "</div>";
  518. // snhtml += "<div class='f16'>机具品牌:" + brand.Name + "</div>";
  519. // snhtml += "<div class='f16'>SN:" + items.PosSn + "</div></div>";
  520. // }
  521. // snhtml += "</div>";
  522. // RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  523. // {
  524. // UserId = Convert.ToInt32(UserId), //创客
  525. // Title = "商户费率变更通知", //标题
  526. // Content = "<div class='f16' style='margin-bottom: .72rem'>您的部分机具已绑定超过180天,刷卡费率已自动变更为0.63%,如需调整费率,请前往我的商户-商户详情中调整费率</div>" + snhtml, //内容
  527. // Summary = "您的部分机具已绑定超过180天,刷卡费率已自动变更为0.63%,如需调整费率,请前往我的商户-商户详情中调整费率",
  528. // CreateDate = DateTime.Now,
  529. // }));
  530. // }
  531. // }
  532. // db.SaveChanges();
  533. // db.Dispose();
  534. // return "success";
  535. // }
  536. // #endregion
  537. #region 导入费率调整结果
  538. /// <summary>
  539. /// 导入费率调整结果
  540. /// </summary>
  541. /// <param name="ExcelData"></param>
  542. public string ImportEnd(string ExcelData)
  543. {
  544. ExcelData = HttpUtility.UrlDecode(ExcelData);
  545. JsonData list = JsonMapper.ToObject(ExcelData);
  546. List<int> dnposIds = new List<int>();
  547. string userIds = "";
  548. string warning = "";
  549. for (int i = 1; i < list.Count; i++)
  550. {
  551. JsonData dr = list[i];
  552. string PosNo = dr[0].ToString(); // 机具Sn
  553. var Amount = double.Parse(dr[1].ToString()); // 调整费率
  554. int Kind = int.Parse(dr[2].ToString()); // 1 调升 2 调低
  555. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosNo) ?? new PosMachinesTwo();
  556. if (pos.UpFeeFlag == 1)
  557. {
  558. if (Kind != 2 || Amount != 0.6)
  559. {
  560. warning += PosNo + ",该机具调低费率数值或类型不正确,请检查好后全部重新导入";
  561. }
  562. else
  563. {
  564. if (Kind == 2 && Amount == 0.6)
  565. {
  566. pos.DownFeeFlag = 1;
  567. pos.DownFeeDate = DateTime.Now;
  568. pos.DownFeeMan = SysUserName + "_" + SysRealName;
  569. var poschange = db.PosMachinesFeeChangeRecord.FirstOrDefault(m => m.PosId == pos.Id);
  570. poschange.Status = 1;
  571. db.SaveChanges();
  572. dnposIds.Add(pos.Id);
  573. }
  574. if (!userIds.Contains(pos.BuyUserId.ToString()))
  575. {
  576. userIds += pos.BuyUserId + ",";
  577. }
  578. }
  579. }
  580. else
  581. {
  582. warning += PosNo + ",该机具不符合调低条件,请检查好后全部重新导入";
  583. }
  584. }
  585. if (!string.IsNullOrEmpty(warning))
  586. {
  587. return "waning |" + warning;
  588. }
  589. string[] lists = userIds.TrimEnd(',').Split(new char[] { ',' });
  590. int times = lists.ToList().Count;
  591. if (dnposIds.Count > 0)
  592. {
  593. //调降
  594. for (int i = 0; i < times; i++)
  595. {
  596. var UserId = lists[i];
  597. var posInfo = db.PosMachinesTwo.Where(m => dnposIds.Contains(m.Id) && m.BuyUserId == Convert.ToInt32(UserId)).ToList();
  598. string snhtml = "<div style='margin-bottom: .48rem;'>";
  599. foreach (var items in posInfo)
  600. {
  601. var mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == items.BindMerchantId);
  602. string Name = mer.MerchantName;
  603. if (mer.BrandId == 2)
  604. {
  605. if (Name.Contains("-"))
  606. {
  607. Name = Name.Split('-')[1];
  608. }
  609. else if (Name.Contains("_"))
  610. {
  611. Name = Name.Split('_')[1];
  612. }
  613. }
  614. var brand = db.KqProducts.FirstOrDefault(m => m.Id == items.BrandId);
  615. snhtml += "<div style='margin-bottom: .48rem;'><div class='f16'>商户姓名:" + Name + "</div>";
  616. snhtml += "<div class='f16'>机具品牌:" + brand.Name + "</div>";
  617. snhtml += "<div class='f16'>SN:" + items.PosSn + "</div>";
  618. snhtml += "<div class='f16'>当前费率:0.6%</div>";
  619. snhtml += "<div class='f16'>费率调整时间:" + items.DownFeeDate + "</div></div>";
  620. }
  621. snhtml += "</div>";
  622. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  623. {
  624. UserId = Convert.ToInt32(UserId), //创客
  625. Title = "商户费率变更通知", //标题
  626. Content = "<div class='f16' style='margin-bottom: .72rem'>您的商户刷卡交易费率已变更成功!</div>" + snhtml, //内容
  627. Summary = "您的商户刷卡交易费率已变更成功!",
  628. CreateDate = DateTime.Now,
  629. }));
  630. }
  631. }
  632. AddSysLog("0", "PosMachinesTwoChange", "ImportEnd");
  633. return "success";
  634. }
  635. #endregion
  636. #region 导入数据
  637. public IActionResult Import(string right)
  638. {
  639. ViewBag.RightInfo = RightInfo;
  640. ViewBag.right = right;
  641. return View();
  642. }
  643. /// <summary>
  644. /// 导入数据
  645. /// </summary>
  646. /// <param name="ExcelData"></param>
  647. [HttpPost]
  648. public string ImportPost(string ExcelPath)
  649. {
  650. string key = function.MD5_16(Guid.NewGuid().ToString());
  651. RedisDbconn.Instance.AddList("ExcelImportV2", ExcelPath + "#cut#ChangeFee#cut#" + key + "#cut#" + SysUserName);
  652. return "success|" + key;
  653. }
  654. public string CheckImport(string key)
  655. {
  656. string result = RedisDbconn.Instance.Get<string>("CheckImport:" + key);
  657. if (!string.IsNullOrEmpty(result))
  658. {
  659. string[] datalist = result.Split('|');
  660. if (datalist[0] == "success")
  661. {
  662. return result;
  663. }
  664. return datalist[0];
  665. }
  666. return "0";
  667. }
  668. public Dictionary<string, object> CheckImportV2(string key)
  669. {
  670. Dictionary<string, object> Obj = new Dictionary<string, object>();
  671. string result = RedisDbconn.Instance.Get<string>("CheckImport:" + key);
  672. if (!string.IsNullOrEmpty(result))
  673. {
  674. string[] datalist = result.Split('|');
  675. if (datalist[0] == "success")
  676. {
  677. List<string> errList = RedisDbconn.Instance.GetList<string>("ErrList" + key);
  678. if (errList.Count > 0)
  679. {
  680. Obj.Add("status", 2);
  681. Obj.Add("errList", errList);
  682. }
  683. else
  684. {
  685. Obj.Add("status", 1);
  686. Obj.Add("data", result);
  687. }
  688. return Obj;
  689. }
  690. Obj.Add("status", 0);
  691. Obj.Add("data", datalist[0]);
  692. return Obj;
  693. }
  694. Obj.Add("status", -1);
  695. Obj.Add("data", "执行中...");
  696. return Obj;
  697. }
  698. #endregion
  699. #region 导出Excel
  700. /// <summary>
  701. /// 导出Excel
  702. /// </summary>
  703. /// <returns></returns>
  704. public JsonResult ExportExcel(PosMachinesTwo data, string BindingStateSelect, string ActivationStateSelect, string UserIdMakerCode, string UserIdRealName, string StoreIdCode, string StoreIdName, string UpFeeFlagSelect)
  705. {
  706. Dictionary<string, string> Fields = new Dictionary<string, string>();
  707. Fields.Add("PosSn", "1"); //SN编号
  708. Fields.Add("BrandId", "0"); //品牌
  709. string condition = " and Status>-1 and BrandId = " + data.BrandId + " ";
  710. //绑定状态
  711. if (!string.IsNullOrEmpty(BindingStateSelect))
  712. {
  713. condition += " and BindingState=" + BindingStateSelect;
  714. }
  715. //激活状态
  716. if (!string.IsNullOrEmpty(ActivationStateSelect))
  717. {
  718. condition += " and ActivationState=" + ActivationStateSelect;
  719. }
  720. //所属创客创客编号
  721. if (!string.IsNullOrEmpty(UserIdMakerCode))
  722. {
  723. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  724. }
  725. //所属创客真实姓名
  726. if (!string.IsNullOrEmpty(UserIdRealName))
  727. {
  728. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  729. }
  730. //所属仓库编号
  731. if (!string.IsNullOrEmpty(StoreIdCode))
  732. {
  733. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreIdCode + "')";
  734. }
  735. //所属仓库名称
  736. if (!string.IsNullOrEmpty(StoreIdName))
  737. {
  738. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreIdName + "')";
  739. }
  740. //是否调整
  741. if (!string.IsNullOrEmpty(UpFeeFlagSelect))
  742. {
  743. condition += " and UpFeeFlag = " + UpFeeFlagSelect;
  744. }
  745. 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);
  746. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  747. foreach (Dictionary<string, object> dic in diclist)
  748. {
  749. //绑定状态
  750. int BindingState = int.Parse(dic["BindingState"].ToString());
  751. if (BindingState == 0) dic["BindingState"] = "未绑定";
  752. if (BindingState == 1) dic["BindingState"] = "已绑定";
  753. //绑定时间
  754. if (!string.IsNullOrEmpty(dic["BindingTime"].ToString()))
  755. {
  756. DateTime BindingTime = Convert.ToDateTime(dic["BindingTime"].ToString());
  757. }
  758. //激活状态
  759. int ActivationState = int.Parse(dic["ActivationState"].ToString());
  760. if (ActivationState == 0) dic["ActivationState"] = "未激活";
  761. if (ActivationState == 1) dic["ActivationState"] = "已激活";
  762. //激活时间
  763. if (!string.IsNullOrEmpty(dic["ActivationTime"].ToString()))
  764. {
  765. DateTime ActivationTime = Convert.ToDateTime(dic["ActivationTime"].ToString());
  766. }
  767. //划拨时间
  768. if (!string.IsNullOrEmpty(dic["TransferTime"].ToString()))
  769. {
  770. DateTime TransferTime = Convert.ToDateTime(dic["TransferTime"].ToString());
  771. }
  772. //调升时间
  773. if (!string.IsNullOrEmpty(dic["UpFeeDate"].ToString()))
  774. {
  775. DateTime UpFeeDate = Convert.ToDateTime(dic["UpFeeDate"].ToString());
  776. }
  777. //调降时间
  778. if (!string.IsNullOrEmpty(dic["DownFeeDate"].ToString()))
  779. {
  780. DateTime DownFeeDate = Convert.ToDateTime(dic["DownFeeDate"].ToString());
  781. }
  782. //所属创客
  783. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  784. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  785. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  786. dic["UserIdRealName"] = userid_Users.RealName;
  787. dic.Remove("UserId");
  788. //所属仓库
  789. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  790. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  791. dic["StoreIdCode"] = storeid_StoreHouse.StoreNo;
  792. dic["StoreIdName"] = storeid_StoreHouse.StoreName;
  793. dic.Remove("StoreId");
  794. //产品类型
  795. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  796. //参加活动
  797. // dic["ActivityList"] = RelationClass.GetProfitObjectsActivesList(dic["ActivityList"].ToString());
  798. //绑定商户
  799. int BindMerchantId = int.Parse(function.CheckInt(dic["BindMerchantId"].ToString()));
  800. PosMerchantInfo bindmerchantid_MerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == BindMerchantId) ?? new PosMerchantInfo();
  801. dic["BindMerchantIdMerchantNo"] = bindmerchantid_MerchantInfo.MerchantNo;
  802. dic["BindMerchantIdMerchantName"] = bindmerchantid_MerchantInfo.MerchantName;
  803. dic.Remove("BindMerchantId");
  804. //机具类型
  805. int PosSnType = int.Parse(dic["PosSnType"].ToString());
  806. if (PosSnType == 0) dic["PosSnType"] = "购买机具";
  807. if (PosSnType == 1) dic["PosSnType"] = "赠送机具";
  808. // //设备类型
  809. // string DeviceType = dic["DeviceType"].ToString();
  810. // if (DeviceType == "KysSignPos") dic["DeviceType"] = "快益刷电签POS";
  811. // if (DeviceType == "KssSignPos") dic["DeviceType"] = "快闪刷电签POS";
  812. // if (DeviceType == "") dic["DeviceType"] = "";
  813. }
  814. Dictionary<string, object> result = new Dictionary<string, object>();
  815. result.Add("Status", "1");
  816. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  817. result.Add("Obj", diclist);
  818. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  819. ReturnFields.Add("UserIdMakerCode", "创客编号");
  820. ReturnFields.Add("UserIdRealName", "创客姓名");
  821. ReturnFields.Add("StoreIdCode", "仓库编号");
  822. ReturnFields.Add("StoreIdName", "仓库名称");
  823. ReturnFields.Add("BrandId", "产品类型");
  824. ReturnFields.Add("PosSn", "SN编号");
  825. ReturnFields.Add("PosSnType", "SN类型");
  826. // ReturnFields.Add("ActivityList", "参加活动");
  827. ReturnFields.Add("BindMerchantIdMerchantNo", "绑定商户编号");
  828. ReturnFields.Add("BindMerchantIdMerchantName", "绑定商户姓名");
  829. ReturnFields.Add("DeviceType", "设备类型");
  830. ReturnFields.Add("BindingState", "绑定状态");
  831. ReturnFields.Add("BindingTime", "绑定时间");
  832. ReturnFields.Add("ActivationState", "激活状态");
  833. ReturnFields.Add("ActivationTime", "激活时间");
  834. ReturnFields.Add("TransferTime", "划拨时间");
  835. ReturnFields.Add("UpFeeFlag", "调升标记");
  836. ReturnFields.Add("UpFeeDate", "调升时间");
  837. ReturnFields.Add("UpFeeMan", "调升人");
  838. ReturnFields.Add("DownFeeFlag", "调降标记");
  839. ReturnFields.Add("DownFeeDate", "调降时间");
  840. ReturnFields.Add("DownFeeMan", "调降人");
  841. result.Add("Fields", ReturnFields);
  842. AddSysLog("0", "PosMachinesTwo", "ExportExcel");
  843. return Json(result);
  844. }
  845. #endregion
  846. }
  847. }