PosMachinesTwoChangeController.cs 41 KB

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