PosMachinesTwoChangeController.cs 41 KB

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