PosMachinesTwoController.cs 43 KB

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