PosMachinesTwoChangeController.cs 42 KB

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