PosMachinesTwoController.cs 42 KB

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