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