PosMachinesTwoChangeController.cs 42 KB

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