PosMachinesTwoController.cs 42 KB

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