PosMachinesTwoController.cs 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  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 PosMachinesTwoController : BaseController
  24. {
  25. public PosMachinesTwoController(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 BrandId, string ActivationDateData, string BindingDateData, string IsStoreSelect, string OpCode, int ShowFlag = 0, int page = 1, int limit = 30)
  47. {
  48. Dictionary<string, string> Fields = new Dictionary<string, string>();
  49. Fields.Add("PosSn", "1"); //SN编号
  50. Fields.Add("BrandId", "0"); //品牌
  51. if (ShowFlag == 0)
  52. {
  53. Dictionary<string, object> objs = new Dictionary<string, object>();
  54. Dictionary<string, object> others = new Dictionary<string, object>();
  55. others.Add("TotalCount", 0);
  56. others.Add("KysCount99", 0);
  57. others.Add("KssCount99", 0);
  58. others.Add("KssCoun198", 0);
  59. others.Add("KssCount298", 0);
  60. objs.Add("other", others);
  61. return Json(objs);
  62. }
  63. string condition = " and Status>-1";
  64. //是否仓库机
  65. if (!string.IsNullOrEmpty(IsStoreSelect))
  66. {
  67. if (int.Parse(IsStoreSelect) > 0)
  68. {
  69. condition += " and UserId=0 and BuyUserId=0";
  70. }
  71. }
  72. //绑定状态
  73. if (!string.IsNullOrEmpty(BindingStateSelect))
  74. {
  75. condition += " and BindingState=" + BindingStateSelect;
  76. }
  77. //激活状态
  78. if (!string.IsNullOrEmpty(ActivationStateSelect))
  79. {
  80. condition += " and ActivationState=" + ActivationStateSelect;
  81. }
  82. //所属创客编号
  83. if (!string.IsNullOrEmpty(UserIdMakerCode))
  84. {
  85. condition += " and BuyUserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  86. }
  87. //所属创客真实姓名
  88. if (!string.IsNullOrEmpty(UserIdRealName))
  89. {
  90. condition += " and BuyUserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  91. }
  92. //所属仓库编号
  93. if (!string.IsNullOrEmpty(StoreIdCode))
  94. {
  95. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreIdCode + "')";
  96. }
  97. //所属仓库名称
  98. if (!string.IsNullOrEmpty(StoreIdName))
  99. {
  100. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreIdName + "')";
  101. }
  102. //运营中心编号
  103. if (!string.IsNullOrEmpty(OpCode))
  104. {
  105. var sysUser = opdb.SysAdmin.FirstOrDefault(m => m.OpCode == OpCode) ?? new OpModels.SysAdmin();
  106. if (sysUser.Id > 0)
  107. {
  108. condition += " and OpId=" + sysUser.UserId;
  109. }
  110. }
  111. //品牌
  112. if (!string.IsNullOrEmpty(BrandId))
  113. {
  114. condition += " and BrandId =" + BrandId;
  115. }
  116. if (!string.IsNullOrEmpty(ActivationDateData))
  117. {
  118. string[] datelist = ActivationDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  119. string start = datelist[0];
  120. string end = datelist[1];
  121. condition += " and ActivationTime>='" + start + " 00:00:00' and ActivationTime<='" + end + " 23:59:59'";
  122. }
  123. if (!string.IsNullOrEmpty(BindingDateData))
  124. {
  125. string[] datelist = BindingDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  126. string start = datelist[0];
  127. string end = datelist[1];
  128. condition += " and BindingTime>='" + start + " 00:00:00' and BindingTime<='" + end + " 23:59:59'";
  129. }
  130. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosMachinesTwo", Fields, "Id desc", "0", page, limit, condition);
  131. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  132. foreach (Dictionary<string, object> dic in diclist)
  133. {
  134. //绑定状态
  135. int BindingState = int.Parse(dic["BindingState"].ToString());
  136. if (BindingState == 0) dic["BindingState"] = "未绑定";
  137. if (BindingState == 1) dic["BindingState"] = "已绑定";
  138. //激活状态
  139. int ActivationState = int.Parse(dic["ActivationState"].ToString());
  140. if (ActivationState == 0) dic["ActivationState"] = "未激活";
  141. if (ActivationState == 1) dic["ActivationState"] = "已激活";
  142. //所属创客
  143. int BuyUserId = int.Parse(function.CheckInt(dic["BuyUserId"].ToString()));
  144. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == BuyUserId) ?? new Users();
  145. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  146. dic["UserIdRealName"] = userid_Users.RealName;
  147. dic.Remove("BuyUserId");
  148. //所属仓库
  149. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  150. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  151. dic["StoreIdCode"] = storeid_StoreHouse.StoreNo;
  152. dic["StoreIdName"] = storeid_StoreHouse.StoreName;
  153. dic.Remove("StoreId");
  154. //产品类型
  155. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  156. //参加活动
  157. dic["ActivityList"] = RelationClass.GetProfitObjectsActivesList(dic["ActivityList"].ToString());
  158. //绑定商户
  159. int BindMerchantId = int.Parse(function.CheckInt(dic["BindMerchantId"].ToString()));
  160. PosMerchantInfo bindmerchantid_MerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == BindMerchantId) ?? new PosMerchantInfo();
  161. dic["BindMerchantIdMerchantNo"] = bindmerchantid_MerchantInfo.MerchantNo;
  162. dic["BindMerchantIdMerchantName"] = bindmerchantid_MerchantInfo.MerchantName;
  163. dic.Remove("BindMerchantId");
  164. //机具类型
  165. int PosSnType = int.Parse(dic["PosSnType"].ToString());
  166. if (PosSnType == 0) dic["PosSnType"] = "兑换机具";
  167. if (PosSnType == 1) dic["PosSnType"] = "循环机具";
  168. //设备类型
  169. string DeviceType = dic["DeviceType"].ToString();
  170. if (DeviceType == "KysSignPos") dic["DeviceType"] = "快益刷电签POS";
  171. if (DeviceType == "KssSignPos") dic["DeviceType"] = "快闪刷电签POS";
  172. if (DeviceType == "") dic["DeviceType"] = "";
  173. //盟主信息
  174. int LeaderUserId = int.Parse(function.CheckInt(dic["LeaderUserId"].ToString()));
  175. if (LeaderUserId != 0)
  176. {
  177. Users users = db.Users.FirstOrDefault(m => m.Id == LeaderUserId) ?? new Users();
  178. dic["UserInfo"] = users.MakerCode + "_" + users.RealName;
  179. }
  180. //是否为第一台机具
  181. int IsFirst = int.Parse(dic["IsFirst"].ToString());
  182. if (IsFirst == 0) dic["IsFirst"] = "否";
  183. if (IsFirst == 1) dic["IsFirst"] = "是";
  184. //实际押金
  185. string SeoKeyword = dic["SeoKeyword"].ToString();
  186. if (SeoKeyword.Length > 3)
  187. {
  188. SeoKeyword = (decimal.Parse(SeoKeyword) / 100).ToString();
  189. }
  190. dic["SeoKeyword"] = SeoKeyword;
  191. //设置押金
  192. string PrizeParams = dic["PrizeParams"].ToString();
  193. dic["PrizeParams"] = PrizeParams;
  194. //所属运营中心
  195. int OpId = int.Parse(dic["OpId"].ToString());
  196. if (OpId != 0)
  197. {
  198. var sys = opdb.SysAdmin.FirstOrDefault(m => m.QueryCount > 0 && m.UserId == OpId) ?? new OpModels.SysAdmin();
  199. dic["OpCode"] = sys.OpCode;
  200. }
  201. }
  202. Dictionary<string, object> other = new Dictionary<string, object>();
  203. int TotalCount = 0;//总机具数
  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. other.Add("TotalCount", TotalCount);
  210. other.Add("KysCount99", 0);
  211. other.Add("KssCount99", 0);
  212. other.Add("KssCoun198", 0);
  213. other.Add("KssCount298", 0);
  214. obj.Add("other", other);
  215. return Json(obj);
  216. }
  217. #endregion
  218. #region 增加机具库
  219. /// <summary>
  220. /// 增加或修改机具库信息
  221. /// </summary>
  222. /// <returns></returns>
  223. public IActionResult Add(string right)
  224. {
  225. ViewBag.RightInfo = RightInfo;
  226. ViewBag.right = right;
  227. return View();
  228. }
  229. #endregion
  230. #region 增加机具库
  231. /// <summary>
  232. /// 增加或修改机具库信息
  233. /// </summary>
  234. /// <returns></returns>
  235. [HttpPost]
  236. public string Add(PosMachinesTwo data)
  237. {
  238. Dictionary<string, object> Fields = new Dictionary<string, object>();
  239. Fields.Add("SeoTitle", data.SeoTitle);
  240. Fields.Add("SeoKeyword", data.SeoKeyword);
  241. Fields.Add("SeoDescription", data.SeoDescription);
  242. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("PosMachinesTwo", Fields, 0);
  243. AddSysLog(data.Id.ToString(), "PosMachinesTwo", "add");
  244. db.SaveChanges();
  245. return "success";
  246. }
  247. #endregion
  248. #region 修改机具库
  249. /// <summary>
  250. /// 增加或修改机具库信息
  251. /// </summary>
  252. /// <returns></returns>
  253. public IActionResult Edit(string right, int Id = 0)
  254. {
  255. ViewBag.RightInfo = RightInfo;
  256. ViewBag.right = right;
  257. PosMachinesTwo editData = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id) ?? new PosMachinesTwo();
  258. ViewBag.data = editData;
  259. return View();
  260. }
  261. #endregion
  262. #region 修改机具库
  263. /// <summary>
  264. /// 增加或修改机具库信息
  265. /// </summary>
  266. /// <returns></returns>
  267. [HttpPost]
  268. public string Edit(PosMachinesTwo data)
  269. {
  270. Dictionary<string, object> Fields = new Dictionary<string, object>();
  271. Fields.Add("PosSnType", data.PosSnType);
  272. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, data.Id);
  273. AddSysLog(data.Id.ToString(), "PosMachinesTwo", "update");
  274. db.SaveChanges();
  275. return "success";
  276. }
  277. #endregion
  278. #region 未使用机具归位总仓
  279. /// <summary>
  280. /// 未使用机具归位总仓
  281. /// </summary>
  282. /// <returns></returns>
  283. public IActionResult Home(string right, int Id = 0)
  284. {
  285. ViewBag.RightInfo = RightInfo;
  286. ViewBag.right = right;
  287. PosMachinesTwo editData = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id) ?? new PosMachinesTwo();
  288. ViewBag.data = editData;
  289. return View();
  290. }
  291. #endregion
  292. #region 未使用机具归位总仓
  293. /// <summary>
  294. /// 未使用机具归位总仓
  295. /// </summary>
  296. /// <returns></returns>
  297. [HttpPost]
  298. public string Home(PosMachinesTwo data)
  299. {
  300. Dictionary<string, object> Fields = new Dictionary<string, object>();
  301. Fields.Add("SeoTitle", "");
  302. Fields.Add("SeoKeyword", "");
  303. Fields.Add("PosSnType", 0);
  304. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, data.Id);
  305. AddSysLog(data.Id.ToString(), "PosMachinesTwo", "home");
  306. db.SaveChanges();
  307. return "success";
  308. }
  309. #endregion
  310. #region 删除机具库信息
  311. /// <summary>
  312. /// 删除机具库信息
  313. /// </summary>
  314. /// <returns></returns>
  315. public string Delete(string Id)
  316. {
  317. string[] idlist = Id.Split(new char[] { ',' });
  318. AddSysLog(Id, "PosMachinesTwo", "del");
  319. foreach (string subid in idlist)
  320. {
  321. int id = int.Parse(subid);
  322. Dictionary<string, object> Fields = new Dictionary<string, object>();
  323. Fields.Add("Status", -1);
  324. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, id);
  325. }
  326. db.SaveChanges();
  327. return "success";
  328. }
  329. #endregion
  330. #region 开启
  331. /// <summary>
  332. /// 开启
  333. /// </summary>
  334. /// <returns></returns>
  335. public string Open(string Id)
  336. {
  337. string[] idlist = Id.Split(new char[] { ',' });
  338. AddSysLog(Id, "PosMachinesTwo", "open");
  339. foreach (string subid in idlist)
  340. {
  341. int id = int.Parse(subid);
  342. Dictionary<string, object> Fields = new Dictionary<string, object>();
  343. Fields.Add("Status", 1);
  344. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, id);
  345. }
  346. db.SaveChanges();
  347. return "success";
  348. }
  349. #endregion
  350. #region 关闭
  351. /// <summary>
  352. /// 关闭
  353. /// </summary>
  354. /// <returns></returns>
  355. public string Close(string Id)
  356. {
  357. string[] idlist = Id.Split(new char[] { ',' });
  358. AddSysLog(Id, "PosMachinesTwo", "close");
  359. foreach (string subid in idlist)
  360. {
  361. int id = int.Parse(subid);
  362. Dictionary<string, object> Fields = new Dictionary<string, object>();
  363. Fields.Add("Status", 0);
  364. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, id);
  365. }
  366. db.SaveChanges();
  367. return "success";
  368. }
  369. #endregion
  370. #region 排序
  371. /// <summary>
  372. /// 排序
  373. /// </summary>
  374. /// <param name="Id"></param>
  375. public string Sort(int Id, int Sort)
  376. {
  377. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("PosMachinesTwo", Sort, Id);
  378. AddSysLog(Id.ToString(), "PosMachinesTwo", "sort");
  379. return "success";
  380. }
  381. #endregion
  382. #region 导入金控入库时间数据
  383. /// <summary>
  384. /// 导入金控入库时间数据
  385. /// </summary>
  386. /// <param name="ImportCreateData"></param>
  387. public string ImportCreateData(string ExcelData)
  388. {
  389. ExcelData = HttpUtility.UrlDecode(ExcelData);
  390. JsonData list = JsonMapper.ToObject(ExcelData);
  391. string error = "";
  392. string info = "";
  393. var brandInfo = db.KqProducts.ToList();
  394. for (int i = 1; i < list.Count; i++)
  395. {
  396. JsonData dr = list[i];
  397. string itemJson = dr.ToJson();
  398. string PosSn = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
  399. string CreateDate = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
  400. var pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn) ?? new PosMachinesTwo();
  401. if (pos.Id > 0)
  402. {
  403. var brandName = brandInfo.FirstOrDefault(m => m.Id == pos.BrandId);
  404. if (brandName.Name.StartsWith("金控"))
  405. {
  406. info += "机具Sn:" + PosSn + "原入库时间:" + pos.CreateDate + "新入库时间:" + CreateDate;
  407. pos.CreateDate = DateTime.Parse(CreateDate);
  408. }
  409. else
  410. {
  411. error += "以下操作失败" + PosSn + ',' + "该机具号品牌不符合修改规则" + '\n';
  412. }
  413. }
  414. else
  415. {
  416. error += "以下操作失败" + PosSn + ',' + "该机具号不存在" + '\n';
  417. }
  418. }
  419. if (!string.IsNullOrEmpty(error))
  420. {
  421. return "Warning|" + error;
  422. }
  423. else
  424. {
  425. db.SaveChanges();
  426. string text = string.Format("导入金控入库时间数据: '" + info + "',操作人: '" + SysUserName + "_" + SysRealName + "',Time'" + DateTime.Now + "'");
  427. function.WriteLog(text, "导入金控入库时间数据");
  428. AddSysLog("0", "ImportCreateData", "Import");
  429. return "success";
  430. }
  431. }
  432. #endregion
  433. #region 导入数据
  434. public IActionResult Import(string right)
  435. {
  436. ViewBag.RightInfo = RightInfo;
  437. ViewBag.right = right;
  438. return View();
  439. }
  440. /// <summary>
  441. /// 导入数据
  442. /// </summary>
  443. /// <param name="ExcelData"></param>
  444. [HttpPost]
  445. public string ImportPost(string ExcelPath)
  446. {
  447. string key = function.MD5_16(Guid.NewGuid().ToString());
  448. RedisDbconn.Instance.AddList("ExcelImportV2", ExcelPath + "#cut#ImportJKCreateData#cut#" + key + "#cut#" + SysUserName);
  449. return "success|" + key;
  450. }
  451. public string CheckImport(string key)
  452. {
  453. string result = RedisDbconn.Instance.Get<string>("CheckImport:" + key);
  454. if (!string.IsNullOrEmpty(result))
  455. {
  456. string[] datalist = result.Split('|');
  457. if (datalist[0] == "success")
  458. {
  459. return result;
  460. }
  461. return datalist[0];
  462. }
  463. return "0";
  464. }
  465. public Dictionary<string, object> CheckImportV2(string key)
  466. {
  467. Dictionary<string, object> Obj = new Dictionary<string, object>();
  468. string result = RedisDbconn.Instance.Get<string>("CheckImport:" + key);
  469. if (!string.IsNullOrEmpty(result))
  470. {
  471. string[] datalist = result.Split('|');
  472. if (datalist[0] == "success")
  473. {
  474. List<string> errList = RedisDbconn.Instance.GetList<string>("ErrList" + key);
  475. if (errList.Count > 0)
  476. {
  477. Obj.Add("status", 2);
  478. Obj.Add("errList", errList);
  479. }
  480. else
  481. {
  482. Obj.Add("status", 1);
  483. Obj.Add("data", result);
  484. }
  485. return Obj;
  486. }
  487. Obj.Add("status", 0);
  488. Obj.Add("data", datalist[0]);
  489. return Obj;
  490. }
  491. Obj.Add("status", -1);
  492. Obj.Add("data", "执行中...");
  493. return Obj;
  494. }
  495. #endregion
  496. #region 导出Excel
  497. /// <summary>
  498. /// 导出Excel
  499. /// </summary>
  500. /// <returns></returns>
  501. public JsonResult ExportExcel(PosMachinesTwo data, string BindingStateSelect, string ActivationStateSelect, string UserIdMakerCode, string UserIdRealName, string StoreIdCode, string StoreIdName, string BrandId, string ActivationDateData, string BindingDateData, string IsStoreSelect, string OpCode)
  502. {
  503. Dictionary<string, string> Fields = new Dictionary<string, string>();
  504. Fields.Add("PosSn", "1"); //SN编号
  505. Fields.Add("BrandId", "0"); //品牌
  506. string condition = " and Status>-1";
  507. //是否仓库机
  508. if (!string.IsNullOrEmpty(IsStoreSelect))
  509. {
  510. if (int.Parse(IsStoreSelect) > 0)
  511. {
  512. condition += " and UserId=0 and BuyUserId=0";
  513. }
  514. }
  515. //绑定状态
  516. if (!string.IsNullOrEmpty(BindingStateSelect))
  517. {
  518. condition += " and BindingState=" + BindingStateSelect;
  519. }
  520. //激活状态
  521. if (!string.IsNullOrEmpty(ActivationStateSelect))
  522. {
  523. condition += " and ActivationState=" + ActivationStateSelect;
  524. }
  525. //所属创客编号
  526. if (!string.IsNullOrEmpty(UserIdMakerCode))
  527. {
  528. condition += " and BuyUserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  529. }
  530. //所属创客真实姓名
  531. if (!string.IsNullOrEmpty(UserIdRealName))
  532. {
  533. condition += " and BuyUserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  534. }
  535. //所属仓库编号
  536. if (!string.IsNullOrEmpty(StoreIdCode))
  537. {
  538. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreIdCode + "')";
  539. }
  540. //所属仓库名称
  541. if (!string.IsNullOrEmpty(StoreIdName))
  542. {
  543. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreIdName + "')";
  544. }
  545. //运营中心编号
  546. if (!string.IsNullOrEmpty(OpCode))
  547. {
  548. var sysUser = opdb.SysAdmin.FirstOrDefault(m => m.OpCode == OpCode) ?? new OpModels.SysAdmin();
  549. if (sysUser.Id > 0)
  550. {
  551. condition += " and OpId=" + sysUser.UserId;
  552. }
  553. }
  554. //品牌
  555. if (!string.IsNullOrEmpty(BrandId))
  556. {
  557. condition += " and BrandId =" + BrandId;
  558. }
  559. if (!string.IsNullOrEmpty(ActivationDateData))
  560. {
  561. string[] datelist = ActivationDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  562. string start = datelist[0];
  563. string end = datelist[1];
  564. condition += " and ActivationTime>='" + start + " 00:00:00' and ActivationTime<='" + end + " 23:59:59'";
  565. }
  566. if (!string.IsNullOrEmpty(BindingDateData))
  567. {
  568. string[] datelist = BindingDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  569. string start = datelist[0];
  570. string end = datelist[1];
  571. condition += " and BindingTime>='" + start + " 00:00:00' and BindingTime<='" + end + " 23:59:59'";
  572. }
  573. 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,ActivationTime,TransferTime,OpId", false);
  574. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  575. foreach (Dictionary<string, object> dic in diclist)
  576. {
  577. //绑定状态
  578. int BindingState = int.Parse(dic["BindingState"].ToString());
  579. if (BindingState == 0) dic["BindingState"] = "未绑定";
  580. if (BindingState == 1) dic["BindingState"] = "已绑定";
  581. //绑定时间
  582. if (!string.IsNullOrEmpty(dic["BindingTime"].ToString()))
  583. {
  584. DateTime BindingTime = Convert.ToDateTime(dic["BindingTime"].ToString());
  585. }
  586. //激活状态
  587. int ActivationState = int.Parse(dic["ActivationState"].ToString());
  588. if (ActivationState == 0) dic["ActivationState"] = "未激活";
  589. if (ActivationState == 1) dic["ActivationState"] = "已激活";
  590. //激活时间
  591. if (!string.IsNullOrEmpty(dic["ActivationTime"].ToString()))
  592. {
  593. DateTime ActivationTime = Convert.ToDateTime(dic["ActivationTime"].ToString());
  594. }
  595. //划拨时间
  596. if (!string.IsNullOrEmpty(dic["TransferTime"].ToString()))
  597. {
  598. DateTime TransferTime = Convert.ToDateTime(dic["TransferTime"].ToString());
  599. }
  600. //所属创客
  601. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  602. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  603. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  604. dic["UserIdRealName"] = userid_Users.RealName;
  605. dic.Remove("UserId");
  606. //所属仓库
  607. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  608. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  609. dic["StoreIdCode"] = storeid_StoreHouse.StoreNo;
  610. dic["StoreIdName"] = storeid_StoreHouse.StoreName;
  611. dic.Remove("StoreId");
  612. //产品类型
  613. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  614. //绑定商户
  615. int BindMerchantId = int.Parse(function.CheckInt(dic["BindMerchantId"].ToString()));
  616. PosMerchantInfo bindmerchantid_MerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == BindMerchantId) ?? new PosMerchantInfo();
  617. dic["BindMerchantIdMerchantNo"] = bindmerchantid_MerchantInfo.MerchantNo;
  618. dic["BindMerchantIdMerchantName"] = bindmerchantid_MerchantInfo.MerchantName;
  619. dic.Remove("BindMerchantId");
  620. //机具类型
  621. int PosSnType = int.Parse(dic["PosSnType"].ToString());
  622. if (PosSnType == 0) dic["PosSnType"] = "兑换机具";
  623. if (PosSnType == 1) dic["PosSnType"] = "循环机具";
  624. //所属运营中心
  625. int OpId = int.Parse(dic["OpId"].ToString());
  626. if (OpId != 0)
  627. {
  628. var sys = opdb.SysAdmin.FirstOrDefault(m => m.QueryCount > 0 && m.UserId == OpId) ?? new OpModels.SysAdmin();
  629. dic["OpCode"] = sys.OpCode;
  630. }
  631. }
  632. Dictionary<string, object> result = new Dictionary<string, object>();
  633. result.Add("Status", "1");
  634. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  635. result.Add("Obj", diclist);
  636. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  637. ReturnFields.Add("UserIdMakerCode", "创客编号");
  638. ReturnFields.Add("UserIdRealName", "创客姓名");
  639. ReturnFields.Add("StoreIdCode", "仓库编号");
  640. ReturnFields.Add("StoreIdName", "仓库名称");
  641. ReturnFields.Add("BrandId", "产品类型");
  642. ReturnFields.Add("PosSn", "SN编号");
  643. ReturnFields.Add("PosSnType", "SN类型");
  644. ReturnFields.Add("BindMerchantIdMerchantNo", "绑定商户编号");
  645. ReturnFields.Add("BindMerchantIdMerchantName", "绑定商户姓名");
  646. ReturnFields.Add("DeviceType", "设备类型");
  647. ReturnFields.Add("BindingState", "绑定状态");
  648. ReturnFields.Add("BindingTime", "绑定时间");
  649. ReturnFields.Add("ActivationState", "激活状态");
  650. ReturnFields.Add("ActivationTime", "激活时间");
  651. ReturnFields.Add("TransferTime", "划拨时间");
  652. ReturnFields.Add("OpCode", "所属运营中心");
  653. result.Add("Fields", ReturnFields);
  654. AddSysLog("0", "PosMachinesTwo", "ExportExcel");
  655. return Json(result);
  656. }
  657. #endregion
  658. #region 过期机具扣费列表
  659. /// <summary>
  660. /// 根据条件查询过期机具扣费列表
  661. /// </summary>
  662. /// <returns></returns>
  663. public IActionResult Indexs(PosMachinesTwo data, string right)
  664. {
  665. ViewBag.RightInfo = RightInfo;
  666. ViewBag.right = right;
  667. return View();
  668. }
  669. #endregion
  670. #region 根据条件查询过期机具扣费列表
  671. /// <summary>
  672. /// 过期机具扣费列表
  673. /// </summary>
  674. /// <returns></returns>
  675. public JsonResult IndexsData(PosMachinesTwo data, string PosSn, string UserIdMakerCode, string StoreMakerCode, string BrandId, string RecycEndDateData, string AmountYk, string Amountk, string AmountDk, int ShowFlag = 0, int page = 1, int limit = 30)
  676. {
  677. Dictionary<string, string> Fields = new Dictionary<string, string>();
  678. if (ShowFlag == 0)
  679. {
  680. Dictionary<string, object> objs = new Dictionary<string, object>();
  681. Dictionary<string, object> others = new Dictionary<string, object>();
  682. others.Add("TotalCount", 0);
  683. others.Add("AmountYks", 0);
  684. others.Add("AmountDks", 0);
  685. objs.Add("other", others);
  686. return Json(objs);
  687. }
  688. decimal AmountYks = 0;//已扣
  689. decimal AmountDks = 0;//待扣
  690. var time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  691. string condition = " and Status>-1 and RecycEndDate<'" + time + "' and ScanQrTrade>0 and ScanQrTrade<999 and BindingState=0";
  692. //所属创客编号
  693. if (!string.IsNullOrEmpty(UserIdMakerCode))
  694. {
  695. condition += " and BuyUserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  696. }
  697. //仓库所属创客编号
  698. if (!string.IsNullOrEmpty(StoreMakerCode))
  699. {
  700. var userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == StoreMakerCode) ?? new UserForMakerCode();
  701. var user = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  702. var store = db.StoreHouse.Where(m => m.UserId == user.Id && m.Status > -1).ToList();
  703. var storeIds = "";
  704. foreach (var item in store)
  705. {
  706. storeIds += item.Id + ",";
  707. }
  708. storeIds = storeIds.TrimEnd(',');
  709. condition += " and StoreId in (" + storeIds + ")";
  710. }
  711. //品牌
  712. if (!string.IsNullOrEmpty(BrandId))
  713. {
  714. condition += " and BrandId =" + BrandId;
  715. }
  716. if (!string.IsNullOrEmpty(PosSn))
  717. {
  718. condition += " and PosSn =" + PosSn + "";
  719. }
  720. if (!string.IsNullOrEmpty(RecycEndDateData))
  721. {
  722. string[] datelist = RecycEndDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  723. string start = datelist[0];
  724. string end = datelist[1];
  725. condition += " and RecycEndDate>='" + start + " 00:00:00' and RecycEndDate<='" + end + " 23:59:59'";
  726. }
  727. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosMachinesTwo", Fields, "Id desc", "0", page, limit, condition);
  728. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  729. foreach (Dictionary<string, object> dic in diclist)
  730. {
  731. //绑定状态
  732. int BindingState = int.Parse(dic["BindingState"].ToString());
  733. if (BindingState == 0) dic["BindingState"] = "未绑定";
  734. if (BindingState == 1) dic["BindingState"] = "已绑定";
  735. //激活状态
  736. int ActivationState = int.Parse(dic["ActivationState"].ToString());
  737. if (ActivationState == 0) dic["ActivationState"] = "未激活";
  738. if (ActivationState == 1) dic["ActivationState"] = "已激活";
  739. //所属创客
  740. int BuyUserId = int.Parse(function.CheckInt(dic["BuyUserId"].ToString()));
  741. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == BuyUserId) ?? new Users();
  742. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  743. dic["UserIdRealName"] = userid_Users.RealName;
  744. dic.Remove("BuyUserId");
  745. //所属仓库
  746. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  747. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  748. dic["StoreIdCode"] = storeid_StoreHouse.StoreNo;
  749. dic["StoreIdName"] = storeid_StoreHouse.StoreName;
  750. dic.Remove("StoreId");
  751. //产品类型
  752. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  753. decimal ScanQrTrade = decimal.Parse(dic["ScanQrTrade"].ToString());
  754. var brandInfo = dic["BrandId"].ToString();
  755. decimal amount = 0;
  756. if (brandInfo.Contains("电签"))
  757. {
  758. amount = 200;
  759. }
  760. if (brandInfo.Contains("大POS"))
  761. {
  762. amount = 300;
  763. }
  764. if (ScanQrTrade > 0 && ScanQrTrade < 999)
  765. {
  766. dic["AmountYk"] = amount;
  767. dic["Amountk"] = ScanQrTrade;
  768. dic["AmountDk"] = amount - ScanQrTrade;
  769. }
  770. if (ScanQrTrade == 999)
  771. {
  772. dic["AmountYk"] = amount;
  773. dic["Amountk"] = amount;
  774. dic["AmountDk"] = 0;
  775. }
  776. //参加活动
  777. dic["ActivityList"] = RelationClass.GetProfitObjectsActivesList(dic["ActivityList"].ToString());
  778. //绑定商户
  779. int BindMerchantId = int.Parse(function.CheckInt(dic["BindMerchantId"].ToString()));
  780. PosMerchantInfo bindmerchantid_MerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == BindMerchantId) ?? new PosMerchantInfo();
  781. dic["BindMerchantIdMerchantNo"] = bindmerchantid_MerchantInfo.MerchantNo;
  782. dic["BindMerchantIdMerchantName"] = bindmerchantid_MerchantInfo.MerchantName;
  783. dic.Remove("BindMerchantId");
  784. //机具类型
  785. int PosSnType = int.Parse(dic["PosSnType"].ToString());
  786. if (PosSnType == 0) dic["PosSnType"] = "兑换机具";
  787. if (PosSnType == 1) dic["PosSnType"] = "循环机具";
  788. //设备类型
  789. string DeviceType = dic["DeviceType"].ToString();
  790. if (DeviceType == "KysSignPos") dic["DeviceType"] = "快益刷电签POS";
  791. if (DeviceType == "KssSignPos") dic["DeviceType"] = "快闪刷电签POS";
  792. if (DeviceType == "") dic["DeviceType"] = "";
  793. //盟主信息
  794. int LeaderUserId = int.Parse(function.CheckInt(dic["LeaderUserId"].ToString()));
  795. if (LeaderUserId != 0)
  796. {
  797. Users users = db.Users.FirstOrDefault(m => m.Id == LeaderUserId) ?? new Users();
  798. dic["UserInfo"] = users.MakerCode + "_" + users.RealName;
  799. }
  800. //是否为第一台机具
  801. int IsFirst = int.Parse(dic["IsFirst"].ToString());
  802. if (IsFirst == 0) dic["IsFirst"] = "否";
  803. if (IsFirst == 1) dic["IsFirst"] = "是";
  804. //实际押金
  805. string SeoKeyword = dic["SeoKeyword"].ToString();
  806. if (SeoKeyword.Length > 2)
  807. {
  808. SeoKeyword = (decimal.Parse(SeoKeyword) / 100).ToString();
  809. }
  810. dic["SeoKeyword"] = SeoKeyword;
  811. //设置押金
  812. string PrizeParams = dic["PrizeParams"].ToString();
  813. dic["PrizeParams"] = PrizeParams;
  814. //所属运营中心
  815. int OpId = int.Parse(dic["OpId"].ToString());
  816. if (OpId != 0)
  817. {
  818. var sys = opdb.SysAdmin.FirstOrDefault(m => m.QueryCount > 0 && m.UserId == OpId) ?? new OpModels.SysAdmin();
  819. dic["OpCode"] = sys.OpCode;
  820. }
  821. }
  822. Dictionary<string, object> other = new Dictionary<string, object>();
  823. int TotalCount = 0;//总机具数
  824. DataTable dt = OtherMySqlConn.dtable("select count(0) from PosMachinesTwo where 1=1" + condition);
  825. if (dt.Rows.Count > 0)
  826. {
  827. TotalCount = int.Parse(function.CheckNum(dt.Rows[0][0].ToString()));
  828. }
  829. DataTable dts = OtherMySqlConn.dtable("select Id from PosMachinesTwo where 1=1" + condition);
  830. var Ids = "";
  831. foreach (DataRow item in dts.Rows)
  832. {
  833. Ids += item["Id"].ToString() + ",";
  834. }
  835. var Id = "," + Ids;
  836. var pos = db.PosMachinesTwo.Where(m => Id.Contains("," + m.Id + ",")).ToList();
  837. string[] strids = Ids.TrimEnd(',').Split(',');
  838. foreach (var items in strids)
  839. {
  840. int posId = int.Parse(items);
  841. var posInfo = pos.FirstOrDefault(m => m.Id == posId) ?? new PosMachinesTwo();
  842. decimal ScanQrTrade = decimal.Parse(posInfo.ScanQrTrade.ToString());
  843. var brandInfo = RelationClass.GetKqProductBrandInfo(int.Parse(posInfo.BrandId.ToString()));
  844. decimal amount = 0;
  845. if (brandInfo.Contains("电签"))
  846. {
  847. amount = 200;
  848. }
  849. if (brandInfo.Contains("大POS"))
  850. {
  851. amount = 300;
  852. }
  853. if (ScanQrTrade > 0 && ScanQrTrade < 999)
  854. {
  855. AmountYks += ScanQrTrade;
  856. AmountDks += amount - ScanQrTrade;
  857. }
  858. if (ScanQrTrade == 999)
  859. {
  860. AmountYks += amount;
  861. }
  862. }
  863. other.Add("TotalCount", TotalCount);
  864. other.Add("AmountYks", AmountYks);
  865. other.Add("AmountDks", AmountDks);
  866. obj.Add("other", other);
  867. return Json(obj);
  868. }
  869. #endregion
  870. }
  871. }