PosMachinesTwoController.cs 42 KB

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