PosMachinesTwoController.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  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, 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. string condition = " and Status>-1";
  52. //绑定状态
  53. if (!string.IsNullOrEmpty(BindingStateSelect))
  54. {
  55. condition += " and BindingState=" + BindingStateSelect;
  56. }
  57. //激活状态
  58. if (!string.IsNullOrEmpty(ActivationStateSelect))
  59. {
  60. condition += " and ActivationState=" + ActivationStateSelect;
  61. }
  62. //所属创客编号
  63. if (!string.IsNullOrEmpty(UserIdMakerCode))
  64. {
  65. condition += " and BuyUserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  66. }
  67. //所属创客真实姓名
  68. if (!string.IsNullOrEmpty(UserIdRealName))
  69. {
  70. condition += " and BuyUserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  71. }
  72. //所属仓库编号
  73. if (!string.IsNullOrEmpty(StoreIdCode))
  74. {
  75. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreIdCode + "')";
  76. }
  77. //所属仓库名称
  78. if (!string.IsNullOrEmpty(StoreIdName))
  79. {
  80. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreIdName + "')";
  81. }
  82. //品牌
  83. if (!string.IsNullOrEmpty(BrandId))
  84. {
  85. condition += " and BrandId =" + BrandId;
  86. }
  87. if (!string.IsNullOrEmpty(ActivationDateData))
  88. {
  89. string[] datelist = ActivationDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  90. string start = datelist[0];
  91. string end = datelist[1];
  92. condition += " and ActivationTime>='" + start + " 00:00:00' and ActivationTime<='" + end + " 23:59:59'";
  93. }
  94. if (!string.IsNullOrEmpty(BindingDateData))
  95. {
  96. string[] datelist = BindingDateData.Split(new string[] { " - " }, StringSplitOptions.None);
  97. string start = datelist[0];
  98. string end = datelist[1];
  99. condition += " and BindingTime>='" + start + " 00:00:00' and BindingTime<='" + end + " 23:59:59'";
  100. }
  101. Dictionary<string, object> obj = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).IndexData("PosMachinesTwo", Fields, "Id desc", "0", page, limit, condition);
  102. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  103. foreach (Dictionary<string, object> dic in diclist)
  104. {
  105. //绑定状态
  106. int BindingState = int.Parse(dic["BindingState"].ToString());
  107. if (BindingState == 0) dic["BindingState"] = "未绑定";
  108. if (BindingState == 1) dic["BindingState"] = "已绑定";
  109. //激活状态
  110. int ActivationState = int.Parse(dic["ActivationState"].ToString());
  111. if (ActivationState == 0) dic["ActivationState"] = "未激活";
  112. if (ActivationState == 1) dic["ActivationState"] = "已激活";
  113. //所属创客
  114. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  115. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  116. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  117. dic["UserIdRealName"] = userid_Users.RealName;
  118. dic.Remove("UserId");
  119. //所属仓库
  120. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  121. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  122. dic["StoreIdCode"] = storeid_StoreHouse.StoreNo;
  123. dic["StoreIdName"] = storeid_StoreHouse.StoreName;
  124. dic.Remove("StoreId");
  125. //产品类型
  126. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  127. //参加活动
  128. dic["ActivityList"] = RelationClass.GetProfitObjectsActivesList(dic["ActivityList"].ToString());
  129. //绑定商户
  130. int BindMerchantId = int.Parse(function.CheckInt(dic["BindMerchantId"].ToString()));
  131. PosMerchantInfo bindmerchantid_MerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == BindMerchantId) ?? new PosMerchantInfo();
  132. dic["BindMerchantIdMerchantNo"] = bindmerchantid_MerchantInfo.MerchantNo;
  133. dic["BindMerchantIdMerchantName"] = bindmerchantid_MerchantInfo.MerchantName;
  134. dic.Remove("BindMerchantId");
  135. //机具类型
  136. int PosSnType = int.Parse(dic["PosSnType"].ToString());
  137. if (PosSnType == 0) dic["PosSnType"] = "购买机具";
  138. if (PosSnType == 1) dic["PosSnType"] = "赠送机具";
  139. //设备类型
  140. string DeviceType = dic["DeviceType"].ToString();
  141. if (DeviceType == "KysSignPos") dic["DeviceType"] = "快益刷电签POS";
  142. if (DeviceType == "KssSignPos") dic["DeviceType"] = "快闪刷电签POS";
  143. if (DeviceType == "") dic["DeviceType"] = "";
  144. //盟主信息
  145. int LeaderUserId = int.Parse(function.CheckInt(dic["LeaderUserId"].ToString()));
  146. if (LeaderUserId != 0)
  147. {
  148. Users users = db.Users.FirstOrDefault(m => m.Id == LeaderUserId) ?? new Users();
  149. dic["UserInfo"] = users.MakerCode + "_" + users.RealName;
  150. }
  151. //是否为第一台机具
  152. int IsFirst = int.Parse(dic["IsFirst"].ToString());
  153. if (IsFirst == 0) dic["IsFirst"] = "否";
  154. if (IsFirst == 1) dic["IsFirst"] = "是";
  155. //循环开始时间
  156. if (!string.IsNullOrEmpty(dic["RecycEndDate"].ToString()))
  157. {
  158. var RecycStartDate = Convert.ToDateTime(dic["RecycEndDate"].ToString()).AddDays(-180).ToString("yyyy-MM-dd HH:mm:ss");
  159. dic["RecycStartDate"] = RecycStartDate;
  160. }
  161. }
  162. Dictionary<string, object> other = new Dictionary<string, object>();
  163. int TotalCount = 0;//总机具数
  164. string KysCount99 = "0.00";
  165. string KssCount99 = "0.00";
  166. string KssCoun198 = "0.00";
  167. string KssCount298 = "0.00";
  168. DataTable dt = OtherMySqlConn.dtable("select count(0) from PosMachinesTwo where 1=1" + condition);
  169. if (dt.Rows.Count > 0)
  170. {
  171. TotalCount = int.Parse(function.CheckNum(dt.Rows[0][0].ToString()));
  172. }
  173. // dt = OtherMySqlConn.dtable("select sum(TotalPrice) from Orders where PayStatus=1" + condition);
  174. // if (dt.Rows.Count > 0)
  175. // {
  176. // FailAmount = decimal.Parse(function.CheckNum(dt.Rows[0][0].ToString())).ToString("f2");
  177. // }
  178. other.Add("TotalCount", TotalCount);
  179. other.Add("KysCount99", 0);
  180. other.Add("KssCount99", 0);
  181. other.Add("KssCoun198", 0);
  182. other.Add("KssCount298", 0);
  183. obj.Add("other", other);
  184. return Json(obj);
  185. }
  186. #endregion
  187. #region 增加机具库
  188. /// <summary>
  189. /// 增加或修改机具库信息
  190. /// </summary>
  191. /// <returns></returns>
  192. public IActionResult Add(string right)
  193. {
  194. ViewBag.RightInfo = RightInfo;
  195. ViewBag.right = right;
  196. return View();
  197. }
  198. #endregion
  199. #region 增加机具库
  200. /// <summary>
  201. /// 增加或修改机具库信息
  202. /// </summary>
  203. /// <returns></returns>
  204. [HttpPost]
  205. public string Add(PosMachinesTwo data)
  206. {
  207. Dictionary<string, object> Fields = new Dictionary<string, object>();
  208. Fields.Add("SeoTitle", data.SeoTitle);
  209. Fields.Add("SeoKeyword", data.SeoKeyword);
  210. Fields.Add("SeoDescription", data.SeoDescription);
  211. int Id = new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Add("PosMachinesTwo", Fields, 0);
  212. AddSysLog(data.Id.ToString(), "PosMachinesTwo", "add");
  213. db.SaveChanges();
  214. return "success";
  215. }
  216. #endregion
  217. #region 修改机具库
  218. /// <summary>
  219. /// 增加或修改机具库信息
  220. /// </summary>
  221. /// <returns></returns>
  222. public IActionResult Edit(string right, int Id = 0)
  223. {
  224. ViewBag.RightInfo = RightInfo;
  225. ViewBag.right = right;
  226. PosMachinesTwo editData = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id) ?? new PosMachinesTwo();
  227. ViewBag.data = editData;
  228. return View();
  229. }
  230. #endregion
  231. #region 修改机具库
  232. /// <summary>
  233. /// 增加或修改机具库信息
  234. /// </summary>
  235. /// <returns></returns>
  236. [HttpPost]
  237. public string Edit(PosMachinesTwo data)
  238. {
  239. Dictionary<string, object> Fields = new Dictionary<string, object>();
  240. Fields.Add("PosSnType", data.PosSnType);
  241. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, data.Id);
  242. AddSysLog(data.Id.ToString(), "PosMachinesTwo", "update");
  243. db.SaveChanges();
  244. RedisDbconn.Instance.Clear("PosMachinesTwo:" + data.Id);
  245. return "success";
  246. }
  247. #endregion
  248. #region 未使用机具归位总仓
  249. /// <summary>
  250. /// 未使用机具归位总仓
  251. /// </summary>
  252. /// <returns></returns>
  253. public IActionResult Home(string right, int Id = 0)
  254. {
  255. ViewBag.RightInfo = RightInfo;
  256. ViewBag.right = right;
  257. PosMachinesTwo editData = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id) ?? new PosMachinesTwo();
  258. ViewBag.data = editData;
  259. return View();
  260. }
  261. #endregion
  262. #region 未使用机具归位总仓
  263. /// <summary>
  264. /// 未使用机具归位总仓
  265. /// </summary>
  266. /// <returns></returns>
  267. [HttpPost]
  268. public string Home(PosMachinesTwo data)
  269. {
  270. Dictionary<string, object> Fields = new Dictionary<string, object>();
  271. Fields.Add("SeoTitle", "");
  272. Fields.Add("SeoKeyword", "");
  273. Fields.Add("PosSnType", 0);
  274. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, data.Id);
  275. AddSysLog(data.Id.ToString(), "PosMachinesTwo", "home");
  276. db.SaveChanges();
  277. RedisDbconn.Instance.Clear("PosMachinesTwo:" + data.Id);
  278. return "success";
  279. }
  280. #endregion
  281. #region 删除机具库信息
  282. /// <summary>
  283. /// 删除机具库信息
  284. /// </summary>
  285. /// <returns></returns>
  286. public string Delete(string Id)
  287. {
  288. string[] idlist = Id.Split(new char[] { ',' });
  289. AddSysLog(Id, "PosMachinesTwo", "del");
  290. foreach (string subid in idlist)
  291. {
  292. int id = int.Parse(subid);
  293. Dictionary<string, object> Fields = new Dictionary<string, object>();
  294. Fields.Add("Status", -1);
  295. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, id);
  296. }
  297. db.SaveChanges();
  298. return "success";
  299. }
  300. #endregion
  301. #region 开启
  302. /// <summary>
  303. /// 开启
  304. /// </summary>
  305. /// <returns></returns>
  306. public string Open(string Id)
  307. {
  308. string[] idlist = Id.Split(new char[] { ',' });
  309. AddSysLog(Id, "PosMachinesTwo", "open");
  310. foreach (string subid in idlist)
  311. {
  312. int id = int.Parse(subid);
  313. Dictionary<string, object> Fields = new Dictionary<string, object>();
  314. Fields.Add("Status", 1);
  315. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, id);
  316. }
  317. db.SaveChanges();
  318. return "success";
  319. }
  320. #endregion
  321. #region 关闭
  322. /// <summary>
  323. /// 关闭
  324. /// </summary>
  325. /// <returns></returns>
  326. public string Close(string Id)
  327. {
  328. string[] idlist = Id.Split(new char[] { ',' });
  329. AddSysLog(Id, "PosMachinesTwo", "close");
  330. foreach (string subid in idlist)
  331. {
  332. int id = int.Parse(subid);
  333. Dictionary<string, object> Fields = new Dictionary<string, object>();
  334. Fields.Add("Status", 0);
  335. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Edit("PosMachinesTwo", Fields, id);
  336. }
  337. db.SaveChanges();
  338. return "success";
  339. }
  340. #endregion
  341. #region 排序
  342. /// <summary>
  343. /// 排序
  344. /// </summary>
  345. /// <param name="Id"></param>
  346. public string Sort(int Id, int Sort)
  347. {
  348. new AdminContentOther(_accessor.HttpContext, PublicFunction.MainTables).Sort("PosMachinesTwo", Sort, Id);
  349. AddSysLog(Id.ToString(), "PosMachinesTwo", "sort");
  350. return "success";
  351. }
  352. #endregion
  353. #region 导入数据
  354. /// <summary>
  355. /// 导入数据
  356. /// </summary>
  357. /// <param name="ExcelData"></param>
  358. public string Import(string ExcelData, int Kind = 0)
  359. {
  360. ExcelData = HttpUtility.UrlDecode(ExcelData);
  361. JsonData list = JsonMapper.ToObject(ExcelData);
  362. if (Kind == 1)
  363. {
  364. string error = "";
  365. List<string> PosSnList = new List<string>();
  366. for (int i = 1; i < list.Count; i++)
  367. {
  368. JsonData dr = list[i];
  369. string itemJson = dr.ToJson();
  370. string PosSn = itemJson.Contains("\"A\"") ? dr["A"].ToString() : "";
  371. string BrandId = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
  372. string MakerCode = itemJson.Contains("\"C\"") ? dr["C"].ToString() : "";
  373. string StoreNo = itemJson.Contains("\"D\"") ? dr["D"].ToString() : "";
  374. string No = itemJson.Contains("\"E\"") ? dr["E"].ToString() : "";
  375. string Remark = itemJson.Contains("\"F\"") ? dr["F"].ToString() : "";
  376. UserForMakerCode userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  377. var user = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  378. MachineForSnNo machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  379. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId && m.BrandId == Convert.ToInt32(BrandId) && m.UserId == user.Id && m.BindingState == 0);
  380. if (posInfo == null)
  381. {
  382. error += "以下操作失败" + PosSn + ',' + "未找到该品牌的机具" + '\n';
  383. }
  384. else if (PosSnList.Contains(PosSn))
  385. {
  386. error += "以下操作失败" + PosSn + ',' + "该机具号重复" + '\n';
  387. }
  388. else if (!string.IsNullOrEmpty(error))
  389. {
  390. return "Warning|" + error;
  391. }
  392. else
  393. {
  394. PosSnList.Add(PosSn);
  395. }
  396. }
  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 BrandId = itemJson.Contains("\"B\"") ? dr["B"].ToString() : "";
  403. string MakerCode = itemJson.Contains("\"C\"") ? dr["C"].ToString() : "";
  404. string StoreNo = itemJson.Contains("\"D\"") ? dr["D"].ToString() : "";
  405. string No = itemJson.Contains("\"E\"") ? dr["E"].ToString() : "";
  406. string Remark = itemJson.Contains("\"F\"") ? dr["F"].ToString() : "";
  407. decimal amount = 0;
  408. UserForMakerCode userForMakerCode = db.UserForMakerCode.FirstOrDefault(m => m.MakerCode == MakerCode);
  409. var user = db.Users.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new Users();
  410. var userAccount = db.UserAccount.FirstOrDefault(m => m.Id == userForMakerCode.UserId) ?? new UserAccount();
  411. var brandInfo = db.KqProducts.FirstOrDefault(m => m.Id == Convert.ToInt32(BrandId)) ?? new KqProducts();
  412. if (brandInfo.Name.Contains("电签"))
  413. {
  414. amount = 200;
  415. }
  416. if (brandInfo.Name.Contains("大POS"))
  417. {
  418. amount = 300;
  419. }
  420. userAccount.ValidAmount += amount;
  421. string text = string.Format("导入机具驳回仓库,UserId: '" + user.Id + "',BeforeChangeAmount:'" + userAccount.ValidAmount + "',AfterChangeAmount:'" + userAccount.ValidAmount + amount + "',ChangeAmount:'" + amount + "',Time'" + DateTime.Now + "'");
  422. function.WriteLog(text, "机具驳回仓库");//机具驳回仓库日志
  423. db.SaveChanges();
  424. MachineForSnNo machineForSnNo = db.MachineForSnNo.FirstOrDefault(m => m.SnNo == PosSn) ?? new MachineForSnNo();
  425. var posInfo = db.PosMachinesTwo.FirstOrDefault(m => m.Id == machineForSnNo.SnId && m.BrandId == Convert.ToInt32(BrandId) && m.UserId == user.Id && m.BindingState == 0);
  426. if (posInfo != null)
  427. {
  428. var storehouse = db.StoreHouse.FirstOrDefault(m => m.Id == posInfo.StoreId);
  429. StoreStockChange stockchange = db.StoreStockChange.Add(new StoreStockChange()
  430. {
  431. CreateDate = DateTime.Now,
  432. StoreId = storehouse.Id, //出货 仓库
  433. BrandId = Convert.ToInt32(BrandId), //产品类型
  434. ProductName = RelationClass.GetKqProductBrandInfo(Convert.ToInt32(BrandId)), //产品名称
  435. BizBatchNo = No, //业务批次号
  436. TransType = 1, //交易类型
  437. SnNo = PosSn, //SN编号
  438. StockOpDirect = 1, //库存操作方向
  439. SnStatus = 1, //SN状态
  440. DeviceVendor = posInfo.DeviceName, //设备厂商
  441. DeviceModel = posInfo.DeviceKind, //设备型号
  442. DeviceType = posInfo.DeviceType, //设备类型
  443. SourceStoreId = posInfo.SourceStoreId, //源仓库编号
  444. BrandType = posInfo.DeviceType, //品牌类型
  445. }).Entity;
  446. db.StoreChangeHistory.Add(new StoreChangeHistory()
  447. {
  448. CreateDate = DateTime.Now,
  449. UserId = user.Id, //创客
  450. BrandId = Convert.ToInt32(BrandId), //产品类型
  451. ChangeRecordNo = "JJBH" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8), //变更记录单号
  452. SeoTitle = "机具驳回仓库",
  453. BizBatchNo = No, //业务批次号
  454. SnNo = PosSn, //SN编号
  455. });
  456. StoreBalance balance = db.StoreBalance.Add(new StoreBalance()
  457. {
  458. CreateDate = DateTime.Now,
  459. StoreId = posInfo.StoreId, //仓库
  460. BrandId = Convert.ToInt32(BrandId), //产品类型
  461. OpStoreNum = 1, //操作库存数
  462. OpSymbol = "+", //操作符
  463. BeforeTotalNum = storehouse.TotalNum, //操作前总库存数
  464. AfterTotalNum = storehouse.TotalNum + 1, //操作后总库存数
  465. BeforeLaveNum = storehouse.LaveNum, //操作前剩余库存数
  466. AfterLaveNum = storehouse.LaveNum + 1, //操作后剩余库存数
  467. BeforeOutNum = storehouse.OutNum, //操作前出库数
  468. AfterOutNum = storehouse.OutNum - 1, //操作后出库数
  469. }).Entity;
  470. }
  471. }
  472. db.SaveChanges();
  473. }
  474. AddSysLog("0", "MachinesRejectStore", "Import");
  475. return "success";
  476. }
  477. #endregion
  478. #region 导出Excel
  479. /// <summary>
  480. /// 导出Excel
  481. /// </summary>
  482. /// <returns></returns>
  483. public JsonResult ExportExcel(PosMachinesTwo data, string BindingStateSelect, string ActivationStateSelect, string UserIdMakerCode, string UserIdRealName, string StoreIdCode, string StoreIdName)
  484. {
  485. Dictionary<string, string> Fields = new Dictionary<string, string>();
  486. Fields.Add("PosSn", "1"); //SN编号
  487. Fields.Add("BrandId", "0"); //品牌
  488. string condition = " and Status>-1";
  489. //绑定状态
  490. if (!string.IsNullOrEmpty(BindingStateSelect))
  491. {
  492. condition += " and BindingState=" + BindingStateSelect;
  493. }
  494. //激活状态
  495. if (!string.IsNullOrEmpty(ActivationStateSelect))
  496. {
  497. condition += " and ActivationState=" + ActivationStateSelect;
  498. }
  499. //所属创客创客编号
  500. if (!string.IsNullOrEmpty(UserIdMakerCode))
  501. {
  502. condition += " and UserId in (select UserId from UserForMakerCode where MakerCode='" + UserIdMakerCode + "')";
  503. }
  504. //所属创客真实姓名
  505. if (!string.IsNullOrEmpty(UserIdRealName))
  506. {
  507. condition += " and UserId in (select UserId from UserForRealName where RealName='" + UserIdRealName + "')";
  508. }
  509. //所属仓库编号
  510. if (!string.IsNullOrEmpty(StoreIdCode))
  511. {
  512. condition += " and StoreId in (select StoreId from StoreForCode where Code='" + StoreIdCode + "')";
  513. }
  514. //所属仓库名称
  515. if (!string.IsNullOrEmpty(StoreIdName))
  516. {
  517. condition += " and StoreId in (select StoreId from StoreForName where Name='" + StoreIdName + "')";
  518. }
  519. 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", false);
  520. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  521. foreach (Dictionary<string, object> dic in diclist)
  522. {
  523. //绑定状态
  524. int BindingState = int.Parse(dic["BindingState"].ToString());
  525. if (BindingState == 0) dic["BindingState"] = "未绑定";
  526. if (BindingState == 1) dic["BindingState"] = "已绑定";
  527. //绑定时间
  528. if (!string.IsNullOrEmpty(dic["BindingTime"].ToString()))
  529. {
  530. DateTime BindingTime = Convert.ToDateTime(dic["BindingTime"].ToString());
  531. }
  532. //激活状态
  533. int ActivationState = int.Parse(dic["ActivationState"].ToString());
  534. if (ActivationState == 0) dic["ActivationState"] = "未激活";
  535. if (ActivationState == 1) dic["ActivationState"] = "已激活";
  536. //激活时间
  537. if (!string.IsNullOrEmpty(dic["ActivationTime"].ToString()))
  538. {
  539. DateTime ActivationTime = Convert.ToDateTime(dic["ActivationTime"].ToString());
  540. }
  541. //划拨时间
  542. if (!string.IsNullOrEmpty(dic["TransferTime"].ToString()))
  543. {
  544. DateTime TransferTime = Convert.ToDateTime(dic["TransferTime"].ToString());
  545. }
  546. //所属创客
  547. int UserId = int.Parse(function.CheckInt(dic["UserId"].ToString()));
  548. Users userid_Users = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
  549. dic["UserIdMakerCode"] = userid_Users.MakerCode;
  550. dic["UserIdRealName"] = userid_Users.RealName;
  551. dic.Remove("UserId");
  552. //所属仓库
  553. int StoreId = int.Parse(function.CheckInt(dic["StoreId"].ToString()));
  554. StoreHouse storeid_StoreHouse = db.StoreHouse.FirstOrDefault(m => m.Id == StoreId) ?? new StoreHouse();
  555. dic["StoreIdCode"] = storeid_StoreHouse.StoreNo;
  556. dic["StoreIdName"] = storeid_StoreHouse.StoreName;
  557. dic.Remove("StoreId");
  558. //产品类型
  559. dic["BrandId"] = RelationClass.GetKqProductBrandInfo(int.Parse(dic["BrandId"].ToString()));
  560. //参加活动
  561. // dic["ActivityList"] = RelationClass.GetProfitObjectsActivesList(dic["ActivityList"].ToString());
  562. //绑定商户
  563. int BindMerchantId = int.Parse(function.CheckInt(dic["BindMerchantId"].ToString()));
  564. PosMerchantInfo bindmerchantid_MerchantInfo = db.PosMerchantInfo.FirstOrDefault(m => m.Id == BindMerchantId) ?? new PosMerchantInfo();
  565. dic["BindMerchantIdMerchantNo"] = bindmerchantid_MerchantInfo.MerchantNo;
  566. dic["BindMerchantIdMerchantName"] = bindmerchantid_MerchantInfo.MerchantName;
  567. dic.Remove("BindMerchantId");
  568. //机具类型
  569. int PosSnType = int.Parse(dic["PosSnType"].ToString());
  570. if (PosSnType == 0) dic["PosSnType"] = "购买机具";
  571. if (PosSnType == 1) dic["PosSnType"] = "赠送机具";
  572. // //设备类型
  573. // string DeviceType = dic["DeviceType"].ToString();
  574. // if (DeviceType == "KysSignPos") dic["DeviceType"] = "快益刷电签POS";
  575. // if (DeviceType == "KssSignPos") dic["DeviceType"] = "快闪刷电签POS";
  576. // if (DeviceType == "") dic["DeviceType"] = "";
  577. }
  578. Dictionary<string, object> result = new Dictionary<string, object>();
  579. result.Add("Status", "1");
  580. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  581. result.Add("Obj", diclist);
  582. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  583. ReturnFields.Add("UserIdMakerCode", "创客编号");
  584. ReturnFields.Add("UserIdRealName", "创客姓名");
  585. ReturnFields.Add("StoreIdCode", "仓库编号");
  586. ReturnFields.Add("StoreIdName", "仓库名称");
  587. ReturnFields.Add("BrandId", "产品类型");
  588. ReturnFields.Add("PosSn", "SN编号");
  589. ReturnFields.Add("PosSnType", "SN类型");
  590. // ReturnFields.Add("ActivityList", "参加活动");
  591. ReturnFields.Add("BindMerchantIdMerchantNo", "绑定商户编号");
  592. ReturnFields.Add("BindMerchantIdMerchantName", "绑定商户姓名");
  593. ReturnFields.Add("DeviceType", "设备类型");
  594. ReturnFields.Add("BindingState", "绑定状态");
  595. ReturnFields.Add("BindingTime", "绑定时间");
  596. ReturnFields.Add("ActivationState", "激活状态");
  597. ReturnFields.Add("ActivationTime", "激活时间");
  598. ReturnFields.Add("TransferTime", "划拨时间");
  599. result.Add("Fields", ReturnFields);
  600. AddSysLog("0", "PosMachinesTwo", "ExportExcel");
  601. return Json(result);
  602. }
  603. #endregion
  604. }
  605. }