PosMachinesTwoChangeController.cs 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967
  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 opdate = function.ReadInstance("/PublicParams/UpFeeDate/" + DateTime.Now.ToString("yyyyMMdd") + ".txt");
  399. if(!string.IsNullOrEmpty(opdate))
  400. {
  401. return "已提交,请勿重复操作";
  402. }
  403. function.WritePage("/PublicParams/UpFeeDate/", DateTime.Now.ToString("yyyyMMdd") + ".txt", DateTime.Now.ToString("HH:mm:ss"));
  404. // string[] idlist = Id.Split(new char[] { ',' });
  405. AddSysLog(Id, "PosMachinesTwo", "UpFeePosMachinesTwo");
  406. List<int> posIds = new List<int>();
  407. List<int> upposIds = new List<int>();
  408. string userIds = "";
  409. DateTime check = DateTime.Now.AddDays(-120);
  410. 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
  411. foreach (PosMachinesTwo pos in poslist)
  412. {
  413. Dictionary<string, object> Fields = new Dictionary<string, object>();
  414. Fields.Add("UpFeeFlag", 1);
  415. Fields.Add("UpFeeMan", SysUserName);
  416. Fields.Add("UpFeeDate", DateTime.Now);
  417. if (!userIds.Contains(pos.BuyUserId.ToString()))
  418. {
  419. userIds += pos.BuyUserId + ",";
  420. }
  421. if (pos.BrandId == 1 || pos.BrandId == 3 || pos.BrandId == 2 || pos.BrandId == 4 || pos.BrandId == 5 || pos.BrandId == 6 || pos.BrandId == 7)
  422. {
  423. // PosId:机具Id
  424. // Kind:1或2,1为费率0.63,2为费率0.6
  425. // OpMan:操作人,app传创客编号,后台传SysUserName
  426. string info = "{\"RecordId\":\"\",\"PosId\":\"" + pos.Id + "\",\"Fee\": \"" + 0.63 + "\",\"Kind\": \"" + 1 + "\",\"OpMan\": \"" + SysUserName + "\"}";
  427. RedisDbconn.Instance.AddList("SetDepositPostQueue", info);
  428. }
  429. // else
  430. // {
  431. // upposIds.Add(pos.Id);
  432. // }
  433. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, pos.Id);
  434. }
  435. // string[] lists = userIds.TrimEnd(',').Split(new char[] { ',' });
  436. // int times = lists.ToList().Count;
  437. // if (upposIds.Count > 0)
  438. // {
  439. // //调升
  440. // for (int i = 0; i < times; i++)
  441. // {
  442. // var UserId = lists[i];
  443. // var posInfo = db.PosMachinesTwo.Where(m => upposIds.Contains(m.Id) && m.BuyUserId == Convert.ToInt32(UserId)).ToList();
  444. // string snhtml = "<div style='margin-bottom: .48rem;'>";
  445. // foreach (var items in posInfo)
  446. // {
  447. // var mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == items.BindMerchantId);
  448. // string Name = mer.MerchantName;
  449. // if (mer.BrandId == 2)
  450. // {
  451. // if (Name.Contains("-"))
  452. // {
  453. // Name = Name.Split('-')[1];
  454. // }
  455. // else if (Name.Contains("_"))
  456. // {
  457. // Name = Name.Split('_')[1];
  458. // }
  459. // }
  460. // var brand = db.KqProducts.FirstOrDefault(m => m.Id == items.BrandId);
  461. // snhtml += "<div style='margin-bottom: .48rem;'><div class='f16'>商户姓名:" + Name + "</div>";
  462. // snhtml += "<div class='f16'>机具品牌:" + brand.Name + "</div>";
  463. // snhtml += "<div class='f16'>SN:" + items.PosSn + "</div></div>";
  464. // }
  465. // snhtml += "</div>";
  466. // RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  467. // {
  468. // UserId = Convert.ToInt32(UserId), //创客
  469. // Title = "商户费率变更通知", //标题
  470. // Content = "<div class='f16' style='margin-bottom: .72rem'>您的部分机具已绑定超过120天,刷卡费率已自动变更为0.63%,如需调整费率,请前往我的商户-商户详情中调整费率</div>" + snhtml, //内容
  471. // Summary = "您的部分机具已绑定超过120天,刷卡费率已自动变更为0.63%,如需调整费率,请前往我的商户-商户详情中调整费率",
  472. // CreateDate = DateTime.Now,
  473. // }));
  474. // }
  475. // }
  476. db.SaveChanges();
  477. return "success";
  478. }
  479. #endregion
  480. // #region 批量调升费率(无接口限制)
  481. // /// <summary>
  482. // /// 批量调升费率
  483. // /// </summary>
  484. // /// <returns></returns>
  485. // public string BatchSetting(string Id)
  486. // {
  487. // string[] idlist = Id.Split(new char[] { ',' });
  488. // AddSysLog(Id, "PosMachinesTwo", "UpFeePosMachinesTwo");
  489. // List<int> posIds = new List<int>();
  490. // List<int> upposIds = new List<int>();
  491. // string userIds = "";
  492. // foreach (string subids in idlist)
  493. // {
  494. // int id = int.Parse(subids);
  495. // var pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == id) ?? new PosMachinesTwo();
  496. // Dictionary<string, object> Fields = new Dictionary<string, object>();
  497. // Fields.Add("UpFeeFlag", 1);
  498. // Fields.Add("UpFeeMan", SysUserName);
  499. // Fields.Add("UpFeeDate", DateTime.Now);
  500. // if (!userIds.Contains(pos.BuyUserId.ToString()))
  501. // {
  502. // userIds += pos.BuyUserId + ",";
  503. // }
  504. // upposIds.Add(id);
  505. // new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, id);
  506. // }
  507. // string[] lists = userIds.TrimEnd(',').Split(new char[] { ',' });
  508. // int times = lists.ToList().Count;
  509. // if (upposIds.Count > 0)
  510. // {
  511. // //调升
  512. // for (int i = 0; i < times; i++)
  513. // {
  514. // var UserId = lists[i];
  515. // var posInfo = db.PosMachinesTwo.Where(m => upposIds.Contains(m.Id) && m.BuyUserId == Convert.ToInt32(UserId)).ToList();
  516. // string snhtml = "<div style='margin-bottom: .48rem;'>";
  517. // foreach (var items in posInfo)
  518. // {
  519. // var mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == items.BindMerchantId);
  520. // string Name = mer.MerchantName;
  521. // if (mer.BrandId == 2)
  522. // {
  523. // if (Name.Contains("-"))
  524. // {
  525. // Name = Name.Split('-')[1];
  526. // }
  527. // else if (Name.Contains("_"))
  528. // {
  529. // Name = Name.Split('_')[1];
  530. // }
  531. // }
  532. // var brand = db.KqProducts.FirstOrDefault(m => m.Id == items.BrandId);
  533. // snhtml += "<div style='margin-bottom: .48rem;'><div class='f16'>商户姓名:" + Name + "</div>";
  534. // snhtml += "<div class='f16'>机具品牌:" + brand.Name + "</div>";
  535. // snhtml += "<div class='f16'>SN:" + items.PosSn + "</div></div>";
  536. // }
  537. // snhtml += "</div>";
  538. // RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  539. // {
  540. // UserId = Convert.ToInt32(UserId), //创客
  541. // Title = "商户费率变更通知", //标题
  542. // Content = "<div class='f16' style='margin-bottom: .72rem'>您的部分机具已绑定超过120天,刷卡费率已自动变更为0.63%,如需调整费率,请前往我的商户-商户详情中调整费率</div>" + snhtml, //内容
  543. // Summary = "您的部分机具已绑定超过120天,刷卡费率已自动变更为0.63%,如需调整费率,请前往我的商户-商户详情中调整费率",
  544. // CreateDate = DateTime.Now,
  545. // }));
  546. // }
  547. // }
  548. // db.SaveChanges();
  549. // db.Dispose();
  550. // return "success";
  551. // }
  552. // #endregion
  553. #region 导入费率调整结果
  554. /// <summary>
  555. /// 导入费率调整结果
  556. /// </summary>
  557. /// <param name="ExcelData"></param>
  558. public string ImportEnd(string ExcelData)
  559. {
  560. ExcelData = HttpUtility.UrlDecode(ExcelData);
  561. JsonData list = JsonMapper.ToObject(ExcelData);
  562. List<int> dnposIds = new List<int>();
  563. string userIds = "";
  564. string warning = "";
  565. for (int i = 1; i < list.Count; i++)
  566. {
  567. JsonData dr = list[i];
  568. string PosNo = dr[0].ToString(); // 机具Sn
  569. var Amount = double.Parse(dr[1].ToString()); // 调整费率
  570. int Kind = int.Parse(dr[2].ToString()); // 1 调升 2 调低
  571. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosNo) ?? new PosMachinesTwo();
  572. if (pos.UpFeeFlag == 1)
  573. {
  574. if (Kind != 2 || Amount != 0.6)
  575. {
  576. warning += PosNo + ",该机具调低费率数值或类型不正确,请检查好后全部重新导入";
  577. }
  578. else
  579. {
  580. if (Kind == 2 && Amount == 0.6)
  581. {
  582. pos.DownFeeFlag = 1;
  583. pos.DownFeeDate = DateTime.Now;
  584. pos.DownFeeMan = SysUserName + "_" + SysRealName;
  585. var poschange = db.PosMachinesFeeChangeRecord.FirstOrDefault(m => m.PosId == pos.Id);
  586. poschange.Status = 1;
  587. db.SaveChanges();
  588. dnposIds.Add(pos.Id);
  589. }
  590. if (!userIds.Contains(pos.BuyUserId.ToString()))
  591. {
  592. userIds += pos.BuyUserId + ",";
  593. }
  594. }
  595. }
  596. else
  597. {
  598. warning += PosNo + ",该机具不符合调低条件,请检查好后全部重新导入";
  599. }
  600. }
  601. if (!string.IsNullOrEmpty(warning))
  602. {
  603. return "waning |" + warning;
  604. }
  605. string[] lists = userIds.TrimEnd(',').Split(new char[] { ',' });
  606. int times = lists.ToList().Count;
  607. if (dnposIds.Count > 0)
  608. {
  609. //调降
  610. for (int i = 0; i < times; i++)
  611. {
  612. var UserId = lists[i];
  613. var posInfo = db.PosMachinesTwo.Where(m => dnposIds.Contains(m.Id) && m.BuyUserId == Convert.ToInt32(UserId)).ToList();
  614. string snhtml = "<div style='margin-bottom: .48rem;'>";
  615. foreach (var items in posInfo)
  616. {
  617. var mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == items.BindMerchantId);
  618. string Name = mer.MerchantName;
  619. if (mer.BrandId == 2)
  620. {
  621. if (Name.Contains("-"))
  622. {
  623. Name = Name.Split('-')[1];
  624. }
  625. else if (Name.Contains("_"))
  626. {
  627. Name = Name.Split('_')[1];
  628. }
  629. }
  630. var brand = db.KqProducts.FirstOrDefault(m => m.Id == items.BrandId);
  631. snhtml += "<div style='margin-bottom: .48rem;'><div class='f16'>商户姓名:" + Name + "</div>";
  632. snhtml += "<div class='f16'>机具品牌:" + brand.Name + "</div>";
  633. snhtml += "<div class='f16'>SN:" + items.PosSn + "</div>";
  634. snhtml += "<div class='f16'>当前费率:0.6%</div>";
  635. snhtml += "<div class='f16'>费率调整时间:" + items.DownFeeDate + "</div></div>";
  636. }
  637. snhtml += "</div>";
  638. RedisDbconn.Instance.AddList("MsgPersonalQueue", Newtonsoft.Json.JsonConvert.SerializeObject(new MsgPersonal()
  639. {
  640. UserId = Convert.ToInt32(UserId), //创客
  641. Title = "商户费率变更通知", //标题
  642. Content = "<div class='f16' style='margin-bottom: .72rem'>您的商户刷卡交易费率已变更成功!</div>" + snhtml, //内容
  643. Summary = "您的商户刷卡交易费率已变更成功!",
  644. CreateDate = DateTime.Now,
  645. }));
  646. }
  647. }
  648. AddSysLog("0", "PosMachinesTwoChange", "ImportEnd");
  649. return "success";
  650. }
  651. #endregion
  652. #region 导入数据
  653. public IActionResult Import(string right)
  654. {
  655. ViewBag.RightInfo = RightInfo;
  656. ViewBag.right = right;
  657. return View();
  658. }
  659. /// <summary>
  660. /// 导入数据
  661. /// </summary>
  662. /// <param name="ExcelData"></param>
  663. [HttpPost]
  664. public string ImportPost(string ExcelPath)
  665. {
  666. string key = function.MD5_16(Guid.NewGuid().ToString());
  667. RedisDbconn.Instance.AddList("ExcelImportV2", ExcelPath + "#cut#ChangeFee#cut#" + key + "#cut#" + SysUserName);
  668. return "success|" + key;
  669. }
  670. public string CheckImport(string key)
  671. {
  672. string result = RedisDbconn.Instance.Get<string>("CheckImport:" + key);
  673. if (!string.IsNullOrEmpty(result))
  674. {
  675. string[] datalist = result.Split('|');
  676. if (datalist[0] == "success")
  677. {
  678. return result;
  679. }
  680. return datalist[0];
  681. }
  682. return "0";
  683. }
  684. public Dictionary<string, object> CheckImportV2(string key)
  685. {
  686. Dictionary<string, object> Obj = new Dictionary<string, object>();
  687. string result = RedisDbconn.Instance.Get<string>("CheckImport:" + key);
  688. if (!string.IsNullOrEmpty(result))
  689. {
  690. string[] datalist = result.Split('|');
  691. if (datalist[0] == "success")
  692. {
  693. List<string> errList = RedisDbconn.Instance.GetList<string>("ErrList" + key);
  694. if (errList.Count > 0)
  695. {
  696. Obj.Add("status", 2);
  697. Obj.Add("errList", errList);
  698. }
  699. else
  700. {
  701. Obj.Add("status", 1);
  702. Obj.Add("data", result);
  703. }
  704. return Obj;
  705. }
  706. Obj.Add("status", 0);
  707. Obj.Add("data", datalist[0]);
  708. return Obj;
  709. }
  710. Obj.Add("status", -1);
  711. Obj.Add("data", "执行中...");
  712. return Obj;
  713. }
  714. #endregion
  715. #region 导出Excel
  716. /// <summary>
  717. /// 导出Excel
  718. /// </summary>
  719. /// <returns></returns>
  720. public JsonResult ExportExcel(PosMachinesTwo data, string BindingStateSelect, string ActivationStateSelect, string UserIdMakerCode, string UserIdRealName, string StoreIdCode, string StoreIdName, string UpFeeFlagSelect)
  721. {
  722. Dictionary<string, string> Fields = new Dictionary<string, string>();
  723. Fields.Add("PosSn", "1"); //SN编号
  724. Fields.Add("BrandId", "0"); //品牌
  725. string condition = " and Status>-1 and BrandId = " + data.BrandId + " ";
  726. //绑定状态
  727. if (!string.IsNullOrEmpty(BindingStateSelect))
  728. {
  729. condition += " and BindingState=" + BindingStateSelect;
  730. }
  731. //激活状态
  732. if (!string.IsNullOrEmpty(ActivationStateSelect))
  733. {
  734. condition += " and ActivationState=" + ActivationStateSelect;
  735. }
  736. //所属创客编号
  737. if (!string.IsNullOrEmpty(UserIdMakerCode))
  738. {
  739. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  740. }
  741. //所属创客真实姓名
  742. if (!string.IsNullOrEmpty(UserIdRealName))
  743. {
  744. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  745. }
  746. //所属仓库编号
  747. if (!string.IsNullOrEmpty(StoreIdCode))
  748. {
  749. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreIdCode + "')";
  750. }
  751. //所属仓库名称
  752. if (!string.IsNullOrEmpty(StoreIdName))
  753. {
  754. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreIdName + "')";
  755. }
  756. //是否调整
  757. if (!string.IsNullOrEmpty(UpFeeFlagSelect))
  758. {
  759. condition += " and UpFeeFlag = " + UpFeeFlagSelect;
  760. }
  761. 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);
  762. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  763. foreach (Dictionary<string, object> dic in diclist)
  764. {
  765. //绑定状态
  766. int BindingState = int.Parse(dic["BindingState"].ToString());
  767. if (BindingState == 0) dic["BindingState"] = "未绑定";
  768. if (BindingState == 1) dic["BindingState"] = "已绑定";
  769. //绑定时间
  770. if (!string.IsNullOrEmpty(dic["BindingTime"].ToString()))
  771. {
  772. DateTime BindingTime = Convert.ToDateTime(dic["BindingTime"].ToString());
  773. }
  774. //激活状态
  775. int ActivationState = int.Parse(dic["ActivationState"].ToString());
  776. if (ActivationState == 0) dic["ActivationState"] = "未激活";
  777. if (ActivationState == 1) dic["ActivationState"] = "已激活";
  778. //激活时间
  779. if (!string.IsNullOrEmpty(dic["ActivationTime"].ToString()))
  780. {
  781. DateTime ActivationTime = Convert.ToDateTime(dic["ActivationTime"].ToString());
  782. }
  783. //划拨时间
  784. if (!string.IsNullOrEmpty(dic["TransferTime"].ToString()))
  785. {
  786. DateTime TransferTime = Convert.ToDateTime(dic["TransferTime"].ToString());
  787. }
  788. //调升时间
  789. if (!string.IsNullOrEmpty(dic["UpFeeDate"].ToString()))
  790. {
  791. DateTime UpFeeDate = Convert.ToDateTime(dic["UpFeeDate"].ToString());
  792. }
  793. //调降时间
  794. if (!string.IsNullOrEmpty(dic["DownFeeDate"].ToString()))
  795. {
  796. DateTime DownFeeDate = Convert.ToDateTime(dic["DownFeeDate"].ToString());
  797. }
  798. //所属创客
  799. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  800. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  801. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  802. dic["UserIdRealName"] = userid_Users.RealName;
  803. dic.Remove("UserId");
  804. //所属仓库
  805. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  806. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  807. dic["StoreIdCode"] = storeid_StoreHouse.StoreNo;
  808. dic["StoreIdName"] = storeid_StoreHouse.StoreName;
  809. dic.Remove("StoreId");
  810. //产品类型
  811. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  812. //参加活动
  813. // dic["ActivityList"] = RelationClass.GetProfitObjectsActivesList(dic["ActivityList"].ToString());
  814. //绑定商户
  815. int BindMerchantId = int.Parse(function.CheckInt(dic["BindMerchantId"].ToString()));
  816. PosMerchantInfo bindmerchantid_MerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == BindMerchantId) ?? new PosMerchantInfo();
  817. dic["BindMerchantIdMerchantNo"] = bindmerchantid_MerchantInfo.MerchantNo;
  818. dic["BindMerchantIdMerchantName"] = bindmerchantid_MerchantInfo.MerchantName;
  819. dic.Remove("BindMerchantId");
  820. //机具类型
  821. int PosSnType = int.Parse(dic["PosSnType"].ToString());
  822. if (PosSnType == 0) dic["PosSnType"] = "兑换机具";
  823. if (PosSnType == 1) dic["PosSnType"] = "循环机具";
  824. // //设备类型
  825. // string DeviceType = dic["DeviceType"].ToString();
  826. // if (DeviceType == "KysSignPos") dic["DeviceType"] = "快益刷电签POS";
  827. // if (DeviceType == "KssSignPos") dic["DeviceType"] = "快闪刷电签POS";
  828. // if (DeviceType == "") dic["DeviceType"] = "";
  829. }
  830. Dictionary<string, object> result = new Dictionary<string, object>();
  831. result.Add("Status", "1");
  832. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  833. result.Add("Obj", diclist);
  834. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  835. ReturnFields.Add("UserIdMakerCode", "创客编号");
  836. ReturnFields.Add("UserIdRealName", "创客姓名");
  837. ReturnFields.Add("StoreIdCode", "仓库编号");
  838. ReturnFields.Add("StoreIdName", "仓库名称");
  839. ReturnFields.Add("BrandId", "产品类型");
  840. ReturnFields.Add("PosSn", "SN编号");
  841. ReturnFields.Add("PosSnType", "SN类型");
  842. // ReturnFields.Add("ActivityList", "参加活动");
  843. ReturnFields.Add("BindMerchantIdMerchantNo", "绑定商户编号");
  844. ReturnFields.Add("BindMerchantIdMerchantName", "绑定商户姓名");
  845. ReturnFields.Add("DeviceType", "设备类型");
  846. ReturnFields.Add("BindingState", "绑定状态");
  847. ReturnFields.Add("BindingTime", "绑定时间");
  848. ReturnFields.Add("ActivationState", "激活状态");
  849. ReturnFields.Add("ActivationTime", "激活时间");
  850. ReturnFields.Add("TransferTime", "划拨时间");
  851. ReturnFields.Add("UpFeeFlag", "调升标记");
  852. ReturnFields.Add("UpFeeDate", "调升时间");
  853. ReturnFields.Add("UpFeeMan", "调升人");
  854. ReturnFields.Add("DownFeeFlag", "调降标记");
  855. ReturnFields.Add("DownFeeDate", "调降时间");
  856. ReturnFields.Add("DownFeeMan", "调降人");
  857. result.Add("Fields", ReturnFields);
  858. AddSysLog("0", "PosMachinesTwo", "ExportExcel");
  859. return Json(result);
  860. }
  861. #endregion
  862. }
  863. }